swadhinbiswas feat: implement air-gapped mode, UI fixes, and project management integrations · 7/9/2026
e3bd4a1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/**
* SSH Key Commands
* Manage SSH keys from the CLI
*/
import chalk from "chalk";
import { Command } from "commander";
import * as fs from "fs";
import inquirer from "inquirer";
import ora from "ora";
import * as os from "os";
import * as path from "path";
import { deleteWithAuth, getWithAuth, postWithAuth } from "../../lib/api.js";
import { getConfig } from "../../lib/config.js";
interface SSHKey {
id: string;
title: string;
key: string;
fingerprint: string;
createdAt: string;
lastUsedAt?: string;
}
export const sshKeyCommands = new Command("ssh-key").description(
"Manage SSH keys",
);
// SSH Key Add
sshKeyCommands
.command("add")
.description("Add an SSH key to your account")
.option("-t, --title <title>", "Key title")
.option("-f, --file <path>", "Path to public key file")
.action(async (options) => {
const config = getConfig();
if (!config.token) {
console.error(chalk.hex("#ff5555")("Not logged in. Run 'och auth login' first."));
process.exit(1);
}
try {
let publicKey: string;
let title = options.title;
if (options.file) {
// Read from file
const keyPath = options.file.replace("~", os.homedir());
if (!fs.existsSync(keyPath)) {
console.error(chalk.hex("#ff5555")(`File not found: ${keyPath}`));
process.exit(1);
}
publicKey = fs.readFileSync(keyPath, "utf-8").trim();
} else {
// Look for default keys
const sshDir = path.join(os.homedir(), ".ssh");
const defaultKeys = ["id_ed25519.pub", "id_rsa.pub", "id_ecdsa.pub"];
const availableKeys: { name: string; path: string }[] = [];
for (const keyFile of defaultKeys) {
const keyPath = path.join(sshDir, keyFile);
if (fs.existsSync(keyPath)) {
availableKeys.push({ name: keyFile, path: keyPath });
}
}
if (availableKeys.length === 0) {
console.log(chalk.hex("#f1fa8c")("No SSH keys found in ~/.ssh/"));
console.log(chalk.hex("#6272a4")("Generate one with: ssh-keygen -t ed25519"));
process.exit(1);
}
const { selectedKey } = await inquirer.prompt([
{
type: "list",
name: "selectedKey",
message: "Select SSH key to add:",
choices: availableKeys.map((k) => ({
name: k.name,
value: k.path,
})),
},
]);
publicKey = fs.readFileSync(selectedKey, "utf-8").trim();
}
// Parse key type and validate
if (!publicKey.startsWith("ssh-") && !publicKey.startsWith("ecdsa-")) {
console.error(chalk.hex("#ff5555")("Invalid SSH public key format"));
process.exit(1);
}
// Get title if not provided
if (!title) {
const defaultTitle = `${os.userInfo().username}@${os.hostname()}`;
const answers = await inquirer.prompt([
{
type: "input",
name: "title",
message: "Key title:",
default: defaultTitle,
},
]);
title = answers.title;
}
const spinner = ora("Adding SSH key...").start();
const result = await postWithAuth<{ data: SSHKey }>("/api/user/keys", {
title,
key: publicKey,
});
spinner.succeed(`Added SSH key: ${chalk.hex("#8be9fd")(title)}`);
console.log(chalk.hex("#6272a4")(` Fingerprint: ${result.data.fingerprint}`));
} catch (error) {
console.error(chalk.hex("#ff5555")("Failed to add SSH key"));
console.error(
chalk.hex("#ff5555")(error instanceof Error ? error.message : "Unknown error"),
);
process.exit(1);
}
});
// SSH Key List
sshKeyCommands
.command("list")
.alias("ls")
.description("List your SSH keys")
.action(async () => {
const config = getConfig();
if (!config.token) {
console.error(chalk.hex("#ff5555")("Not logged in. Run 'och auth login' first."));
process.exit(1);
}
const spinner = ora("Fetching SSH keys...").start();
try {
const result = await getWithAuth<{ data: SSHKey[] }>(
"/api/user/ssh-keys",
);
spinner.stop();
if (result.data.length === 0) {
console.log(chalk.hex("#6272a4")("No SSH keys found."));
console.log(chalk.hex("#6272a4")("Add one with: och ssh-key add"));
return;
}
console.log(chalk.bold(`\n🔑 SSH Keys (${result.data.length})\n`));
for (const key of result.data) {
const keyType = key.key.split(" ")[0].replace("ssh-", "").toUpperCase();
console.log(` ${chalk.hex("#8be9fd")(key.title)} ${chalk.hex("#6272a4")(`(${keyType})`)}`);
console.log(chalk.hex("#6272a4")(` ID: ${key.id}`));
console.log(chalk.hex("#6272a4")(` Fingerprint: ${key.fingerprint}`));
console.log(
chalk.hex("#6272a4")(
` Added: ${new Date(key.createdAt).toLocaleDateString()}`,
),
);
if (key.lastUsedAt) {
console.log(
chalk.hex("#6272a4")(
` Last used: ${new Date(key.lastUsedAt).toLocaleDateString()}`,
),
);
}
console.log("");
}
} catch (error) {
spinner.fail("Failed to list SSH keys");
console.error(
chalk.hex("#ff5555")(error instanceof Error ? error.message : "Unknown error"),
);
process.exit(1);
}
});
// SSH Key Delete
sshKeyCommands
.command("delete <id>")
.alias("rm")
.description("Delete an SSH key")
.option("-y, --yes", "Skip confirmation")
.action(async (id: string, options) => {
const config = getConfig();
if (!config.token) {
console.error(chalk.hex("#ff5555")("Not logged in. Run 'och auth login' first."));
process.exit(1);
}
try {
// Get key info first
const spinner = ora("Fetching key info...").start();
const result = await getWithAuth<{ data: SSHKey[] }>(
"/api/user/ssh-keys",
);
const key = result.data.find((k) => k.id === id);
spinner.stop();
if (!key) {
console.error(chalk.hex("#ff5555")(`SSH key not found: ${id}`));
process.exit(1);
}
if (!options.yes) {
const { confirm } = await inquirer.prompt([
{
type: "confirm",
name: "confirm",
message: `Delete SSH key "${key.title}"?`,
default: false,
},
]);
if (!confirm) {
console.log(chalk.hex("#6272a4")("Cancelled."));
return;
}
}
const deleteSpinner = ora("Deleting SSH key...").start();
await deleteWithAuth(`/api/user/keys/${id}`);
deleteSpinner.succeed(`Deleted SSH key: ${chalk.hex("#8be9fd")(key.title)}`);
} catch (error) {
console.error(chalk.hex("#ff5555")("Failed to delete SSH key"));
console.error(
chalk.hex("#ff5555")(error instanceof Error ? error.message : "Unknown error"),
);
process.exit(1);
}
});
export default sshKeyCommands;