@xerktech/claude-hud 0.1.31 → 0.1.33

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.
@@ -1,185 +0,0 @@
1
- import { spawn as defaultSpawn } from 'node:child_process';
2
- import { mkdtempSync, writeFileSync } from 'node:fs';
3
- import { tmpdir } from 'node:os';
4
- import { join } from 'node:path';
5
- /**
6
- * Cross-platform detached-terminal launcher. Dispatches on `process.platform`:
7
- *
8
- * - **Windows** (`win32`): tries `wt new-tab` first, falls back to a
9
- * `Start-Process powershell` shell-out on ENOENT or any spawn failure.
10
- * - **macOS** (`darwin`): drives Terminal.app via `osascript`. Fails loudly
11
- * if osascript spawn throws — the glasses launching screen surfaces the
12
- * error and the user can tap-to-retry.
13
- * - **Linux** (`linux`): silent detached spawn of `claude-hud`. No GUI
14
- * probing — headless servers, WSL, and minimal desktops are the common
15
- * case in this product. The wrapper still attaches to the broker over
16
- * HTTP/WS so the session is reachable from the glasses; the user just
17
- * lacks a PC-side terminal window.
18
- *
19
- * Every path throws `terminal-launch-failed: <detail>` on failure so the
20
- * routes layer can return HTTP 500 with a uniform error shape.
21
- *
22
- * The spawned process inherits `opts.env` — the wrapper inside reads
23
- * `CLAUDE_HUD_PENDING_ID` to correlate its attached-registration POST with
24
- * the pending spawn record the broker is holding.
25
- */
26
- export async function launchTerminal(opts) {
27
- switch (process.platform) {
28
- case 'win32':
29
- return launchWindows(opts);
30
- case 'darwin':
31
- return launchDarwin(opts);
32
- case 'linux':
33
- return launchLinux(opts);
34
- default:
35
- throw new Error(`terminal-launch-failed: unsupported platform ${process.platform}`);
36
- }
37
- }
38
- function resolveSpawnImpl(opts) {
39
- return (opts.spawnImpl ??
40
- ((cmd, args, options) => {
41
- const child = defaultSpawn(cmd, args, options);
42
- return { pid: child.pid, unref: () => child.unref() };
43
- }));
44
- }
45
- async function launchWindows(opts) {
46
- const spawnImpl = resolveSpawnImpl(opts);
47
- const env = { ...process.env, ...opts.env };
48
- const extra = opts.extraArgs ?? [];
49
- // wt new-tab is a layered-parsing nightmare for command bodies that contain
50
- // `;` or `$env:` assignments:
51
- // - wt's CLI parser treats `;` as a subcommand separator (escape with \;).
52
- // - wt does NOT inherit env vars from the wt CLI invocation; the new tab
53
- // uses the wt server process's env (captured at first wt launch).
54
- // - Node child_process.spawn quotes argv on Windows in a way that often
55
- // mangles backslashes inside the -Command body.
56
- // Instead of fighting all three, write a small .ps1 script to a temp file
57
- // that (a) sets the spawn-correlation env vars and (b) invokes claude-hud,
58
- // then have powershell run that file via -File. -File takes a single path
59
- // and doesn't have the -Command quoting issues.
60
- const scriptPath = writePsLaunchScript(opts);
61
- // Attempt 1: Windows Terminal.
62
- try {
63
- const child = spawnImpl('wt', [
64
- 'new-tab',
65
- '--startingDirectory',
66
- opts.cwd,
67
- '--title',
68
- opts.label,
69
- 'powershell',
70
- '-NoExit',
71
- '-ExecutionPolicy',
72
- 'Bypass',
73
- '-File',
74
- scriptPath,
75
- ], { detached: true, stdio: 'ignore', env });
76
- child.unref();
77
- return;
78
- }
79
- catch (err) {
80
- const code = err.code;
81
- if (code !== 'ENOENT' && !/not found|not recognized/i.test(err.message)) {
82
- console.warn(`[terminal] wt launch failed: ${err.message}`);
83
- }
84
- }
85
- // Attempt 2: PowerShell Start-Process fallback. Uses the same temp script.
86
- const psTokens = [
87
- "'-NoExit'",
88
- "'-ExecutionPolicy'",
89
- "'Bypass'",
90
- "'-File'",
91
- `'${scriptPath.replace(/'/g, "''")}'`,
92
- ].join(',');
93
- try {
94
- const child = spawnImpl('powershell', [
95
- '-NoProfile',
96
- '-Command',
97
- `Start-Process powershell -ArgumentList ${psTokens} -WorkingDirectory ${quoteShellArg(opts.cwd)}`,
98
- ], { detached: true, stdio: 'ignore', env });
99
- child.unref();
100
- return;
101
- }
102
- catch (err) {
103
- throw new Error(`terminal-launch-failed: ${err.message}`);
104
- }
105
- // Note: extraArgs is still referenced in writePsLaunchScript below; this
106
- // void-ref keeps the linter happy on the rare path where neither attempt
107
- // runs (both throws are propagated above).
108
- void extra;
109
- }
110
- /**
111
- * Write a small .ps1 to %TEMP% that sets the spawn-correlation env vars and
112
- * then runs `claude-hud <extraArgs>`. PowerShell `-File` invokes it cleanly
113
- * without any of the `-Command` quoting / wt `;`-splitting hazards.
114
- */
115
- function writePsLaunchScript(opts) {
116
- const lines = [];
117
- for (const [k, v] of Object.entries(opts.env ?? {})) {
118
- // PowerShell single-quoted strings: `'` is escaped by doubling.
119
- lines.push(`$env:${k} = '${String(v).replace(/'/g, "''")}'`);
120
- }
121
- const cmdParts = ['claude-hud', ...(opts.extraArgs ?? [])];
122
- lines.push(cmdParts.join(' '));
123
- const body = lines.join('\r\n') + '\r\n';
124
- const dir = mkdtempSync(join(tmpdir(), 'claude-hud-launch-'));
125
- const scriptPath = join(dir, 'launch.ps1');
126
- writeFileSync(scriptPath, body, 'utf8');
127
- return scriptPath;
128
- }
129
- async function launchDarwin(opts) {
130
- const spawnImpl = resolveSpawnImpl(opts);
131
- const env = { ...process.env, ...opts.env };
132
- // `do script` body is run in the new Terminal tab's shell. Quote every
133
- // token so paths/args with spaces survive. Embedded single quotes in the
134
- // cwd are escaped via the standard close-escape-quote-open trick inside
135
- // quoteShellArg().
136
- const cmd = ['claude-hud', ...(opts.extraArgs ?? [])].map(quoteShellArg).join(' ');
137
- const script = `tell application "Terminal"
138
- activate
139
- do script "cd ${quoteShellArg(opts.cwd)} && ${cmd}"
140
- end tell`;
141
- try {
142
- const child = spawnImpl('osascript', ['-e', script], {
143
- detached: true,
144
- stdio: 'ignore',
145
- env,
146
- });
147
- child.unref();
148
- return;
149
- }
150
- catch (err) {
151
- throw new Error(`terminal-launch-failed: ${err.message}`);
152
- }
153
- }
154
- async function launchLinux(opts) {
155
- const spawnImpl = resolveSpawnImpl(opts);
156
- const env = { ...process.env, ...opts.env };
157
- try {
158
- const child = spawnImpl('claude-hud', opts.extraArgs ?? [], {
159
- detached: true,
160
- stdio: 'ignore',
161
- cwd: opts.cwd,
162
- env,
163
- });
164
- child.unref();
165
- return;
166
- }
167
- catch (err) {
168
- const code = err.code;
169
- if (code === 'ENOENT') {
170
- throw new Error('terminal-launch-failed: claude-hud not found on PATH');
171
- }
172
- throw new Error(`terminal-launch-failed: ${err.message}`);
173
- }
174
- }
175
- /**
176
- * POSIX-shell single-quote escape: wrap `s` in single quotes and escape any
177
- * embedded single quote via the standard close-escape-quote-open sequence
178
- * (`'\''`). Safe for use inside both an osascript `do script` body (where
179
- * the inner shell parses the quotes) and a PowerShell `-WorkingDirectory`
180
- * argument (which uses POSIX-style single-quote rules on Windows too).
181
- */
182
- function quoteShellArg(s) {
183
- return `'${s.replace(/'/g, "'\\''")}'`;
184
- }
185
- //# sourceMappingURL=terminal.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"terminal.js","sourceRoot":"","sources":["../src/terminal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,YAAY,EAAqB,MAAM,oBAAoB,CAAA;AAC7E,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAuBhC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,IAA2B;IAC9D,QAAQ,OAAO,CAAC,QAAQ,EAAE,CAAC;QACzB,KAAK,OAAO;YACV,OAAO,aAAa,CAAC,IAAI,CAAC,CAAA;QAC5B,KAAK,QAAQ;YACX,OAAO,YAAY,CAAC,IAAI,CAAC,CAAA;QAC3B,KAAK,OAAO;YACV,OAAO,WAAW,CAAC,IAAI,CAAC,CAAA;QAC1B;YACE,MAAM,IAAI,KAAK,CAAC,gDAAgD,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAA;IACvF,CAAC;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,IAA2B;IACnD,OAAO,C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