omnikey-cli 1.0.16 → 1.0.18

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,6 +1,6 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
- import { execSync } from 'child_process';
3
+ import { execSync, execFileSync } from 'child_process';
4
4
  import { isWindows, getHomeDir, getConfigDir, readConfig } from './utils';
5
5
 
6
6
  export function killLaunchdAgent() {
@@ -20,28 +20,38 @@ export function killLaunchdAgent() {
20
20
  }
21
21
 
22
22
  export function killWindowsTask() {
23
- const taskName = 'OmnikeyDaemon';
24
- try {
25
- execSync(`schtasks /end /tn "${taskName}"`, { stdio: 'pipe' });
26
- } catch {
27
- // Task may not be running — that's fine
28
- }
23
+ const serviceName = 'OmnikeyDaemon';
24
+
25
+ // Try NSSM first (current implementation)
26
+ let nssmPath: string | null = null;
29
27
  try {
30
- execSync(`schtasks /delete /tn "${taskName}" /f`, { stdio: 'pipe' });
31
- console.log(`Removed Windows Task Scheduler task: ${taskName}`);
32
- } catch {
33
- console.log(`Windows Task Scheduler task does not exist: ${taskName}`);
34
- }
28
+ nssmPath = execSync('where nssm', { stdio: 'pipe' }).toString().trim().split('\n')[0].trim();
29
+ } catch { /* NSSM not installed */ }
35
30
 
36
- // Also remove the wrapper script
37
- const wrapperPath = path.join(getConfigDir(), 'start-daemon.cmd');
38
- if (fs.existsSync(wrapperPath)) {
31
+ if (nssmPath) {
32
+ try { execFileSync(nssmPath, ['stop', serviceName], { stdio: 'pipe' }); } catch { /* not running */ }
33
+ try {
34
+ execFileSync(nssmPath, ['remove', serviceName, 'confirm'], { stdio: 'pipe' });
35
+ console.log(`Removed NSSM service: ${serviceName}`);
36
+ } catch {
37
+ console.log(`NSSM service does not exist: ${serviceName}`);
38
+ }
39
+ } else {
40
+ // Fallback: remove legacy Task Scheduler task from previous installs
41
+ try { execSync(`schtasks /end /tn "${serviceName}"`, { stdio: 'pipe' }); } catch { /* not running */ }
39
42
  try {
40
- fs.rmSync(wrapperPath);
43
+ execSync(`schtasks /delete /tn "${serviceName}" /f`, { stdio: 'pipe' });
44
+ console.log(`Removed Windows Task Scheduler task: ${serviceName}`);
41
45
  } catch {
42
- // Ignore
46
+ console.log(`Windows Task Scheduler task does not exist: ${serviceName}`);
43
47
  }
44
48
  }
49
+
50
+ // Remove legacy wrapper script if present
51
+ const wrapperPath = path.join(getConfigDir(), 'start-daemon.cmd');
52
+ if (fs.existsSync(wrapperPath)) {
53
+ try { fs.rmSync(wrapperPath); } catch { /* ignore */ }
54
+ }
45
55
  }
46
56
 
47
57
  /**
@@ -111,13 +121,21 @@ export function removeConfigAndDb(includeDb = false) {
111
121
  console.log('Skipping SQLite database removal (use --db to remove it).');
112
122
  }
113
123
 
114
- // Remove .omnikey directory
124
+ // Remove all files/folders inside .omnikey except the SQLite database
115
125
  if (fs.existsSync(configDir)) {
116
126
  try {
117
- fs.rmSync(configDir, { recursive: true, force: true });
118
- console.log(`Removed config directory: ${configDir}`);
127
+ const entries = fs.readdirSync(configDir);
128
+ for (const entry of entries) {
129
+ if (entry.endsWith('.sqlite')) {
130
+ continue;
131
+ }
132
+ const entryPath = path.join(configDir, entry);
133
+ fs.rmSync(entryPath, { recursive: true, force: true });
134
+ console.log(`Removed: ${entryPath}`);
135
+ }
136
+ console.log(`Cleared config directory (SQLite preserved): ${configDir}`);
119
137
  } catch (e) {
120
- console.error(`Failed to remove config directory: ${e}`);
138
+ console.error(`Failed to clear config directory: ${e}`);
121
139
  }
122
140
  } else {
123
141
  console.log(`Config directory does not exist: ${configDir}`);
@@ -0,0 +1,16 @@
1
+ import fs from 'fs';
2
+ import { readConfig, getConfigPath, getConfigDir } from './utils';
3
+
4
+ export function setConfig(key: string, value: string) {
5
+ const configDir = getConfigDir();
6
+ const configPath = getConfigPath();
7
+
8
+ if (!fs.existsSync(configDir)) {
9
+ fs.mkdirSync(configDir, { recursive: true });
10
+ }
11
+
12
+ const config = readConfig();
13
+ config[key] = value;
14
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2), 'utf-8');
15
+ console.log(`Set ${key} in ${configPath}`);
16
+ }
@@ -0,0 +1,47 @@
1
+ import fs from 'fs';
2
+ import { readConfig, getConfigPath, getConfigDir } from './utils';
3
+
4
+ const API_KEY_FIELDS = [
5
+ 'OPENAI_API_KEY',
6
+ 'ANTHROPIC_API_KEY',
7
+ 'GEMINI_API_KEY',
8
+ 'SERPER_API_KEY',
9
+ 'BRAVE_SEARCH_API_KEY',
10
+ 'TAVILY_API_KEY',
11
+ ];
12
+
13
+ function maskSecret(value: string): string {
14
+ if (value.length <= 8) return '****';
15
+ return value.slice(0, 4) + '****' + value.slice(-4);
16
+ }
17
+
18
+ export function showConfig() {
19
+ const configPath = getConfigPath();
20
+ const configDir = getConfigDir();
21
+
22
+ if (!fs.existsSync(configPath)) {
23
+ console.log('No configuration found. Run `omnikey onboard` to get started.');
24
+ return;
25
+ }
26
+
27
+ const config = readConfig();
28
+ const keys = Object.keys(config);
29
+
30
+ if (keys.length === 0) {
31
+ console.log('Configuration file exists but is empty.');
32
+ return;
33
+ }
34
+
35
+ console.log(`Config file: ${configPath}\n`);
36
+ console.log('Current configuration:');
37
+ console.log('─'.repeat(50));
38
+
39
+ for (const key of keys) {
40
+ const raw = String(config[key]);
41
+ const display = API_KEY_FIELDS.includes(key) ? maskSecret(raw) : raw;
42
+ console.log(` ${key}: ${display}`);
43
+ }
44
+
45
+ console.log('─'.repeat(50));
46
+ console.log(`\nConfig directory: ${configDir}`);
47
+ }