The hub's own small model calls (action badges, short header titles, Send-later titles) leave the core for a plugin, on any model: - sidecar POST /complete (host only): one short answer, no transcript — a harness driver's optional complete() (claude / agy / opencode / pi), or the EVOX2 / OpenRouter over HTTP; wakeLocal:false never wakes the box or loads a model (asleep → fallback at once); fallback model/harness/account; usage returned in Anthropic's shape. - complete.run bridge (hub/complete): calls /complete, books the spend in the side-call ledger. conversations.label bridge: hub/labels/pending (look_pending.py), hub/labels/look (meta.lookAuto), hub/labels/short-title. - provides conversation.title (scheduled/title.py, short_title.py — no plugin: first words / no short title) and conversation.look. - removed: sidecar/title.py, sidecar/look.py, conversations/look_labeler.py and its thread; /api/look/pending rebuilt on look_pending. - docs/plugins.md, CLAUDE.md, sidecar README updated; tests: test_hubcomplete, test_complete, test_look, test_short_title. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
126 lines
5.9 KiB
Python
126 lines
5.9 KiB
Python
"""The ``complete.run`` / ``conversations.label`` bridges and the
|
|
``conversation.title`` dispatch (plugins/hubcomplete.py, labels_bridge.py):
|
|
the body a plugin may send, the spend booked per engine, the labels written,
|
|
and what the core does with no labelling plugin installed."""
|
|
|
|
import types
|
|
import unittest
|
|
|
|
from plugins import hubcomplete, labels_bridge, manifest
|
|
from scheduled import title as title_mod
|
|
|
|
USAGE = {"input_tokens": 400, "output_tokens": 20, "cache_read_input_tokens": 0,
|
|
"cache_creation_input_tokens": 0}
|
|
|
|
|
|
class Ledger:
|
|
def __init__(self):
|
|
self.rows = []
|
|
|
|
def add_side_call(self, kind, ref, account, model, cost, units, usage, t=None):
|
|
self.rows.append((kind, ref, account, model, cost, units, usage))
|
|
|
|
|
|
class NormComplete(unittest.TestCase):
|
|
def test_clamps_and_keeps_known_fields(self):
|
|
b = hubcomplete.norm_complete({"prompt": " hi ", "system": "s", "model": "haiku",
|
|
"harness": "claude", "account": "work",
|
|
"fallbackModel": "gemini-3.8-flash",
|
|
"fallbackHarness": "agy", "timeout": 999,
|
|
"bogus": 1})
|
|
self.assertEqual(b, {"system": "s", "prompt": "hi", "wakeLocal": False, "timeout": 120,
|
|
"model": "haiku", "harness": "claude", "account": "work",
|
|
"fallbackModel": "gemini-3.8-flash", "fallbackHarness": "agy"})
|
|
|
|
def test_refuses(self):
|
|
for bad in ({}, {"prompt": "x", "model": "a b"}, {"prompt": "x", "harness": "../x"},
|
|
{"prompt": "x", "account": "A;rm"}):
|
|
with self.assertRaises(ValueError):
|
|
hubcomplete.norm_complete(bad)
|
|
|
|
|
|
class Book(unittest.TestCase):
|
|
def setUp(self):
|
|
self.deps = types.SimpleNamespace(usage_store=Ledger())
|
|
|
|
def test_claude_is_priced_from_its_tokens(self):
|
|
from conversations import pricing
|
|
model = "claude-haiku-5-5-20261001"
|
|
out = hubcomplete.book(self.deps, {"harness": "claude", "model": model, "usage": USAGE,
|
|
"account": "work", "costUsd": 99}, "short-title", "c1")
|
|
[(kind, ref, account, m, cost, units, usage)] = self.deps.usage_store.rows
|
|
u = pricing.norm_usage(USAGE)
|
|
self.assertEqual((kind, ref, account, m, usage), ("short-title", "c1", "work", model, USAGE))
|
|
self.assertAlmostEqual(cost, pricing.usage_cost(u, model))
|
|
self.assertAlmostEqual(units, pricing.plan_units(u, model))
|
|
self.assertAlmostEqual(out["costUsd"], round(cost, 6))
|
|
|
|
def test_direct_engines_carry_their_own_figure(self):
|
|
hubcomplete.book(self.deps, {"harness": "openrouter", "model": "qwen/qwen3.8-27b",
|
|
"usage": USAGE, "account": "openrouter", "costUsd": 0.0012},
|
|
"look", "s")
|
|
hubcomplete.book(self.deps, {"harness": "evox2", "model": "inkling-2-mini",
|
|
"usage": USAGE, "account": "evox2", "costUsd": 0.0},
|
|
"look", "s")
|
|
self.assertEqual([(r[2], r[4], r[5]) for r in self.deps.usage_store.rows],
|
|
[("openrouter", 0.0012, 0.0), ("evox2", 0.0, 0.0)])
|
|
|
|
|
|
class WriteLook(unittest.TestCase):
|
|
def setUp(self):
|
|
self.metas, self.events = {}, []
|
|
self.deps = types.SimpleNamespace(
|
|
meta_store=types.SimpleNamespace(update=lambda sid, p: self.metas.setdefault(sid, p)),
|
|
hub=types.SimpleNamespace(publish=self.events.append))
|
|
|
|
def test_known_action_kept_unknown_stored_as_none(self):
|
|
self.assertEqual(hubcomplete.write_look(self.deps, "s1", " Fix ", "haiku", "plugin:x"),
|
|
"fix")
|
|
self.assertIsNone(hubcomplete.write_look(self.deps, "s2", "dance", "haiku"))
|
|
self.assertEqual(self.metas["s1"]["lookAuto"]["action"], "fix")
|
|
self.assertEqual(self.metas["s1"]["lookAuto"]["source"], "plugin:x")
|
|
self.assertIsNone(self.metas["s2"]["lookAuto"]["action"])
|
|
self.assertEqual(self.events, [{"type": "meta", "id": "s1"}, {"type": "meta", "id": "s2"}])
|
|
|
|
|
|
class NoPlugin(unittest.TestCase):
|
|
"""No ``conversation.title`` provider: nothing is asked, the scheduled
|
|
title falls back to the prompt's first words."""
|
|
|
|
def test_falls_back(self):
|
|
deps = types.SimpleNamespace(plugin_store=None)
|
|
self.assertFalse(labels_bridge.available(deps))
|
|
self.assertIsNone(labels_bridge.title(deps, "Audit every compose file", "scheduled-title"))
|
|
out = title_mod.generate(deps, "Audit every compose file in the lab tonight")
|
|
self.assertEqual(out, {"title": "Audit every compose file in the…",
|
|
"summary": None, "source": "prompt"})
|
|
|
|
def test_a_provider_answer_is_cleaned(self):
|
|
orig = labels_bridge.run
|
|
seen = []
|
|
labels_bridge.run = lambda deps, key, payload: seen.append((key, payload)) or {
|
|
"title": ' "Nightly audit" ', "summary": "Checks."}
|
|
try:
|
|
ans = labels_bridge.title(object(), "x" * 9000, "short-title", "c", "work")
|
|
finally:
|
|
labels_bridge.run = orig
|
|
self.assertEqual(ans, {"title": "Nightly audit", "summary": "Checks."})
|
|
[(key, payload)] = seen
|
|
self.assertEqual(key, "conversation.title")
|
|
self.assertEqual((len(payload["text"]), payload["account"], payload["isolated"]),
|
|
(6000, "work", True))
|
|
|
|
|
|
class Manifest(unittest.TestCase):
|
|
def test_new_capabilities_and_provides_are_operator_only(self):
|
|
for cap in ("complete.run", "conversations.label"):
|
|
self.assertIn(cap, manifest._CAPABILITIES)
|
|
self.assertIn(cap, manifest._OPERATOR_CAPS)
|
|
self.assertIn(cap, manifest._CAP_LABELS)
|
|
for key in ("conversation.title", "conversation.look"):
|
|
self.assertIn(key, manifest._PROVIDES)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|