Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
117 commits
Select commit Hold shift + click to select a range
7d6712e
Lab control folder: start/stop the selected program from scripts (#76)
dayfine Oct 30, 2026
b30fb26
Lab control folder: a README for the files and their protocol
dayfine Nov 1, 2026
bc834a8
Command File Runner: a developer program driven by text command files
dayfine Nov 1, 2026
557e5ec
Skills: the console-iteration dev loop, with the Command File Runner …
dayfine Nov 1, 2026
e280a48
Lab scripts: the console lock, Lab Control and Command File Runner fr…
dayfine Nov 1, 2026
8f2441d
Skills: make the console-iteration loop program-agnostic
dayfine Nov 1, 2026
21e2ce3
Command File Runner: expose its command table for the lab channel
dayfine Nov 1, 2026
bec4aee
Lab channel: one request folder per app, replacing the lab control fo…
dayfine Nov 1, 2026
00b35e8
Lab channel: select a program and set its options from a request
dayfine Nov 1, 2026
7483b96
Lab channel: the owner lock and keepawake
dayfine Nov 1, 2026
ac5ea4b
Lab channel: one README for the files, the commands and a worked run
dayfine Nov 1, 2026
7f99715
Merge remote-tracking branch 'origin/lab/tooling' into lab/tooling-ch…
dayfine Nov 1, 2026
7ea0326
Lab scripts: speak the lab channel
dayfine Nov 1, 2026
c004be6
Lab scripts README: the claim's journal line is line 2, after the own…
dayfine Nov 1, 2026
4151709
Command File Runner: std::format for log and error lines
dayfine Nov 1, 2026
842ef8b
Lab channel: drop LabControl.md
dayfine Nov 1, 2026
8459564
Lab channel: a refused start or stop is a journal error
dayfine Nov 1, 2026
9c150c1
Lab channel: "set" takes the JSON as written; '#' inside a string is …
dayfine Nov 1, 2026
9c4b56f
Lab channel: start from MainWindow only when Lab/ exists, as a pool task
dayfine Nov 1, 2026
e35c859
Lab commands: screen-only commands don't wait for the controller
dayfine Nov 1, 2026
566ede8
lablock.sh: a lock being written is not stale
dayfine Nov 1, 2026
c23466d
Skill: how to use it, and one step of any program
dayfine Nov 1, 2026
e275c27
Skills: make CFR verification explicit in the console iteration loop
dayfine Nov 1, 2026
94be4fd
Skills: scope console iteration examples to their game and task
dayfine Nov 1, 2026
5c26218
Lab channel: start the console's inference threads for each command
dayfine Nov 1, 2026
7f993e3
Merge origin/base/upstream-main into lab/tooling
dayfine Nov 1, 2026
315f4f8
Design: an MCP server for agents to run and develop programs over the…
dayfine Nov 1, 2026
bd2e96e
Design: agent integration as one lab CLI; MCP an optional thin wrappe…
dayfine Nov 1, 2026
ba405cf
Lab channel: popups lists the app's message boxes, popups close press…
dayfine Nov 1, 2026
6c5451a
Lab channel: popups compiles (QPushButton include)
dayfine Nov 1, 2026
e177edc
Merge origin/base/upstream-main into lab/tooling
dayfine Nov 2, 2026
035acb2
Merge origin/lab/tooling into design/agent-integration
dayfine Nov 2, 2026
2b3eac8
Lab: start waits for the controller; state shows controller=
dayfine Nov 2, 2026
0eba3a1
Merge lab/tooling into design/agent-integration
dayfine Nov 2, 2026
c75bfb1
Merge origin/base/upstream-main into lab/tooling
dayfine Nov 4, 2026
037924c
Merge origin/lab/tooling into design/agent-integration
dayfine Nov 4, 2026
1d428e6
Command File Runner: hold buttons with stick, walk and dpad
dayfine Nov 10, 2026
a2608d7
Merge pull request #317 from dayfine/lab/cfr-held-buttons
dayfine Nov 10, 2026
16baf42
Merge origin/base/upstream-main into lab/tooling
dayfine Nov 10, 2026
a023591
Merge origin/lab/tooling into design/agent-integration
dayfine Nov 10, 2026
aa5a927
FRLG: remove tests for navigation behavior (#1896)
theastrogoth Nov 12, 2026
4024a63
FRLG Egg RNG: accept lower advances for the held frame (#1897)
theastrogoth Nov 12, 2026
8958cda
Command-line test runner: filter tests by name substring (#1895)
pa-devbot Nov 12, 2026
213e996
Home simplify exit menu (#1873)
Dalton-V Nov 12, 2026
5220644
Home - StorageView (#1900)
Dalton-V Nov 12, 2026
d914382
Home - Box number reader (#1901)
Dalton-V Nov 12, 2026
14cf718
Recover the boss from the summary when header read is not a boss (#1894)
dayfine Nov 13, 2026
e5b3172
Support different game languages (#1904)
Dalton-V Nov 13, 2026
8d67694
Home - Detect Selection Hand (#1903)
Dalton-V Nov 13, 2026
72de561
Sockets: add a per-connection id to server socket sends (#1910)
pa-devbot Nov 13, 2026
73fecab
FRLG Box Sorter - BallReader (#1908)
Dalton-V Nov 13, 2026
39f94a9
FRLG SpriteReader fixes and tests (#1913)
theastrogoth Nov 13, 2026
02118eb
More FRLG Ball Reader Tests (#1914)
Dalton-V Nov 14, 2026
cf011f6
HttpServer: add a minimal Qt-free HTTP/1.1 server (#1879)
pa-devbot Nov 14, 2026
e961bf4
Start of PageView Detector (#1911)
Dalton-V Nov 14, 2026
db53d19
Design: MCP lab server shaped by the week's incidents
dayfine Nov 14, 2026
8cf5938
Expand agent integration design and rollout plan
dayfine Nov 14, 2026
7a2da8f
Design: fit the lab server to the existing locks, hooks and repo rules
dayfine Nov 14, 2026
9f5fdc7
Design: record the 2026-11-14 decisions (fork-only, declared precheck…
dayfine Nov 14, 2026
90509c9
Lab channel: write Lab/state.json for the lab server (#131 Slice 1)
dayfine Nov 14, 2026
629bfde
Lab channel: snapshot command for a frame newer than the call (#131 S…
dayfine Nov 14, 2026
5c32c74
Design: settle the open questions and the implementation review
dayfine Nov 14, 2026
c97618b
Merge pull request #131 from dayfine/design/agent-integration
dayfine Nov 14, 2026
ba5e19f
MgbaLink: connection and video source for mGBA (lab slice 1)
dayfine Nov 14, 2026
753eff4
MgbaLink: code health (case tables, namespace comments, header docs)
dayfine Nov 14, 2026
06d50dd
MgbaLink tests: split registration by table
dayfine Nov 14, 2026
3ee6891
Lab state: forget the last transition when the panel changes
dayfine Nov 14, 2026
bd6f9f7
MgbaLink: review fixes (clock, dead bridge, abort, single-use open)
dayfine Nov 14, 2026
d9bbbed
Merge pull request #481 from dayfine/lab/observation-seam
dayfine Nov 15, 2026
5087514
Agent-Integration: Slice 7b retires CFR
dayfine Nov 15, 2026
3fa53bf
Merge pull request #499 from dayfine/design/retire-cfr
dayfine Nov 15, 2026
a468cd0
Lab channel: document the inbox/outbox transport and its alternatives
dayfine Nov 15, 2026
1d3d6a9
MgbaLink: opt out of the no-video watchdog again; log a bad frame siz…
dayfine Nov 15, 2026
3409f94
Merge lab/tooling into lab/mgba-slice1
dayfine Nov 15, 2026
5101913
Merge pull request #493 from dayfine/lab/mgba-slice1
dayfine Nov 15, 2026
42ca61e
Merge pull request #501 from dayfine/lab-transport-alternatives
dayfine Nov 15, 2026
2af92d6
MgbaLink: key schedule, input log and Pro Controller key map (slice 2)
dayfine Nov 15, 2026
bc1c2aa
Lab: describe_program and game_open commands
dayfine Nov 15, 2026
72e4867
Lab contract: free keyed_options(), game_open verdict in its own file…
dayfine Nov 15, 2026
dc8c240
CommandFileRunner.h: drop a stray blank line
dayfine Nov 15, 2026
0d30871
MgbaLink: GRANT pacer and mGBA Pro Controller (slice 2b)
dayfine Nov 15, 2026
b5e83cc
Lab: close the Slice 1 gaps (shot worker, transition source, state.js…
dayfine Nov 15, 2026
90e18b8
Lab: code health (helper for the start record, transition filter besi…
dayfine Nov 15, 2026
c00b1af
Merge pull request #503 from dayfine/lab/mgba-slice2
dayfine Nov 15, 2026
392abf6
Merge remote-tracking branch 'origin/lab/tooling' into lab/slice4b
dayfine Nov 15, 2026
276a942
ProgramSession: one helper ends the run, so run_program() keeps its l…
dayfine Nov 15, 2026
624a14a
Merge remote-tracking branch 'origin/lab/tooling' into lab/mgba-slice2b
dayfine Nov 15, 2026
d87a8ac
MgbaLink: re-anchor the controller clock across LOAD and RESET
dayfine Nov 15, 2026
f1d8983
Merge pull request #504 from dayfine/lab/slice4b
dayfine Nov 15, 2026
d0a42b8
MgbaLink: build the descriptor and selector widget in SerialProgramsL…
dayfine Nov 15, 2026
140ca70
Merge branch 'lab/mgba-slice2b' into lab/mgba-reanchor
dayfine Nov 15, 2026
f6d01a5
MgbaLink tests: a later state ends at +14, not +15
dayfine Nov 15, 2026
7f6de24
Merge branch 'lab/mgba-slice2b' into lab/mgba-reanchor
dayfine Nov 15, 2026
0e5dbd2
Merge pull request #506 from dayfine/lab/mgba-slice2b
dayfine Nov 15, 2026
42e9c2d
Merge pull request #508 from dayfine/lab/mgba-reanchor
dayfine Nov 15, 2026
a5b451f
Merge pull request #507 from dayfine/lab/slice1-gaps
dayfine Nov 15, 2026
9ef885e
Lab channel: Slice 7b is option B, test the console command gate
dayfine Nov 15, 2026
19922bd
Merge pull request #509 from dayfine/lab/cfr-retire-b
dayfine Nov 15, 2026
b72cd77
Lab: describe_program lists the program's prechecks
dayfine Nov 15, 2026
a5f921c
Merge pull request #511 from dayfine/lab/slice-4
dayfine Nov 15, 2026
deff563
Lab: preflight runs a program's start checks without starting it
dayfine Nov 16, 2026
e707e71
Home Replace non calibrated tests (#1917)
Dalton-V Nov 16, 2026
d7bdd1c
Lab: ProgramSession::Prechecks holds the precheck list and the checks…
dayfine Nov 16, 2026
fe662b6
Lab: user hold - the lab channel refuses presses and starts while the…
dayfine Nov 16, 2026
266a1a0
Merge upstream #1913 into lab/tooling: FRLG WildEncounterReader test …
dayfine Nov 16, 2026
8ad0026
Merge lab/tooling into lab/app-preflight (upstream #1913: FRLG test f…
dayfine Nov 16, 2026
07aa01c
Merge lab/app-preflight into lab/user-hold (upstream #1913: FRLG test…
dayfine Nov 16, 2026
d3b3a1e
Merge upstream main into lab/tooling
dayfine Nov 16, 2026
6687fb4
Merge lab/tooling (upstream main) into lab/app-preflight
dayfine Nov 16, 2026
18777ad
Merge lab/app-preflight into lab/user-hold
dayfine Nov 16, 2026
9bc8e6a
Lab preflight: stage and restore options on the UI thread; keep a use…
dayfine Nov 16, 2026
77377b0
Merge remote-tracking branch 'origin/lab/app-preflight' into lab/user…
dayfine Nov 16, 2026
d5f26ae
Merge pull request #601 from dayfine/lab/app-preflight
dayfine Nov 16, 2026
958025a
Merge remote-tracking branch 'origin/lab/tooling' into lab/user-hold
dayfine Nov 16, 2026
f6146ba
Lab preflight: put the options back after a panel change, and reply
dayfine Nov 16, 2026
ee101da
Merge pull request #616 from dayfine/lab/mcp-followups
dayfine Nov 16, 2026
79519ac
Merge pull request #608 from dayfine/lab/user-hold
dayfine Nov 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
821 changes: 821 additions & 0 deletions Common/Cpp/HttpServer/HttpServer.cpp

Large diffs are not rendered by default.

169 changes: 169 additions & 0 deletions Common/Cpp/HttpServer/HttpServer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/* HTTP Server
*
* From: https://github.com/PokemonAutomation/
*
* The "AbstractServerSocket" implementation of "AbstractHttpServer": a
* minimal HTTP/1.1 server on the platform's default server socket, for a
* single local client that issues one request at a time. The request/
* response types, the handler contract, and the threading rules are in
* "AbstractHttpServer.h"; this file documents the implementation.
*
*/

#ifndef PokemonAutomation_HttpServer_H
#define PokemonAutomation_HttpServer_H

#include <atomic>
#include <cstddef>
#include <cstdint>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "Common/Cpp/Concurrency/AsyncTask.h"
#include "Common/Cpp/Concurrency/ConditionVariable.h"
#include "Common/Cpp/Concurrency/Mutex.h"
#include "Common/Cpp/HttpServer/AbstractHttpServer.h"
#include "Common/Cpp/Sockets/AbstractServerSocket.h"

namespace PokemonAutomation{

class ThreadPool;



class HttpServer : public AbstractHttpServer, private AbstractServerSocket::Listener{
public:
// The interface's types, re-exported under this class's name.
using AbstractHttpServer::Request;
using AbstractHttpServer::Response;
using AbstractHttpServer::HandlerContext;
using AbstractHttpServer::Handler;
using AbstractHttpServer::Listener;


public:
explicit HttpServer(ThreadPool& thread_pool);
~HttpServer();

virtual void start(const std::string& address, uint16_t port, Handler handler) override;
virtual void stop() override;
virtual bool is_running() const override;


private:
// AbstractServerSocket::Listener.
virtual void on_listen_finished(const std::string& error_message) override;
virtual void on_connect() override;
virtual void on_connect_rejected() override;
virtual void on_receive_data(const void* data, size_t bytes) override;
virtual void on_disconnect(const std::string& error_message) override;


private:
// One request that is waiting to be parsed out of the buffer.
enum class ParseState{
NEED_MORE,
NEED_BODY,
READY,
// Named "ERROR_RESPONSE" rather than "ERROR" because "ERROR" is
// a macro on Windows (winerror.h).
ERROR_RESPONSE,
};

struct ParsedRequest{
ParseState state = ParseState::NEED_MORE;

// ERROR_RESPONSE
int error_status = 400;
std::string error_reason;
std::vector<std::pair<std::string, std::string>> error_headers;

// READY / NEED_BODY
Request request;
bool http_1_1 = true;
bool connection_close_requested = false;
bool expect_continue = false;
};

// Per-connection state. The connection task is the only thread that
// parses or writes; "on_receive_data"/"on_disconnect" only append
// data and flip flags.
struct Connection{
Mutex lock;
ConditionVariable cv;
std::string buffer;
std::atomic<bool> dead{false};

// The server socket's connection_id() when this connection was
// accepted. Passed to every send(), so a write that outlives the
// connection is refused instead of reaching the next client.
uint64_t socket_id = 0;
};

// Runs on a thread from the thread pool, one instance per
// connection.
void connection_task(
const std::shared_ptr<Connection>& conn,
AbstractServerSocket* socket
);

// Parses one complete request out of "buffer", removing it on
// success. Must be called with "conn->lock" held.
static ParsedRequest try_parse(std::string& buffer);

// Marks the connection dead and closes it at the socket level. No-op
// if the socket is no longer connected to this client.
void end_connection(
const std::shared_ptr<Connection>& conn,
AbstractServerSocket* socket
);

// Writes "bytes" to the connection completely; returns false (and
// ends the connection) if the peer went away or the write stalled.
bool write_raw(
const std::shared_ptr<Connection>& conn,
AbstractServerSocket* socket,
const std::string& bytes
);

// Formats and writes the final response.
bool write_response(
const std::shared_ptr<Connection>& conn,
AbstractServerSocket* socket,
const Response& response,
bool keep_alive
);

// The standard reason phrase for "status", or "Unknown Status".
static const char* status_reason(int status);

// Builds the wire format of a response.
static std::string format_response(const Response& response, bool keep_alive);


private:
ThreadPool& m_thread_pool;

// Guards m_socket, m_connection, and m_handler. Never held across a
// blocking wait, a task destruction, or a socket destruction.
mutable Mutex m_lock;
std::unique_ptr<AbstractServerSocket> m_socket;
std::shared_ptr<Connection> m_connection;
Handler m_handler;

// Guards m_tasks. Never held while an AsyncTask destructor runs:
// the destructor blocks until the task finishes, and the task's
// final cleanup takes m_lock.
Mutex m_task_lock;
std::vector<AsyncTask> m_tasks;

// Set by "stop()"; checked by the connection tasks between requests
// and by "HandlerContext".
std::atomic<bool> m_stop_requested{false};
};



}
#endif
Loading