Commit Graph

12 Commits

Author SHA1 Message Date
Teknium
e629f6f720 docs(providers): reword provider-specific comments generically
providers/base.py auth_type values and the client-construction hook's pointer
(now the model-provider plugin developer guide), gateway/session_cli_turn.py and
tools/schema_sanitizer.py comments no longer name a specific provider.
2026-10-25 19:26:49 -07:00
David Dudok de Wit
97e6f117de fix(gateway): keep the session's route for a --once alias with no endpoint
A session on Anthropic behind a proxy, or rotating a credential pool, ran
/model haiku --once, and that one turn went to the provider's default
host with its default key, without the pool or the session's request
overrides. So did an endpointless model_aliases entry, a plain model id
that reverse-matches one, and an external_process provider's own alias
or declared id, which also lost the session's command. With the previous
commit, /model M --once through an alias named M with no endpoint now
reaches the owner too.

The owner ran a pick whole whenever resolved_via_alias was set. But
switch_model gives a pick its own endpoint and key only for a direct
alias with a base_url (_apply_direct_alias_endpoint); for every other
alias kind it resolves the provider's default route, and the owner ran
that in place of the session's.

switch_model now says on its result whether it applied a direct alias's
own endpoint (alias_endpoint_applied, False by default), and the owner
runs a same-provider pick whole only then. The owner decides from the
route switch_model resolved and validated, not from a second read of the
alias table, which a config.yaml edit in between or another profile's
reload of the shared table could change. Every other alias keeps the
session's pool, endpoint, key, command and overrides, and the wire still
follows a provider that picks it per model. An alias with its own
endpoint, and a different provider, still run whole; the CLI still sends
the alias name.

Refs #134889, #140719

(cherry picked from commit eeac2f5b5fdd7d9b5e863a154bdaf654ea99202a)
(cherry picked from commit 752350eb3dd60e18c0c94e4fbed4382c6dfc79fc)
2026-10-19 10:18:29 -04:00
Teknium
0632abae13 fix(cli): keep a --once reasoning level on its one admission
/model B --once --reasoning high sent two session-scope reasoning
mutations: _apply_reasoning_after_switch called pin_reasoning, and the
rebuilt agent pinned again through push_reasoning. With MP-16 each one
records session_pins.reasoning = True, and the restore never unpins, so
the session stopped following its profile's level for good, even when
high was already the inherited level.

A --once level now rides the admission: model_override.reasoning, which
the owner validates and applies for that execution only
(one_turn_reasoning). The CLI stages it on the gateway agent without a
mutate, the agent chat rebuilds carries it from the restore snapshot,
push_reasoning is off for a one-turn build, and the restore only puts
the level back locally. A session /reasoning and a session /model
--reasoning still commit as before.

Review finding by @kshitijk4poor on #140969
Refs #134889 (CLI-36)
Refs #134889 (MP-16)
Refs #140719
2026-10-18 03:44:28 -07:00
Teknium
fa73655887 fix(gateway): run a same-provider --once alias on its own endpoint and wire
one_turn_runtime kept the session's base_url and key whenever the target
provider matched. Two regressions came with that:

- A model_aliases entry on the session's provider with its own base_url
  and key (_apply_direct_alias_endpoint) ran against the session's host
  with the session's key. An alias route now runs whole: endpoint, key,
  route settings, and no session credential pool.
- It took result.api_mode, which _build_switch_result derives from the
  provider's default host. A session on openai-api behind a
  chat-completions proxy sent codex_responses to the proxy. The target's
  wire now replaces the session's only when model_derived_api_mode names
  one (Copilot, Nous, OpenCode), as _rederive_per_model_route does.

A plain same-provider pick still keeps the session's endpoint, key and
pool.

Review finding by @kshitijk4poor on #140969
Refs #134889 (CLI-36)
Refs #140719
2026-10-18 03:44:27 -07:00
David Dudok de Wit
cd2d28f2a9 fix(cli): keep a one-turn model switch on the rebuilt agent
/model --once either rewrote the shared session or vanished when chat
rebuilt the agent. The agent chat builds now carries the pick, and that
admission alone submits it as model_override. The session row stays put.
After the turn the published route is the policy model. A same-provider
override keeps the session endpoint and key, and its wire follows the
target model. A second --once before the turn still restores the route
from before the first. A resumed session still asks the large-context
confirm. A later session switch of that same target commits on the
generation fence.

Refs #140412

