superbased 1.4.0 → 1.5.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.
- package/SUPERBASED_SKILL.md +91 -32
- package/dist/headless/electron/modules/active-window.js +8 -0
- package/dist/headless/electron/modules/api-server.js +137 -3
- package/dist/headless/electron/modules/azure-speech-realtime.js +187 -54
- package/dist/headless/electron/modules/dictation.js +122 -0
- package/dist/headless/headless/dictation-hotkey.js +212 -47
- package/dist/headless/headless/dictation-overlay.js +218 -0
- package/dist/headless/headless/mic-capture.js +95 -1
- package/dist/headless/headless/platform-headless.js +103 -3
- package/dist/headless/headless/win32-text-injector.js +359 -0
- package/mcp-server/dist/index.js +4 -4
- package/package.json +1 -1
|
@@ -48,6 +48,11 @@ exports.isMicAvailable = isMicAvailable;
|
|
|
48
48
|
exports.getMicBackend = getMicBackend;
|
|
49
49
|
exports.startRecording = startRecording;
|
|
50
50
|
exports.recordForDuration = recordForDuration;
|
|
51
|
+
exports.startWarmMic = startWarmMic;
|
|
52
|
+
exports.startWarmCapture = startWarmCapture;
|
|
53
|
+
exports.stopWarmCapture = stopWarmCapture;
|
|
54
|
+
exports.shutdownWarmMic = shutdownWarmMic;
|
|
55
|
+
exports.isWarmMicRunning = isWarmMicRunning;
|
|
51
56
|
exports.prewarm = prewarm;
|
|
52
57
|
const childProcess = __importStar(require("child_process"));
|
|
53
58
|
const os = __importStar(require("os"));
|
|
@@ -300,8 +305,97 @@ async function recordForDuration(seconds) {
|
|
|
300
305
|
await new Promise((r) => setTimeout(r, seconds * 1000));
|
|
301
306
|
return handle.stop();
|
|
302
307
|
}
|
|
308
|
+
// ── Warm Mic (persistent ffmpeg for instant dictation start) ──
|
|
309
|
+
let warmProc = null;
|
|
310
|
+
let warmPcmCallback = null;
|
|
311
|
+
let warmHeaderSkipped = false;
|
|
312
|
+
let warmActive = false;
|
|
303
313
|
/**
|
|
304
|
-
*
|
|
314
|
+
* Start a persistent ffmpeg process that keeps the mic open.
|
|
315
|
+
* PCM chunks are only forwarded when startWarmCapture() is called.
|
|
316
|
+
* Eliminates the ~800ms dshow device open delay on each dictation.
|
|
317
|
+
*/
|
|
318
|
+
function startWarmMic() {
|
|
319
|
+
if (warmProc || detectBackend() !== 'ffmpeg')
|
|
320
|
+
return;
|
|
321
|
+
let inputArgs;
|
|
322
|
+
if (process.platform === 'win32') {
|
|
323
|
+
const micName = detectWindowsMicrophone();
|
|
324
|
+
inputArgs = ['-f', 'dshow', '-i', `audio=${micName}`];
|
|
325
|
+
}
|
|
326
|
+
else if (process.platform === 'darwin') {
|
|
327
|
+
inputArgs = ['-f', 'avfoundation', '-i', ':default'];
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
inputArgs = ['-f', 'pulse', '-i', 'default'];
|
|
331
|
+
}
|
|
332
|
+
const args = [
|
|
333
|
+
'-hide_banner', '-loglevel', 'error',
|
|
334
|
+
'-y',
|
|
335
|
+
...inputArgs,
|
|
336
|
+
'-ar', '16000', '-ac', '1', '-f', 'wav',
|
|
337
|
+
'pipe:1',
|
|
338
|
+
];
|
|
339
|
+
warmProc = childProcess.spawn(ffmpegPath, args, { stdio: ['pipe', 'pipe', 'pipe'] });
|
|
340
|
+
warmHeaderSkipped = false;
|
|
341
|
+
warmProc.stdout?.on('data', (chunk) => {
|
|
342
|
+
if (!warmActive || !warmPcmCallback)
|
|
343
|
+
return;
|
|
344
|
+
// Skip 44-byte WAV header on first chunk
|
|
345
|
+
if (!warmHeaderSkipped) {
|
|
346
|
+
warmHeaderSkipped = true;
|
|
347
|
+
if (chunk.length > 44) {
|
|
348
|
+
warmPcmCallback(chunk.subarray(44));
|
|
349
|
+
}
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
warmPcmCallback(chunk);
|
|
353
|
+
});
|
|
354
|
+
warmProc.on('close', () => { warmProc = null; });
|
|
355
|
+
warmProc.on('error', () => { warmProc = null; });
|
|
356
|
+
// Suppress stderr noise
|
|
357
|
+
warmProc.stderr?.on('data', () => { });
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Start forwarding PCM chunks from the warm mic to the callback.
|
|
361
|
+
* Returns immediately — no ffmpeg spawn delay.
|
|
362
|
+
*/
|
|
363
|
+
function startWarmCapture(callback) {
|
|
364
|
+
warmPcmCallback = callback;
|
|
365
|
+
warmActive = true;
|
|
366
|
+
// Reset header skip for fresh WAV header detection if mic was restarted
|
|
367
|
+
if (!warmProc) {
|
|
368
|
+
startWarmMic();
|
|
369
|
+
warmHeaderSkipped = false;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* Stop forwarding PCM chunks but keep the warm mic alive.
|
|
374
|
+
*/
|
|
375
|
+
function stopWarmCapture() {
|
|
376
|
+
warmActive = false;
|
|
377
|
+
warmPcmCallback = null;
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* Shut down the warm mic entirely.
|
|
381
|
+
*/
|
|
382
|
+
function shutdownWarmMic() {
|
|
383
|
+
warmActive = false;
|
|
384
|
+
warmPcmCallback = null;
|
|
385
|
+
if (warmProc) {
|
|
386
|
+
try {
|
|
387
|
+
warmProc.stdin?.write('q');
|
|
388
|
+
}
|
|
389
|
+
catch { /* ignore */ }
|
|
390
|
+
warmProc.kill('SIGTERM');
|
|
391
|
+
warmProc = null;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
function isWarmMicRunning() {
|
|
395
|
+
return warmProc !== null;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Pre-warm: detect backend + cache mic device name + start warm mic on startup.
|
|
305
399
|
* Call this early to avoid detection latency on first dictation.
|
|
306
400
|
*/
|
|
307
401
|
function prewarm() {
|
|
@@ -38,6 +38,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
38
38
|
exports.headlessPlatform = void 0;
|
|
39
39
|
const os = __importStar(require("os"));
|
|
40
40
|
const path = __importStar(require("path"));
|
|
41
|
+
const fs = __importStar(require("fs"));
|
|
41
42
|
const childProcess = __importStar(require("child_process"));
|
|
42
43
|
const paths_1 = require("../electron/core/paths");
|
|
43
44
|
function getVersion() {
|
|
@@ -112,9 +113,108 @@ exports.headlessPlatform = {
|
|
|
112
113
|
setClipboardText: clipboardWrite,
|
|
113
114
|
getClipboardImage: () => null, // Not supported in headless without Electron
|
|
114
115
|
listWindows: async () => {
|
|
115
|
-
//
|
|
116
|
-
//
|
|
117
|
-
|
|
116
|
+
// List ALL visible windows using platform-specific commands.
|
|
117
|
+
// On Windows, Get-Process only returns one MainWindowTitle per process,
|
|
118
|
+
// so Electron apps with multiple windows only show up once. We use
|
|
119
|
+
// Win32 EnumWindows via inline C# to enumerate every top-level window.
|
|
120
|
+
try {
|
|
121
|
+
if (process.platform === 'win32') {
|
|
122
|
+
// Write PowerShell script to temp file to avoid quote-escaping issues
|
|
123
|
+
// with inline C# code passed via -command argument.
|
|
124
|
+
const tmpScript = path.join(os.tmpdir(), 'superbased-winlist.ps1');
|
|
125
|
+
fs.writeFileSync(tmpScript, `
|
|
126
|
+
Add-Type -TypeDefinition @'
|
|
127
|
+
using System; using System.Text; using System.Runtime.InteropServices; using System.Collections.Generic;
|
|
128
|
+
public class WinEnum {
|
|
129
|
+
[DllImport("user32.dll")] static extern bool EnumWindows(CallBack cb, int lp);
|
|
130
|
+
[DllImport("user32.dll")] static extern int GetWindowText(IntPtr h, StringBuilder s, int n);
|
|
131
|
+
[DllImport("user32.dll")] static extern bool IsWindowVisible(IntPtr h);
|
|
132
|
+
[DllImport("user32.dll")] static extern int GetWindowTextLength(IntPtr h);
|
|
133
|
+
[DllImport("user32.dll")] static extern uint GetWindowThreadProcessId(IntPtr h, out uint pid);
|
|
134
|
+
[DllImport("user32.dll")] static extern bool IsIconic(IntPtr h);
|
|
135
|
+
delegate bool CallBack(IntPtr h, int lp);
|
|
136
|
+
public static List<long> handles = new List<long>();
|
|
137
|
+
public static List<int[]> pids = new List<int[]>();
|
|
138
|
+
public static List<string> titles = new List<string>();
|
|
139
|
+
public static List<bool> minimized = new List<bool>();
|
|
140
|
+
public static void Run() {
|
|
141
|
+
EnumWindows((h, l) => {
|
|
142
|
+
if (IsWindowVisible(h) && GetWindowTextLength(h) > 0) {
|
|
143
|
+
var t = new StringBuilder(512); GetWindowText(h, t, 512);
|
|
144
|
+
uint pid; GetWindowThreadProcessId(h, out pid);
|
|
145
|
+
handles.Add(h.ToInt64()); pids.Add(new int[]{(int)pid});
|
|
146
|
+
titles.Add(t.ToString()); minimized.Add(IsIconic(h));
|
|
147
|
+
}
|
|
148
|
+
return true;
|
|
149
|
+
}, 0);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
'@
|
|
153
|
+
[WinEnum]::Run()
|
|
154
|
+
$r = @(); for($i=0;$i -lt [WinEnum]::titles.Count;$i++){
|
|
155
|
+
$r += [PSCustomObject]@{Hwnd=[WinEnum]::handles[$i];Id=[WinEnum]::pids[$i][0];Title=[WinEnum]::titles[$i];Minimized=[WinEnum]::minimized[$i]}
|
|
156
|
+
}
|
|
157
|
+
$r | ConvertTo-Json -Compress
|
|
158
|
+
`);
|
|
159
|
+
const output = childProcess.execSync(`powershell -ExecutionPolicy Bypass -File "${tmpScript}"`, { encoding: 'utf-8', timeout: 8000 });
|
|
160
|
+
try {
|
|
161
|
+
fs.unlinkSync(tmpScript);
|
|
162
|
+
}
|
|
163
|
+
catch { /* cleanup */ }
|
|
164
|
+
const parsed = JSON.parse(output.trim());
|
|
165
|
+
const items = Array.isArray(parsed) ? parsed : [parsed];
|
|
166
|
+
return items
|
|
167
|
+
.filter((w) => w.Title && w.Title.trim())
|
|
168
|
+
.map((w) => ({
|
|
169
|
+
id: String(w.Id),
|
|
170
|
+
name: w.Title,
|
|
171
|
+
hwnd: String(w.Hwnd),
|
|
172
|
+
minimized: w.Minimized,
|
|
173
|
+
}));
|
|
174
|
+
}
|
|
175
|
+
else if (process.platform === 'darwin') {
|
|
176
|
+
// List all visible windows with their app name and window title
|
|
177
|
+
const output = childProcess.execSync(`osascript -e '
|
|
178
|
+
set output to ""
|
|
179
|
+
tell application "System Events"
|
|
180
|
+
set procs to every process whose visible is true
|
|
181
|
+
repeat with p in procs
|
|
182
|
+
set pName to name of p
|
|
183
|
+
set pId to unix id of p
|
|
184
|
+
try
|
|
185
|
+
set wins to every window of p
|
|
186
|
+
repeat with w in wins
|
|
187
|
+
set wTitle to name of w
|
|
188
|
+
set output to output & pId & "\\t" & pName & " - " & wTitle & "\\n"
|
|
189
|
+
end repeat
|
|
190
|
+
end try
|
|
191
|
+
end repeat
|
|
192
|
+
end tell
|
|
193
|
+
return output'`, { encoding: 'utf-8', timeout: 8000 });
|
|
194
|
+
return output.trim().split('\n').filter(Boolean).map((line) => {
|
|
195
|
+
const tabIdx = line.indexOf('\t');
|
|
196
|
+
if (tabIdx === -1)
|
|
197
|
+
return { id: '0', name: line.trim() };
|
|
198
|
+
return {
|
|
199
|
+
id: line.substring(0, tabIdx).trim(),
|
|
200
|
+
name: line.substring(tabIdx + 1).trim(),
|
|
201
|
+
};
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
// Linux: wmctrl or xdotool
|
|
206
|
+
const output = childProcess.execSync('wmctrl -l 2>/dev/null || xdotool search --name "" getwindowname 2>/dev/null || echo ""', {
|
|
207
|
+
encoding: 'utf-8', timeout: 5000,
|
|
208
|
+
});
|
|
209
|
+
return output.trim().split('\n').filter(Boolean).map((line, i) => ({
|
|
210
|
+
id: String(i),
|
|
211
|
+
name: line.replace(/^0x[\da-f]+\s+\d+\s+\S+\s+/i, '').trim() || line.trim(),
|
|
212
|
+
}));
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
catch {
|
|
216
|
+
return [];
|
|
217
|
+
}
|
|
118
218
|
},
|
|
119
219
|
openUrl,
|
|
120
220
|
isElectron: () => false,
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Pre-spawned PowerShell helper for injecting text into the active text field
|
|
3
|
+
// via Win32 SendInput with KEYEVENTF_UNICODE. Bypasses the keyboard input
|
|
4
|
+
// pipeline entirely — characters arrive as VK_PACKET, which is immune to
|
|
5
|
+
// modifier key state (Ctrl+Alt held during dictation).
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
40
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
41
|
+
};
|
|
42
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
43
|
+
exports.initTextInjector = initTextInjector;
|
|
44
|
+
exports.replaceChar = replaceChar;
|
|
45
|
+
exports.simpleReplace = simpleReplace;
|
|
46
|
+
exports.typeText = typeText;
|
|
47
|
+
exports.typeTextFull = typeTextFull;
|
|
48
|
+
exports.sendUnicodeBackspaces = sendUnicodeBackspaces;
|
|
49
|
+
exports.sendBackspaces = sendBackspaces;
|
|
50
|
+
exports.sendBackspacesFull = sendBackspacesFull;
|
|
51
|
+
exports.isReady = isReady;
|
|
52
|
+
exports.shutdownTextInjector = shutdownTextInjector;
|
|
53
|
+
const path = __importStar(require("path"));
|
|
54
|
+
const fs = __importStar(require("fs"));
|
|
55
|
+
const os = __importStar(require("os"));
|
|
56
|
+
const child_process_1 = require("child_process");
|
|
57
|
+
const file_logger_1 = __importDefault(require("../electron/core/file-logger"));
|
|
58
|
+
let helperProcess = null;
|
|
59
|
+
let ready = false;
|
|
60
|
+
const SCRIPT_PATH = path.join(os.tmpdir(), 'superbased-text-injector.ps1');
|
|
61
|
+
function initTextInjector() {
|
|
62
|
+
if (process.platform !== 'win32')
|
|
63
|
+
return;
|
|
64
|
+
fs.writeFileSync(SCRIPT_PATH, PS1_SCRIPT);
|
|
65
|
+
helperProcess = (0, child_process_1.spawn)('powershell', [
|
|
66
|
+
'-ExecutionPolicy', 'Bypass',
|
|
67
|
+
'-WindowStyle', 'Hidden',
|
|
68
|
+
'-File', SCRIPT_PATH,
|
|
69
|
+
], {
|
|
70
|
+
stdio: ['pipe', 'pipe', 'pipe'],
|
|
71
|
+
detached: false,
|
|
72
|
+
windowsHide: true,
|
|
73
|
+
});
|
|
74
|
+
helperProcess.on('error', (err) => {
|
|
75
|
+
file_logger_1.default.warn('[TextInjector] Failed to spawn:', err);
|
|
76
|
+
helperProcess = null;
|
|
77
|
+
});
|
|
78
|
+
helperProcess.on('exit', () => {
|
|
79
|
+
helperProcess = null;
|
|
80
|
+
ready = false;
|
|
81
|
+
});
|
|
82
|
+
// Read stdout for READY signal
|
|
83
|
+
if (helperProcess.stdout) {
|
|
84
|
+
let buf = '';
|
|
85
|
+
helperProcess.stdout.on('data', (chunk) => {
|
|
86
|
+
const text = chunk.toString();
|
|
87
|
+
buf += text;
|
|
88
|
+
file_logger_1.default.info(`[TextInjector] stdout: ${text.trim()}`);
|
|
89
|
+
if (buf.includes('READY')) {
|
|
90
|
+
ready = true;
|
|
91
|
+
file_logger_1.default.info('[TextInjector] Helper ready');
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
// Log stderr for diagnostics
|
|
96
|
+
if (helperProcess.stderr) {
|
|
97
|
+
helperProcess.stderr.on('data', (chunk) => {
|
|
98
|
+
file_logger_1.default.warn(`[TextInjector] stderr: ${chunk.toString().trim()}`);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
file_logger_1.default.info('[TextInjector] Pre-spawning PowerShell helper');
|
|
102
|
+
}
|
|
103
|
+
/** Replace the last character: release mods → backspace → type new char (no re-press). */
|
|
104
|
+
function replaceChar(char) {
|
|
105
|
+
if (!ready || !helperProcess?.stdin)
|
|
106
|
+
return;
|
|
107
|
+
helperProcess.stdin.write(`repl:${char}\n`);
|
|
108
|
+
}
|
|
109
|
+
/** Simple replace: backspace + new char (no modifier release). Use after mods already released. */
|
|
110
|
+
function simpleReplace(char) {
|
|
111
|
+
if (!ready || !helperProcess?.stdin)
|
|
112
|
+
return;
|
|
113
|
+
helperProcess.stdin.write(`simpl:${char}\n`);
|
|
114
|
+
}
|
|
115
|
+
/** Type text using KEYEVENTF_UNICODE (no modifier release). */
|
|
116
|
+
function typeText(text) {
|
|
117
|
+
if (!ready || !helperProcess?.stdin) {
|
|
118
|
+
file_logger_1.default.warn(`[TextInjector] typeText skipped: ready=${ready}, stdin=${!!helperProcess?.stdin}`);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
file_logger_1.default.info(`[TextInjector] Sending: type:${text}`);
|
|
122
|
+
helperProcess.stdin.write(`type:${text}\n`);
|
|
123
|
+
}
|
|
124
|
+
/** Type text with atomic modifier release + restore (fallback). */
|
|
125
|
+
function typeTextFull(text) {
|
|
126
|
+
if (!ready || !helperProcess?.stdin) {
|
|
127
|
+
file_logger_1.default.warn(`[TextInjector] typeTextFull skipped: ready=${ready}, stdin=${!!helperProcess?.stdin}`);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
file_logger_1.default.info(`[TextInjector] Sending: typefull:${text}`);
|
|
131
|
+
helperProcess.stdin.write(`typefull:${text}\n`);
|
|
132
|
+
}
|
|
133
|
+
/** Send backspaces via KEYEVENTF_UNICODE (char 0x08) — works while modifiers held. */
|
|
134
|
+
function sendUnicodeBackspaces(count) {
|
|
135
|
+
if (!ready || !helperProcess?.stdin)
|
|
136
|
+
return;
|
|
137
|
+
helperProcess.stdin.write(`unibs:${count}\n`);
|
|
138
|
+
}
|
|
139
|
+
/** Send backspaces (simple — no modifier manipulation). */
|
|
140
|
+
function sendBackspaces(count) {
|
|
141
|
+
if (!ready || !helperProcess?.stdin) {
|
|
142
|
+
file_logger_1.default.warn(`[TextInjector] sendBackspaces skipped: ready=${ready}`);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
file_logger_1.default.info(`[TextInjector] Sending: bs:${count}`);
|
|
146
|
+
helperProcess.stdin.write(`bs:${count}\n`);
|
|
147
|
+
}
|
|
148
|
+
/** Send backspaces with modifier release (use when modifiers might still be held). */
|
|
149
|
+
function sendBackspacesFull(count) {
|
|
150
|
+
if (!ready || !helperProcess?.stdin)
|
|
151
|
+
return;
|
|
152
|
+
file_logger_1.default.info(`[TextInjector] Sending: bsfull:${count}`);
|
|
153
|
+
helperProcess.stdin.write(`bsfull:${count}\n`);
|
|
154
|
+
}
|
|
155
|
+
function isReady() {
|
|
156
|
+
return ready;
|
|
157
|
+
}
|
|
158
|
+
function shutdownTextInjector() {
|
|
159
|
+
if (helperProcess?.stdin) {
|
|
160
|
+
try {
|
|
161
|
+
helperProcess.stdin.write('exit\n');
|
|
162
|
+
}
|
|
163
|
+
catch { /* ignore */ }
|
|
164
|
+
}
|
|
165
|
+
if (helperProcess) {
|
|
166
|
+
const proc = helperProcess;
|
|
167
|
+
helperProcess = null;
|
|
168
|
+
setTimeout(() => { try {
|
|
169
|
+
proc.kill();
|
|
170
|
+
}
|
|
171
|
+
catch { /* ignore */ } }, 2000);
|
|
172
|
+
}
|
|
173
|
+
ready = false;
|
|
174
|
+
}
|
|
175
|
+
// C# class compiled once via Add-Type. Provides SendInput wrappers for:
|
|
176
|
+
// - TypeUnicode: KEYEVENTF_UNICODE chars (no modifier manipulation)
|
|
177
|
+
// - TypeWithModRelease: release Ctrl+Alt → type → restore (atomic batch)
|
|
178
|
+
// - SendBackspaces: release Ctrl+Alt → backspaces → restore (atomic batch)
|
|
179
|
+
const PS1_SCRIPT = `
|
|
180
|
+
Add-Type -TypeDefinition @'
|
|
181
|
+
using System;
|
|
182
|
+
using System.Runtime.InteropServices;
|
|
183
|
+
|
|
184
|
+
public class TextInjector {
|
|
185
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
186
|
+
public struct INPUT {
|
|
187
|
+
public uint type;
|
|
188
|
+
public INPUTUNION u;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
[StructLayout(LayoutKind.Explicit, Size = 32)]
|
|
192
|
+
public struct INPUTUNION {
|
|
193
|
+
[FieldOffset(0)] public KEYBDINPUT ki;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
[StructLayout(LayoutKind.Sequential)]
|
|
197
|
+
public struct KEYBDINPUT {
|
|
198
|
+
public ushort wVk;
|
|
199
|
+
public ushort wScan;
|
|
200
|
+
public uint dwFlags;
|
|
201
|
+
public uint time;
|
|
202
|
+
public IntPtr dwExtraInfo;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
[DllImport("user32.dll", SetLastError = true)]
|
|
206
|
+
static extern uint SendInput(uint nInputs, INPUT[] pInputs, int cbSize);
|
|
207
|
+
|
|
208
|
+
const uint INPUT_KEYBOARD = 1;
|
|
209
|
+
const uint KEYEVENTF_KEYUP = 0x0002;
|
|
210
|
+
const uint KEYEVENTF_UNICODE = 0x0004;
|
|
211
|
+
const ushort VK_BACK = 0x08;
|
|
212
|
+
const ushort VK_LCONTROL = 0xA2;
|
|
213
|
+
const ushort VK_LMENU = 0xA4;
|
|
214
|
+
|
|
215
|
+
static INPUT KeyDown(ushort vk) {
|
|
216
|
+
var inp = new INPUT();
|
|
217
|
+
inp.type = INPUT_KEYBOARD;
|
|
218
|
+
inp.u.ki.wVk = vk;
|
|
219
|
+
inp.u.ki.dwFlags = 0;
|
|
220
|
+
return inp;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
static INPUT KeyUp(ushort vk) {
|
|
224
|
+
var inp = new INPUT();
|
|
225
|
+
inp.type = INPUT_KEYBOARD;
|
|
226
|
+
inp.u.ki.wVk = vk;
|
|
227
|
+
inp.u.ki.dwFlags = KEYEVENTF_KEYUP;
|
|
228
|
+
return inp;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
static INPUT UnicodeDown(char c) {
|
|
232
|
+
var inp = new INPUT();
|
|
233
|
+
inp.type = INPUT_KEYBOARD;
|
|
234
|
+
inp.u.ki.wScan = (ushort)c;
|
|
235
|
+
inp.u.ki.dwFlags = KEYEVENTF_UNICODE;
|
|
236
|
+
return inp;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
static INPUT UnicodeUp(char c) {
|
|
240
|
+
var inp = new INPUT();
|
|
241
|
+
inp.type = INPUT_KEYBOARD;
|
|
242
|
+
inp.u.ki.wScan = (ushort)c;
|
|
243
|
+
inp.u.ki.dwFlags = KEYEVENTF_UNICODE | KEYEVENTF_KEYUP;
|
|
244
|
+
return inp;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
public static uint TypeUnicode(string text) {
|
|
248
|
+
var inputs = new INPUT[text.Length * 2];
|
|
249
|
+
for (int i = 0; i < text.Length; i++) {
|
|
250
|
+
inputs[i * 2] = UnicodeDown(text[i]);
|
|
251
|
+
inputs[i * 2 + 1] = UnicodeUp(text[i]);
|
|
252
|
+
}
|
|
253
|
+
return SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
public static uint TypeWithModRelease(string text) {
|
|
257
|
+
var inputs = new INPUT[text.Length * 2 + 4];
|
|
258
|
+
int idx = 0;
|
|
259
|
+
inputs[idx++] = KeyUp(VK_LCONTROL);
|
|
260
|
+
inputs[idx++] = KeyUp(VK_LMENU);
|
|
261
|
+
for (int i = 0; i < text.Length; i++) {
|
|
262
|
+
inputs[idx++] = UnicodeDown(text[i]);
|
|
263
|
+
inputs[idx++] = UnicodeUp(text[i]);
|
|
264
|
+
}
|
|
265
|
+
inputs[idx++] = KeyDown(VK_LCONTROL);
|
|
266
|
+
inputs[idx++] = KeyDown(VK_LMENU);
|
|
267
|
+
return SendInput((uint)idx, inputs, Marshal.SizeOf(typeof(INPUT)));
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// Replace last char: release mods → backspace → type new char (NO re-press).
|
|
271
|
+
// Used once (first animation frame) to transition from mods-held to mods-released.
|
|
272
|
+
public static uint ReplaceChar(char c) {
|
|
273
|
+
var inputs = new INPUT[6];
|
|
274
|
+
int idx = 0;
|
|
275
|
+
inputs[idx++] = KeyUp(VK_LCONTROL);
|
|
276
|
+
inputs[idx++] = KeyUp(VK_LMENU);
|
|
277
|
+
inputs[idx++] = KeyDown(VK_BACK);
|
|
278
|
+
inputs[idx++] = KeyUp(VK_BACK);
|
|
279
|
+
inputs[idx++] = UnicodeDown(c);
|
|
280
|
+
inputs[idx++] = UnicodeUp(c);
|
|
281
|
+
return SendInput((uint)idx, inputs, Marshal.SizeOf(typeof(INPUT)));
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// Simple replace: backspace + type new char (atomic). No modifier release.
|
|
285
|
+
// Used for animation frames after mods are already logically released.
|
|
286
|
+
public static uint SimpleReplace(char c) {
|
|
287
|
+
var inputs = new INPUT[4];
|
|
288
|
+
inputs[0] = KeyDown(VK_BACK);
|
|
289
|
+
inputs[1] = KeyUp(VK_BACK);
|
|
290
|
+
inputs[2] = UnicodeDown(c);
|
|
291
|
+
inputs[3] = UnicodeUp(c);
|
|
292
|
+
return SendInput(4, inputs, Marshal.SizeOf(typeof(INPUT)));
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
public static uint SendBackspaces(int count) {
|
|
296
|
+
var inputs = new INPUT[count * 2];
|
|
297
|
+
for (int i = 0; i < count; i++) {
|
|
298
|
+
inputs[i * 2] = KeyDown(VK_BACK);
|
|
299
|
+
inputs[i * 2 + 1] = KeyUp(VK_BACK);
|
|
300
|
+
}
|
|
301
|
+
return SendInput((uint)inputs.Length, inputs, Marshal.SizeOf(typeof(INPUT)));
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
public static uint SendBackspacesFull(int count) {
|
|
305
|
+
var inputs = new INPUT[count * 2 + 4];
|
|
306
|
+
int idx = 0;
|
|
307
|
+
inputs[idx++] = KeyUp(VK_LCONTROL);
|
|
308
|
+
inputs[idx++] = KeyUp(VK_LMENU);
|
|
309
|
+
for (int i = 0; i < count; i++) {
|
|
310
|
+
inputs[idx++] = KeyDown(VK_BACK);
|
|
311
|
+
inputs[idx++] = KeyUp(VK_BACK);
|
|
312
|
+
}
|
|
313
|
+
inputs[idx++] = KeyDown(VK_LCONTROL);
|
|
314
|
+
inputs[idx++] = KeyDown(VK_LMENU);
|
|
315
|
+
return SendInput((uint)idx, inputs, Marshal.SizeOf(typeof(INPUT)));
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
'@
|
|
319
|
+
|
|
320
|
+
$sz = [System.Runtime.InteropServices.Marshal]::SizeOf([type][TextInjector+INPUT])
|
|
321
|
+
[Console]::Error.WriteLine("TextInjector: C# compiled OK, sizeof(INPUT)=$sz")
|
|
322
|
+
[Console]::Out.WriteLine("READY")
|
|
323
|
+
[Console]::Out.Flush()
|
|
324
|
+
|
|
325
|
+
while ($true) {
|
|
326
|
+
$line = [Console]::In.ReadLine()
|
|
327
|
+
if ($line -eq $null -or $line -eq "exit") { break }
|
|
328
|
+
|
|
329
|
+
[Console]::Error.WriteLine("TextInjector: got cmd: $line")
|
|
330
|
+
if ($line.StartsWith("simpl:")) {
|
|
331
|
+
$r = [TextInjector]::SimpleReplace($line[6])
|
|
332
|
+
[Console]::Error.WriteLine("TextInjector: SimpleReplace result=$r")
|
|
333
|
+
}
|
|
334
|
+
elseif ($line.StartsWith("repl:")) {
|
|
335
|
+
$r = [TextInjector]::ReplaceChar($line[5])
|
|
336
|
+
[Console]::Error.WriteLine("TextInjector: ReplaceChar result=$r")
|
|
337
|
+
}
|
|
338
|
+
elseif ($line.StartsWith("type:")) {
|
|
339
|
+
$r = [TextInjector]::TypeUnicode($line.Substring(5))
|
|
340
|
+
[Console]::Error.WriteLine("TextInjector: TypeUnicode result=$r")
|
|
341
|
+
}
|
|
342
|
+
elseif ($line.StartsWith("typefull:")) {
|
|
343
|
+
$r = [TextInjector]::TypeWithModRelease($line.Substring(9))
|
|
344
|
+
[Console]::Error.WriteLine("TextInjector: TypeWithModRelease result=$r")
|
|
345
|
+
}
|
|
346
|
+
elseif ($line.StartsWith("unibs:")) {
|
|
347
|
+
$r = [TextInjector]::SendUnicodeBackspaces([int]$line.Substring(6))
|
|
348
|
+
[Console]::Error.WriteLine("TextInjector: SendUnicodeBackspaces result=$r")
|
|
349
|
+
}
|
|
350
|
+
elseif ($line.StartsWith("bsfull:")) {
|
|
351
|
+
$r = [TextInjector]::SendBackspacesFull([int]$line.Substring(7))
|
|
352
|
+
[Console]::Error.WriteLine("TextInjector: SendBackspacesFull result=$r")
|
|
353
|
+
}
|
|
354
|
+
elseif ($line.StartsWith("bs:")) {
|
|
355
|
+
$r = [TextInjector]::SendBackspaces([int]$line.Substring(3))
|
|
356
|
+
[Console]::Error.WriteLine("TextInjector: SendBackspaces result=$r")
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
`;
|
package/mcp-server/dist/index.js
CHANGED
|
@@ -456,7 +456,7 @@ async function startMcpServer(port = 47592, projectDir) {
|
|
|
456
456
|
server.tool('superbased_capture_image', {
|
|
457
457
|
mode: zod_1.z.enum(['fullscreen', 'region', 'active_window']).default('fullscreen').describe('Capture mode'),
|
|
458
458
|
resolution: zod_1.z.enum(['full', 'high', 'half', 'quarter', 'thumbnail']).default('half').describe('Image resolution (half saves ~4x tokens vs full)'),
|
|
459
|
-
window: zod_1.z.string().optional().describe('Capture a specific window by name substring'),
|
|
459
|
+
window: zod_1.z.string().optional().describe('Capture a specific window by name substring (use superbased_window_list to find names). Activates the window, captures, then restores focus. Works even on minimized windows.'),
|
|
460
460
|
x: zod_1.z.number().optional(), y: zod_1.z.number().optional(),
|
|
461
461
|
width: zod_1.z.number().optional(), height: zod_1.z.number().optional(),
|
|
462
462
|
}, async ({ mode, resolution, window: windowName, x, y, width, height }) => {
|
|
@@ -591,7 +591,7 @@ async function startMcpServer(port = 47592, projectDir) {
|
|
|
591
591
|
}
|
|
592
592
|
});
|
|
593
593
|
// ── Tool: superbased_window_list ──
|
|
594
|
-
server.tool('superbased_window_list', {}, async () => {
|
|
594
|
+
server.tool('superbased_window_list', 'List all visible windows with names, active status, and minimized state. Use window names with superbased_capture_image to target specific windows.', {}, async () => {
|
|
595
595
|
try {
|
|
596
596
|
const res = await client.listWindows();
|
|
597
597
|
return { content: [{ type: 'text', text: formatResponse(res.data) }] };
|
|
@@ -656,10 +656,10 @@ async function startMcpServer(port = 47592, projectDir) {
|
|
|
656
656
|
}
|
|
657
657
|
});
|
|
658
658
|
// ── Tool: superbased_dictate ──
|
|
659
|
-
server.tool('superbased_dictate', {
|
|
659
|
+
server.tool('superbased_dictate', 'Transcribe audio with text cleanup (filler removal, deduplication). Supports file input, base64, or live microphone recording.', {
|
|
660
660
|
audioPath: zod_1.z.string().optional().describe('Path to audio file to transcribe with text cleanup'),
|
|
661
661
|
audioBase64: zod_1.z.string().optional().describe('Base64-encoded audio data'),
|
|
662
|
-
mic: zod_1.z.boolean().optional().describe('Record from microphone (requires
|
|
662
|
+
mic: zod_1.z.boolean().optional().describe('Record from microphone (requires ffmpeg). Set to true to capture live audio.'),
|
|
663
663
|
duration: zod_1.z.number().optional().describe('Mic recording duration in seconds (default 10)'),
|
|
664
664
|
language: zod_1.z.string().optional().describe('BCP 47 language code'),
|
|
665
665
|
cleanup: zod_1.z.boolean().default(true).describe('Apply filler word removal and deduplication'),
|