omnikey-cli 1.6.2 → 1.6.3

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.
@@ -9,10 +9,10 @@ const zod_1 = __importDefault(require("zod"));
9
9
  const fs_1 = __importDefault(require("fs"));
10
10
  const path_1 = __importDefault(require("path"));
11
11
  const os_1 = __importDefault(require("os"));
12
+ const child_process_1 = require("child_process");
12
13
  const authMiddleware_1 = require("./authMiddleware");
13
14
  const config_1 = require("./config");
14
15
  const logger_1 = require("./logger");
15
- const scheduledJobExecutor_1 = require("./scheduledJobExecutor");
16
16
  const providerEnum = zod_1.default.enum(['openai', 'anthropic', 'gemini', 'nemotron']);
17
17
  const putSchema = zod_1.default.object({
18
18
  apiKey: zod_1.default.string().min(1).max(4096),
@@ -100,48 +100,31 @@ function readActiveProvider(cfg) {
100
100
  return config_1.config.aiProvider;
101
101
  }
102
102
  /**
103
- * Triggers a daemon restart by handing off to the shared `runScript` helper
104
- * (the same one used by the scheduled-job executor). The script invokes the
105
- * `omnikey restart-daemon --port <port>` CLI, which tears down the
106
- * launchd / NSSM persistence agent and brings a fresh daemon back up on the
107
- * same port picking up the rewritten config.json values from env on the
108
- * way up.
103
+ * Triggers a daemon restart by spawning a detached `omnikey restart-daemon`
104
+ * process. Using spawn with detached:true + unref() instead of a shell script
105
+ * avoids PATH lookup failures when the daemon runs under launchd/NSSM (which
106
+ * provide a minimal environment). We resolve the CLI path relative to
107
+ * __dirname so it works regardless of PATH.
109
108
  *
110
- * Important: `omnikey restart-daemon` calls `killDaemon()` first, which kills
111
- * *this* Node process. To survive that, we wrap the call in `nohup ... &`
112
- * with stdio redirected to a log file and `disown` so the actual
113
- * `omnikey restart-daemon` invocation escapes the shell's process tree
114
- * before this process is terminated. `runScript` is fire-and-forget: we do
115
- * not await it because we expect to be killed before it returns.
109
+ * The API server lives in cli/backend-dist/ and the omnikey CLI lives in
110
+ * cli/dist/, so path.resolve(__dirname, '../dist/index.js') is always valid.
116
111
  */
117
112
  function scheduleDaemonRestart(reason) {
118
113
  setTimeout(() => {
119
114
  const port = config_1.config.port;
120
115
  const logFile = path_1.default.join(process.env.HOME || os_1.default.homedir(), '.omnikey', 'restart-daemon.log');
121
- const script = [
122
- '#!/usr/bin/env bash',
123
- 'set -u',
124
- `mkdir -p "$(dirname "${logFile}")"`,
125
- `echo "[$(date -Iseconds)] restart-daemon triggered: ${reason}" >> "${logFile}"`,
126
- // Detach the actual restart so it survives this daemon's imminent death.
127
- `nohup omnikey restart-daemon --port ${port} >> "${logFile}" 2>&1 &`,
128
- 'disown || true',
129
- 'exit 0',
130
- ].join('\n');
131
- logger_1.logger.info(`Running \`omnikey restart-daemon --port ${port}\` via runScript (${reason})`);
132
- // Fire-and-forget: we expect `omnikey restart-daemon` to kill this process
133
- // long before runScript's exec promise resolves.
134
- void (0, scheduledJobExecutor_1.runScript)(script)
135
- .then((result) => {
136
- if (result.isError) {
137
- logger_1.logger.error('runScript reported a non-zero exit for restart-daemon.', {
138
- output: result.output,
139
- });
140
- }
141
- })
142
- .catch((err) => {
143
- logger_1.logger.error('Unexpected runScript failure while restarting daemon.', { error: err });
144
- });
116
+ const omnikeyCli = path_1.default.resolve(__dirname, '../dist/index.js');
117
+ logger_1.logger.info(`Spawning detached \`omnikey restart-daemon --port ${port}\` (${reason})`);
118
+ try {
119
+ fs_1.default.mkdirSync(path_1.default.dirname(logFile), { recursive: true });
120
+ const out = fs_1.default.openSync(logFile, 'a');
121
+ const child = (0, child_process_1.spawn)(process.execPath, [omnikeyCli, 'restart-daemon', '--port', String(port)], { detached: true, stdio: ['ignore', out, out] });
122
+ child.unref();
123
+ fs_1.default.closeSync(out);
124
+ }
125
+ catch (err) {
126
+ logger_1.logger.error('Failed to spawn restart-daemon process.', { error: err });
127
+ }
145
128
  }, 500);
146
129
  }
147
130
  function aiProviderRouter() {
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public",
5
5
  "registry": "https://registry.npmjs.org/"
6
6
  },
7
- "version": "1.6.2",
7
+ "version": "1.6.3",
8
8
  "description": "CLI for onboarding users to Omnikey AI and configuring OPENAI_API_KEY. Use Yarn for install/build.",
9
9
  "engines": {
10
10
  "node": ">=14.0.0",