model/context: move context window config to host-level hive-c0re.nix

This commit is contained in:
damocles 2026-05-20 15:42:56 +02:00 committed by Mara
parent 7e2f13cad8
commit d3d52349c3
10 changed files with 81 additions and 59 deletions

View file

@ -57,6 +57,31 @@ in
approval needed.
'';
};
contextWindowTokens = lib.mkOption {
type = lib.types.attrsOf lib.types.int;
default = {
haiku = 200000;
sonnet = 1000000;
opus = 1000000;
};
example = {
haiku = 150000;
sonnet = 900000;
};
description = ''
Per-model context-window sizes in tokens. Each key is a
model-family short name matched case-insensitively as a
substring of the active model name at runtime (e.g. `"sonnet"`
matches `"claude-sonnet-4-5"`). The defaults cover the known
Anthropic families; add entries for new models or override
existing ones here to change the window for all agents at once.
Passed to `hive-c0re serve` as JSON and injected into every
container's harness service environment as
`HIVE_CONTEXT_WINDOW_TOKENS_<KEY_UPPER>`. Changes propagate
on the next ` R3BU1LD` no per-agent approval needed.
'';
};
};
config = lib.mkIf cfg.enable {
@ -89,7 +114,7 @@ in
];
environment.HYPERHIVE_GIT = "${pkgs.git}/bin/git";
serviceConfig = {
ExecStart = "${cfg.package}/bin/hive-c0re --socket /run/hyperhive/host.sock serve --hyperhive-flake ${cfg.hyperhiveFlake} --dashboard-port ${toString cfg.dashboardPort} --operator-pronouns ${lib.escapeShellArg cfg.operatorPronouns}";
ExecStart = "${cfg.package}/bin/hive-c0re --socket /run/hyperhive/host.sock serve --hyperhive-flake ${cfg.hyperhiveFlake} --dashboard-port ${toString cfg.dashboardPort} --operator-pronouns ${lib.escapeShellArg cfg.operatorPronouns} --context-window-tokens ${lib.escapeShellArg (builtins.toJSON cfg.contextWindowTokens)}";
Restart = "on-failure";
RestartSec = 2;
RuntimeDirectory = "hyperhive";

View file

@ -36,41 +36,6 @@
'';
};
options.hyperhive.contextWindowTokens = lib.mkOption {
type = lib.types.attrsOf lib.types.int;
# Canonical defaults for known Anthropic model families.
# Override any entry in your agent.nix, or add new keys for
# model families not listed here.
default = {
haiku = 200000;
sonnet = 1000000;
opus = 1000000;
};
example = {
haiku = 150000;
sonnet = 900000;
};
description = ''
Per-model context-window sizes in tokens. Each key is a
model-family short name (e.g. `"haiku"`, `"sonnet"`) matched as a
case-insensitive substring of the active model name at runtime, so
`"sonnet"` matches `"claude-sonnet-4-5"` and any future variant.
The defaults declared here cover the known Anthropic model families.
Add or override entries in your `agent.nix` when using a
non-standard model or when Anthropic changes a model's window.
Each entry is rendered as
`HIVE_CONTEXT_WINDOW_TOKENS_<KEY_UPPER>` (e.g.
`HIVE_CONTEXT_WINDOW_TOKENS_SONNET = "1000000"`). The harness
checks these per-model vars in order (first substring match wins),
then falls back to `200000` when no key matches. At runtime the
effective window drives compaction (75%) and auto-reset (50%)
watermarks, and is exposed via `/api/state` as
`context_window_tokens`.
'';
};
options.hyperhive.allowedBashPatterns = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
@ -264,25 +229,15 @@
environment.etc."hyperhive/claude-plugins-auto-update.json".text =
builtins.toJSON config.hyperhive.claudePluginsAutoUpdate;
# Model + context-window env vars consumed by the harness at boot.
# HIVE_DEFAULT_MODEL seeds the initial model selection when no persisted
# model choice exists in the state dir.
# HIVE_CONTEXT_WINDOW_TOKENS_<KEY_UPPER> provides per-model overrides
# (e.g. HIVE_CONTEXT_WINDOW_TOKENS_SONNET) from contextWindowTokens attrset.
# SHELL must be set so claude's Bash tool finds a POSIX shell.
environment.variables = lib.mkMerge (
[
{
HIVE_DEFAULT_MODEL = config.hyperhive.model;
SHELL = "${pkgs.bashInteractive}/bin/bash";
}
]
++ lib.mapAttrsToList
(model: tokens: {
"HIVE_CONTEXT_WINDOW_TOKENS_${lib.toUpper model}" = toString tokens;
})
config.hyperhive.contextWindowTokens
);
# model choice exists in the state dir. SHELL must be set so claude's
# Bash tool finds a POSIX shell.
# HIVE_CONTEXT_WINDOW_TOKENS_* are injected by the meta flake from the
# host-level `services.hive-c0re.contextWindowTokens` option — not set here.
environment.variables = {
HIVE_DEFAULT_MODEL = config.hyperhive.model;
SHELL = "${pkgs.bashInteractive}/bin/bash";
};
boot.isNspawnContainer = true;