kern0-cli 0.1.3 → 0.1.5

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.
@@ -13,6 +13,7 @@ import {
13
13
  pollForToken,
14
14
  completeLogin,
15
15
  } from "../auth-flow";
16
+ import { listOrganizations } from "../api";
16
17
  import open from "open";
17
18
 
18
19
  export async function login(): Promise<void> {
@@ -52,8 +53,8 @@ export async function login(): Promise<void> {
52
53
  console.log("✅ Approved!\n");
53
54
  console.log("⏳ Completing login...\n");
54
55
 
55
- // Step 3: Complete login (fetch user, orgs, save config)
56
- const { user, organizations } = await completeLogin(
56
+ // Step 3: Complete login (save user and token)
57
+ const { user } = await completeLogin(
57
58
  tokenResponse.access_token,
58
59
  tokenResponse.expires_in,
59
60
  tokenResponse.user,
@@ -62,12 +63,19 @@ export async function login(): Promise<void> {
62
63
  console.log("✅ Login successful!\n");
63
64
  console.log(`👤 User: ${user.email}\n`);
64
65
 
65
- // Step 4: Select organization
66
+ // Step 4: Fetch organizations from API
67
+ console.log("⏳ Loading organizations...\n");
68
+ const organizations = await listOrganizations();
69
+
66
70
  if (organizations.length === 0) {
67
- console.log("⚠️ No organizations found. Create one with 'kern0 org create'.\n");
71
+ console.log("ℹ️ No organizations found. Create one with 'kern0 org create'.\n");
68
72
  return;
69
73
  }
70
74
 
75
+ // Save organizations to config
76
+ const orgData = organizations.map(o => ({ id: o.id, name: o.name }));
77
+ setOrganizations(orgData);
78
+
71
79
  if (organizations.length === 1) {
72
80
  // Auto-select if only one org
73
81
  setCurrentOrg(organizations[0].id);
@@ -0,0 +1,174 @@
1
+ import { requireAuthentication, requireOrganization } from "../config";
2
+ import { apiCall } from "../api";
3
+
4
+ export async function analyzeReadiness(): Promise<void> {
5
+ try {
6
+ requireAuthentication();
7
+ const orgId = requireOrganization();
8
+
9
+ console.log("\n⏳ Analyzing recovery readiness...\n");
10
+
11
+ const response = await apiCall<{
12
+ readinessPercentage: number;
13
+ totalEnvironments: number;
14
+ onlineCount: number;
15
+ offlineCount: number;
16
+ validBackupsCount: number;
17
+ assessment: string;
18
+ }>("GET", `/api/v1/orgs/${orgId}/readiness`);
19
+
20
+ const pct = response.readinessPercentage;
21
+ const bar = "█".repeat(Math.floor(pct / 5)) + "░".repeat(20 - Math.floor(pct / 5));
22
+
23
+ console.log("📊 Recovery Readiness Assessment\n");
24
+ console.log(` Readiness: [${bar}] ${pct}%\n`);
25
+ console.log(` Assessment: ${response.assessment}\n`);
26
+ console.log(" Details:");
27
+ console.log(` • Total Environments: ${response.totalEnvironments}`);
28
+ console.log(` • Online: ${response.onlineCount}`);
29
+ console.log(` • Offline: ${response.offlineCount}`);
30
+ console.log(` • Valid Backups: ${response.validBackupsCount}/${response.totalEnvironments}\n`);
31
+
32
+ if (pct < 50) {
33
+ console.log(" ⚠️ Action Required: Below 50% readiness\n");
34
+ } else if (pct < 80) {
35
+ console.log(" ⚡ Action Recommended: Room for improvement\n");
36
+ } else {
37
+ console.log(" ✅ Status: Good\n");
38
+ }
39
+ } catch (error) {
40
+ if (error instanceof Error) {
41
+ console.error("Error:", error.message);
42
+ }
43
+ process.exit(1);
44
+ }
45
+ }
46
+
47
+ export async function checkBackupHealth(): Promise<void> {
48
+ try {
49
+ requireAuthentication();
50
+ const orgId = requireOrganization();
51
+
52
+ console.log("\n⏳ Checking backup health...\n");
53
+
54
+ const response = await apiCall<{
55
+ healthyBackups: number;
56
+ totalEnvironments: number;
57
+ failedBackups: Array<{
58
+ environmentId: string;
59
+ label: string;
60
+ reason: string;
61
+ lastBackup: number;
62
+ }>;
63
+ summary: string;
64
+ }>("GET", `/api/v1/orgs/${orgId}/backups/health`);
65
+
66
+ console.log("💾 Backup Health Status\n");
67
+ console.log(` Healthy: ${response.healthyBackups}/${response.totalEnvironments}\n`);
68
+ console.log(` Summary: ${response.summary}\n`);
69
+
70
+ if (response.failedBackups.length > 0) {
71
+ console.log(" ⚠️ Failed Backups:\n");
72
+ response.failedBackups.forEach((backup) => {
73
+ const lastBackupDate = new Date(backup.lastBackup).toLocaleDateString();
74
+ console.log(` • ${backup.label}`);
75
+ console.log(` Reason: ${backup.reason}`);
76
+ console.log(` Last backup: ${lastBackupDate}\n`);
77
+ });
78
+ } else {
79
+ console.log(" ✅ All backups healthy\n");
80
+ }
81
+ } catch (error) {
82
+ if (error instanceof Error) {
83
+ console.error("Error:", error.message);
84
+ }
85
+ process.exit(1);
86
+ }
87
+ }
88
+
89
+ export async function getEnvironmentStatus(envId: string): Promise<void> {
90
+ try {
91
+ requireAuthentication();
92
+ const orgId = requireOrganization();
93
+
94
+ console.log("\n⏳ Loading environment details...\n");
95
+
96
+ const response = await apiCall<{
97
+ id: string;
98
+ label: string;
99
+ status: "online" | "offline" | "degraded";
100
+ customer: string;
101
+ product: string;
102
+ lastHeartbeat: number;
103
+ backupStatus: "healthy" | "warning" | "critical";
104
+ recoveryReadiness: number;
105
+ nodeCount: number;
106
+ onlineNodes: number;
107
+ }>("GET", `/api/v1/orgs/${orgId}/environments/${envId}`);
108
+
109
+ const statusEmoji =
110
+ response.status === "online" ? "🟢" : response.status === "offline" ? "🔴" : "🟡";
111
+ const backupEmoji =
112
+ response.backupStatus === "healthy" ? "✅" : response.backupStatus === "warning" ? "⚠️" : "❌";
113
+
114
+ console.log("🌍 Environment Status\n");
115
+ console.log(` Label: ${response.label}`);
116
+ console.log(` Status: ${statusEmoji} ${response.status.toUpperCase()}`);
117
+ console.log(` Customer: ${response.customer}`);
118
+ console.log(` Product: ${response.product}\n`);
119
+
120
+ console.log("📊 Health Metrics:");
121
+ console.log(` Backup Status: ${backupEmoji} ${response.backupStatus}`);
122
+ console.log(` Recovery Readiness: ${response.recoveryReadiness}%`);
123
+ console.log(` Nodes: ${response.onlineNodes}/${response.nodeCount} online`);
124
+ console.log(` Last Heartbeat: ${new Date(response.lastHeartbeat).toLocaleString()}\n`);
125
+ } catch (error) {
126
+ if (error instanceof Error) {
127
+ console.error("Error:", error.message);
128
+ }
129
+ process.exit(1);
130
+ }
131
+ }
132
+
133
+ export async function listAuditLogs(limit: string = "50"): Promise<void> {
134
+ try {
135
+ requireAuthentication();
136
+ const orgId = requireOrganization();
137
+
138
+ console.log("\n⏳ Loading audit logs...\n");
139
+
140
+ const limitNum = parseInt(limit) || 50;
141
+ const response = await apiCall<{
142
+ logs: Array<{
143
+ id: string;
144
+ timestamp: number;
145
+ userId: string;
146
+ action: string;
147
+ resource: string;
148
+ status: number;
149
+ }>;
150
+ }>("GET", `/api/v1/orgs/${orgId}/audit-logs?limit=${limitNum}`);
151
+
152
+ const logs = response.logs || [];
153
+
154
+ if (logs.length === 0) {
155
+ console.log(" No audit logs found.\n");
156
+ return;
157
+ }
158
+
159
+ console.log(`📋 Recent Actions (${logs.length} logs)\n`);
160
+
161
+ logs.forEach((log) => {
162
+ const timestamp = new Date(log.timestamp).toLocaleString();
163
+ const statusEmoji = log.status >= 200 && log.status < 300 ? "✅" : "❌";
164
+ console.log(` ${statusEmoji} ${timestamp}`);
165
+ console.log(` Action: ${log.action} ${log.resource}`);
166
+ console.log(` User: ${log.userId}\n`);
167
+ });
168
+ } catch (error) {
169
+ if (error instanceof Error) {
170
+ console.error("Error:", error.message);
171
+ }
172
+ process.exit(1);
173
+ }
174
+ }
@@ -34,12 +34,12 @@ export async function listOrgs(): Promise<void> {
34
34
 
35
35
  orgs.forEach(org => {
36
36
  if (!org.id || !org.name) return; // Skip orgs without proper data
37
- const marker = org.id === currentOrgId ? "* " : " ";
37
+ const marker = org.id === currentOrgId ? "✓ " : " ";
38
38
  const type = org.type === "msp" ? " (MSP)" : "";
39
- console.log(` ${marker}${org.id.substring(0, 8)}... ${org.name}${type}`);
39
+ console.log(` ${marker}${org.id} ${org.name}${type}`);
40
40
  });
41
41
 
42
- console.log("");
42
+ console.log("\n📌 Usage: kern0 org select <orgId> or kern0 org select <name>\n");
43
43
  } catch (error) {
44
44
  if (error instanceof Error) {
45
45
  console.error("Error:", error.message);
@@ -48,15 +48,21 @@ export async function listOrgs(): Promise<void> {
48
48
  }
49
49
  }
50
50
 
51
- export async function selectOrg(orgId: string): Promise<void> {
51
+ export async function selectOrg(orgIdentifier: string): Promise<void> {
52
52
  try {
53
53
  requireAuthentication();
54
54
 
55
+ // Check if orgIdentifier is a name by fetching all orgs
56
+ const allOrgs = await listOrganizations();
57
+ const orgByName = allOrgs.find(o => o.name.toLowerCase() === orgIdentifier.toLowerCase());
58
+
59
+ const finalOrgId = orgByName ? orgByName.id : orgIdentifier;
60
+
55
61
  // Verify org exists by fetching it
56
- const org = await getOrganization(orgId);
62
+ const org = await getOrganization(finalOrgId);
57
63
 
58
64
  // Update current org
59
- setCurrentOrg(orgId);
65
+ setCurrentOrg(finalOrgId);
60
66
 
61
67
  // Add to organizations list if not already there
62
68
  addOrganization({ id: org.id, name: org.name });
package/lib/cli/index.ts CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  import { login, logout } from "./commands/auth";
4
4
  import { setupCommand } from "./commands/setup";
5
+ import {
6
+ analyzeReadiness,
7
+ checkBackupHealth,
8
+ getEnvironmentStatus,
9
+ listAuditLogs,
10
+ } from "./commands/health";
5
11
  import {
6
12
  listOrgs,
7
13
  selectOrg,
@@ -45,6 +51,30 @@ async function main() {
45
51
  await setupCommand();
46
52
  break;
47
53
 
54
+ // Health & Monitoring commands
55
+ case "health":
56
+ case "readiness":
57
+ await analyzeReadiness();
58
+ break;
59
+
60
+ case "backups":
61
+ await checkBackupHealth();
62
+ break;
63
+
64
+ case "audit":
65
+ case "logs":
66
+ await listAuditLogs(arg1);
67
+ break;
68
+
69
+ case "env-status":
70
+ case "env-health":
71
+ if (!arg1) {
72
+ console.error("Usage: kern0 env-status <envId>");
73
+ process.exit(1);
74
+ }
75
+ await getEnvironmentStatus(arg1);
76
+ break;
77
+
48
78
  // Organization commands
49
79
  case "org":
50
80
  switch (subcommand) {
@@ -187,6 +217,12 @@ AUTHENTICATION:
187
217
  logout Clear credentials and log out
188
218
  whoami Show current user, organization, and customer
189
219
 
220
+ MONITORING & HEALTH:
221
+ health Analyze recovery readiness (%)
222
+ backups Check backup health status
223
+ audit [limit] View recent action audit logs
224
+ env-status <id> Get detailed environment status
225
+
190
226
  ORGANIZATIONS:
191
227
  org list List your organizations
192
228
  org select <id> Switch to an organization
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kern0-cli",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "KernZero CLI - Recovery control plane management from the terminal",
5
5
  "private": false,
6
6
  "license": "MIT",