feat(codex-link): bridge 7 - external models work like subscription models

Measured with the unmodified Codex binary on 10 Oct 2026:
- real context windows per model (NanoGPT list, local table, combo = its
  smallest member, capped at the summarizer's window) so Codex compacts by
  itself when switching to a smaller model; an overflow guard trims
  oversized old parts and reports what still does not fit
- classic tools instead of code mode for external models: GLM 0/3 -> 3/3,
  Qwen 0/3 -> 2/3 on simple tool tasks, Claude/cx/Gemini unchanged
- phase (commentary / final_answer) on external assistant messages
- an answer cut by the client is carried to the next turn once
- images stay for vision-capable targets
- summary brake stops tight loops, not frequent compaction
- permanent gateway errors and tool-less targets fail at once with a
  readable message instead of five reconnects
- a lone "." (used to apply a model change in voice) is answered locally
- the bridge listens within seconds; the IDE waits 45 s for it

Release: AITURK IDE 1.0.0-beta.26.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
yilsemandClaude Opus 5.5 committed 2026-10-10 22:04:58 +03:00
1 parent ac0fdcf355
commit acf88f8314
19 files changed
+1160 -47

No files matched your search

@@ -0,0 +1,91 @@
"""Bridge 7: tool-less models are learned, flat gateway errors are translated, instructions are never trimmed."""
import ast
import json
import tempfile
import unittest
from pathlib import Path
import pencere
tree = ast.parse(Path(__file__).with_name("bridge.py").read_text(encoding="utf-8"))
names = {"fix_tool_ids", "SseRewriter", "phase_damgala", "asistan_mesaji_mi", "nokta_mesaji_mi", "hazir_yaniti"}
nodes = [n for n in tree.body if isinstance(n, (ast.FunctionDef, ast.ClassDef)) and n.name in names]
for node in tree.body:
if isinstance(node, ast.Assign) and any(isinstance(t, ast.Name) and t.id in
{"ID_PREFIX", "FOREIGN_ID_MARK", "REFERENCE_TYPES", "INLINE_TYPES", "ARAC_OGELERI", "NOKTA_ISARETLERI"} for t in node.targets):
nodes.insert(0, node)
env = {"json": json, "re": __import__("re"), "time": __import__("time"), "log": lambda message: None, "pencere": pencere}
exec(compile(ast.Module(body=nodes, type_ignores=[]), "bridge.py", "exec"), env)
def feed(event, **kw):
adapter = env["SseRewriter"](set(), **kw)
raw = b"data: " + json.dumps(event).encode() + b"\n\n"
return [json.loads(line[6:]) for line in (adapter.feed(raw) + adapter.flush()).decode().splitlines()
if line.startswith("data: ")]
class Ek(unittest.TestCase):
def test_model_without_tool_calls_is_reported_and_remembered(self):
seen = []
flat = {"type": "error", "code": "bad_request", "status_code": 400, "message":
'[400]: {"error":{"message":"This model does not support tool calls.","code":"tool_choice_unsupported"}}'}
out = feed(flat, hedef="m", aracsiz=seen.append)
self.assertEqual(out[0]["type"], "response.failed")
self.assertIn("araç çağrısını desteklemiyor", out[0]["response"]["error"]["message"])
self.assertEqual(seen, ["m"])
home = tempfile.mkdtemp()
self.assertTrue(pencere.ogren_aracsiz(home, "m"))
self.assertFalse(pencere.ogren_aracsiz(home, "m"))
self.assertFalse(pencere.coz("m", "model", "cc/claude-opus-5-5", aracsiz=pencere.aracsizlar(home))["arac"])
self.assertTrue(pencere.coz("n", "model", "cc/claude-opus-5-5", aracsiz=pencere.aracsizlar(home))["arac"])
def test_flat_overflow_error_is_translated_and_learned(self):
seen = []
flat = {"type": "error", "code": "bad_request", "message":
"Your prompt exceeds the model's context length. Max context tokens: 65536."}
out = feed(flat, hedef="m", tasma=lambda hedef, metin: seen.append(pencere.sinir_oku(metin)))
self.assertEqual(out[0]["response"]["error"]["code"], "context_length_exceeded")
self.assertEqual(seen, [65536])
self.assertEqual(feed({"type": "error", "code": "server_error", "message": "upstream 503"})[0]["type"], "error")
def test_guard_never_trims_instruction_messages(self):
big = "KURAL " * 40000
req = {"input": [
{"type": "message", "role": "developer", "content": [{"type": "input_text", "text": big}]},
{"type": "message", "role": "user", "content": [{"type": "input_text", "text": "eski " * 40000}]},
{"type": "message", "role": "user", "content": [{"type": "input_text", "text": "soru"}]}]}
pencere.sigdir(req, 65536)
self.assertEqual(req["input"][0]["content"][0]["text"], big)
self.assertIn("çıkarıldı (köprü)", req["input"][1]["content"][0]["text"])
class Nokta(unittest.TestCase):
def user(self, content):
return {"type": "message", "role": "user", "content": content}
def test_only_a_lone_dot_from_the_user_is_answered_locally(self):
is_dot = env["nokta_mesaji_mi"]
self.assertTrue(is_dot({"input": [self.user([{"type": "input_text", "text": " . "}])]}))
self.assertTrue(is_dot({"input": [self.user("x"), self.user(".")]}))
for other in ("..", "?", "Selam", "", "1."):
self.assertFalse(is_dot({"input": [self.user([{"type": "input_text", "text": other}])]}), other)
self.assertFalse(is_dot({"input": [self.user("."), {"type": "function_call_output", "call_id": "c", "output": "x"}]}))
self.assertFalse(is_dot({"input": [self.user([{"type": "input_text", "text": "."}, {"type": "input_image", "image_url": "x"}])]}))
self.assertFalse(is_dot({"input": [{"type": "message", "role": "assistant", "content": "."}]}))
self.assertFalse(is_dot({"input": []}))
def test_local_answer_is_a_complete_response_with_a_final_answer(self):
raw = env["hazir_yaniti"]("ide/x", "cc/opus-5-5 hazır.").decode()
events = [json.loads(line[6:]) for line in raw.splitlines() if line.startswith("data: ")]
self.assertEqual([e["type"] for e in events], ["response.created", "response.output_item.added",
"response.output_text.delta", "response.output_item.done", "response.completed"])
done = events[-1]["response"]
self.assertEqual(done["status"], "completed")
self.assertEqual(done["output"][0]["phase"], "final_answer")
self.assertEqual(done["output"][0]["content"][0]["text"], "cc/opus-5-5 hazır.")
self.assertEqual(done["usage"]["total_tokens"], 0)
if __name__ == "__main__":
unittest.main()