omnikey-cli 1.0.9 → 1.0.11

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/dist/index.js CHANGED
@@ -52,8 +52,10 @@ program
52
52
  .command('logs')
53
53
  .description('Show logs of the running Omnikey daemon')
54
54
  .option('--lines <lines>', 'Number of log lines to show', '50')
55
+ .option('--errors', 'Show only error logs')
55
56
  .action((options) => {
56
57
  const lines = Number(options.lines) || 50;
57
- (0, showLogs_1.showLogs)(lines);
58
+ const errorsOnly = !!options.errors;
59
+ (0, showLogs_1.showLogs)(lines, errorsOnly);
58
60
  });
59
61
  program.parseAsync(process.argv);
@@ -2,31 +2,42 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.killDaemon = killDaemon;
4
4
  const child_process_1 = require("child_process");
5
+ const removeConfig_1 = require("./removeConfig");
5
6
  /**
6
7
  * Kill the Omnikey API backend daemon running on a given port (default 7071).
7
8
  * Looks for node processes running backend-dist/index.js on the specified port and kills them.
8
9
  * @param port The port to look for (default 7071)
9
10
  */
10
11
  function killDaemon(port = 7071) {
12
+ // 1. Unload/kill the launchd agent first
11
13
  try {
12
- // Find the PID(s) of node processes running backend-dist/index.js on the given port
13
- // macOS: lsof -i :PORT -t
14
- const pids = (0, child_process_1.execSync)(`lsof -i :${port} -t`).toString().split('\n').filter(Boolean);
15
- if (pids.length === 0) {
16
- console.log(`No daemon found running on port ${port}.`);
17
- return;
18
- }
19
- for (const pid of pids) {
20
- try {
21
- process.kill(Number(pid), 'SIGTERM');
22
- console.log(`Killed daemon process with PID ${pid} on port ${port}.`);
23
- }
24
- catch (e) {
25
- console.error(`Failed to kill process ${pid}:`, e);
26
- }
27
- }
14
+ (0, removeConfig_1.killLaunchdAgent)();
15
+ console.log('Launchd agent unloaded (if it existed).');
16
+ }
17
+ catch (e) {
18
+ console.warn('Failed to unload launchd agent or agent did not exist:', e);
19
+ }
20
+ // 2. Check if the port is still in use
21
+ let pids = [];
22
+ try {
23
+ pids = (0, child_process_1.execSync)(`lsof -i :${port} -t`).toString().split('\n').filter(Boolean);
28
24
  }
29
25
  catch (e) {
30
- console.log(`No daemon found running on port ${port}.`);
26
+ // lsof returns non-zero exit code if nothing is using the port
27
+ pids = [];
28
+ }
29
+ if (pids.length === 0) {
30
+ console.log(`No process found using port ${port} after unloading launchd agent.`);
31
+ return;
32
+ }
33
+ // 3. If the port is still occupied, kill the process using the port
34
+ for (const pid of pids) {
35
+ try {
36
+ process.kill(Number(pid), 'SIGTERM');
37
+ console.log(`Killed process with PID ${pid} using port ${port}.`);
38
+ }
39
+ catch (e) {
40
+ console.error(`Failed to kill process ${pid}:`, e);
41
+ }
31
42
  }
32
43
  }
@@ -3,11 +3,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.killLaunchdAgent = killLaunchdAgent;
6
7
  exports.removeConfigAndDb = removeConfigAndDb;
7
8
  const fs_1 = __importDefault(require("fs"));
8
9
  const path_1 = __importDefault(require("path"));
9
10
  const os_1 = __importDefault(require("os"));
10
11
  const child_process_1 = require("child_process");
12
+ function killLaunchdAgent() {
13
+ const homeDir = process.env.HOME || process.env.USERPROFILE || os_1.default.homedir();
14
+ const plistName = 'com.omnikey.daemon.plist';
15
+ const plistPath = path_1.default.join(homeDir, 'Library', 'LaunchAgents', plistName);
16
+ if (fs_1.default.existsSync(plistPath)) {
17
+ try {
18
+ (0, child_process_1.execSync)(`launchctl unload "${plistPath}"`);
19
+ fs_1.default.rmSync(plistPath);
20
+ console.log(`Removed launchd agent: ${plistPath}`);
21
+ }
22
+ catch (e) {
23
+ console.error(`Failed to remove launchd agent: ${e}`);
24
+ }
25
+ }
26
+ else {
27
+ console.log(`Launchd agent does not exist: ${plistPath}`);
28
+ }
29
+ }
11
30
  /**
12
31
  * Removes the ~/.omnikey config directory and the SQLite database file specified in config.json.
13
32
  */
