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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/**
* Config Commands
* Manage CLI configuration
*/
import chalk from "chalk";
import { Command } from "commander";
import fs from "fs";
import { applyTlsConfig } from "../../lib/api.js";
import {
clearConfig,
getConfig,
getConfigPath,
getTokenStorageMode,
saveConfig,
supportsSecureTokenStorage,
unsetConfigKey,
} from "../../lib/config.js";
const configDescriptions: Record<string, string> = {
serverUrl: "OpenCodeHub server URL",
token: "Personal access token",
defaultBranch: "Default base branch for PRs",
editor: "Editor to use for interactive editing",
pager: "Pager to use for long output",
caFile: "Path to custom CA bundle (self-signed TLS)",
insecure: "Disable TLS certificate verification",
};
export const configCommands = new Command("config").description(
"Manage CLI configuration",
);
// Config List
configCommands
.command("list")
.alias("ls")
.description("List all configuration values")
.action(() => {
const currentConfig = getConfig();
console.log(chalk.bold("\n⚙️ CLI Configuration\n"));
const keys = ["serverUrl", "defaultBranch", "editor", "pager", "caFile", "insecure"] as const;
for (const key of keys) {
const value = currentConfig[key];
const desc = configDescriptions[key] || "";
const displayValue =
typeof value === "boolean"
? String(value)
: value || chalk.hex("#6272a4")("(not set)");
console.log(`${chalk.hex("#8be9fd")(key)}: ${displayValue}`);
if (desc) {
console.log(chalk.hex("#6272a4")(` ${desc}`));
}
}
// Show token status (not the actual token)
const hasToken = !!currentConfig.token;
const storageMode = getTokenStorageMode(currentConfig.serverUrl);
const storageLabel =
storageMode === "env"
? "env (OCH_TOKEN)"
: storageMode === "keychain"
? "secure keychain"
: storageMode === "file"
? "config file fallback"
: "not set";
console.log(
`${chalk.hex("#8be9fd")("token")}: ${hasToken ? chalk.hex("#50fa7b")("●") + " configured" : chalk.hex("#6272a4")("(not set)")}`,
);
console.log(chalk.hex("#6272a4")(` Personal access token (${storageLabel})`));
console.log(chalk.hex("#6272a4")(`\nConfig file: ${getConfigPath()}`));
if (!supportsSecureTokenStorage()) {
console.log(
chalk.hex("#f1fa8c")(
"Secure keychain backend unavailable on this host. Token uses config file fallback unless OCH_TOKEN is set.",
),
);
}
console.log("");
});
// Config Get
configCommands
.command("get <key>")
.description("Get a configuration value")
.action((key: string) => {
const currentConfig = getConfig();
if (key === "token") {
if (typeof currentConfig.token === "string" && currentConfig.token) {
console.log(currentConfig.token.slice(0, 12) + "...");
} else {
console.log(chalk.hex("#6272a4")("(not set)"));
}
return;
}
const validKeys = [
"serverUrl",
"defaultBranch",
"editor",
"pager",
"caFile",
"insecure",
"username",
];
if (!validKeys.includes(key)) {
console.error(chalk.hex("#ff5555")(`Unknown config key: ${key}`));
console.log(
chalk.hex("#6272a4")(
"Available keys: serverUrl, token, defaultBranch, editor, pager, caFile, insecure, username",
),
);
process.exit(1);
}
const value = currentConfig[key as keyof typeof currentConfig];
if (value !== undefined) {
console.log(String(value));
} else {
console.log(chalk.hex("#6272a4")("(not set)"));
}
});
// Config Set
configCommands
.command("set <key> <value>")
.description("Set a configuration value")
.action((key: string, value: string) => {
const validKeys = [
"serverUrl",
"token",
"defaultBranch",
"editor",
"pager",
"caFile",
"insecure",
];
if (!validKeys.includes(key)) {
console.error(chalk.hex("#ff5555")(`Unknown config key: ${key}`));
console.log(chalk.hex("#6272a4")(`Available keys: ${validKeys.join(", ")}`));
process.exit(1);
}
const normalizedValue = key === "insecure" ? value === "true" || value === "1" : value;
try {
saveConfig({ [key]: normalizedValue } as any);
} catch (error) {
console.error(
chalk.hex("#ff5555")(error instanceof Error ? error.message : "Invalid configuration value"),
);
process.exit(1);
}
const displayValue =
key === "token" && typeof normalizedValue === "string"
? `${normalizedValue.slice(0, 12)}...`
: String(normalizedValue);
console.log(chalk.hex("#50fa7b")(`✓ Set ${key} = ${displayValue}`));
});
// Config Unset
configCommands
.command("unset <key>")
.alias("delete")
.description("Unset a configuration value")
.action((key: string) => {
const validKeys = [
"serverUrl",
"token",
"defaultBranch",
"editor",
"pager",
"caFile",
"insecure",
];
if (!validKeys.includes(key)) {
console.error(chalk.hex("#ff5555")(`Unknown config key: ${key}`));
process.exit(1);
}
unsetConfigKey(key as any);
console.log(chalk.hex("#50fa7b")(`✓ Unset ${key}`));
});
// Config Path
configCommands
.command("path")
.description("Show config file path")
.action(() => {
console.log(getConfigPath());
});
// Config Reset
configCommands
.command("reset")
.description("Reset all configuration to defaults")
.option("-y, --yes", "Skip confirmation")
.action(async (options) => {
if (!options.yes) {
const inquirer = await import("inquirer");
const { confirm } = await inquirer.default.prompt([
{
type: "confirm",
name: "confirm",
message: "Reset all configuration to defaults?",
default: false,
},
]);
if (!confirm) {
console.log(chalk.hex("#6272a4")("Cancelled."));
return;
}
}
clearConfig();
console.log(chalk.hex("#50fa7b")("✓ Configuration reset to defaults"));
});
export default configCommands;
// Config Doctor
configCommands
.command("doctor")
.description("Validate CLI configuration and connectivity")
.action(async () => {
console.log(chalk.bold("\n🩺 Config Doctor\n"));
const currentConfig = getConfig();
const serverUrl = currentConfig.serverUrl;
const token = currentConfig.token;
const caFile = currentConfig.caFile;
const insecure = currentConfig.insecure;
let hasIssues = false;
if (!serverUrl) {
hasIssues = true;
console.log(chalk.hex("#ff5555")("✗ serverUrl is not set"));
console.log(chalk.hex("#6272a4")(" Run: och config set serverUrl <url>"));
} else {
console.log(chalk.hex("#50fa7b")("✓ serverUrl configured"));
console.log(chalk.hex("#6272a4")(` ${serverUrl}`));
}
if (!token) {
hasIssues = true;
console.log(chalk.hex("#ff5555")("✗ token is not set"));
console.log(chalk.hex("#6272a4")(" Run: och auth login --url <url>"));
} else {
console.log(chalk.hex("#50fa7b")("✓ token configured"));
}
if (caFile) {
if (!fs.existsSync(caFile)) {
hasIssues = true;
console.log(chalk.hex("#ff5555")("✗ caFile does not exist"));
console.log(chalk.hex("#6272a4")(` ${caFile}`));
} else {
console.log(chalk.hex("#50fa7b")("✓ caFile found"));
console.log(chalk.hex("#6272a4")(` ${caFile}`));
}
}
if (insecure) {
console.log(chalk.hex("#f1fa8c")("! insecure TLS is enabled"));
}
if (serverUrl && token) {
try {
applyTlsConfig();
const response = await fetch(`${serverUrl}/api/user`, {
headers: {
Authorization: `Bearer ${token}`,
},
});
if (!response.ok) {
hasIssues = true;
console.log(chalk.hex("#ff5555")("✗ token validation failed"));
console.log(chalk.hex("#6272a4")(` HTTP ${response.status}`));
} else {
const data = await response.json();
const username = data?.data?.username || "unknown";
console.log(chalk.hex("#50fa7b")("✓ token is valid"));
console.log(chalk.hex("#6272a4")(` Authenticated as ${username}`));
}
} catch (error) {
hasIssues = true;
console.log(chalk.hex("#ff5555")("✗ could not reach server"));
console.log(
chalk.hex("#6272a4")(String(error instanceof Error ? error.message : error)),
);
}
}
if (hasIssues) {
console.log(chalk.hex("#ff5555")("\nConfig doctor found issues."));
process.exit(1);
}
console.log(chalk.hex("#50fa7b")("\nConfig doctor found no issues."));
});