llama.cpp on a jailbroken PS5: run any GGUF model natively on the console, starting with Qwen 3.8
Codex on Qwen (#55), sliding-window models get their full context (#57) (#58)
Mert Cobanov707768548dae
diff --git a/.github/workflows/fleet-host.yml b/.github/workflows/fleet-host.ymlindex b4b41bc..a8897b7 100644--- a/.github/workflows/fleet-host.yml+++ b/.github/workflows/fleet-host.yml@@ -8,6 +8,7 @@ on:- 'ps5/app/fleet_worker*'- 'tests/fleet*'- 'tests/test_fleet_*'+ - 'tests/server_*'- 'tests/make_fleet_fixture.py'- 'tests/requirements-fleet.txt'- 'scripts/build-fleet-host.sh'@@ -23,6 +24,7 @@ on:- 'ps5/app/fleet_worker*'- 'tests/fleet*'- 'tests/test_fleet_*'+ - 'tests/server_*'- 'tests/make_fleet_fixture.py'- 'tests/requirements-fleet.txt'- 'scripts/build-fleet-host.sh'diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 93b1f68..7bafd0b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -44,6 +44,12 @@ v0.1.x are the upstream payload releases by cobanov.- The TV's request feed shows OpenAI Responses requests (`/v1/responses`, what codex sends): thequestion from `input`, the answer from the response or its `output_text` deltas. They showedblank before. The API page lists the endpoint, and docs/CLI.md says what it takes.+- **A PC's GPU as a fleet worker.** `PS5LM_FLEET_GPU=metal` (or `cuda`, `vulkan`)+ `scripts/build-fleet-host.sh` adds that backend, so `ggml-rpc-server -d MTL0` serves the PC's+ GPU next to the consoles. The default host build stays CPU only.+- `scripts/ps5lm-app.sh launch` works again, with PS5LM's own launcher payload+ (`ps5/app/launch_app.c`, built by `build-app.sh`) instead of the removed+ ps5-homebrew-dev-protocol.### Changed- **The fleet worker is part of the app.** There is no separate fleet build or@@ -80,14 +86,6 @@ v0.1.x are the upstream payload releases by cobanov.- Every line the app writes to `app.log` starts with the console's local time, as`22:56:01 ps5lm-app: start` (#40). Lines from the graphics stack keep their own form.-### Added-- **A PC's GPU as a fleet worker.** `PS5LM_FLEET_GPU=metal` (or `cuda`, `vulkan`)- `scripts/build-fleet-host.sh` adds that backend, so `ggml-rpc-server -d MTL0` serves the PC's- GPU next to the consoles. The default host build stays CPU only.-- `scripts/ps5lm-app.sh launch` works again, with PS5LM's own launcher payload- (`ps5/app/launch_app.c`, built by `build-app.sh`) instead of the removed- ps5-homebrew-dev-protocol.-### Fixed- A download that meets a full drive anyway stops at once, "Failed: App storage is full", insteadof retrying twenty times.@@ -95,6 +93,17 @@ v0.1.x are the upstream payload releases by cobanov.takes, so it looked hung (#30). It now says "Checking the SHA-256, 45%". The queue is savedbefore the check, so a restart during it checks the file again but no longer fetches the lastpiece first.+- codex failed on Qwen models with "System message must be at the beginning" (#55): it sends two+ developer messages after its instructions, and Qwen's template refuses a system message that is+ not first. `patches/0004` folded such messages into the first one only for the Anthropic API+ (Claude Code); it now does so for Chat Completions, Responses and Anthropic alike, with+ `tests/server_system_messages_test.py` checking all three on a host build. docs/CLI.md's codex+ setup is the one codex 0.166 reads: the profile in its own `~/.codex/ps5.config.toml`.+- Models with sliding-window attention got far less context than fits (#57): the planner counted+ every attention layer at full length. It now reads `<arch>.attention.sliding_window_pattern` and+ counts the window layers at their window, as llama.cpp keeps them. Spark-X2.6 4B (27 of 36 layers+ keep 512 tokens) plans 256k with a q8_0 cache instead of 128k with q4_0. **Longest context** in+ Settings goes to 192k and 256k, and the planner tries both.## [0.10.0] - 2026-11-01diff --git a/docs/CLI.md b/docs/CLI.mdindex dfc74f9..64b1f42 100644--- a/docs/CLI.md+++ b/docs/CLI.md@@ -58,13 +58,26 @@ minutes before anything reaches the console.name = "PS5LM"base_url = "http://192.168.1.19:8081/v1"wire_api = "responses"+```++`~/.codex/ps5.config.toml`, the profile:-[profiles.ps5]+```tomlmodel_provider = "ps5lm"model = "ps5"```-Then `codex -p ps5`.+Then `codex -p ps5`. Codex 0.166 reads a profile from its own `<name>.config.toml` and refuses to+start while `config.toml` still has an old `[profiles.ps5]` table.++Codex sends two developer messages after its instructions. Qwen's chat template refuses a system+message that is not first ("System message must be at the beginning"), so the app's llama-server+folds them into the first one (`patches/0004`).++If codex gets `404 Not Found` from the console while macOS has a system HTTP proxy (spoofdpi and+similar tools set one), codex is sending through that proxy even for addresses on its exception+list, and the proxy forwards the request in a form llama-server does not route. Start codex with+`NO_PROXY=192.168.1.19` (the console's address).### The Responses API@@ -94,8 +107,8 @@ CLAUDE_CODE_MAX_CONTEXT_TOKENS=65536 claudeSet `CLAUDE_CODE_MAX_CONTEXT_TOKENS` to the context the dashboard shows:Claude Code does not know the model and otherwise assumes 200k. It sends somesystem messages in the middle of a conversation, which Qwen's chat template-refuses ("System message must be at the beginning"); the app's llama-server-folds them into the first one (`patches/0004`).+refuses; the app's llama-server folds them into the first one (`patches/0004`),+on every endpoint.## aiderdiff --git a/patches/0004-anthropic-system-messages.patch b/patches/0004-anthropic-system-messages.patchdeleted file mode 100644index 8ff5f6b..0000000--- a/patches/0004-anthropic-system-messages.patch+++ /dev/null@@ -1,48 +0,0 @@-PS5LM: fold system messages that are not first (Claude Code sends some) into the leading one, so templates like Qwen's accept the Anthropic API.--diff --git a/tools/server/server-chat.cpp b/tools/server/server-chat.cpp-index a3a4ea152..0dd4b6c33 100644---- a/tools/server/server-chat.cpp-+++ b/tools/server/server-chat.cpp-@@ -543,6 +543,41 @@ json server_chat_convert_anthropic_to_oai(const json & body) {- }- }--+ // PS5LM: some clients (Claude Code) send system messages inside-+ // `messages`; templates such as Qwen's refuse a system message that is not-+ // first. Fold every later one into the leading system message.-+ {-+ json merged = json::array();-+ std::string extra;-+ for (const auto & m : oai_messages) {-+ const std::string r = json_value(m, "role", std::string());-+ if ((r == "system" || r == "developer") && !merged.empty()) {-+ const json & c = m.contains("content") ? m.at("content") : json();-+ if (c.is_string()) {-+ extra += "\n\n" + c.get<std::string>();-+ } else if (c.is_array()) {-+ for (const auto & part : c) {-+ extra += "\n\n" + json_value(part, "text", std::string());-+ }-+ }-+ continue;-+ }-+ merged.push_back(m);-+ }-+ if (!extra.empty()) {-+ if (!merged.empty() && json_value(merged[0], "role", std::string()) == "system" && merged[0].at("content").is_string()) {-+ merged[0]["content"] = merged[0].at("content").get<std::string>() + extra;-+ } else {-+ json front = json::array();-+ front.push_back({ { "role", "system" }, { "content", extra.substr(2) } });-+ for (auto & m : merged) {-+ front.push_back(std::move(m));-+ }-+ merged = std::move(front);-+ }-+ }-+ oai_messages = std::move(merged);-+ }- oai_body["messages"] = oai_messages;-- // Convert toolsdiff --git a/patches/0004-fold-late-system-messages.patch b/patches/0004-fold-late-system-messages.patchnew file mode 100644index 0000000..4c2986f--- /dev/null+++ b/patches/0004-fold-late-system-messages.patch@@ -0,0 +1,61 @@+PS5LM: fold every system or developer message that is not first into the leading one (Codex and Claude Code send them), so templates like Qwen's accept the Chat Completions, Responses and Anthropic APIs.++diff --git a/tools/server/server-common.cpp b/tools/server/server-common.cpp+index 4f1acba1a..76058afd7 100644+--- a/tools/server/server-common.cpp++++ b/tools/server/server-common.cpp+@@ -1405,6 +1405,54 @@ json oaicompat_chat_params_parse(+ if (!messages.is_array()) {+ throw std::invalid_argument("Expected 'messages' to be an array");+ }++++ // PS5LM: templates such as Qwen's refuse a system message that is not++ // first, and clients send them: Codex puts developer messages after its++ // instructions, Claude Code puts system messages inside `messages`. Fold++ // every later system or developer message into the leading one, for the++ // Chat Completions, Responses and Anthropic endpoints alike.++ {++ const auto is_system = [](const json & m) {++ const std::string r = json_value(m, "role", std::string());++ return r == "system" || r == "developer";++ };++ json kept = json::array();++ std::string extra;++ for (auto & m : messages) {++ if (!kept.empty() && is_system(m)) {++ const json c = m.contains("content") ? m.at("content") : json();++ if (c.is_string()) {++ extra += "\n\n" + c.get<std::string>();++ } else if (c.is_array()) {++ for (const auto & part : c) {++ if (part.contains("text")) {++ extra += "\n\n" + json_value(part, "text", std::string());++ }++ }++ }++ continue;++ }++ kept.push_back(std::move(m));++ }++ if (!extra.empty()) {++ if (is_system(kept[0])) {++ json & c = kept[0]["content"];++ if (c.is_array()) {++ c.push_back({ { "type", "text" }, { "text", extra } });++ } else {++ c = c.is_string() ? c.get<std::string>() + extra : extra.substr(2);++ }++ } else {++ json front = json::array();++ front.push_back({ { "role", "system" }, { "content", extra.substr(2) } });++ for (auto & m : kept) {++ front.push_back(std::move(m));++ }++ kept = std::move(front);++ }++ }++ messages = std::move(kept);++ }+ for (auto & msg : messages) {+ std::string role = json_value(msg, "role", std::string());+ if (role != "assistant" && !msg.contains("content")) {diff --git a/ps5/app/dashboard.cpp b/ps5/app/dashboard.cppindex 83af23d..3c68aa8 100644--- a/ps5/app/dashboard.cpp+++ b/ps5/app/dashboard.cpp@@ -126,7 +126,7 @@ constexpr SettingCategory kCategories[] = {constexpr int kCategoryCount = 7;constexpr int kDiagnostics = 6;-constexpr uint32_t kCtxSteps[] = { 4096, 8192, 16384, 32768, 65536, 131072 };+constexpr uint32_t kCtxSteps[] = { 4096, 8192, 16384, 32768, 65536, 131072, 196608, 262144 };constexpr const char * kKvSteps[] = { "auto", "f16", "q8_0", "q4_0" };constexpr uint32_t kScratchSteps[] = { 1, 2, 5, 10, 20 };diff --git a/ps5/app/model_plan.cpp b/ps5/app/model_plan.cppindex e748ea4..c00522d 100644--- a/ps5/app/model_plan.cpp+++ b/ps5/app/model_plan.cpp@@ -170,6 +170,7 @@ ModelInfo parse_model_info(Reader r, const std::string & path, uint64_t file_bytconst uint64_t n_kv = r.get<uint64_t>();std::map<std::string, uint64_t> ints; // every scalar, and the largest element of numeric arrays+ std::map<std::string, uint64_t> sums; // numeric arrays: the sum of their elementsstd::map<std::string, std::string> strs;for (uint64_t i = 0; i < n_kv && !r.bad; i++) {const std::string key = r.str();@@ -184,11 +185,14 @@ ModelInfo parse_model_info(Reader r, const std::string & path, uint64_t file_bytr.skip(r.get<uint64_t>());}} else if (n <= 4096) { // per-layer values, such as head_count_kv- uint64_t mx = 0;+ uint64_t mx = 0, sum = 0;for (uint64_t j = 0; j < n; j++) {- mx = std::max(mx, read_int(r, et));+ const uint64_t v = read_int(r, et);+ mx = std::max(mx, v);+ sum += v;}ints[key] = mx;+ sums[key] = sum;} else {r.skip(n * scalar_size(et)); // vocabularies and the like}@@ -240,6 +244,14 @@ ModelInfo parse_model_info(Reader r, const std::string & path, uint64_t file_bytm.value_length = (uint32_t) num("attention.value_length", head_dim);m.full_attn_every = (uint32_t) std::max<uint64_t>(1, num("full_attention_interval", 1));m.n_ctx_train = (uint32_t) num("context_length");+ // Sliding-window attention with its layers listed (true: a window layer),+ // as llama.cpp reads it. A pattern only in llama.cpp's code (Gemma) or a+ // single number is counted as full attention, which over-reserves.+ const auto pattern = sums.find(a + "attention.sliding_window_pattern");+ if (pattern != sums.end() && num("attention.sliding_window")) {+ m.n_swa_layers = (uint32_t) std::min<uint64_t>(pattern->second, m.n_kv_layers());+ m.swa_window = (uint32_t) num("attention.sliding_window");+ }m.n_expert = (uint32_t) num("expert_count");// Recurrent layers (Gated DeltaNet, Mamba): a fixed f32 state each,@@ -278,9 +290,17 @@ ModelInfo read_model_header(const std::string & name, const std::string & head,return parse_model_info(r, name, file_bytes);}-double kv_bytes_per_token(const ModelInfo & m, const std::string & type) {+namespace {++double kv_bytes_per_layer_token(const ModelInfo & m, const std::string & type) {const double per_elem = type == "f16" ? 2.0 : type == "q8_0" ? 34.0 / 32 : 18.0 / 32; // q4_0- return (double) m.n_kv_layers() * m.n_head_kv * (m.key_length + m.value_length) * per_elem;+ return (double) m.n_head_kv * (m.key_length + m.value_length) * per_elem;+}++} // namespace++double kv_bytes_per_token(const ModelInfo & m, const std::string & type) {+ return (m.n_kv_layers() - m.n_swa_layers) * kv_bytes_per_layer_token(m, type);}// Sampling as each model's authors recommend it. Settings the planner works@@ -361,7 +381,7 @@ Plan plan_model(const ModelInfo & m, double budget_gib, uint32_t ctx_cap, constp.reserve_gib = 0.75 + p.state_gib + (m.mmproj.empty() ? 0.0 : 0.25) + (wide ? 0.5 : 0.0) + ub_extra;// The longest context first, and at each length the best cache that fits.- static const uint32_t ctxs[] = { 131072, 65536, 32768, 16384, 8192, 4096 };+ static const uint32_t ctxs[] = { 262144, 196608, 131072, 65536, 32768, 16384, 8192, 4096 };static const char * types[] = { "f16", "q8_0", "q4_0" };for (uint32_t ctx : ctxs) {if (ctx > ctx_cap) {@@ -375,7 +395,11 @@ Plan plan_model(const ModelInfo & m, double budget_gib, uint32_t ctx_cap, constif (!kv_force && std::strcmp(t, "f16") == 0 && ctx > 8192) {continue;}- const double kv = kv_bytes_per_token(m, t) * ctx / kGiB;+ // Window layers hold the window and one ubatch, padded to 256,+ // whatever the context (llama.cpp's iSWA cache without --swa-full).+ const uint32_t swa_tokens = std::min(ctx, (m.swa_window + p.ubatch + 255) / 256 * 256);+ const double kv = (kv_bytes_per_token(m, t) * ctx ++ m.n_swa_layers * kv_bytes_per_layer_token(m, t) * swa_tokens) / kGiB;const double total = p.weights_gib + kv + p.state_gib + p.reserve_gib;if (total <= budget_gib) {p.fits = true;diff --git a/ps5/app/model_plan.hpp b/ps5/app/model_plan.hppindex 2656a6a..5b2bf8a 100644--- a/ps5/app/model_plan.hpp+++ b/ps5/app/model_plan.hpp@@ -29,6 +29,8 @@ struct ModelInfo {uint32_t key_length = 0; // per KV headuint32_t value_length = 0;uint32_t full_attn_every = 1; // 1: every layer is attention+ uint32_t n_swa_layers = 0; // attention layers that keep only a sliding window+ uint32_t swa_window = 0; // that window, in tokensuint32_t n_ctx_train = 0;uint32_t n_expert = 0; // 0: denseuint64_t state_bytes = 0; // recurrent state, all layers (f32)@@ -51,7 +53,8 @@ std::string find_mmproj(const std::string & model_path);ModelInfo read_model_info(const std::string & path);-// Bytes of KV cache per token of context, for a cache type ("f16", "q8_0", "q4_0").+// Bytes of KV cache per token of context, for a cache type ("f16", "q8_0", "q4_0"):+// the full-attention layers. Sliding-window layers add a fixed amount (plan_model).double kv_bytes_per_token(const ModelInfo & m, const std::string & type);struct Preset {diff --git a/ps5/app/model_plan_test.cpp b/ps5/app/model_plan_test.cppindex 8bfcbea..6a91215 100644--- a/ps5/app/model_plan_test.cpp+++ b/ps5/app/model_plan_test.cpp@@ -12,6 +12,7 @@#include <cstdint>#include <cstdio>#include <string>+#include <vector>namespace {@@ -23,6 +24,14 @@ struct Gguf {static std::string str(const std::string & v) { return raw<uint64_t>(v.size()) + v; }Gguf & kv(const std::string & k, const std::string & v) { kvs += str(k) + raw<uint32_t>(8) + str(v); n++; return *this; }Gguf & kv(const std::string & k, uint32_t v) { kvs += str(k) + raw<uint32_t>(4) + raw(v); n++; return *this; }+ Gguf & kv(const std::string & k, const std::vector<bool> & v) { // a bool array+ kvs += str(k) + raw<uint32_t>(9) + raw<uint32_t>(7) + raw<uint64_t>(v.size());+ for (bool b : v) {+ kvs += (char) b;+ }+ n++;+ return *this;+ }// magic, version 3, tensor count, metadata count, metadatastd::string bytes() const { return "GGUF" + raw<uint32_t>(3) + raw<uint64_t>(0) + raw(n) + kvs; }};@@ -92,6 +101,28 @@ int main(int argc, char ** argv) {const ps5lm::ModelInfo pt = ps5lm::read_model_header("Ternary-Bonsai-2-27B-PTQ1_0.gguf", bonsai(143), 5946648928ull);assert(!pt.ok && pt.error.find("PTQ1_0") != std::string::npos);+ // Sliding-window attention (#57): Spark-X2.6 4B's header. 27 of its 36+ // layers keep a 512-token window, so 256k fits; counted as full attention+ // it stopped at 128k.+ std::vector<bool> swa;+ for (int i = 0; i < 36; i++) {+ swa.push_back(i % 4 != 3);+ }+ Gguf spark;+ spark.kv("general.architecture", "spark2_5").kv("spark2_5.block_count", 36u)+ .kv("spark2_5.attention.head_count", 16u).kv("spark2_5.attention.head_count_kv", 4u)+ .kv("spark2_5.embedding_length", 2560u).kv("spark2_5.attention.key_length", 256u)+ .kv("spark2_5.attention.value_length", 256u).kv("spark2_5.context_length", 1048576u)+ .kv("spark2_5.attention.sliding_window", 512u).kv("spark2_5.attention.sliding_window_pattern", swa);+ const ps5lm::ModelInfo s = ps5lm::read_model_header("Spark-X2.6-4B-Q8_0.gguf", spark.bytes(), 4375021824ull);+ assert(s.ok && s.n_swa_layers == 27 && s.swa_window == 512);+ assert(kv_bytes_per_token(s, "q8_0") == 9 * 4 * 512 * 34.0 / 32);+ const ps5lm::Plan sp = ps5lm::plan_model(s, budget, 262144);+ assert(sp.fits && sp.ctx == 262144 && sp.kv_type == "q8_0");+ ps5lm::ModelInfo full = s;+ full.n_swa_layers = 0;+ assert(ps5lm::plan_model(full, budget, 262144).ctx == 131072);+if (argc < 2) {std::puts("model_plan_test: ok (synthetic only)");return 0;diff --git a/scripts/test-fleet.sh b/scripts/test-fleet.shindex 5e091e3..4a58035 100755--- a/scripts/test-fleet.sh+++ b/scripts/test-fleet.sh@@ -26,6 +26,7 @@ if [[ ${1:-} == --rpc ]]; then"$(dirname "$(command -v "${CMAKE:-cmake}")")/ctest" --test-dir "$out" -R '^test-rpc-multi-server$'python3 tests/fleet_rpc_no_comm_test.py --binary "$out/bin/ggml-rpc-server"python3 tests/fleet_rpc_smoke.py --build "$out"+ python3 tests/server_system_messages_test.py --build "$out"elif [[ $# != 0 ]]; thenecho 'usage: scripts/test-fleet.sh [--rpc]' >&2exit 2diff --git a/tests/server_system_messages_test.py b/tests/server_system_messages_test.pynew file mode 100644index 0000000..2a51f52--- /dev/null+++ b/tests/server_system_messages_test.py@@ -0,0 +1,96 @@+#!/usr/bin/env python3+"""patches/0004 on a host llama-server: system and developer messages after the+first one reach a template that refuses them (Qwen's rule), on every endpoint.++Run after scripts/build-fleet-host.sh. The model is the untrained fixture, so+only the rendered prompt and the HTTP status are checked, not the words.+"""+from contextlib import ExitStack+from pathlib import Path+import argparse+import json+import os+import urllib.error+import urllib.request++from fleet_rpc_smoke import free_ports, spawn, wait_ready+from make_fleet_fixture import ROOT, make_fixture++# Qwen's rule, cut down: a system message anywhere but first is an error.+TEMPLATE = (+ "{%- for m in messages -%}"+ "{%- if m.role == 'system' and not loop.first -%}"+ "{{- raise_exception('System message must be at the beginning.') -}}"+ "{%- endif -%}"+ "<{{ m.role }}>{{ m.content }}"+ "{%- endfor -%}"+ "{%- if add_generation_prompt -%}<assistant>{%- endif -%}"+)+++def post(port, path, body):+ request = urllib.request.Request(f"http://127.0.0.1:{port}{path}", data=json.dumps(body).encode(),+ headers={"Content-Type": "application/json"})+ try:+ with urllib.request.urlopen(request, timeout=60) as response:+ return response.status, json.load(response)+ except urllib.error.HTTPError as error:+ return error.code, error.read().decode(errors="replace")+++def run(build, output):+ output.mkdir(parents=True, exist_ok=True)+ fixture = make_fixture(output / "tiny-llama.gguf")+ template = output / "system-first.jinja"+ template.write_text(TEMPLATE)+ server = build / "bin/llama-server"+ if not server.is_file():+ raise FileNotFoundError(f"{server}; first run scripts/build-fleet-host.sh")+ (port,) = free_ports(1)+ command = [str(server), "--model", str(fixture), "--host", "127.0.0.1", "--port", str(port),+ "--ctx-size", "256", "--parallel", "1", "--threads", "2", "--device", "none",+ "--gpu-layers", "0", "--fit", "off", "--no-warmup", "--jinja",+ "--chat-template-file", str(template)]+ with ExitStack() as stack:+ process = spawn(stack, command, output / "server.log", dict(os.environ))+ wait_ready(process, port, http=True)++ # The order and the joins, on the rendered prompt.+ status, body = post(port, "/apply-template", {"messages": [+ {"role": "system", "content": "a"}, {"role": "user", "content": "b"},+ {"role": "system", "content": "c"}, {"role": "developer", "content": "d"}]})+ assert status == 200, body+ assert body["prompt"] == "<system>a\n\nc\n\nd<user>b<assistant>", body["prompt"]++ # No leading system message: the late ones become one in front.+ status, body = post(port, "/apply-template", {"messages": [+ {"role": "user", "content": "b"}, {"role": "system", "content": "c"}]})+ assert status == 200, body+ assert body["prompt"] == "<system>c<user>b<assistant>", body["prompt"]++ cases = {+ "/v1/chat/completions": {"max_tokens": 1, "messages": [+ {"role": "system", "content": "a"}, {"role": "user", "content": "b"},+ {"role": "system", "content": "c"}]},+ # What codex sends (#55): instructions, then two developer messages.+ "/v1/responses": {"max_output_tokens": 1, "instructions": "a", "input": [+ {"type": "message", "role": "developer", "content": [{"type": "input_text", "text": "c"}]},+ {"type": "message", "role": "developer", "content": [{"type": "input_text", "text": "d"}]},+ {"type": "message", "role": "user", "content": [{"type": "input_text", "text": "b"}]}]},+ # What Claude Code sends: a system message inside `messages`.+ "/v1/messages": {"max_tokens": 1, "system": "a", "messages": [+ {"role": "user", "content": "b"}, {"role": "system", "content": "c"},+ {"role": "user", "content": "e"}]},+ }+ for path, request in cases.items():+ status, body = post(port, path, request)+ assert status == 200, f"{path}: {status} {body}"+ print("server system messages: folded into the first on chat, responses and messages")+++if __name__ == "__main__":+ parser = argparse.ArgumentParser(description=__doc__)+ parser.add_argument("--build", type=Path, default=ROOT / "build/fleet-host")+ parser.add_argument("--output", type=Path, default=ROOT / "build/server-system-messages")+ args = parser.parse_args()+ run(args.build.resolve(), args.output.resolve())