Implement qwen4exp loading, tokenizer and chat formatting, PLE sidecars,
Metal text and vision graphs, built-in MTP, and recurrent KV persistence.
Integrate the CLI, agent, server, download targets, and conversion tools.
Preserve the native Q4_1 encoder, Q4_K accumulation guard, and shared
quantizer build target. Keep exact-MTP rewind and vision-cache row-width
fixes. Persist valid logits and recurrent state at completed prefill chunks,
and reuse Qwen text-answer history when tools clients omit reasoning.
Retain exact reasoning replay and test continued checkpoints, cancellation,
cache eviction, and restart reuse with and without reasoning_content. Include
reproducible charts and measurements comparing throughput before and after
the checkpoint fixes on M3 Ultra.
Add Qwen trunk steering and prompt activation capture, including GDN layers.
Keep the MTP predictor outside the 48-row bank and preserve prompt dumps
through one-token prefill tails and multi-row speculative verification.
Recover Chrome target creation and retain its last page target. Preserve
full agent transcripts in stripped-session format when KV no longer fits,
while retaining the newer automatic compaction and continuation logic.
Add steering/MTP/capture, Chrome CDP recovery, and full-session save/reload
regressions. Adapt the intended changes from fork PRs #13 and #7.
Reconcile with antirez main bd66c40, preserving DeepSeek v4.1 model IDs,
tool syntax, session state, and Metal kernel dispatch. Exclude superseded
engine code and prototypes.
Co-authored-by: Andreas Parusel <aparuael@7170c824-6152-4cf1-985e-9503832ce673.fritz.box>
Co-authored-by: david <contact@davidberard.fr>
Co-authored-by: Michael Kuebbeler <cropduster@users.noreply.github.com>
Co-authored-by: Ogilthorp3 <bertrand@nepveu.name>
Co-authored-by: anemll <realanemll@gmail.com>
86 lines
3.4 KiB
Python
86 lines
3.4 KiB
Python
"""Local CDP fixture: last-tab retention, HTTP recovery, and failure reporting."""
|
|
import base64
|
|
import hashlib
|
|
import http.server
|
|
import json
|
|
import pathlib
|
|
import struct
|
|
import subprocess
|
|
import sys
|
|
import threading
|
|
|
|
|
|
def main():
|
|
state = {"creates": 0, "puts": 0, "lists": 0, "closes": []}
|
|
|
|
class Handler(http.server.BaseHTTPRequestHandler):
|
|
def log_message(self, *args):
|
|
pass
|
|
|
|
def reply(self, data):
|
|
body = json.dumps(data).encode()
|
|
self.send_response(200)
|
|
self.send_header("Content-Length", str(len(body)))
|
|
self.end_headers()
|
|
self.wfile.write(body)
|
|
|
|
def do_GET(self):
|
|
if self.path == "/json/version":
|
|
self.reply({"webSocketDebuggerUrl": f"ws://127.0.0.1:{self.server.server_port}/browser"})
|
|
elif self.path == "/json/list":
|
|
state["lists"] += 1
|
|
self.reply([{"type": "page"}] * state["lists"] + [{"type": "service_worker"}])
|
|
elif self.path.startswith("/json/close/"):
|
|
state["closes"].append(self.path)
|
|
self.reply({})
|
|
elif self.path == "/browser":
|
|
key = self.headers["Sec-WebSocket-Key"] + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
|
|
self.send_response(101)
|
|
self.send_header("Upgrade", "websocket")
|
|
self.send_header("Connection", "Upgrade")
|
|
self.send_header("Sec-WebSocket-Accept", base64.b64encode(hashlib.sha1(key.encode()).digest()).decode())
|
|
self.end_headers()
|
|
header = self.rfile.read(2)
|
|
length = header[1] & 127
|
|
if length == 126:
|
|
length = struct.unpack("!H", self.rfile.read(2))[0]
|
|
elif length == 127:
|
|
length = struct.unpack("!Q", self.rfile.read(8))[0]
|
|
mask = self.rfile.read(4)
|
|
payload = self.rfile.read(length)
|
|
request = json.loads(bytes(v ^ mask[i % 4] for i, v in enumerate(payload)))
|
|
assert request["method"] == "Target.createTarget", request
|
|
state["creates"] += 1
|
|
response = {"id": request["id"]}
|
|
if state["creates"] == 2:
|
|
response["result"] = {"targetId": "cdp-target"}
|
|
else:
|
|
response["error"] = {"code": -32000, "message": "No browser window"}
|
|
data = json.dumps(response).encode()
|
|
assert len(data) < 126
|
|
self.wfile.write(bytes([0x81, len(data)]) + data)
|
|
self.wfile.flush()
|
|
else:
|
|
self.send_error(404)
|
|
|
|
def do_PUT(self):
|
|
assert self.path == "/json/new?about%3Ablank", self.path
|
|
state["puts"] += 1
|
|
self.reply({"id": "http-target"} if state["puts"] == 1 else {})
|
|
|
|
server = http.server.ThreadingHTTPServer(("127.0.0.1", 0), Handler)
|
|
thread = threading.Thread(target=server.serve_forever, daemon=True)
|
|
thread.start()
|
|
try:
|
|
binary = pathlib.Path(sys.argv[1]).resolve()
|
|
subprocess.run([str(binary), str(server.server_port)], check=True, timeout=30)
|
|
assert state == {"creates": 3, "puts": 2, "lists": 2, "closes": ["/json/close/cdp-target"]}, state
|
|
finally:
|
|
server.shutdown()
|
|
server.server_close()
|
|
thread.join()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|