@yahyahammad/venastine 0.3.15 → 0.3.16

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
@@ -787,7 +787,7 @@ paths are cached and 200 matches offered; narrow the query when a limit is shown
787
787
  | `/mentions [ignored on\|off]` | Show file mention status or include ignored paths for this session |
788
788
  | `/quit` | Leave the harness, on one invocation — a typed command is already deliberate. `/exit` and `/bye` are the same command under other names; type toward either and the suggestion list says so |
789
789
 
790
- Keys: **ctrl+c** twice quits — the first press arms it and the footer changes to say so, and it goes back to `Quit` after a couple of seconds; a **ctrl+c** over selected text copies instead and arms nothing, so nothing you copy can end the session. **ctrl+q** quits on a single press, from anywhere, including under a dialog · **ctrl+t** thread picker · **ctrl+l** claims view · **ctrl+j** (or **shift+enter**) newline in the prompt · **shift+tab** in the prompt switches to the next agent in `config.yaml`'s `agent_cycle` (default → plan → build as shipped) · **up/down** and **enter**/**tab** to pick a slash command, **escape** to dismiss the list · **ctrl+click** a URL in an answer — or in a tool line — to open it, or the name on a `spawn_subagent` line to read what that agent did, or the name on a `shell_background`, `shell_monitor` or `shell_interactive` line to read that session -- its command, why it was started, what it printed, and what became of it. A session the harness no longer holds (it aged out, or you restarted) opens the same way and shows what the agent was given, saying so; a live one refreshes as it writes. While sessions are running the sidebar lists them, and clicking a row opens it; **ctrl+g** lists the runs going on right now and opens one from the keyboard · **ctrl+b** stops a background session, and always asks which one rather than killing on a single press. While background sessions are running the prompt and most commands are refused — `ctrl+b`, `/kill`, answering a dialog and quitting stay usable, because they are the ways out.
790
+ Keys: **ctrl+c** twice quits — the first press arms it and the footer changes to say so, and it goes back to `Quit` after a couple of seconds; a **ctrl+c** over selected text copies instead and arms nothing, so nothing you copy can end the session. **ctrl+q** quits on a single press, from anywhere, including under a dialog · **ctrl+t** thread picker · **ctrl+l** claims view · **ctrl+j** (or **shift+enter**) newline in the prompt · **shift+tab** in the prompt switches to the next agent in `config.yaml`'s `agent_cycle` (default → plan → build as shipped) · **up/down** and **enter**/**tab** to pick a slash command, **escape** to dismiss the list · **ctrl+click** a URL in an answer — or in a tool line — to open it, or the name on a `spawn_subagent` line to read what that agent did, or the name on a `shell_background`, `shell_monitor` or `shell_interactive` line to read that session -- its command, why it was started, what it printed, and what became of it. A session the harness no longer holds (it aged out, or you restarted) opens the same way and shows what the agent was given, saying so; a live one refreshes as it writes. The sidebar lists the running sessions, then the five that finished most recently, each marked with how it ended (`☑` exit 0, `☒` with its exit code, `killed`, `timed out` or `failed`), and clicking a row opens it; **ctrl+g** lists the runs going on right now and opens one from the keyboard · **ctrl+b** stops a background session, and always asks which one rather than killing on a single press. While background sessions are running the prompt and most commands are refused — `ctrl+b`, `/kill`, answering a dialog and quitting stay usable, because they are the ways out.
791
791
 
792
792
  Answers are rendered rather than printed as their source: tables become grids, headings and `**bold**` take weight, `*emphasis*` and `~~strike~~` take their own marks, code fences are highlighted, and a list item that runs past the edge wraps **under its own text** instead of back to the margin. A line indented four spaces or more is left exactly as written, so a code sample keeps its operators and its `#` comments. What is deliberately not rendered: block quotes, horizontal rules, heading *levels* (a `#` and a `######` look the same), and anything at all inside a reasoning block. `/copy` always hands back the markdown the model wrote — the rendering is what the screen does, never what is stored.
793
793
 
@@ -901,7 +901,7 @@ A level is validated against the model that will **receive** it, not the one it
901
901
  | Provider | Levels | Where the set comes from |
902
902
  |---|---|---|
903
903
  | Anthropic | `low`, `medium`, `high`, `xhigh`, `max` — whichever the model reports supported | Queried live from the Models API, so newly released Anthropic models need no entry anywhere |
904
- | OpenAI-compatible | `low`, `medium`, `high` assumed for unknown models | Static table (`model_effort_levels` in `config.yaml`). Known non-reasoning models — gpt-4o family, gpt-3.5 — ship with *empty* lists, meaning "takes no effort parameter": a requested level is dropped cleanly instead of 400ing every call. An unlisted model gets the assumption plus a WARNING naming it |
904
+ | OpenAI-compatible | `default_effort_levels` assumed for unknown models (shipped: `low` through `ultra`) | Static table (`model_effort_levels` in `config.yaml`). Known non-reasoning models — gpt-4o family, gpt-3.5 — ship with *empty* lists, meaning "takes no effort parameter": a requested level is dropped cleanly instead of 400ing every call. An unlisted model gets the assumption plus a WARNING naming it. If it then refuses the level with a 400 that mentions reasoning or thinking — a local model that cannot reason does — the same request is sent once more without it; if that succeeds, the model gets no effort for the rest of the session, and a WARNING says which `model_effort_levels` entry makes that permanent |
905
905
  | Google | Levels map to integer thinking budgets, `low`→2,048 through `max`→dynamic | Mapped at the boundary and sent as `thinking_budget`. On since batch 172, when the `google-genai` pin moved to 2.29.0; an unlisted Gemini model gets the default level set plus a WARNING, like any other unlisted model |