Refs #134889 (CLI-36)
Refs #140719

(cherry picked from commit 8c7259776946e5f5ddb3865e59ff43fcfb07d578)
2026-10-18 03:44:27 -07:00
Teknium
a011d11d8c fix(gateway): any local viewer that declares clarify_batch gets the batch panel
Before #106742, main's classic CLI, Ink TUI (prompts.tsx A-compact batch
panel: status list, Tab between questions, answers editable until the last
lock) and Desktop (pending.tsx: all questions, one Confirm) all showed the
clarify tool's question set at once. On the owner only a classic-CLI turn
could get the one `clarify` batch request: clarify_batch_turn() also
required the `cli` surface policy, so an Ink turn fell to one card per
question even when its submitter asked for the batch.

clarify_batch_turn() now keys on the viewer's declaration alone (a local
viewer turn whose admission committed clarify_batch). Viewers that never
set it (ACP editors, raw WebSocket clients) keep one clarify.request card
per question, as before.

Red first: test_local_viewer_clarify_batch.py::
test_a_tui_turn_that_asked_for_the_batch_gets_the_batch_panel

Refs #134889 (TUI-18)
Refs #140337
2026-10-17 08:03:49 -07:00
unsupportedpastels
895c9fc93a fix(gateway): expand @ references on every local route, once, on the model's text
Removing the classic CLI's own expansion pass (PLG-4) left three local
routes where @ references or their refusal no longer reached anyone.
They now share one step, gateway/session_context_refs.py:

- CLI API-only text: a voice turn or a pending model-switch or
  skills-reload note sends cli_turn_v1.api_text, which
  _prepare_turn_message swaps in for the admitted text after the inbound
  step had expanded only that admitted text. The inbound step now expands
  the text the model reads: when api_text is committed, its references are
  expanded and rebound for this execution (rebind_api_text). The stored
  user row stays as typed, and the committed row is untouched, so a retry
  expands afresh rather than twice.
- Managed workers: --safe-mode / --ignore-user-config sessions (and the
  managed-workers opt-in) branch to execute_managed before the inbound
  step, so the worker ran the raw text. execute_managed now expands the
  admitted text against the session's policy cwd before it spawns,
  and hands it to the bootstrap frame. The context length comes from the
  frozen policy rather than the profile file a bypass session must not
  read. A bypass session loads no plugins, so its references are
  built-in kinds only (parse_context_references(plugins=False)).
- Refusals: over the 50% budget, the gateway sent the refusal through
  LocalSessionAdapter.send, which publishes nothing (local delivery is
  settlement), and dropped the turn. A refused local turn now answers
  with its refusal as the turn's reply, so message.complete and the
  CLI's receipt carry it; a finite prompt fails with it. A refused
  managed turn settles the same way without spawning a worker.
  Messaging platforms still get the adapter send.

The expansion body moves out of run_inbound.py into the new module;
_expand_inbound_context_references keeps its contract.

Refs NousResearch#134889
2026-10-14 20:38:25 -04:00
Teknium
ee8bd1160f fix(gateway,cli): only a turn the classic CLI submitted gets the batch clarify request
Wave B (4d73ffa0de) sent the clarify tool's whole batch as one `clarify` server request whenever
the turn was a local-viewer turn on a `cli`-source session (classic_cli_turn). That predicate names
the session's surface, not the viewer: an ACP editor and raw WebSocket viewers also drive
`source='cli'` sessions and answer per-question `clarify.request` cards (prompts in
session.resume). They got a server request they never answer and no card, so the turn sat out the
clarify timeout: test_gateway_editor_clarify (3), test_local_session[clarify] and
test_journey_restart_open_prompts [crash, graceful] ("no open clarify prompt").

- prompt.submit gains an optional `clarify_batch: bool`, committed with the admission in
  `cli_turn_v1` (validated like the other per-turn CLI fields; contract TS/OpenRPC regenerated).
- GatewayAgent sets it when main's HermesCLI registered its clarify callback (the batch panel).
- The runner takes the batch path only for that admission (session_cli_turn.clarify_batch_turn);
  every other turn keeps main's one card per question. The classic CLI keeps main's batch panel.

Red first: test_local_viewer_clarify_batch.py::
test_a_cli_source_turn_the_classic_cli_did_not_submit_keeps_one_card_per_question.
2026-10-13 00:56:48 -07:00
Teknium
bfa156802d refactor(gateway): the classic CLI turn seams live in session_cli_turn; health clean
scripts/check --only health against cli-base flagged TurnRunner._run_sync_scoped at CC 21
(target 20) and four blind excepts in the new code.

