Commit 87e18fce authored by Jan Koester's avatar Jan Koester
Browse files

better rules

parent 4b9c0576
Loading
Loading
Loading
Loading
+64 −4
Changes for editor/src/webedit_api.cpp: 64 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -3444,6 +3444,60 @@ void webedit::Api::handleAiSettings(libhttppp::HttpRequest &curreq) {
// Models without tool-calling support simply never emit tool_calls and the
// loop falls through to a plain single-turn text/HTML reply, same as before.

// Layout- und Mobil-Regeln fuer KI-erzeugte Seiten: eingebauter Agent
// (System-Prompt) und externe MCP-Clients (initialize -> instructions).
std::string webedit::aiLayoutGuidelines() {
    return
        "== PAGE WIDTH & RESPONSIVE LAYOUT (mandatory) ==\n"
        "Pages must use the available width -- a narrow column centered in a wide "
        "screen is a defect.\n"
        "- Sections span the full width (width:100%; background edge to edge). Put "
        "the content in an inner wrapper: width:100%; max-width:min(1400px, 100%); "
        "margin-inline:auto; padding-inline:clamp(16px, 4vw, 48px); box-sizing:border-box.\n"
        "- Never cap a whole page or section at small fixed widths (no max-width:600px/"
        "800px/960px on layout containers, no fixed px widths on columns). Only running "
        "text paragraphs may be limited for readability (max-width:75ch).\n"
        "- Multi-column content: display:grid; grid-template-columns:repeat(auto-fit, "
        "minmax(min(280px, 100%), 1fr)); gap:clamp(16px, 2.5vw, 32px). It reflows from "
        "4 columns on wide screens to 1 on phones without breakpoint hacks.\n"
        "- Fluid type: headings with clamp(), e.g. h1 font-size:clamp(2rem, 1.2rem + 3vw, "
        "3.5rem); body text at least 1rem.\n"
        "- Media: img, video {max-width:100%; height:auto; display:block}. Tables get a "
        "wrapper with overflow-x:auto. Nothing may cause horizontal page scrolling at "
        "360px width.\n"
        "- Write mobile-first: base styles for small screens, then @media (min-width: "
        "768px) and (min-width: 1200px) to widen. Check the layout mentally at 360px, "
        "768px, 1280px and 1920px.\n"
        "- Prefix every class you define with a short unique prefix so page CSS cannot "
        "collide with the theme.\n\n"

        "== FEEL NATIVE ON PHONES (mandatory for every interactive element) ==\n"
        "- Hover: put every :hover rule inside @media (hover: hover) and (pointer: fine) "
        "-- otherwise hover states stick after a tap on touch screens.\n"
        "- Press feedback: every button/link-styled control gets an :active state "
        "(e.g. transform:scale(0.97)) with transition 100-160ms ease-out, so it reacts "
        "when the finger lands, not when it lifts.\n"
        "- Controls (buttons, tabs, chips, links styled as buttons): touch-action:"
        "manipulation; user-select:none; -webkit-user-select:none; "
        "-webkit-tap-highlight-color:transparent. Never put user-select:none on "
        "running text -- users copy content.\n"
        "- Tap targets at least 44x44px; spacing between adjacent targets.\n"
        "- Heights: never 100vh. Use 100svh (min-height) for hero/first screens and "
        "100dvh for full-screen panels.\n"
        "- Inner scroll areas (horizontal card rows, long lists in a box): "
        "overscroll-behavior:contain. Horizontal sliders: native scroll with "
        "scroll-snap-type:x mandatory on the track and scroll-snap-align:start on the "
        "items; touch-action:pan-y if anything handles horizontal drags itself.\n"
        "- Fixed/sticky bars or floating buttons at the screen edge: pad with "
        "env(safe-area-inset-bottom, 0px) / env(safe-area-inset-top, 0px) so they clear "
        "the notch and home indicator.\n"
        "- Any input/select/textarea in CustomHtml: font-size at least 16px (smaller "
        "makes iOS zoom the page); set inputmode/type (tel, email, numeric) to get the "
        "right keyboard.\n"
        "- Never touch zoom (no user-scalable=no / maximum-scale) and never add "
        "<meta> tags -- viewport, theme-color and safe-area setup belong to the theme.\n";
}

namespace {

json_object *aiToolFunction(const char *name, const char *description, json_object *schema) {
@@ -3602,7 +3656,8 @@ std::string generateAiAgentSystemPrompt() {
        "--blogi-success-bg, --blogi-success-text, --blogi-nav-active, "
        "--blogi-nav-hover, --blogi-nav-border -- never hardcoded colors.\n"
        "- Use relative units (em, rem, %, vw, clamp()) and CSS Grid/Flexbox for "
        "layout; include @media rules for responsiveness (max-width: 768px and 480px).\n";
        "layout.\n\n"
        + webedit::aiLayoutGuidelines();
}

// Pulls the "data: <payload>" line out of one SSE event block (which may
@@ -3818,12 +3873,17 @@ void webedit::Api::handleAiPrompt(libhttppp::HttpRequest &curreq,
    }

    std::string fullPrompt = userPrompt;
    // Breite/Responsiv-Regeln stehen im System-Prompt; hier nur die Gewichtung.
    if (desktop && mobile) {
        fullPrompt += "\n(Note: Consider both Desktop and Mobile layout/responsiveness.)";
        fullPrompt += "\n(Note: The page must work equally well on desktop and phones -- use the full "
                      "page width on large screens and reflow to one column on phones, following the "
                      "PAGE WIDTH and FEEL NATIVE rules.)";
    } else if (desktop) {
        fullPrompt += "\n(Note: Optimize primarily for Desktop layout.)";
        fullPrompt += "\n(Note: Optimize primarily for desktop: use the full page width (wide container, "
                      "multi-column grids). It must still reflow cleanly on phones.)";
    } else if (mobile) {
        fullPrompt += "\n(Note: Optimize primarily for Mobile layout.)";
        fullPrompt += "\n(Note: Optimize primarily for phones: single column, large tap targets, "
                      "the FEEL NATIVE rules. It must still widen sensibly on desktop.)";
    }

    // Cheap hint so the model doesn't have to spend its first turn on a
+3 −0
Changes for editor/src/webedit_api.h: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -43,6 +43,9 @@
#include "webedit_session.h"

namespace webedit {
    // Regeln fuer Seitenbreite/Responsiv/Mobil, Teil aller KI-Prompts
    std::string aiLayoutGuidelines();


    // Thrown by Api::mcpXxx entry points on tool-execution failure; caught by
    // webedit::Mcp and translated into an MCP tool-result error (not a JSON-RPC
+5 −0
Changes for editor/src/webedit_mcp.cpp: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -262,6 +262,11 @@ json_object *webedit::Mcp::dispatch(json_object *rpcRequest, const std::string &
        json_object_object_add(result, "protocolVersion", json_object_new_string("2025-06-18"));
        json_object_object_add(result, "capabilities", caps);
        json_object_object_add(result, "serverInfo", serverInfo);
        // Externe KIs bekommen dieselben Layout-/Mobil-Regeln wie der
        // eingebaute Agent (gilt fuer import_html und CustomHtml).
        json_object_object_add(result, "instructions", json_object_new_string(
            ("When you create or change page content (import_html, CustomHtml, styles), follow these rules.\n\n"
             + aiLayoutGuidelines()).c_str()));
        return makeResult(idObj, result);
    }