906
906
 
907
907
  **Seeing the thinking is separate from doing it.** Effort is what makes the model reason; whether the API hands those thoughts back to the client is a different question, and the answer varies by provider. Reasoning streams into the transcript on **Anthropic** and on OpenAI-compatible providers that send it — DeepSeek, Qwen, Z.AI, OpenRouter. It is absent on **OpenAI**, whose Chat Completions endpoint returns no reasoning text at all, and on **Google**, whose request deliberately does not ask for thought summaries: those would be billed as extra output for something the model produces either way. On those two the turn still thinks; you just do not see it. `tui.show_thinking` and `/thinking` control the display, never the reasoning.
@@ -1043,8 +1043,8 @@ Deliberately not settings.json keys: editing these means editing the harness's o
1043
1043
 
1044
1044
  | Field | Meaning |
1045
1045
  |---|---|
1046
- | `API_URL` | Endpoint base URL; empty for ANTHROPIC and GOOGLE, which use their SDKs' defaults |
1047
- | `API_KEY` | The credential, stored directly |
1046
+ | `API_URL` | Endpoint base URL; empty for ANTHROPIC and GOOGLE, which use their SDKs' defaults. For an OpenAI-compatible server it is the address the harness adds `/chat/completions` and `/models` to, so it usually ends in `/v1`: a local Ollama is `http://localhost:11434/v1`. Without the `/v1` the server answers `404 page not found`, and the harness's error says it is the address, not the model |
1047
+ | `API_KEY` | The credential, stored directly. A local OpenAI-compatible server that needs none can leave it empty: the harness sends a placeholder, because the openai SDK will not build a client with an empty key |
1048
1048
  | `is_v1_compatible` | `true` routes the provider through the OpenAI-compatible translation |
1049
1049
  | `supports_stream_usage` | Promises streamed responses carry token usage. If a stream then ends with none, the harness **raises** rather than accounting zero tokens — a silent zero would disable the budget stop condition while looking healthy. Endpoints that don't return streaming usage ship with `false` |
1050
1050
  | `echoes_reasoning` | Opt in to sending this provider's own reasoning back on the next request (§44). Off everywhere by default: there is no standard for it the way there is for receiving reasoning — DeepSeek documents that `reasoning_content` must not be supplied on input and returns a 400, while OpenRouter accepts it for some models and ignores it for others. Anthropic needs no flag; its thinking blocks are signed and are echoed to the model that produced them automatically |
