An open-source, self-hosted system for apps built with web technologies.
Release System 0.1.93
zohayrslilehb21230f7b053
diff --git a/bun.lock b/bun.lockindex 46f696c..9ff56b2 100644--- a/bun.lock+++ b/bun.lock@@ -8,8 +8,8 @@"@fontsource/roboto": "^5.3.0","@hono/node-server": "^2.1.1","@jitl/quickjs-ng-wasmfile-release-sync": "^0.32.0",- "@phreshos/core": "^0.1.61",- "@phreshos/react-ui": "^0.1.37",+ "@phreshos/core": "^0.1.62",+ "@phreshos/react-ui": "^0.1.38","@the-link/core": "^0.3.1","@the-link/http": "^0.1.1","@the-link/ipc": "^0.2.2",@@ -199,9 +199,9 @@"@oxc-project/types": ["@oxc-project/[email protected]", "", {}, "sha512-rDS5/31E9HfPl/CIzGrn0DOlvBbXFseQ5URJ9sYMfstbKLD/c6Gm9vmRzRGDdAXyOIL4zmO37lc9RIwYqVruZw=="],- "@phreshos/core": ["@phreshos/[email protected]", "", { "dependencies": { "zod": "^4.6.5" } }, "sha512-ih5YrIey/5ANhEmn8UCizPZ0ktCrzPre0MEL+Civa0bxDlJJPTwWg9MnPDgN7tBVaWJ7+6XmWVHGNiud9g9yKQ=="],+ "@phreshos/core": ["@phreshos/[email protected]", "", { "dependencies": { "zod": "^4.6.5" } }, "sha512-ifLLhfyqVGc8f/5DcDwlfMh6YKA6+1ODBD+KfvdY0BKynhr6Wbs3xPaah8+NQI4iHYyESD+v/N2qYkcfY2m0rg=="],- "@phreshos/react-ui": ["@phreshos/[email protected]", "", { "dependencies": { "@base-ui/react": "^1.7.0", "@internationalized/date": "^3.12.3", "@phreshos/core": "^0.1.61", "colorjs.io": "^0.7.1", "lucide-react": "^1.48.0", "react-aria": "^3.51.0", "react-aria-components": "^1.20.0" }, "peerDependencies": { "react": "^19.2.0", "react-dom": "^19.2.0" } }, "sha512-jRVzjckBtGCDS5swQ985qHiXMpt7lGxMQoViQY3BWFgYF/j5qs8EdnlCkc/MMQnEXd7GkBIO83w4Af3gYJLLOA=="],+ "@phreshos/react-ui": ["@phreshos/[email protected]", "", { "dependencies": { "@base-ui/react": "^1.7.0", "@internationalized/date": "^3.12.3", "@phreshos/core": "^0.1.62", "colorjs.io": "^0.7.1", "lucide-react": "^1.48.0", "react-aria": "^3.51.0", "react-aria-components": "^1.20.0" }, "peerDependencies": { "react": "^19.2.0", "react-dom": "^19.2.0" } }, "sha512-/ioPu7PpfFkDsA2r+5gj55TrikiJmTLsdqja19oCttOpdUl0R8DgTMh3dWIhIG9lZHpXA+F4Elh9pIY6vj7mPg=="],"@react-types/shared": ["@react-types/[email protected]", "", { "peerDependencies": { "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1" } }, "sha512-AzsuD9OfxTOZMMvTRhlN3oHBwOmFN7tDh27LzqmHt4+uOgPhJT7ZM7/kVs/8/o0WxayMUIk3hBmCFRHv1FUoag=="],diff --git a/package.json b/package.jsonindex a531020..1bedb60 100644--- a/package.json+++ b/package.json@@ -1,7 +1,7 @@{"name": "phreshos","displayName": "PhreshOS",- "version": "0.1.92",+ "version": "0.1.93","description": "The PhreshOS server, desktop, and authoritative system runtime.","type": "module","private": true,@@ -37,8 +37,8 @@"@fontsource/roboto": "^5.3.0","@hono/node-server": "^2.1.1","@jitl/quickjs-ng-wasmfile-release-sync": "^0.32.0",- "@phreshos/core": "^0.1.61",- "@phreshos/react-ui": "^0.1.37",+ "@phreshos/core": "^0.1.62",+ "@phreshos/react-ui": "^0.1.38","@the-link/core": "^0.3.1","@the-link/http": "^0.1.1","@the-link/ipc": "^0.2.2",diff --git a/source/client/core/link-manager/auth-manager/process-manager/process-manager.ts b/source/client/core/link-manager/auth-manager/process-manager/process-manager.tsindex 55a0192..47f0ef6 100644--- a/source/client/core/link-manager/auth-manager/process-manager/process-manager.ts+++ b/source/client/core/link-manager/auth-manager/process-manager/process-manager.ts@@ -226,6 +226,17 @@ export default class ProcessManager extends TheLink {await this.$outbound.publish("/endpoint/stop", identity, which)}+ public async clientMemory(identity: string, operation: string, key?: unknown, value?: unknown, expected?: unknown) {++ return await this.$outbound.publishFirst("/client-memory", identity, operation, key, value, expected)+ }++ @Subscribe("/client-memory-change")+ protected async clientMemoryChanged(identity: string, key: string, snapshot: unknown) {++ await this.$inbound.publish("/client-memory-change", identity, key, snapshot)+ }+/** Announces a locally changed counterpart to desktop representations. */public async changed() {diff --git a/source/client/view/components/desktop-host/client-process-boundary.ts b/source/client/view/components/desktop-host/client-process-boundary.tsindex 6200f2b..9b5b996 100644--- a/source/client/view/components/desktop-host/client-process-boundary.ts+++ b/source/client/view/components/desktop-host/client-process-boundary.ts@@ -899,7 +899,16 @@ export default class ClientProcessBoundary extends TheLink {return}- const stop = this.traffic.observe(this.pane, route, kind, event, (delivery, ...values) => {+ const stop = route === "host-client-memory" && kind === "publish"+ ? this.authManager.processManager.$inbound.subscribe("/client-memory-change", (identity: string, key: string, snapshot: unknown) => {+ if (event !== null && event !== key) return+ const target = this.authManager.processManager.processes.get(identity)+ if (!target?.client) return+ void this.systemAccess.canProcess(target).then(allowed => {+ if (allowed) this.deliver(route, key, identity, snapshot).catch(() => undefined)+ })+ })+ : this.traffic.observe(this.pane, route, kind, event, (delivery, ...values) => {if (this.trafficDeliveries.has(delivery)) returndiff --git a/source/client/view/components/desktop-host/host.ts b/source/client/view/components/desktop-host/host.tsindex 59c1a7a..1766825 100644--- a/source/client/view/components/desktop-host/host.ts+++ b/source/client/view/components/desktop-host/host.ts@@ -170,6 +170,13 @@ export default function host(authManager: AuthManager, pane: string, viewport: (return async function answer(word: unknown, ...args: unknown[]) {+ if (word === "client-memory") {++ const target = await permittedProcess(args[0])++ return [await processManager.clientMemory(target.identity, String(args[1]), args[2], args[3], args[4])]+ }+// When it started is a fact about this process, which a pane may// already ask everything else about — it was missing on this side// only because it was added on the other.diff --git a/source/client/view/structure/desktop/layers/shell/start-menu/start-menu.tsx b/source/client/view/structure/desktop/layers/shell/start-menu/start-menu.tsxindex fae6d4f..27af312 100644--- a/source/client/view/structure/desktop/layers/shell/start-menu/start-menu.tsx+++ b/source/client/view/structure/desktop/layers/shell/start-menu/start-menu.tsx@@ -96,6 +96,7 @@ export const StartMenuButton = memo(function StartMenuButton({ showLabel = truelabel={application.displayName}showLabel={showLabel}color="default:base"+ material="extended"aria-controls={control.id}aria-expanded={control.open}aria-haspopup="dialog"diff --git a/source/client/view/structure/desktop/layers/shell/taskbar/programs/taskbar-item.tsx b/source/client/view/structure/desktop/layers/shell/taskbar/programs/taskbar-item.tsxindex 4c4fbce..ce9122f 100644--- a/source/client/view/structure/desktop/layers/shell/taskbar/programs/taskbar-item.tsx+++ b/source/client/view/structure/desktop/layers/shell/taskbar/programs/taskbar-item.tsx@@ -1,4 +1,4 @@-import { Button, type ButtonProps } from "@phreshos/react-ui"+import { Button, type ButtonActionProps } from "@phreshos/react-ui"import { type TaskbarPosition } from "@phreshos/core"import { forwardRef, type ReactNode } from "react"@@ -38,7 +38,7 @@ export function taskbarIndicatorClassName(position: TaskbarPosition) {return "inset-y-3 right-0 w-0.5"}-export interface TaskbarItemProps extends Omit<ButtonProps, "children"> {+export interface TaskbarItemProps extends Omit<ButtonActionProps, "children"> {active?: booleandiff --git a/source/client/view/structure/desktop/layers/shell/taskbar/taskbar-button.tsx b/source/client/view/structure/desktop/layers/shell/taskbar/taskbar-button.tsxindex ba66629..7747576 100644--- a/source/client/view/structure/desktop/layers/shell/taskbar/taskbar-button.tsx+++ b/source/client/view/structure/desktop/layers/shell/taskbar/taskbar-button.tsx@@ -1,4 +1,4 @@-import { Button, type ButtonProps } from "@phreshos/react-ui"+import { Button, type ButtonActionProps } from "@phreshos/react-ui"import { type ReactNode } from "react"/** One visual contract for the Taskbar's fixed system controls. */@@ -13,7 +13,7 @@ export default function TaskbarButton({ icon, label, showLabel = true, ...props</Button>}-interface TaskbarButtonProps extends Omit<ButtonProps, "children"> {+interface TaskbarButtonProps extends Omit<ButtonActionProps, "children"> {icon: ReactNodediff --git a/source/client/view/structure/desktop/windows/window-surface.tsx b/source/client/view/structure/desktop/windows/window-surface.tsxindex 7abae9c..4c0ea9e 100644--- a/source/client/view/structure/desktop/windows/window-surface.tsx+++ b/source/client/view/structure/desktop/windows/window-surface.tsx@@ -9,7 +9,7 @@ import { resolveWindowTransaction } from "@client/view/appearance/motion"import { useAppearance } from "@phreshos/react-ui"/** Paints the optional Desktop-owned backing surface for a supported presentation. */-export default function WindowSurface({ surface, animation, onComplete }: WindowSurfaceProps) {+export default function WindowSurface({ surface, active = true, animation, onComplete }: WindowSurfaceProps) {const reducedMotion = useReducedMotion()const appearance = useAppearance()@@ -58,7 +58,7 @@ export default function WindowSurface({ surface, animation, onComplete }: Window<Surfacearia-hidden="true"color={surfaceColor(retained.current)}- material={surfaceMaterial(retained.current)}+ material={surfaceMaterial(retained.current, active)}radius={windowSurfaceRadius(retained.current, appearance)}style={{ position: "absolute", inset: 0 }}/>@@ -69,6 +69,9 @@ interface WindowSurfaceProps {surface: WindowSurfaceDefinition+ /** Whether this is the front window. Only the front window is frosted. */+ active?: boolean+animation: PresentationAnimation | nullonComplete: (revision: number) => void@@ -85,13 +88,16 @@ function surfaceColor(surface: VisibleWindowSurface): Color | undefined {: surface.color}-function surfaceMaterial(surface: VisibleWindowSurface): "none" | "full" | MaterialOptions {+function surfaceMaterial(surface: VisibleWindowSurface, active: boolean): "none" | "basic" | "full" | MaterialOptions {- if (surface === true || surface.material === undefined) return "full"+ const material = surface === true || surface.material === undefined ? "full" : surface.material- if (surface.material === false) return "none"+ if (material === false) return "none"- return surface.material+ // Frost blurs everything behind a window again whenever anything behind it+ // changes, so its cost grows with every open window. Only the front window+ // keeps it; the others become the same paint, opaque, as on macOS.+ return active ? material : "basic"}const appearanceColors = ["background", "foreground", "default", "primary", "secondary", "success", "warning", "danger", "info"] as const satisfies readonly AppearanceColor[]diff --git a/source/client/view/structure/desktop/windows/window.tsx b/source/client/view/structure/desktop/windows/window.tsxindex baf9a33..31088de 100644--- a/source/client/view/structure/desktop/windows/window.tsx+++ b/source/client/view/structure/desktop/windows/window.tsx@@ -628,7 +628,10 @@ export default function ({ title, header = true, surface, layer, icon, children,// lower layers; content inside the iframe cannot cross that boundary.className={`absolute ${minimized || closing || !interactive ? "pointer-events-none" : "pointer-events-auto"} ${className ?? ""}`}- style={{ ...style, left: 0, top: 0, ...geometryMotion.style }}+ // Each window keeps its own compositor layer. Moving, raising, or+ // minimizing one window then only recomposites it, instead of+ // repainting the windows it shares a layer with.+ style={{ ...style, left: 0, top: 0, willChange: "transform", ...geometryMotion.style }}{...props}@@ -673,6 +676,7 @@ export default function ({ title, header = true, surface, layer, icon, children,><WindowSurfacesurface={surfaceDefinition}+ active={active}animation={surfaceAnimation ?? null}onComplete={revision => onPresentationAnimationComplete?.("surface", revision)}/>diff --git a/source/client/view/structure/structure.tsx b/source/client/view/structure/structure.tsxindex 1d57945..ede3c9d 100644--- a/source/client/view/structure/structure.tsx+++ b/source/client/view/structure/structure.tsx@@ -38,20 +38,40 @@ function DesktopReadiness({ appearance }: { appearance: ReturnType<typeof useAppconst { pending } = useReadiness<DesktopReadinessRequirement>()+ const covering = pending.length > 0++ const duration = appearance.transaction.duration++ // Once faded out, the cover leaves the tree. Kept at zero opacity, it+ // stayed a full-screen layer over the Desktop that repainted with every+ // frame of any animation, and its spinner never stopped.+ const [faded, setFaded] = useState(!covering)++ if (covering && faded) setFaded(false)++ if (!covering && !faded && duration === 0) setFaded(true)++ if (faded) return null+return <Loading- aria-hidden={pending.length === 0}+ aria-hidden={!covering}- className={pending.length ? "opacity-100" : "pointer-events-none opacity-0"}+ className={covering ? "opacity-100" : "pointer-events-none opacity-0"}style={{// New pending work must cover the next representation// immediately; only completed readiness fades away.- transitionDuration: pending.length ? "0ms" : String(appearance.transaction.duration) + "ms",+ transitionDuration: covering ? "0ms" : String(duration) + "ms",transitionTimingFunction: cssEasing(appearance.transaction.easing),transitionProperty: "opacity"}}+ onTransitionEnd={event => {++ if (!covering && event.target === event.currentTarget && event.propertyName === "opacity") setFaded(true)+ }}+>{pending[0]?.message ?? "Loading…"}</Loading>}diff --git a/source/server/core/link-manager/auth-manager/process-manager/client-memory.ts b/source/server/core/link-manager/auth-manager/process-manager/client-memory.tsnew file mode 100644index 0000000..051c8a3--- /dev/null+++ b/source/server/core/link-manager/auth-manager/process-manager/client-memory.ts@@ -0,0 +1,127 @@+import { randomUUID } from "node:crypto"+import { Buffer } from "node:buffer"+import type { JsonValue } from "@phreshos/core"++const maximumValueBytes = 16 * 1024+const maximumRunBytes = 64 * 1024++export type MemorySnapshot = Readonly<{ run: string, revision: number, value: JsonValue | undefined }>+export type MemoryChange = Readonly<{ key: string, snapshot: MemorySnapshot }>++/** The state of one Client execution, independent of every browser representation. */+export default class ClientMemoryState {+ public readonly run = randomUUID()++ private readonly values = new Map<string, { value: JsonValue, bytes: number }>()+ private readonly listeners = new Set<(change: MemoryChange) => void>()+ private revision = 0+ private totalBytes = 0+ private open = true++ public snapshot(key: string): MemorySnapshot {+ this.requireOpen()+ requireKey(key)+ return { run: this.run, revision: this.revision, value: clone(this.values.get(key)?.value) }+ }++ public entries(): readonly (readonly [string, JsonValue])[] {+ this.requireOpen()+ return [...this.values].map(([key, entry]) => [key, clone(entry.value) as JsonValue] as const)+ }++ public set(key: string, value: unknown): MemorySnapshot {+ this.requireOpen()+ requireKey(key)+ const json = jsonValue(value)+ const encoded = JSON.stringify(json)+ const bytes = Buffer.byteLength(key, "utf8") + Buffer.byteLength(encoded, "utf8")+ if (Buffer.byteLength(encoded, "utf8") > maximumValueBytes) throw new Error("A Client memory value exceeds 16 KiB")++ const previous = this.values.get(key)+ if (previous && JSON.stringify(previous.value) === encoded) return this.snapshot(key)+ if (this.totalBytes - (previous?.bytes ?? 0) + bytes > maximumRunBytes) throw new Error("Client memory exceeds 64 KiB")++ this.values.set(key, { value: json, bytes })+ this.totalBytes += bytes - (previous?.bytes ?? 0)+ this.revision+++ const snapshot = this.snapshot(key)+ this.emit({ key, snapshot })+ return snapshot+ }++ public compareAndSet(key: string, expected: { run: string, revision: number }, value: unknown) {+ this.requireOpen()+ requireKey(key)+ if (expected.run !== this.run || expected.revision !== this.revision) return { changed: false, snapshot: this.snapshot(key) } as const+ return { changed: true, snapshot: this.set(key, value) } as const+ }++ public delete(key: string): boolean {+ this.requireOpen()+ requireKey(key)+ const previous = this.values.get(key)+ if (!previous) return false+ this.values.delete(key)+ this.totalBytes -= previous.bytes+ this.revision+++ this.emit({ key, snapshot: this.snapshot(key) })+ return true+ }++ /** Delivers one coherent initial snapshot before later changes. */+ public subscribe(key: string, listener: (snapshot: MemorySnapshot) => void) {+ this.requireOpen()+ requireKey(key)+ const follow = (change: MemoryChange) => { if (change.key === key) listener(change.snapshot) }+ this.listeners.add(follow)+ listener(this.snapshot(key))+ return () => { this.listeners.delete(follow) }+ }++ public changes(listener: (change: MemoryChange) => void) {+ this.requireOpen()+ this.listeners.add(listener)+ return () => { this.listeners.delete(listener) }+ }++ public close() {+ this.open = false+ this.listeners.clear()+ this.values.clear()+ this.totalBytes = 0+ }++ private requireOpen() {+ if (!this.open) throw new Error("This Client run has stopped")+ }++ private emit(change: MemoryChange) {+ for (const listener of this.listeners) listener(change)+ }+}++function requireKey(key: unknown): asserts key is string {+ if (typeof key !== "string") throw new Error("A Client memory key must be text")+}++function jsonValue(value: unknown): JsonValue {+ const visited = new Set<object>()+ function valid(candidate: unknown): candidate is JsonValue {+ if (candidate === null || typeof candidate === "string" || typeof candidate === "boolean") return true+ if (typeof candidate === "number") return Number.isFinite(candidate)+ if (typeof candidate !== "object" || visited.has(candidate)) return false+ if (!Array.isArray(candidate) && Object.getPrototypeOf(candidate) !== Object.prototype && Object.getPrototypeOf(candidate) !== null) return false+ visited.add(candidate)+ const accepted = Array.isArray(candidate)+ ? Array.from({ length: candidate.length }, (_, index) => Object.hasOwn(candidate, index) && valid(candidate[index])).every(Boolean)+ : Object.keys(candidate).every(key => valid((candidate as Record<string, unknown>)[key]))+ visited.delete(candidate)+ return accepted+ }+ if (!valid(value)) throw new Error("A Client memory value must be JSON")+ return JSON.parse(JSON.stringify(value)) as JsonValue+}++function clone(value: JsonValue | undefined): JsonValue | undefined {+ return value === undefined ? undefined : JSON.parse(JSON.stringify(value)) as JsonValue+}diff --git a/source/server/core/link-manager/auth-manager/process-manager/client-state.ts b/source/server/core/link-manager/auth-manager/process-manager/client-state.tsindex 467e426..9e8adfc 100644--- a/source/server/core/link-manager/auth-manager/process-manager/client-state.ts+++ b/source/server/core/link-manager/auth-manager/process-manager/client-state.ts@@ -1,3 +1,5 @@+import ClientMemoryState from "./client-memory"+/*** The current execution context of a Process's Client Endpoint.*@@ -6,6 +8,8 @@*/export default class ClientState {+ public readonly memory = new ClientMemoryState()+public readonly service: booleanpublic constructor(service: boolean) {diff --git a/source/server/core/link-manager/auth-manager/process-manager/host-traffic.ts b/source/server/core/link-manager/auth-manager/process-manager/host-traffic.tsindex 3780a0e..0b7b112 100644--- a/source/server/core/link-manager/auth-manager/process-manager/host-traffic.ts+++ b/source/server/core/link-manager/auth-manager/process-manager/host-traffic.ts@@ -50,4 +50,4 @@ type Subscriber = (delivery: object, event: string, ...values: unknown[]) => unkexport type HostDomain = Domain-type Domain = "program" | "process" | "window" | "connection" | "session" | "service" | "permission" | "log" | "programLog"+type Domain = "program" | "process" | "window" | "connection" | "session" | "service" | "permission" | "log" | "programLog" | "clientMemory"diff --git a/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts b/source/server/core/link-manager/auth-manager/process-manager/process-manager.tsindex 4961418..5142dc0 100644--- a/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts+++ b/source/server/core/link-manager/auth-manager/process-manager/process-manager.ts@@ -40,6 +40,7 @@ import SystemAccess from "./system-access"import { WebSocket } from "ws"import { permissionCatalog } from "@server/core/permissions"import { defaultPermissionRequestTimeout } from "@server/core/permission-manager"+import type { MemorySnapshot } from "./client-memory"type SerializedClientLayer = DesktopReplacementLayer | "shell"@@ -204,6 +205,34 @@ export default class ProcessManager extends TheLink {return this.hostTraffic.observe(domain, event, subject, (_delivery, word, ...values) => subscriber(word, ...values))}+ /** All roads operate on the same current Client run, never on a browser document. */+ public clientMemory(identity: string, operation: string, key?: unknown, value?: unknown, expected?: unknown) {+ const process = this.find(identity)+ if (!process.clientEndpoint) throw new Error("This Program declared no Client Endpoint")+ const memory = process.client?.memory+ if (!memory && operation === "entries") return []+ if (!memory && operation === "snapshot" && typeof key === "string") return { run: null, revision: 0, value: undefined }+ if (!memory) throw new Error("This Client Endpoint is not running")+ if (operation === "entries") return memory.entries()+ if (typeof key !== "string") throw new Error("A Client memory key must be text")+ if (operation === "snapshot") return memory.snapshot(key)+ if (operation === "set") return memory.set(key, value)+ if (operation === "delete") return memory.delete(key)+ if (operation === "compareAndSet") {+ const revision = expected as Partial<MemorySnapshot> | null+ if (!revision || typeof revision.run !== "string" || !Number.isSafeInteger(revision.revision) || (revision.revision as number) < 0) {+ throw new Error("A Client memory update requires a run and revision")+ }+ return memory.compareAndSet(key, { run: revision.run, revision: revision.revision as number }, value)+ }+ throw new Error(`The Client memory does not know the operation "${operation}"`)+ }++ @Subscribe("/client-memory")+ protected clientMemoryForConnection(identity: unknown, operation: unknown, key?: unknown, value?: unknown, expected?: unknown) {+ return this.clientMemory(String(identity), String(operation), key, value, expected)+ }+/** Observe destinationless events from one exact live Endpoint. */public observeEndpoint(identity: string, half: Half, event: string | null, subscriber: (payload: unknown, event: string) => void, impossible?: (reason: string) => void) {@@ -627,7 +656,17 @@ export default class ProcessManager extends TheLink {stop = this.observeServiceFromOutside(observation.address, observation.kind, event, followed)}- else throw new Error("A System observation scope is endpoint, traffic, or service")+ else if (observation.scope === "clientMemory") {++ if (typeof observation.key !== "string") throw new Error("A Client memory key must be text")+ const process = this.find(String(observation.process))+ stop = process.client+ ? process.client.memory.subscribe(observation.key, snapshot => followed(observation.key as string, snapshot))+ : () => undefined+ if (!process.client) followed(observation.key, { run: null, revision: 0, value: undefined })+ }++ else throw new Error("Unknown System observation scope")observations.set(subscription, stop)}@@ -942,7 +981,7 @@ export default class ProcessManager extends TheLink {return server}- private serverHostVisible(process: Process, domain: "program" | "process" | "connection" | "session" | "service" | "window" | "permission" | "log" | "programLog", subject: string | null) {+ private serverHostVisible(process: Process, domain: "program" | "process" | "connection" | "session" | "service" | "window" | "permission" | "log" | "programLog" | "clientMemory", subject: string | null) {const access = new SystemAccess(this, process)@@ -1035,6 +1074,13 @@ export default class ProcessManager extends TheLink {)) throw new Error("Another Program already occupies the shell layer")process.startClient(service)++ process.client?.memory.changes(({ key, snapshot }) => {+ // A browser document may disappear while the Client run remains.+ // Publish from the run so every current representation sees one order.+ this.hostTraffic.emitSubject("clientMemory", key, process.reference, processReference(process), snapshot).catch(() => undefined)+ this.$outbound.publish("/client-memory-change", process.identity, key, snapshot).catch(() => undefined)+ })}public async register(identity: string, name: string | null, program: Program, options: Options, launch: ProcessLaunch, runtime: ServerRuntimeFactory<Program> | null, client: boolean, shape: Shape | null, parent: Process | null, registration?: ProcessRegistration) {@@ -2722,6 +2768,11 @@ export default class ProcessManager extends TheLink {return [await this.system.programStore(whose, operation, key, value, ttl)]}+ if (word === "client-memory") {+ const target = heldProcess(rest[0])+ return [this.clientMemory(target.identity, String(rest[1]), rest[2], rest[3], rest[4])]+ }+throw new Error(`The host does not know the word "${String(word)}"`)}diff --git a/source/server/core/link-manager/auth-manager/process-manager/process.ts b/source/server/core/link-manager/auth-manager/process-manager/process.tsindex 774276e..f8225d2 100644--- a/source/server/core/link-manager/auth-manager/process-manager/process.ts+++ b/source/server/core/link-manager/auth-manager/process-manager/process.ts@@ -176,6 +176,8 @@ export default class Process {if (!this.client) return false+ this.client.memory.close()+this.client = null// Stopping ends this incarnation rather than retaining values for thediff --git a/source/server/core/link-manager/auth-manager/process-manager/server-process-boundary.ts b/source/server/core/link-manager/auth-manager/process-manager/server-process-boundary.tsindex afbdee1..96177d7 100644--- a/source/server/core/link-manager/auth-manager/process-manager/server-process-boundary.ts+++ b/source/server/core/link-manager/auth-manager/process-manager/server-process-boundary.ts@@ -375,6 +375,7 @@ export default class ServerProcessBoundary extends TheLink {: route === "host-permission" || route === "permission-host" ? "permission": route === "host-log" ? "log": route === "program-log" ? "programLog"+ : route === "host-client-memory" ? "clientMemory": route === "host-end" ? "window": null@@ -538,4 +539,4 @@ export type { Stream } from "@server/core/server-runtime"export type Ending = (code: number | null, signal: NodeJS.Signals | null) => void-export type HostVisibility = (domain: "program" | "process" | "connection" | "session" | "service" | "window" | "permission" | "log" | "programLog", subject: string | null) => boolean+export type HostVisibility = (domain: "program" | "process" | "connection" | "session" | "service" | "window" | "permission" | "log" | "programLog" | "clientMemory", subject: string | null) => booleandiff --git a/tests/client-memory.test.ts b/tests/client-memory.test.tsnew file mode 100644index 0000000..c4c4609--- /dev/null+++ b/tests/client-memory.test.ts@@ -0,0 +1,41 @@+import assert from "node:assert/strict"+import { test } from "vitest"+import ClientMemoryState from "@server/core/link-manager/auth-manager/process-manager/client-memory"++test("one Client run shares live values and an atomic revision", () => {+ const memory = new ClientMemoryState()+ const first: unknown[] = []+ const second: unknown[] = []+ const stopFirst = memory.subscribe("tab", snapshot => first.push(snapshot.value))+ const stopSecond = memory.subscribe("tab", snapshot => second.push(snapshot.value))+ assert.deepEqual(first, [undefined])+ assert.deepEqual(second, [undefined])++ const initial = memory.snapshot("tab")+ assert.equal(memory.compareAndSet("tab", initial, "colors").changed, true)+ assert.equal(memory.compareAndSet("tab", initial, "old").changed, false)+ assert.deepEqual(first, [undefined, "colors"])+ assert.deepEqual(second, [undefined, "colors"])+ assert.deepEqual(memory.entries(), [["tab", "colors"]])++ stopFirst()+ memory.delete("tab")+ assert.deepEqual(first, [undefined, "colors"])+ assert.deepEqual(second, [undefined, "colors", undefined])+ stopSecond()++ memory.close()+ assert.throws(() => memory.snapshot("tab"), /stopped/)+ assert.deepEqual(new ClientMemoryState().entries(), [])+})++test("Client memory enforces JSON and both byte limits without partial writes", () => {+ const memory = new ClientMemoryState()+ assert.throws(() => memory.set("invalid", undefined), /JSON/)+ assert.throws(() => memory.set("invalid", [undefined]), /JSON/)+ assert.throws(() => memory.set("invalid", new Array(1)), /JSON/)+ assert.throws(() => memory.set("large", "x".repeat(16 * 1024)), /16 KiB/)+ for (let index = 0; index < 4; index++) memory.set(String(index), "x".repeat(15 * 1024))+ assert.throws(() => memory.set("fifth", "x".repeat(5 * 1024)), /64 KiB/)+ assert.equal(memory.entries().length, 4)+})diff --git a/tests/client-system-access.test.ts b/tests/client-system-access.test.tsindex 57c350a..e3dcca7 100644--- a/tests/client-system-access.test.ts+++ b/tests/client-system-access.test.ts@@ -55,6 +55,8 @@ test("client system access contract", async () => {assert(!access.ownsProgram(outsideProgram))assert(access.ownsProcess(sibling))assert(!access.ownsProcess(outside))+ assert.equal(await access.canProcess(sibling), true)+ assert.equal(await access.canProcess(outside), false)assert.equal(await access.program(ownProgram as never), ownProgram)await assert.rejects(access.service(ownService), /Execution is not permitted/)await assert.rejects(access.service(siblingService), /Execution is not permitted/)@@ -93,6 +95,7 @@ test("client system access contract", async () => {assert.equal(await access.program(outsideProgram as never), outsideProgram)assert.equal(await access.process(outside), outside)+ assert.equal(await access.canProcess(outside), true)await assert.rejects(access.service(outsideService), /Execution is not permitted/)await assert.rejects(access.requireAll(), /Execution is not permitted/)diff --git a/tests/process-lifecycle.test.ts b/tests/process-lifecycle.test.tsindex 33fcf05..4fbd71d 100644--- a/tests/process-lifecycle.test.ts+++ b/tests/process-lifecycle.test.ts@@ -92,7 +92,17 @@ test("process lifecycle contract", async () => {)process.server = {} as ServerProcessBoundary+ const memoryChanges: unknown[][] = []+ manager.$outbound.subscribe("/client-memory-change", (...values) => { memoryChanges.push(values) })+ manager.clientMemory(process.identity, "set", "tab", "colors")+ assert.equal((manager.clientMemory(process.identity, "snapshot", "tab") as { value: unknown }).value, "colors")+ assert.equal(memoryChanges.length, 1)+ assert.equal(memoryChanges[0]?.[0], process.identity)+ assert.equal(memoryChanges[0]?.[1], "tab")await manager.stopClient(process.identity)+ assert.equal((manager.clientMemory(process.identity, "snapshot", "tab") as { value: unknown }).value, undefined)+ assert.deepEqual(manager.clientMemory(process.identity, "entries"), [])+ assert.throws(() => manager.clientMemory(process.identity, "set", "tab", "colors"), /not running/)assert.equal(process.client, null)assert.ok(process.clientEndpoint)@@ -103,6 +113,8 @@ test("process lifecycle contract", async () => {await manager.startClient(process.identity)+ assert.equal((manager.clientMemory(process.identity, "snapshot", "tab") as { value: unknown }).value, undefined)+assert.deepEqual(process.clientEndpoint.window.position, { x: 0, y: 0 })assert.equal(process.clientEndpoint.window.header, true)