@stav-ai/cli 0.1.6 → 0.1.9

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 CHANGED
@@ -26,7 +26,7 @@ is not ours.
26
26
  | `stav whoami` | Who you are, and which workspace |
27
27
  | `stav workspace [<slug>]` | Show your workspaces, or choose one |
28
28
  | `stav apps` | The apps this CLI can launch |
29
- | `stav launch <app> [--model <id>] [--workspace <slug>] [--yes] [-- <app arguments>]` | Start an app on Stav |
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`),
32
32
  **DeepSeek Harness** (`dsh`), **Kilo Code** (`kilo`), the
@@ -36,10 +36,19 @@ It launches **Claude Code** (`claude`), **Codex** (`codex`),
36
36
  npm: the CLI says where its installer is). With `--yes`, or with no terminal, it installs
37
37
  nothing and prints the command instead.
38
38
 
39
+ `--model` takes a model, `auto` (your workspace's default Router) or a Router
40
+ (`@workspace/router`). Add one rule to the name to say where it may run:
41
+ `--model auto:eu`, `--model auto:eea`, or the lowest sovereignty level that
42
+ may serve, `--model auto:L3`. If nothing inside the rule can serve, the
43
+ request is refused and nothing is sent.
44
+
39
45
  ## What `stav launch` does
40
46
 
41
47
  1. Checks the app can be launched, and that your workspace has credits.
42
- 2. Shows what it will do, and asks once.
48
+ 2. Shows a short plan (the key and its access, the model, and a warning if
49
+ the app runs commands), and asks once.
50
+ `--verbose` shows the details: the key's access, every setting it gives
51
+ the app and any warning about the app.
43
52
  3. Makes an API key for the app, or uses the one it saved last time:
44
53
  - a personal key, under your workspace's key policy; if that policy
45
54
  refuses it and you are an owner or admin, a workspace key instead;
@@ -51,7 +60,8 @@ nothing and prints the command instead.
51
60
  **No file is written.** Your `~/.claude` and `~/.codex/config.toml` are not
52
61
  changed. For a model Claude Code does not know, the CLI also tells it the
53
62
  model's context window (`CLAUDE_CODE_MAX_CONTEXT_TOKENS`, the largest
54
- window Stav serves that model at for your workspace).
63
+ window Stav serves that model at for your workspace; 200,000 for `auto` or
64
+ a Router).
55
65
 
56
66
  DeepSeek Harness reads its model providers from a file, so the CLI starts
57
67
  its one-shot command `dsh --profile headless` with `--patch` and a file
@@ -129,7 +139,7 @@ macOS and Linux. Windows is not supported yet: use WSL.
129
139
  ## Privacy
130
140
 
131
141
  The CLI sends no telemetry. It talks only to `stav.ai`, `api.stav.ai` and
132
- `auth.stav.ai`.
142
+ `auth.stav.ai`, and with `stav agent` to `relay.stav.ai`.
133
143
 
134
144
  ## Source and releases
135
145
 
@@ -40,10 +40,35 @@ function claudeKnows(model) {
40
40
  * served).
41
41
  */
42
42
  function claudeNeedsWindow(model) {
43
- return model !== null && model !== 'auto' && !model.startsWith('@') && !claudeKnows(model);
43
+ return model !== null && !isRouted(model) && !claudeKnows(model);
44
+ }
45
+ /**
46
+ * A model id as the gateway takes it; mirrors launch_recipes.MODEL_RE. Lower
47
+ * case, except a rule after the name: auto:eu, @workspace/router:L3.
48
+ */
49
+ export const MODEL_RE = /^(?=.{1,128}$)[a-z0-9@][a-z0-9._/@:-]*(?::(?:[Ee][Uu]|[Ee][Ee][Aa]|[Ll][1-4]))?$/;
50
+ /** "auto" or an @workspace/router, with or without a rule after it (auto:L3). */
51
+ export function isRouted(model) {
52
+ return model === 'auto' || model.startsWith('auto:') || model.startsWith('@');
53
+ }
54
+ /**
55
+ * The window Claude Code is given for "auto" or a Router. It has none of its
56
+ * own, and Claude Code 2.1.336 assumes 1 million tokens for a name it does
57
+ * not know, so it would compact far too late. 200,000 is the value the app
58
+ * test of auto:eea proved.
59
+ */
60
+ export const CLAUDE_ROUTED_CONTEXT = 200_000;
61
+ /**
62
+ * The output cap for one model: what the app test proved, but at most a
63
+ * quarter of the context window, so the prompt still fits on a small model.
64
+ * A reasoning model spends these tokens on its thinking too: with 16,384,
65
+ * Kilo Code and pi ran out before they wrote any code. Stav lowers it to an
66
+ * endpoint's own cap and names that in X-Stav-Clamped-Params.
67
+ * pi-stav-provider.js has the same quarter rule.
68
+ */
69
+ function outputCap(max, contextWindow) {
70
+ return Math.min(max, Math.floor(contextWindow / 4));
44
71
  }
45
- /** A model id as the gateway takes it; mirrors launch_recipes.MODEL_RE. */
46
- export const MODEL_RE = /^[a-z0-9@][a-z0-9._/@:-]{0,127}$/;
47
72
  const claudeCode = {
48
73
  name: 'claude-code',
49
74
  apps: ['claude-code'],
@@ -67,6 +92,8 @@ const claudeCode = {
67
92
  // 200k. The real one lets it compact at the right point.
68
93
  if (contextWindow && claudeNeedsWindow(model))
69
94
  env.CLAUDE_CODE_MAX_CONTEXT_TOKENS = String(contextWindow);
95
+ if (isRouted(model))
96
+ env.CLAUDE_CODE_MAX_CONTEXT_TOKENS = String(CLAUDE_ROUTED_CONTEXT);
70
97
  }
71
98
  // A window from the person's own shell (another gateway, another model)
72
99
  // must never reach a Stav launch: with none from Stav, whatever the
@@ -75,10 +102,11 @@ const claudeCode = {
75
102
  // The preview runs before the key exists, so the window is not known
76
103
  // yet (contextWindow undefined): it is named, not given.
77
104
  const describeWindow = env.CLAUDE_CODE_MAX_CONTEXT_TOKENS
78
- ? [`CLAUDE_CODE_MAX_CONTEXT_TOKENS=${env.CLAUDE_CODE_MAX_CONTEXT_TOKENS} (the model's context window in your workspace)`]
105
+ ? [`CLAUDE_CODE_MAX_CONTEXT_TOKENS=${env.CLAUDE_CODE_MAX_CONTEXT_TOKENS} (${model && isRouted(model) ? 'a Router picks the model, so this is a fixed value' : "the model's context window in your workspace"})`]
79
106
  : contextWindow === undefined && claudeNeedsWindow(model)
80
107
  ? ["CLAUDE_CODE_MAX_CONTEXT_TOKENS=<the model's largest context window in your workspace, read from Stav; a long chat then sends more tokens per turn before it is compacted>"]
81
108
  : [];
109
+ const modelLine = model ? `model ${model}` : "Claude Code's own default model";
82
110
  return {
83
111
  program: 'claude',
84
112
  args: [],
@@ -93,9 +121,10 @@ const claudeCode = {
93
121
  describe: [
94
122
  `ANTHROPIC_BASE_URL=${gatewayUrl}`,
95
123
  'ANTHROPIC_AUTH_TOKEN=<the key, in the environment only>',
96
- model ? `model ${model}` : "Claude Code's own default model",
124
+ modelLine,
97
125
  ...describeWindow,
98
126
  ],
127
+ summary: modelLine,
99
128
  };
100
129
  },
101
130
  async conflicts(home = os.homedir(), cwd = process.cwd()) {
@@ -148,6 +177,7 @@ const codex = {
148
177
  ];
149
178
  if (model)
150
179
  args.push('-m', model);
180
+ const modelLine = model ? `model ${model}` : "Codex's own default model";
151
181
  return {
152
182
  program: 'codex',
153
183
  args,
@@ -156,8 +186,9 @@ const codex = {
156
186
  describe: [
157
187
  `a "stav" model provider at ${base}, for this run only (your ~/.codex/config.toml is not changed)`,
158
188
  'STAV_API_KEY=<the key, in the environment only>',
159
- model ? `model ${model}` : "Codex's own default model",
189
+ modelLine,
160
190
  ],
191
+ summary: modelLine,
161
192
  };
162
193
  },
163
194
  };
@@ -172,7 +203,7 @@ const DSH_DEFAULT_CONTEXT_WINDOW = 1_000_000;
172
203
  export const DSH_MAX_TOKENS = 32_000;
173
204
  /** A named model, not "auto" or an @workspace/router. */
174
205
  function namedModel(model) {
175
- return model !== null && model !== 'auto' && !model.startsWith('@');
206
+ return model !== null && !isRouted(model);
176
207
  }
177
208
  const deepseekHarness = {
178
209
  name: 'deepseek-harness',
@@ -199,6 +230,9 @@ const deepseekHarness = {
199
230
  : contextWindow === undefined && namedModel(model)
200
231
  ? "the model's largest context window in your workspace, read from Stav"
201
232
  : `dsh's own context window guess (${DSH_DEFAULT_CONTEXT_WINDOW} tokens)`;
233
+ const modelLine = model ? `model ${model}` : 'model auto (your workspace\'s default Router)';
234
+ const noteLine = "note: dsh runs the commands the model writes without asking; DeepSeek's own SAFETY.md says to run it in a container or VM";
235
+ const taskLine = 'give the task after --, for example: stav launch deepseek-harness -- "run the tests"';
202
236
  return {
203
237
  program: 'dsh',
204
238
  args: ['--profile', 'headless', '--patch', DSH_PATCH_FILE],
@@ -215,13 +249,15 @@ const deepseekHarness = {
215
249
  describe: [
216
250
  `the one-shot command dsh --profile headless, with a "stav-cli" model provider at ${base} for this run only (your ~/.dsh is not changed)`,
217
251
  'STAV_DSH_API_KEY=<the key, in the environment only>',
218
- model ? `model ${model}` : 'model auto (your workspace\'s default Router)',
252
+ modelLine,
219
253
  describeWindow,
220
254
  `at most ${DSH_MAX_TOKENS} output tokens per call`,
221
255
  'DSH_TELEMETRY_MODE=DISABLED (no feedback uploads to DeepSeek)',
222
- "note: dsh runs the commands the model writes without asking; DeepSeek's own SAFETY.md says to run it in a container or VM",
223
- 'give the task after --, for example: stav launch deepseek-harness -- "run the tests"',
256
+ noteLine,
257
+ taskLine,
224
258
  ],
259
+ summary: modelLine,
260
+ warning: 'DeepSeek Harness runs commands without asking.',
225
261
  };
226
262
  },
227
263
  };
@@ -275,11 +311,10 @@ function describePicker(models, dropped, ctx, picker) {
275
311
  /** 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. */
276
312
  export const KILO_PROVIDER = 'stav-cli';
277
313
  /**
278
- * The output cap Kilo Code sends as max_tokens on every call (limit.output).
279
- * 16,384 is the value the app test proved; Stav lowers it to an endpoint's
280
- * own cap and names that in X-Stav-Clamped-Params.
314
+ * The most output tokens given per call (limit.output; see outputCap). Kilo
315
+ * Code 7.8.40 itself sends at most 32,000 as max_tokens.
281
316
  */
282
- export const KILO_MAX_OUTPUT = 16_384;
317
+ export const KILO_MAX_OUTPUT = 65_536;
283
318
  /**
284
319
  * The context window given for auto, a Router, or a model Stav knows no
285
320
  * window for. Kilo Code compacts by it; 128,000 fits the smaller models a
@@ -319,7 +354,7 @@ const kiloCode = {
319
354
  // Kilo's model picker (/models) offers them all; the launch's model is
320
355
  // the one selected.
321
356
  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 } });
357
+ const entry = (m) => ({ name: m.id, provider: { npm: sdk, api: base }, limit: { context: m.contextWindow ?? KILO_DEFAULT_CONTEXT, output: outputCap(KILO_MAX_OUTPUT, m.contextWindow ?? KILO_DEFAULT_CONTEXT) } });
323
358
  const picker = pickerModels(ctx, KILO_DEFAULT_CONTEXT, (m) => JSON.stringify({ [m.id]: entry(m) }).length);
324
359
  const config = {
325
360
  model: ref,
@@ -341,6 +376,9 @@ const kiloCode = {
341
376
  : contextWindow === undefined && namedModel(model)
342
377
  ? "the model's largest context window in your workspace, read from Stav"
343
378
  : `a context window of ${KILO_DEFAULT_CONTEXT} tokens (Kilo Code compacts the chat by it)`;
379
+ const modelLine = model ? `model ${model}` : "model auto (your workspace's default Router)";
380
+ const agentLine = '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';
381
+ const noteLine = '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)';
344
382
  return {
345
383
  program: 'kilo',
346
384
  args: [],
@@ -356,15 +394,17 @@ const kiloCode = {
356
394
  describe: [
357
395
  `Kilo Code with a "${KILO_PROVIDER}" provider at ${base} as its only provider, for this run only (your ~/.config/kilo is not changed)`,
358
396
  'STAV_KILO_API_KEY=<the key, in the environment only>',
359
- model ? `model ${model}` : "model auto (your workspace's default Router)",
397
+ modelLine,
360
398
  describeWindow,
361
399
  describePicker(picker.models, picker.dropped, ctx, '/models'),
362
400
  `at most ${KILO_MAX_OUTPUT} output tokens per call`,
363
401
  'KILO_TELEMETRY_LEVEL=off, KILO_DISABLE_SESSION_INGEST=1, KILO_DISABLE_SHARE=1 (no usage data or session uploads to Kilo)',
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)',
365
- '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',
402
+ noteLine,
403
+ agentLine,
366
404
  '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',
367
405
  ],
406
+ summary: modelLine,
407
+ warning: 'Kilo Code runs commands and edits files; it asks before most commands.',
368
408
  };
369
409
  },
370
410
  };
@@ -403,6 +443,10 @@ const githubCopilot = {
403
443
  };
404
444
  if (routed)
405
445
  env.COPILOT_PROVIDER_WIRE_MODEL = id;
446
+ const modelLine = routed
447
+ ? `model ${id}${model ? '' : " (your workspace's default Router)"}, given to the CLI as ${COPILOT_ROUTER_MODEL}`
448
+ : `model ${id}`;
449
+ const noteLine = '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)';
406
450
  return {
407
451
  program: 'copilot',
408
452
  args: [],
@@ -429,13 +473,13 @@ const githubCopilot = {
429
473
  describe: [
430
474
  `the Copilot CLI with Stav at ${base} as its model provider, for this run only (no provider settings are written to ~/.copilot)`,
431
475
  'COPILOT_PROVIDER_API_KEY=<the key, in the environment only>',
432
- routed
433
- ? `model ${id}${model ? '' : " (your workspace's default Router)"}, given to the CLI as ${COPILOT_ROUTER_MODEL}`
434
- : `model ${id}`,
476
+ modelLine,
435
477
  'COPILOT_OFFLINE=true (no GitHub sign-in, telemetry, web tools, GitHub MCP server or auto-update)',
436
- '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)',
478
+ noteLine,
437
479
  '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',
438
480
  ],
481
+ summary: modelLine,
482
+ warning: 'The Copilot CLI runs commands and edits files; it asks first.',
439
483
  };
440
484
  },
441
485
  };
@@ -443,8 +487,8 @@ const githubCopilot = {
443
487
  export const PI_EXTENSION_FILE = fileURLToPath(new URL('./pi-stav-provider.js', import.meta.url));
444
488
  /** The provider id the pi adapter registers; one only the CLI uses. */
445
489
  export const PI_PROVIDER = 'stav-cli';
446
- /** The output cap pi sends as max_completion_tokens (the value the app test proved). */
447
- export const PI_MAX_TOKENS = 16_384;
490
+ /** The most output tokens pi asks for per call (the value the app test proved; see outputCap, which the extension applies per model). */
491
+ export const PI_MAX_TOKENS = 65_536;
448
492
  /** The context window given for auto, a Router, or a model Stav knows none for (pi's own default). */
449
493
  export const PI_DEFAULT_CONTEXT = 128_000;
450
494
  const pi = {
@@ -475,6 +519,8 @@ const pi = {
475
519
  : contextWindow === undefined && namedModel(model)
476
520
  ? "the model's largest context window in your workspace, read from Stav"
477
521
  : `a context window of ${PI_DEFAULT_CONTEXT} tokens (pi compacts the chat by it)`;
522
+ const modelLine = model ? `model ${model}` : "model auto (your workspace's default Router)";
523
+ const noteLine = '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';
478
524
  return {
479
525
  program: 'pi',
480
526
  args: ['--extension', PI_EXTENSION_FILE, '--provider', PI_PROVIDER, '--model', id],
@@ -492,14 +538,16 @@ const pi = {
492
538
  describe: [
493
539
  `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)`,
494
540
  'STAV_PI_API_KEY=<the key, in the environment only>',
495
- model ? `model ${model}` : "model auto (your workspace's default Router)",
541
+ modelLine,
496
542
  describeWindow,
497
543
  describePicker(picker.models, picker.dropped, ctx, '/model'),
498
544
  `at most ${PI_MAX_TOKENS} output tokens per call`,
499
545
  'PI_OFFLINE=1 (no model catalogue refresh or update check at pi.dev)',
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',
546
+ noteLine,
501
547
  'run one task without the chat screen after --, for example: stav launch pi -- -p "fix the failing test"',
502
548
  ],
549
+ summary: modelLine,
550
+ warning: 'pi runs commands without asking.',
503
551
  };
504
552
  },
505
553
  async conflicts(home = os.homedir(), cwd = process.cwd(), env = process.env, appArgs = []) {
@@ -573,6 +621,10 @@ export const HERMES_UNSET = [
573
621
  'HERMES_TUI_PROVIDER', 'HERMES_TUI_GATEWAY_URL', 'HERMES_PROFILE',
574
622
  'HERMES_YOLO_MODE', 'HERMES_SAFE_MODE', 'HERMES_IGNORE_USER_CONFIG', 'HERMES_ACCEPT_HOOKS',
575
623
  ];
624
+ /** A named model with a rule after it (zai-org/glm-5-2:eu). */
625
+ function modelWithRule(model) {
626
+ return namedModel(model) && /:(?:eu|eea|l[1-4])$/i.test(model);
627
+ }
576
628
  const hermesAgent = {
577
629
  name: 'hermes-agent',
578
630
  apps: ['hermes-agent'],
@@ -592,6 +644,8 @@ const hermesAgent = {
592
644
  const base = `${gatewayUrl}/v1`;
593
645
  const id = model ?? 'auto';
594
646
  const home = hermesHome(key);
647
+ const modelLine = model ? `model ${model}` : "model auto (your workspace's default Router)";
648
+ const noteLine = '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';
595
649
  return {
596
650
  program: 'hermes',
597
651
  args: ['--provider', `custom:${HERMES_PROVIDER}`, '-m', id],
@@ -607,12 +661,20 @@ const hermesAgent = {
607
661
  `Hermes Agent with a "${HERMES_PROVIDER}" provider at ${base}, set by a file that ships with the Stav CLI, for this run only`,
608
662
  `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
663
  '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",
664
+ modelLine,
665
+ // Hermes looks the name up in GET /v1/models, which lists a model
666
+ // without a rule, and then takes the first id the name contains.
667
+ modelWithRule(model)
668
+ ? "Hermes does not find a model name with a rule in Stav's list and may use another model's context window; to be sure, put the rule on a Router and use @workspace/router"
669
+ : "Hermes reads each model's context window from Stav",
612
670
  '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',
671
+ noteLine,
614
672
  'run one task without the chat screen after --, for example: stav launch hermes-agent -- -z "fix the failing test"',
615
673
  ],
674
+ summary: modelLine,
675
+ warning: modelWithRule(model)
676
+ ? `Hermes Agent can run commands without asking, and it may use another model's context window for ${model}.`
677
+ : 'Hermes Agent can run commands without asking.',
616
678
  };
617
679
  },
618
680
  };
@@ -42,7 +42,8 @@ export default function stavProvider(pi) {
42
42
  input: ["text"],
43
43
  cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
44
44
  contextWindow: m.contextWindow,
45
- maxTokens: Number(env.STAV_PI_MAX_TOKENS),
45
+ // At most a quarter of the window, so the prompt fits (outputCap in index.ts).
46
+ maxTokens: Math.min(Number(env.STAV_PI_MAX_TOKENS), Math.floor(m.contextWindow / 4)),
46
47
  })),
47
48
  });
48
49
  }