@@ -1077,7 +1077,7 @@ note that shell approval is governed solely by `shell_approval_mode` -- `tool_ap
1077
1077
  deliberately has no `shell` key, so an old file carrying one is refused at startup
1078
1078
  naming the key — see `tests/BREAKING_CHANGES.md` §24.
1079
1079
 
1080
- Run the test suite with `pytest` — 9461 tests, fully offline, no API keys needed. Since batch 243 the suite holds itself to that: a test that asks DNS for a name, or writes into your home folder, fails by name, and every test process runs with HOME pointing at a throwaway folder of its own. The suite's own packages are `requirements-test.txt`, separate from `requirements.txt` since batch 136: they used to be in the shipped dependency list, so installing the harness also installed a test runner. It runs in parallel by default (`pytest-xdist`, 70% of your cores): **1:26 on a 16-core machine, against 9:06 single-process.** `pytest -n0` forces the old serial run, which is what you want under a debugger or when something is parsing the output. Eight further tests are marked `integration` and excluded by default: three spawn a real stdio MCP server, one runs an external program through the host fallback shell, one builds the hosted bundle's Docker image, and three run the installers' uv path against a real uv (`pytest -m integration`).
1080
+ Run the test suite with `pytest` — 9510 tests, fully offline, no API keys needed. Since batch 243 the suite holds itself to that: a test that asks DNS for a name, or writes into your home folder, fails by name, and every test process runs with HOME pointing at a throwaway folder of its own. The suite's own packages are `requirements-test.txt`, separate from `requirements.txt` since batch 136: they used to be in the shipped dependency list, so installing the harness also installed a test runner. It runs in parallel by default (`pytest-xdist`, 70% of your cores): **1:26 on a 16-core machine, against 9:06 single-process.** `pytest -n0` forces the old serial run, which is what you want under a debugger or when something is parsing the output. Eight further tests are marked `integration` and excluded by default: three spawn a real stdio MCP server, one runs an external program through the host fallback shell, one builds the hosted bundle's Docker image, and three run the installers' uv path against a real uv (`pytest -m integration`).
1081
1081
 
1082
1082
  ## Documentation
1083
1083
 
package/core/client.py CHANGED
@@ -10,6 +10,7 @@ from uuid import UUID, uuid4
10
10
 
11
11
  import config
12
12
  import credentials
13
+ from core import provider_errors
13
14
  from credentials import (
14
15
  load_provider_data,
15
16
  no_providers_message,
@@ -41,6 +42,11 @@ logger = logging.getLogger(__name__)
41
42
  # rebuild the client (and re-read the credentials file) every time.
42
43
  _client_cache: dict[str, object] = {}
43
44
 
45
+ #: What an OpenAI-compatible provider with an empty API_KEY is sent instead
46
+ #: (batch 258; see api_initialization). Says what it is, to anyone reading
47
+ #: a server's log, and is not shaped like any provider's real key.
48
+ KEYLESS = "venastine-no-key-configured"
49
+
44
50
 
45
51
  def api_initialization(provider_name: str):
46
52
  if provider_name in _client_cache:
@@ -70,7 +76,16 @@ def api_initialization(provider_name: str):
70
76
  client = _chatgpt_client()
71
77
  elif entry.get("is_v1_compatible", False):
72
78
  from openai import OpenAI
73
- client = OpenAI(base_url=entry["API_URL"], api_key=entry["API_KEY"],
79
+ # BATCH 258. An EMPTY key is sent as KEYLESS. openai 3.x refuses
80
+ # "" while the client is being built -- "Missing credentials ...
81
+ # set the OPENAI_API_KEY environment variable", measured on 3.45.0
82
+ # -- which broke the one configuration this harness says needs no
83
+ # key (credentials.missing_key_message: "unless it is a local
84
+ # endpoint that needs none"), and said so in another vendor's
85
+ # words. A local server ignores the placeholder; a remote one
86
+ # answers 401, and launch has already warned that the key is empty.
87
+ client = OpenAI(base_url=entry["API_URL"],
88
+ api_key=entry["API_KEY"] or KEYLESS,
74
89
  **_metered("openai"))
75
90
  elif provider_name == "GOOGLE":
76
91
  from google import genai
@@ -1238,6 +1253,12 @@ def _messages_for_provider(provider_name: str, neutral_messages: list[dict],
1238
1253
  # Anthropic branch queries the API once per process rather than per call.
1239
1254
  _effort_levels_cache: dict[tuple[str, str], list[str]] = {}
1240
1255
 
1256
+ # (provider_name, model, level) whose drop effort_for has already reported.
1257
+ # Batch 258: a model that refused effort is recorded as taking none, and
1258
+ # effort_for then drops the chosen level on every turn -- said once, not
1259
+ # once per message.
1260
+ _effort_drops_said: set[tuple[str, str, str]] = set()
1261
+
1241
1262
  # (provider_name, model) -> context window in tokens, or None for "asked,
1242
1263
  # and this provider does not report one". Same lazy, once-per-process
1243
1264
  # posture as the effort cache above; see context_window_for() for why None
@@ -1422,9 +1443,13 @@ def effort_for(client, provider_name: str, model: str,
1422
1443
  "Could not verify effort %r for %s/%s; sending it unverified.",
1423
1444
  requested, provider_name, model)
1424
1445
  return requested
1425
- logger.warning(
1426
- "Dropping effort %r: %s/%s accepts %s. Sending no effort parameter.",
1427
- requested, provider_name, model, levels or "no effort control")
1446
+ said = (provider_name, model, requested)
1447
+ if said not in _effort_drops_said:
1448
+ _effort_drops_said.add(said)
1449
+ logger.warning(
1450
+ "Dropping effort %r: %s/%s accepts %s. Sending no effort "
1451
+ "parameter.", requested, provider_name, model,
1452
+ levels or "no effort control")
1428
1453
  return None
1429
1454
 
1430
1455
 
@@ -1689,7 +1714,16 @@ def _model_info(client, model):
1689
1714
  raise
1690
1715
  try:
1691
1716
  entries = list(listing())
1692
- except Exception:
1717
+ except Exception as listing_error:
1718
+ # BATCH 258: one exception to the rule below. `/models` is the
1719
+ # route EVERY OpenAI-compatible server has, so a page-not-found
1720
+ # there is not about this model -- it is the address, and the
1721
+ # most useful thing this lookup can say (core/provider_errors.
1722
+ # route_miss). The per-id route cannot carry that alone: some
1723
+ # providers have no such route for ids with a slash.
1724
+ if provider_errors.route_miss(listing_error):
1725
+ raise provider_errors.explain_route_miss(
1726
+ listing_error) from None
1693
1727
  # The listing is not a second opinion about the retrieve; it is
1694
1728
  # the same question by another route. Report the FIRST failure,
1695
1729
  # which is the one that names the endpoint the caller asked for.
@@ -2023,11 +2057,14 @@ def _chatgpt_open(client, request: dict):
2023
2057
  them (CG10). A refresh that could not be made at all is a
2024
2058
  `ConnectionError`, which the loop retries like any dropped connection.
2025
2059
 
2026
- THE ONE RESEND THIS FILE MAKES, and it is not a retry in AGENTS.md's
2027
- sense, which this file does not own: nothing was wrong with the request
2028
- or the weather, the credential was stale, and the second attempt is made
2029
- with a different one. Every retry for a failure the provider might not
2030
- repeat is still `core/loop.py`'s, asked of `core/provider_errors.py`.
2060
+ ONE OF THE TWO RESENDS THIS FILE MAKES, and neither is a retry in
2061
+ AGENTS.md's sense, which this file does not own: nothing was wrong with
2062
+ the request or the weather, the credential was stale, and the second
2063
+ attempt is made with a different one. The other is
2064
+ `_resend_without_effort` (batch 258), the same kind: a different
2065
+ request, never the same one again. Every retry for a failure the
2066
+ provider might not repeat is still `core/loop.py`'s, asked of
2067
+ `core/provider_errors.py`.
2031
2068
  """
2032
2069
  from core import chatgpt_auth
2033
2070
 
@@ -2192,6 +2229,50 @@ def _chatgpt_stream(client, model: str, items: list, system_prompt: str,
2192
2229
  # ---- Streaming call + helpers -----------------------------------------------
2193
2230
  # ============================================================================
2194
2231
 
2232
+ def _resend_without_effort(client, provider_name: str, model: str,
2233
+ kwargs: dict, thinking: dict, sampling: dict,
2234
+ temperature, effort: Optional[str], refusal):
2235
+ """Send an OpenAI-compatible request once more, without the reasoning
2236
+ effort a model refused, and return its stream (batch 258).
2237
+
2238
+ THE SECOND RESEND THIS FILE MAKES, and it is CG10's kind, not a retry:
2239
+ the request was wrong for this model, and the second attempt is a
2240
+ different request. `default_effort: high` ships, and a model with no
2241
+ `model_effort_levels` entry is assumed to take every level, so a local
2242
+ model that cannot reason was sent `reasoning_effort` on its first turn
2243
+ and refused it -- a local Ollama: `"llama3.2:3b" does not support
2244
+ thinking`, a 400 (measured). The owner chose to drop it and resend.
2245
+
2246
+ BELIEVED ONLY IF THE RESEND SUCCEEDS. `provider_errors.refuses_effort`
2247
+ matches widely, because no two servers word this alike; what makes
2248
+ that safe is here. A resend that fails too means the effort was not
2249
+ the cause, so the FIRST refusal is raised -- it is about the request
2250
+ the user's settings made -- and nothing is recorded. A resend that
2251
+ succeeds records the model as taking no effort for the life of the
2252
+ process (`_effort_levels`' cache), so effort_for drops the level from
2253
+ then on and the picker stops offering one.
2254
+
2255
+ `sampling` is rebuilt for no effort: on OPENAI the effort decides
2256
+ whether a temperature may be sent at all (`_sampling_kwargs`).
2257
+ """
2258
+ resend = {key: value for key, value in kwargs.items()
2259
+ if key not in thinking and key not in sampling}
2260
+ resend.update(_sampling_kwargs(provider_name, model, temperature, None))
2261
+ try:
2262
+ stream = client.chat.completions.create(**resend)
2263
+ except Exception:
2264
+ raise refusal from None
2265
+ _effort_levels_cache[(provider_name, model)] = []
2266
+ logger.warning(
2267
+ "%s/%s refused reasoning effort %r (%s). Sent again without it, "
2268
+ "which it accepted, so no effort is sent to this model again this "
2269
+ "session. To make that permanent, add %r: [] under "
2270
+ "model_effort_levels in config.yaml.",
2271
+ provider_name, model, effort, provider_errors.describe(refusal),
2272
+ model)
2273
+ return stream
2274
+
2275
+
2195
2276
  def call_model_stream(
2196
2277
  client,
2197
2278
  provider_name: str,
@@ -2450,7 +2531,17 @@ def call_model_stream(
2450
2531
  usage = {"input_tokens": None, "output_tokens": None}
2451
2532
 
2452
2533
  finish_reason = None
2453
- for chunk in client.chat.completions.create(**openai_kwargs):
2534
+ try:
2535
+ stream = client.chat.completions.create(**openai_kwargs)
2536
+ except Exception as refusal:
2537
+ if not (thinking and provider_errors.refuses_effort(refusal)):
2538
+ # Batch 258: a page-not-found names the address, not a model.
2539
+ provider_errors.explain_route_miss(refusal)
2540
+ raise
2541
+ stream = _resend_without_effort(
2542
+ client, provider_name, model, openai_kwargs, thinking, sampling,
2543
+ temperature, effort, refusal)
2544
+ for chunk in stream:
2454
2545
  if chunk.choices:
2455
2546
  # W4 (#37): free -- chunk.choices[0] is already read here. The
2456
2547
  # provider sets this on the last content chunk, and `or