- The one-turn model override and the receipt-field capture move into
  session_cli_turn.one_turn_route / run_classic_cli_turn: _run_sync_scoped keeps one call
  each (CC back under target). Behaviour unchanged.
- classic_cli_turn catches only RuntimeStoreError (an unrestored frozen policy).
- prompt_timeout_s drops its try: both readers already fall back to their defaults.
- The edit snapshot / diff preview keep their display-only catch-all, now logged with
  exc_info and waived inline (# health: allow BLE001), as main's CLI _on_tool_complete does.

(cherry picked from commit 5ff704361883fa6efbd13a3daf100d94a44cb817)
2026-10-12 22:25:38 -07:00
Teknium
89944edd27 feat(gateway): a classic CLI turn's receipt is the run_conversation-shaped result
Main's HermesCLI reads its turn result straight from AIAgent.run_conversation. Over the
session authority it reads prompt.receipt {include_result: true}, which lacked the keys it
renders from. For a local-viewer turn on a classic-CLI surface session (policy platform
"cli": cli / oneshot / tool) the committed result now also carries:

- pending_steer: the leftover /steer. It is taken OUT of the gateway's result so the drain no
  longer runs it as a follow-up inside this admission; main's CLI queues it as its own next
  turn and prints "delivering leftover steer", as it does in process.
- pre_transform_response, response_transformed, billing_block, last_reasoning,
  response_previewed, turn_exit_reason, verbatim.
- final_response: the agent's raw text. An empty failed turn no longer arrives as the
  gateway's chat copy, so main's chat_error_copy renders it. The delivered reply
  (message.complete text) keeps the gateway's copy for every other viewer.
- auxiliary_usage on finite turns (chat -q --usage-file / stream-json): this turn's per-task
  auxiliary delta, read exactly as hermes_cli/oneshot.py did.

TUI, Desktop, ACP and messaging turns are unchanged: they never match the predicate.

(cherry picked from commit 68f31aad0b62b4d60229e65f7f7d912f9485d7ab)
2026-10-12 22:25:26 -07:00
Teknium
01080bae83 feat(gateway): an admitted CLI turn runs its api_text, one-turn model and author
The turn now uses the committed cli_turn_v1 of the admission it executes (matched by the
event's admission id, so a follow-up drained on the same task never inherits it):

- api_text is the message run_conversation sends; the admitted text stays the persisted user
  row (main's agent_message vs persist_user_message). The gateway's own recovery wording stays
  API-only on top of it.
- model_override {model, provider?} resolves through the same switch_model pipeline /model
  uses, against the session's current route, for this turn only (main's /model --once and
  /moa runtime swap). Nothing is written to the session route, policy or override map; the
  next turn resolves its own route. An unresolvable target fails the turn with the switch's
  own sentence before any agent is built.
- turn_author was already read by row_turn_author from the committed row; pinned here.

Messaging turns never carry cli_turn_v1, so their message, persistence and runtime are
unchanged.

(cherry picked from commit b81379b855f50fed72d8bcb7635c12aff862ca90)
2026-10-12 22:25:26 -07:00
Teknium
9665f6404c feat(gateway): prompt.submit admits the classic CLI's turn_author, api_text and model_override
Main's HermesCLI sends run_conversation an API-only message (voice prefix, model-switch and
skills-reload notes) while persisting the clean text, names the turn's author for memory
attribution, and runs /model --once and /moa as a one-turn runtime swap. Over the session
authority those are facts about ONE admitted turn.

gateway/session_cli_turn.py validates the wire fields (turn_author via parse_turn_author,
api_text as a bounded string, model_override {model, provider?} only) and commits them with the
admission row as cli_turn_v1, so a retry or a queued drain runs exactly what was admitted.
execute_finite_admission binds them for that admission only (cli_turn_scope), row_turn_author
reads the committed author, and the local-operator check accepts the key. A malformed field is
refused with invalid_params before anything is committed.

Contracts: CanonicalSubmitParams declares turn_author / api_text / model_override; generated
TS/OpenRPC regenerated. This commit only admits and binds; the turn uses them next.

(cherry picked from commit bbda17ba96abe5fded71587f31c0ab01423e3178)
2026-10-12 22:25:25 -07:00