@sortlist/cli 0.26.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/.published +1 -0
- package/README.md +145 -0
- package/bin/sl.mjs +73 -0
- package/codegen.ts +36 -0
- package/package.json +62 -0
- package/src/commands/chat/chat.ts +302 -0
- package/src/commands/chat/interactive/App.tsx +119 -0
- package/src/commands/chat/interactive/components/ChatInput.tsx +115 -0
- package/src/commands/chat/interactive/components/ChoicePrompt.tsx +35 -0
- package/src/commands/chat/interactive/components/MessageView.tsx +63 -0
- package/src/commands/chat/interactive/components/ThinkingBox.tsx +54 -0
- package/src/commands/chat/interactive/connection.ts +111 -0
- package/src/commands/chat/interactive/debug-log.ts +19 -0
- package/src/commands/chat/interactive/hooks/useChat.ts +440 -0
- package/src/commands/chat/interactive/hooks/useTerminalSize.ts +23 -0
- package/src/commands/chat/interactive/index.tsx +26 -0
- package/src/commands/chat/interactive/markdown.ts +29 -0
- package/src/commands/chat/interactive/types.ts +34 -0
- package/src/commands/config.ts +94 -0
- package/src/commands/dynamic.ts +396 -0
- package/src/commands/login.ts +191 -0
- package/src/commands/logout.ts +43 -0
- package/src/commands/offer.ts +96 -0
- package/src/commands/switch.ts +72 -0
- package/src/commands/token.ts +23 -0
- package/src/commands/whoami.ts +50 -0
- package/src/graphql/client.ts +257 -0
- package/src/graphql/generated/gql.ts +106 -0
- package/src/graphql/generated/graphql.ts +7732 -0
- package/src/graphql/generated/index.ts +1 -0
- package/src/graphql/introspection.ts +240 -0
- package/src/graphql/operations/common.ts +115 -0
- package/src/graphql/operations/hermes.ts +54 -0
- package/src/graphql/query-builder.ts +236 -0
- package/src/index.ts +176 -0
- package/src/lib/auth.ts +58 -0
- package/src/lib/browser.ts +6 -0
- package/src/lib/company.ts +35 -0
- package/src/lib/config.ts +73 -0
- package/src/lib/env.ts +10 -0
- package/src/lib/output.ts +84 -0
- package/src/lib/parse.ts +8 -0
- package/src/lib/sentry.ts +77 -0
- package/src/lib/sequence-buffer.ts +95 -0
- package/src/lib/version-check.ts +88 -0
- package/src/types/marked-terminal.d.ts +20 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
|
|
4
|
+
import { isLocalDev } from './env.ts';
|
|
5
|
+
import { error, hint, info, success, warn } from './output.ts';
|
|
6
|
+
|
|
7
|
+
const PACKAGE_NAME = '@sortlist/cli';
|
|
8
|
+
|
|
9
|
+
function getCurrentVersion(): string {
|
|
10
|
+
const pkg = JSON.parse(fs.readFileSync(new URL('../../package.json', import.meta.url), 'utf-8'));
|
|
11
|
+
return pkg.version;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
async function fetchLatestVersion(): Promise<string | null> {
|
|
15
|
+
try {
|
|
16
|
+
const controller = new AbortController();
|
|
17
|
+
const timeout = setTimeout(() => controller.abort(), 3000);
|
|
18
|
+
const res = await fetch(`https://registry.npmjs.org/${encodeURIComponent(PACKAGE_NAME)}/latest`, {
|
|
19
|
+
signal: controller.signal,
|
|
20
|
+
});
|
|
21
|
+
clearTimeout(timeout);
|
|
22
|
+
if (!res.ok) return null;
|
|
23
|
+
const data = (await res.json()) as { version: string };
|
|
24
|
+
return data.version;
|
|
25
|
+
} catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function parseSemver(version: string): [number, number, number] {
|
|
31
|
+
const [major, minor, patch] = version.split('.').map(Number);
|
|
32
|
+
return [major ?? 0, minor ?? 0, patch ?? 0];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function autoUpdate(current: string, latest: string): void {
|
|
36
|
+
info(`Updating ${PACKAGE_NAME}: ${current} \u2192 ${latest}...`);
|
|
37
|
+
|
|
38
|
+
try {
|
|
39
|
+
// Clean stale temp directories that cause ENOTEMPTY errors. npm stages a
|
|
40
|
+
// package under a sibling `.<name>-<hash>` dir; for scoped names the dot
|
|
41
|
+
// sits on the final segment, e.g. `@sortlist/.cli-<hash>`.
|
|
42
|
+
const prefix = execFileSync('npm', ['prefix', '-g'], { stdio: 'pipe', encoding: 'utf-8' }).trim();
|
|
43
|
+
const lastSlash = PACKAGE_NAME.lastIndexOf('/');
|
|
44
|
+
const scope = lastSlash === -1 ? '' : `${PACKAGE_NAME.slice(0, lastSlash)}/`;
|
|
45
|
+
const name = lastSlash === -1 ? PACKAGE_NAME : PACKAGE_NAME.slice(lastSlash + 1);
|
|
46
|
+
const staleDir = `${prefix}/lib/node_modules/${scope}.${name}-`;
|
|
47
|
+
execFileSync('sh', ['-c', `rm -rf "${staleDir}"* 2>/dev/null || true`], { stdio: 'pipe' });
|
|
48
|
+
|
|
49
|
+
execFileSync('npm', ['install', '-g', '--prefer-online', `${PACKAGE_NAME}@${latest}`], {
|
|
50
|
+
stdio: 'pipe',
|
|
51
|
+
});
|
|
52
|
+
success(`Updated to ${latest}. Restart \`sl\` to use the new version.`);
|
|
53
|
+
} catch (err) {
|
|
54
|
+
const stderr = err && typeof err === 'object' && 'stderr' in err ? String(err.stderr).trim() : '';
|
|
55
|
+
const detail = stderr ? ` (${stderr.split('\n')[0]})` : '';
|
|
56
|
+
warn(`Auto-update failed${detail}.`);
|
|
57
|
+
hint(`Run \`npm i -g ${PACKAGE_NAME}\` to update manually.`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Checks npm for the latest version.
|
|
63
|
+
* - Major mismatch: blocks execution and exits.
|
|
64
|
+
* - Minor/patch mismatch: auto-updates with a spinner, then continues.
|
|
65
|
+
*/
|
|
66
|
+
export async function checkForUpdates(): Promise<void> {
|
|
67
|
+
if (isLocalDev) return;
|
|
68
|
+
|
|
69
|
+
const current = getCurrentVersion();
|
|
70
|
+
const latest = await fetchLatestVersion();
|
|
71
|
+
if (!latest || latest === current) return;
|
|
72
|
+
|
|
73
|
+
const [curMajor] = parseSemver(current);
|
|
74
|
+
const [latMajor] = parseSemver(latest);
|
|
75
|
+
|
|
76
|
+
if (latMajor > curMajor) {
|
|
77
|
+
error(`Breaking update: ${current} \u2192 ${latest}`);
|
|
78
|
+
info('');
|
|
79
|
+
info(' Your CLI is incompatible with the current API.');
|
|
80
|
+
info(' Update before continuing:');
|
|
81
|
+
info('');
|
|
82
|
+
info(` npm i -g ${PACKAGE_NAME}`);
|
|
83
|
+
info('');
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
autoUpdate(current, latest);
|
|
88
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
declare module 'marked-terminal' {
|
|
2
|
+
import type { MarkedExtension } from 'marked';
|
|
3
|
+
|
|
4
|
+
interface MarkedTerminalOptions {
|
|
5
|
+
reflowText?: boolean;
|
|
6
|
+
width?: number;
|
|
7
|
+
tab?: number;
|
|
8
|
+
showSectionPrefix?: boolean;
|
|
9
|
+
unescape?: boolean;
|
|
10
|
+
emoji?: boolean;
|
|
11
|
+
tableOptions?: Record<string, unknown>;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function markedTerminal(
|
|
15
|
+
options?: MarkedTerminalOptions,
|
|
16
|
+
highlightOptions?: Record<string, unknown>,
|
|
17
|
+
): MarkedExtension;
|
|
18
|
+
|
|
19
|
+
export default class Renderer {}
|
|
20
|
+
}
|