@solti/cli 0.1.1 → 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/README.md +18 -1
- package/dist/api/client.js +18 -1
- package/dist/auth/oauth.js +107 -37
- package/dist/commands/cronjob.js +24 -0
- package/dist/commands/job.js +16 -5
- package/dist/commands/workflow.js +76 -0
- package/dist/index.js +78 -5
- package/dist/lib/parse.js +49 -0
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Command-line interface for the [Solti Platform](https://solti.run) — schedule and run asynchronous workloads without managing infrastructure.
|
|
4
4
|
|
|
5
|
+
**Packages:** `@solti/cli` (npm) · `solti-cli` (PyPI) · **License:** MIT
|
|
6
|
+
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
7
9
|
```bash
|
|
@@ -15,6 +17,13 @@ npm install -g @solti/cli
|
|
|
15
17
|
# or: pnpm add -g @solti/cli
|
|
16
18
|
```
|
|
17
19
|
|
|
20
|
+
Or via pip / uv (requires Node.js >= 20 on your PATH):
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install solti-cli
|
|
24
|
+
# or: uv add solti-cli
|
|
25
|
+
```
|
|
26
|
+
|
|
18
27
|
## Quickstart
|
|
19
28
|
|
|
20
29
|
```bash
|
|
@@ -55,4 +64,12 @@ pnpm build
|
|
|
55
64
|
node dist/index.js --help
|
|
56
65
|
```
|
|
57
66
|
|
|
58
|
-
|
|
67
|
+
### PyPI packaging (Change 069)
|
|
68
|
+
|
|
69
|
+
The `solti-cli` Python package vendors a self-contained Node bundle. To
|
|
70
|
+
rebuild it after a code change:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
pnpm build && pnpm bundle:python
|
|
74
|
+
uv build
|
|
75
|
+
```
|
package/dist/api/client.js
CHANGED
|
@@ -69,6 +69,23 @@ export function projectBaseUrl(credentials, apiUrlOverride) {
|
|
|
69
69
|
return GLOBAL_API_URL;
|
|
70
70
|
}
|
|
71
71
|
/** Returns the active profile's `api_url` override, if set. */
|
|
72
|
+
/** Returns the api-url override for the current invocation.
|
|
73
|
+
*
|
|
74
|
+
* Headless env auth (SOLTI_API_KEY set without an explicit SOLTI_PROFILE)
|
|
75
|
+
* bypasses local profile config entirely: otherwise the active profile's
|
|
76
|
+
* `api_url` silently hijacks SOLTI_API_URL and headless requests are routed
|
|
77
|
+
* to the wrong host (observed 2026-10-24 — headless preview requests were
|
|
78
|
+
* served by the live API because the active syslive profile pointed there).
|
|
79
|
+
* With SOLTI_PROFILE set explicitly, that profile's `api_url` wins over the
|
|
80
|
+
* env var (documented precedence); without a profile override, the env var
|
|
81
|
+
* applies. */
|
|
82
|
+
export async function resolveApiUrlOverride() {
|
|
83
|
+
if (process.env.SOLTI_API_KEY && !process.env.SOLTI_PROFILE) {
|
|
84
|
+
return process.env.SOLTI_API_URL ?? null;
|
|
85
|
+
}
|
|
86
|
+
const profileOverride = await profileApiUrlOverride();
|
|
87
|
+
return profileOverride ?? process.env.SOLTI_API_URL ?? null;
|
|
88
|
+
}
|
|
72
89
|
async function profileApiUrlOverride() {
|
|
73
90
|
const account = await getActiveAccount();
|
|
74
91
|
if (account === null)
|
|
@@ -115,7 +132,7 @@ export async function request(path, options = {}) {
|
|
|
115
132
|
}
|
|
116
133
|
}
|
|
117
134
|
else {
|
|
118
|
-
const override = await
|
|
135
|
+
const override = await resolveApiUrlOverride();
|
|
119
136
|
const url = projectBaseUrl(credentials, override);
|
|
120
137
|
if (url === null) {
|
|
121
138
|
throw new Error("No active project. Run `solti profile set <name> --project-id <id>` / `solti project use <id>`, or set SOLTI_PROJECT_ID.");
|
package/dist/auth/oauth.js
CHANGED
|
@@ -1,32 +1,100 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Solti ID (Authorizer) OAuth 2.0 Authorization Code + PKCE flow for the
|
|
3
|
+
* Solti CLI (Change 057f — direct loopback PKCE, no relay, no solti-api
|
|
4
|
+
* token endpoints).
|
|
3
5
|
*
|
|
4
|
-
* Registered
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* -
|
|
8
|
-
* -
|
|
6
|
+
* Registered reserved interactive clients (Change 057b spike; public clients,
|
|
7
|
+
* no secret — authorization_code+PKCE token exchanges need client_id alone,
|
|
8
|
+
* refresh/revoke need client_id + token):
|
|
9
|
+
* - live Authorizer (https://id.solti.run): `113215f1a2a2beeed9f5c6279e3537a2`
|
|
10
|
+
* - dev Authorizer (https://id.dev.solti.run): `b7435147811323ceb1055d8bec85b315`
|
|
11
|
+
* - Redirect URIs http://localhost:4242..4245/callback (exact-match, also
|
|
12
|
+
* registered as allowed origins); scopes `openid offline_access email
|
|
13
|
+
* profile`. No OAuth `resource` param: access tokens are Authorizer JWTs
|
|
14
|
+
* with aud=client_id and solti-api now validates aud=client_id (057e).
|
|
15
|
+
*
|
|
16
|
+
* The DEFAULT issuer is the live one: the CLI's default API host is the live
|
|
17
|
+
* `https://api.solti.run/1`, and the live API rejects dev-issued tokens
|
|
18
|
+
* — the previous dev default made plain `solti account login` unusable
|
|
19
|
+
* against the default API (Change 048). Dev-issuer sign-in remains available
|
|
20
|
+
* via SOLTI_AUTHORIZER_ISSUER / SOLTI_AUTHORIZER_CLIENT_ID (the pre-migration
|
|
21
|
+
* SOLTI_LOGTO_ISSUER / SOLTI_LOGTO_CLIENT_ID names are still honored as
|
|
22
|
+
* deprecated fallbacks so existing env profiles survive the migration).
|
|
23
|
+
* Whichever environment a login used is persisted per account
|
|
24
|
+
* (AuthStore.issuer/client_id) so token refresh and logout hit the same
|
|
25
|
+
* Authorizer instance.
|
|
9
26
|
*/
|
|
10
27
|
import crypto from "node:crypto";
|
|
11
28
|
import http from "node:http";
|
|
12
29
|
import { deleteAuth, getActiveAccount, listAccounts, readActive, readAuth, writeActive, writeAuth, } from "../config/store.js";
|
|
13
|
-
export const CLIENT_ID = process.env.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export const
|
|
17
|
-
|
|
30
|
+
export const CLIENT_ID = process.env.SOLTI_AUTHORIZER_CLIENT_ID ??
|
|
31
|
+
process.env.SOLTI_LOGTO_CLIENT_ID ??
|
|
32
|
+
"113215f1a2a2beeed9f5c6279e3537a2";
|
|
33
|
+
export const ISSUER = process.env.SOLTI_AUTHORIZER_ISSUER ??
|
|
34
|
+
process.env.SOLTI_LOGTO_ISSUER ??
|
|
35
|
+
"https://id.solti.run";
|
|
36
|
+
export const SCOPES = "openid offline_access email profile";
|
|
37
|
+
/** Manual endpoint fallback for issuers whose OIDC discovery is unavailable
|
|
38
|
+
* (Change 057b evidence: Authorizer serves the standard paths). */
|
|
39
|
+
function fallbackEndpoints(issuer) {
|
|
40
|
+
return {
|
|
41
|
+
authorization_endpoint: `${issuer}/authorize`,
|
|
42
|
+
token_endpoint: `${issuer}/oauth/token`,
|
|
43
|
+
userinfo_endpoint: `${issuer}/userinfo`,
|
|
44
|
+
revocation_endpoint: `${issuer}/oauth/revoke`,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/** Decodes JWT payload claims (no signature check — best-effort hints only). */
|
|
48
|
+
function decodeJwtClaims(token) {
|
|
49
|
+
if (token === undefined)
|
|
50
|
+
return null;
|
|
51
|
+
const parts = token.split(".");
|
|
52
|
+
if (parts.length !== 3)
|
|
53
|
+
return null;
|
|
54
|
+
try {
|
|
55
|
+
return JSON.parse(Buffer.from(parts[1], "base64url").toString("utf8"));
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** Per-account OIDC resolution for refresh/logout (pure — unit-tested). */
|
|
62
|
+
export function resolveOidc(auth) {
|
|
63
|
+
const claims = decodeJwtClaims(auth.access_token);
|
|
64
|
+
const issuer = auth.issuer ??
|
|
65
|
+
(typeof claims?.iss === "string" && claims.iss !== "" ? claims.iss : null) ??
|
|
66
|
+
ISSUER;
|
|
67
|
+
const clientId = auth.client_id ??
|
|
68
|
+
(typeof claims?.client_id === "string" && claims.client_id !== "" ? claims.client_id : null) ??
|
|
69
|
+
CLIENT_ID;
|
|
70
|
+
return { issuer, clientId };
|
|
71
|
+
}
|
|
72
|
+
/** Fixed registered loopback port range (spec §1.1 / logto-changes.md §5.1).
|
|
73
|
+
* The listener binds dual-stack (no explicit host) so browsers resolving
|
|
74
|
+
* `localhost` to ::1 still reach the callback server (observed in the 057f
|
|
75
|
+
* e2e: Chromium connected to ::1 only). */
|
|
18
76
|
const CALLBACK_PORTS = [4242, 4243, 4244, 4245];
|
|
19
77
|
const CALLBACK_PATH = "/callback";
|
|
20
|
-
|
|
21
|
-
export async function discover() {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
78
|
+
const discoveryCache = new Map();
|
|
79
|
+
export async function discover(issuer = ISSUER) {
|
|
80
|
+
const cached = discoveryCache.get(issuer);
|
|
81
|
+
if (cached !== undefined)
|
|
82
|
+
return cached;
|
|
83
|
+
try {
|
|
84
|
+
const response = await fetch(`${issuer}/.well-known/openid-configuration`);
|
|
85
|
+
if (!response.ok) {
|
|
86
|
+
throw new Error(`HTTP ${response.status}`);
|
|
87
|
+
}
|
|
88
|
+
const discovery = (await response.json());
|
|
89
|
+
discoveryCache.set(issuer, discovery);
|
|
90
|
+
return discovery;
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
// Discovery unavailable — fall back to the standard Authorizer paths.
|
|
94
|
+
const discovery = fallbackEndpoints(issuer);
|
|
95
|
+
discoveryCache.set(issuer, discovery);
|
|
96
|
+
return discovery;
|
|
27
97
|
}
|
|
28
|
-
discoveryCache = (await response.json());
|
|
29
|
-
return discoveryCache;
|
|
30
98
|
}
|
|
31
99
|
function base64url(buffer) {
|
|
32
100
|
return buffer.toString("base64url");
|
|
@@ -60,13 +128,9 @@ export async function login(options) {
|
|
|
60
128
|
authorizationUrl.searchParams.set("client_id", CLIENT_ID);
|
|
61
129
|
authorizationUrl.searchParams.set("redirect_uri", redirectUri);
|
|
62
130
|
authorizationUrl.searchParams.set("scope", SCOPES);
|
|
63
|
-
authorizationUrl.searchParams.set("resource", RESOURCE);
|
|
64
131
|
authorizationUrl.searchParams.set("code_challenge", codeChallenge);
|
|
65
132
|
authorizationUrl.searchParams.set("code_challenge_method", "S256");
|
|
66
133
|
authorizationUrl.searchParams.set("state", state);
|
|
67
|
-
// LogTo only issues a refresh token when `prompt=consent` is requested
|
|
68
|
-
// (first-party apps skip the visible consent screen).
|
|
69
|
-
authorizationUrl.searchParams.set("prompt", "consent");
|
|
70
134
|
if (launchBrowser) {
|
|
71
135
|
console.log(`Opening browser for sign-in:\n ${authorizationUrl.toString()}\n`);
|
|
72
136
|
openBrowser(authorizationUrl.toString());
|
|
@@ -77,7 +141,7 @@ export async function login(options) {
|
|
|
77
141
|
const code = await waitForCallback(server, state);
|
|
78
142
|
server.close();
|
|
79
143
|
const tokens = (await exchangeCode(oidc, code, redirectUri, codeVerifier));
|
|
80
|
-
// Diagnostics: help identify what
|
|
144
|
+
// Diagnostics: help identify what the issuer actually granted.
|
|
81
145
|
if (tokens.access_token.split(".").length !== 3) {
|
|
82
146
|
console.error("(warning: access token is opaque, not a JWT — the API resource was not bound to the grant)");
|
|
83
147
|
}
|
|
@@ -94,6 +158,10 @@ export async function login(options) {
|
|
|
94
158
|
expires_at: new Date(Date.now() + tokens.expires_in * 1000).toISOString(),
|
|
95
159
|
token_type: tokens.token_type ?? "Bearer",
|
|
96
160
|
email,
|
|
161
|
+
// Persist the environment this login used so refresh/logout stay on the
|
|
162
|
+
// same Authorizer instance (Change 048, retargeted by 057f).
|
|
163
|
+
issuer: ISSUER,
|
|
164
|
+
client_id: CLIENT_ID,
|
|
97
165
|
};
|
|
98
166
|
await writeAuth(email, auth);
|
|
99
167
|
// Switch the active account (adds the account if another one was active).
|
|
@@ -121,7 +189,7 @@ function bindCallbackServer() {
|
|
|
121
189
|
reject(error);
|
|
122
190
|
}
|
|
123
191
|
});
|
|
124
|
-
server.listen(port,
|
|
192
|
+
server.listen(port, () => {
|
|
125
193
|
resolve(server);
|
|
126
194
|
});
|
|
127
195
|
};
|
|
@@ -172,7 +240,6 @@ async function exchangeCode(oidc, code, redirectUri, codeVerifier) {
|
|
|
172
240
|
redirect_uri: redirectUri,
|
|
173
241
|
client_id: CLIENT_ID,
|
|
174
242
|
code_verifier: codeVerifier,
|
|
175
|
-
resource: RESOURCE,
|
|
176
243
|
}),
|
|
177
244
|
});
|
|
178
245
|
if (!response.ok) {
|
|
@@ -221,7 +288,7 @@ export async function ensureFreshAccessToken(email) {
|
|
|
221
288
|
}
|
|
222
289
|
const expiresAt = Date.parse(auth.expires_at);
|
|
223
290
|
const refreshThreshold = Date.now() + 5 * 60 * 1000;
|
|
224
|
-
// An opaque access token is useless against
|
|
291
|
+
// An opaque (non-JWT) access token is useless against JWT-verifying APIs —
|
|
225
292
|
// treat it as stale and refresh into a JWT.
|
|
226
293
|
const isJwt = auth.access_token.split(".").length === 3;
|
|
227
294
|
if (Number.isFinite(expiresAt) && expiresAt > refreshThreshold && isJwt) {
|
|
@@ -230,29 +297,31 @@ export async function ensureFreshAccessToken(email) {
|
|
|
230
297
|
if (auth.refresh_token === "") {
|
|
231
298
|
throw new Error(`Session for ${email} expired and no refresh token is stored. Run \`solti account login\`.`);
|
|
232
299
|
}
|
|
233
|
-
const
|
|
300
|
+
const { issuer, clientId } = resolveOidc(auth);
|
|
301
|
+
const oidc = await discover(issuer);
|
|
234
302
|
const response = await fetch(oidc.token_endpoint, {
|
|
235
303
|
method: "POST",
|
|
236
304
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
237
305
|
body: new URLSearchParams({
|
|
238
306
|
grant_type: "refresh_token",
|
|
239
307
|
refresh_token: auth.refresh_token,
|
|
240
|
-
client_id:
|
|
241
|
-
// LogTo does not auto-reuse the grant's resource (useGrantedResource=false)
|
|
242
|
-
// — the refreshed access token must explicitly request it to stay a JWT.
|
|
243
|
-
resource: RESOURCE,
|
|
308
|
+
client_id: clientId,
|
|
244
309
|
}),
|
|
245
310
|
});
|
|
246
311
|
if (!response.ok) {
|
|
247
|
-
throw new Error(`Token refresh failed for ${email} (HTTP ${response.status})
|
|
312
|
+
throw new Error(`Token refresh failed for ${email} (HTTP ${response.status}): ` +
|
|
313
|
+
`session expired — run \`solti account login\` again.`);
|
|
248
314
|
}
|
|
249
315
|
const tokens = (await response.json());
|
|
250
316
|
const updated = {
|
|
251
317
|
...auth,
|
|
252
318
|
access_token: tokens.access_token,
|
|
253
|
-
//
|
|
319
|
+
// Authorizer rotates refresh tokens on use — persist the new one.
|
|
254
320
|
refresh_token: tokens.refresh_token ?? auth.refresh_token,
|
|
255
321
|
expires_at: new Date(Date.now() + tokens.expires_in * 1000).toISOString(),
|
|
322
|
+
// Stamp the resolved environment so legacy auth.json entries are upgraded.
|
|
323
|
+
issuer,
|
|
324
|
+
client_id: clientId,
|
|
256
325
|
};
|
|
257
326
|
await writeAuth(email, updated);
|
|
258
327
|
return updated.access_token;
|
|
@@ -262,12 +331,13 @@ export async function logout(email) {
|
|
|
262
331
|
const auth = await readAuth(email);
|
|
263
332
|
if (auth !== null && auth.refresh_token !== "") {
|
|
264
333
|
try {
|
|
265
|
-
const
|
|
334
|
+
const { issuer, clientId } = resolveOidc(auth);
|
|
335
|
+
const oidc = await discover(issuer);
|
|
266
336
|
if (oidc.revocation_endpoint !== undefined) {
|
|
267
337
|
await fetch(oidc.revocation_endpoint, {
|
|
268
338
|
method: "POST",
|
|
269
339
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
270
|
-
body: new URLSearchParams({ token: auth.refresh_token, client_id:
|
|
340
|
+
body: new URLSearchParams({ token: auth.refresh_token, client_id: clientId }),
|
|
271
341
|
});
|
|
272
342
|
}
|
|
273
343
|
}
|
package/dist/commands/cronjob.js
CHANGED
|
@@ -21,6 +21,30 @@ export async function cronjobShow(idOrName) {
|
|
|
21
21
|
console.log(`Image: ${c.job_definition?.image ?? "—"}`);
|
|
22
22
|
console.log(`Last run: ${c.last_triggered_at ?? "Never"}`);
|
|
23
23
|
}
|
|
24
|
+
export async function cronjobWorkflows(idOrName, options = {}) {
|
|
25
|
+
// GET /1/cronjobs/{id_or_name}/workflows (change 092; OpenAPI 0.3.2): the
|
|
26
|
+
// cronjob's workflow-run history — same list envelope as GET /1/workflows
|
|
27
|
+
// (ListWorkflowsResponse). Query params forwarded verbatim; the API
|
|
28
|
+
// validates (status enum 422, limit ≤ 200). No trailing slash: this is a
|
|
29
|
+
// sub-resource route like GET /1/workflows/{id}.
|
|
30
|
+
const query = new URLSearchParams();
|
|
31
|
+
if (options.status !== undefined)
|
|
32
|
+
query.set("status", options.status);
|
|
33
|
+
if (options.limit !== undefined)
|
|
34
|
+
query.set("limit", options.limit);
|
|
35
|
+
if (options.offset !== undefined)
|
|
36
|
+
query.set("offset", options.offset);
|
|
37
|
+
const qs = query.toString();
|
|
38
|
+
const data = (await request(`cronjobs/${idOrName}/workflows${qs ? `?${qs}` : ""}`));
|
|
39
|
+
if (data.workflows.length === 0) {
|
|
40
|
+
console.log(`No workflow runs for ${idOrName} yet.`);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
console.log("NAME | STATUS | CREATED | ENDED");
|
|
44
|
+
for (const workflow of data.workflows) {
|
|
45
|
+
console.log(`${workflow.name} | ${workflow.status} | ${workflow.created_at ?? "—"} | ${workflow.ended_at ?? "—"}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
24
48
|
export async function cronjobCreate(options) {
|
|
25
49
|
// Two forms per tools/cli.md: inline (--image [+ --command/--args]) or a
|
|
26
50
|
// workload YAML/JSON file reused as the job_definition template (--file).
|
package/dist/commands/job.js
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import { request } from "../api/client.js";
|
|
3
|
-
import { parseEnvFile, parseResources, parseVolumeShorthand } from "../lib/parse.js";
|
|
3
|
+
import { parseEnvFile, parseResources, parseRunAfter, parseStringList, parseVolumeShorthand } from "../lib/parse.js";
|
|
4
4
|
export async function jobList(options = {}) {
|
|
5
5
|
// API filters (jobs/dtos.py ListJobsRequest): repeatable `tag=` and
|
|
6
6
|
// `label=` query params; labels are "key:value" ("key=value" accepted).
|
|
7
|
+
// Commander keeps a non-collect option as a scalar when used once, so
|
|
8
|
+
// coerce to arrays here (a bare string would otherwise iterate chars).
|
|
9
|
+
const tags = parseStringList(options.tag);
|
|
10
|
+
const labels = parseStringList(options.label);
|
|
7
11
|
const query = new URLSearchParams();
|
|
8
|
-
for (const tag of
|
|
12
|
+
for (const tag of tags)
|
|
9
13
|
query.append("tag", tag);
|
|
10
|
-
for (const label of
|
|
14
|
+
for (const label of labels) {
|
|
11
15
|
if (!label.includes(":") && !label.includes("=")) {
|
|
12
16
|
throw new Error(`Invalid --label '${label}' — expected key:value (or key=value)`);
|
|
13
17
|
}
|
|
@@ -93,6 +97,10 @@ export async function jobRun(options) {
|
|
|
93
97
|
name: options.name,
|
|
94
98
|
namePrefix: options.namePrefix,
|
|
95
99
|
maxRetries: options.maxRetries !== undefined ? Number(options.maxRetries) : undefined,
|
|
100
|
+
// Change 090: validated timezone-aware datetime — the job stays queued
|
|
101
|
+
// (no VM, zero cost) until the instant passes. Sent verbatim; the API
|
|
102
|
+
// normalizes aware values to UTC.
|
|
103
|
+
runAfter: options.runAfter !== undefined ? parseRunAfter(options.runAfter) : undefined,
|
|
96
104
|
env: {
|
|
97
105
|
// --env-from-file provides the base set; explicit --env flags win.
|
|
98
106
|
...(options.envFromFile !== undefined ? parseEnvFile(readEnvFile(options.envFromFile)) : {}),
|
|
@@ -122,8 +130,11 @@ export async function jobRun(options) {
|
|
|
122
130
|
})),
|
|
123
131
|
labels: Object.fromEntries((options.label ?? []).map((l) => l.split("=", 2))),
|
|
124
132
|
tags: options.tag,
|
|
125
|
-
|
|
126
|
-
|
|
133
|
+
// Arrays only — Change 048: the API accepts the documented scalar form
|
|
134
|
+
// (`cloud: aws`) but a scalar JSON string in jobs.cloud 500s every
|
|
135
|
+
// /1/jobs* read, so the CLI always sends arrays.
|
|
136
|
+
cloud: parseStringList(options.cloud).length > 0 ? parseStringList(options.cloud) : undefined,
|
|
137
|
+
region: parseStringList(options.region).length > 0 ? parseStringList(options.region) : undefined,
|
|
127
138
|
};
|
|
128
139
|
if (options.resources !== undefined) {
|
|
129
140
|
const parsed = parseResources(options.resources);
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { request } from "../api/client.js";
|
|
3
|
+
export async function workflowSubmit(file, options = {}) {
|
|
4
|
+
const raw = fs.readFileSync(file, "utf8");
|
|
5
|
+
// Same JSON-then-YAML loading as `solti job run -f` (jobRun).
|
|
6
|
+
let parsed;
|
|
7
|
+
try {
|
|
8
|
+
parsed = JSON.parse(raw);
|
|
9
|
+
}
|
|
10
|
+
catch {
|
|
11
|
+
const { parse } = await import("yaml");
|
|
12
|
+
parsed = parse(raw);
|
|
13
|
+
}
|
|
14
|
+
const templates = parsed.templates;
|
|
15
|
+
if (!Array.isArray(templates) || templates.length === 0) {
|
|
16
|
+
throw new Error(`Invalid workflow file '${file}' — expected an object with a non-empty \`templates\` list (WorkflowCreateRequest)`);
|
|
17
|
+
}
|
|
18
|
+
// Explicit flags win over name/namePrefix carried in the file (091 D-3).
|
|
19
|
+
const payload = {
|
|
20
|
+
name: options.name ?? parsed.name,
|
|
21
|
+
namePrefix: options.namePrefix ?? parsed.namePrefix,
|
|
22
|
+
templates,
|
|
23
|
+
};
|
|
24
|
+
// Trailing slash: collection routes live at /1/workflows/ (see jobList —
|
|
25
|
+
// a bare /1/workflows 307-redirects behind the TLS-terminating LB).
|
|
26
|
+
const workflow = (await request("workflows/", { method: "POST", body: payload }));
|
|
27
|
+
console.log(`Workflow submitted: ${workflow.name} (${workflow.workflow_id ?? workflow.id}) — ${workflow.status}`);
|
|
28
|
+
}
|
|
29
|
+
export async function workflowGet(idOrName) {
|
|
30
|
+
const workflow = (await request(`workflows/${idOrName}`));
|
|
31
|
+
console.log(`Name: ${workflow.name}`);
|
|
32
|
+
console.log(`ID: ${workflow.id}`);
|
|
33
|
+
console.log(`Status: ${workflow.status}`);
|
|
34
|
+
if (workflow.error_message)
|
|
35
|
+
console.log(`Error: ${workflow.error_message}`);
|
|
36
|
+
console.log(`Nodes: ${workflow.node_count ?? workflow.nodes?.length ?? "—"}`);
|
|
37
|
+
console.log(`Cost (EST): ${workflow.estimated_cost ?? "—"}`);
|
|
38
|
+
console.log(`Cost (ACT): ${workflow.actual_cost ?? "—"}`);
|
|
39
|
+
console.log("\nNODE | STATUS | VM STATUS | JOB ID | COST (EST/ACT) | ERROR");
|
|
40
|
+
for (const node of workflow.nodes ?? []) {
|
|
41
|
+
console.log(`${node.name} | ${node.status} | ${node.vm_status ?? "—"} | ${node.job_id} | ${node.estimated_cost ?? "—"}/${node.actual_cost ?? "—"} | ${node.error_message ?? "—"}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export async function workflowList(options = {}) {
|
|
45
|
+
// GET /1/workflows query params: status (running|succeeded|failed|cancelled),
|
|
46
|
+
// limit (default 50/max 200), offset. Forwarded verbatim; the API validates.
|
|
47
|
+
const query = new URLSearchParams();
|
|
48
|
+
if (options.status !== undefined)
|
|
49
|
+
query.set("status", options.status);
|
|
50
|
+
if (options.limit !== undefined)
|
|
51
|
+
query.set("limit", options.limit);
|
|
52
|
+
if (options.offset !== undefined)
|
|
53
|
+
query.set("offset", options.offset);
|
|
54
|
+
const qs = query.toString();
|
|
55
|
+
const data = (await request(`workflows/${qs ? `?${qs}` : ""}`));
|
|
56
|
+
if (data.workflows.length === 0) {
|
|
57
|
+
console.log("No workflows. Submit one with `solti workflow submit <file.yaml>`.");
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
console.log("NAME | STATUS | NODES");
|
|
61
|
+
for (const workflow of data.workflows) {
|
|
62
|
+
console.log(`${workflow.name} | ${workflow.status} | ${workflow.node_count ?? "—"}`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export async function workflowCancel(idOrName, options = {}) {
|
|
66
|
+
// Confirmation pattern mirrors projectDelete/organizationDelete: no
|
|
67
|
+
// interactive prompt — refuse until --yes.
|
|
68
|
+
if (!options.yes) {
|
|
69
|
+
console.error("This cancels every non-terminal node job of the workflow. Re-run with --yes to confirm.");
|
|
70
|
+
process.exitCode = 1;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
// Only valid while the workflow is running (the API 409s otherwise).
|
|
74
|
+
await request(`workflows/${idOrName}/cancel`, { method: "POST" });
|
|
75
|
+
console.log(`Cancellation requested for ${idOrName}.`);
|
|
76
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -9,22 +9,51 @@ import * as organization from "./commands/organization.js";
|
|
|
9
9
|
import * as profile from "./commands/profile.js";
|
|
10
10
|
import * as project from "./commands/project.js";
|
|
11
11
|
import * as resource from "./commands/resource.js";
|
|
12
|
+
import * as workflow from "./commands/workflow.js";
|
|
12
13
|
const program = new Command();
|
|
13
14
|
program
|
|
14
15
|
.name("solti")
|
|
15
16
|
.description("Solti Platform CLI — schedule and run asynchronous workloads without managing infrastructure.")
|
|
16
|
-
.version("0.1.
|
|
17
|
+
.version("0.1.5")
|
|
17
18
|
.option("--profile <name>", "override the active profile (or set SOLTI_PROFILE)")
|
|
18
|
-
.option("--api-key <key>", "override the API key (or set SOLTI_API_KEY)")
|
|
19
|
+
.option("--api-key <key>", "override the API key (or set SOLTI_API_KEY)")
|
|
20
|
+
// Positional options: the root only consumes its options BEFORE the
|
|
21
|
+
// subcommand. Without this, commander's root-level parse swallows an
|
|
22
|
+
// occurrence of --api-key after the subcommand too, so `profile set` (which
|
|
23
|
+
// declares its own --api-key) never sees the value and silently persists
|
|
24
|
+
// null (change 073 follow-up, item 20).
|
|
25
|
+
.enablePositionalOptions();
|
|
26
|
+
// Global override flags must take effect before any command resolves its
|
|
27
|
+
// credentials: every resolution path reads SOLTI_PROFILE / SOLTI_API_KEY from
|
|
28
|
+
// the environment (resolveCredentials, profile stores), so map the explicit
|
|
29
|
+
// flags onto the env vars here. Explicit flags win over a pre-set env var —
|
|
30
|
+
// they are the more specific user intent.
|
|
31
|
+
// Read the ROOT options, not thisCommand's: with enablePositionalOptions a
|
|
32
|
+
// subcommand-local --api-key (`profile set`) never lands here (it must not
|
|
33
|
+
// leak into the global override), and flags placed before the subcommand are
|
|
34
|
+
// stored at the root.
|
|
35
|
+
program.hook("preAction", () => {
|
|
36
|
+
const globalOptions = program.opts();
|
|
37
|
+
if (globalOptions.profile)
|
|
38
|
+
process.env.SOLTI_PROFILE = globalOptions.profile;
|
|
39
|
+
if (globalOptions.apiKey)
|
|
40
|
+
process.env.SOLTI_API_KEY = globalOptions.apiKey;
|
|
41
|
+
});
|
|
19
42
|
function fail(error) {
|
|
20
43
|
console.error(`error: ${error.message}`);
|
|
21
44
|
process.exit(1);
|
|
22
45
|
}
|
|
46
|
+
/** Commander collector for repeatable valued options: each occurrence appends
|
|
47
|
+
* (plain non-collect options overwrite — last value wins). Comma-separated
|
|
48
|
+
* values stay joined here; commands split them via parseStringList. */
|
|
49
|
+
function collectValues(value, previous) {
|
|
50
|
+
return [...previous, value];
|
|
51
|
+
}
|
|
23
52
|
// --- account ----------------------------------------------------------------
|
|
24
53
|
const accountCommand = program.command("account").description("Manage logged-in accounts");
|
|
25
54
|
accountCommand
|
|
26
55
|
.command("login")
|
|
27
|
-
.description("Log in via your browser (
|
|
56
|
+
.description("Log in via your browser (Solti ID)")
|
|
28
57
|
.option("--no-launch-browser", "print the sign-in URL instead of opening a browser")
|
|
29
58
|
.action(async (_args, command) => {
|
|
30
59
|
const { launchBrowser } = command.opts();
|
|
@@ -180,6 +209,7 @@ jobCommand
|
|
|
180
209
|
.option("--name <name>", "explicit job name")
|
|
181
210
|
.option("--name-prefix <prefix>", "prefix for auto-generated names")
|
|
182
211
|
.option("--max-retries <n>", "maximum container retries")
|
|
212
|
+
.option("--run-after <datetime>", "start the job only after this RFC 3339 datetime (timezone required, e.g. 2026-11-25T02:00:00Z) — it stays queued with no VM until the instant passes")
|
|
183
213
|
.option("--env <key=value>", "environment variable (repeatable)")
|
|
184
214
|
.option("--env-from-file <path>", "load KEY=VALUE lines from a .env file (explicit --env flags win)")
|
|
185
215
|
.option("--volume <spec>", "storage volume mount: <bucket>[/<prefix>]:<mountPath> or bucket=<b>,mountPath=<p>[,connection=...][,prefix=...] (repeatable)")
|
|
@@ -187,8 +217,8 @@ jobCommand
|
|
|
187
217
|
.option("--resources <spec>", "e.g. cpu=4,memory=16Gi,gpu=24Gi or gpu.model=A100,gpu.count=2")
|
|
188
218
|
.option("--label <key=value>", "label (repeatable)")
|
|
189
219
|
.option("--tag <tag>", "tag (repeatable)")
|
|
190
|
-
.option("--cloud <provider>", "cloud constraint (aws | gcp | azure)")
|
|
191
|
-
.option("--region <region>", "region constraint")
|
|
220
|
+
.option("--cloud <provider>", "cloud constraint (aws | gcp | azure; repeatable or comma-separated)", collectValues, [])
|
|
221
|
+
.option("--region <region>", "region constraint (repeatable or comma-separated)", collectValues, [])
|
|
192
222
|
.allowUnknownOption(true)
|
|
193
223
|
.argument("[operands...]", "positional command and args (after --)")
|
|
194
224
|
.action(async (_operands, options, command) => {
|
|
@@ -216,6 +246,40 @@ jobCommand
|
|
|
216
246
|
.action(async (jobIdOrName) => {
|
|
217
247
|
await job.jobCancel(jobIdOrName).catch(fail);
|
|
218
248
|
});
|
|
249
|
+
// --- workflow ---------------------------------------------------------------
|
|
250
|
+
const workflowCommand = program
|
|
251
|
+
.command("workflow")
|
|
252
|
+
.description("Manage DAG workflows (templates of standard jobs)");
|
|
253
|
+
workflowCommand
|
|
254
|
+
.command("submit <file>")
|
|
255
|
+
.description("Submit a workflow from a YAML/JSON file (Argo-ish templates payload)")
|
|
256
|
+
.option("--name <name>", "explicit workflow name (overrides the file)")
|
|
257
|
+
.option("--name-prefix <prefix>", "prefix for auto-generated names (overrides the file)")
|
|
258
|
+
.action(async (file, options) => {
|
|
259
|
+
await workflow.workflowSubmit(file, options).catch(fail);
|
|
260
|
+
});
|
|
261
|
+
workflowCommand
|
|
262
|
+
.command("get <id_or_name>")
|
|
263
|
+
.description("Show workflow status and its node jobs")
|
|
264
|
+
.action(async (idOrName) => {
|
|
265
|
+
await workflow.workflowGet(idOrName).catch(fail);
|
|
266
|
+
});
|
|
267
|
+
workflowCommand
|
|
268
|
+
.command("list")
|
|
269
|
+
.description("List recent workflows")
|
|
270
|
+
.option("--status <status>", "filter by status (running | succeeded | failed | cancelled)")
|
|
271
|
+
.option("--limit <n>", "maximum number of workflows to return")
|
|
272
|
+
.option("--offset <n>", "number of workflows to skip")
|
|
273
|
+
.action(async (options) => {
|
|
274
|
+
await workflow.workflowList(options).catch(fail);
|
|
275
|
+
});
|
|
276
|
+
workflowCommand
|
|
277
|
+
.command("cancel <id_or_name>")
|
|
278
|
+
.description("Cancel a workflow (cancels all non-terminal node jobs)")
|
|
279
|
+
.option("--yes", "skip the confirmation prompt")
|
|
280
|
+
.action(async (idOrName, options) => {
|
|
281
|
+
await workflow.workflowCancel(idOrName, options).catch(fail);
|
|
282
|
+
});
|
|
219
283
|
// --- cronjob ----------------------------------------------------------------
|
|
220
284
|
const cronjobCommand = program
|
|
221
285
|
.command("cronjob")
|
|
@@ -232,6 +296,15 @@ cronjobCommand
|
|
|
232
296
|
.action(async (idOrName) => {
|
|
233
297
|
await cronjob.cronjobShow(idOrName).catch(fail);
|
|
234
298
|
});
|
|
299
|
+
cronjobCommand
|
|
300
|
+
.command("workflows <id_or_name>")
|
|
301
|
+
.description("List the workflow runs spawned by a cronjob")
|
|
302
|
+
.option("--status <status>", "filter by status (running | succeeded | failed | cancelled)")
|
|
303
|
+
.option("--limit <n>", "maximum number of workflows to return")
|
|
304
|
+
.option("--offset <n>", "number of workflows to skip")
|
|
305
|
+
.action(async (idOrName, options) => {
|
|
306
|
+
await cronjob.cronjobWorkflows(idOrName, options).catch(fail);
|
|
307
|
+
});
|
|
235
308
|
cronjobCommand
|
|
236
309
|
.command("create")
|
|
237
310
|
.description("Create a cronjob (--image form, or --file with a workload YAML/JSON template)")
|
package/dist/lib/parse.js
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
* Pure parsers for `solti job run` flag payloads (constitution tools/cli.md
|
|
3
3
|
* §2.2). Kept free of I/O so they can be unit-tested directly (tests/parse.test.ts).
|
|
4
4
|
*/
|
|
5
|
+
/** Normalizes repeatable + comma-separated flag values (cli.md §2.2:
|
|
6
|
+
* `--cloud aws,gcp` and `--cloud aws --cloud gcp` are both valid). Returns a
|
|
7
|
+
* flat, trimmed, empty-item-free array so the API always receives a JSON
|
|
8
|
+
* array — a scalar `cloud`/`region` payload is what poisoned jobs.cloud on
|
|
9
|
+
* the live API (Change 048). */
|
|
10
|
+
export function parseStringList(values) {
|
|
11
|
+
const list = values === undefined ? [] : Array.isArray(values) ? values : [values];
|
|
12
|
+
return list
|
|
13
|
+
.flatMap((value) => value.split(","))
|
|
14
|
+
.map((value) => value.trim())
|
|
15
|
+
.filter((value) => value !== "");
|
|
16
|
+
}
|
|
5
17
|
/** Parses `.env`-style content: KEY=VALUE lines; blank lines and `#`
|
|
6
18
|
* comments are ignored; whitespace is trimmed; matching surrounding quotes
|
|
7
19
|
* are stripped from values. */
|
|
@@ -26,6 +38,43 @@ export function parseEnvFile(text) {
|
|
|
26
38
|
return env;
|
|
27
39
|
}
|
|
28
40
|
const VRAM_RE = /^\d+(\.\d+)?(Gi|Mi)?$/;
|
|
41
|
+
/** Matches an RFC 3339 / ISO 8601 datetime that carries an explicit UTC
|
|
42
|
+
* offset: `Z`/`z`, `±HH:MM`, `±HHMM`, or `±HH`; `T`/`t`/space separator;
|
|
43
|
+
* optional fractional seconds. Naive datetimes (no offset) never match —
|
|
44
|
+
* the API rejects them with 422 (Change 090), so the CLI must too. */
|
|
45
|
+
const RUN_AFTER_RE = /^(\d{4})-(\d{2})-(\d{2})[Tt ](\d{2}):(\d{2}):(\d{2})(\.\d+)?(?:[Zz]|([+-])(\d{2}):?(\d{2})?)$/;
|
|
46
|
+
const NAIVE_RUN_AFTER_RE = /^\d{4}-\d{2}-\d{2}[Tt ]\d{2}:\d{2}:\d{2}(\.\d+)?$/;
|
|
47
|
+
/** Validates a `--run-after` value (Change 090): a parseable, timezone-aware
|
|
48
|
+
* RFC 3339 / ISO 8601 datetime. Garbage and naive datetimes (no offset) throw
|
|
49
|
+
* with a clear message — no server-local-time guessing. Past instants are
|
|
50
|
+
* allowed (the API treats them as "start now"). Returns the trimmed value for
|
|
51
|
+
* the `runAfter` payload field verbatim; the API normalizes it to UTC. */
|
|
52
|
+
export function parseRunAfter(value) {
|
|
53
|
+
const datetime = value.trim();
|
|
54
|
+
if (NAIVE_RUN_AFTER_RE.test(datetime)) {
|
|
55
|
+
throw new Error(`Invalid --run-after '${value}' — naive datetime without a timezone; append an offset (Z or ±HH:MM), e.g. 2026-11-25T02:00:00Z`);
|
|
56
|
+
}
|
|
57
|
+
const match = RUN_AFTER_RE.exec(datetime);
|
|
58
|
+
if (!match) {
|
|
59
|
+
throw new Error(`Invalid --run-after '${value}' — expected an RFC 3339 / ISO 8601 datetime with timezone, e.g. 2026-11-25T02:00:00Z or 2026-11-25T11:00:00+09:00`);
|
|
60
|
+
}
|
|
61
|
+
// Round-trip the calendar components through Date.UTC: impossible dates
|
|
62
|
+
// (2026-02-30) or out-of-range times (25:00) silently roll over in JS, so
|
|
63
|
+
// a mismatch means the value is not a real datetime. Date.UTC ignores the
|
|
64
|
+
// offset entirely, so the offset groups are range-checked separately.
|
|
65
|
+
const [, year, month, day, hour, minute, second, , offsetSign, offsetHours, offsetMinutes] = match;
|
|
66
|
+
const parsed = new Date(Date.UTC(Number(year), Number(month) - 1, Number(day), Number(hour), Number(minute), Number(second)));
|
|
67
|
+
if (parsed.getUTCFullYear() !== Number(year) ||
|
|
68
|
+
parsed.getUTCMonth() !== Number(month) - 1 ||
|
|
69
|
+
parsed.getUTCDate() !== Number(day) ||
|
|
70
|
+
parsed.getUTCHours() !== Number(hour) ||
|
|
71
|
+
parsed.getUTCMinutes() !== Number(minute) ||
|
|
72
|
+
parsed.getUTCSeconds() !== Number(second) ||
|
|
73
|
+
(offsetSign !== undefined && (Number(offsetHours) > 23 || Number(offsetMinutes ?? "0") > 59))) {
|
|
74
|
+
throw new Error(`Invalid --run-after '${value}' — not a real calendar datetime`);
|
|
75
|
+
}
|
|
76
|
+
return datetime;
|
|
77
|
+
}
|
|
29
78
|
/** Parses a `--resources` spec, e.g. `cpu=4,memory=16Gi,gpu=24Gi` or
|
|
30
79
|
* `cpu=4,memory=16Gi,gpu.model=A100,gpu.count=2`. Unknown keys, duplicates
|
|
31
80
|
* of the same key, non-numeric cpu/count values, and `gpu.count` without
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solti/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Solti Platform CLI — schedule and run asynchronous workloads without managing infrastructure.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build": "tsc",
|
|
20
20
|
"dev": "tsc --watch",
|
|
21
|
-
"test": "bun test"
|
|
21
|
+
"test": "bun test",
|
|
22
|
+
"bundle:python": "esbuild dist/index.js --bundle --platform=node --format=cjs --target=node20 --outfile=solti_cli/vendor/cli.cjs"
|
|
22
23
|
},
|
|
23
24
|
"dependencies": {
|
|
24
25
|
"commander": "^14.0.2",
|
|
@@ -26,6 +27,7 @@
|
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
29
|
"@types/node": "^24.10.1",
|
|
30
|
+
"esbuild": "^0.28.2",
|
|
29
31
|
"typescript": "^5.9.3"
|
|
30
32
|
}
|
|
31
33
|
}
|