@@ -57,9 +57,11 @@ which says nothing true. So both questions this module answers walk
57
57
  worth another attempt, and its own sentence is the description.
58
58
  """
59
59
 
60
+ import json
60
61
  from random import random
61
62
  from time import sleep
62
63
  from typing import Optional
64
+ from urllib.parse import urlsplit, urlunsplit
63
65
 
64
66
  #: Beside any 5xx. The same set the openai and anthropic SDKs retry.
65
67
  RETRYABLE_STATUSES = frozenset({408, 409, 429})
@@ -76,6 +78,11 @@ JITTER = 0.25
76
78
  #: sentence and the error object google-genai folds into its message.
77
79
  DESCRIBE_LIMIT = 500
78
80
 
81
+ #: The words `explain_route_miss` adds before the address (batch 258), and
82
+ #: how it knows an exception already carries them -- the lookup and the
83
+ #: call can both reach the same one, and saying it twice says nothing more.
84
+ ROUTE_MISS_MARK = "nothing answers at"
85
+
79
86
  _CONNECTION_NAMES = frozenset({
80
87
  "APIConnectionError", "APITimeoutError", # openai, anthropic
81
88
  "TransportError", "TimeoutException", # httpx: raw mid-stream; google-genai
@@ -272,3 +279,98 @@ def describe(exc: BaseException) -> str:
272
279
  text = text[:DESCRIBE_LIMIT - 1].rstrip() + "…"
273
280
  name = type(exc).__name__
274
281
  return f"{name}: {text}" if text else name
282
+
283
+
284
+ def _bare_address(url: str) -> str:
285
+ """Scheme, host, port and path -- never a query, a fragment or a
286
+ user:password, which an address can carry and a message must not."""
287
+ parts = urlsplit(url)
288
+ host = parts.hostname or ""
289
+ if ":" in host:
290
+ host = f"[{host}]"
291
+ if parts.port is not None:
292
+ host = f"{host}:{parts.port}"
293
+ return urlunsplit((parts.scheme, host, parts.path, "", ""))
294
+
295
+
296
+ def route_miss(exc: BaseException) -> Optional[str]:
297
+ """The address a request was sent to that the server has NO ROUTE for,
298
+ or None when `exc` is anything else (batch 258).
299
+
300
+ A 404 whose body is not JSON. An OpenAI-compatible server answers in
301
+ JSON for everything it understands -- a model it does not have, a model
302
+ without tools, a model that cannot reason -- so a plain body is the
303
+ server's own page-not-found, sent before any model was looked at.
304
+ Measured on a real local Ollama: `/models` and `/chat/completions`
305
+ answer `404 text/plain` "404 page not found", while `/v1/...` answers a
306
+ missing model with a JSON 404 naming it. The openai SDK keeps a body it
307
+ could not parse as the STRING it was (`body`), and the request it sent
308
+ (`request.url`), which is all this reads -- no SDK import, for this
309
+ module's reason.
310
+ """
311
+ if _as_status(getattr(exc, "status_code", None)) != 404:
312
+ return None
313
+ if not isinstance(getattr(exc, "body", None), str):
314
+ return None
315
+ url = getattr(getattr(exc, "request", None), "url", None)
316
+ if url is None:
317
+ return None
318
+ return _bare_address(str(url))
319
+
320
+
321
+ def explain_route_miss(exc: BaseException) -> BaseException:
322
+ """Add what a route miss MEANS to `exc`'s own message, in place, and
323
+ return it (batch 258).
324
+
325
+ "404 page not found" -- or, on openai 3.x, "Error code: 404" -- was the
326
+ whole report, and a reader took it for the model: missing tool support,
327
+ a bad Modelfile. It is the address. The words go ON THE EXCEPTION
328
+ because every surface prints the exception -- the transcript's error
329
+ line, the CLI's, the worker log, `describe` and the context-window
330
+ warning -- and five call sites each adding a hint is five chances to
331
+ miss one. In place, so the type, status and body that `is_transient`
332
+ and every caller read are the ones the SDK set.
333
+ """
334
+ url = route_miss(exc)
335
+ if url is None or ROUTE_MISS_MARK in str(exc):
336
+ return exc
337
+ # Imported here, so this module's own imports stay the standard
338
+ # library's, and read through the module so a test's monkeypatch of
339
+ # LLM_PROVIDERS_FILE is seen.
340
+ import credentials
341
+
342
+ text = (f"{exc} -- {ROUTE_MISS_MARK} {url}. That is the server's "
343
+ f"page-not-found, sent before any model was asked, so the "
344
+ f"address is wrong rather than the model: API_URL in "
345
+ f"{credentials.LLM_PROVIDERS_FILE} is not where this server's "
346
+ f"API is. An OpenAI-compatible server's API_URL usually ends in "
347
+ f"/v1, as a local Ollama's does (http://localhost:11434/v1).")
348
+ exc.args = (text,)
349
+ if hasattr(exc, "message"):
350
+ exc.message = text
351
+ return exc
352
+
353
+
354
+ def refuses_effort(exc: BaseException) -> bool:
355
+ """Whether a refusal MIGHT be about the reasoning effort a request
356
+ carried (batch 258).
357
+
358
+ A 400 or 422 whose message or error object says "reasoning" or
359
+ "thinking". Wide on purpose, and safe because of what it decides: the
360
+ caller sends the request once more WITHOUT the effort and believes the
361
+ answer only if that resend succeeds. A wrong match costs one request and
362
+ changes nothing. A narrow match costs the user a turn that fails: there
363
+ is no standard wording -- a local Ollama says `"llama3.2:3b" does not
364
+ support thinking` (measured), OpenAI-compatible routers name the
365
+ `reasoning_effort` parameter.
366
+ """
367
+ if _as_status(getattr(exc, "status_code", None)) not in (400, 422):
368
+ return False
369
+ body = getattr(exc, "body", None)
370
+ words = str(exc)
371
+ if isinstance(body, (dict, list)):
372
+ words += " " + json.dumps(body, default=str)
373
+ elif isinstance(body, str):
374
+ words += " " + body
375
+ words = words.lower()
376
+ return "reasoning" in words or "thinking" in words
@@ -479,6 +479,13 @@ class SessionRow:
479
479
  ran_on: str
480
480
  tier: str
481
481
  return_code: Optional[int]
482
+ # BATCH 258. When the session ended, on the manager's monotonic clock,
483
+ # and None while it runs. The sidebar keeps the five most recent
484
+ # finished sessions under the running ones (SS14, amended), and
485
+ # "most recent" is an order by THIS -- the start order the rows
486
+ # arrive in is not the order they end in. Last and defaulted, so a
487
+ # row built by keyword elsewhere is still a whole row.
488
+ finished_mono: Optional[float] = None
482
489
 
483
490
 
484
491
  @dataclass
@@ -530,7 +537,8 @@ class _Session:
530
537
  call_id=self.call_id, state=self.state,
531
538
  started_wall=self.started_wall, timeout_s=self.timeout_s,
532
539
  match_count=self.match_count, output_chars=self.output.total,
533
- ran_on=self.ran_on, tier=self.tier, return_code=self.return_code)
540
+ ran_on=self.ran_on, tier=self.tier, return_code=self.return_code,
541
+ finished_mono=self.finished_mono)
534
542
 
535
543
 
536
544
  @dataclass
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yahyahammad/venastine",
3
- "version": "0.3.15",
3
+ "version": "0.3.16",
4
4
  "description": "A from-scratch agentic harness: tool-using chat plus a ten-pass self-critiquing research pipeline.",
5
5
  "keywords": [
6
6
  "agent",
package/pyproject.toml CHANGED
@@ -18,7 +18,7 @@ build-backend = "setuptools.build_meta"
18
18
 
19
19
  [project]
20
20
  name = "venastine-research-harness"
21
- version = "0.3.15"
21
+ version = "0.3.16"
22
22
  description = "A from-scratch agentic harness: tool-using chat plus a ten-pass self-critiquing research pipeline."
23
23
  readme = "README.md"
24
24
  # The same words as package.json's `keywords`, in the same order: what a
package/tui/app.py CHANGED
@@ -487,8 +487,9 @@ class SessionRowsChanged(Message):
487
487
  sink runs on the manager's threads and the handler on the UI thread,
488
488
  so a delta would have the panel reassembling an order it never saw.
489
489
 
490
- FILTERED ON THE UI SIDE, not here. The panel shows live sessions
491
- only (SS14), and doing that in the handler keeps this message a
490
+ FILTERED ON THE UI SIDE, not here. The panel shows the running
491
+ sessions and the five most recent finished ones (SS14, amended in
492
+ batch 258), and doing that in the handler keeps this message a
492
493
  faithful copy of what the manager said rather than a view of it --
493
494
  which is what lets a second reader be added without the first one's
494
495
  filter being in the way.
@@ -656,14 +657,45 @@ def _redacted_command(row) -> str:
656
657
  return check_output_policy(tool, {"command": row.command})["command"]
657
658
 
658
659
 
660
+ #: How many finished sessions the sidebar keeps under the running ones
661
+ #: (SS14 as amended in batch 258; the owner's choice of five). The
662
+ #: manager keeps twenty (`_FINISHED_KEPT`), so this is a view of what it
663
+ #: holds and never a reason for it to hold more.
664
+ PANEL_FINISHED_SHOWN = 5
665
+
666
+
667
+ def _panel_outcome(row) -> tuple[str, str]:
668
+ """A session's `(status, outcome)` for the panel: how it ended, in as
669
+ few cells as say it.
670
+
671
+ `done` is an exit of 0 and nothing else. A non-zero code, a kill, a
672
+ timeout and a start that failed are all `failed`, and the outcome
673
+ text tells them apart -- the code itself where there is one, because
674
+ `2` and `137` are what a person would go and look up.
675
+ """
676
+ if row.state in shell_sessions.LIVE_STATES:
677
+ return "running", ""
678
+ if row.state == shell_sessions.EXITED:
679
+ if row.return_code is None:
680
+ return "failed", "exited"
681
+ return ("done" if row.return_code == 0 else "failed",
682
+ str(row.return_code))
683
+ return "failed", {shell_sessions.KILLED: "killed",
684
+ shell_sessions.TIMED_OUT: "timed out",
685
+ shell_sessions.FAILED: "failed"}.get(row.state,
686
+ row.state)
687
+
688
+
659
689
  def _panel_rows(rows) -> list[dict]:
660
- """`SessionRow`s as the session panel's `{id, label}` pairs (SS14).
690
+ """`SessionRow`s as the session panel's rows (SS14).
661
691
 
662
692
  EIGHTEEN COLUMNS, so the label is the id and as much of the command
663
693
  as fits -- the widget elides, and what it elides from has to be the
664
694
  part that identifies the session rather than a prefix of `docker`.
665
695
  A monitor's match count rides along when there is one, because "it
666
696
  has matched something" is the whole reason a monitor is on screen.
697
+ A finished row adds its `status` and `outcome` (`_panel_outcome`),
698
+ which the widget fits before the command.
667
699
 
668
700
  Module-level beside `_kill_rows`, for its reason.
669
701
  """
