@sudoji/cli 0.1.5 → 0.1.7

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.
Files changed (2) hide show
  1. package/dist/index.js +43 -14
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -3,6 +3,7 @@ import "./chunk-RWRJASDG.js";
3
3
 
4
4
  // src/index.ts
5
5
  import { Command as Command7 } from "commander";
6
+ import { createRequire } from "module";
6
7
 
7
8
  // src/commands/login.ts
8
9
  import { Command } from "commander";
@@ -15,12 +16,17 @@ import { existsSync, readFileSync, writeFileSync, mkdirSync, chmodSync } from "f
15
16
  import { join, dirname } from "path";
16
17
  import { homedir } from "os";
17
18
  var SERVICE = "sudoji";
19
+ function noKeychainAvailable() {
20
+ if (process.platform !== "linux") return false;
21
+ return !process.env["DBUS_SESSION_BUS_ADDRESS"] && !process.env["DISPLAY"];
22
+ }
18
23
  async function tryKeytar() {
19
- if (process.env["SUDOJI_NO_KEYCHAIN"]) return null;
24
+ if (process.env["SUDOJI_NO_KEYCHAIN"] || noKeychainAvailable()) return null;
20
25
  try {
21
26
  const k = await import("./keytar-2QOTTVWZ.js");
22
27
  const mod = "default" in k ? k.default : k;
23
- return mod ?? null;
28
+ if (!mod || typeof mod.setPassword !== "function") return null;
29
+ return mod;
24
30
  } catch {
25
31
  return null;
26
32
  }
@@ -51,20 +57,22 @@ function writeFile(path, creds) {
51
57
  async function store(creds, profile = "default") {
52
58
  const keytar = await tryKeytar();
53
59
  if (keytar) {
54
- await keytar.setPassword(SERVICE, profile, JSON.stringify(creds));
55
- return;
60
+ try {
61
+ await keytar.setPassword(SERVICE, profile, JSON.stringify(creds));
62
+ return;
63
+ } catch {
64
+ }
56
65
  }
57
66
  writeFile(filePath(profile), creds);
58
67
  }
59
68
  async function load(profile = "default") {
60
69
  const keytar = await tryKeytar();
61
70
  if (keytar) {
62
- const raw = await keytar.getPassword(SERVICE, profile);
63
- if (!raw) return null;
64
71
  try {
72
+ const raw = await keytar.getPassword(SERVICE, profile);
73
+ if (!raw) return null;
65
74
  return JSON.parse(raw);
66
75
  } catch {
67
- return null;
68
76
  }
69
77
  }
70
78
  return readFile(filePath(profile));
@@ -72,8 +80,11 @@ async function load(profile = "default") {
72
80
  async function clear(profile = "default") {
73
81
  const keytar = await tryKeytar();
74
82
  if (keytar) {
75
- await keytar.deletePassword(SERVICE, profile);
76
- return;
83
+ try {
84
+ await keytar.deletePassword(SERVICE, profile);
85
+ return;
86
+ } catch {
87
+ }
77
88
  }
78
89
  const path = filePath(profile);
79
90
  if (existsSync(path)) {
@@ -82,6 +93,24 @@ async function clear(profile = "default") {
82
93
  }
83
94
 
84
95
  // src/commands/login.ts
96
+ var _ = "\x1B[0m";
97
+ var C = "\x1B[36m";
98
+ var B = "\x1B[1m";
99
+ var G = "\x1B[32m";
100
+ var D = "\x1B[2m";
101
+ function printBanner(profile, key) {
102
+ const masked = key.slice(0, 14) + "\u2026";
103
+ console.log();
104
+ console.log(` ${C}${B}\u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510${_}`);
105
+ console.log(` ${C}${B}\u2502${_} \u{1F99A} ${B}sudoji agent${_} ${G}${B}connected${_} ${C}${B}\u2502${_}`);
106
+ console.log(` ${C}${B}\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518${_}`);
107
+ console.log();
108
+ console.log(` ${D}profile${_} ${profile}`);
109
+ console.log(` ${D}key${_} ${masked}`);
110
+ console.log();
111
+ console.log(` ${D}next \u2192${_} sudoji doctor`);
112
+ console.log();
113
+ }
85
114
  function loginCommand() {
86
115
  return new Command("login").description("Authenticate the Sudoji CLI with an API key").option("--paste <key>", "Accept a key directly \u2014 useful for CI and scripting").option("--profile <name>", "Credentials profile to store the key under", "default").action(async (opts) => {
87
116
  let key;
@@ -99,10 +128,8 @@ function loginCommand() {
99
128
  console.error('Invalid key \u2014 keys start with "sudoji_sk_" and are at least 26 characters.');
100
129
  process.exit(1);
101
130
  }
102
- await store(key, opts.profile);
103
- console.log(`
104
- Logged in. Key stored for profile "${opts.profile}".`);
105
- console.log("Run: sudoji doctor to verify the connection.");
131
+ await store({ token: key }, opts.profile);
132
+ printBanner(opts.profile, key);
106
133
  });
107
134
  }
108
135
 
@@ -483,7 +510,9 @@ function keysCommand() {
483
510
  }
484
511
 
485
512
  // src/index.ts
486
- var program = new Command7().name("sudoji").description("Sudoji Agent \u2014 AI-powered IT operations for Linux servers").version("0.1.0", "--version", "print version and exit");
513
+ var require2 = createRequire(import.meta.url);
514
+ var { version } = require2("../package.json");
515
+ var program = new Command7().name("sudoji").description("Sudoji Agent \u2014 AI-powered IT operations for Linux servers").version(version, "--version", "print version and exit");
487
516
  program.addCommand(loginCommand());
488
517
  program.addCommand(logoutCommand());
489
518
  program.addCommand(doctorCommand());
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@sudoji/cli",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Sudoji installable IT agent CLI — diagnose, approve, fix on your Linux server.",
5
5
  "type": "module",
6
6
  "bin": {
7
- "sudoji": "./dist/index.js"
7
+ "sudoji": "dist/index.js"
8
8
  },
9
9
  "files": [
10
10
  "dist"