This is a rigorous and highly effective architectural constraint. Enforcing a
strict 150-line limit per file will force absolute separation of concerns.
This approach also perfectly preserves your V1.0 "No Network Stack in the VM"
ruling. The LPC Microkernel remains a pure, isolated bytecode executor; it is
the **Host OS (the Node.js REPL wrapper)** that handles the asynchronous TCP
sockets. The VM simply receives strings and yields execution, remaining
completely oblivious to the network layer.
Here is the architectural design to achieve this modularity, and the specific
answer on how to handle outbound data.
### How to Implement Sending Lines Back
To send lines back to the client without polluting the LPC VM with socket
logic, we establish a **1:1 Mapping between an Object ID (OID) and a TCP
Socket** inside the Node.js Host.
1. **The Host Connection Map:** When a user connects to a port, the Host
clones the target LPC file (e.g., `/obj/login.c`). The Host stores the socket
in a map keyed by the new clone's OID: `activeConnections.set(clone_oid,
tcp_socket)`.
2. **Inbound Routing:** When the TCP socket receives a line, the Host executes
an immediate `ECALL` on that specific `clone_oid`, passing the string handle
to the `receive_line(string)` function.
3. **Outbound Routing (The Solution):** We introduce a new Syscall:
`sys_net_write`.
When the LPC object wants to reply, it calls `net_write("Welcome!
");`. The VM traps to the Host OS. The Host looks at `ctx.current_oid`,
retrieves the corresponding TCP socket from `activeConnections`, and calls
`socket.write(string)`.
The LPC object never touches a socket. It simply talks to a Host interface.
---
### The Modular REPL Architecture (Max 150 Lines/File)
To adhere strictly to the size constraints, we will split the Host environment
into four highly focused modules inside a new `src/repl/` directory.
#### 1. `repl.js` (The Entry Point)
* Parses command-line arguments (e.g., `node src/repl/repl.js
4000=/obj/login.c 4001=/obj/chat.c`).
* Instantiates the HAUKI-X86 Engine facade (`src/index.js`).
* Initializes the CLI and Network modules.
#### 2. `net_server.js` (The TCP Manager)
* Loops through the parsed port configurations and calls `net.createServer()`.
* Implements a line-buffering mechanism (splitting incoming `data` chunks by `
`).
* Fires high-level events to the Host Bridge: `onNewConnection(port, socket)`
and `onLineReceived(socket, line)`.
#### 3. `host_bridge.js` (The Glue & Syscalls)
* Maintains the `Map<OID, Socket>` and `Map<Socket, OID>`.
* Registers new Efuns into the VM (`net_write`, `destruct`).
* **On connection:** Calls `vm.clone_object()`, maps the OID, and initiates a
`CTX` in the Scheduler.
* **On line received:** Translates the JS string to a Tagged Pointer, sets up
the registers, and forces an `ECALL` to `receive_line`.
#### 4. `wizard_cli.js` (The Admin Console)
* Uses Node's `readline` module attached to `process.stdin`.
* Implements the interactive wizard commands:
* `ls`: Lists VFS contents.
* `list`: Iterates the MOI array to show active objects.
* `destr <oid>`: Flags an MOI entry as dead and drops the TCP socket.
* `lpc <code>`: Writes a temporary blueprint, clones it, and executes it.
---
### Master Control: Dev-Chat Prompt
To guarantee the dev-chat adheres to your 150-line rule and builds this exact
architecture, paste this prompt into a new chat:
> **System Prompt:**
> You are an expert systems engineer and compiler architect working on the
HAUKI-X86 LPC Engine. This is a strict, isomorphic, cooperative microkernel
built in Node.js.
> **Rule 1:** You must strictly obey the architectural boundaries defined in
the AST-MD documentation below.
> **Rule 2:** The VM execution core is isolated. The network stack lives
entirely in the Host OS wrapper.
> **Rule 3 (STRICT):** You must design the system in a highly modular way.
Absolutely no source code file you generate may exceed 150 lines in length.
Break logic into smaller files if necessary.
> Here is the current architectural state:
> ```markdown
> [PASTE CONTENTS OF docs/GD-AST.md HERE]
>
> ```
>
>
> Here is the current bundled source code:
> ```text
> [PASTE OUTPUT OF `x-package-src src/` HERE]
>
> ```
>
>
> **Current Task:**
> We are building the Host REPL environment. It must support both an
interactive Wizard CLI (via `process.stdin`) and TCP Server capabilities
defined via command-line arguments (e.g., `node repl.js 4000=/obj/login.c`).
> Requirements:
> 1. TCP ports operate in line-mode.
> 2. A new connection clones the specified LPC file and maps the TCP socket to
the new Object ID (OID).
> 3. Incoming lines trigger an `ECALL` to `receive_line(string)` on the cloned
object.
> 4. Outbound data is handled by a new syscall `net_write(string)`, which
looks up the socket by the calling `ctx.current_oid` and writes to it.
>
>
> Please generate the code for `src/repl/net_server.js` and `src/repl/host_brid
ge.js` first, strictly adhering to the <150 lines rule.