@@ -31,21 +50,7 @@ function removeConfigAndDb() {
31
50
  }
32
51
  }
33
52
  // Remove launchd agent if exists (macOS)
34
- const plistName = 'com.omnikey.daemon.plist';
35
- const plistPath = path_1.default.join(homeDir, 'Library', 'LaunchAgents', plistName);
36
- if (fs_1.default.existsSync(plistPath)) {
37
- try {
38
- (0, child_process_1.execSync)(`launchctl unload "${plistPath}"`);
39
- fs_1.default.rmSync(plistPath);
40
- console.log(`Removed launchd agent: ${plistPath}`);
41
- }
42
- catch (e) {
43
- console.error(`Failed to remove launchd agent: ${e}`);
44
- }
45
- }
46
- else {
47
- console.log(`Launchd agent does not exist: ${plistPath}`);
48
- }
53
+ killLaunchdAgent();
49
54
  // Remove SQLite database
50
55
  if (fs_1.default.existsSync(sqlitePath)) {
51
56
  try {
package/dist/showLogs.js CHANGED
@@ -9,40 +9,24 @@ const path_1 = __importDefault(require("path"));
9
9
  /**
10
10
  * Show the logs of the running Omnikey daemon by printing the contents of the daemon log file.
11
11
  * Prints the last N lines (default 50) for convenience.
12
+ * If errorsOnly is true, shows daemon-error.log instead.
12
13
  */
13
- function showLogs(lines = 50) {
14
+ function showLogs(lines = 50, errorsOnly = false) {
14
15
  const homeDir = process.env.HOME || process.env.USERPROFILE || '.';
15
16
  const configDir = path_1.default.join(homeDir, '.omnikey');
16
- const logPath = path_1.default.join(configDir, 'daemon.log');
17
- const errorLogPath = path_1.default.join(configDir, 'daemon-error.log');
18
- let logLines = [];
19
- let errorLines = [];
20
- if (fs_1.default.existsSync(logPath)) {
21
- const logContent = fs_1.default.readFileSync(logPath, 'utf-8');
22
- logLines = logContent.split('\n');
23
- }
24
- if (fs_1.default.existsSync(errorLogPath)) {
25
- const errorContent = fs_1.default.readFileSync(errorLogPath, 'utf-8');
26
- errorLines = errorContent.split('\n');
27
- }
28
- if (logLines.length === 0 && errorLines.length === 0) {
29
- console.log('No daemon.log or daemon-error.log file found.');
17
+ const logPath = path_1.default.join(configDir, errorsOnly ? 'daemon-error.log' : 'daemon.log');
18
+ if (!fs_1.default.existsSync(logPath)) {
19
+ console.log(errorsOnly ? 'No error logs found.' : 'No daemon logs found.');
30
20
  return;
31
21
  }
32
- const left = logLines.slice(-lines);
33
- const right = errorLines.slice(-lines);
34
- // Calculate column widths
35
- const leftWidth = Math.max(40, ...left.map((l) => l.length));
36
- const rightWidth = Math.max(40, ...right.map((l) => l.length));
37
- // Print header
38
- const leftHeader = 'Other Logs'.padEnd(leftWidth);
39
- const rightHeader = 'Errors'.padEnd(rightWidth);
40
- console.log(`${leftHeader} | ${rightHeader}`);
41
- console.log('-'.repeat(leftWidth) + '-+-' + '-'.repeat(rightWidth));
42
- // Print lines side by side
43
- for (let i = 0; i < lines; i++) {
44
- const l = left[i] !== undefined ? left[i] : '';
45
- const r = right[i] !== undefined ? right[i] : '';
46
- console.log(l.padEnd(leftWidth) + ' | ' + r.padEnd(rightWidth));
22
+ const logContent = fs_1.default.readFileSync(logPath, 'utf-8');
23
+ const logLines = logContent.split('\n');
24
+ const lastLines = logLines.slice(-lines);
25
+ if (errorsOnly) {
26
+ console.log('--- Error Logs ---');
27
+ }
28
+ else {
29
+ console.log('--- Daemon Logs ---');
47
30
  }
31
+ lastLines.forEach((line) => console.log(line));
48
32
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "access": "public",
5
5
  "registry": "https://registry.npmjs.org/"
6
6
  },
7
- "version": "1.0.9",
7
+ "version": "1.0.11",
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",
package/src/index.ts CHANGED
@@ -61,9 +61,11 @@ program
61
61
  .command('logs')
62
62
  .description('Show logs of the running Omnikey daemon')
63
63
  .option('--lines <lines>', 'Number of log lines to show', '50')
64
+ .option('--errors', 'Show only error logs')
64
65
  .action((options) => {
65
66
  const lines = Number(options.lines) || 50;
66
- showLogs(lines);
67
+ const errorsOnly = !!options.errors;
68
+ showLogs(lines, errorsOnly);
67
69
  });
68
70
 
69
71
  program.parseAsync(process.argv);
package/src/killDaemon.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { execSync } from 'child_process';
2
+ import { killLaunchdAgent } from './removeConfig';
2
3
 
3
4
  /**
4
5
  * Kill the Omnikey API backend daemon running on a given port (default 7071).
@@ -6,23 +7,35 @@ import { execSync } from 'child_process';
6
7
  * @param port The port to look for (default 7071)
7
8
  */
8
9
  export function killDaemon(port: number = 7071) {
10
+ // 1. Unload/kill the launchd agent first
9
11
  try {
10
- // Find the PID(s) of node processes running backend-dist/index.js on the given port
11
- // macOS: lsof -i :PORT -t
12
- const pids = execSync(`lsof -i :${port} -t`).toString().split('\n').filter(Boolean);
13
- if (pids.length === 0) {
14
- console.log(`No daemon found running on port ${port}.`);
15
- return;
16
- }
17
- for (const pid of pids) {
18
- try {
19
- process.kill(Number(pid), 'SIGTERM');
20
- console.log(`Killed daemon process with PID ${pid} on port ${port}.`);
21
- } catch (e) {
22
- console.error(`Failed to kill process ${pid}:`, e);
23
- }
24
- }
12
+ killLaunchdAgent();
13
+ console.log('Launchd agent unloaded (if it existed).');
14
+ } catch (e) {
15
+ console.warn('Failed to unload launchd agent or agent did not exist:', e);
16
+ }
17
+
18
+ // 2. Check if the port is still in use
19
+ let pids: string[] = [];
20
+ try {
21
+ pids = execSync(`lsof -i :${port} -t`).toString().split('\n').filter(Boolean);
25
22
  } catch (e) {
26
- console.log(`No daemon found running on port ${port}.`);
23
+ // lsof returns non-zero exit code if nothing is using the port
24
+ pids = [];
25
+ }
26
+
27
+ if (pids.length === 0) {
28
+ console.log(`No process found using port ${port} after unloading launchd agent.`);
29
+ return;
30
+ }
31
+
32
+ // 3. If the port is still occupied, kill the process using the port
33
+ for (const pid of pids) {
34
+ try {
35
+ process.kill(Number(pid), 'SIGTERM');
36
+ console.log(`Killed process with PID ${pid} using port ${port}.`);
37
+ } catch (e) {
38
+ console.error(`Failed to kill process ${pid}:`, e);
39
+ }
27
40
  }
28
41
  }
@@ -3,6 +3,23 @@ import path from 'path';
3
3
  import os from 'os';
4
4
  import { execSync } from 'child_process';
5
5
 
6
+ export function killLaunchdAgent() {
7
+ const homeDir = process.env.HOME || process.env.USERPROFILE || os.homedir();
8
+ const plistName = 'com.omnikey.daemon.plist';
9
+ const plistPath = path.join(homeDir, 'Library', 'LaunchAgents', plistName);
10
+ if (fs.existsSync(plistPath)) {
11
+ try {
12
+ execSync(`launchctl unload "${plistPath}"`);
13
+ fs.rmSync(plistPath);
14
+ console.log(`Removed launchd agent: ${plistPath}`);
15
+ } catch (e) {
16
+ console.error(`Failed to remove launchd agent: ${e}`);
17
+ }
18
+ } else {
19
+ console.log(`Launchd agent does not exist: ${plistPath}`);
20
+ }
21
+ }
22
+
6
23
  /**
7
24
  * Removes the ~/.omnikey config directory and the SQLite database file specified in config.json.
8
25
  */
@@ -27,19 +44,7 @@ export function removeConfigAndDb() {
27
44
  }
28
45
 
29
46
  // Remove launchd agent if exists (macOS)
30
- const plistName = 'com.omnikey.daemon.plist';
31
- const plistPath = path.join(homeDir, 'Library', 'LaunchAgents', plistName);
32
- if (fs.existsSync(plistPath)) {
33
- try {
34
- execSync(`launchctl unload "${plistPath}"`);
35
- fs.rmSync(plistPath);
36
- console.log(`Removed launchd agent: ${plistPath}`);
37
- } catch (e) {
38
- console.error(`Failed to remove launchd agent: ${e}`);
39
- }
40
- } else {
41
- console.log(`Launchd agent does not exist: ${plistPath}`);
42
- }
47
+ killLaunchdAgent();
43
48
 
44
49
  // Remove SQLite database
45
50
  if (fs.existsSync(sqlitePath)) {
package/src/showLogs.ts CHANGED
@@ -4,46 +4,25 @@ import path from 'path';
4
4
  /**
5
5
  * Show the logs of the running Omnikey daemon by printing the contents of the daemon log file.
6
6
  * Prints the last N lines (default 50) for convenience.
7
+ * If errorsOnly is true, shows daemon-error.log instead.
7
8
  */
8
- export function showLogs(lines: number = 50) {
9
+ export function showLogs(lines: number = 50, errorsOnly: boolean = false) {
9
10
  const homeDir = process.env.HOME || process.env.USERPROFILE || '.';
10
11
  const configDir = path.join(homeDir, '.omnikey');
11
- const logPath = path.join(configDir, 'daemon.log');
12
- const errorLogPath = path.join(configDir, 'daemon-error.log');
12
+ const logPath = path.join(configDir, errorsOnly ? 'daemon-error.log' : 'daemon.log');
13
13
 
14
- let logLines: string[] = [];
15
- let errorLines: string[] = [];
16
- if (fs.existsSync(logPath)) {
17
- const logContent = fs.readFileSync(logPath, 'utf-8');
18
- logLines = logContent.split('\n');
19
- }
20
- if (fs.existsSync(errorLogPath)) {
21
- const errorContent = fs.readFileSync(errorLogPath, 'utf-8');
22
- errorLines = errorContent.split('\n');
23
- }
24
-
25
- if (logLines.length === 0 && errorLines.length === 0) {
26
- console.log('No daemon.log or daemon-error.log file found.');
14
+ if (!fs.existsSync(logPath)) {
15
+ console.log(errorsOnly ? 'No error logs found.' : 'No daemon logs found.');
27
16
  return;
28
17
  }
29
18
 
30
- const left = logLines.slice(-lines);
31
- const right = errorLines.slice(-lines);
32
-
33
- // Calculate column widths
34
- const leftWidth = Math.max(40, ...left.map((l) => l.length));
35
- const rightWidth = Math.max(40, ...right.map((l) => l.length));
36
-
37
- // Print header
38
- const leftHeader = 'Other Logs'.padEnd(leftWidth);
39
- const rightHeader = 'Errors'.padEnd(rightWidth);
40
- console.log(`${leftHeader} | ${rightHeader}`);
41
- console.log('-'.repeat(leftWidth) + '-+-' + '-'.repeat(rightWidth));
42
-
43
- // Print lines side by side
44
- for (let i = 0; i < lines; i++) {
45
- const l = left[i] !== undefined ? left[i] : '';
46
- const r = right[i] !== undefined ? right[i] : '';
47
- console.log(l.padEnd(leftWidth) + ' | ' + r.padEnd(rightWidth));
19
+ const logContent = fs.readFileSync(logPath, 'utf-8');
20
+ const logLines = logContent.split('\n');
21
+ const lastLines = logLines.slice(-lines);
22
+ if (errorsOnly) {
23
+ console.log('--- Error Logs ---');
24
+ } else {
25
+ console.log('--- Daemon Logs ---');
48
26
  }
27
+ lastLines.forEach((line) => console.log(line));
49
28
  }