@notchlet/cli 0.0.0-stage → 0.2.0
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.
- package/dist/auth.js +380 -0
- package/dist/cli-format.js +46 -0
- package/dist/cli-prompt.js +73 -0
- package/dist/cli.js +1040 -0
- package/dist/guidance-install.js +111 -0
- package/dist/integration.js +806 -0
- package/dist/setup.js +92 -0
- package/guidance/aliases.json +27 -0
- package/guidance/generated/claude-code/notchlet-deliver/SKILL.md +94 -0
- package/guidance/generated/claude-code/notchlet-implement/SKILL.md +94 -0
- package/guidance/generated/claude-code/notchlet-init/SKILL.md +30 -0
- package/guidance/generated/claude-code/notchlet-mcp/SKILL.md +60 -0
- package/guidance/generated/claude-code/notchlet-plan/SKILL.md +100 -0
- package/guidance/generated/claude-code/notchlet-platform/SKILL.md +85 -0
- package/guidance/generated/claude-code/notchlet-review/SKILL.md +68 -0
- package/guidance/generated/claude-code/notchlet-super/SKILL.md +47 -0
- package/guidance/generated/compatibility.json +94 -0
- package/guidance/generated/manifest.json +140 -0
- package/guidance/generated/opencode/notchlet-deliver/SKILL.md +94 -0
- package/guidance/generated/opencode/notchlet-implement/SKILL.md +94 -0
- package/guidance/generated/opencode/notchlet-init/SKILL.md +30 -0
- package/guidance/generated/opencode/notchlet-mcp/SKILL.md +60 -0
- package/guidance/generated/opencode/notchlet-plan/SKILL.md +100 -0
- package/guidance/generated/opencode/notchlet-platform/SKILL.md +85 -0
- package/guidance/generated/opencode/notchlet-review/SKILL.md +68 -0
- package/guidance/generated/opencode/notchlet-super/SKILL.md +47 -0
- package/package.json +1 -6
- package/scripts/generate-guidance.mjs +115 -0
- package/README.md +0 -3
package/dist/auth.js
ADDED
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
import { chmod, mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { createInterface } from 'node:readline/promises';
|
|
5
|
+
export function normalizeOrigin(input) {
|
|
6
|
+
let url;
|
|
7
|
+
try {
|
|
8
|
+
url = new URL(input);
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
throw new Error('Server must be a valid HTTPS origin.');
|
|
12
|
+
}
|
|
13
|
+
if (url.protocol !== 'https:' || url.username || url.password || url.search || url.hash || (url.pathname !== '/' && url.pathname !== ''))
|
|
14
|
+
throw new Error('Server must be an HTTPS origin without credentials, path, query, or fragment.');
|
|
15
|
+
return url.origin.toLowerCase();
|
|
16
|
+
}
|
|
17
|
+
export function serverKey(origin) { return Buffer.from(origin).toString('base64url'); }
|
|
18
|
+
export function configDir() {
|
|
19
|
+
if (process.env.NOTCHLET_CONFIG_DIR)
|
|
20
|
+
return process.env.NOTCHLET_CONFIG_DIR;
|
|
21
|
+
if (process.platform === 'win32')
|
|
22
|
+
return path.join(process.env.LOCALAPPDATA ?? path.join(os.homedir(), 'AppData', 'Local'), 'Notchlet');
|
|
23
|
+
return path.join(process.env.XDG_CONFIG_HOME ?? path.join(os.homedir(), '.config'), 'notchlet');
|
|
24
|
+
}
|
|
25
|
+
function profilesPath() { return path.join(configDir(), 'profiles.json'); }
|
|
26
|
+
function parseUserSession(value) {
|
|
27
|
+
try {
|
|
28
|
+
const session = JSON.parse(value);
|
|
29
|
+
if (session.kind === 'notchlet-user-session' && typeof session.accessToken === 'string' && typeof session.refreshToken === 'string' && typeof session.email === 'string')
|
|
30
|
+
return session;
|
|
31
|
+
}
|
|
32
|
+
catch { /* existing installations may contain a raw scoped MCP token */ }
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
function jwtExpiry(token) {
|
|
36
|
+
try {
|
|
37
|
+
const part = token.split('.')[1];
|
|
38
|
+
if (!part)
|
|
39
|
+
return undefined;
|
|
40
|
+
const payload = JSON.parse(Buffer.from(part, 'base64url').toString('utf8'));
|
|
41
|
+
return typeof payload.exp === 'number' ? payload.exp : undefined;
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
return undefined;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
async function refreshUserSession(origin, session, fetcher) {
|
|
48
|
+
let response;
|
|
49
|
+
try {
|
|
50
|
+
response = await fetcher(`${origin}/auth/refresh`, { method: 'POST', headers: { Authorization: `Bearer ${session.refreshToken}` } });
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
throw new Error('Notchlet is unreachable while refreshing the login session.');
|
|
54
|
+
}
|
|
55
|
+
if (!response.ok)
|
|
56
|
+
throw new Error('Notchlet session expired or was revoked.');
|
|
57
|
+
const tokens = await response.json();
|
|
58
|
+
if (typeof tokens.accessToken !== 'string' || typeof tokens.refreshToken !== 'string')
|
|
59
|
+
throw new Error('Notchlet returned an invalid refreshed session.');
|
|
60
|
+
return { kind: 'notchlet-user-session', accessToken: tokens.accessToken, refreshToken: tokens.refreshToken, email: session.email };
|
|
61
|
+
}
|
|
62
|
+
async function readProfiles() {
|
|
63
|
+
try {
|
|
64
|
+
const value = JSON.parse(await readFile(profilesPath(), 'utf8'));
|
|
65
|
+
if (value.schemaVersion !== 1 || !value.profiles || typeof value.profiles !== 'object')
|
|
66
|
+
throw new Error('Invalid profiles file.');
|
|
67
|
+
return value;
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
if (error.code === 'ENOENT')
|
|
71
|
+
return { schemaVersion: 1, profiles: {} };
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** Resolve a token for the selected server without printing or persisting it. */
|
|
76
|
+
export async function resolveCredential(options = {}) {
|
|
77
|
+
const profiles = await readProfiles();
|
|
78
|
+
const origin = options.server ? normalizeOrigin(options.server) : profiles.current ? profiles.profiles[profiles.current]?.origin : undefined;
|
|
79
|
+
if (!origin)
|
|
80
|
+
throw new Error('No server selected. Run auth login or provide --server.');
|
|
81
|
+
const key = serverKey(origin), profile = profiles.profiles[key];
|
|
82
|
+
if (!profile)
|
|
83
|
+
throw new Error('No profile exists for this server. Run auth login first.');
|
|
84
|
+
if (process.env.NOTCHLET_TOKEN?.trim())
|
|
85
|
+
return { profile, token: process.env.NOTCHLET_TOKEN, authMode: 'token' };
|
|
86
|
+
let store;
|
|
87
|
+
if (profile.credentialStore === 'file') {
|
|
88
|
+
if (!options.allowFileStore)
|
|
89
|
+
throw new Error('This profile uses file credentials; pass --allow-file-token-store to enable it.');
|
|
90
|
+
store = fileCredentialStore();
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
try {
|
|
94
|
+
store = options.store ?? await (options.loadStore ?? osCredentialStore)();
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
if (!options.allowFileStore)
|
|
98
|
+
throw new Error('OS credential store is unavailable or locked.');
|
|
99
|
+
store = fileCredentialStore();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const stored = await store.get(key);
|
|
103
|
+
if (!stored)
|
|
104
|
+
throw new Error('No credential is available for the selected server. Run `notchlet auth login`.');
|
|
105
|
+
const session = parseUserSession(stored);
|
|
106
|
+
if (!session)
|
|
107
|
+
return { profile, token: stored, authMode: 'token' };
|
|
108
|
+
let current = session;
|
|
109
|
+
const expiresAt = jwtExpiry(session.accessToken);
|
|
110
|
+
if (expiresAt !== undefined && expiresAt <= Date.now() / 1000 + 60) {
|
|
111
|
+
try {
|
|
112
|
+
current = await refreshUserSession(origin, session, options.fetch ?? fetch);
|
|
113
|
+
await store.set(key, JSON.stringify(current));
|
|
114
|
+
}
|
|
115
|
+
catch {
|
|
116
|
+
if (expiresAt <= Date.now() / 1000)
|
|
117
|
+
throw new Error('Notchlet session expired. Run `notchlet auth login` again.');
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return { profile, token: current.accessToken, refreshToken: current.refreshToken, authMode: 'user' };
|
|
121
|
+
}
|
|
122
|
+
async function writeProfiles(value) {
|
|
123
|
+
await mkdir(configDir(), { recursive: true, mode: 0o700 });
|
|
124
|
+
await writeFile(profilesPath(), `${JSON.stringify(value, null, 2)}\n`, { mode: 0o600 });
|
|
125
|
+
if (process.platform !== 'win32')
|
|
126
|
+
await chmod(profilesPath(), 0o600);
|
|
127
|
+
}
|
|
128
|
+
export async function getProfile(server) {
|
|
129
|
+
const profiles = await readProfiles();
|
|
130
|
+
const key = server ? serverKey(normalizeOrigin(server)) : profiles.current;
|
|
131
|
+
return key ? profiles.profiles[key] : undefined;
|
|
132
|
+
}
|
|
133
|
+
/** Select an existing server profile while preserving all other user-global profiles. */
|
|
134
|
+
export async function selectProfile(server) {
|
|
135
|
+
const profiles = await readProfiles();
|
|
136
|
+
const key = serverKey(normalizeOrigin(server));
|
|
137
|
+
const profile = profiles.profiles[key];
|
|
138
|
+
if (!profile)
|
|
139
|
+
return undefined;
|
|
140
|
+
profiles.current = key;
|
|
141
|
+
await writeProfiles(profiles);
|
|
142
|
+
return profile;
|
|
143
|
+
}
|
|
144
|
+
/** User-confirmed restricted-file adapter, kept separate from profiles.json. */
|
|
145
|
+
export function fileCredentialStore() {
|
|
146
|
+
assertFileFallbackSupported();
|
|
147
|
+
const file = path.join(configDir(), 'credentials.json');
|
|
148
|
+
const read = async () => {
|
|
149
|
+
try {
|
|
150
|
+
if (process.platform !== 'win32') {
|
|
151
|
+
const { mode } = await (await import('node:fs/promises')).stat(file);
|
|
152
|
+
if ((mode & 0o077) !== 0)
|
|
153
|
+
throw new Error('Credential file permissions are too broad; restrict it to the current user (0600).');
|
|
154
|
+
}
|
|
155
|
+
return JSON.parse(await readFile(file, 'utf8'));
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
if (error.code === 'ENOENT')
|
|
159
|
+
return {};
|
|
160
|
+
throw error;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
const save = async (values) => {
|
|
164
|
+
await mkdir(configDir(), { recursive: true, mode: 0o700 });
|
|
165
|
+
await writeFile(file, `${JSON.stringify(values, null, 2)}\n`, { mode: 0o600 });
|
|
166
|
+
if (process.platform !== 'win32')
|
|
167
|
+
await chmod(file, 0o600);
|
|
168
|
+
};
|
|
169
|
+
return { name: `restricted user file (${file}; permissions 0600; directory 0700)`, async get(k) { return (await read())[k]; }, async set(k, v) { const d = await read(); d[k] = v; await save(d); }, async delete(k) { const d = await read(); delete d[k]; await save(d); } };
|
|
170
|
+
}
|
|
171
|
+
export function assertFileFallbackSupported(platform = process.platform) {
|
|
172
|
+
if (platform === 'win32')
|
|
173
|
+
throw new Error('Restricted-file credential storage is not supported on Windows because file mode bits do not guarantee a private ACL; set NOTCHLET_TOKEN or use a working OS credential store.');
|
|
174
|
+
}
|
|
175
|
+
/** Lazily load the maintained native OS credential store so non-auth CLI commands don't load native bindings. */
|
|
176
|
+
export async function osCredentialStore(loadModule) {
|
|
177
|
+
try {
|
|
178
|
+
const load = loadModule ?? (() => {
|
|
179
|
+
const dynamicImport = new Function('specifier', 'return import(specifier)');
|
|
180
|
+
return dynamicImport('@napi-rs/keyring');
|
|
181
|
+
});
|
|
182
|
+
const keyring = await load();
|
|
183
|
+
const service = 'notchlet-cli';
|
|
184
|
+
return {
|
|
185
|
+
name: 'operating-system credential store (@napi-rs/keyring)',
|
|
186
|
+
async get(key) { return (await new keyring.Entry(service, key).getPassword()) ?? undefined; },
|
|
187
|
+
async set(key, value) { await new keyring.Entry(service, key).setPassword(value); },
|
|
188
|
+
async delete(key) { await new keyring.Entry(service, key).deletePassword(); },
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
// Do not surface native-loader or backend errors; they can contain implementation details.
|
|
193
|
+
throw new Error('OS credential store is unavailable or locked.');
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
export async function readHiddenToken(io = {}, prompt = 'Token (input hidden): ') {
|
|
197
|
+
const input = io.stdin ?? process.stdin, output = io.stdout ?? process.stderr;
|
|
198
|
+
if (!input.isTTY || !output.isTTY || !input.setRawMode)
|
|
199
|
+
throw new Error('Hidden password/token entry requires a TTY; use NOTCHLET_EMAIL and NOTCHLET_PASSWORD or NOTCHLET_TOKEN for automation.');
|
|
200
|
+
output.write(prompt);
|
|
201
|
+
return new Promise((resolve, reject) => {
|
|
202
|
+
let value = '';
|
|
203
|
+
const finish = (error) => { input.setRawMode(false); input.pause(); input.removeListener('data', onData); output.write('\n'); error ? reject(error) : resolve(value); };
|
|
204
|
+
const onData = (chunk) => {
|
|
205
|
+
for (const byte of chunk) {
|
|
206
|
+
if (byte === 3)
|
|
207
|
+
return finish(new Error('Token entry cancelled.'));
|
|
208
|
+
if (byte === 13 || byte === 10)
|
|
209
|
+
return finish();
|
|
210
|
+
if (byte === 8 || byte === 127)
|
|
211
|
+
value = value.slice(0, -1);
|
|
212
|
+
else
|
|
213
|
+
value += String.fromCharCode(byte);
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
input.setRawMode(true);
|
|
217
|
+
input.resume();
|
|
218
|
+
input.on('data', onData);
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
async function readEmail(io = {}) {
|
|
222
|
+
if (io.readLine)
|
|
223
|
+
return (await io.readLine('Notchlet email: ')).trim();
|
|
224
|
+
const input = io.stdin ?? process.stdin, output = io.stdout ?? process.stderr;
|
|
225
|
+
if (!input.isTTY || !output.isTTY)
|
|
226
|
+
throw new Error('Interactive login requires a TTY; set NOTCHLET_EMAIL and NOTCHLET_PASSWORD for automation.');
|
|
227
|
+
const readline = createInterface({ input, output });
|
|
228
|
+
try {
|
|
229
|
+
return (await readline.question('Notchlet email: ')).trim();
|
|
230
|
+
}
|
|
231
|
+
finally {
|
|
232
|
+
readline.close();
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
async function loginWithPassword(origin, email, password, fetcher) {
|
|
236
|
+
let response;
|
|
237
|
+
try {
|
|
238
|
+
response = await fetcher(`${origin}/auth/login`, {
|
|
239
|
+
method: 'POST',
|
|
240
|
+
headers: { 'Content-Type': 'application/json' },
|
|
241
|
+
body: JSON.stringify({ email, password }),
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
catch {
|
|
245
|
+
throw new Error('Could not reach Notchlet login. Check the server URL and network connection.');
|
|
246
|
+
}
|
|
247
|
+
if (response.status === 401)
|
|
248
|
+
throw new Error('Email/password authentication failed. Check your credentials.');
|
|
249
|
+
if (response.status === 403)
|
|
250
|
+
throw new Error('This account cannot sign in yet. Verify the email address or contact your workspace administrator.');
|
|
251
|
+
if (!response.ok)
|
|
252
|
+
throw new Error(`Notchlet login failed with HTTP ${response.status}.`);
|
|
253
|
+
const result = await response.json();
|
|
254
|
+
if (typeof result.accessToken !== 'string' || typeof result.refreshToken !== 'string')
|
|
255
|
+
throw new Error('Notchlet returned an invalid login response.');
|
|
256
|
+
return { kind: 'notchlet-user-session', accessToken: result.accessToken, refreshToken: result.refreshToken, email: typeof result.user?.email === 'string' ? result.user.email : email };
|
|
257
|
+
}
|
|
258
|
+
export async function authCommand(action, options = {}) {
|
|
259
|
+
const profiles = await readProfiles();
|
|
260
|
+
let origin;
|
|
261
|
+
if (options.server)
|
|
262
|
+
origin = normalizeOrigin(options.server);
|
|
263
|
+
else if (profiles.current && profiles.profiles[profiles.current])
|
|
264
|
+
origin = profiles.profiles[profiles.current].origin;
|
|
265
|
+
else
|
|
266
|
+
throw new Error('No server selected. Provide --server https://host or log in to a server first.');
|
|
267
|
+
const key = serverKey(origin);
|
|
268
|
+
const fallback = () => {
|
|
269
|
+
if (!options.allowFileStore)
|
|
270
|
+
throw new Error('OS credential store is unavailable or locked. To use the restricted per-user file fallback, explicitly pass --allow-file-token-store.');
|
|
271
|
+
return fileCredentialStore();
|
|
272
|
+
};
|
|
273
|
+
const profile = { origin, serverIdentity: origin };
|
|
274
|
+
if (action === 'login') {
|
|
275
|
+
const usingEnvironmentToken = !options.forceUserLogin && Boolean(process.env.NOTCHLET_TOKEN?.trim());
|
|
276
|
+
const legacyToken = options.forceUserLogin ? undefined : process.env.NOTCHLET_TOKEN?.trim() || options.token?.trim();
|
|
277
|
+
let credentialValue;
|
|
278
|
+
if (legacyToken) {
|
|
279
|
+
profile.authMode = 'token';
|
|
280
|
+
credentialValue = legacyToken;
|
|
281
|
+
}
|
|
282
|
+
else {
|
|
283
|
+
let email = options.email?.trim() || process.env.NOTCHLET_EMAIL?.trim();
|
|
284
|
+
let password = options.password || process.env.NOTCHLET_PASSWORD;
|
|
285
|
+
if (options.json && (!email || !password))
|
|
286
|
+
throw new Error('Interactive email/password login is disabled in JSON mode; set NOTCHLET_EMAIL and NOTCHLET_PASSWORD.');
|
|
287
|
+
if (!email)
|
|
288
|
+
email = await readEmail(options.io);
|
|
289
|
+
if (!password)
|
|
290
|
+
password = options.io?.readSecret ? await options.io.readSecret('Notchlet password (input hidden): ') : await readHiddenToken(options.io, 'Notchlet password (input hidden): ');
|
|
291
|
+
if (!email || !password.trim())
|
|
292
|
+
throw new Error('Email and password cannot be empty.');
|
|
293
|
+
const session = await loginWithPassword(origin, email, password, options.fetch ?? fetch);
|
|
294
|
+
credentialValue = JSON.stringify(session);
|
|
295
|
+
profile.authMode = 'user';
|
|
296
|
+
profile.email = session.email;
|
|
297
|
+
}
|
|
298
|
+
let selected;
|
|
299
|
+
if (!usingEnvironmentToken) {
|
|
300
|
+
try {
|
|
301
|
+
selected = options.store ?? await (options.loadStore ?? osCredentialStore)();
|
|
302
|
+
}
|
|
303
|
+
catch {
|
|
304
|
+
selected = fallback();
|
|
305
|
+
}
|
|
306
|
+
try {
|
|
307
|
+
await selected.set(key, credentialValue);
|
|
308
|
+
}
|
|
309
|
+
catch {
|
|
310
|
+
selected = fallback();
|
|
311
|
+
await selected.set(key, credentialValue);
|
|
312
|
+
}
|
|
313
|
+
profile.credentialStore = selected.name.startsWith('restricted user file') ? 'file' : 'os';
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
profile.credentialStore = 'environment';
|
|
317
|
+
}
|
|
318
|
+
profiles.profiles[key] = profile;
|
|
319
|
+
profiles.current = key;
|
|
320
|
+
await writeProfiles(profiles);
|
|
321
|
+
return { profile, credential: { source: usingEnvironmentToken ? 'environment' : selected.name, status: 'available' } };
|
|
322
|
+
}
|
|
323
|
+
if (!profiles.profiles[key])
|
|
324
|
+
throw new Error('No profile exists for this server. Run auth login first.');
|
|
325
|
+
if (action === 'status') {
|
|
326
|
+
const env = process.env.NOTCHLET_TOKEN;
|
|
327
|
+
let selected, saved;
|
|
328
|
+
if (!env) {
|
|
329
|
+
try {
|
|
330
|
+
selected = profiles.profiles[key].credentialStore === 'file' ? fallback() : options.store ?? await (options.loadStore ?? osCredentialStore)();
|
|
331
|
+
saved = await selected.get(key);
|
|
332
|
+
}
|
|
333
|
+
catch {
|
|
334
|
+
selected = fallback();
|
|
335
|
+
saved = await selected.get(key);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return { profile: profiles.profiles[key], current: profiles.current === key, credential: { source: env ? 'environment' : selected?.name ?? 'none', status: env || saved ? 'available' : 'missing' } };
|
|
339
|
+
}
|
|
340
|
+
if (action === 'logout') {
|
|
341
|
+
let selected;
|
|
342
|
+
try {
|
|
343
|
+
selected = profiles.profiles[key].credentialStore === 'file' ? fallback() : options.store ?? await (options.loadStore ?? osCredentialStore)();
|
|
344
|
+
}
|
|
345
|
+
catch {
|
|
346
|
+
selected = fallback();
|
|
347
|
+
}
|
|
348
|
+
let serverLogout = 'not-user-session';
|
|
349
|
+
const saved = await selected.get(key).catch(() => undefined);
|
|
350
|
+
const session = saved ? parseUserSession(saved) : null;
|
|
351
|
+
if (session) {
|
|
352
|
+
try {
|
|
353
|
+
let current = session;
|
|
354
|
+
const exp = jwtExpiry(session.accessToken);
|
|
355
|
+
if (exp !== undefined && exp <= Date.now() / 1000 + 60) {
|
|
356
|
+
current = await refreshUserSession(origin, session, options.fetch ?? fetch);
|
|
357
|
+
await selected.set(key, JSON.stringify(current));
|
|
358
|
+
}
|
|
359
|
+
const response = await (options.fetch ?? fetch)(`${origin}/auth/logout`, { method: 'POST', headers: { Authorization: `Bearer ${current.accessToken}` } });
|
|
360
|
+
serverLogout = response.ok ? 'revoked' : 'unavailable';
|
|
361
|
+
}
|
|
362
|
+
catch {
|
|
363
|
+
serverLogout = 'unavailable';
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
try {
|
|
367
|
+
await selected.delete(key);
|
|
368
|
+
}
|
|
369
|
+
catch {
|
|
370
|
+
selected = fallback();
|
|
371
|
+
await selected.delete(key);
|
|
372
|
+
}
|
|
373
|
+
delete profiles.profiles[key];
|
|
374
|
+
if (profiles.current === key)
|
|
375
|
+
profiles.current = Object.keys(profiles.profiles)[0];
|
|
376
|
+
await writeProfiles(profiles);
|
|
377
|
+
return { loggedOut: true, profile: origin, currentProfile: profiles.current ? profiles.profiles[profiles.current] : null, serverLogout, credential: { source: process.env.NOTCHLET_TOKEN ? 'environment' : 'none', status: process.env.NOTCHLET_TOKEN ? 'still configured in environment' : 'removed' } };
|
|
378
|
+
}
|
|
379
|
+
throw new Error('Use auth login, auth status, or auth logout.');
|
|
380
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const BOLD = '\x1b[1m';
|
|
2
|
+
const DIM = '\x1b[2m';
|
|
3
|
+
const GREEN = '\x1b[32m';
|
|
4
|
+
const RED = '\x1b[31m';
|
|
5
|
+
const YELLOW = '\x1b[33m';
|
|
6
|
+
const CYAN = '\x1b[36m';
|
|
7
|
+
const RESET = '\x1b[0m';
|
|
8
|
+
const supportsColor = process.stdout.isTTY && !process.env.NO_COLOR;
|
|
9
|
+
const c = (code) => (supportsColor ? code : '');
|
|
10
|
+
const wrap = (str, code) => (supportsColor ? `${code}${str}${RESET}` : str);
|
|
11
|
+
export function section(title) {
|
|
12
|
+
return `${c(BOLD)}${title}${RESET}`;
|
|
13
|
+
}
|
|
14
|
+
export function kv(label, value) {
|
|
15
|
+
return ` ${c(DIM)}${label}${RESET}: ${value}`;
|
|
16
|
+
}
|
|
17
|
+
export function bullet(text, prefix = '•') {
|
|
18
|
+
return ` ${c(CYAN)}${prefix}${RESET} ${text}`;
|
|
19
|
+
}
|
|
20
|
+
export function ok(text) {
|
|
21
|
+
return wrap(text, GREEN);
|
|
22
|
+
}
|
|
23
|
+
export function err(text) {
|
|
24
|
+
return wrap(text, RED);
|
|
25
|
+
}
|
|
26
|
+
export function warn(text) {
|
|
27
|
+
return wrap(text, YELLOW);
|
|
28
|
+
}
|
|
29
|
+
export function table(headers, rows) {
|
|
30
|
+
if (rows.length === 0)
|
|
31
|
+
return `${c(DIM)}(none)${RESET}`;
|
|
32
|
+
const widths = headers.map((h, i) => Math.max(h.length, ...rows.map((r) => (r[i] ?? '').length)));
|
|
33
|
+
const line = (cells) => cells.map((cell, i) => cell.padEnd(widths[i])).join(' ');
|
|
34
|
+
const out = [];
|
|
35
|
+
out.push(line(headers));
|
|
36
|
+
out.push(widths.map((w) => '-'.repeat(w)).join(' '));
|
|
37
|
+
for (const row of rows)
|
|
38
|
+
out.push(line(row));
|
|
39
|
+
return out.join('\n');
|
|
40
|
+
}
|
|
41
|
+
export function box(lines) {
|
|
42
|
+
return lines.join('\n');
|
|
43
|
+
}
|
|
44
|
+
export function divider() {
|
|
45
|
+
return c(DIM) + '──────────────────────────────────────────────────────────────' + RESET;
|
|
46
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { createInterface } from 'node:readline/promises';
|
|
2
|
+
export function isTty() {
|
|
3
|
+
return Boolean(process.stdin.isTTY && process.stderr.isTTY);
|
|
4
|
+
}
|
|
5
|
+
export async function prompt(text) {
|
|
6
|
+
if (!isTty())
|
|
7
|
+
throw new Error(`Interactive input required but not a TTY: ${text}`);
|
|
8
|
+
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
9
|
+
try {
|
|
10
|
+
return (await rl.question(text)).trim();
|
|
11
|
+
}
|
|
12
|
+
finally {
|
|
13
|
+
rl.close();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export async function secret(text = 'Value (input hidden): ') {
|
|
17
|
+
const input = process.stdin, output = process.stderr;
|
|
18
|
+
if (!input.isTTY || !output.isTTY || !input.setRawMode)
|
|
19
|
+
throw new Error('Hidden input requires a TTY.');
|
|
20
|
+
output.write(text);
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
let value = '';
|
|
23
|
+
const finish = (error) => { input.setRawMode(false); input.pause(); input.removeListener('data', onData); output.write('\n'); error ? reject(error) : resolve(value); };
|
|
24
|
+
const onData = (chunk) => {
|
|
25
|
+
for (const byte of chunk) {
|
|
26
|
+
if (byte === 3)
|
|
27
|
+
return finish(new Error('Cancelled.'));
|
|
28
|
+
if (byte === 13 || byte === 10)
|
|
29
|
+
return finish();
|
|
30
|
+
if (byte === 8 || byte === 127)
|
|
31
|
+
value = value.slice(0, -1);
|
|
32
|
+
else
|
|
33
|
+
value += String.fromCharCode(byte);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
input.setRawMode(true);
|
|
37
|
+
input.resume();
|
|
38
|
+
input.on('data', onData);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
export async function confirm(text, defaultYes = false) {
|
|
42
|
+
if (!isTty())
|
|
43
|
+
return defaultYes;
|
|
44
|
+
const suffix = defaultYes ? ' [Y/n]' : ' [y/N]';
|
|
45
|
+
const answer = (await prompt(`${text}${suffix}: `)).toLowerCase();
|
|
46
|
+
if (answer === '')
|
|
47
|
+
return defaultYes;
|
|
48
|
+
return answer === 'y' || answer === 'yes';
|
|
49
|
+
}
|
|
50
|
+
/** If value is already set, return it. Otherwise interactively prompt. Returns undefined if not a TTY and no value. */
|
|
51
|
+
export async function requiredString(value, promptText) {
|
|
52
|
+
if (value)
|
|
53
|
+
return value;
|
|
54
|
+
if (!isTty())
|
|
55
|
+
return undefined;
|
|
56
|
+
return await prompt(promptText);
|
|
57
|
+
}
|
|
58
|
+
export async function requiredNumber(value, promptText) {
|
|
59
|
+
if (value) {
|
|
60
|
+
const n = Number(value);
|
|
61
|
+
if (Number.isSafeInteger(n))
|
|
62
|
+
return n;
|
|
63
|
+
}
|
|
64
|
+
if (!isTty())
|
|
65
|
+
return undefined;
|
|
66
|
+
while (true) {
|
|
67
|
+
const answer = await prompt(promptText);
|
|
68
|
+
const n = Number(answer);
|
|
69
|
+
if (Number.isSafeInteger(n))
|
|
70
|
+
return n;
|
|
71
|
+
process.stderr.write('Enter a valid integer.\n');
|
|
72
|
+
}
|
|
73
|
+
}
|