felix-mcp 2.0.134 → 2.0.136
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/README.md +87 -30
- package/dist/credential-store.js +589 -0
- package/dist/getting-started-guide.js +11 -3
- package/dist/human-prompt.js +245 -0
- package/dist/index.js +757 -111
- package/dist/key-backup.js +227 -159
- package/dist/market-stream-guide.js +14 -4
- package/dist/money-journal-identity.js +4 -3
- package/package.json +5 -2
- package/scripts/keychain-write.exp +15 -1
- package/server.json +3 -3
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
// CROSS_PLATFORM_KEYS_20261123: the few moments felix-keys needs a person, on every operating system.
|
|
2
|
+
//
|
|
3
|
+
// confirmHuman -> a yes/no the owner must click or type (never answerable by an agent's stdin).
|
|
4
|
+
// askHidden -> a secret typed by the owner (passphrase, key), never echoed.
|
|
5
|
+
// askVisible -> a short typed confirmation.
|
|
6
|
+
// showToHuman -> show a secret only on the owner's screen, never on stdout.
|
|
7
|
+
//
|
|
8
|
+
// macOS uses native dialogs (osascript). Windows uses a native message box and the console host. Linux uses
|
|
9
|
+
// zenity/kdialog on a desktop and the controlling terminal (/dev/tty) otherwise. Every path reads the answer
|
|
10
|
+
// from the screen or terminal, not from stdin, so an agent piping input cannot answer for the owner.
|
|
11
|
+
import { spawnSync } from "node:child_process";
|
|
12
|
+
import { closeSync, lstatSync, openSync, writeSync } from "node:fs";
|
|
13
|
+
import { delimiter, join } from "node:path";
|
|
14
|
+
const TITLE = "Felix";
|
|
15
|
+
function cancelled() {
|
|
16
|
+
throw new Error("Human confirmation was cancelled.");
|
|
17
|
+
}
|
|
18
|
+
function noHuman() {
|
|
19
|
+
throw new Error("This step needs the owner at this computer, and no dialog or terminal is available here. Run the same felix-keys command yourself in a terminal.");
|
|
20
|
+
}
|
|
21
|
+
function findExecutable(name) {
|
|
22
|
+
for (const directory of ["/usr/bin", "/bin", "/usr/local/bin", ...String(process.env.PATH || "").split(delimiter)]) {
|
|
23
|
+
if (!directory || !directory.startsWith("/"))
|
|
24
|
+
continue;
|
|
25
|
+
try {
|
|
26
|
+
if (lstatSync(join(directory, name)).isFile())
|
|
27
|
+
return join(directory, name);
|
|
28
|
+
}
|
|
29
|
+
catch { /* not here */ }
|
|
30
|
+
}
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
// ------------------------------------------------------------ macOS
|
|
34
|
+
function appleScript(lines) {
|
|
35
|
+
const result = spawnSync("/usr/bin/osascript", lines.flatMap((line) => ["-e", line]), {
|
|
36
|
+
encoding: "utf8", maxBuffer: 16 * 1024, stdio: ["ignore", "pipe", "pipe"],
|
|
37
|
+
});
|
|
38
|
+
if (result.status !== 0)
|
|
39
|
+
cancelled();
|
|
40
|
+
return String(result.stdout || "").replace(/\r?\n$/, "");
|
|
41
|
+
}
|
|
42
|
+
function appleScriptStdin(script) {
|
|
43
|
+
const result = spawnSync("/usr/bin/osascript", ["-"], {
|
|
44
|
+
encoding: "utf8", input: script, maxBuffer: 16 * 1024, stdio: ["pipe", "pipe", "pipe"],
|
|
45
|
+
});
|
|
46
|
+
if (result.status !== 0)
|
|
47
|
+
cancelled();
|
|
48
|
+
return String(result.stdout || "").replace(/\r?\n$/, "");
|
|
49
|
+
}
|
|
50
|
+
// ------------------------------------------------------------ Windows
|
|
51
|
+
function windowsPowerShell() {
|
|
52
|
+
const root = process.env.SystemRoot || process.env.windir || "C:\\Windows";
|
|
53
|
+
return join(root, "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
|
|
54
|
+
}
|
|
55
|
+
// QA r18: no caller text is ever spliced into PowerShell source. Prompt text travels in environment variables
|
|
56
|
+
// (never secrets), answers come back between markers so host chatter on stdout cannot corrupt them, and
|
|
57
|
+
// secrets never appear in argv (visible to other processes) or the environment.
|
|
58
|
+
const ANSWER_START = "<<felix-answer>>";
|
|
59
|
+
const ANSWER_END = "<</felix-answer>>";
|
|
60
|
+
function powerShell(script, options = {}) {
|
|
61
|
+
const encoded = Buffer.from(`$ErrorActionPreference = 'Stop'\n${script}`, "utf16le").toString("base64");
|
|
62
|
+
const textEnv = Object.fromEntries(Object.entries(options.text || {}).map(([key, value]) => [`FELIX_PROMPT_${key}`, value]));
|
|
63
|
+
return spawnSync(windowsPowerShell(), [
|
|
64
|
+
"-NoProfile", ...(options.inheritConsole ? [] : ["-NonInteractive"]), "-ExecutionPolicy", "Bypass", "-EncodedCommand", encoded,
|
|
65
|
+
], {
|
|
66
|
+
encoding: "utf8",
|
|
67
|
+
input: options.inheritConsole ? undefined : "",
|
|
68
|
+
env: { ...process.env, ...textEnv },
|
|
69
|
+
maxBuffer: 64 * 1024,
|
|
70
|
+
stdio: [options.inheritConsole ? "inherit" : "pipe", "pipe", options.inheritConsole ? "inherit" : "pipe"],
|
|
71
|
+
timeout: 15 * 60_000,
|
|
72
|
+
windowsHide: !options.inheritConsole,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function framedAnswer(result) {
|
|
76
|
+
if (result.status !== 0)
|
|
77
|
+
cancelled();
|
|
78
|
+
const text = String(result.stdout || "");
|
|
79
|
+
const start = text.lastIndexOf(ANSWER_START);
|
|
80
|
+
const end = text.lastIndexOf(ANSWER_END);
|
|
81
|
+
if (start < 0 || end < start)
|
|
82
|
+
cancelled();
|
|
83
|
+
return text.slice(start + ANSWER_START.length, end);
|
|
84
|
+
}
|
|
85
|
+
const PS_WRITE_ANSWER = [
|
|
86
|
+
"$o = [Console]::OpenStandardOutput()",
|
|
87
|
+
`$b = [System.Text.Encoding]::UTF8.GetBytes('${ANSWER_START}' + $v + '${ANSWER_END}')`,
|
|
88
|
+
"$o.Write($b, 0, $b.Length); $o.Flush()",
|
|
89
|
+
].join("\n");
|
|
90
|
+
// ------------------------------------------------------------ terminal (Linux, and fallback elsewhere)
|
|
91
|
+
function terminalPath() {
|
|
92
|
+
// Started by the MCP server: the terminal (if any) belongs to the AI client's UI, never prompt there.
|
|
93
|
+
if (process.platform === "win32" || process.env.FELIX_HUMAN_PROMPT_NO_TERMINAL === "1")
|
|
94
|
+
return undefined;
|
|
95
|
+
try {
|
|
96
|
+
closeSync(openSync("/dev/tty", "r+"));
|
|
97
|
+
return "/dev/tty";
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
function writeTerminal(text) {
|
|
104
|
+
const fd = openSync("/dev/tty", "w");
|
|
105
|
+
try {
|
|
106
|
+
writeSync(fd, text);
|
|
107
|
+
}
|
|
108
|
+
finally {
|
|
109
|
+
closeSync(fd);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function readTerminalLine(hidden) {
|
|
113
|
+
const script = hidden
|
|
114
|
+
? "stty -echo < /dev/tty; IFS= read -r a < /dev/tty; s=$?; stty echo < /dev/tty; printf '\\n' > /dev/tty; [ $s -eq 0 ] || exit 1; printf %s \"$a\""
|
|
115
|
+
: "IFS= read -r a < /dev/tty || exit 1; printf %s \"$a\"";
|
|
116
|
+
const result = spawnSync("/bin/sh", ["-c", script], {
|
|
117
|
+
encoding: "utf8", maxBuffer: 16 * 1024, stdio: ["ignore", "pipe", "ignore"], timeout: 15 * 60_000,
|
|
118
|
+
});
|
|
119
|
+
if (result.status !== 0)
|
|
120
|
+
cancelled();
|
|
121
|
+
return String(result.stdout || "");
|
|
122
|
+
}
|
|
123
|
+
function linuxDesktop() {
|
|
124
|
+
if (!process.env.DISPLAY && !process.env.WAYLAND_DISPLAY)
|
|
125
|
+
return undefined;
|
|
126
|
+
const zenity = findExecutable("zenity");
|
|
127
|
+
const kdialog = zenity ? undefined : findExecutable("kdialog");
|
|
128
|
+
return zenity || kdialog ? { zenity, kdialog } : undefined;
|
|
129
|
+
}
|
|
130
|
+
// ------------------------------------------------------------ public API
|
|
131
|
+
/** True when a person can be asked from this process (used before an agent-started step that needs a click). */
|
|
132
|
+
export function humanConfirmationAvailable(allowTerminal = true) {
|
|
133
|
+
if (process.platform === "darwin" || process.platform === "win32")
|
|
134
|
+
return true;
|
|
135
|
+
return Boolean(linuxDesktop() || (allowTerminal && terminalPath()));
|
|
136
|
+
}
|
|
137
|
+
export function confirmHuman(message, continueLabel = "Continue") {
|
|
138
|
+
if (process.platform === "darwin") {
|
|
139
|
+
appleScript([
|
|
140
|
+
`display alert ${JSON.stringify(`${TITLE} credential recovery`)} message ${JSON.stringify(message)} buttons {"Cancel", ${JSON.stringify(continueLabel)}} default button ${JSON.stringify(continueLabel)} cancel button "Cancel" as critical`,
|
|
141
|
+
]);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
if (process.platform === "win32") {
|
|
145
|
+
const result = powerShell([
|
|
146
|
+
"Add-Type -AssemblyName System.Windows.Forms",
|
|
147
|
+
"$r = [System.Windows.Forms.MessageBox]::Show($env:FELIX_PROMPT_TEXT, $env:FELIX_PROMPT_TITLE, 'OKCancel', 'Warning', 'Button2')",
|
|
148
|
+
"if ($r -ne 'OK') { exit 1 }",
|
|
149
|
+
].join("\n"), { text: { TEXT: `${message}\n\nChoose OK to ${continueLabel.toLowerCase()}.`, TITLE: TITLE } });
|
|
150
|
+
if (result.status !== 0)
|
|
151
|
+
cancelled();
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const desktop = linuxDesktop();
|
|
155
|
+
if (desktop?.zenity) {
|
|
156
|
+
const result = spawnSync(desktop.zenity, [
|
|
157
|
+
"--question", "--default-cancel", `--title=${TITLE}`, `--text=${message}`, `--ok-label=${continueLabel}`, "--cancel-label=Cancel", "--no-markup", "--width=480",
|
|
158
|
+
], { stdio: ["ignore", "ignore", "ignore"], timeout: 15 * 60_000 });
|
|
159
|
+
if (result.status !== 0)
|
|
160
|
+
cancelled();
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (desktop?.kdialog) {
|
|
164
|
+
const result = spawnSync(desktop.kdialog, ["--title", TITLE, "--warningcontinuecancel", message], {
|
|
165
|
+
stdio: ["ignore", "ignore", "ignore"], timeout: 15 * 60_000,
|
|
166
|
+
});
|
|
167
|
+
if (result.status !== 0)
|
|
168
|
+
cancelled();
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (!terminalPath())
|
|
172
|
+
noHuman();
|
|
173
|
+
writeTerminal(`\n${message}\nType "yes" to ${continueLabel.toLowerCase()}: `);
|
|
174
|
+
if (readTerminalLine(false).trim().toLowerCase() !== "yes")
|
|
175
|
+
cancelled();
|
|
176
|
+
}
|
|
177
|
+
export function askHidden(prompt) {
|
|
178
|
+
if (process.platform === "darwin") {
|
|
179
|
+
return appleScript([
|
|
180
|
+
`set response to display dialog ${JSON.stringify(prompt)} default answer "" with hidden answer buttons {"Cancel", "Continue"} default button "Continue" cancel button "Cancel" with title "${TITLE} credential recovery"`,
|
|
181
|
+
"return text returned of response",
|
|
182
|
+
]);
|
|
183
|
+
}
|
|
184
|
+
if (process.platform === "win32") {
|
|
185
|
+
return framedAnswer(powerShell([
|
|
186
|
+
"$s = Read-Host -AsSecureString -Prompt $env:FELIX_PROMPT_TEXT",
|
|
187
|
+
"$p = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($s)",
|
|
188
|
+
"try { $v = [Runtime.InteropServices.Marshal]::PtrToStringBSTR($p) } finally { [Runtime.InteropServices.Marshal]::ZeroFreeBSTR($p) }",
|
|
189
|
+
PS_WRITE_ANSWER,
|
|
190
|
+
].join("\n"), { inheritConsole: true, text: { TEXT: prompt } }));
|
|
191
|
+
}
|
|
192
|
+
if (!terminalPath())
|
|
193
|
+
noHuman();
|
|
194
|
+
writeTerminal(`${prompt} `);
|
|
195
|
+
return readTerminalLine(true);
|
|
196
|
+
}
|
|
197
|
+
export function askVisible(prompt) {
|
|
198
|
+
if (process.platform === "darwin") {
|
|
199
|
+
return appleScript([
|
|
200
|
+
`set response to display dialog ${JSON.stringify(prompt)} default answer "" buttons {"Cancel", "Restore"} default button "Restore" cancel button "Cancel" with title "${TITLE} credential recovery"`,
|
|
201
|
+
"return text returned of response",
|
|
202
|
+
]);
|
|
203
|
+
}
|
|
204
|
+
if (process.platform === "win32") {
|
|
205
|
+
return framedAnswer(powerShell([
|
|
206
|
+
"$v = Read-Host -Prompt $env:FELIX_PROMPT_TEXT",
|
|
207
|
+
PS_WRITE_ANSWER,
|
|
208
|
+
].join("\n"), { inheritConsole: true, text: { TEXT: prompt } }));
|
|
209
|
+
}
|
|
210
|
+
if (!terminalPath())
|
|
211
|
+
noHuman();
|
|
212
|
+
writeTerminal(`${prompt} `);
|
|
213
|
+
return readTerminalLine(false);
|
|
214
|
+
}
|
|
215
|
+
/** Show a secret on the owner's screen only. It never goes to stdout, so an agent reading output never sees it. */
|
|
216
|
+
export function showToHuman(title, message, secret) {
|
|
217
|
+
if (process.platform === "darwin") {
|
|
218
|
+
appleScriptStdin(`display dialog ${JSON.stringify(message)} default answer ${JSON.stringify(secret)} buttons {"Done"} default button "Done" with title ${JSON.stringify(title)}`);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
if (process.platform === "win32") {
|
|
222
|
+
let consoleOut;
|
|
223
|
+
try {
|
|
224
|
+
consoleOut = openSync("\\\\.\\CONOUT$", "r+");
|
|
225
|
+
}
|
|
226
|
+
catch {
|
|
227
|
+
noHuman();
|
|
228
|
+
}
|
|
229
|
+
try {
|
|
230
|
+
writeSync(consoleOut, `\r\n${title}\r\n${message}\r\n\r\n ${secret}\r\n\r\n`);
|
|
231
|
+
}
|
|
232
|
+
finally {
|
|
233
|
+
closeSync(consoleOut);
|
|
234
|
+
}
|
|
235
|
+
const waited = powerShell("[void](Read-Host -Prompt $env:FELIX_PROMPT_TEXT)\nClear-Host\n[Console]::Write([char]27 + '[3J')", { inheritConsole: true, text: { TEXT: "Press Enter when you have stored it" } });
|
|
236
|
+
if (waited.status !== 0)
|
|
237
|
+
cancelled();
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
if (!terminalPath())
|
|
241
|
+
noHuman();
|
|
242
|
+
writeTerminal(`\n${title}\n${message}\n\n ${secret}\n\nPress Enter when you have stored it.`);
|
|
243
|
+
readTerminalLine(false);
|
|
244
|
+
writeTerminal("\x1b[2J\x1b[3J\x1b[H");
|
|
245
|
+
}
|