Watch
0
0
Fork
You've already forked hyperhive
0

remove c0re.operatorPronouns and c0re.contextWindowTokens

Both options are now ignored with a warning (the swarm-peers-removed.nix
shape), so a host that still sets one keeps evaluating.

- operatorPronouns: the agents' system prompt names the pronouns as
  she/her, the value the harness fell back to and the option's default.
  The --operator-pronouns flag, HiveEnv field, meta-flake let binding
  and HIVE_OPERATOR_PRONOUNS env var are gone.
- contextWindowTokens: the per-family defaults (haiku 200000, sonnet
  1000000, opus 1000000) move into hive-agent's harness_state as a
  table; the window the API reports after a turn still wins. The
  --context-window-tokens flag, HiveEnv field and the rendered
  HIVE_CONTEXT_WINDOW_TOKENS_<KEY> env vars are gone.
This commit is contained in:
atlas 2026-10-16 17:18:23 +02:00 • committed by mara
commit 4b5707768c
18 changed files with 151 additions and 258 deletions

View file

@ -237,33 +237,31 @@ pub fn configured_effort() -> Option<&'static str> {
.map(|s| &*Box::leak(s.into_boxed_str()))
}
/// Context-window size in tokens for a given model name.
///
/// Canonical per-model sizes are declared in the harness nix modules as
/// `hyperhive.contextWindowTokens` and injected as
/// `HIVE_CONTEXT_WINDOW_TOKENS_<KEY_UPPER>` env vars — so this function
/// normally just reads them. The Rust code carries no model knowledge;
/// updating model families only requires a Nix change.
/// Context-window size in tokens per model family, keyed by a substring
/// of the model name (`"sonnet"` matches `"claude-sonnet-4-5"`).
const CONTEXT_WINDOW_DEFAULTS: [(&str, u64); 3] = [
("haiku", 200_000),
("sonnet", 1_000_000),
("opus", 1_000_000),
];
/// Context-window size in tokens for a given model name, used until a
/// completed turn reports the real window (`Bus::effective_context_window`
/// prefers that one).
///
/// Resolution order (first match wins):
/// 1. `HIVE_CONTEXT_WINDOW_TOKENS_<KEY>` — key (lowercased) is a
/// substring of the active model name. Populated by the Nix default
/// map for all known families; add/override in `agent.nix`.
/// 1. [`CONTEXT_WINDOW_DEFAULTS`] — the family key, case-insensitively,
/// is a substring of the model name.
/// 2. `HIVE_CONTEXT_WINDOW_TOKENS` — single global override (any model).
/// 3. Hard fallback: `200_000` (conservative; only hit outside NixOS).
/// 3. Hard fallback: `200_000`.
#[must_use]
pub fn context_window_tokens(model: &str) -> u64 {
let m = model.to_ascii_lowercase();
// Per-model env vars set by `hyperhive.contextWindowTokens` in Nix.
for (key, val) in std::env::vars() {
if let Some(suffix) = key.strip_prefix("HIVE_CONTEXT_WINDOW_TOKENS_")
&& !suffix.is_empty()
&& m.contains(&suffix.to_ascii_lowercase())
&& let Ok(v) = val.trim().parse::<u64>()
&& v > 0
{
return v;
}
if let Some((_, tokens)) = CONTEXT_WINDOW_DEFAULTS
.iter()
.find(|(family, _)| m.contains(family))
{
return *tokens;
}
// Global override (single value, any model).
if let Ok(s) = std::env::var("HIVE_CONTEXT_WINDOW_TOKENS")
@ -272,13 +270,25 @@ pub fn context_window_tokens(model: &str) -> u64 {
{
return v;
}
// Hard fallback for dev/test outside NixOS where env vars aren't set.
200_000
}
#[cfg(test)]
mod tests {
use super::{DEFAULT_EFFORT, DEFAULT_MODEL, Source, effort_from, model_from};
use super::{
DEFAULT_EFFORT, DEFAULT_MODEL, Source, context_window_tokens, effort_from, model_from,
};
#[test]
fn context_window_defaults_per_model_family() {
assert_eq!(context_window_tokens("claude-haiku-4-5"), 200_000);
assert_eq!(context_window_tokens("haiku"), 200_000);
assert_eq!(context_window_tokens("claude-sonnet-4-5"), 1_000_000);
assert_eq!(context_window_tokens("Claude-Sonnet-4-6"), 1_000_000);
assert_eq!(context_window_tokens("sonnet"), 1_000_000);
assert_eq!(context_window_tokens("claude-opus-4-1"), 1_000_000);
assert_eq!(context_window_tokens("opus"), 1_000_000);
}
#[test]
fn compiled_default_effort_matches_claude_settings() {