@stav-ai/cli 0.1.4 → 0.1.6
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 +22 -3
- package/dist/adapters/adapters.json +5 -0
- package/dist/adapters/hermes-managed/config.yaml +26 -0
- package/dist/adapters/index.js +151 -9
- package/dist/adapters/pi-stav-provider.js +29 -13
- package/dist/cli.js +1 -0
- package/dist/launch.js +31 -3
- package/dist/stav.js +30 -0
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -11,6 +11,7 @@ npx @stav-ai/cli launch dsh -- "run the tests"
|
|
|
11
11
|
npx @stav-ai/cli launch kilo
|
|
12
12
|
npx @stav-ai/cli launch copilot
|
|
13
13
|
npx @stav-ai/cli launch pi
|
|
14
|
+
npx @stav-ai/cli launch hermes
|
|
14
15
|
```
|
|
15
16
|
|
|
16
17
|
Always use the scoped name `@stav-ai/cli`. The unscoped `stav` package on npm
|
|
@@ -29,9 +30,10 @@ is not ours.
|
|
|
29
30
|
|
|
30
31
|
It launches **Claude Code** (`claude`), **Codex** (`codex`),
|
|
31
32
|
**DeepSeek Harness** (`dsh`), **Kilo Code** (`kilo`), the
|
|
32
|
-
**GitHub Copilot CLI** (`copilot`)
|
|
33
|
-
not installed, it offers to install it with
|
|
34
|
-
only if you say yes
|
|
33
|
+
**GitHub Copilot CLI** (`copilot`), **pi** (`pi`) and **Hermes Agent**
|
|
34
|
+
(`hermes`). If the app is not installed, it offers to install it with
|
|
35
|
+
`npm install -g` and does so only if you say yes (Hermes Agent is not on
|
|
36
|
+
npm: the CLI says where its installer is). With `--yes`, or with no terminal, it installs
|
|
35
37
|
nothing and prints the command instead.
|
|
36
38
|
|
|
37
39
|
## What `stav launch` does
|
|
@@ -95,6 +97,23 @@ nothing and prints the command instead.
|
|
|
95
97
|
the model writes without asking. For one task without the chat screen,
|
|
96
98
|
give `-p "<task>"` after `--`.
|
|
97
99
|
|
|
100
|
+
Hermes Agent runs every turn in a background process that keeps the key it
|
|
101
|
+
started with, and reads a key saved in `~/.hermes/.env` before the
|
|
102
|
+
environment. So the CLI starts Hermes with a home of its own in
|
|
103
|
+
`~/.stav/hermes` (`HERMES_HOME`), one folder per API key, so a launch for
|
|
104
|
+
another workspace never uses the key of one still open; a new key starts an
|
|
105
|
+
empty folder. Sessions, memory
|
|
106
|
+
and skills there are kept apart from your own Hermes, and `~/.hermes` is
|
|
107
|
+
not read or changed.
|
|
108
|
+
Hermes takes the provider from a settings folder that ships with the CLI
|
|
109
|
+
(`HERMES_MANAGED_DIR`). That file holds no key and no address: every value
|
|
110
|
+
comes from the environment, and the key is only in `STAV_HERMES_API_KEY`.
|
|
111
|
+
The same file turns off the update check at GitHub and the free web search
|
|
112
|
+
fallback. Hermes runs the commands the model writes; those it does not
|
|
113
|
+
judge dangerous run without asking, and they can read
|
|
114
|
+
`STAV_HERMES_API_KEY` from their environment. For one task without the chat screen,
|
|
115
|
+
give `-z "<task>"` after `--`; then every command runs without asking.
|
|
116
|
+
|
|
98
117
|
The key is kept in your operating system's keychain, or in a file only you
|
|
99
118
|
can read when there is no keychain. Never in your project folder.
|
|
100
119
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# The Hermes Agent settings for `stav launch hermes-agent`.
|
|
2
|
+
#
|
|
3
|
+
# The Stav CLI points Hermes at this folder with HERMES_MANAGED_DIR (Hermes's
|
|
4
|
+
# administrator overlay, laid over its own config.yaml). Hermes expands each
|
|
5
|
+
# ${VAR} from the environment of the process only, so every value comes from
|
|
6
|
+
# what the CLI sets for this run. No secret is written here: the key is read
|
|
7
|
+
# from STAV_HERMES_API_KEY through key_env.
|
|
8
|
+
model:
|
|
9
|
+
provider: custom:stav-cli
|
|
10
|
+
default: ${STAV_HERMES_MODEL}
|
|
11
|
+
providers:
|
|
12
|
+
stav-cli:
|
|
13
|
+
api: ${STAV_HERMES_BASE_URL}
|
|
14
|
+
key_env: STAV_HERMES_API_KEY
|
|
15
|
+
transport: chat_completions
|
|
16
|
+
# Traffic that would not go through Stav: the daily update check at GitHub and
|
|
17
|
+
# the free third-party web search fallback.
|
|
18
|
+
updates:
|
|
19
|
+
check: false
|
|
20
|
+
web:
|
|
21
|
+
keyless_fallback: false
|
|
22
|
+
# Hermes runs each turn in a background process that keeps the key and model
|
|
23
|
+
# it started with. Let it end soon after the last window closes, so the next
|
|
24
|
+
# launch starts one with its own values.
|
|
25
|
+
gateway:
|
|
26
|
+
unmanaged_idle_exit_seconds: 5
|
package/dist/adapters/index.js
CHANGED
|
@@ -11,13 +11,15 @@
|
|
|
11
11
|
* provider from KILO_CONFIG_CONTENT, the GitHub Copilot CLI from its
|
|
12
12
|
* COPILOT_PROVIDER_* variables, and pi from a fixed provider extension
|
|
13
13
|
* shipped with the CLI (pi-stav-provider.js) whose values all come from the
|
|
14
|
-
* environment
|
|
14
|
+
* environment, and Hermes Agent from a fixed overlay folder shipped with the
|
|
15
|
+
* CLI (hermes-managed/), in a Hermes home of its own. The key goes only into the child's
|
|
15
16
|
* environment, never into its arguments or a file (R-20).
|
|
16
17
|
*
|
|
17
18
|
* adapters.json is byte-identical to the Stav API's
|
|
18
19
|
* app/services/launch_recipes/adapters.json (the admin endpoint checks
|
|
19
20
|
* recipes against it; a lockstep test pins the copy).
|
|
20
21
|
*/
|
|
22
|
+
import { createHash } from 'node:crypto';
|
|
21
23
|
import { promises as fs } from 'node:fs';
|
|
22
24
|
import os from 'node:os';
|
|
23
25
|
import path from 'node:path';
|
|
@@ -223,6 +225,53 @@ const deepseekHarness = {
|
|
|
223
225
|
};
|
|
224
226
|
},
|
|
225
227
|
};
|
|
228
|
+
/**
|
|
229
|
+
* The most bytes the model list may take in the one environment variable
|
|
230
|
+
* that carries it. Linux refuses a single variable over 128 KiB
|
|
231
|
+
* (MAX_ARG_STRLEN) and the program would not start; this leaves room for
|
|
232
|
+
* the rest of the value. macOS has no per-variable limit below that. Windows
|
|
233
|
+
* (32,767 characters per variable) is not a concern: `stav launch` refuses
|
|
234
|
+
* win32 before any adapter runs (checkLaunch in launch.ts, code
|
|
235
|
+
* `unsupported_platform`). Lower this before launches on Windows are allowed.
|
|
236
|
+
*/
|
|
237
|
+
export const MODEL_LIST_BUDGET = 96_000;
|
|
238
|
+
/**
|
|
239
|
+
* The models an app's picker offers: the launch's own model first, with its
|
|
240
|
+
* window, then every other one the key may use, in the order Stav gave them
|
|
241
|
+
* (auto, the Routers, the models). Models past ``budget`` bytes, as
|
|
242
|
+
* ``entryBytes`` counts them, are left out and counted in ``dropped``; the
|
|
243
|
+
* launch's model, ``auto`` and the Routers are always kept.
|
|
244
|
+
*/
|
|
245
|
+
export function pickerModels(ctx, defaultContext, entryBytes, budget = MODEL_LIST_BUDGET) {
|
|
246
|
+
const id = ctx.model ?? 'auto';
|
|
247
|
+
const first = { id, contextWindow: ctx.contextWindow && namedModel(ctx.model) ? ctx.contextWindow : defaultContext };
|
|
248
|
+
const out = [first];
|
|
249
|
+
let used = entryBytes(first);
|
|
250
|
+
let dropped = 0;
|
|
251
|
+
for (const m of ctx.models ?? []) {
|
|
252
|
+
if (m.id === id)
|
|
253
|
+
continue;
|
|
254
|
+
const entry = { id: m.id, contextWindow: m.contextWindow ?? defaultContext };
|
|
255
|
+
const n = entryBytes(entry);
|
|
256
|
+
if (namedModel(m.id) && used + n > budget) {
|
|
257
|
+
dropped += 1;
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
used += n;
|
|
261
|
+
out.push(entry);
|
|
262
|
+
}
|
|
263
|
+
return { models: out, dropped };
|
|
264
|
+
}
|
|
265
|
+
/** The plan's line about the picker, for the preview and the run. */
|
|
266
|
+
function describePicker(models, dropped, ctx, picker) {
|
|
267
|
+
if (ctx.models === undefined)
|
|
268
|
+
return `every chat model and Router your key may use, read from Stav, to pick from with ${picker}`;
|
|
269
|
+
if (ctx.models === null)
|
|
270
|
+
return `only this model in ${picker}: the list of models could not be read from Stav`;
|
|
271
|
+
const more = models.length - 1;
|
|
272
|
+
const left = dropped ? ` (${dropped} more models left out: the list would not fit in one environment variable)` : '';
|
|
273
|
+
return `${more} more models and Routers your key may use, to pick from with ${picker}${left}`;
|
|
274
|
+
}
|
|
226
275
|
/** The provider id the kilo-code adapter gives Stav; one only the CLI uses, so a "stav" block a person made from the guide never merges into it. */
|
|
227
276
|
export const KILO_PROVIDER = 'stav-cli';
|
|
228
277
|
/**
|
|
@@ -244,7 +293,9 @@ const kiloCode = {
|
|
|
244
293
|
program: 'kilo',
|
|
245
294
|
scopes: ['inference:chat'],
|
|
246
295
|
wantsContextWindow: namedModel,
|
|
247
|
-
|
|
296
|
+
wantsModelList: true,
|
|
297
|
+
plan(ctx) {
|
|
298
|
+
const { gatewayUrl, key, model, contextWindow } = ctx;
|
|
248
299
|
// Kilo Code merges KILO_CONFIG_CONTENT after the global and the project
|
|
249
300
|
// config files, and resolves {env:} in it (checked with Kilo Code
|
|
250
301
|
// 7.8.40), so the whole provider is given in the environment and no file
|
|
@@ -257,7 +308,6 @@ const kiloCode = {
|
|
|
257
308
|
const base = `${gatewayUrl}/v1`;
|
|
258
309
|
const id = model ?? 'auto';
|
|
259
310
|
const ref = `${KILO_PROVIDER}/${id}`;
|
|
260
|
-
const window = contextWindow && namedModel(model) ? contextWindow : KILO_DEFAULT_CONTEXT;
|
|
261
311
|
// The config files merge deep, so a "stav-cli" block in the person's own
|
|
262
312
|
// config keeps every key this one does not set. The SDK and the address
|
|
263
313
|
// are therefore set at both levels Kilo Code reads them from (provider and
|
|
@@ -265,7 +315,12 @@ const kiloCode = {
|
|
|
265
315
|
// reach Stav, never anywhere else. Only a Kilo organisation's console
|
|
266
316
|
// config and MDM-managed config merge after KILO_CONFIG_CONTENT; those are
|
|
267
317
|
// set by the person's administrator and are meant to win.
|
|
318
|
+
// Every chat model, Router and auto the key may use is listed, so
|
|
319
|
+
// Kilo's model picker (/models) offers them all; the launch's model is
|
|
320
|
+
// the one selected.
|
|
268
321
|
const sdk = '@ai-sdk/openai-compatible';
|
|
322
|
+
const entry = (m) => ({ name: m.id, provider: { npm: sdk, api: base }, limit: { context: m.contextWindow ?? KILO_DEFAULT_CONTEXT, output: KILO_MAX_OUTPUT } });
|
|
323
|
+
const picker = pickerModels(ctx, KILO_DEFAULT_CONTEXT, (m) => JSON.stringify({ [m.id]: entry(m) }).length);
|
|
269
324
|
const config = {
|
|
270
325
|
model: ref,
|
|
271
326
|
small_model: ref,
|
|
@@ -276,9 +331,7 @@ const kiloCode = {
|
|
|
276
331
|
api: base,
|
|
277
332
|
name: 'Stav',
|
|
278
333
|
options: { apiKey: '{env:STAV_KILO_API_KEY}', baseURL: base },
|
|
279
|
-
models:
|
|
280
|
-
[id]: { name: id, provider: { npm: sdk, api: base }, limit: { context: window, output: KILO_MAX_OUTPUT } },
|
|
281
|
-
},
|
|
334
|
+
models: Object.fromEntries(picker.models.map((m) => [m.id, entry(m)])),
|
|
282
335
|
},
|
|
283
336
|
},
|
|
284
337
|
};
|
|
@@ -305,6 +358,7 @@ const kiloCode = {
|
|
|
305
358
|
'STAV_KILO_API_KEY=<the key, in the environment only>',
|
|
306
359
|
model ? `model ${model}` : "model auto (your workspace's default Router)",
|
|
307
360
|
describeWindow,
|
|
361
|
+
describePicker(picker.models, picker.dropped, ctx, '/models'),
|
|
308
362
|
`at most ${KILO_MAX_OUTPUT} output tokens per call`,
|
|
309
363
|
'KILO_TELEMETRY_LEVEL=off, KILO_DISABLE_SESSION_INGEST=1, KILO_DISABLE_SHARE=1 (no usage data or session uploads to Kilo)',
|
|
310
364
|
'note: Kilo Code runs commands and edits files. It asks before most shell commands, unless your Kilo config allows them (Kilo writes bash: allow into a config file that existed before its first start)',
|
|
@@ -400,7 +454,9 @@ const pi = {
|
|
|
400
454
|
program: 'pi',
|
|
401
455
|
scopes: ['inference:chat'],
|
|
402
456
|
wantsContextWindow: namedModel,
|
|
403
|
-
|
|
457
|
+
wantsModelList: true,
|
|
458
|
+
plan(ctx) {
|
|
459
|
+
const { gatewayUrl, key, model, contextWindow } = ctx;
|
|
404
460
|
// pi reads a custom provider's base URL only from models.json, so the
|
|
405
461
|
// shipped extension registers a "stav-cli" provider from the STAV_PI_*
|
|
406
462
|
// variables (checked with pi 1.7.0). --provider is always given: Stav
|
|
@@ -409,6 +465,10 @@ const pi = {
|
|
|
409
465
|
const base = `${gatewayUrl}/v1`;
|
|
410
466
|
const id = model ?? 'auto';
|
|
411
467
|
const window = contextWindow && namedModel(model) ? contextWindow : PI_DEFAULT_CONTEXT;
|
|
468
|
+
// Every chat model, Router and auto the key may use, for pi's model
|
|
469
|
+
// picker (/model), in STAV_PI_MODELS; the launch's model comes first.
|
|
470
|
+
const toEnv = (m) => ({ id: m.id, contextWindow: m.contextWindow ?? PI_DEFAULT_CONTEXT });
|
|
471
|
+
const picker = pickerModels(ctx, PI_DEFAULT_CONTEXT, (m) => JSON.stringify(toEnv(m)).length + 1);
|
|
412
472
|
// undefined: the preview, before the key exists; null: read, and Stav knows none.
|
|
413
473
|
const describeWindow = contextWindow && namedModel(model)
|
|
414
474
|
? `a context window of ${contextWindow} tokens (the model's in your workspace)`
|
|
@@ -424,6 +484,7 @@ const pi = {
|
|
|
424
484
|
STAV_PI_MODEL: id,
|
|
425
485
|
STAV_PI_CONTEXT_WINDOW: String(window),
|
|
426
486
|
STAV_PI_MAX_TOKENS: String(PI_MAX_TOKENS),
|
|
487
|
+
STAV_PI_MODELS: JSON.stringify(picker.models.map(toEnv)),
|
|
427
488
|
// No model catalogue refresh or update check at pi.dev.
|
|
428
489
|
PI_OFFLINE: '1',
|
|
429
490
|
},
|
|
@@ -433,9 +494,10 @@ const pi = {
|
|
|
433
494
|
'STAV_PI_API_KEY=<the key, in the environment only>',
|
|
434
495
|
model ? `model ${model}` : "model auto (your workspace's default Router)",
|
|
435
496
|
describeWindow,
|
|
497
|
+
describePicker(picker.models, picker.dropped, ctx, '/model'),
|
|
436
498
|
`at most ${PI_MAX_TOKENS} output tokens per call`,
|
|
437
499
|
'PI_OFFLINE=1 (no model catalogue refresh or update check at pi.dev)',
|
|
438
|
-
'note: pi runs the commands the model writes without asking; run it in a folder or container where that is safe',
|
|
500
|
+
'note: pi runs the commands the model writes without asking, and those commands can read STAV_PI_API_KEY from their environment; run it in a folder or container where that is safe',
|
|
439
501
|
'run one task without the chat screen after --, for example: stav launch pi -- -p "fix the failing test"',
|
|
440
502
|
],
|
|
441
503
|
};
|
|
@@ -475,13 +537,93 @@ const pi = {
|
|
|
475
537
|
return null;
|
|
476
538
|
},
|
|
477
539
|
};
|
|
478
|
-
|
|
540
|
+
/** The folder Hermes reads its fixed overlay from; built next to this module (npm run build copies it). */
|
|
541
|
+
export const HERMES_MANAGED_DIR = fileURLToPath(new URL('./hermes-managed/', import.meta.url));
|
|
542
|
+
/** The provider id in that overlay; one only the CLI uses. */
|
|
543
|
+
export const HERMES_PROVIDER = 'stav-cli';
|
|
544
|
+
/** The folder that holds the Hermes homes of every launch. */
|
|
545
|
+
export function hermesHomes(home = os.homedir()) {
|
|
546
|
+
return path.join(home, '.stav', 'hermes');
|
|
547
|
+
}
|
|
548
|
+
/**
|
|
549
|
+
* The Hermes home a launch uses: its own, never the person's ~/.hermes, and
|
|
550
|
+
* one per key. Hermes runs every turn in a background process that reads the
|
|
551
|
+
* key from its own environment and from <home>/.env, which wins over the
|
|
552
|
+
* environment. Into the person's home, a launch would use a key saved there
|
|
553
|
+
* or the key of a Hermes window already open; into one shared home, a launch
|
|
554
|
+
* for another workspace would use the key of a launch still open, and bill
|
|
555
|
+
* the wrong workspace (checked with Hermes 0.23.5). The folder name is a
|
|
556
|
+
* short hash of the key, never the key.
|
|
557
|
+
*/
|
|
558
|
+
export function hermesHome(key, home = os.homedir()) {
|
|
559
|
+
return path.join(hermesHomes(home), createHash('sha256').update(key).digest('hex').slice(0, 16));
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* Variables that would send this run somewhere else, or change what the
|
|
563
|
+
* overlay sets: another provider, base URL or model, a remote gateway, a
|
|
564
|
+
* profile, or a mode that skips the config or the command approvals. Also
|
|
565
|
+
* STAV_API_KEY: Hermes would take it as the key for any api.stav.ai address.
|
|
566
|
+
*/
|
|
567
|
+
export const HERMES_UNSET = [
|
|
568
|
+
'STAV_API_KEY',
|
|
569
|
+
'OPENAI_BASE_URL', 'OPENAI_API_KEY',
|
|
570
|
+
'CUSTOM_BASE_URL', 'CUSTOM_API_KEY',
|
|
571
|
+
'OPENROUTER_BASE_URL', 'OPENROUTER_API_KEY',
|
|
572
|
+
'HERMES_INFERENCE_PROVIDER', 'HERMES_INFERENCE_MODEL', 'HERMES_MODEL',
|
|
573
|
+
'HERMES_TUI_PROVIDER', 'HERMES_TUI_GATEWAY_URL', 'HERMES_PROFILE',
|
|
574
|
+
'HERMES_YOLO_MODE', 'HERMES_SAFE_MODE', 'HERMES_IGNORE_USER_CONFIG', 'HERMES_ACCEPT_HOOKS',
|
|
575
|
+
];
|
|
576
|
+
const hermesAgent = {
|
|
577
|
+
name: 'hermes-agent',
|
|
578
|
+
apps: ['hermes-agent'],
|
|
579
|
+
displayName: 'Hermes Agent',
|
|
580
|
+
program: 'hermes',
|
|
581
|
+
// Hermes reads GET /v1/models for each model's context window.
|
|
582
|
+
scopes: ['inference:chat', 'inference:models'],
|
|
583
|
+
plan({ gatewayUrl, key, model }) {
|
|
584
|
+
// Hermes takes this run's provider from the overlay in HERMES_MANAGED_DIR,
|
|
585
|
+
// whose values all come from the STAV_HERMES_* variables, and keeps its
|
|
586
|
+
// state in a home of its own (checked with Hermes 0.23.5). It reads each
|
|
587
|
+
// model's context window from Stav itself. The provider and model are
|
|
588
|
+
// also given as arguments: a second window shares the first one's
|
|
589
|
+
// background process, which would otherwise keep the first one's model.
|
|
590
|
+
// With no model, "auto" (the workspace's default Router), never Hermes's
|
|
591
|
+
// own default.
|
|
592
|
+
const base = `${gatewayUrl}/v1`;
|
|
593
|
+
const id = model ?? 'auto';
|
|
594
|
+
const home = hermesHome(key);
|
|
595
|
+
return {
|
|
596
|
+
program: 'hermes',
|
|
597
|
+
args: ['--provider', `custom:${HERMES_PROVIDER}`, '-m', id],
|
|
598
|
+
env: {
|
|
599
|
+
HERMES_HOME: home,
|
|
600
|
+
HERMES_MANAGED_DIR,
|
|
601
|
+
STAV_HERMES_API_KEY: key,
|
|
602
|
+
STAV_HERMES_BASE_URL: base,
|
|
603
|
+
STAV_HERMES_MODEL: id,
|
|
604
|
+
},
|
|
605
|
+
unset: [...HERMES_UNSET],
|
|
606
|
+
describe: [
|
|
607
|
+
`Hermes Agent with a "${HERMES_PROVIDER}" provider at ${base}, set by a file that ships with the Stav CLI, for this run only`,
|
|
608
|
+
`a Hermes home of its own in ${hermesHomes()}, one folder per API key (a new key starts an empty one): sessions, memory and skills there are kept apart from your own Hermes, and ~/.hermes is not read or changed`,
|
|
609
|
+
'STAV_HERMES_API_KEY=<the key, in the environment only>',
|
|
610
|
+
model ? `model ${model}` : "model auto (your workspace's default Router)",
|
|
611
|
+
"Hermes reads each model's context window from Stav",
|
|
612
|
+
'no update check at GitHub and no free third-party web search fallback (both would go around Stav)',
|
|
613
|
+
'note: Hermes runs the commands the model writes. Commands it does not judge dangerous run without asking, and with -z every command runs without asking. Those commands can read STAV_HERMES_API_KEY from their environment; run it in a folder or container where that is safe',
|
|
614
|
+
'run one task without the chat screen after --, for example: stav launch hermes-agent -- -z "fix the failing test"',
|
|
615
|
+
],
|
|
616
|
+
};
|
|
617
|
+
},
|
|
618
|
+
};
|
|
619
|
+
export const ADAPTERS = [claudeCode, codex, deepseekHarness, kiloCode, githubCopilot, pi, hermesAgent];
|
|
479
620
|
/** Names a person may type for an app (DECIDE-APPS-P: `claude` → claude-code). */
|
|
480
621
|
export const ALIASES = {
|
|
481
622
|
claude: 'claude-code',
|
|
482
623
|
dsh: 'deepseek-harness',
|
|
483
624
|
kilo: 'kilo-code',
|
|
484
625
|
copilot: 'github-copilot',
|
|
626
|
+
hermes: 'hermes-agent',
|
|
485
627
|
};
|
|
486
628
|
export function resolveApp(name) {
|
|
487
629
|
const n = name.trim().toLowerCase();
|
|
@@ -8,25 +8,41 @@
|
|
|
8
8
|
// registered at startup is ready for --provider/--model on the same run, and
|
|
9
9
|
// ~/.pi/agent is not changed. Checked with pi 1.7.0.
|
|
10
10
|
|
|
11
|
+
// STAV_PI_MODELS is the list for pi's model picker (/model): every chat
|
|
12
|
+
// model, Router and auto the key may use, the launch's model first, each as
|
|
13
|
+
// {id, contextWindow}. Without it, or when it does not read, only
|
|
14
|
+
// STAV_PI_MODEL is offered.
|
|
15
|
+
function pickerModels(env) {
|
|
16
|
+
const one = [{ id: env.STAV_PI_MODEL, contextWindow: Number(env.STAV_PI_CONTEXT_WINDOW) }];
|
|
17
|
+
let list;
|
|
18
|
+
try {
|
|
19
|
+
list = JSON.parse(env.STAV_PI_MODELS ?? "");
|
|
20
|
+
} catch {
|
|
21
|
+
return one;
|
|
22
|
+
}
|
|
23
|
+
if (!Array.isArray(list)) return one;
|
|
24
|
+
const ok = list.filter(
|
|
25
|
+
(m) => m && typeof m.id === "string" && m.id && Number.isInteger(m.contextWindow) && m.contextWindow > 0,
|
|
26
|
+
);
|
|
27
|
+
return ok.length ? ok : one;
|
|
28
|
+
}
|
|
29
|
+
|
|
11
30
|
export default function stavProvider(pi) {
|
|
12
31
|
const env = process.env;
|
|
13
|
-
const model = env.STAV_PI_MODEL;
|
|
14
32
|
pi.registerProvider("stav-cli", {
|
|
15
33
|
name: "Stav",
|
|
16
34
|
baseUrl: env.STAV_PI_BASE_URL,
|
|
17
35
|
apiKey: "$STAV_PI_API_KEY",
|
|
18
36
|
api: "openai-completions",
|
|
19
|
-
models:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
},
|
|
30
|
-
],
|
|
37
|
+
models: pickerModels(env).map((m) => ({
|
|
38
|
+
type: "chat",
|
|
39
|
+
id: m.id,
|
|
40
|
+
name: m.id,
|
|
41
|
+
reasoning: false,
|
|
42
|
+
input: ["text"],
|
|
43
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
44
|
+
contextWindow: m.contextWindow,
|
|
45
|
+
maxTokens: Number(env.STAV_PI_MAX_TOKENS),
|
|
46
|
+
})),
|
|
31
47
|
});
|
|
32
48
|
}
|
package/dist/cli.js
CHANGED
|
@@ -46,6 +46,7 @@ Examples:
|
|
|
46
46
|
stav launch kilo
|
|
47
47
|
stav launch copilot -- -p "fix the failing test"
|
|
48
48
|
stav launch pi
|
|
49
|
+
stav launch hermes -- -z "fix the failing test"
|
|
49
50
|
`;
|
|
50
51
|
// Every line goes through terminalText: much of it is text from the Stav API.
|
|
51
52
|
const out = (line = '') => process.stdout.write(`${terminalText(line)}\n`);
|
package/dist/launch.js
CHANGED
|
@@ -26,7 +26,11 @@ export const INSTALL_PACKAGE = {
|
|
|
26
26
|
copilot: '@github/copilot',
|
|
27
27
|
pi: '@earendil-works/pi-coding-agent',
|
|
28
28
|
};
|
|
29
|
-
export const INSTALL_HINT =
|
|
29
|
+
export const INSTALL_HINT = {
|
|
30
|
+
...Object.fromEntries(Object.entries(INSTALL_PACKAGE).map(([program, pkg]) => [program, `npm install -g ${pkg}`])),
|
|
31
|
+
// Not on npm: Hermes installs with its own installer, so the CLI only says where.
|
|
32
|
+
hermes: 'its installer, see https://hermes-agent.nousresearch.com/docs/getting-started/quickstart',
|
|
33
|
+
};
|
|
30
34
|
/**
|
|
31
35
|
* Everything that can refuse runs first; only then, if the app is missing,
|
|
32
36
|
* is the install offered, so a yes never installs an app for a launch that
|
|
@@ -257,8 +261,9 @@ export async function launch(opts, d) {
|
|
|
257
261
|
if (plan.workspace && plan.rememberWorkspace)
|
|
258
262
|
await d.saveSetting('workspace', plan.workspace.id);
|
|
259
263
|
const secret = await settleKey(plan, d);
|
|
260
|
-
|
|
261
|
-
const
|
|
264
|
+
// Both reads at once: each gives up after its own timeout.
|
|
265
|
+
const [contextWindow, models] = await Promise.all([readContextWindow(plan, secret, d), readModelList(plan, secret, d)]);
|
|
266
|
+
const run = plan.adapter.plan({ gatewayUrl: d.cfg.gatewayUrl, key: secret, model: plan.model, contextWindow, models });
|
|
262
267
|
const env = { ...d.env };
|
|
263
268
|
for (const k of run.unset)
|
|
264
269
|
delete env[k];
|
|
@@ -289,6 +294,29 @@ async function readContextWindow(plan, key, d) {
|
|
|
289
294
|
d.log(`Stav does not know the context window of ${plan.model} for your workspace; ${plan.adapter.displayName} starts without the window from Stav (see the plan above for what it uses).`);
|
|
290
295
|
return n;
|
|
291
296
|
}
|
|
297
|
+
/**
|
|
298
|
+
* Every chat model, Router and auto the key may use, when the adapter wants
|
|
299
|
+
* them for the app's model picker. Never stops the launch: without the list
|
|
300
|
+
* the app offers only the launch's model, and the person is told.
|
|
301
|
+
* ``undefined`` when the adapter does not want it.
|
|
302
|
+
*/
|
|
303
|
+
async function readModelList(plan, key, d) {
|
|
304
|
+
if (!plan.adapter.wantsModelList)
|
|
305
|
+
return undefined;
|
|
306
|
+
d.log('Reading the models and Routers your key may use from Stav...');
|
|
307
|
+
try {
|
|
308
|
+
const list = await new Stav(d.cfg, d.fetchFn).chatModels(key);
|
|
309
|
+
if (list === null)
|
|
310
|
+
d.log(`Stav did not list the models for this key; ${plan.adapter.displayName} offers only ${plan.model ?? 'auto'}.`);
|
|
311
|
+
else
|
|
312
|
+
d.log(`Stav listed ${list.length} models and Routers for this key.`);
|
|
313
|
+
return list;
|
|
314
|
+
}
|
|
315
|
+
catch (err) {
|
|
316
|
+
d.log(`Could not read the models your key may use (${err instanceof Error ? err.message : String(err)}); ${plan.adapter.displayName} offers only ${plan.model ?? 'auto'}.`);
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
292
320
|
/** PATH lookup without a shell. */
|
|
293
321
|
export function which(program, env = process.env) {
|
|
294
322
|
for (const dir of (env.PATH ?? '').split(path.delimiter)) {
|
package/dist/stav.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** The Stav calls the CLI makes, typed. */
|
|
2
|
+
import { MODEL_RE } from './adapters/index.js';
|
|
2
3
|
import { StavError } from './errors.js';
|
|
3
4
|
import { request } from './http.js';
|
|
4
5
|
/**
|
|
@@ -56,6 +57,35 @@ export class Stav {
|
|
|
56
57
|
const m = await request(this.fetchFn, `${this.cfg.gatewayUrl}/v1/models/${path}`, { token: key, nullOn: [401, 403, 404], timeoutMs: WINDOW_TIMEOUT_MS });
|
|
57
58
|
return ok(m?.context_length) ? m.context_length : null;
|
|
58
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Every chat model the key's workspace may use, with ``auto`` and the
|
|
62
|
+
* workspace's Routers, from the gateway's model list (the key's own
|
|
63
|
+
* policy). Order: ``auto``, then the Routers, then the models in the
|
|
64
|
+
* gateway's order. ``contextWindow`` is the list's ``context_length``:
|
|
65
|
+
* the smallest window any serving endpoint states, so it holds wherever
|
|
66
|
+
* a call lands; null for ``auto``, a Router, or a model with none stated.
|
|
67
|
+
* Null when the gateway refuses the key.
|
|
68
|
+
*/
|
|
69
|
+
async chatModels(key) {
|
|
70
|
+
const list = await request(this.fetchFn, `${this.cfg.gatewayUrl}/v1/models`, { token: key, nullOn: [401, 403, 404], timeoutMs: WINDOW_TIMEOUT_MS });
|
|
71
|
+
if (!list)
|
|
72
|
+
return null;
|
|
73
|
+
const out = [];
|
|
74
|
+
const seen = new Set();
|
|
75
|
+
for (const m of list.data ?? []) {
|
|
76
|
+
if (typeof m.id !== 'string' || !MODEL_RE.test(m.id) || seen.has(m.id))
|
|
77
|
+
continue;
|
|
78
|
+
if (!Array.isArray(m.stav_surfaces) || !m.stav_surfaces.includes('chat'))
|
|
79
|
+
continue;
|
|
80
|
+
seen.add(m.id);
|
|
81
|
+
const router = m.id === 'auto' || m.id.startsWith('@');
|
|
82
|
+
const n = m.context_length;
|
|
83
|
+
out.push({ id: m.id, contextWindow: !router && typeof n === 'number' && Number.isInteger(n) && n > 0 ? n : null });
|
|
84
|
+
}
|
|
85
|
+
const rank = (id) => (id === 'auto' ? 0 : id.startsWith('@') ? 1 : 2);
|
|
86
|
+
// Array.prototype.sort is stable: the gateway's order holds inside each group.
|
|
87
|
+
return out.sort((a, b) => rank(a.id) - rank(b.id));
|
|
88
|
+
}
|
|
59
89
|
/** Whether a key still works, and for which workspace. Null when it does not. */
|
|
60
90
|
checkKey(key) {
|
|
61
91
|
return request(this.fetchFn, `${this.cfg.gatewayUrl}/v1/auth/validate`, { token: key, nullOn: [401, 403] });
|
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.6';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stav-ai/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "Run your coding agent on Stav: sign in, get a key for the app, and start it pointed at the Stav gateway.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"node": ">=22"
|
|
16
16
|
},
|
|
17
17
|
"scripts": {
|
|
18
|
-
"build": "tsc -p tsconfig.build.json && node --input-type=module -e \"import { copyFileSync } from 'node:fs'; copyFileSync('src/adapters/deepseek-harness.patch.yml', 'dist/adapters/deepseek-harness.patch.yml'); copyFileSync('src/adapters/pi-stav-provider.js', 'dist/adapters/pi-stav-provider.js')\"",
|
|
18
|
+
"build": "tsc -p tsconfig.build.json && node --input-type=module -e \"import { copyFileSync, mkdirSync } from 'node:fs'; copyFileSync('src/adapters/deepseek-harness.patch.yml', 'dist/adapters/deepseek-harness.patch.yml'); copyFileSync('src/adapters/pi-stav-provider.js', 'dist/adapters/pi-stav-provider.js'); mkdirSync('dist/adapters/hermes-managed', { recursive: true }); copyFileSync('src/adapters/hermes-managed/config.yaml', 'dist/adapters/hermes-managed/config.yaml')\"",
|
|
19
19
|
"prepack": "npm run build",
|
|
20
20
|
"typecheck": "tsc --noEmit",
|
|
21
21
|
"test": "tsx --test 'src/**/*.test.ts'",
|