@stav-ai/cli 0.1.2 → 0.1.4
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 +46 -3
- package/dist/adapters/adapters.json +15 -0
- package/dist/adapters/index.js +265 -4
- package/dist/adapters/pi-stav-provider.js +32 -0
- package/dist/cli.js +3 -0
- package/dist/launch.js +52 -11
- package/dist/version.js +2 -2
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -8,6 +8,9 @@ needs, and starts the app pointed at Stav.
|
|
|
8
8
|
npx @stav-ai/cli launch claude
|
|
9
9
|
npx @stav-ai/cli launch codex --model zai-org/glm-5-2
|
|
10
10
|
npx @stav-ai/cli launch dsh -- "run the tests"
|
|
11
|
+
npx @stav-ai/cli launch kilo
|
|
12
|
+
npx @stav-ai/cli launch copilot
|
|
13
|
+
npx @stav-ai/cli launch pi
|
|
11
14
|
```
|
|
12
15
|
|
|
13
16
|
Always use the scoped name `@stav-ai/cli`. The unscoped `stav` package on npm
|
|
@@ -24,8 +27,12 @@ is not ours.
|
|
|
24
27
|
| `stav apps` | The apps this CLI can launch |
|
|
25
28
|
| `stav launch <app> [--model <id>] [--workspace <slug>] [--yes] [-- <app arguments>]` | Start an app on Stav |
|
|
26
29
|
|
|
27
|
-
It launches **Claude Code** (`claude`), **Codex** (`codex`)
|
|
28
|
-
**DeepSeek Harness** (`dsh`)
|
|
30
|
+
It launches **Claude Code** (`claude`), **Codex** (`codex`),
|
|
31
|
+
**DeepSeek Harness** (`dsh`), **Kilo Code** (`kilo`), the
|
|
32
|
+
**GitHub Copilot CLI** (`copilot`) and **pi** (`pi`). If the app is
|
|
33
|
+
not installed, it offers to install it with `npm install -g` and does so
|
|
34
|
+
only if you say yes. With `--yes`, or with no terminal, it installs
|
|
35
|
+
nothing and prints the command instead.
|
|
29
36
|
|
|
30
37
|
## What `stav launch` does
|
|
31
38
|
|
|
@@ -36,7 +43,8 @@ It launches **Claude Code** (`claude`), **Codex** (`codex`) and
|
|
|
36
43
|
refuses it and you are an owner or admin, a workspace key instead;
|
|
37
44
|
- named for the app and you, marked with the app in your request log;
|
|
38
45
|
- with only the scope the app needs (`inference:messages` for Claude Code,
|
|
39
|
-
`inference:chat` for Codex
|
|
46
|
+
`inference:chat` for Codex, DeepSeek Harness, Kilo Code, the
|
|
47
|
+
GitHub Copilot CLI and pi).
|
|
40
48
|
4. Starts the app with the Stav gateway and the key in its environment.
|
|
41
49
|
**No file is written.** Your `~/.claude` and `~/.codex/config.toml` are not
|
|
42
50
|
changed. For a model Claude Code does not know, the CLI also tells it the
|
|
@@ -52,6 +60,41 @@ It launches **Claude Code** (`claude`), **Codex** (`codex`) and
|
|
|
52
60
|
model writes without asking. Its own `SAFETY.md` says to run it in a
|
|
53
61
|
container or a VM.
|
|
54
62
|
|
|
63
|
+
Kilo Code takes the whole Stav provider from the environment
|
|
64
|
+
(`KILO_CONFIG_CONTENT`, which it reads after its own config files). The
|
|
65
|
+
key is only in `STAV_KILO_API_KEY`. For this run Stav is Kilo Code's only
|
|
66
|
+
provider, and your `~/.config/kilo` is not changed. The CLI also turns off
|
|
67
|
+
Kilo Code's usage data and session uploads to Kilo
|
|
68
|
+
(`KILO_TELEMETRY_LEVEL=off`, `KILO_DISABLE_SESSION_INGEST=1`,
|
|
69
|
+
`KILO_DISABLE_SHARE=1`). It starts the chat screen; for one task without
|
|
70
|
+
it, give `run "<task>"` after `--`. `kilo run` cannot ask, so it refuses
|
|
71
|
+
the shell commands it would ask about: add `--auto` after `run` to let it
|
|
72
|
+
run them without asking.
|
|
73
|
+
|
|
74
|
+
The GitHub Copilot CLI takes Stav as its model provider from the
|
|
75
|
+
environment (`COPILOT_PROVIDER_BASE_URL` and `COPILOT_PROVIDER_API_KEY`).
|
|
76
|
+
It then needs no GitHub sign-in, and no provider settings are written to
|
|
77
|
+
`~/.copilot`. The
|
|
78
|
+
CLI also sets `COPILOT_OFFLINE=true`, so the Copilot CLI sends nothing to
|
|
79
|
+
GitHub: no sign-in, telemetry, web tools, GitHub MCP server or
|
|
80
|
+
auto-update. The Copilot CLI keeps the model name `auto` for GitHub's own
|
|
81
|
+
router, so for `auto` or a Router the CLI names the model `stav-router`
|
|
82
|
+
and sends the Stav value as `COPILOT_PROVIDER_WIRE_MODEL`. The Copilot CLI
|
|
83
|
+
asks before it runs a tool; the CLI removes `COPILOT_ALLOW_ALL` from your
|
|
84
|
+
shell for the run so that stays true. For one task without the chat
|
|
85
|
+
screen, give `-p "<task>"` after `--`. `-p` cannot ask, so it refuses
|
|
86
|
+
edits and commands: add `--allow-tool` or `--allow-all-tools` after the
|
|
87
|
+
task to allow them without asking.
|
|
88
|
+
|
|
89
|
+
pi reads a provider's address only from its own `models.json`, so the CLI
|
|
90
|
+
starts it with `--extension` and a provider file that ships with the CLI.
|
|
91
|
+
That file holds no key and no address: every value comes from the
|
|
92
|
+
environment, and the key is only in `STAV_PI_API_KEY`. No provider
|
|
93
|
+
settings are written to `~/.pi/agent`. The CLI also sets `PI_OFFLINE=1`, so pi does not refresh
|
|
94
|
+
its model catalogue or check for updates at pi.dev. pi runs the commands
|
|
95
|
+
the model writes without asking. For one task without the chat screen,
|
|
96
|
+
give `-p "<task>"` after `--`.
|
|
97
|
+
|
|
55
98
|
The key is kept in your operating system's keychain, or in a file only you
|
|
56
99
|
can read when there is no keychain. Never in your project folder.
|
|
57
100
|
|
package/dist/adapters/index.js
CHANGED
|
@@ -5,9 +5,13 @@
|
|
|
5
5
|
* default model. Everything that runs on the person's machine — the program,
|
|
6
6
|
* its environment and its arguments — is here, reviewed and released with
|
|
7
7
|
* the CLI. No adapter writes a file: Claude Code and Codex take everything
|
|
8
|
-
* from the environment and the command line,
|
|
8
|
+
* from the environment and the command line, DeepSeek Harness reads a
|
|
9
9
|
* fixed overlay file shipped with the CLI (deepseek-harness.patch.yml) whose
|
|
10
|
-
* values all come from the environment
|
|
10
|
+
* values all come from the environment, Kilo Code takes its whole
|
|
11
|
+
* provider from KILO_CONFIG_CONTENT, the GitHub Copilot CLI from its
|
|
12
|
+
* COPILOT_PROVIDER_* variables, and pi from a fixed provider extension
|
|
13
|
+
* shipped with the CLI (pi-stav-provider.js) whose values all come from the
|
|
14
|
+
* environment. The key goes only into the child's
|
|
11
15
|
* environment, never into its arguments or a file (R-20).
|
|
12
16
|
*
|
|
13
17
|
* adapters.json is byte-identical to the Stav API's
|
|
@@ -219,9 +223,266 @@ const deepseekHarness = {
|
|
|
219
223
|
};
|
|
220
224
|
},
|
|
221
225
|
};
|
|
222
|
-
|
|
226
|
+
/** 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
|
+
export const KILO_PROVIDER = 'stav-cli';
|
|
228
|
+
/**
|
|
229
|
+
* The output cap Kilo Code sends as max_tokens on every call (limit.output).
|
|
230
|
+
* 16,384 is the value the app test proved; Stav lowers it to an endpoint's
|
|
231
|
+
* own cap and names that in X-Stav-Clamped-Params.
|
|
232
|
+
*/
|
|
233
|
+
export const KILO_MAX_OUTPUT = 16_384;
|
|
234
|
+
/**
|
|
235
|
+
* The context window given for auto, a Router, or a model Stav knows no
|
|
236
|
+
* window for. Kilo Code compacts by it; 128,000 fits the smaller models a
|
|
237
|
+
* Router may pick.
|
|
238
|
+
*/
|
|
239
|
+
export const KILO_DEFAULT_CONTEXT = 128_000;
|
|
240
|
+
const kiloCode = {
|
|
241
|
+
name: 'kilo-code',
|
|
242
|
+
apps: ['kilo-code'],
|
|
243
|
+
displayName: 'Kilo Code',
|
|
244
|
+
program: 'kilo',
|
|
245
|
+
scopes: ['inference:chat'],
|
|
246
|
+
wantsContextWindow: namedModel,
|
|
247
|
+
plan({ gatewayUrl, key, model, contextWindow }) {
|
|
248
|
+
// Kilo Code merges KILO_CONFIG_CONTENT after the global and the project
|
|
249
|
+
// config files, and resolves {env:} in it (checked with Kilo Code
|
|
250
|
+
// 7.8.40), so the whole provider is given in the environment and no file
|
|
251
|
+
// is written. The key itself is only in STAV_KILO_API_KEY, a name no
|
|
252
|
+
// other tool uses. enabled_providers replaces any list the person has,
|
|
253
|
+
// so for this run Stav is the only provider: an agent or small_model in
|
|
254
|
+
// their config set to another provider fails instead of going there.
|
|
255
|
+
// With no model, "auto" (the workspace's default Router), never Kilo's
|
|
256
|
+
// own cloud default.
|
|
257
|
+
const base = `${gatewayUrl}/v1`;
|
|
258
|
+
const id = model ?? 'auto';
|
|
259
|
+
const ref = `${KILO_PROVIDER}/${id}`;
|
|
260
|
+
const window = contextWindow && namedModel(model) ? contextWindow : KILO_DEFAULT_CONTEXT;
|
|
261
|
+
// The config files merge deep, so a "stav-cli" block in the person's own
|
|
262
|
+
// config keeps every key this one does not set. The SDK and the address
|
|
263
|
+
// are therefore set at both levels Kilo Code reads them from (provider and
|
|
264
|
+
// model); options.baseURL wins over both. Headers from such a block still
|
|
265
|
+
// reach Stav, never anywhere else. Only a Kilo organisation's console
|
|
266
|
+
// config and MDM-managed config merge after KILO_CONFIG_CONTENT; those are
|
|
267
|
+
// set by the person's administrator and are meant to win.
|
|
268
|
+
const sdk = '@ai-sdk/openai-compatible';
|
|
269
|
+
const config = {
|
|
270
|
+
model: ref,
|
|
271
|
+
small_model: ref,
|
|
272
|
+
enabled_providers: [KILO_PROVIDER],
|
|
273
|
+
provider: {
|
|
274
|
+
[KILO_PROVIDER]: {
|
|
275
|
+
npm: sdk,
|
|
276
|
+
api: base,
|
|
277
|
+
name: 'Stav',
|
|
278
|
+
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
|
+
},
|
|
282
|
+
},
|
|
283
|
+
},
|
|
284
|
+
};
|
|
285
|
+
// undefined: the preview, before the key exists; null: read, and Stav knows none.
|
|
286
|
+
const describeWindow = contextWindow && namedModel(model)
|
|
287
|
+
? `a context window of ${contextWindow} tokens (the model's in your workspace)`
|
|
288
|
+
: contextWindow === undefined && namedModel(model)
|
|
289
|
+
? "the model's largest context window in your workspace, read from Stav"
|
|
290
|
+
: `a context window of ${KILO_DEFAULT_CONTEXT} tokens (Kilo Code compacts the chat by it)`;
|
|
291
|
+
return {
|
|
292
|
+
program: 'kilo',
|
|
293
|
+
args: [],
|
|
294
|
+
env: {
|
|
295
|
+
STAV_KILO_API_KEY: key,
|
|
296
|
+
KILO_CONFIG_CONTENT: JSON.stringify(config),
|
|
297
|
+
// Usage data to Kilo, and session uploads to Kilo's cloud when signed in.
|
|
298
|
+
KILO_TELEMETRY_LEVEL: 'off',
|
|
299
|
+
KILO_DISABLE_SESSION_INGEST: '1',
|
|
300
|
+
KILO_DISABLE_SHARE: '1',
|
|
301
|
+
},
|
|
302
|
+
unset: [],
|
|
303
|
+
describe: [
|
|
304
|
+
`Kilo Code with a "${KILO_PROVIDER}" provider at ${base} as its only provider, for this run only (your ~/.config/kilo is not changed)`,
|
|
305
|
+
'STAV_KILO_API_KEY=<the key, in the environment only>',
|
|
306
|
+
model ? `model ${model}` : "model auto (your workspace's default Router)",
|
|
307
|
+
describeWindow,
|
|
308
|
+
`at most ${KILO_MAX_OUTPUT} output tokens per call`,
|
|
309
|
+
'KILO_TELEMETRY_LEVEL=off, KILO_DISABLE_SESSION_INGEST=1, KILO_DISABLE_SHARE=1 (no usage data or session uploads to Kilo)',
|
|
310
|
+
'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)',
|
|
311
|
+
'an agent in your Kilo config with a model of its own stops with "Model not found" for this run: Stav is the only provider',
|
|
312
|
+
'run one task without the chat screen after --, for example: stav launch kilo-code -- run "fix the failing test". kilo run refuses the shell commands it would ask about; add --auto after run to allow them without asking',
|
|
313
|
+
],
|
|
314
|
+
};
|
|
315
|
+
},
|
|
316
|
+
};
|
|
317
|
+
/**
|
|
318
|
+
* The name the github-copilot adapter gives the CLI for "auto" or a Router.
|
|
319
|
+
* The Copilot CLI keeps the name "auto" for GitHub's own router and stops
|
|
320
|
+
* before it sends anything ("Auto is unavailable for this account"), so the
|
|
321
|
+
* Stav value goes in COPILOT_PROVIDER_WIRE_MODEL under another name.
|
|
322
|
+
*/
|
|
323
|
+
export const COPILOT_ROUTER_MODEL = 'stav-router';
|
|
324
|
+
const githubCopilot = {
|
|
325
|
+
name: 'github-copilot',
|
|
326
|
+
apps: ['github-copilot'],
|
|
327
|
+
displayName: 'GitHub Copilot CLI',
|
|
328
|
+
program: 'copilot',
|
|
329
|
+
scopes: ['inference:chat'],
|
|
330
|
+
plan({ gatewayUrl, key, model }) {
|
|
331
|
+
// Setting COPILOT_PROVIDER_BASE_URL switches the CLI to its own-provider
|
|
332
|
+
// mode: no GitHub sign-in, and a saved ~/.copilot/providers.json is
|
|
333
|
+
// ignored unless COPILOT_PROVIDERS_CONFIG names one (checked with the
|
|
334
|
+
// Copilot CLI 1.0.117, `copilot help environment`). Chat Completions with
|
|
335
|
+
// the openai type is the path the app test proved end to end. With no
|
|
336
|
+
// model, "auto" (the workspace's default Router), never a GitHub model.
|
|
337
|
+
const base = `${gatewayUrl}/v1`;
|
|
338
|
+
const id = model ?? 'auto';
|
|
339
|
+
const routed = !namedModel(id);
|
|
340
|
+
const env = {
|
|
341
|
+
COPILOT_PROVIDER_BASE_URL: base,
|
|
342
|
+
COPILOT_PROVIDER_TYPE: 'openai',
|
|
343
|
+
COPILOT_PROVIDER_WIRE_API: 'completions',
|
|
344
|
+
COPILOT_PROVIDER_API_KEY: key,
|
|
345
|
+
COPILOT_MODEL: routed ? COPILOT_ROUTER_MODEL : id,
|
|
346
|
+
// No GitHub sign-in, no telemetry to GitHub, no web tools, no GitHub
|
|
347
|
+
// MCP server, no auto-update: only model traffic leaves, to Stav.
|
|
348
|
+
COPILOT_OFFLINE: 'true',
|
|
349
|
+
};
|
|
350
|
+
if (routed)
|
|
351
|
+
env.COPILOT_PROVIDER_WIRE_MODEL = id;
|
|
352
|
+
return {
|
|
353
|
+
program: 'copilot',
|
|
354
|
+
args: [],
|
|
355
|
+
env,
|
|
356
|
+
// Settings from the person's shell that would send this run, or the
|
|
357
|
+
// key, somewhere else: a providers file named here wins over the base
|
|
358
|
+
// URL, and a key command or bearer token wins over the key.
|
|
359
|
+
unset: [
|
|
360
|
+
'COPILOT_PROVIDERS_CONFIG',
|
|
361
|
+
'COPILOT_PROVIDER_API_KEY_COMMAND',
|
|
362
|
+
'COPILOT_PROVIDER_BEARER_TOKEN',
|
|
363
|
+
'COPILOT_PROVIDER_HEADERS',
|
|
364
|
+
'COPILOT_PROVIDER_TRANSPORT',
|
|
365
|
+
'COPILOT_PROVIDER_AZURE_API_VERSION',
|
|
366
|
+
'COPILOT_PROVIDER_MODEL_ID',
|
|
367
|
+
// Sizes and image support set for another provider's model.
|
|
368
|
+
'COPILOT_PROVIDER_MAX_PROMPT_TOKENS',
|
|
369
|
+
'COPILOT_PROVIDER_MAX_OUTPUT_TOKENS',
|
|
370
|
+
'COPILOT_PROVIDER_VISION',
|
|
371
|
+
// Approval turned off in the shell: the launch says it asks first.
|
|
372
|
+
'COPILOT_ALLOW_ALL',
|
|
373
|
+
...(routed ? [] : ['COPILOT_PROVIDER_WIRE_MODEL']),
|
|
374
|
+
],
|
|
375
|
+
describe: [
|
|
376
|
+
`the Copilot CLI with Stav at ${base} as its model provider, for this run only (no provider settings are written to ~/.copilot)`,
|
|
377
|
+
'COPILOT_PROVIDER_API_KEY=<the key, in the environment only>',
|
|
378
|
+
routed
|
|
379
|
+
? `model ${id}${model ? '' : " (your workspace's default Router)"}, given to the CLI as ${COPILOT_ROUTER_MODEL}`
|
|
380
|
+
: `model ${id}`,
|
|
381
|
+
'COPILOT_OFFLINE=true (no GitHub sign-in, telemetry, web tools, GitHub MCP server or auto-update)',
|
|
382
|
+
'note: the Copilot CLI runs commands and edits files. It asks first unless you pass --allow-all-tools (COPILOT_ALLOW_ALL from your shell is removed for this run)',
|
|
383
|
+
'run one task without the chat screen after --, for example: stav launch github-copilot -- -p "fix the failing test". -p cannot ask, so it refuses edits and commands; add --allow-tool or --allow-all-tools after the task to allow them without asking',
|
|
384
|
+
],
|
|
385
|
+
};
|
|
386
|
+
},
|
|
387
|
+
};
|
|
388
|
+
/** The provider extension pi loads; built next to this module (npm run build copies it). */
|
|
389
|
+
export const PI_EXTENSION_FILE = fileURLToPath(new URL('./pi-stav-provider.js', import.meta.url));
|
|
390
|
+
/** The provider id the pi adapter registers; one only the CLI uses. */
|
|
391
|
+
export const PI_PROVIDER = 'stav-cli';
|
|
392
|
+
/** The output cap pi sends as max_completion_tokens (the value the app test proved). */
|
|
393
|
+
export const PI_MAX_TOKENS = 16_384;
|
|
394
|
+
/** The context window given for auto, a Router, or a model Stav knows none for (pi's own default). */
|
|
395
|
+
export const PI_DEFAULT_CONTEXT = 128_000;
|
|
396
|
+
const pi = {
|
|
397
|
+
name: 'pi',
|
|
398
|
+
apps: ['pi'],
|
|
399
|
+
displayName: 'pi',
|
|
400
|
+
program: 'pi',
|
|
401
|
+
scopes: ['inference:chat'],
|
|
402
|
+
wantsContextWindow: namedModel,
|
|
403
|
+
plan({ gatewayUrl, key, model, contextWindow }) {
|
|
404
|
+
// pi reads a custom provider's base URL only from models.json, so the
|
|
405
|
+
// shipped extension registers a "stav-cli" provider from the STAV_PI_*
|
|
406
|
+
// variables (checked with pi 1.7.0). --provider is always given: Stav
|
|
407
|
+
// model ids contain "/", which pi reads as a provider otherwise. With no
|
|
408
|
+
// model, "auto" (the workspace's default Router), never pi's own default.
|
|
409
|
+
const base = `${gatewayUrl}/v1`;
|
|
410
|
+
const id = model ?? 'auto';
|
|
411
|
+
const window = contextWindow && namedModel(model) ? contextWindow : PI_DEFAULT_CONTEXT;
|
|
412
|
+
// undefined: the preview, before the key exists; null: read, and Stav knows none.
|
|
413
|
+
const describeWindow = contextWindow && namedModel(model)
|
|
414
|
+
? `a context window of ${contextWindow} tokens (the model's in your workspace)`
|
|
415
|
+
: contextWindow === undefined && namedModel(model)
|
|
416
|
+
? "the model's largest context window in your workspace, read from Stav"
|
|
417
|
+
: `a context window of ${PI_DEFAULT_CONTEXT} tokens (pi compacts the chat by it)`;
|
|
418
|
+
return {
|
|
419
|
+
program: 'pi',
|
|
420
|
+
args: ['--extension', PI_EXTENSION_FILE, '--provider', PI_PROVIDER, '--model', id],
|
|
421
|
+
env: {
|
|
422
|
+
STAV_PI_API_KEY: key,
|
|
423
|
+
STAV_PI_BASE_URL: base,
|
|
424
|
+
STAV_PI_MODEL: id,
|
|
425
|
+
STAV_PI_CONTEXT_WINDOW: String(window),
|
|
426
|
+
STAV_PI_MAX_TOKENS: String(PI_MAX_TOKENS),
|
|
427
|
+
// No model catalogue refresh or update check at pi.dev.
|
|
428
|
+
PI_OFFLINE: '1',
|
|
429
|
+
},
|
|
430
|
+
unset: [],
|
|
431
|
+
describe: [
|
|
432
|
+
`pi with a "${PI_PROVIDER}" provider at ${base}, loaded from a file that ships with the Stav CLI, for this run only (no provider settings are written to ~/.pi/agent)`,
|
|
433
|
+
'STAV_PI_API_KEY=<the key, in the environment only>',
|
|
434
|
+
model ? `model ${model}` : "model auto (your workspace's default Router)",
|
|
435
|
+
describeWindow,
|
|
436
|
+
`at most ${PI_MAX_TOKENS} output tokens per call`,
|
|
437
|
+
'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',
|
|
439
|
+
'run one task without the chat screen after --, for example: stav launch pi -- -p "fix the failing test"',
|
|
440
|
+
],
|
|
441
|
+
};
|
|
442
|
+
},
|
|
443
|
+
async conflicts(home = os.homedir(), cwd = process.cwd(), env = process.env, appArgs = []) {
|
|
444
|
+
// A "stav-cli" entry in pi's own models.json is merged over the
|
|
445
|
+
// extension and could send the key to another address; a stored
|
|
446
|
+
// credential for it would replace the key. The check reads the folder pi
|
|
447
|
+
// will read. pi accepts comments and a BOM in these files (pi 1.7.0,
|
|
448
|
+
// model-config.js), so the provider id written out anywhere in them
|
|
449
|
+
// counts, parsed or not; an id spelled with JSON escapes is not caught.
|
|
450
|
+
// Not checked: extensions pi loads from <agent-dir>/extensions, from a
|
|
451
|
+
// trusted project's .pi/ or from packages. Those run code in pi already,
|
|
452
|
+
// so they can read the key with or without this launch.
|
|
453
|
+
if (appArgs.some((a) => a === '--agent-dir' || a.startsWith('--agent-dir='))) {
|
|
454
|
+
return 'stav launch pi cannot check a folder given with --agent-dir. Set PI_CODING_AGENT_DIR instead, then run stav launch again.';
|
|
455
|
+
}
|
|
456
|
+
// Exactly the value pi reads: no trimming, so both read the same folder.
|
|
457
|
+
const configured = env.PI_CODING_AGENT_DIR;
|
|
458
|
+
const expanded = configured
|
|
459
|
+
? configured === '~' || configured.startsWith('~/') ? path.join(home, configured.slice(1)) : configured
|
|
460
|
+
: path.join(home, '.pi', 'agent');
|
|
461
|
+
const dir = path.resolve(cwd, expanded);
|
|
462
|
+
for (const name of ['models.json', 'auth.json']) {
|
|
463
|
+
const file = path.join(dir, name);
|
|
464
|
+
let text;
|
|
465
|
+
try {
|
|
466
|
+
text = await fs.readFile(file, 'utf8');
|
|
467
|
+
}
|
|
468
|
+
catch {
|
|
469
|
+
continue; // No file: nothing overrides.
|
|
470
|
+
}
|
|
471
|
+
if (text.includes(`"${PI_PROVIDER}"`)) {
|
|
472
|
+
return `pi's ${name} (${file}) has an entry for "${PI_PROVIDER}", which would override the launch. Remove it, then run stav launch again.`;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
return null;
|
|
476
|
+
},
|
|
477
|
+
};
|
|
478
|
+
export const ADAPTERS = [claudeCode, codex, deepseekHarness, kiloCode, githubCopilot, pi];
|
|
223
479
|
/** Names a person may type for an app (DECIDE-APPS-P: `claude` → claude-code). */
|
|
224
|
-
export const ALIASES = {
|
|
480
|
+
export const ALIASES = {
|
|
481
|
+
claude: 'claude-code',
|
|
482
|
+
dsh: 'deepseek-harness',
|
|
483
|
+
kilo: 'kilo-code',
|
|
484
|
+
copilot: 'github-copilot',
|
|
485
|
+
};
|
|
225
486
|
export function resolveApp(name) {
|
|
226
487
|
const n = name.trim().toLowerCase();
|
|
227
488
|
return ALIASES[n] ?? n;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// The Stav provider for pi, given to `pi --extension` by the pi adapter in
|
|
2
|
+
// index.ts. Shipped with the CLI and never written at run time: every value
|
|
3
|
+
// comes from the environment the CLI sets for the child, so the key is never
|
|
4
|
+
// in this file or in an argument (R-20).
|
|
5
|
+
//
|
|
6
|
+
// pi reads a custom provider from models.json, where only apiKey and headers
|
|
7
|
+
// take environment variables; the base URL does not. A provider extension
|
|
8
|
+
// registered at startup is ready for --provider/--model on the same run, and
|
|
9
|
+
// ~/.pi/agent is not changed. Checked with pi 1.7.0.
|
|
10
|
+
|
|
11
|
+
export default function stavProvider(pi) {
|
|
12
|
+
const env = process.env;
|
|
13
|
+
const model = env.STAV_PI_MODEL;
|
|
14
|
+
pi.registerProvider("stav-cli", {
|
|
15
|
+
name: "Stav",
|
|
16
|
+
baseUrl: env.STAV_PI_BASE_URL,
|
|
17
|
+
apiKey: "$STAV_PI_API_KEY",
|
|
18
|
+
api: "openai-completions",
|
|
19
|
+
models: [
|
|
20
|
+
{
|
|
21
|
+
type: "chat",
|
|
22
|
+
id: model,
|
|
23
|
+
name: model,
|
|
24
|
+
reasoning: false,
|
|
25
|
+
input: ["text"],
|
|
26
|
+
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
27
|
+
contextWindow: Number(env.STAV_PI_CONTEXT_WINDOW),
|
|
28
|
+
maxTokens: Number(env.STAV_PI_MAX_TOKENS),
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
});
|
|
32
|
+
}
|
package/dist/cli.js
CHANGED
|
@@ -43,6 +43,9 @@ Examples:
|
|
|
43
43
|
stav launch claude
|
|
44
44
|
stav launch codex --model zai-org/glm-5-2
|
|
45
45
|
stav launch dsh -- "run the tests"
|
|
46
|
+
stav launch kilo
|
|
47
|
+
stav launch copilot -- -p "fix the failing test"
|
|
48
|
+
stav launch pi
|
|
46
49
|
`;
|
|
47
50
|
// Every line goes through terminalText: much of it is text from the Stav API.
|
|
48
51
|
const out = (line = '') => process.stdout.write(`${terminalText(line)}\n`);
|
package/dist/launch.js
CHANGED
|
@@ -17,12 +17,26 @@ import { appKeyName, saveAppKey } from './store/index.js';
|
|
|
17
17
|
import { compareVersions } from './version-compare.js';
|
|
18
18
|
import { VERSION } from './version.js';
|
|
19
19
|
import { chooseWorkspace } from './workspace.js';
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
/** The npm package that installs each app's program. */
|
|
21
|
+
export const INSTALL_PACKAGE = {
|
|
22
|
+
claude: '@anthropic-ai/claude-code',
|
|
23
|
+
codex: '@openai/codex',
|
|
24
|
+
dsh: '@deepseek-ai/dsh',
|
|
25
|
+
kilo: '@kilocode/cli',
|
|
26
|
+
copilot: '@github/copilot',
|
|
27
|
+
pi: '@earendil-works/pi-coding-agent',
|
|
24
28
|
};
|
|
29
|
+
export const INSTALL_HINT = Object.fromEntries(Object.entries(INSTALL_PACKAGE).map(([program, pkg]) => [program, `npm install -g ${pkg}`]));
|
|
30
|
+
/**
|
|
31
|
+
* Everything that can refuse runs first; only then, if the app is missing,
|
|
32
|
+
* is the install offered, so a yes never installs an app for a launch that
|
|
33
|
+
* would be refused anyway.
|
|
34
|
+
*/
|
|
25
35
|
export async function planLaunch(opts, d) {
|
|
36
|
+
const plan = await checkLaunch(opts, d);
|
|
37
|
+
return plan.programPath ? plan : { ...plan, programPath: await offerInstall(plan.adapter, opts, d), installed: true };
|
|
38
|
+
}
|
|
39
|
+
async function checkLaunch(opts, d) {
|
|
26
40
|
if (d.platform === 'win32') {
|
|
27
41
|
throw new StavError('The Stav CLI does not launch apps on Windows yet. Use WSL, or set the app up by hand: https://stav.ai/apps', 'unsupported_platform');
|
|
28
42
|
}
|
|
@@ -38,10 +52,7 @@ export async function planLaunch(opts, d) {
|
|
|
38
52
|
throw new StavError(`"${model}" is not a model id. Use one like zai-org/glm-5-2.`, 'bad_model');
|
|
39
53
|
}
|
|
40
54
|
const programPath = d.which(adapter.program);
|
|
41
|
-
|
|
42
|
-
throw new StavError(`${adapter.displayName} is not installed. Install it with: ${INSTALL_HINT[adapter.program] ?? adapter.program}`, 'not_installed');
|
|
43
|
-
}
|
|
44
|
-
const conflict = adapter.conflicts ? await adapter.conflicts(d.env.HOME, d.cwd) : null;
|
|
55
|
+
const conflict = adapter.conflicts ? await adapter.conflicts(d.env.HOME, d.cwd, d.env, opts.appArgs ?? []) : null;
|
|
45
56
|
if (conflict)
|
|
46
57
|
throw new StavError(conflict, 'settings_conflict');
|
|
47
58
|
// A key in the environment: no sign-in, no key made (B.9).
|
|
@@ -85,6 +96,36 @@ export async function planLaunch(opts, d) {
|
|
|
85
96
|
key: { create: true, orWorkspaceKey, name: `${adapter.displayName} (${me.email})` },
|
|
86
97
|
};
|
|
87
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* The app is not on PATH. In a terminal, offer to install it with npm and
|
|
101
|
+
* do so only on a yes; otherwise refuse and say the command. --yes never
|
|
102
|
+
* installs: it answers the key question, and a global install is a
|
|
103
|
+
* different thing to agree to. Returns the program's path once installed.
|
|
104
|
+
*/
|
|
105
|
+
async function offerInstall(adapter, opts, d) {
|
|
106
|
+
const pkg = INSTALL_PACKAGE[adapter.program];
|
|
107
|
+
const hint = INSTALL_HINT[adapter.program] ?? adapter.program;
|
|
108
|
+
const refuse = (text = `${adapter.displayName} is not installed. Install it with: ${hint}`) => new StavError(text, 'not_installed');
|
|
109
|
+
const npm = pkg ? d.which('npm') : null;
|
|
110
|
+
if (!pkg || !npm || !d.prompter.interactive || opts.yes)
|
|
111
|
+
throw refuse();
|
|
112
|
+
if (!(await confirm(d.prompter, `${adapter.displayName} is not installed. Install it now with ${hint}?`)))
|
|
113
|
+
throw refuse();
|
|
114
|
+
// An argv array and no shell, like the app itself.
|
|
115
|
+
// npm runs the package's install scripts: they get no STAV_* variable,
|
|
116
|
+
// so a key in STAV_API_KEY never reaches them.
|
|
117
|
+
const env = Object.fromEntries(Object.entries(d.env).filter(([k]) => !k.toUpperCase().startsWith('STAV_')));
|
|
118
|
+
const code = await d.spawn(npm, ['install', '-g', pkg], { stdio: 'inherit', env, shell: false });
|
|
119
|
+
if (code !== 0) {
|
|
120
|
+
throw new StavError(`npm could not install ${adapter.displayName} (exit code ${code}). Install it yourself with: ${hint}`, 'install_failed');
|
|
121
|
+
}
|
|
122
|
+
const installed = d.which(adapter.program);
|
|
123
|
+
if (!installed) {
|
|
124
|
+
throw refuse(`${adapter.displayName} was installed, but "${adapter.program}" is not on your PATH. Open a new terminal, or add npm's global bin folder (npm prefix -g) to PATH, then run this again.`);
|
|
125
|
+
}
|
|
126
|
+
d.log(`Installed ${adapter.displayName}.`);
|
|
127
|
+
return installed;
|
|
128
|
+
}
|
|
88
129
|
function checkLaunchable(app, adapter, slug) {
|
|
89
130
|
if (!app) {
|
|
90
131
|
throw new StavError(`${adapter.displayName} is not in the Stav app catalogue yet.`, 'not_launchable');
|
|
@@ -209,7 +250,7 @@ export async function launch(opts, d) {
|
|
|
209
250
|
throw new StavError('This makes an API key. Run it in a terminal, or add --yes.', 'confirm_required');
|
|
210
251
|
}
|
|
211
252
|
else if (!(await confirm(d.prompter, changes ? 'Go ahead?' : 'Start it?'))) {
|
|
212
|
-
d.log('Nothing was changed.');
|
|
253
|
+
d.log(plan.installed ? `No key was made, and ${plan.adapter.displayName} was not started. It stays installed.` : 'Nothing was changed.');
|
|
213
254
|
return 1;
|
|
214
255
|
}
|
|
215
256
|
}
|
|
@@ -241,11 +282,11 @@ async function readContextWindow(plan, key, d) {
|
|
|
241
282
|
n = await stav.modelContext(key, plan.model);
|
|
242
283
|
}
|
|
243
284
|
catch (err) {
|
|
244
|
-
d.log(`Could not read the context window of ${plan.model} (${err instanceof Error ? err.message : String(err)}); ${plan.adapter.displayName}
|
|
285
|
+
d.log(`Could not read the context window of ${plan.model} (${err instanceof Error ? err.message : String(err)}); ${plan.adapter.displayName} starts without the window from Stav (see the plan above for what it uses).`);
|
|
245
286
|
return null;
|
|
246
287
|
}
|
|
247
288
|
if (n === null)
|
|
248
|
-
d.log(`Stav does not know the context window of ${plan.model} for your workspace; ${plan.adapter.displayName}
|
|
289
|
+
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).`);
|
|
249
290
|
return n;
|
|
250
291
|
}
|
|
251
292
|
/** PATH lookup without a shell. */
|
package/dist/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/** The CLI's own version. Kept equal to package.json by
|
|
2
|
-
export const VERSION = '0.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.4';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stav-ai/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
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')\"",
|
|
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')\"",
|
|
19
19
|
"prepack": "npm run build",
|
|
20
20
|
"typecheck": "tsc --noEmit",
|
|
21
21
|
"test": "tsx --test 'src/**/*.test.ts'",
|