@stav-ai/cli 0.1.3 → 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 +17 -5
- package/dist/adapters/adapters.json +5 -0
- package/dist/adapters/index.js +95 -3
- package/dist/adapters/pi-stav-provider.js +32 -0
- package/dist/cli.js +1 -0
- package/dist/launch.js +50 -11
- package/dist/version.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -10,6 +10,7 @@ npx @stav-ai/cli launch codex --model zai-org/glm-5-2
|
|
|
10
10
|
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
|
+
npx @stav-ai/cli launch pi
|
|
13
14
|
```
|
|
14
15
|
|
|
15
16
|
Always use the scoped name `@stav-ai/cli`. The unscoped `stav` package on npm
|
|
@@ -27,9 +28,11 @@ is not ours.
|
|
|
27
28
|
| `stav launch <app> [--model <id>] [--workspace <slug>] [--yes] [-- <app arguments>]` | Start an app on Stav |
|
|
28
29
|
|
|
29
30
|
It launches **Claude Code** (`claude`), **Codex** (`codex`),
|
|
30
|
-
**DeepSeek Harness** (`dsh`), **Kilo Code** (`kilo`)
|
|
31
|
-
**GitHub Copilot CLI** (`copilot`).
|
|
32
|
-
|
|
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.
|
|
33
36
|
|
|
34
37
|
## What `stav launch` does
|
|
35
38
|
|
|
@@ -40,8 +43,8 @@ already be installed.
|
|
|
40
43
|
refuses it and you are an owner or admin, a workspace key instead;
|
|
41
44
|
- named for the app and you, marked with the app in your request log;
|
|
42
45
|
- with only the scope the app needs (`inference:messages` for Claude Code,
|
|
43
|
-
`inference:chat` for Codex, DeepSeek Harness, Kilo Code
|
|
44
|
-
GitHub Copilot CLI).
|
|
46
|
+
`inference:chat` for Codex, DeepSeek Harness, Kilo Code, the
|
|
47
|
+
GitHub Copilot CLI and pi).
|
|
45
48
|
4. Starts the app with the Stav gateway and the key in its environment.
|
|
46
49
|
**No file is written.** Your `~/.claude` and `~/.codex/config.toml` are not
|
|
47
50
|
changed. For a model Claude Code does not know, the CLI also tells it the
|
|
@@ -83,6 +86,15 @@ already be installed.
|
|
|
83
86
|
edits and commands: add `--allow-tool` or `--allow-all-tools` after the
|
|
84
87
|
task to allow them without asking.
|
|
85
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
|
+
|
|
86
98
|
The key is kept in your operating system's keychain, or in a file only you
|
|
87
99
|
can read when there is no keychain. Never in your project folder.
|
|
88
100
|
|
package/dist/adapters/index.js
CHANGED
|
@@ -8,8 +8,10 @@
|
|
|
8
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
10
|
* values all come from the environment, Kilo Code takes its whole
|
|
11
|
-
* provider from KILO_CONFIG_CONTENT,
|
|
12
|
-
* COPILOT_PROVIDER_* variables
|
|
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
|
|
13
15
|
* environment, never into its arguments or a file (R-20).
|
|
14
16
|
*
|
|
15
17
|
* adapters.json is byte-identical to the Stav API's
|
|
@@ -383,7 +385,97 @@ const githubCopilot = {
|
|
|
383
385
|
};
|
|
384
386
|
},
|
|
385
387
|
};
|
|
386
|
-
|
|
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];
|
|
387
479
|
/** Names a person may type for an app (DECIDE-APPS-P: `claude` → claude-code). */
|
|
388
480
|
export const ALIASES = {
|
|
389
481
|
claude: 'claude-code',
|
|
@@ -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
|
@@ -45,6 +45,7 @@ Examples:
|
|
|
45
45
|
stav launch dsh -- "run the tests"
|
|
46
46
|
stav launch kilo
|
|
47
47
|
stav launch copilot -- -p "fix the failing test"
|
|
48
|
+
stav launch pi
|
|
48
49
|
`;
|
|
49
50
|
// Every line goes through terminalText: much of it is text from the Stav API.
|
|
50
51
|
const out = (line = '') => process.stdout.write(`${terminalText(line)}\n`);
|
package/dist/launch.js
CHANGED
|
@@ -17,14 +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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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',
|
|
26
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
|
+
*/
|
|
27
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) {
|
|
28
40
|
if (d.platform === 'win32') {
|
|
29
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');
|
|
30
42
|
}
|
|
@@ -40,10 +52,7 @@ export async function planLaunch(opts, d) {
|
|
|
40
52
|
throw new StavError(`"${model}" is not a model id. Use one like zai-org/glm-5-2.`, 'bad_model');
|
|
41
53
|
}
|
|
42
54
|
const programPath = d.which(adapter.program);
|
|
43
|
-
|
|
44
|
-
throw new StavError(`${adapter.displayName} is not installed. Install it with: ${INSTALL_HINT[adapter.program] ?? adapter.program}`, 'not_installed');
|
|
45
|
-
}
|
|
46
|
-
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;
|
|
47
56
|
if (conflict)
|
|
48
57
|
throw new StavError(conflict, 'settings_conflict');
|
|
49
58
|
// A key in the environment: no sign-in, no key made (B.9).
|
|
@@ -87,6 +96,36 @@ export async function planLaunch(opts, d) {
|
|
|
87
96
|
key: { create: true, orWorkspaceKey, name: `${adapter.displayName} (${me.email})` },
|
|
88
97
|
};
|
|
89
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
|
+
}
|
|
90
129
|
function checkLaunchable(app, adapter, slug) {
|
|
91
130
|
if (!app) {
|
|
92
131
|
throw new StavError(`${adapter.displayName} is not in the Stav app catalogue yet.`, 'not_launchable');
|
|
@@ -211,7 +250,7 @@ export async function launch(opts, d) {
|
|
|
211
250
|
throw new StavError('This makes an API key. Run it in a terminal, or add --yes.', 'confirm_required');
|
|
212
251
|
}
|
|
213
252
|
else if (!(await confirm(d.prompter, changes ? 'Go ahead?' : 'Start it?'))) {
|
|
214
|
-
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.');
|
|
215
254
|
return 1;
|
|
216
255
|
}
|
|
217
256
|
}
|
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.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'",
|