llmtab-desktop 2.0.2 → 2.0.4

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 LLMTab contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -21,6 +21,29 @@ links the bins of the package you name:
21
21
  npm i -g llmtab llmtab-desktop
22
22
  ```
23
23
 
24
+ ## Running in the background
25
+
26
+ `llmtab-desktop` detaches from your terminal. The prompt comes straight back,
27
+ Ctrl-C does not kill the tray app, and closing the terminal leaves it running:
28
+
29
+ ```sh
30
+ llmtab-desktop
31
+ # llmtab-desktop: started in the background (pid 51234) · log: ~/.llmtab/desktop.log
32
+ ```
33
+
34
+ Quit it from the tray menu. Output goes to `~/.llmtab/desktop.log`
35
+ (`$LLMTAB_HOME/desktop.log` if you set that).
36
+
37
+ To keep it attached to the terminal instead — useful when debugging a crash on
38
+ startup — pass `--foreground`:
39
+
40
+ ```sh
41
+ llmtab-desktop --foreground # or -F
42
+ ```
43
+
44
+ Any other arguments are forwarded to Electron as-is; anything after `--` is
45
+ left for the app.
46
+
24
47
  ## Platform support
25
48
 
26
49
  | OS | status |
package/bin.mjs CHANGED
@@ -7,11 +7,16 @@
7
7
  * force on people who just want the CLI. We locate the installed `llmtab` via
8
8
  * normal Node resolution, so npm/pnpm/yarn layouts all work without guessing
9
9
  * at node_modules paths.
10
+ *
11
+ * The shell is a menu-bar app, so it detaches by default: the prompt comes
12
+ * straight back, Ctrl-C no longer kills it, and closing the terminal leaves it
13
+ * running. Pass --foreground (-F) to keep it attached for debugging.
10
14
  */
11
15
  import { createRequire } from "node:module";
12
16
  import { spawn } from "node:child_process";
13
- import { existsSync } from "node:fs";
17
+ import { existsSync, mkdirSync, openSync } from "node:fs";
14
18
  import path from "node:path";
19
+ import { logFilePath, parseArgs } from "./launcher.mjs";
15
20
 
16
21
  const require = createRequire(import.meta.url);
17
22
 
@@ -59,12 +64,44 @@ function resolveElectron() {
59
64
  return electronPath;
60
65
  }
61
66
 
62
- const child = spawn(resolveElectron(), [resolveShellEntry(), ...process.argv.slice(2)], {
63
- stdio: "inherit",
64
- });
67
+ /**
68
+ * Opens the detached shell's log in append mode, creating the state dir if the
69
+ * CLI has never run. A log we cannot open is not worth aborting the launch for
70
+ * — the app matters more than its diagnostics — so fall back to discarding.
71
+ */
72
+ function openLog() {
73
+ const file = logFilePath();
74
+ try {
75
+ mkdirSync(path.dirname(file), { recursive: true });
76
+ return { fd: openSync(file, "a"), file };
77
+ } catch {
78
+ return { fd: "ignore", file: null };
79
+ }
80
+ }
65
81
 
66
- child.on("error", (err) => die(`failed to launch Electron: ${err.message}`));
67
- child.on("exit", (code, signal) => {
68
- if (signal) process.kill(process.pid, signal);
69
- else process.exit(code ?? 0);
70
- });
82
+ const { foreground, forward } = parseArgs(process.argv.slice(2));
83
+ const args = [resolveShellEntry(), ...forward];
84
+ const electron = resolveElectron();
85
+
86
+ if (foreground) {
87
+ const child = spawn(electron, args, { stdio: "inherit" });
88
+ child.on("error", (err) => die(`failed to launch Electron: ${err.message}`));
89
+ child.on("exit", (code, signal) => {
90
+ if (signal) process.kill(process.pid, signal);
91
+ else process.exit(code ?? 0);
92
+ });
93
+ } else {
94
+ // `detached` puts the shell in its own process group, so the terminal's
95
+ // Ctrl-C (SIGINT to the foreground group) and its SIGHUP on close no longer
96
+ // reach it. Redirecting stdio frees the prompt; unref lets us exit first.
97
+ const { fd, file } = openLog();
98
+ const child = spawn(electron, args, {
99
+ detached: true,
100
+ stdio: ["ignore", fd, fd],
101
+ });
102
+ child.on("error", (err) => die(`failed to launch Electron: ${err.message}`));
103
+ child.unref();
104
+ const where = file ? ` · log: ${file}` : "";
105
+ console.log(`llmtab-desktop: started in the background (pid ${child.pid})${where}`);
106
+ console.log(" stop it from the tray menu; run with --foreground to keep it attached.");
107
+ }
package/launcher.mjs ADDED
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Pure launcher decisions for `llmtab-desktop`, split out of bin.mjs so they
3
+ * can be tested without spawning Electron.
4
+ */
5
+ import os from "node:os";
6
+ import path from "node:path";
7
+
8
+ /**
9
+ * Splits our own flags from the ones Electron should receive.
10
+ *
11
+ * A menu-bar app that holds the terminal hostage is a bug, so detaching is the
12
+ * default and `--foreground` is the escape hatch for debugging. Everything else
13
+ * is forwarded verbatim; anything after `--` belongs to the app, so a
14
+ * `--foreground` there is passed through rather than consumed.
15
+ */
16
+ export function parseArgs(argv) {
17
+ const forward = [];
18
+ let foreground = false;
19
+ let appArgs = false;
20
+ for (const arg of argv) {
21
+ if (appArgs) {
22
+ forward.push(arg);
23
+ continue;
24
+ }
25
+ if (arg === "--") {
26
+ appArgs = true;
27
+ forward.push(arg);
28
+ continue;
29
+ }
30
+ if (arg === "--foreground" || arg === "-F") {
31
+ foreground = true;
32
+ continue;
33
+ }
34
+ forward.push(arg);
35
+ }
36
+ return { foreground, forward };
37
+ }
38
+
39
+ /** Base state dir, mirroring src/shared/paths.ts (LLMTAB_HOME overrides). */
40
+ export function stateHome(env = process.env, home = os.homedir()) {
41
+ return env.LLMTAB_HOME ?? path.join(home, ".llmtab");
42
+ }
43
+
44
+ /** Where a detached shell's stdout/stderr are appended. */
45
+ export function logFilePath(env = process.env, home = os.homedir()) {
46
+ return path.join(stateHome(env, home), "desktop.log");
47
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "llmtab-desktop",
3
- "version": "2.0.2",
4
- "description": "Menu-bar / tray app for LLMTab adds the Electron shell to the llmtab CLI.",
3
+ "version": "2.0.4",
4
+ "description": "Menu-bar / tray app for LLMTab \u2014 adds the Electron shell to the llmtab CLI.",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "author": "naninanides",
@@ -33,10 +33,12 @@
33
33
  },
34
34
  "files": [
35
35
  "bin.mjs",
36
+ "launcher.mjs",
37
+ "LICENSE",
36
38
  "README.md"
37
39
  ],
38
40
  "dependencies": {
39
41
  "electron": "^44.0.0",
40
- "llmtab": "^2.0.1"
42
+ "llmtab": "^2.0.2"
41
43
  }
42
- }
44
+ }