An open-source, self-hosted system for apps built with web technologies.
Support owner-local intake on Windows
zohayrslileh1a6216d30073
diff --git a/.github/workflows/verify.yml b/.github/workflows/verify.ymlindex 6225632..6b695d0 100644--- a/.github/workflows/verify.yml+++ b/.github/workflows/verify.yml@@ -23,3 +23,17 @@ jobs:package-manager-cache: false- run: bun install --frozen-lockfile- run: bun run verify++ windows:+ runs-on: windows-latest+ steps:+ - uses: actions/checkout@v5+ - uses: oven-sh/setup-bun@v2+ with:+ bun-version: 1.3.14+ - uses: actions/setup-node@v5+ with:+ node-version: 24+ package-manager-cache: false+ - run: bun install --frozen-lockfile+ - run: bun run verifydiff --git a/package.json b/package.jsonindex 6b24c06..804e379 100644--- a/package.json+++ b/package.json@@ -30,7 +30,7 @@"build": "vite-node --config vite.server.ts source/build.ts","start": "node --run build && node dist/server/main.js","pack": "node --run build && vite-node --config vite.server.ts source/pack.ts",- "verify:contracts": "vite-node --config vite.server.ts scripts/verify-client-launch.mjs && vite-node --config vite.server.ts scripts/verify-readiness.mjs && vite-node --config vite.server.ts scripts/verify-endpoint-services.mjs",+ "verify:contracts": "vite-node --config vite.server.ts scripts/verify-client-launch.mjs && vite-node --config vite.server.ts scripts/verify-readiness.mjs && vite-node --config vite.server.ts scripts/verify-endpoint-services.mjs && vite-node --config vite.server.ts scripts/verify-intake-address.mjs","verify:distribution": "node scripts/verify-distribution.mjs","verify": "node --run check && node --run verify:contracts && node --run verify:distribution"},diff --git a/scripts/verify-intake-address.mjs b/scripts/verify-intake-address.mjsnew file mode 100644index 0000000..7fbe93b--- /dev/null+++ b/scripts/verify-intake-address.mjs@@ -0,0 +1,12 @@+import assert from "node:assert/strict"+import intakeAddress from "../source/server/view/intake-address.ts"++const first = intakeAddress("C:\\Users\\Person\\.phreshos", "win32")++assert.match(first, /^\\\\\.\\pipe\\phreshos-[a-f0-9]{32}-intake$/)++assert.equal(first, intakeAddress("c:/users/person/.phreshos/", "win32"))++assert.notEqual(first, intakeAddress("C:\\Users\\Other\\.phreshos", "win32"))++assert.equal(intakeAddress("/home/person/.phreshos", "linux"), "/home/person/.phreshos/intake.sock")diff --git a/source/server/view/intake-address.ts b/source/server/view/intake-address.tsnew file mode 100644index 0000000..5ea5981--- /dev/null+++ b/source/server/view/intake-address.ts@@ -0,0 +1,14 @@+import { createHash } from "node:crypto"+import { join } from "node:path"++/** Resolve the owner-local address shared by this System and its local CLI. */+export default function intakeAddress(storage: string, platform = process.platform) {++ if (platform !== "win32") return join(storage, "intake.sock")++ const owner = storage.replaceAll("\\", "/").replace(/\/+$/, "").toLowerCase()++ const identity = createHash("sha256").update(owner).digest("hex").slice(0, 32)++ return `\\\\.\\pipe\\phreshos-${identity}-intake`+}diff --git a/source/server/view/intake.ts b/source/server/view/intake.tsindex c0f47b0..5f7ae88 100644--- a/source/server/view/intake.ts+++ b/source/server/view/intake.ts@@ -34,13 +34,12 @@ import { dirname } from "node:path"* that means inventing a token — a mechanism the transport made* necessary rather than one anything needed.*- * **POSIX only, deliberately.** Node maps a listening path onto a named- * pipe on Windows, so the *address* would port with two lines. The- * authorization would not: a named pipe made through Node has no- * permission story reachable from here, and its default admits any local- * process. Windows support is therefore not a transport change but a- * security-model change, and it is not owed one until something needs- * it. The rest of the system is already POSIX-only for smaller reasons.+ * On POSIX, the socket file's 0600 mode is the authorization. On Windows,+ * the equivalent address is a named pipe created without `readableAll` or+ * `writableAll`. Windows grants the creator owner full control while other+ * accounts do not receive the duplex access required by this protocol. The+ * pipe name is derived from the storage root so users and isolated instances+ * do not collide in Windows' machine-wide pipe namespace.** **One system per storage root.** The socket lives in the root, so it* follows wherever the root is — which is how the lab runs a throwaway@@ -75,6 +74,8 @@ import { dirname } from "node:path"*/export default function intake(application: Application, path: string) {+ const namedPipe = process.platform === "win32"+// A message is a line. The first version had no framing at all — a// question was whatever arrived before the asker closed its own side// — which is elegant and needs half-close to work, and bun's `net`@@ -115,7 +116,7 @@ export default function intake(application: Application, path: string) {socket.on("error", () => undefined)})- mkdirSync(dirname(path), { recursive: true })+ if (!namedPipe) mkdirSync(dirname(path), { recursive: true })return new Promise<string>(function (settle, refuse) {@@ -136,21 +137,23 @@ export default function intake(application: Application, path: string) {if (running) return refuse(new Error(`A system is already running here — ${dirname(path)} holds one system, and two would share its programs and persistent state`))+ if (namedPipe) return refuse(error)+rmSync(path, { force: true })- server.listen(path, () => settle(secured(path)))+ server.listen(path, () => settle(secured(path, namedPipe)))}, refuse)})- server.listen(path, () => settle(secured(path)))+ server.listen({ path, readableAll: false, writableAll: false }, () => settle(secured(path, namedPipe)))})}// The mode is the authorization, so it is set before anything is// answered rather than left to whatever umask was in force.-function secured(path: string) {+function secured(path: string, namedPipe: boolean) {- chmodSync(path, 0o600)+ if (!namedPipe) chmodSync(path, 0o600)return path}diff --git a/source/server/view/view.ts b/source/server/view/view.tsindex 7b395fa..6aa4871 100644--- a/source/server/view/view.ts+++ b/source/server/view/view.ts@@ -4,6 +4,7 @@ import { serve } from "@hono/node-server"import { WebSocketServer } from "ws"import doors from "./doors"import intake from "./intake"+import intakeAddress from "./intake-address"import program from "./program"import proxy from "./proxy"import storage from "./storage"@@ -72,7 +73,7 @@ export default async function (config: Config) {// Local program intake beside the way the network reaches the system.// Not HTTP: it is a filesystem socket reachable only from this machine,// for installing or running the one program a local project declares.- const socket = await intake(application, application.storage.join("intake.sock"))+ const socket = await intake(application, intakeAddress(application.storage.path))const origin = `http://localhost:${port}`