@@ -671,8 +703,10 @@ def _panel_rows(rows) -> list[dict]:
671
703
  for row in rows:
672
704
  matches = (f" {row.match_count}✓"
673
705
  if row.kind == "monitor" and row.match_count else "")
706
+ status, outcome = _panel_outcome(row)
674
707
  out.append({"id": row.id,
675
- "label": f"{row.id}{matches} {_redacted_command(row)}"})
708
+ "label": f"{row.id}{matches} {_redacted_command(row)}",
709
+ "status": status, "outcome": outcome})
676
710
  return out
677
711
 
678
712
 
@@ -2439,13 +2473,15 @@ class VenastineApp(App):
2439
2473
  self.open_session(str(message.session_id))
2440
2474
 
2441
2475
  def open_session(self, session_id: str) -> None:
2442
- """Show a LIVE session, read-only (SS14).
2476
+ """Show a session this process holds, read-only (SS14).
2443
2477
 
2444
2478
  The panel's route, and the only one that starts from a session
2445
2479
  id: the panel draws what the manager holds, so by definition
2446
- this process has the session. A row that has finished between
2447
- the draw and the click is the one race, and it is answered the
2448
- way a missing thread is -- said, not ignored.
2480
+ this process has the session -- running, or one of the finished
2481
+ rows the panel keeps since batch 258, whose output the manager
2482
+ still has. A row that aged out of the manager between the draw
2483
+ and the click is the one race, and it is answered the way a
2484
+ missing thread is -- said, not ignored.
2449
2485
  """
2450
2486
  row = shell_sessions.sessions.row(session_id)
2451
2487
  if row is None:
@@ -3651,9 +3687,9 @@ class VenastineApp(App):
3651
3687
  def on_session_rows_changed(self, message: SessionRowsChanged) -> None:
3652
3688
  """The session sink spoke. Runs on the UI thread (§49, SS14)."""
3653
3689
  self.refresh_session_panel(message.rows)
3654
- # SS14: the panel shows live sessions only, so a session that
3655
- # just finished leaves it -- and the view of it, if one is open,
3656
- # is now showing a state that has moved. Repainted here because
3690
+ # SS14: a session that just finished changes its row's mark --
3691
+ # and the view of it, if one is open, is now showing a state
3692
+ # that has moved. Repainted here because
3657
3693
  # this is the only signal: the poll stops the moment the session
3658
3694
  # stops being live, so without this the view would keep the last
3659
3695
  # tick's "running" header for good.
@@ -3675,13 +3711,23 @@ class VenastineApp(App):
3675
3711
  `refresh_agent_panel`'s reason: two writers of one widget is how
3676
3712
  the two come to draw it differently.
3677
3713
 
3678
- THE FILTER IS HERE, which is SS14's "live sessions only" -- the
3679
- message carries everything the manager holds, so this is the one
3680
- place that decides what a reader sees.
3714
+ THE FILTER IS HERE, which is SS14's -- the message carries
3715
+ everything the manager holds, so this is the one place that
3716
+ decides what a reader sees. Since batch 258 that is every running
3717
+ session as it started, then the PANEL_FINISHED_SHOWN most recent
3718
+ finished ones, newest first. It was running only, and a session
3719
+ then left the panel at the moment it ended -- which is also the
3720
+ moment its wake starts the agent's next turn, so the row seemed
3721
+ to be taken by the turn.
3681
3722
  """
