1123Javayanglei/vscode-chat-proxy/monitor does not have a README file

    Flow

    pub(all) struct Flow {
    id : Int
    start_ms : UInt64
    client_addr : String
    http_method : String
    target : String
    request_headers : Array[(String, String)]
    request_size : Int
    intercepted : Bool
    upstream : String
    request_body : Bytes
    request_truncated : Bool
    injected : Bool
    upstream_body : Bytes?
    upstream_truncated : Bool
    status : Int
    reason : String
    response_headers : Array[(String, String)]
    response_body : Bytes
    response_size : Int
    response_truncated : Bool
    end_ms : UInt64
    error : String?
    finished : Bool
    persisted : Bool
    }

    One proxied request/response pair, as shown in the monitor UI.

    Flow::detail

    Full detail for the flow detail API (shared contract type).

    Flow::summary

    Summary row for the flow list API (shared contract type).

    FlowStore

    pub struct FlowStore {
    dir : String
    capacity : Int
    active : Array[Flow]
    pending : Array[Flow]
    next_id : Int
    total : Int
    injected_total : Int
    intercept_enabled : Bool
    // private fields
    }

    Async sequential append-only file store for captured flows.

    Uses two rotating segment files (flows.0.log and flows.1.log) inside the monitor directory so:
    • Writes are batched into ONE sequential @fs.File::write_at call that runs off the event loop in moonbitlang/async's C worker thread pool (zero event-loop stalls even on 64–256 KiB LLM request/response bodies).
    • Disk usage is strictly bounded without compaction copies: once the active segment holds >= capacity records and the inactive segment has no live entries, the inactive segment is truncated and becomes active (1.0x write amplification).
    • GET /api/flows is served purely from memory; GET /api/flows/:id reads only the requested record via a single async File::read_exactly_at.
    • FlowStore::new keeps records in memory for unit tests; FlowStore::disabled disables recording for --no-web zero-overhead runs.

    FlowStore::begin

    fn FlowStore::begin(self : FlowStore, client_addr~ : String, http_method~ : String, target~ : String, request_headers~ : Array[(String, String)], request_body~ : Bytes, intercepted~ : Bool, upstream~ : String) -> Flow

    Register a new flow (request fully read, response pending). Pure in-memory on the proxy hot path — zero disk I/O.

    FlowStore::clear

    async fn FlowStore::clear(self : FlowStore) -> Unit

    Clear the in-memory index, truncate/reset segment files, and zero counters.

    FlowStore::close

    async fn FlowStore::close(self : FlowStore) -> Unit

    Flush remaining flows and close underlying segment files.

    FlowStore::data_dir

    fn FlowStore::data_dir(self : FlowStore) -> String

    Directory currently backing this store; empty means the in-memory store.

    FlowStore::detail

    Full detail of one flow: served from memory while in flight / pending, or via a single async pread (File::read_exactly_at) once persisted.

    FlowStore::disabled

    fn FlowStore::disabled() -> FlowStore

    No-op flow store for --no-web mode: keeps the live intercept_enabled flag without writing files or buffering request/response bodies.

    FlowStore::find

    async fn FlowStore::find(self : FlowStore, id : Int) -> Flow?

    Look up a flow by id (metadata only for persisted flows).

    FlowStore::finish

    fn FlowStore::finish(self : FlowStore, flow : Flow) -> Unit

    Mark a flow complete (idempotent) and queue it for batched async append.

    FlowStore::flush_pending

    async fn FlowStore::flush_pending(self : FlowStore) -> Unit

    Persist all surviving finished flows in ONE sequential async file append (executed off the event loop in moonbitlang/async's C worker thread pool) and release their in-memory bodies.

    FlowStore::intercept_enabled

    fn FlowStore::intercept_enabled(self : FlowStore) -> Bool

    Live interception switch: when false the proxy forwards everything unchanged (pure pass-through), ignoring the Chat Completions rule.

    FlowStore::is_recording

    fn FlowStore::is_recording(self : FlowStore) -> Bool

    Whether this store actually records flows (false for FlowStore::disabled, used in --no-web mode so the proxy pays zero monitoring overhead).

    FlowStore::list_response

    Flow list API payload (newest first, shared contract type). In single-worker mode this is served 100% from memory (zero disk I/O); in multi-worker mode it merges metadata headers from sibling workers' logs.

    FlowStore::new

    fn FlowStore::new(capacity? : Int) -> FlowStore

    In-memory store (tests, and the fallback when the temp directory is not writable). Uses the exact same binary record codec and eviction rules as the file-backed store.

    FlowStore::open

    async fn FlowStore::open(dir : String, capacity? : Int, worker_id? : Int, workers? : Int) -> FlowStore

    Open (or create) the monitor directory and its rotating append-only segment files (flows.0.log / flows.1.log). I/O failures degrade gracefully to an in-memory store so the proxy itself is never taken down by the monitor.

    FlowStore::run_flusher

    async fn FlowStore::run_flusher(self : FlowStore) -> Unit

    Background flusher: batch-append finished flows off the event loop every ~100ms so the proxy hot path never blocks on disk I/O.

    FlowStore::set_intercept_enabled

    fn FlowStore::set_intercept_enabled(self : FlowStore, enabled : Bool) -> Unit

    Flip the interception switch at runtime (monitor UI / API). Initial value comes from config; not persisted across restarts.

    body_capture_limit

    let body_capture_limit : Int

    Max bytes stored per body (request or response) in the monitor.

    cap_bytes

    fn cap_bytes(b : Bytes) -> (Bytes, Bool)

    Store at most body_capture_limit bytes of a body.

    decode_chunked_body

    fn decode_chunked_body(raw : Bytes) -> Bytes

    Best-effort decode of a complete chunked body (for display only; the bytes forwarded to the client are never touched). Falls back to the raw bytes when the input is not valid chunked framing.

    default_store_dir

    fn default_store_dir(port~ : Int) -> String

    Default on-disk location for monitor data: a stable subdirectory of the system temp directory, one per monitor port so separate proxy instances do not overwrite each other's logs.

    MONITOR_DIR / VSCODE_CHAT_PROXY_MONITOR_DIR override the location. The OS may clean the temp directory at any time; losing these files only loses monitor history, never proxy correctness.

    run_web_server

    async fn run_web_server(host : String, port : Int, store : FlowStore) -> Unit

    Serve the monitor UI and JSON API on host:port.