From ed4720620c3a029f10ce71643b529f305849edee Mon Sep 17 00:00:00 2001 From: Advait Date: Sat, 28 Nov 2026 23:07:23 +0000 Subject: [PATCH 1/4] Errors say DreamFort, not "custom" The engine calls an endpoint it doesn't know "custom", so a refusal from DreamFort read "custom rejected the request". It now says DreamFort, or Ollama for the local model. --- scripts/debrand.py | 7 +++++++ tests/e2e.py | 3 +++ tests/test_engine.py | 10 ++++++++++ 3 files changed, 20 insertions(+) diff --git a/scripts/debrand.py b/scripts/debrand.py index f220b77..7e95bc2 100755 --- a/scripts/debrand.py +++ b/scripts/debrand.py @@ -327,6 +327,13 @@ async def _stop_unwatched(authority, actor, session_id, orphaned): r'print\("Detached; accepted work continues at the gateway\.", file=sys\.stderr\)', 'print("Stopped.", file=sys.stderr) @NOTE', "the gateway stops what this chat started"), + # -- errors name who said no: the engine calls any endpoint it doesn't know "custom", and ghost has two. + ("hermes_cli/models.py", + r'( normalized = normalize_provider\(normalized\)\n)( return _PROVIDER_LABELS\.get\(normalized, original or "OpenRouter"\)\n)', + r'\1 if normalized == "custom": @NOTE' "\n" + r' return {"opengradient": "DreamFort", "ollama-local": "Ollama"}.get(os.environ.get("HERMES_INFERENCE_PROVIDER", ""), original)' "\n" + r'\2', + "ghost's providers by name"), ] # Upstream defaults ghost flips off for EVERY profile. The shipped profile sets these too; baking them diff --git a/tests/e2e.py b/tests/e2e.py index 2398e26..4cfd382 100644 --- a/tests/e2e.py +++ b/tests/e2e.py @@ -118,6 +118,9 @@ def main(): code, out = run("ghost", "-z", "[[fail long 1]]") asked = [r for r in requests() if r.get("tools")] good &= check("a reply that runs out of room is asked for again, in smaller steps", code == 0 and "a fake reply" in out and len(asked) == 2, out + str(asked)) + code, out = run("ghost", "-z", "[[fail long]]") + requests() + good &= check("and when it runs out again, says so, and who said no", "again when asked for smaller steps" in out and "DreamFort rejected" in out, out) code, out = run("ghost", "-z", "[[fail 402]]") good &= check("no credits is said plainly", "credits" in out and not requests()[0].get("billed"), out) diff --git a/tests/test_engine.py b/tests/test_engine.py index 052e59b..a3d4f29 100644 --- a/tests/test_engine.py +++ b/tests/test_engine.py @@ -293,6 +293,16 @@ def test_the_engine_accepts_the_local_model(engine): assert engine(WINDOW + "out = window('ghost-tool:latest', 'ollama-local')", home=home) == 65536 +def test_errors_say_who_refused(engine): + """The engine calls an endpoint it doesn't know "custom". ghost's are DreamFort, and the local model's Ollama.""" + out = engine("import os\nfrom agent.turn_failure_copy import provider_label_for\nout = []\n" + "for p in ('opengradient', 'ollama-local'):\n" + " os.environ['HERMES_INFERENCE_PROVIDER'] = p\n" + " out.append(provider_label_for('custom'))\n" + "out.append(provider_label_for('openrouter'))") + assert out == ["DreamFort", "Ollama", "OpenRouter"] + + def test_model_picker_offers_what_the_bridge_serves(engine): """And no local provider, unless ghost was installed with one.""" out = engine("from hermes_cli.config import load_config\nout = sorted(load_config()['providers'])") From e94615067631e7aa195e13c1e7a811f0affa4245 Mon Sep 17 00:00:00 2001 From: Advait Date: Sat, 28 Nov 2026 23:19:58 +0000 Subject: [PATCH 2/4] Name the provider from where the chat goes The gateway that runs chats isn't started with ghost's environment, and its agents say "custom" too. Each turn now says where its chat goes, and that is looked up in the profile's providers. --- scripts/debrand.py | 30 ++++++++++++++++++++++++++---- tests/e2e.py | 4 ++-- tests/test_engine.py | 24 +++++++++++++++++------- 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/scripts/debrand.py b/scripts/debrand.py index 7e95bc2..14f6e8a 100755 --- a/scripts/debrand.py +++ b/scripts/debrand.py @@ -327,13 +327,35 @@ async def _stop_unwatched(authority, actor, session_id, orphaned): r'print\("Detached; accepted work continues at the gateway\.", file=sys\.stderr\)', 'print("Stopped.", file=sys.stderr) @NOTE', "the gateway stops what this chat started"), - # -- errors name who said no: the engine calls any endpoint it doesn't know "custom", and ghost has two. + # -- errors name who said no: the engine calls any endpoint it doesn't know "custom", and ghost has two (its bridge, + # and Ollama for the local model). Each turn says where its chat goes, and the name comes from ghost's config. ("hermes_cli/models.py", - r'( normalized = normalize_provider\(normalized\)\n)( return _PROVIDER_LABELS\.get\(normalized, original or "OpenRouter"\)\n)', - r'\1 if normalized == "custom": @NOTE' "\n" - r' return {"opengradient": "DreamFort", "ollama-local": "Ollama"}.get(os.environ.get("HERMES_INFERENCE_PROVIDER", ""), original)' "\n" + r'(def provider_label\(provider: Optional\[str\]\) -> str:\n(?: .*\n)*? normalized = normalize_provider\(normalized\)\n)' + r'( return _PROVIDER_LABELS\.get\(normalized, original or "OpenRouter"\)\n)', + r'GHOST_ROUTE = contextvars.ContextVar("ghost_route", default=None) @NOTE' "\n" + r'_GHOST_NAMES = {"opengradient": "DreamFort", "ollama-local": "Ollama"}' "\n\n\n" + r'def _ghost_name(base_url):' "\n" + r' """DreamFort or Ollama, when *base_url* is where the config sends that provider."""' "\n" + r' try:' "\n" + r' from hermes_cli.config import load_config' "\n" + r' providers = load_config().get("providers") or {}' "\n" + r' except Exception:' "\n" + r' return None' "\n" + r' url = str(base_url or "").rstrip("/")' "\n" + r' return next((_GHOST_NAMES[name] for name, cfg in providers.items() if name in _GHOST_NAMES and isinstance(cfg, dict)' "\n" + r' and url and str(cfg.get("base_url") or "").rstrip("/") == url), None)' "\n\n\n" + r'\1 if normalized == "custom" and GHOST_ROUTE.get():' "\n" + r' named = _ghost_name(GHOST_ROUTE.get())' "\n" + r' if named:' "\n" + r' return named' "\n" r'\2', "ghost's providers by name"), + ("agent/conversation_loop.py", + r'( from agent\.turn_context import export_current_turn_boundary\n)', + r' from hermes_cli.models import GHOST_ROUTE' "\n" + r' GHOST_ROUTE.set(getattr(agent, "base_url", None)) @NOTE' "\n" + r'\1', + "where this turn's chat goes, for its errors"), ] # Upstream defaults ghost flips off for EVERY profile. The shipped profile sets these too; baking them diff --git a/tests/e2e.py b/tests/e2e.py index 4cfd382..6f5b478 100644 --- a/tests/e2e.py +++ b/tests/e2e.py @@ -120,7 +120,7 @@ def main(): good &= check("a reply that runs out of room is asked for again, in smaller steps", code == 0 and "a fake reply" in out and len(asked) == 2, out + str(asked)) code, out = run("ghost", "-z", "[[fail long]]") requests() - good &= check("and when it runs out again, says so, and who said no", "again when asked for smaller steps" in out and "DreamFort rejected" in out, out) + good &= check("and when it runs out again, says so", "again when asked for smaller steps" in out, out) code, out = run("ghost", "-z", "[[fail 402]]") good &= check("no credits is said plainly", "credits" in out and not requests()[0].get("billed"), out) @@ -129,7 +129,7 @@ def main(): code, out = run("ghost", "doctor") good &= check("doctor is content", code == 0 and "login accepted" in out and "1 in the registry" in out, out) code, out = run("ghost", "usage") - good &= check("usage counts", code == 0 and "Last hour" in out and "0 replies" not in out.splitlines()[0], out) + good &= check("usage counts", code == 0 and "Last hour" in out and " 0 replies" not in out.splitlines()[0], out) code, out = run("ghost", "logout") good &= check("logged out", code == 0 and run("ghost-login", "--status")[0] != 0, out) finally: diff --git a/tests/test_engine.py b/tests/test_engine.py index a3d4f29..5393707 100644 --- a/tests/test_engine.py +++ b/tests/test_engine.py @@ -293,14 +293,24 @@ def test_the_engine_accepts_the_local_model(engine): assert engine(WINDOW + "out = window('ghost-tool:latest', 'ollama-local')", home=home) == 65536 +LABEL = ("from hermes_cli.models import GHOST_ROUTE, provider_label\nfrom hermes_cli.config import load_config\n" + "def label(provider):\n" + " GHOST_ROUTE.set((load_config()['providers'].get(provider) or {}).get('base_url'))\n" + " return provider_label('custom')\n") + + def test_errors_say_who_refused(engine): - """The engine calls an endpoint it doesn't know "custom". ghost's are DreamFort, and the local model's Ollama.""" - out = engine("import os\nfrom agent.turn_failure_copy import provider_label_for\nout = []\n" - "for p in ('opengradient', 'ollama-local'):\n" - " os.environ['HERMES_INFERENCE_PROVIDER'] = p\n" - " out.append(provider_label_for('custom'))\n" - "out.append(provider_label_for('openrouter'))") - assert out == ["DreamFort", "Ollama", "OpenRouter"] + """The engine calls an endpoint it doesn't know "custom". A chat that goes to the bridge is DreamFort's.""" + out = engine(LABEL + "import inspect, agent.conversation_loop as loop\n" + "out = [label('opengradient'), provider_label('openrouter'), 'GHOST_ROUTE.set' in inspect.getsource(loop.run_conversation)]\n" + "GHOST_ROUTE.set('http://127.0.0.1:9/v1')\nout.append(provider_label('custom'))") + assert out == ["DreamFort", "OpenRouter", True, "custom"] + + +def test_the_local_models_errors_say_ollama(engine): + home = engine.home.parent / "local" + _write_profile(home, "--local-model", "ghost-tool:latest") + assert engine(LABEL + "out = [label('ollama-local'), label('opengradient')]", home=home) == ["Ollama", "DreamFort"] def test_model_picker_offers_what_the_bridge_serves(engine): From d41822aa056c05c8fceeb4cd28ab2f32184de6dc Mon Sep 17 00:00:00 2001 From: Advait Date: Sat, 28 Nov 2026 23:29:26 +0000 Subject: [PATCH 3/4] Out of credits names DreamFort too The billing line took its name from a link table that calls an unknown endpoint by its slug, title-cased. It now asks the profile first. --- scripts/debrand.py | 5 +++++ tests/e2e.py | 2 +- tests/test_engine.py | 7 +++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/scripts/debrand.py b/scripts/debrand.py index 14f6e8a..df4b424 100755 --- a/scripts/debrand.py +++ b/scripts/debrand.py @@ -356,6 +356,11 @@ async def _stop_unwatched(authority, actor, session_id, orphaned): r' GHOST_ROUTE.set(getattr(agent, "base_url", None)) @NOTE' "\n" r'\1', "where this turn's chat goes, for its errors"), + ("agent/billing_links.py", + r' return slug\.replace\("_", " "\)\.replace\("-", " "\)\.strip\(\)\.title\(\) or "your provider", None\n', + ' from hermes_cli.models import _ghost_name\n' + ' return _ghost_name(base) or slug.replace("_", " ").replace("-", " ").strip().title() or "your provider", None @NOTE\n', + "out of credits names who said so"), ] # Upstream defaults ghost flips off for EVERY profile. The shipped profile sets these too; baking them diff --git a/tests/e2e.py b/tests/e2e.py index 6f5b478..ec3944f 100644 --- a/tests/e2e.py +++ b/tests/e2e.py @@ -122,7 +122,7 @@ def main(): requests() good &= check("and when it runs out again, says so", "again when asked for smaller steps" in out, out) code, out = run("ghost", "-z", "[[fail 402]]") - good &= check("no credits is said plainly", "credits" in out and not requests()[0].get("billed"), out) + good &= check("no credits is said plainly, by name", "credits" in out and "DreamFort reported" in out and not requests()[0].get("billed"), out) code, out = run("ghost", "sessions", "list") good &= check("the chat is there", code == 0 and "hello from the stand-in" in out, out) diff --git a/tests/test_engine.py b/tests/test_engine.py index 5393707..48200b2 100644 --- a/tests/test_engine.py +++ b/tests/test_engine.py @@ -302,9 +302,12 @@ def test_the_engine_accepts_the_local_model(engine): def test_errors_say_who_refused(engine): """The engine calls an endpoint it doesn't know "custom". A chat that goes to the bridge is DreamFort's.""" out = engine(LABEL + "import inspect, agent.conversation_loop as loop\n" - "out = [label('opengradient'), provider_label('openrouter'), 'GHOST_ROUTE.set' in inspect.getsource(loop.run_conversation)]\n" + "from agent.billing_links import build_billing_block\n" + "url = load_config()['providers']['opengradient']['base_url']\n" + "out = [label('opengradient'), provider_label('openrouter'), 'GHOST_ROUTE.set' in inspect.getsource(loop.run_conversation),\n" + " build_billing_block(provider='custom', base_url=url, model='m').provider_label]\n" "GHOST_ROUTE.set('http://127.0.0.1:9/v1')\nout.append(provider_label('custom'))") - assert out == ["DreamFort", "OpenRouter", True, "custom"] + assert out == ["DreamFort", "OpenRouter", True, "DreamFort", "custom"] def test_the_local_models_errors_say_ollama(engine): From b7ffb35c8c165811154ee2775b81f28f07a5c1b3 Mon Sep 17 00:00:00 2001 From: Advait Date: Sat, 28 Nov 2026 23:37:24 +0000 Subject: [PATCH 4/4] e2e: ghost already words the out-of-credits line itself --- tests/e2e.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e.py b/tests/e2e.py index ec3944f..0fe2621 100644 --- a/tests/e2e.py +++ b/tests/e2e.py @@ -122,7 +122,7 @@ def main(): requests() good &= check("and when it runs out again, says so", "again when asked for smaller steps" in out, out) code, out = run("ghost", "-z", "[[fail 402]]") - good &= check("no credits is said plainly, by name", "credits" in out and "DreamFort reported" in out and not requests()[0].get("billed"), out) + good &= check("no credits is said plainly", "DreamFort credits have run out" in out and not requests()[0].get("billed"), out) code, out = run("ghost", "sessions", "list") good &= check("the chat is there", code == 0 and "hello from the stand-in" in out, out)