@stav-ai/cli 0.1.9 → 0.1.10
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 +8 -2
- package/dist/app-names.js +54 -0
- package/dist/cli.js +14 -4
- package/dist/launch.js +6 -3
- package/dist/update-check.js +67 -0
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ is not ours.
|
|
|
25
25
|
| `stav logout` | Remove the sign-in from this machine |
|
|
26
26
|
| `stav whoami` | Who you are, and which workspace |
|
|
27
27
|
| `stav workspace [<slug>]` | Show your workspaces, or choose one |
|
|
28
|
-
| `stav apps` | The apps this CLI can launch |
|
|
28
|
+
| `stav apps` | The apps this CLI can launch, and the names you can type for each |
|
|
29
29
|
| `stav launch <app> [--model <id>] [--workspace <slug>] [--yes] [--verbose] [-- <app arguments>]` | Start an app on Stav |
|
|
30
30
|
|
|
31
31
|
It launches **Claude Code** (`claude`), **Codex** (`codex`),
|
|
@@ -139,7 +139,13 @@ macOS and Linux. Windows is not supported yet: use WSL.
|
|
|
139
139
|
## Privacy
|
|
140
140
|
|
|
141
141
|
The CLI sends no telemetry. It talks only to `stav.ai`, `api.stav.ai` and
|
|
142
|
-
`auth.stav.ai`, and with `stav agent` to `relay.stav.ai
|
|
142
|
+
`auth.stav.ai`, and with `stav agent` to `relay.stav.ai`, with one exception:
|
|
143
|
+
at most once a day it asks the npm registry (`registry.npmjs.org`) for the
|
|
144
|
+
newest version number, so it can tell you when there is an update. That
|
|
145
|
+
request holds no key, no account and nothing about your use; like any
|
|
146
|
+
request, it shows npm your IP address. Set `STAV_NO_UPDATE_CHECK=1` to turn it
|
|
147
|
+
off. It is also off in CI, when the output is not a terminal, and for
|
|
148
|
+
`stav agent`. (If you say yes to installing an app, npm installs it.)
|
|
143
149
|
|
|
144
150
|
## Source and releases
|
|
145
151
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The names a person may type after `stav launch`, the `stav apps` list, and
|
|
3
|
+
* the hint for a name that is nearly right.
|
|
4
|
+
*/
|
|
5
|
+
import { ADAPTERS, ALIASES } from './adapters/index.js';
|
|
6
|
+
/** The short name of an app ("claude" for claude-code), or null when it has none. */
|
|
7
|
+
export function shortName(slug) {
|
|
8
|
+
return Object.keys(ALIASES).find((a) => ALIASES[a] === slug) ?? null;
|
|
9
|
+
}
|
|
10
|
+
/** The lines of `stav apps`: the name to type first, then the long name, which works too. */
|
|
11
|
+
export function appsTable(rows) {
|
|
12
|
+
const cells = [
|
|
13
|
+
['NAME', 'LONG NAME', 'APP', 'STATE'],
|
|
14
|
+
...rows.map((r) => {
|
|
15
|
+
const short = shortName(r.slug);
|
|
16
|
+
return [short ?? r.slug, short ? r.slug : '', r.displayName, r.ready ? 'ready' : 'not launchable yet'];
|
|
17
|
+
}),
|
|
18
|
+
];
|
|
19
|
+
const widths = [0, 1, 2].map((i) => Math.max(...cells.map((c) => c[i].length)));
|
|
20
|
+
return cells.map((c) => c.map((x, i) => (i < 3 ? x.padEnd(widths[i]) : x)).join(' '));
|
|
21
|
+
}
|
|
22
|
+
/** Edits (add, remove, change or swap two letters) between two words. */
|
|
23
|
+
function distance(a, b) {
|
|
24
|
+
const d = Array.from({ length: a.length + 1 }, (_, i) => Array.from({ length: b.length + 1 }, (_, j) => (i === 0 ? j : j === 0 ? i : 0)));
|
|
25
|
+
for (let i = 1; i <= a.length; i++) {
|
|
26
|
+
for (let j = 1; j <= b.length; j++) {
|
|
27
|
+
const change = a[i - 1] === b[j - 1] ? 0 : 1;
|
|
28
|
+
d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + change);
|
|
29
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1])
|
|
30
|
+
d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return d[a.length][b.length];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The name the person most likely meant, or null. Only ever shown as a
|
|
37
|
+
* question: the CLI never starts an app on a guess. One edit for a short
|
|
38
|
+
* word, two for a longer one, or the start of exactly one app's name.
|
|
39
|
+
*/
|
|
40
|
+
export function suggestApp(typed) {
|
|
41
|
+
const t = typed.trim().toLowerCase();
|
|
42
|
+
// Two letters are one edit from too much; a very long word is not a typo.
|
|
43
|
+
if (t.length < 3 || t.length > 40)
|
|
44
|
+
return null;
|
|
45
|
+
const names = [...Object.keys(ALIASES), ...ADAPTERS.flatMap((a) => a.apps)];
|
|
46
|
+
const near = names
|
|
47
|
+
.map((name) => ({ name, d: distance(t, name) }))
|
|
48
|
+
.filter((x) => x.d <= (t.length < 6 ? 1 : 2))
|
|
49
|
+
.sort((a, b) => a.d - b.d)[0];
|
|
50
|
+
if (near)
|
|
51
|
+
return near.name;
|
|
52
|
+
const starts = names.filter((n) => n.startsWith(t));
|
|
53
|
+
return starts.length === 1 ? starts[0] : null;
|
|
54
|
+
}
|
package/dist/cli.js
CHANGED
|
@@ -7,10 +7,12 @@
|
|
|
7
7
|
* stav apps
|
|
8
8
|
* stav launch <app> [--model <id>] [--workspace <slug>] [--yes] [--verbose] [-- <app arguments>]
|
|
9
9
|
*
|
|
10
|
-
* No telemetry (spec B.9).
|
|
10
|
+
* No telemetry (spec B.9). Once a day it asks npm for the newest version
|
|
11
|
+
* (update-check.ts).
|
|
11
12
|
*/
|
|
12
13
|
import { parseArgs } from 'node:util';
|
|
13
14
|
import { ADAPTERS } from './adapters/index.js';
|
|
15
|
+
import { appsTable } from './app-names.js';
|
|
14
16
|
import { agentCommand, TIMES } from './agent/index.js';
|
|
15
17
|
import { accessToken, defaultIO, login, logout } from './auth/session.js';
|
|
16
18
|
import { loadConfig } from './config.js';
|
|
@@ -20,6 +22,7 @@ import { askHere, terminal } from './prompt.js';
|
|
|
20
22
|
import { terminalText } from './terminal-text.js';
|
|
21
23
|
import { Stav } from './stav.js';
|
|
22
24
|
import { forgetAppKeys, openStore, readSettings, writeSetting } from './store/index.js';
|
|
25
|
+
import { updateNotice } from './update-check.js';
|
|
23
26
|
import { VERSION } from './version.js';
|
|
24
27
|
import { chooseWorkspace } from './workspace.js';
|
|
25
28
|
const HELP = `stav ${VERSION} — run your coding agent on Stav
|
|
@@ -29,7 +32,7 @@ Usage:
|
|
|
29
32
|
stav logout [--forget-keys] Remove the sign-in from this machine
|
|
30
33
|
stav whoami Who you are, and which workspace
|
|
31
34
|
stav workspace [<slug>] Show your workspaces, or choose one
|
|
32
|
-
stav apps The apps this CLI can launch
|
|
35
|
+
stav apps The apps this CLI can launch, and their names
|
|
33
36
|
stav launch <app> [options] [-- <app arguments>]
|
|
34
37
|
|
|
35
38
|
Launch options:
|
|
@@ -40,6 +43,7 @@ Launch options:
|
|
|
40
43
|
|
|
41
44
|
Environment:
|
|
42
45
|
STAV_API_KEY Use this key; no sign-in and no key is made
|
|
46
|
+
STAV_NO_UPDATE_CHECK=1 Do not ask npm for a newer version
|
|
43
47
|
|
|
44
48
|
Examples:
|
|
45
49
|
stav launch claude
|
|
@@ -104,6 +108,9 @@ async function main(argv) {
|
|
|
104
108
|
},
|
|
105
109
|
});
|
|
106
110
|
}
|
|
111
|
+
// Before the command: an app that is started takes over the terminal.
|
|
112
|
+
for (const line of await updateNotice({ fetchFn, env: process.env, isTerminal: Boolean(process.stderr.isTTY) }))
|
|
113
|
+
err(line);
|
|
107
114
|
const store = await openStore();
|
|
108
115
|
const stav = new Stav(cfg, fetchFn);
|
|
109
116
|
const token = () => accessToken(fetchFn, cfg, store);
|
|
@@ -191,13 +198,16 @@ async function main(argv) {
|
|
|
191
198
|
return 0;
|
|
192
199
|
}
|
|
193
200
|
case 'apps': {
|
|
201
|
+
const rows = [];
|
|
194
202
|
for (const a of ADAPTERS) {
|
|
195
203
|
for (const slug of a.apps) {
|
|
196
204
|
const app = await stav.app(slug).catch(() => null);
|
|
197
|
-
|
|
198
|
-
out(`${slug.padEnd(14)} ${a.displayName.padEnd(14)} ${state}`);
|
|
205
|
+
rows.push({ slug, displayName: a.displayName, ready: Boolean(app?.cli_available) });
|
|
199
206
|
}
|
|
200
207
|
}
|
|
208
|
+
for (const line of appsTable(rows))
|
|
209
|
+
out(line);
|
|
210
|
+
out('\nStart one with its name or its long name, for example: stav launch claude');
|
|
201
211
|
return 0;
|
|
202
212
|
}
|
|
203
213
|
case 'launch': {
|
package/dist/launch.js
CHANGED
|
@@ -9,11 +9,13 @@ import { spawn as nodeSpawn } from 'node:child_process';
|
|
|
9
9
|
import { accessSync, constants, statSync } from 'node:fs';
|
|
10
10
|
import os from 'node:os';
|
|
11
11
|
import path from 'node:path';
|
|
12
|
+
import { suggestApp } from './app-names.js';
|
|
12
13
|
import { adapterForApp, MODEL_RE, resolveApp } from './adapters/index.js';
|
|
13
14
|
import { StavError } from './errors.js';
|
|
14
15
|
import { confirm } from './prompt.js';
|
|
15
16
|
import { Stav } from './stav.js';
|
|
16
17
|
import { appKeyName, saveAppKey } from './store/index.js';
|
|
18
|
+
import { updateCommand } from './update-check.js';
|
|
17
19
|
import { compareVersions } from './version-compare.js';
|
|
18
20
|
import { VERSION } from './version.js';
|
|
19
21
|
import { chooseWorkspace } from './workspace.js';
|
|
@@ -46,8 +48,9 @@ async function checkLaunch(opts, d) {
|
|
|
46
48
|
}
|
|
47
49
|
const slug = resolveApp(opts.app);
|
|
48
50
|
const adapter = adapterForApp(slug);
|
|
51
|
+
const hint = adapter ? null : suggestApp(opts.app);
|
|
49
52
|
if (!adapter)
|
|
50
|
-
throw new StavError(`The Stav CLI cannot launch "${opts.app}"
|
|
53
|
+
throw new StavError(`The Stav CLI cannot launch "${opts.app}".${hint ? ` Did you mean "${hint}"?` : ''} Run stav apps to see the apps it can.`, 'unknown_app');
|
|
51
54
|
const stav = new Stav(d.cfg, d.fetchFn);
|
|
52
55
|
const app = await stav.app(slug);
|
|
53
56
|
checkLaunchable(app, adapter, slug);
|
|
@@ -139,10 +142,10 @@ function checkLaunchable(app, adapter, slug) {
|
|
|
139
142
|
throw new StavError(`${adapter.displayName} cannot be launched with the Stav CLI yet. See https://stav.ai/apps/${slug} to set it up by hand.`, 'not_launchable');
|
|
140
143
|
}
|
|
141
144
|
if (r.adapter !== adapter.name) {
|
|
142
|
-
throw new StavError(`Stav launches ${adapter.displayName} in a way this CLI does not know. Update it:
|
|
145
|
+
throw new StavError(`Stav launches ${adapter.displayName} in a way this CLI does not know. Update it: ${updateCommand()}`, 'update_cli');
|
|
143
146
|
}
|
|
144
147
|
if (compareVersions(VERSION, r.min_cli) < 0) {
|
|
145
|
-
throw new StavError(`Launching ${adapter.displayName} needs Stav CLI ${r.min_cli} or newer (this is ${VERSION}). Update it:
|
|
148
|
+
throw new StavError(`Launching ${adapter.displayName} needs Stav CLI ${r.min_cli} or newer (this is ${VERSION}). Update it: ${updateCommand()}`, 'update_cli');
|
|
146
149
|
}
|
|
147
150
|
}
|
|
148
151
|
async function readStoredKey(store, name) {
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "A new version is available": asks the npm registry for the newest version
|
|
3
|
+
* of this package, at most once a day, and says so before the command runs
|
|
4
|
+
* (DECIDE-APPS-V).
|
|
5
|
+
*
|
|
6
|
+
* The request is a plain GET of a public address: no key, no sign-in, no
|
|
7
|
+
* version and no machine details. It can never fail a command and holds one
|
|
8
|
+
* up for at most a second, once a day. Nothing from the answer is printed
|
|
9
|
+
* except a version number of the form x.y.z.
|
|
10
|
+
*/
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
13
|
+
import { configDir, FileStore } from './store/index.js';
|
|
14
|
+
import { compareVersions } from './version-compare.js';
|
|
15
|
+
import { VERSION } from './version.js';
|
|
16
|
+
export const DIST_TAGS_URL = 'https://registry.npmjs.org/-/package/@stav-ai/cli/dist-tags';
|
|
17
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
18
|
+
const WAIT_MS = 1000;
|
|
19
|
+
const RELEASE = /^[0-9]{1,5}\.[0-9]{1,5}\.[0-9]{1,5}$/;
|
|
20
|
+
/** How to update this copy: npx keeps its own, which a global install does not change. */
|
|
21
|
+
export function updateCommand(self = fileURLToPath(import.meta.url)) {
|
|
22
|
+
return self.split(/[\\/]/).includes('_npx') ? 'npx @stav-ai/cli@latest' : 'npm install -g @stav-ai/cli@latest';
|
|
23
|
+
}
|
|
24
|
+
async function newest(fetchFn) {
|
|
25
|
+
try {
|
|
26
|
+
const res = await fetchFn(DIST_TAGS_URL, { headers: { Accept: 'application/json' }, redirect: 'error', signal: AbortSignal.timeout(WAIT_MS) });
|
|
27
|
+
if (!res.ok)
|
|
28
|
+
return null;
|
|
29
|
+
const latest = (await res.json())?.latest;
|
|
30
|
+
return typeof latest === 'string' && RELEASE.test(latest) ? latest : null;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return null; // Offline, a proxy, npm down: ask again tomorrow.
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/** The lines to show, or none. Never throws. */
|
|
37
|
+
export async function updateNotice(d) {
|
|
38
|
+
if (!d.isTerminal || d.env.CI || d.env.STAV_NO_UPDATE_CHECK)
|
|
39
|
+
return [];
|
|
40
|
+
const now = (d.now ?? Date.now)();
|
|
41
|
+
const version = d.version ?? VERSION;
|
|
42
|
+
// A file of its own: config.json is read and written whole, and holds the chosen workspace.
|
|
43
|
+
const cache = new FileStore(path.join(configDir(d.env), 'update-check.json'));
|
|
44
|
+
const saved = await cache.readAll();
|
|
45
|
+
let latest = typeof saved.latest === 'string' && RELEASE.test(saved.latest) ? saved.latest : null;
|
|
46
|
+
const age = now - Number(saved.checked_at);
|
|
47
|
+
// A missing or broken time, or one in the future, counts as never asked.
|
|
48
|
+
if (!(age >= 0 && age < DAY_MS)) {
|
|
49
|
+
latest = (await newest(d.fetchFn)) ?? latest;
|
|
50
|
+
try {
|
|
51
|
+
// Saved after a failure too, so being offline costs one wait a day.
|
|
52
|
+
await cache.set('checked_at', String(now));
|
|
53
|
+
if (latest)
|
|
54
|
+
await cache.set('latest', latest);
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// A read-only home: the check then runs again next time.
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (!latest || compareVersions(version, latest) >= 0)
|
|
61
|
+
return [];
|
|
62
|
+
return [
|
|
63
|
+
`A new version of the Stav CLI is available: ${latest} (you have ${version}).`,
|
|
64
|
+
`Update: ${d.command ?? updateCommand()}`,
|
|
65
|
+
'',
|
|
66
|
+
];
|
|
67
|
+
}
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** The CLI's own version. Kept equal to package.json by units.test.ts ("VERSION matches package.json"). */
|
|
2
|
-
export const VERSION = '0.1.
|
|
2
|
+
export const VERSION = '0.1.10';
|