@stav-ai/cli 0.1.7 → 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
@@ -36,12 +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: the workspace, the key, the model
43
- and any warning about the app. `--verbose` shows every setting it gives
44
- the app.
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.
45
52
  3. Makes an API key for the app, or uses the one it saved last time:
46
53
  - a personal key, under your workspace's key policy; if that policy
47
54
  refuses it and you are an owner or admin, a workspace key instead;
@@ -53,7 +60,8 @@ nothing and prints the command instead.
53
60
  **No file is written.** Your `~/.claude` and `~/.codex/config.toml` are not
54
61
  changed. For a model Claude Code does not know, the CLI also tells it the
55
62
  model's context window (`CLAUDE_CODE_MAX_CONTEXT_TOKENS`, the largest
56
- 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).
57
65
 
58
66
  DeepSeek Harness reads its model providers from a file, so the CLI starts
59
67
  its one-shot command `dsh --profile headless` with `--patch` and a file
@@ -131,7 +139,7 @@ macOS and Linux. Windows is not supported yet: use WSL.
131
139
  ## Privacy
132
140
 
133
141
  The CLI sends no telemetry. It talks only to `stav.ai`, `api.stav.ai` and
134
- `auth.stav.ai`.
142
+ `auth.stav.ai`, and with `stav agent` to `relay.stav.ai`.
135
143
 
136
144
  ## Source and releases
137
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,7 +102,7 @@ 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
  : [];
@@ -97,7 +124,7 @@ const claudeCode = {
97
124
  modelLine,
98
125
  ...describeWindow,
99
126
  ],
100
- brief: [modelLine],
127
+ summary: modelLine,
101
128
  };
102
129
  },
103
130
  async conflicts(home = os.homedir(), cwd = process.cwd()) {
@@ -161,7 +188,7 @@ const codex = {
161
188
  'STAV_API_KEY=<the key, in the environment only>',
162
189
  modelLine,
163
190
  ],
164
- brief: [modelLine],
191
+ summary: modelLine,
165
192
  };
166
193
  },
167
194
  };
@@ -176,7 +203,7 @@ const DSH_DEFAULT_CONTEXT_WINDOW = 1_000_000;
176
203
  export const DSH_MAX_TOKENS = 32_000;
177
204
  /** A named model, not "auto" or an @workspace/router. */
178
205
  function namedModel(model) {
179
- return model !== null && model !== 'auto' && !model.startsWith('@');
206
+ return model !== null && !isRouted(model);
180
207
  }
181
208
  const deepseekHarness = {
182
209
  name: 'deepseek-harness',
@@ -229,7 +256,8 @@ const deepseekHarness = {
229
256
  noteLine,
230
257
  taskLine,
231
258
  ],
232
- brief: [modelLine, noteLine, taskLine],
259
+ summary: modelLine,
260
+ warning: 'DeepSeek Harness runs commands without asking.',
233
261
  };
234
262
  },
235
263
  };
@@ -283,11 +311,10 @@ function describePicker(models, dropped, ctx, picker) {
283
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. */
284
312
  export const KILO_PROVIDER = 'stav-cli';
285
313
  /**
286
- * The output cap Kilo Code sends as max_tokens on every call (limit.output).
287
- * 16,384 is the value the app test proved; Stav lowers it to an endpoint's
288
- * 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.
289
316
  */
290
- export const KILO_MAX_OUTPUT = 16_384;
317
+ export const KILO_MAX_OUTPUT = 65_536;
291
318
  /**
292
319
  * The context window given for auto, a Router, or a model Stav knows no
293
320
  * window for. Kilo Code compacts by it; 128,000 fits the smaller models a
@@ -327,7 +354,7 @@ const kiloCode = {
327
354
  // Kilo's model picker (/models) offers them all; the launch's model is
328
355
  // the one selected.
329
356
  const sdk = '@ai-sdk/openai-compatible';
330
- 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) } });
331
358
  const picker = pickerModels(ctx, KILO_DEFAULT_CONTEXT, (m) => JSON.stringify({ [m.id]: entry(m) }).length);
332
359
  const config = {
333
360
  model: ref,
@@ -376,7 +403,8 @@ const kiloCode = {
376
403
  agentLine,
377
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',
378
405
  ],
379
- brief: [modelLine, noteLine, agentLine],
406
+ summary: modelLine,
407
+ warning: 'Kilo Code runs commands and edits files; it asks before most commands.',
380
408
  };
381
409
  },
382
410
  };
@@ -450,7 +478,8 @@ const githubCopilot = {
450
478
  noteLine,
451
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',
452
480
  ],
453
- brief: [modelLine, noteLine],
481
+ summary: modelLine,
482
+ warning: 'The Copilot CLI runs commands and edits files; it asks first.',
454
483
  };
455
484
  },
456
485
  };
@@ -458,8 +487,8 @@ const githubCopilot = {
458
487
  export const PI_EXTENSION_FILE = fileURLToPath(new URL('./pi-stav-provider.js', import.meta.url));
459
488
  /** The provider id the pi adapter registers; one only the CLI uses. */
460
489
  export const PI_PROVIDER = 'stav-cli';
461
- /** The output cap pi sends as max_completion_tokens (the value the app test proved). */
462
- 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;
463
492
  /** The context window given for auto, a Router, or a model Stav knows none for (pi's own default). */
464
493
  export const PI_DEFAULT_CONTEXT = 128_000;
465
494
  const pi = {
@@ -517,7 +546,8 @@ const pi = {
517
546
  noteLine,
518
547
  'run one task without the chat screen after --, for example: stav launch pi -- -p "fix the failing test"',
519
548
  ],
520
- brief: [modelLine, noteLine],
549
+ summary: modelLine,
550
+ warning: 'pi runs commands without asking.',
521
551
  };
522
552
  },
523
553
  async conflicts(home = os.homedir(), cwd = process.cwd(), env = process.env, appArgs = []) {
@@ -591,6 +621,10 @@ export const HERMES_UNSET = [
591
621
  'HERMES_TUI_PROVIDER', 'HERMES_TUI_GATEWAY_URL', 'HERMES_PROFILE',
592
622
  'HERMES_YOLO_MODE', 'HERMES_SAFE_MODE', 'HERMES_IGNORE_USER_CONFIG', 'HERMES_ACCEPT_HOOKS',
593
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
+ }
594
628
  const hermesAgent = {
595
629
  name: 'hermes-agent',
596
630
  apps: ['hermes-agent'],
@@ -628,12 +662,19 @@ const hermesAgent = {
628
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`,
629
663
  'STAV_HERMES_API_KEY=<the key, in the environment only>',
630
664
  modelLine,
631
- "Hermes reads each model's context window from Stav",
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",
632
670
  'no update check at GitHub and no free third-party web search fallback (both would go around Stav)',
633
671
  noteLine,
634
672
  'run one task without the chat screen after --, for example: stav launch hermes-agent -- -z "fix the failing test"',
635
673
  ],
636
- brief: [modelLine, noteLine],
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.',
637
678
  };
638
679
  },
639
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
  }