@superpanel-sdk/cli 0.0.0-stage → 0.1.1
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/README.md +16 -2
- package/bin/superpanel.mjs +23 -0
- package/dist/api/platform.d.ts +31 -0
- package/dist/api/platform.js +39 -0
- package/dist/auth/auth.d.ts +162 -0
- package/dist/auth/auth.js +923 -0
- package/dist/auth/backend-url.d.ts +7 -0
- package/dist/auth/backend-url.js +41 -0
- package/dist/auth/cli-login.d.ts +8 -0
- package/dist/auth/cli-login.js +92 -0
- package/dist/auth/clipboard.d.ts +8 -0
- package/dist/auth/clipboard.js +42 -0
- package/dist/auth/file-lock.d.ts +25 -0
- package/dist/auth/file-lock.js +173 -0
- package/dist/auth/http.d.ts +34 -0
- package/dist/auth/http.js +48 -0
- package/dist/auth/index.d.ts +13 -0
- package/dist/auth/index.js +117 -0
- package/dist/auth/origin-guard.d.ts +4 -0
- package/dist/auth/origin-guard.js +9 -0
- package/dist/auth/origin.d.ts +17 -0
- package/dist/auth/origin.js +142 -0
- package/dist/auth/pending-login.d.ts +5 -0
- package/dist/auth/pending-login.js +67 -0
- package/dist/commands/auth-token.d.ts +26 -0
- package/dist/commands/auth-token.js +71 -0
- package/dist/commands/git-method.d.ts +54 -0
- package/dist/commands/git-method.js +180 -0
- package/dist/commands/setup.d.ts +88 -0
- package/dist/commands/setup.js +366 -0
- package/dist/commands/skill.d.ts +29 -0
- package/dist/commands/skill.js +169 -0
- package/dist/commands/ssh-key.d.ts +13 -0
- package/dist/commands/ssh-key.js +83 -0
- package/dist/git/credential.d.ts +7 -0
- package/dist/git/credential.js +66 -0
- package/dist/git/index.d.ts +36 -0
- package/dist/git/index.js +119 -0
- package/dist/git/run.d.ts +13 -0
- package/dist/git/run.js +32 -0
- package/dist/git/setup.d.ts +97 -0
- package/dist/git/setup.js +471 -0
- package/dist/handover/clone.d.ts +8 -0
- package/dist/handover/clone.js +39 -0
- package/dist/handover/repo-help.d.ts +7 -0
- package/dist/handover/repo-help.js +55 -0
- package/dist/handover/run.d.ts +5 -0
- package/dist/handover/run.js +67 -0
- package/dist/inbound/index.d.ts +44 -0
- package/dist/inbound/index.js +129 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +251 -0
- package/dist/logs/index.d.ts +19 -0
- package/dist/logs/index.js +132 -0
- package/dist/npm-launch.d.ts +19 -0
- package/dist/npm-launch.js +80 -0
- package/dist/ops/agent.d.ts +3 -0
- package/dist/ops/agent.js +14 -0
- package/dist/ops/cache.d.ts +18 -0
- package/dist/ops/cache.js +92 -0
- package/dist/ops/parse.d.ts +6 -0
- package/dist/ops/parse.js +106 -0
- package/dist/ops/register.d.ts +18 -0
- package/dist/ops/register.js +174 -0
- package/dist/ops/run.d.ts +20 -0
- package/dist/ops/run.js +127 -0
- package/dist/ops/types.d.ts +41 -0
- package/dist/ops/types.js +16 -0
- package/dist/protocol.d.ts +4 -0
- package/dist/protocol.js +17 -0
- package/dist/reserved.d.ts +4 -0
- package/dist/reserved.js +25 -0
- package/dist/turns/index.d.ts +20 -0
- package/dist/turns/index.js +108 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +11 -0
- package/package.json +48 -4
- package/skill/SKILL.md +17 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export declare const KNOWN_OPS_FORMAT = 1;
|
|
2
|
+
export declare const KNOWN_PARAM_TYPES: readonly ['string', 'integer', 'boolean', 'enum', 'kv', 'json'];
|
|
3
|
+
export type OpParam = {
|
|
4
|
+
name: string;
|
|
5
|
+
type: string;
|
|
6
|
+
required?: boolean;
|
|
7
|
+
description: string;
|
|
8
|
+
enum?: readonly string[];
|
|
9
|
+
place: string;
|
|
10
|
+
};
|
|
11
|
+
export type OpConfirm = {
|
|
12
|
+
when: string;
|
|
13
|
+
param: string;
|
|
14
|
+
argument: string;
|
|
15
|
+
};
|
|
16
|
+
export type PublicOp = {
|
|
17
|
+
name: string;
|
|
18
|
+
command: string;
|
|
19
|
+
description: string;
|
|
20
|
+
params: OpParam[];
|
|
21
|
+
entrances: string[];
|
|
22
|
+
mutates: boolean;
|
|
23
|
+
destructive: boolean;
|
|
24
|
+
confirm?: OpConfirm;
|
|
25
|
+
};
|
|
26
|
+
export type OpsList = {
|
|
27
|
+
formatVersion: number;
|
|
28
|
+
backendVersion: string;
|
|
29
|
+
ops: PublicOp[];
|
|
30
|
+
};
|
|
31
|
+
export type ListedEnvironment = {
|
|
32
|
+
id: string;
|
|
33
|
+
name: string;
|
|
34
|
+
prod: boolean;
|
|
35
|
+
};
|
|
36
|
+
export declare function confirmationOptionHelp(action: string): string;
|
|
37
|
+
export declare class NeedsPersonError extends Error {
|
|
38
|
+
readonly reason: 'confirmation_required';
|
|
39
|
+
constructor(message: string);
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const KNOWN_OPS_FORMAT = 1;
|
|
2
|
+
export const KNOWN_PARAM_TYPES = ['string', 'integer', 'boolean', 'enum', 'kv', 'json'];
|
|
3
|
+
export function confirmationOptionHelp(action) {
|
|
4
|
+
return action + '. Omit unless the user explicitly chose this option.';
|
|
5
|
+
}
|
|
6
|
+
const CHOICE_GUIDANCE = 'Relay any recommendation the CLI gives for that specific choice. Present other choices neutrally. Never preselect an answer.';
|
|
7
|
+
export class NeedsPersonError extends Error {
|
|
8
|
+
reason = 'confirmation_required';
|
|
9
|
+
constructor(message) {
|
|
10
|
+
super(message +
|
|
11
|
+
'\n' +
|
|
12
|
+
CHOICE_GUIDANCE +
|
|
13
|
+
' Ask the user in chat and wait for their explicit reply. While waiting, do not call tools, check configuration, run commands, or send another message. Use their answer only for the choice they confirmed.');
|
|
14
|
+
this.name = 'NeedsPersonError';
|
|
15
|
+
}
|
|
16
|
+
}
|
package/dist/protocol.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { createRequire } from 'node:module';
|
|
2
|
+
const manifest = createRequire(import.meta.url)('../package.json');
|
|
3
|
+
export const CLI_PROTOCOLS = manifest.superpanel.cliProtocol;
|
|
4
|
+
export function negotiateProtocol(runtimeProtocols) {
|
|
5
|
+
const shared = CLI_PROTOCOLS.filter((version) => runtimeProtocols.includes(version));
|
|
6
|
+
if (shared.length === 0)
|
|
7
|
+
return null;
|
|
8
|
+
return Math.max(...shared);
|
|
9
|
+
}
|
|
10
|
+
export function parseProtocolList(value) {
|
|
11
|
+
return value
|
|
12
|
+
.split(',')
|
|
13
|
+
.map((part) => part.trim())
|
|
14
|
+
.filter((part) => part.length > 0)
|
|
15
|
+
.map((part) => Number(part))
|
|
16
|
+
.filter((version) => Number.isInteger(version) && version > 0);
|
|
17
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const RESERVED_COMMANDS: readonly ['help', 'auth', 'login', 'logout', 'whoami', 'setup', 'setup-git', 'git-credential', 'skill', 'ssh-key', 'env', 'config', 'connection', 'webhook', 'release', 'pr', 'logs', 'inbound', 'turns', 'platform'];
|
|
2
|
+
export type ReservedCommand = (typeof RESERVED_COMMANDS)[number];
|
|
3
|
+
export declare function isReservedCommand(name: string): name is ReservedCommand;
|
|
4
|
+
//# sourceMappingURL=reserved.d.ts.map
|
package/dist/reserved.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export const RESERVED_COMMANDS = [
|
|
2
|
+
'help',
|
|
3
|
+
'auth',
|
|
4
|
+
'login',
|
|
5
|
+
'logout',
|
|
6
|
+
'whoami',
|
|
7
|
+
'setup',
|
|
8
|
+
'setup-git',
|
|
9
|
+
'git-credential',
|
|
10
|
+
'skill',
|
|
11
|
+
'ssh-key',
|
|
12
|
+
'env',
|
|
13
|
+
'config',
|
|
14
|
+
'connection',
|
|
15
|
+
'webhook',
|
|
16
|
+
'release',
|
|
17
|
+
'pr',
|
|
18
|
+
'logs',
|
|
19
|
+
'inbound',
|
|
20
|
+
'turns',
|
|
21
|
+
'platform',
|
|
22
|
+
];
|
|
23
|
+
export function isReservedCommand(name) {
|
|
24
|
+
return RESERVED_COMMANDS.includes(name);
|
|
25
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type TurnsOptions = {
|
|
2
|
+
env?: string;
|
|
3
|
+
instance?: string;
|
|
4
|
+
call?: string;
|
|
5
|
+
run?: string;
|
|
6
|
+
since?: string;
|
|
7
|
+
limit?: number;
|
|
8
|
+
json?: boolean;
|
|
9
|
+
url?: string;
|
|
10
|
+
out?: string;
|
|
11
|
+
};
|
|
12
|
+
type ExportedPage = {
|
|
13
|
+
seq: number;
|
|
14
|
+
auto?: boolean;
|
|
15
|
+
text: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function writeSnapshotPages(dir: string, pages: ExportedPage[] | undefined): void;
|
|
18
|
+
export declare function runTurns(cwd: string, action: string | undefined, turnId: string | undefined, options: TurnsOptions): Promise<void>;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { getValidCliAuthorization, loginCommand, resolveBackendUrl } from '../auth/auth.js';
|
|
4
|
+
import { guardNetworkedClone } from '../auth/origin-guard.js';
|
|
5
|
+
import { apiUrl, requestJson } from '../auth/http.js';
|
|
6
|
+
import { findCloneRoot } from '../handover/clone.js';
|
|
7
|
+
function timeOf(value, now = Date.now()) {
|
|
8
|
+
if (!value)
|
|
9
|
+
return undefined;
|
|
10
|
+
const ago = /^(\d+)\s*(s|m|h|d)$/.exec(value.trim());
|
|
11
|
+
if (ago) {
|
|
12
|
+
const unit = { s: 1_000, m: 60_000, h: 3_600_000, d: 86_400_000 }[ago[2]];
|
|
13
|
+
return new Date(now - Number(ago[1]) * unit).toISOString();
|
|
14
|
+
}
|
|
15
|
+
const at = Date.parse(value);
|
|
16
|
+
if (Number.isNaN(at))
|
|
17
|
+
throw new Error(`${value}: a time is 15m, 2h, 3d (that long ago) or ISO 8601`);
|
|
18
|
+
return new Date(at).toISOString();
|
|
19
|
+
}
|
|
20
|
+
export function writeSnapshotPages(dir, pages) {
|
|
21
|
+
mkdirSync(path.join(dir, 'page'), { recursive: true });
|
|
22
|
+
for (const page of pages ?? []) {
|
|
23
|
+
if (!page.auto)
|
|
24
|
+
writeFileSync(path.join(dir, 'page', `${page.seq}.txt`), page.text);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const clip = (text, max = 80) => {
|
|
28
|
+
const one = (text ?? '').replace(/\s+/g, ' ').trim();
|
|
29
|
+
return one.length > max ? `${one.slice(0, max - 1)}…` : one;
|
|
30
|
+
};
|
|
31
|
+
function formatTurnLine(turn) {
|
|
32
|
+
const parts = [`#${turn.seq} ${turn.kind}`, turn.id];
|
|
33
|
+
if (turn.heard)
|
|
34
|
+
parts.push(`heard "${clip(turn.heard)}"`);
|
|
35
|
+
if (turn.said.length)
|
|
36
|
+
parts.push(`said "${clip(turn.said.join(' '))}"`);
|
|
37
|
+
if (turn.did?.length)
|
|
38
|
+
parts.push(`did ${turn.did.map((item) => item.text).join('; ')}`);
|
|
39
|
+
else if (turn.actions.length)
|
|
40
|
+
parts.push(`did ${turn.actions.map((action) => `${action.key}:${action.status}`).join(', ')}`);
|
|
41
|
+
if (turn.writes.length)
|
|
42
|
+
parts.push(`wrote ${turn.writes.map((write) => `${write.table}.${write.field}`).join(', ')}`);
|
|
43
|
+
if (turn.diagnostics?.length)
|
|
44
|
+
parts.push(`! ${turn.diagnostics.map((item) => item.message).join('; ')}`);
|
|
45
|
+
if (turn.outcome && turn.outcome !== 'done')
|
|
46
|
+
parts.push(turn.outcome);
|
|
47
|
+
if (turn.error)
|
|
48
|
+
parts.push(`error: ${clip(turn.error)}`);
|
|
49
|
+
return parts.join(' ');
|
|
50
|
+
}
|
|
51
|
+
async function postTurns(backendUrl, token, environment, path, body) {
|
|
52
|
+
const { response, payload } = await requestJson(apiUrl(backendUrl, path), {
|
|
53
|
+
method: 'POST',
|
|
54
|
+
headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
|
|
55
|
+
body: JSON.stringify({ environment, ...body }),
|
|
56
|
+
});
|
|
57
|
+
if (response.status === 401)
|
|
58
|
+
throw new Error(`the login was refused: run \`${loginCommand(backendUrl)}\` again`);
|
|
59
|
+
if (!response.ok)
|
|
60
|
+
throw new Error(`turns: ${payload.error ?? `the backend answered ${response.status}`}`);
|
|
61
|
+
return payload;
|
|
62
|
+
}
|
|
63
|
+
export async function runTurns(cwd, action, turnId, options) {
|
|
64
|
+
const backendUrl = resolveBackendUrl(options.url);
|
|
65
|
+
const authorization = await getValidCliAuthorization(backendUrl);
|
|
66
|
+
if (!authorization)
|
|
67
|
+
throw new Error(`not logged in: run "${loginCommand(backendUrl)}" first`);
|
|
68
|
+
await guardNetworkedClone(cwd, backendUrl, authorization.accessToken);
|
|
69
|
+
const repoRoot = findCloneRoot(cwd);
|
|
70
|
+
if (action === undefined) {
|
|
71
|
+
if (!options.instance && !options.call && !options.run)
|
|
72
|
+
throw new Error('turns: name the case (--instance), the call (--call) or the run (--run)');
|
|
73
|
+
const since = timeOf(options.since);
|
|
74
|
+
const { turns } = await postTurns(backendUrl, authorization.accessToken, options.env ?? 'sandbox', 'cli-auth/turns', {
|
|
75
|
+
...(options.instance ? { instanceId: options.instance } : {}),
|
|
76
|
+
...(options.call ? { callId: options.call } : {}),
|
|
77
|
+
...(options.run ? { runId: options.run } : {}),
|
|
78
|
+
...(since ? { since } : {}),
|
|
79
|
+
...(options.limit ? { limit: options.limit } : {}),
|
|
80
|
+
});
|
|
81
|
+
if (!turns.length)
|
|
82
|
+
console.error('no turns');
|
|
83
|
+
for (const turn of turns)
|
|
84
|
+
console.log(options.json ? JSON.stringify(turn) : formatTurnLine(turn));
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (action !== 'export' || !turnId)
|
|
88
|
+
throw new Error('turns: `turns --instance <id>` lists, `turns export <turnId>` writes one');
|
|
89
|
+
const read = await postTurns(backendUrl, authorization.accessToken, options.env ?? 'sandbox', 'cli-auth/turns/read', { turnId });
|
|
90
|
+
if (!repoRoot && !options.out) {
|
|
91
|
+
throw new Error('turns export: pass --out, or run it inside the company repo');
|
|
92
|
+
}
|
|
93
|
+
const dir = path.resolve(options.out ?? path.join(repoRoot, '.superpanel', 'turns', turnId));
|
|
94
|
+
mkdirSync(dir, { recursive: true });
|
|
95
|
+
writeFileSync(path.join(dir, 'turn.json'), `${JSON.stringify(read.turn, null, 2)}\n`);
|
|
96
|
+
if (read.snapshot) {
|
|
97
|
+
writeSnapshotPages(dir, read.snapshot.pages);
|
|
98
|
+
const json = (name, value) => writeFileSync(path.join(dir, name), `${JSON.stringify(value, null, 2)}\n`);
|
|
99
|
+
json('data.json', read.snapshot.data);
|
|
100
|
+
json('context.json', read.snapshot.context);
|
|
101
|
+
json('history.json', read.snapshot.history);
|
|
102
|
+
json('start.json', read.snapshot.start);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
console.error(`turn ${turnId}: its snapshot is no longer kept (30 days); only turn.json was written`);
|
|
106
|
+
}
|
|
107
|
+
console.log(dir);
|
|
108
|
+
}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
let cached;
|
|
4
|
+
export function cliVersion() {
|
|
5
|
+
if (cached)
|
|
6
|
+
return cached;
|
|
7
|
+
const file = fileURLToPath(new URL('../package.json', import.meta.url));
|
|
8
|
+
const pkg = JSON.parse(readFileSync(file, 'utf8'));
|
|
9
|
+
cached = pkg.version ?? '0.0.0';
|
|
10
|
+
return cached;
|
|
11
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,50 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superpanel-sdk/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"superpanel": {
|
|
5
|
+
"cliProtocol": [
|
|
6
|
+
1
|
|
7
|
+
]
|
|
8
|
+
},
|
|
9
|
+
"description": "Superpanel CLI: login, platform commands, and handover into a company repo",
|
|
10
|
+
"license": "UNLICENSED",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=22.15"
|
|
14
|
+
},
|
|
15
|
+
"bin": {
|
|
16
|
+
"superpanel": "./bin/superpanel.mjs"
|
|
17
|
+
},
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js",
|
|
22
|
+
"default": "./dist/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./package.json": "./package.json"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"bin/**/*.mjs",
|
|
28
|
+
"dist/**/*.js",
|
|
29
|
+
"dist/**/*.d.ts",
|
|
30
|
+
"skill/**"
|
|
31
|
+
],
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsc -p tsconfig.json",
|
|
37
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
38
|
+
"test": "tsx --test tests/**/*.test.ts"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"commander": "^15.0.0"
|
|
42
|
+
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@types/node": "^26.1.1",
|
|
45
|
+
"tsx": "^4.23.1",
|
|
46
|
+
"typescript": "7.0.2",
|
|
47
|
+
"yaml": "2.8.1"
|
|
48
|
+
},
|
|
49
|
+
"superpanelSourceCommit": "1ceef88e8e0ccb0e825132341805105eea986f86"
|
|
50
|
+
}
|
package/skill/SKILL.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: superpanel
|
|
3
|
+
description: >-
|
|
4
|
+
Superpanel platform CLI (superpanel): a company's environments, release results, pull requests into main, env connections, SSH keys on the Git account. Load before running superpanel commands, or when the person asks about a Superpanel environment, release or pull request.
|
|
5
|
+
metadata:
|
|
6
|
+
cli-version: 0.1.1
|
|
7
|
+
managed-by: superpanel-cli
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
- Commands come from the backend you are logged in to. Run `superpanel --help` and `superpanel <command> --help` before using one you have not seen.
|
|
11
|
+
- First check it is installed and logged in: `superpanel whoami`. Not found: ask the person to install it (the command is on the Backstage page of the Superpanel web app). Never run `npx superpanel` (another package).
|
|
12
|
+
- In the company repo, read its AGENTS.md first. The fixed steps are the package.json scripts: `npm run typecheck`, `npm run type:gen`, `npm test`, `npm run test:coverage`, `npm run test:integration`, `npm run serve`. Other repo commands are `superpanel type:gen --watch`, `superpanel brief check`, and so on. Run `superpanel --help` for those. Do not add npm scripts for them.
|
|
13
|
+
- To ship: push a branch, point an environment at it, then check the release status. To prod: open a pull request into main and give the person the URL; they merge it.
|
|
14
|
+
- Never take a secret (API key, token, password) in the conversation: give the person a link from `superpanel config link` and they fill it in on the web page.
|
|
15
|
+
- Exit code 2 has a reason. confirmation_required: stop and ask the person, then rerun with the flags the output names (for example --allow-prod "<their words>"). authorization_pending: ask the person to approve in the browser, then rerun.
|
|
16
|
+
|
|
17
|
+
Deployment and local integration runs require the current repository runtime. Platform commands, login and HTTPS Git require the current CLI. Follow the upgrade command in the refusal message.
|