/** * The KONECK web servers running on this machine. * * One server serves one workspace at a time — switching projects in the browser moves that server, * so two projects open at once needs two servers. The terminal has always worked this way: a `koneck` * per directory, as many as you like. The browser did not, because it bound a fixed port and gave up * on the second one with "EADDRINUSE 127.0.0.1:4300", which says what happened and nothing about * what to do. * * So a second server takes the next free port, and this is how anybody finds it afterwards. A port * chosen automatically is only useful if it can be looked up later. * * ## The token is in here * * A running server is useless without its token, so a listing without one would be a list of things * you cannot open. It is written with the same protection as the credentials file — owner-readable * only, in the user's own home — which is the same protection their SSH keys have. The file is * removed when the server stops. */ export interface RunningServer { pid: number; port: number; /** The workspace it was started in. Where it is pointed *now* may differ; the browser can move it. */ cwd: string; url: string; startedAt: number; } /** * The servers that are actually running. * * Dead entries are dropped on every read rather than on a timer: a server killed with SIGKILL never * gets to tidy up after itself, and a list that includes it is worse than no list — somebody opens * a URL that answers nothing and concludes the feature is broken. */ export declare function runningServers(home?: string): RunningServer[]; /** * Records a server that has just come up. * * Keyed on the port rather than on the process. Only one server can hold a port, so it identifies * one exactly — while a process can hold several, which is not merely theoretical: the tests start * two in one process, and keying on the pid made the second overwrite the first and the listing * report one server where two were running. */ export declare function recordServer(server: RunningServer, home?: string): void; /** Forgets one, when it shuts down properly. */ export declare function forgetServer(port: number, home?: string): void; /** * Another server already serving this same workspace, if there is one. * * The one case where a second server is a genuine hazard rather than a convenience: both write * session files into the same `.koneck/sessions`, so two runs in the same project can save over * each other's history. Different projects share nothing and are entirely safe. */ export declare function servingSameWorkspace(cwd: string, home?: string): RunningServer | null; /** * A free port at or after the one asked for. * * Tried in order rather than at random, so the second project a person opens is nearly always 4301 * and the third 4302 — predictable enough to guess, which matters for something you will type into * a browser. Gives up rather than searching for ever: a machine with sixteen KONECK servers on it * has a different problem. */ export declare function freePortFrom(start: number, tries?: number, host?: string): Promise; /** How a listing reads, for the terminal. */ export declare function describeServers(servers: readonly RunningServer[]): string; //# sourceMappingURL=servers.d.ts.map