3682
3723
  live = [row for row in rows
3683
3724
  if row.state in shell_sessions.LIVE_STATES]
3684
- self._session_panel.show(_panel_rows(live))
3725
+ finished = sorted(
3726
+ (row for row in rows
3727
+ if row.state not in shell_sessions.LIVE_STATES),
3728
+ key=lambda row: row.finished_mono or 0.0,
3729
+ reverse=True)[:PANEL_FINISHED_SHOWN]
3730
+ self._session_panel.show(_panel_rows(live) + _panel_rows(finished))
3685
3731
 
3686
3732
  @property
3687
3733
  def _session_panel(self) -> SessionPanel:
package/tui/widgets.py CHANGED
@@ -1197,14 +1197,23 @@ class AgentPanel(Static):
1197
1197
  self.update(as_content(body))
1198
1198
 
1199
1199
  class SessionPanel(Static):
1200
- """What is running in the background, and nothing else (§49, SS14).
1201
-
1202
- LIVE SESSIONS ONLY, which is the decision rather than a consequence
1203
- of how it is fed. A finished session is still readable -- SS14 puts
1204
- that on the tool-call line that started it, resolved at press time
1205
- the way §47 resolves a spawn -- so listing finished ones here would
1206
- spend contested sidebar rows on a second route to the same pane,
1207
- and would grow without bound in a session that starts many.
1200
+ """What is running in the background, and what just finished (§49,
1201
+ SS14 as amended in batch 258).
1202
+
1203
+ RUNNING FIRST, THEN THE FIVE MOST RECENT FINISHED, marked. This was
1204
+ "live sessions only", and that was measured wrong in use: a session
1205
+ left the panel the moment it ended, and its end is also what wakes
1206
+ the agent, so the row vanished just as a new turn began. It read as
1207
+ the turn hiding it, and nobody could tell which sessions had finished
1208
+ without opening each one. The tool-call line still opens a session
1209
+ of any age; this is the glance, and five keeps it bounded in a
1210
+ session that starts many. The cap is app.py's, with the filter.
1211
+
1212
+ A ROW SAYS HOW IT ENDED in the research panel's three marks (E14):
1213
+ `▸` running, `☑` exited 0, `☒` anything else -- a non-zero code,
1214
+ killed, timed out, or failed to start -- with the outcome after the
1215
+ command. The outcome is fitted FIRST and the command gives way to
1216
+ it, because the outcome is the half a finished row exists to show.
1208
1217
 
1209
1218
  PROCESS-WIDE, like AgentPanel above it and like ctrl+b's picker.
1210
1219
  SS11 scopes the five TOOLS to the caller's own thread, which is a
@@ -1220,14 +1229,19 @@ class SessionPanel(Static):
1220
1229
  surface only through check_output_policy, and keeping that call in
1221
1230
  app.py means this file never holds an unredacted one.
1222
1231
 
1223
- Hidden when nothing is running, GoalBanner-style, which is almost
1224
- always -- the sidebar is twenty columns wide and its rows are
1225
- contested.
1232
+ Hidden until a session has started, GoalBanner-style -- the sidebar
1233
+ is twenty columns wide and its rows are contested.
1226
1234
  """
1227
1235
 
1228
1236
  #: AgentPanel's, measured the same way and for the same box.
1229
1237
  WIDTH = 18
1230
1238
 
1239
+ #: `status` -> (mark, style role). The research panel's pass marks
1240
+ #: and roles, so the sidebar's two progress lists read as one family.
1241
+ STATUS = {"running": (MARK_RUNNING, "tool"),
1242
+ "done": (MARK_DONE, "pass_done"),
1243
+ "failed": (MARK_FAILED, "error")}
1244
+
1231
1245
  def __init__(self, **kwargs):
1232
1246
  super().__init__(**kwargs)
1233
1247
  self._rows: list = []
@@ -1243,8 +1257,11 @@ class SessionPanel(Static):
1243
1257
  return themes.styles_for(app)
1244
1258
 
1245
1259
  def show(self, rows) -> None:
1246
- """Draw the live sessions. `rows` is [{"id", "label"}], already
1247
- redacted, in the order they started.
1260
+ """Draw the sessions. `rows` is [{"id", "label", "status",
1261
+ "outcome"}], already redacted and in the order to draw: the
1262
+ running ones as they started, then the finished, newest first.
1263
+ `status` is a key of STATUS and defaults to running; `outcome` is
1264
+ empty while a session runs.
1248
1265
 
1249
1266
  An empty list hides the widget, which is how the panel closes
1250
1267
  without a second method meaning the same thing (ThreadCrumb's
@@ -1279,10 +1296,19 @@ class SessionPanel(Static):
1279
1296
  body = Text()
1280
1297
  body.append("sessions\n\n")
1281
1298
  for row in self._rows:
1282
- label = AgentPanel._fit(row.get("label", ""), self.WIDTH - 2)
1299
+ mark, role = self.STATUS.get(row.get("status", "running"),
1300
+ self.STATUS["running"])
1301
+ outcome = row.get("outcome", "")
1302
+ room = self.WIDTH - 2
1303
+ if outcome:
1304
+ # The outcome is never cut: a row is the mark, a space,
1305
+ # and sixteen cells, and the command takes what is left.
1306
+ room -= cell_len(outcome) + 1
1307
+ label = AgentPanel._fit(row.get("label", ""), room)
1308
+ text = f"{label} {outcome}" if outcome else label
1283
1309
  body.append(
1284
- f"{MARK_RUNNING} {label}\n",
1285
- meta_style(styles.get("tool", ""), "session", row.get("id")))
1310
+ f"{mark} {text}\n",
1311
+ meta_style(styles.get(role, ""), "session", row.get("id")))
1286
1312
  # AgentPanel's note: the nowrap/clip rule lives on the widget in
1287
1313
  # app.tcss, because `Content` carries neither flag.
1288
1314
  self.display = True