An open-source, self-hosted system for apps built with web technologies.
Unify service discovery and window presentation
zohayrslileh23ab52e5c602
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 595d210..4b5a9f9 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@@ -5,9 +5,9 @@ import { Publish, Subscribe } from "@the-link/core/decorators"import { TheLink } from "@the-link/core"import AuthManager from "../auth-manager"import Process from "./process"-import { type ClientLaunch, type ServerLaunch } from "@phreshos/core"+import { type ClientLaunch, type ProgramIconSize, type ServerLaunch } from "@phreshos/core"import { type TrafficKind } from "@server/core/link-manager/auth-manager/process-manager/process-traffic"-import { type ServiceKey, type WindowLayer } from "@phreshos/core"+import { type ServiceAddress, type WindowLayer } from "@phreshos/core"import { type ServiceScope } from "@server/core/link-manager/auth-manager/process-manager/endpoint-services"/**@@ -81,21 +81,37 @@ export default class ProcessManager extends TheLink {return await this.$outbound.publishFirst("/endpoint/is-service", source, target, endpoint) as boolean}- /** Reads current Endpoint existence for one exact Service address. */- public async serviceExists(key: ServiceKey) {+ /** Reads current availability for one exact Service address. */+ public async serviceAvailable(address: ServiceAddress) {- return await this.$outbound.publishFirst("/service/exists", key) as boolean+ return await this.$outbound.publishFirst("/service/available", address) as boolean}- public async waitServiceReady(key: ServiceKey, timeout: number | undefined) {+ public async listServices(name?: string) {- await this.$outbound.publishFirst("/service/wait-ready", key, timeout)+ const route = name === undefined ? "/service/list" : "/service/search"++ return await this.$outbound.publishFirst(route, ...name === undefined ? [] : [name]) as ServiceAddress[]+ }++ public async waitServiceReady(address: ServiceAddress, timeout: number | undefined) {++ await this.$outbound.publishFirst("/service/wait-ready", address, timeout)+ }++ public async serviceProgramMetadata(address: ServiceAddress, iconSize: ProgramIconSize = "medium") {++ return await this.$outbound.publishFirst("/service/program-metadata", address, iconSize) as {+ name: string+ version: string+ icon: number[]+ }}/** Registers one exact service interest for this frame lease. */- public async followService(pane: string, owner: string, subscription: string, key: ServiceKey, scope: ServiceScope, event: string | null) {+ public async followService(pane: string, owner: string, subscription: string, address: ServiceAddress, scope: ServiceScope, event: string | null) {- await this.$outbound.publish("/frame/service/follow", pane, owner, subscription, key, scope, event)+ await this.$outbound.publish("/frame/service/follow", pane, owner, subscription, address, scope, event)}public async unfollowService(pane: string, owner: string, subscription: string) {@@ -103,15 +119,15 @@ export default class ProcessManager extends TheLink {await this.$outbound.publish("/frame/service/unfollow", pane, owner, subscription)}- /** Sends to the live Endpoint behind one exact service key. */- public async sendService(source: string, key: ServiceKey, event: string, payload: unknown) {+ /** Sends to the live Endpoint behind one exact Service address. */+ public async sendService(source: string, address: ServiceAddress, event: string, payload: unknown) {- await this.$outbound.publish("/service/send", source, key, event, payload)+ await this.$outbound.publish("/service/send", source, address, event, payload)}- public async askService(source: string, key: ServiceKey, values: unknown[]) {+ public async askService(source: string, address: ServiceAddress, values: unknown[]) {- await this.$outbound.publish("/frame/service/ask", source, key, values)+ await this.$outbound.publish("/frame/service/ask", source, address, values)}// Handed on, not awaited. Whoever asked is holding the question by@@ -318,13 +334,6 @@ export default class ProcessManager extends TheLink {return this.followed(payload)}- @Subscribe("/geometry")- @Publish("/processes", "inbound")- protected async geometryHandle(payload: { identity: string, window: WindowSnapshot } | null) {-- return this.followed(payload)- }-@Subscribe("/raise")@Publish("/processes", "inbound")protected async raiseHandle(payload: { identity: string, window: WindowSnapshot } | null) {@@ -353,9 +362,9 @@ export default class ProcessManager extends TheLink {return this.followed(payload)}- @Subscribe("/change-opening-transaction")+ @Subscribe("/change-transaction")@Publish("/processes", "inbound")- protected async changeOpeningTransactionHandle(payload: { identity: string, window: WindowSnapshot } | null) {+ protected async changeTransactionHandle(payload: { identity: string, window: WindowSnapshot } | null) {return this.followed(payload)}diff --git a/source/client/core/link-manager/auth-manager/process-manager/window.ts b/source/client/core/link-manager/auth-manager/process-manager/window.tsindex 0b9398b..fa1509d 100644--- a/source/client/core/link-manager/auth-manager/process-manager/window.ts+++ b/source/client/core/link-manager/auth-manager/process-manager/window.ts@@ -107,27 +107,27 @@ export default class Window implements Omit<WindowState, "front"> {public async setGeometry(geometry: WindowGeometry) {- await this.processManager.$outbound.publish("/geometry", this.process, geometry)+ await this.processManager.$outbound.publish("/set-geometry", this.process, geometry)}- public async changeTitle(title: string) {+ public async setTitle(title: string) {- await this.processManager.$outbound.publish("/change-title", this.process, title)+ await this.processManager.$outbound.publish("/set-title", this.process, title)}- public async changeHeader(header: boolean) {+ public async setHeader(header: boolean) {- await this.processManager.$outbound.publish("/change-header", this.process, header)+ await this.processManager.$outbound.publish("/set-header", this.process, header)}- public async changeFrame(frame: WindowFrame) {+ public async setFrame(frame: WindowFrame) {- await this.processManager.$outbound.publish("/change-frame", this.process, frame)+ await this.processManager.$outbound.publish("/set-frame", this.process, frame)}- public async changeOpeningTransaction(transaction: WindowTransaction) {+ public async setTransaction(transaction: WindowTransaction) {- await this.processManager.$outbound.publish("/change-opening-transaction", this.process, transaction)+ await this.processManager.$outbound.publish("/set-transaction", this.process, transaction)}// To the front of its own layer, and nothing else. A hidden windowdiff --git a/source/client/core/link-manager/auth-manager/program-manager/program.ts b/source/client/core/link-manager/auth-manager/program-manager/program.tsindex 733cd25..1f7a0de 100644--- a/source/client/core/link-manager/auth-manager/program-manager/program.ts+++ b/source/client/core/link-manager/auth-manager/program-manager/program.ts@@ -25,7 +25,7 @@ export default class Program {public readonly name: string- public readonly version: string | null+ public readonly version: stringpublic readonly description: string | nulldiff --git a/source/client/view/components/desktop-host/announcements.ts b/source/client/view/components/desktop-host/announcements.tsindex 6b5e419..00ed1e5 100644--- a/source/client/view/components/desktop-host/announcements.ts+++ b/source/client/view/components/desktop-host/announcements.ts@@ -6,6 +6,7 @@ import ClientProcessBoundary from "./client-process-boundary"import ClientTraffic from "./client-traffic"import { sdkProcess, sdkProgram } from "./sdk-records"import SystemAccess from "./system-access"+import { isServiceAddress } from "@phreshos/core"/** Projects authoritative System announcements into every Client frame. */export default function useAnnouncements(authManager: AuthManager, panes: Map<string, ClientProcessBoundary>, traffic: ClientTraffic) {@@ -144,6 +145,16 @@ export default function useAnnouncements(authManager: AuthManager, panes: Map<stprocesses.useSubscribe("/client-start", useCallback((_identity: unknown, payload: HostedProcessRecord | null) => endpoint("endpointStart", "client", payload), [endpoint]))processes.useSubscribe("/client-stop", useCallback((_identity: unknown, payload: HostedProcessRecord | null) => endpoint("endpointStop", "client", payload), [endpoint]))+ const serviceEvent = useCallback((event: "available" | "unavailable", value: unknown) => {++ if (!isServiceAddress(value)) return++ postVisible(access => access.canService(value), "host-service", event, value.process, value)+ }, [postVisible])++ processes.useSubscribe("/service-available", useCallback((value: unknown) => serviceEvent("available", value), [serviceEvent]))+ processes.useSubscribe("/service-unavailable", useCallback((value: unknown) => serviceEvent("unavailable", value), [serviceEvent]))+processes.useSubscribe("/said", useCallback((identity: string, event: string, value: unknown) => {const target = authManager.processManager.processes.get(identity)diff --git a/source/client/view/components/desktop-host/client-process-boundary.ts b/source/client/view/components/desktop-host/client-process-boundary.tsindex 8947e29..aa25297 100644--- a/source/client/view/components/desktop-host/client-process-boundary.ts+++ b/source/client/view/components/desktop-host/client-process-boundary.ts@@ -4,7 +4,7 @@ import host, { TransferredAnswer } from "./host"import ClientTraffic from "./client-traffic"import { failed, succeeded } from "@libs/request-outcome"import { type TrafficKind } from "@server/core/link-manager/auth-manager/process-manager/process-traffic"-import { isServiceKey, parseProgramInstallOptions, type DesktopViewportSnapshot, type ServiceKey, type ShellOptions } from "@phreshos/core"+import { isServiceAddress, parseProgramInstallOptions, type DesktopViewportSnapshot, type ServiceAddress, type ShellOptions } from "@phreshos/core"import { type WindowPresentationHost } from "./window-presentation"import messagepack from "@the-link/messagepack"import { sdkProcess, type SdkProcessSource } from "./sdk-records"@@ -354,7 +354,7 @@ export default class ClientProcessBoundary extends TheLink {if (operation === "service-follow") {- if (isServiceKey(target)) this.systemSubscriptions.set(subscription, { domain: "service", service: target })+ if (isServiceAddress(target)) this.systemSubscriptions.set(subscription, { domain: "service", service: target })return}@@ -1122,7 +1122,7 @@ interface EndpointSubscription {type SystemSubscriptionTarget =| Readonly<{ domain: "program", program: string }>- | Readonly<{ domain: "service", service: ServiceKey }>+ | Readonly<{ domain: "service", service: ServiceAddress }>function desktopPreferencesSubscription(subscription: EndpointSubscription) {diff --git a/source/client/view/components/desktop-host/host.ts b/source/client/view/components/desktop-host/host.tsindex 2a303b2..3f52b5d 100644--- a/source/client/view/components/desktop-host/host.ts+++ b/source/client/view/components/desktop-host/host.ts@@ -11,7 +11,7 @@ import { sdkProcess, sdkProgram } from "./sdk-records"import { type default as ClientProgram } from "@client/core/link-manager/auth-manager/program-manager/program"import { type default as ClientProcess } from "@client/core/link-manager/auth-manager/process-manager/process"import {- isServiceKey,+ isServiceAddress,isUploadFile,parseDesktopPreferencesUpdate,parsePermissionName,@@ -106,7 +106,7 @@ export default function host(authManager: AuthManager, pane: string, viewport: (function permittedService(value: unknown) {- if (!isServiceKey(value)) throw new Error("A complete service key is required")+ if (!isServiceAddress(value)) throw new Error("A complete Service address is required")return access.service(value)}@@ -374,11 +374,25 @@ export default function host(authManager: AuthManager, pane: string, viewport: (return [await processManager.endpointIsService(pane, address(target), endpoint)]}- if (word === "service-exists") {+ if (word === "host-service-list" || word === "host-service-search") {++ const name = word === "host-service-search" ? args[0] : undefined++ if (name !== undefined && (typeof name !== "string" || !name.trim())) throw new Error("A Service name is required")++ const services = await processManager.listServices(name)+ const visible = []++ for (const service of services) if (await access.canService(service)) visible.push(service)++ return [visible]+ }++ if (word === "service-available") {const service = await permittedService(args[0])- return [await processManager.serviceExists(service)]+ return [await processManager.serviceAvailable(service)]}if (word === "service-wait-ready") {@@ -388,21 +402,28 @@ export default function host(authManager: AuthManager, pane: string, viewport: (return [await processManager.waitServiceReady(service, args[1] as number | undefined)]}+ if (word === "service-program-metadata") {++ const service = await permittedService(args[0])++ return [await processManager.serviceProgramMetadata(service, args[1] as ProgramIconSize | undefined)]+ }+if (word === "service-follow") {- const [subscription, key, scope, event] = args+ const [subscription, address, scope, event] = args- if (typeof subscription !== "string" || !isServiceKey(key)) return []+ if (typeof subscription !== "string" || !isServiceAddress(address)) return []if (scope !== "lifecycle" && scope !== "events") return []if (event !== null && typeof event !== "string") return []- await access.service(key)+ if (!await access.canService(address)) return []const owner = frameOwner()- if (owner) await processManager.followService(pane, owner, subscription, key, scope, event)+ if (owner) await processManager.followService(pane, owner, subscription, address, scope, event)return []}@@ -418,7 +439,7 @@ export default function host(authManager: AuthManager, pane: string, viewport: (if (word === "service-send") {- if (!isServiceKey(args[0]) || typeof args[1] !== "string") return []+ if (!isServiceAddress(args[0]) || typeof args[1] !== "string") return []const service = await access.service(args[0])@@ -429,7 +450,7 @@ export default function host(authManager: AuthManager, pane: string, viewport: (if (word === "service-ask") {- if (!isServiceKey(args[0]) || args[0].endpoint !== "server") throw new Error("Only a Server service can be asked")+ if (!isServiceAddress(args[0]) || args[0].endpoint !== "server") throw new Error("Only a Server service can be asked")const service = await access.service(args[0])@@ -842,7 +863,7 @@ export default function host(authManager: AuthManager, pane: string, viewport: (if (word === "windowPresentationGeometry") {const target = presentationProcess(args[0])- await presentation.geometry(target.identity, presentationGeometry(args[1]), selectedTransaction(target))+ await presentation.setGeometry(target.identity, presentationGeometry(args[1]), selectedTransaction(target))return []}@@ -851,20 +872,20 @@ export default function host(authManager: AuthManager, pane: string, viewport: (const target = presentationProcess(args[0])const title = String(args[1] ?? "").trim()if (!title) throw new Error("A Window title must not be empty")- presentation.title(target.identity, title)+ presentation.setTitle(target.identity, title)return []}if (word === "windowPresentationHeader") {const target = presentationProcess(args[0])if (typeof args[1] !== "boolean") throw new Error("Window presentation header state must be true or false")- presentation.header(target.identity, args[1])+ presentation.setHeader(target.identity, args[1])return []}if (word === "windowPresentationFrame") {const target = presentationProcess(args[0])- await presentation.frame(target.identity, presentationFrame(args[1]), selectedTransaction(target))+ await presentation.setFrame(target.identity, presentationFrame(args[1]), selectedTransaction(target))return []}@@ -910,32 +931,32 @@ export default function host(authManager: AuthManager, pane: string, viewport: (return []}- if (word === "changeTitle") {+ if (word === "setTitle") {- await windowOf(await permittedProcess(args[0])).changeTitle(String(args[1] ?? ""))+ await windowOf(await permittedProcess(args[0])).setTitle(String(args[1] ?? ""))return [pane]}- if (word === "changeHeader") {+ if (word === "setHeader") {if (typeof args[1] !== "boolean") throw new Error("Window header state must be true or false")- await windowOf(await permittedProcess(args[0])).changeHeader(args[1])+ await windowOf(await permittedProcess(args[0])).setHeader(args[1])return [pane]}- if (word === "changeFrame") {+ if (word === "setFrame") {- await windowOf(await permittedProcess(args[0])).changeFrame(args[1] as never)+ await windowOf(await permittedProcess(args[0])).setFrame(args[1] as never)return [pane]}- if (word === "changeOpeningTransaction") {+ if (word === "setTransaction") {- await windowOf(await permittedProcess(args[0])).changeOpeningTransaction(args[1] as never)+ await windowOf(await permittedProcess(args[0])).setTransaction(args[1] as never)return [pane]}diff --git a/source/client/view/components/desktop-host/system-access.ts b/source/client/view/components/desktop-host/system-access.tsindex a89d8bd..93d938c 100644--- a/source/client/view/components/desktop-host/system-access.ts+++ b/source/client/view/components/desktop-host/system-access.ts@@ -1,7 +1,7 @@import type AuthManager from "@client/core/link-manager/auth-manager/auth-manager"import type Program from "@client/core/link-manager/auth-manager/program-manager/program"import type Process from "@client/core/link-manager/auth-manager/process-manager/process"-import { parseLaunch, type ClientLaunch, type ConnectionSnapshot, type PermissionName, type PermissionValue, type ServiceKey } from "@phreshos/core"+import { parseLaunch, type ClientLaunch, type ConnectionSnapshot, type PermissionName, type PermissionValue, type ServiceAddress } from "@phreshos/core"const denied = "Execution is not permitted"@@ -20,11 +20,6 @@ export default class SystemAccess {return this.owner().program === process.program}- public serviceProgram(service: ServiceKey) {-- return service.program ?? this.authManager.processManager.processes.get(service.process)?.program ?? null- }-public async all() {return await this.authManager.grantsPermission(this.pane, "all", [])@@ -42,13 +37,9 @@ export default class SystemAccess {|| await this.authManager.grantsPermission(this.pane, "programs", [process.program])}- public async canService(service: ServiceKey) {-- const program = this.serviceProgram(service)-- if (program !== null && this.owner().program === program) return true+ public async canService(service: ServiceAddress) {- return await this.authManager.grantsPermission(this.pane, "services", program === null ? [] : [program])+ return await this.authManager.grantsPermission(this.pane, "services", [service.process])}/** Whether one Connection belongs to this Client's visible scope. */@@ -103,9 +94,9 @@ export default class SystemAccess {return process}- public async service(service: ServiceKey) {+ public async service(service: ServiceAddress) {- if (!await this.canService(service)) throw new Error("The Service represented by this key does not exist")+ if (!await this.canService(service)) throw new Error("Execution is not permitted")return service}diff --git a/source/client/view/components/desktop-host/window-presentation.ts b/source/client/view/components/desktop-host/window-presentation.tsindex 6c457ff..854ec36 100644--- a/source/client/view/components/desktop-host/window-presentation.ts+++ b/source/client/view/components/desktop-host/window-presentation.ts@@ -34,14 +34,14 @@ export interface WindowPresentationHost {read(identity: string, property: WindowPresentationProperty): unknownmove(identity: string, position: Position, transaction?: PresentationTransactionRequest): Promise<void>resize(identity: string, size: Size, transaction?: PresentationTransactionRequest): Promise<void>- geometry(identity: string, geometry: WindowGeometry, transaction?: PresentationTransactionRequest): Promise<void>+ setGeometry(identity: string, geometry: WindowGeometry, transaction?: PresentationTransactionRequest): Promise<void>maximize(identity: string, maximized: boolean, transaction?: PresentationTransactionRequest): Promise<void>minimize(identity: string, minimized: boolean, transaction?: PresentationTransactionRequest): Promise<void>follow(identity: string, transaction?: PresentationTransactionRequest): Promise<void>unfollow(identity: string): Promise<void>- title(identity: string, title: string): void- header(identity: string, header: boolean): void- frame(identity: string, frame: WindowFrame, transaction?: PresentationTransactionRequest): Promise<void>+ setTitle(identity: string, title: string): void+ setHeader(identity: string, header: boolean): void+ setFrame(identity: string, frame: WindowFrame, transaction?: PresentationTransactionRequest): Promise<void>raise(identity: string): voidobserve(identity: string, event: string | null, listener: (event: string, value: unknown) => void): () => voidcomplete(identity: string, kind: "geometry" | "minimize" | "frame", revision: number): void@@ -64,7 +64,11 @@ export function presentationSize(value: unknown): Size {export function presentationGeometry(value: unknown): WindowGeometry {const record = plain(value, "Window presentation geometry")- return Object.freeze({ position: presentationPosition(record.position), size: presentationSize(record.size) })+ valueTerm(record.x, "x")+ valueTerm(record.y, "y")+ valueTerm(record.width, "width")+ valueTerm(record.height, "height")+ return Object.freeze({ x: record.x, y: record.y, width: record.width, height: record.height }) as WindowGeometry}export function presentationFrame(value: unknown) {diff --git a/source/client/view/components/window-manager/window-manager.ts b/source/client/view/components/window-manager/window-manager.tsindex 23afe97..123ea73 100644--- a/source/client/view/components/window-manager/window-manager.ts+++ b/source/client/view/components/window-manager/window-manager.ts@@ -278,9 +278,9 @@ export default function useWindows(authManager: AuthManager) {return}- const geometry = { position, size: { width, height } }+ const geometry = { ...position, width, height }- void presentation.geometry(process.identity, geometry)+ void presentation.setGeometry(process.identity, geometry)commit(window.setGeometry(geometry))@@ -292,9 +292,9 @@ export default function useWindows(authManager: AuthManager) {if (!window || window.layer !== "window") return- const geometry = { position, size }+ const geometry = { ...position, ...size }- void presentation.geometry(process.identity, geometry)+ void presentation.setGeometry(process.identity, geometry)commit(window.setGeometry(geometry))@@ -400,12 +400,9 @@ export default function useWindows(authManager: AuthManager) {if (!window || window.layer !== "window") continue- const geometry = {- position: { x: region.x, y: region.y },- size: { width: region.width, height: region.height }- }+ const geometry = { ...region }- void presentation.geometry(identity, geometry)+ void presentation.setGeometry(identity, geometry)commit(window.setGeometry(geometry))}diff --git a/source/client/view/components/window-manager/window-presentations.ts b/source/client/view/components/window-manager/window-presentations.tsindex f7bba5e..b702a7a 100644--- a/source/client/view/components/window-manager/window-presentations.ts+++ b/source/client/view/components/window-manager/window-presentations.ts@@ -62,6 +62,7 @@ export default class WindowPresentations implements WindowPresentationHost {this.following.set(identity, { snapshot })}if (!next.has(identity)) next.set(identity, initialPresentationState(client))+ else next.set(identity, { ...next.get(identity)!, transaction: snapshot.transaction })this.authoritative.set(identity, snapshot)}@@ -74,7 +75,7 @@ export default class WindowPresentations implements WindowPresentationHost {const state = next.get(identity)!const target = this.authoritative.get(identity)!const previous = relation.snapshot- const changes = { ...followedState(state, target, previous) }+ const changes = { transaction: target.transaction, ...followedState(state, target, previous) }const maximized = changes.maximized ?? state.maximizedconst minimized = changes.minimized ?? state.minimizedconst geometryChanged = ("position" in changes && JSON.stringify(state.position) !== JSON.stringify(changes.position))@@ -199,17 +200,17 @@ export default class WindowPresentations implements WindowPresentationHost {const { identity, state } = this.existing(process)requirePresentationApplication(state.layer, "position")- return this.changeGeometry(identity, { position, size: state.size }, transaction)+ return this.changeGeometry(identity, { ...position, ...state.size }, transaction)}public resize(process: string, size: WindowState["size"], transaction?: PresentationTransactionRequest) {const { identity, state } = this.existing(process)requirePresentationApplication(state.layer, "size")- return this.changeGeometry(identity, { position: state.position, size }, transaction)+ return this.changeGeometry(identity, { ...state.position, ...size }, transaction)}- public geometry(process: string, value: WindowGeometry, transaction?: PresentationTransactionRequest) {+ public setGeometry(process: string, value: WindowGeometry, transaction?: PresentationTransactionRequest) {const { identity, state } = this.existing(process)requirePresentationApplication(state.layer, "position")@@ -228,7 +229,7 @@ export default class WindowPresentations implements WindowPresentationHost {requirePresentationApplication(state.layer, "maximized")if (state.maximized === maximized) return Promise.resolve()this.cancel(identity, "geometry")- const animation = !state.minimized ? presentationAnimation(++this.revision, transaction) : null+ const animation = !state.minimized ? presentationAnimation(++this.revision, state.transaction, transaction) : nullthis.replace(identity, { ...state, maximized, geometryAnimation: animation })return this.waitFor(identity, "geometry", animation, transaction)}@@ -243,8 +244,8 @@ export default class WindowPresentations implements WindowPresentationHost {const visibilityChanged = current.minimized !== projected.minimizedthis.cancel(identity, "geometry")this.cancel(identity, "minimize")- const geometryAnimation = geometryChanged && !projected.minimized ? presentationAnimation(++this.revision, transaction) : null- const minimizeAnimation = visibilityChanged ? presentationAnimation(++this.revision, transaction) : null+ const geometryAnimation = geometryChanged && !projected.minimized ? presentationAnimation(++this.revision, projected.transaction, transaction) : null+ const minimizeAnimation = visibilityChanged ? presentationAnimation(++this.revision, projected.transaction, transaction) : nullthis.replace(identity, {...projected,geometryAnimation,@@ -262,14 +263,14 @@ export default class WindowPresentations implements WindowPresentationHost {return Promise.resolve()}- public title(process: string, title: string) {+ public setTitle(process: string, title: string) {const { identity, state } = this.existing(process)requirePresentationApplication(state.layer, "title")this.replace(identity, { ...state, title })}- public header(process: string, header: boolean) {+ public setHeader(process: string, header: boolean) {const { identity, state } = this.existing(process)requirePresentationApplication(state.layer, "header")@@ -302,14 +303,14 @@ export default class WindowPresentations implements WindowPresentationHost {}}- public frame(process: string, frame: WindowFrame, transaction?: PresentationTransactionRequest) {+ public setFrame(process: string, frame: WindowFrame, transaction?: PresentationTransactionRequest) {const { identity, state } = this.existing(process)requirePresentationApplication(state.layer, "frame")if (JSON.stringify(state.frame) === JSON.stringify(frame)) return Promise.resolve()this.cancel(identity, "frame")- const animation = presentationAnimation(++this.revision, transaction)+ const animation = presentationAnimation(++this.revision, state.transaction, transaction)this.replace(identity, { ...state, frame, frameAnimation: animation })return this.waitFor(identity, "frame", animation, transaction)}@@ -385,15 +386,17 @@ export default class WindowPresentations implements WindowPresentationHost {const state = this.windows.get(identity)if (!state) throw new Error("This Client has no Window presentation")- if (JSON.stringify([state.position, state.size]) === JSON.stringify([value.position, value.size])) return Promise.resolve()+ const position = { x: value.x, y: value.y }+ const size = { width: value.width, height: value.height }+ if (JSON.stringify([state.position, state.size]) === JSON.stringify([position, size])) return Promise.resolve()if (state.minimized || state.maximized) {- this.replace(identity, { ...state, position: value.position, size: value.size })+ this.replace(identity, { ...state, position, size })return Promise.resolve()}this.cancel(identity, "geometry")- const animation = presentationAnimation(++this.revision, transaction)- this.replace(identity, { ...state, position: value.position, size: value.size, geometryAnimation: animation })+ const animation = presentationAnimation(++this.revision, state.transaction, transaction)+ this.replace(identity, { ...state, position, size, geometryAnimation: animation })return this.waitFor(identity, "geometry", animation, transaction)}@@ -405,7 +408,7 @@ export default class WindowPresentations implements WindowPresentationHost {this.cancel(identity, "minimize")if (minimized) this.cancel(identity, "geometry", "The Window presentation was minimized")- const animation = presentationAnimation(++this.revision, transaction)+ const animation = presentationAnimation(++this.revision, state.transaction, transaction)this.replace(identity, { ...state, minimized, minimizeAnimation: animation, geometryAnimation: minimized ? null : state.geometryAnimation })return this.waitFor(identity, "minimize", animation, transaction)}@@ -436,7 +439,6 @@ export default class WindowPresentations implements WindowPresentationHost {const moved = JSON.stringify(previous.position) !== JSON.stringify(current.position)const resized = JSON.stringify(previous.size) !== JSON.stringify(current.size)- if (moved || resized) emit("position", "geometry", { position: current.position, size: current.size })if (moved) emit("position", "move", current.position)if (resized) emit("size", "resize", current.size)if (previous.minimized !== current.minimized) emit("minimized", "minimize", current.minimized)@@ -484,9 +486,11 @@ function animationKey(identity: string, kind: AnimationKind) {return `${identity}:${kind}`}-function presentationAnimation(revision: number, request?: PresentationTransactionRequest) {+function presentationAnimation(revision: number, fallback: WindowState["transaction"], request?: PresentationTransactionRequest) {- const transaction = request?.transaction ?? true+ const transaction = request?.transaction === undefined || request.transaction === true+ ? fallback+ : request.transactionreturn transaction === false ? null : Object.freeze({ revision, transaction })}diff --git a/source/client/view/structure/desktop/desktop.tsx b/source/client/view/structure/desktop/desktop.tsxindex 51bd4ae..9c9c2c7 100644--- a/source/client/view/structure/desktop/desktop.tsx+++ b/source/client/view/structure/desktop/desktop.tsx@@ -131,7 +131,7 @@ export default function Workspace() {layer={presentation.layer}- openingTransaction={presentation.transaction}+ transaction={presentation.transaction}icon={icon(record)}diff --git a/source/client/view/structure/desktop/windows/process-window.tsx b/source/client/view/structure/desktop/windows/process-window.tsxindex 8e872d7..504118a 100644--- a/source/client/view/structure/desktop/windows/process-window.tsx+++ b/source/client/view/structure/desktop/windows/process-window.tsx@@ -17,7 +17,7 @@ const settleDelay = 80* props so memoization can see which process actually changed even though* the peer deliberately keeps each Process instance alive and mutates it.*/-export default memo(function ({ identity, record, assetId, client, title, header, frame, layer, openingTransaction, icon, position, size, frameAnimation, geometryAnimation, minimizeAnimation, onPresentationAnimationComplete, onPresentationRepresentation, paintSurfaceSize, depth, active, minimized, maximized, closing, stopping, entering, door, programAccess, theme, onFrame, onFrameLoad, onReady, onRaise, onMinimize, onFill, onClose, onClosed, onUnavailable, onMove, onResize, onSnap }: ProcessWindowProps) {+export default memo(function ({ identity, record, assetId, client, title, header, frame, layer, transaction, icon, position, size, frameAnimation, geometryAnimation, minimizeAnimation, onPresentationAnimationComplete, onPresentationRepresentation, paintSurfaceSize, depth, active, minimized, maximized, closing, stopping, entering, door, programAccess, theme, onFrame, onFrameLoad, onReady, onRaise, onMinimize, onFill, onClose, onClosed, onUnavailable, onMove, onResize, onSnap }: ProcessWindowProps) {const activate = useCallback(() => onRaise(record), [onRaise, record])@@ -100,7 +100,7 @@ export default memo(function ({ identity, record, assetId, client, title, headerlayer={layer}- openingTransaction={openingTransaction}+ transaction={transaction}icon={icon}@@ -220,7 +220,7 @@ interface ProcessWindowProps {layer: WindowLayer- openingTransaction: WindowTransaction+ transaction: WindowTransactionicon: stringdiff --git a/source/client/view/structure/desktop/windows/window-frame.tsx b/source/client/view/structure/desktop/windows/window-frame.tsxindex de413d0..beeb1da 100644--- a/source/client/view/structure/desktop/windows/window-frame.tsx+++ b/source/client/view/structure/desktop/windows/window-frame.tsx@@ -84,7 +84,7 @@ function frameColor(frame: Exclude<WindowFrameDefinition, false>): Color | undeffunction frameMaterial(frame: Exclude<WindowFrameDefinition, false>): "none" | "full" | MaterialOptions {- if (frame === true || frame.material === undefined || frame.material === true) return "full"+ if (frame === true || frame.material === undefined) return "full"if (frame.material === false) return "none"diff --git a/source/client/view/structure/desktop/windows/window.tsx b/source/client/view/structure/desktop/windows/window.tsxindex 6220f4f..dbb5157 100644--- a/source/client/view/structure/desktop/windows/window.tsx+++ b/source/client/view/structure/desktop/windows/window.tsx@@ -50,7 +50,7 @@ const edges: { edge: WindowEdge, className: string }[] = [const minimizedSurfacePose = { scale: 0.86, y: 28, opacity: 0 }-export default function ({ title, header = true, frame: frameDefinition = false, layer, icon, children, onClose, onClosed, onMinimize, onMaximize, onActivate, onUnavailable, onMove, onResize, onSnap, onPresentationAnimationComplete, onPresentationRepresentation, onFocusCapture, active = false, closing = false, stopping = false, minimized = false, maximized = false, entering = false, openingTransaction = false, position = { x: 0, y: 0 }, size = { width: 520, height: 340 }, frameAnimation, geometryAnimation, minimizeAnimation, paintSurfaceSize = { width: 0, height: 0 }, minWidth = minimumWindowSize.width, minHeight = minimumWindowSize.height, className, style, ...props }: WindowProps) {+export default function ({ title, header = true, frame: frameDefinition = false, layer, icon, children, onClose, onClosed, onMinimize, onMaximize, onActivate, onUnavailable, onMove, onResize, onSnap, onPresentationAnimationComplete, onPresentationRepresentation, onFocusCapture, active = false, closing = false, stopping = false, minimized = false, maximized = false, entering = false, transaction = false, position = { x: 0, y: 0 }, size = { width: 520, height: 340 }, frameAnimation, geometryAnimation, minimizeAnimation, paintSurfaceSize = { width: 0, height: 0 }, minWidth = minimumWindowSize.width, minHeight = minimumWindowSize.height, className, style, ...props }: WindowProps) {const reducedMotion = useReducedMotion()const appearanceTransaction = useAppearance().transaction@@ -146,10 +146,10 @@ export default function ({ title, header = true, frame: frameDefinition = false,}, [minimizeAnimation?.revision, reducedMotion])- const configuredOpeningTransaction = layer === "under" || layer === "over"- ? resolveWindowTransaction(openingTransaction, appearanceTransaction)+ const entryTransaction = layer === "under" || layer === "over"+ ? resolveWindowTransaction(transaction, appearanceTransaction): standard ? appearanceTransaction : null- const opening = entering && !reducedMotion ? configuredOpeningTransaction : null+ const opening = entering && !reducedMotion ? entryTransaction : nullconst [opened, setOpened] = useState(opening === null)const minimizeTransaction = minimizeAnimation? resolveWindowTransaction(minimizeAnimation.transaction, appearanceTransaction)@@ -601,8 +601,8 @@ interface WindowProps extends Omit<ComponentProps<"div">, "onAnimationStart" | "/** Whether mounting this element represents a newly opened Window. */entering?: boolean- /** Opening transaction used by under and over presentations. */- openingTransaction?: WindowTransaction+ /** Default transaction used by under and over presentations. */+ transaction?: WindowTransactionposition?: Positiondiff --git a/source/server/core/link-manager/auth-manager/process-manager/client-process-forwarder.ts b/source/server/core/link-manager/auth-manager/process-manager/client-process-forwarder.tsindex e1b3d6c..256cdb3 100644--- a/source/server/core/link-manager/auth-manager/process-manager/client-process-forwarder.ts+++ b/source/server/core/link-manager/auth-manager/process-manager/client-process-forwarder.ts@@ -2,7 +2,7 @@ import AuthManager from "../auth-manager"import ProcessTraffic, { type Half, type TrafficKind } from "./process-traffic"import EndpointEvents from "./endpoint-events"import EndpointServices, { type ServiceScope } from "./endpoint-services"-import type { ServiceKey } from "@phreshos/core"+import type { ServiceAddress } from "@phreshos/core"/*** Server-host counterpart of one client Process boundary lease.@@ -141,11 +141,11 @@ export default class ClientProcessForwarder {this.endpointSubscriptions.delete(subscription)}- public followService(services: EndpointServices, subscription: string, key: ServiceKey, scope: ServiceScope, event: string | null) {+ public followService(services: EndpointServices, subscription: string, address: ServiceAddress, scope: ServiceScope, event: string | null) {this.unfollowService(subscription)- const stop = services.follow(key, scope, event, (word, payload) => {+ const stop = services.follow(address, scope, event, (word, payload) => {const values = event === null ? [word, payload] : [payload]diff --git a/source/server/core/link-manager/auth-manager/process-manager/endpoint-services.ts b/source/server/core/link-manager/auth-manager/process-manager/endpoint-services.tsindex 0ca4ad6..a90fc9a 100644--- a/source/server/core/link-manager/auth-manager/process-manager/endpoint-services.ts+++ b/source/server/core/link-manager/auth-manager/process-manager/endpoint-services.ts@@ -1,117 +1,131 @@-import { isServiceKey, type ServiceKey } from "@phreshos/core"+import { isServiceAddress, type ServiceAddress } from "@phreshos/core"import { TheLink } from "@the-link/core"import type Process from "./process"import type { Half } from "./process-traffic"-/** Routes live Endpoint services without owning their lifecycle or state. */+/** Resolves and routes the Service view of named Endpoint execution contexts. */export default class EndpointServices extends TheLink {- public constructor(private readonly resolve: (key: ServiceKey) => ServiceTarget | null) {+ private readonly active = new Set<string>()++ public constructor(+ private readonly resolve: (address: ServiceAddress) => ServiceTarget | null,+ private readonly processes: () => Iterable<Process>,+ private readonly changed: (event: "available" | "unavailable", address: ServiceAddress) => Promise<unknown> | unknown+ ) {super()}- public exists(key: unknown) {+ /** Returns the ready Service addresses currently represented by the model. */+ public list(name?: string) {++ const addresses: ServiceAddress[] = []++ for (const process of this.processes()) {++ if (process.name === null || name !== undefined && process.name !== name) continue++ for (const endpoint of ["server", "client"] as const) {- return this.target(key) !== null+ const address = this.addressOf(process, endpoint)++ if (address && this.available(address)) addresses.push(address)+ }+ }++ return addresses}- public async waitReady(key: unknown, timeout: unknown = 10_000, signal?: AbortSignal) {+ public available(value: unknown) {- const resolved = this.key(key)+ const address = this.address(value)+ const target = this.resolve(address)++ return target !== null && this.readyState(target.process, target.endpoint)+ }+ public async waitReady(value: unknown, timeout: unknown = 10_000, signal?: AbortSignal) {++ const address = this.address(value)const milliseconds = serviceTimeout(timeout)+ if (this.available(address)) return+await new Promise<void>((resolve, reject) => {let settled = false- let stopReady: () => void = () => undefined- let stopStart: () => void = () => undefined- let timer: ReturnType<typeof setTimeout> | undefined+ let stop: () => void = () => undefinedconst finish = (complete: () => void) => {if (settled) returnsettled = true- if (timer) clearTimeout(timer)- stopStart()- stopReady()+ clearTimeout(timer)+ stop()signal?.removeEventListener("abort", abort)complete()}- const abort = () => finish(() => reject(signal?.reason instanceof Error ? signal.reason : new Error("Waiting for the service was cancelled")))-- const inspect = () => {-- stopReady()- stopReady = () => undefined-- const target = this.resolve(resolved)-- if (!target) return-- stopReady = target.process.waitReady(resolved.endpoint, () => finish(resolve))- }-- stopStart = this.$inbound.subscribe(this.event(resolved, "lifecycle", "start"), inspect)- timer = setTimeout(() => finish(() => reject(new Error("The service did not become ready before the timeout"))), milliseconds)+ const abort = () => finish(() => reject(signal?.reason instanceof Error ? signal.reason : new Error("Waiting for the Service was cancelled")))+ const timer = setTimeout(() => finish(() => reject(new Error("The Service did not become available before the timeout"))), milliseconds)+ stop = this.follow(address, "lifecycle", "available", () => finish(resolve))signal?.addEventListener("abort", abort, { once: true })if (signal?.aborted) abort()- else inspect()+ else if (this.available(address)) finish(resolve)})}- public target(key: unknown, endpoint?: Half) {+ public target(value: unknown, endpoint?: Half) {- const resolved = this.key(key)- const target = this.resolve(resolved)+ const address = this.address(value)+ const target = this.resolve(address)- if (!target || endpoint && target.endpoint !== endpoint) return null+ if (!target || endpoint && target.endpoint !== endpoint || !this.readyState(target.process, target.endpoint)) return null- return this.live(target.process, target.endpoint) ? target : null+ return target}- /** Mirrors one service Endpoint emission into its identity and name routes. */+ /** Mirrors one application event through the Service's stable address. */public async emit(process: Process, endpoint: Half, event: string, payload: unknown) {- if (!this.configured(process, endpoint)) return []+ const address = this.addressOf(process, endpoint)- return await Promise.all(this.keys(process, endpoint).map(key => (- this.$inbound.publish(this.event(key, "events", event), event, payload)- )))+ if (!address || !this.available(address)) return []++ return await this.$inbound.publish(this.event(address, "events", event), event, payload)}- /** Mirrors one service Endpoint start into its identity and name routes. */- public async started(process: Process, endpoint: Half) {+ /** Re-evaluates Service availability after an Endpoint starts. */+ public started(process: Process, endpoint: Half) {++ return this.refresh(process, endpoint)+ }- if (!this.configured(process, endpoint)) return []+ /** Re-evaluates Server Service availability after it signals readiness. */+ public ready(process: Process, endpoint: Half) {- return await Promise.all(this.keys(process, endpoint).map(key => (- this.$inbound.publish(this.event(key, "lifecycle", "start"), "start", undefined)- )))+ return this.refresh(process, endpoint)}- /** Mirrors one service Endpoint stop into its identity and name routes. */- public async stopped(process: Process, endpoint: Half, service: boolean) {+ /** Removes availability after a previously configured Service Endpoint stops. */+ public stopped(process: Process, endpoint: Half, service: boolean) {- if (!service) return []+ const address = service ? this.addressOf(process, endpoint, true) : null- return await Promise.all(this.keys(process, endpoint).map(key => (- this.$inbound.publish(this.event(key, "lifecycle", "stop"), "stop", undefined)- )))+ return address ? this.transition(address, false) : Promise.resolve([])}- public follow(key: unknown, scope: Scope, event: string | null, subscriber: Subscriber) {+ public follow(value: unknown, scope: Scope, event: string | null, subscriber: Subscriber) {- const resolved = this.key(key)+ const address = this.address(value)- if (scope !== "lifecycle" && scope !== "events") throw new Error("A service subscription scope is invalid")+ if (scope !== "lifecycle" && scope !== "events") throw new Error("A Service subscription scope is invalid")- const prefix = this.prefix(resolved, scope)+ const prefix = this.prefix(address, scope)if (event !== null) return this.$inbound.subscribe(prefix + encodeURIComponent(event), (_word, payload) => subscriber(event, payload))@@ -121,11 +135,44 @@ export default class EndpointServices extends TheLink {}, prefix)}- private key(value: unknown) {+ private refresh(process: Process, endpoint: Half) {++ const address = this.addressOf(process, endpoint)++ if (!address) return Promise.resolve([])++ return this.transition(address, this.available(address))+ }++ private async transition(address: ServiceAddress, available: boolean) {++ const identity = this.identity(address)++ if (this.active.has(identity) === available) return []++ if (available) this.active.add(identity)+ else this.active.delete(identity)++ const event = available ? "available" : "unavailable"++ return await Promise.all([+ this.$inbound.publish(this.event(address, "lifecycle", event), event, undefined),+ this.changed(event, address)+ ])+ }++ private address(value: unknown) {++ if (!isServiceAddress(value)) throw new Error("A complete Service address is required")++ return Object.freeze({ program: value.program, process: value.process, endpoint: value.endpoint })+ }++ private addressOf(process: Process, endpoint: Half, previouslyConfigured = false): ServiceAddress | null {- if (!isServiceKey(value)) throw new Error("A complete service key is required")+ if (process.name === null || !previouslyConfigured && !this.configured(process, endpoint)) return null- return value+ return Object.freeze({ program: process.program.identity, process: process.name, endpoint })}private configured(process: Process, endpoint: Half) {@@ -133,30 +180,26 @@ export default class EndpointServices extends TheLink {return endpoint === "server" ? process.server?.service === true : process.client?.service === true}- private live(process: Process, endpoint: Half) {+ private readyState(process: Process, endpoint: Half) {- return endpoint === "server" ? process.server !== null : process.client !== null+ return endpoint === "server"+ ? process.server?.service === true && process.server.ready+ : process.client?.service === true}- private keys(process: Process, endpoint: Half) {+ private identity(address: ServiceAddress) {- return [- Object.freeze({ process: process.identity, endpoint }),- Object.freeze({ program: process.program.identity, process: process.identity, endpoint }),- ...process.name ? [Object.freeze({ program: process.program.identity, process: process.name, endpoint })] : []- ] satisfies ServiceKey[]+ return JSON.stringify([address.program, address.process, address.endpoint])}- private prefix(key: ServiceKey, scope: Scope) {+ private prefix(address: ServiceAddress, scope: Scope) {- return key.program === undefined- ? `process/${encodeURIComponent(key.process)}/${key.endpoint}/${scope}/`- : `program/${encodeURIComponent(key.program)}/${encodeURIComponent(key.process)}/${key.endpoint}/${scope}/`+ return `program/${encodeURIComponent(address.program)}/${encodeURIComponent(address.process)}/${address.endpoint}/${scope}/`}- private event(key: ServiceKey, scope: Scope, event: string) {+ private event(address: ServiceAddress, scope: Scope, event: string) {- return this.prefix(key, scope) + encodeURIComponent(event)+ return this.prefix(address, scope) + encodeURIComponent(event)}}@@ -164,7 +207,7 @@ export function serviceTimeout(value: unknown = 10_000) {if (typeof value !== "number" || !Number.isFinite(value) || value < 0) {- throw new Error("A service readiness timeout must be a non-negative finite number")+ throw new Error("A Service readiness timeout must be a non-negative finite number")}return valuediff --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 38babd6..372edcb 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"+type Domain = "program" | "process" | "window" | "connection" | "session" | "service"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 5ffb42c..a0bc7ee 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@@ -16,7 +16,7 @@ import EndpointEvents from "./endpoint-events"import EndpointServices, { serviceTimeout } from "./endpoint-services"import OutsideQuestions from "./outside-questions"import {- isServiceKey,+ isServiceAddress,isUploadFile,parsePermissionName,parseProgramInstallOptions,@@ -28,8 +28,9 @@ import {type PermissionName,type PermissionRequest,type PermissionValue,+ type ProgramIconSize,type ServerLaunch,- type ServiceKey,+ type ServiceAddress,type WindowGeometry,type WindowLayer,type WindowState@@ -104,7 +105,14 @@ export default class ProcessManager extends TheLink {this.authManager = authManager- this.services = new EndpointServices(key => this.resolveService(key))+ this.services = new EndpointServices(+ address => this.resolveService(address),+ () => this.processes.values(),+ (event, address) => Promise.all([+ this.hostTraffic.emitHost("service", event, address.process, address),+ this.$outbound.publish(`/service-${event}`, address)+ ])+ )this.connectTo(this.authManager, "/process")@@ -119,20 +127,15 @@ export default class ProcessManager extends TheLink {return process}- private resolveService(key: ServiceKey) {+ private resolveService(address: ServiceAddress) {- const exact = this.processes.get(key.process)- const program = key.program === undefined ? null : this.authManager.programManager.reach(key.program)- const process = key.program === undefined- ? exact- : program && exact?.program === program- ? exact- : program- ? [...this.processes.values()].find(candidate => candidate.program === program && candidate.name === key.process)- : null- const service = key.endpoint === "server" ? process?.server?.service : process?.client?.service+ const program = this.authManager.programManager.reach(address.program)+ const process = program+ ? [...this.processes.values()].find(candidate => candidate.program === program && candidate.name === address.process)+ : null+ const service = address.endpoint === "server" ? process?.server?.service : process?.client?.service- return process && service === true ? { process, endpoint: key.endpoint } : null+ return process && service === true ? { process, endpoint: address.endpoint } : null}private heldWindow(value: unknown, fallback: Process) {@@ -185,7 +188,7 @@ export default class ProcessManager extends TheLink {}/** Observe one authoritative host fact without creating a Program boundary. */- public observeHost(domain: "program" | "process" | "window" | "connection" | "session", event: string, subject: string | null, subscriber: (event: string, ...values: unknown[]) => void) {+ public observeHost(domain: "program" | "process" | "window" | "connection" | "session" | "service", event: string, subject: string | null, subscriber: (event: string, ...values: unknown[]) => void) {return this.hostTraffic.observe(domain, event, subject, (_delivery, word, ...values) => subscriber(word, ...values))}@@ -239,11 +242,13 @@ export default class ProcessManager extends TheLink {))}- public serviceExistsFromOutside(key: unknown) {+ public serviceAvailableFromOutside(address: unknown) {- return this.services.exists(key)+ return this.services.available(address)}+ public listServicesFromOutside(name?: string) { return this.services.list(name) }+public endpointIsServiceFromOutside(identity: string, endpoint: Half) {const process = this.find(identity)@@ -251,34 +256,34 @@ export default class ProcessManager extends TheLink {return endpoint === "server" ? process.server?.service === true : process.client?.service === true}- public waitServiceReadyFromOutside(key: unknown, timeout?: number) {+ public waitServiceReadyFromOutside(address: unknown, timeout?: number) {- return this.services.waitReady(key, timeout)+ return this.services.waitReady(address, timeout)}/** Publish through a Service from an owner boundary represented by `from: null`. */- public async publishServiceFromOutside(key: unknown, event: string, payload: unknown) {+ public async publishServiceFromOutside(address: unknown, event: string, payload: unknown) {- const target = this.services.target(key)+ const target = this.services.target(address)- if (!target) throw new Error("The service endpoint does not exist")+ if (!target) throw new Error("The Service is unavailable")await this.deliver(target.process.identity, target.endpoint, [event, { from: null, payload }])}/** Ask a Server Service from an owner boundary represented by `from: null`. */- public askServiceFromOutside(key: unknown, event: string, payload: unknown, timeout = 10_000, signal?: AbortSignal) {+ public askServiceFromOutside(address: unknown, event: string, payload: unknown, timeout = 10_000, signal?: AbortSignal) {- const target = this.services.target(key, "server")+ const target = this.services.target(address, "server")- if (!target) return Promise.reject(new Error("The service endpoint does not exist"))+ if (!target) return Promise.reject(new Error("The Service is unavailable"))return this.askFromOutside(target.process.identity, event, payload, timeout, signal)}- public observeServiceFromOutside(key: unknown, scope: "lifecycle" | "events", event: string | null, subscriber: (event: string, payload: unknown) => unknown) {+ public observeServiceFromOutside(address: unknown, scope: "lifecycle" | "events", event: string | null, subscriber: (event: string, payload: unknown) => unknown) {- return this.services.follow(key, scope, event, subscriber)+ return this.services.follow(address, scope, event, subscriber)}/** Publish to an Endpoint from the invoking System representation. */@@ -305,20 +310,20 @@ export default class ProcessManager extends TheLink {/** Publish through a Service from the invoking System representation. */@Subscribe("/service/publish")- protected async publishServiceForConnection(key: unknown, event: unknown, payload: unknown) {+ protected async publishServiceForConnection(address: unknown, event: unknown, payload: unknown) {if (typeof event !== "string") throw new Error("A Service event must be text")- await this.publishServiceFromOutside(key, event, payload)+ await this.publishServiceFromOutside(address, event, payload)}/** Ask a Server Service from the invoking System representation. */@Subscribe("/service/ask")- protected askServiceForConnection(key: unknown, event: unknown, payload: unknown, timeout: unknown) {+ protected askServiceForConnection(address: unknown, event: unknown, payload: unknown, timeout: unknown) {if (typeof event !== "string") throw new Error("A Service event must be text")- return this.askServiceFromOutside(key, event, payload, serviceTimeout(timeout), this.authManager.connectionSignal())+ return this.askServiceFromOutside(address, event, payload, serviceTimeout(timeout), this.authManager.connectionSignal())}// The boundary owns its server runtime transport. A stopped child remains@@ -608,7 +613,7 @@ export default class ProcessManager extends TheLink {if (observation.kind !== "events" && observation.kind !== "lifecycle") throw new Error("A Service observation kind is events or lifecycle")- stop = this.observeServiceFromOutside(observation.key, observation.kind, event, followed)+ stop = this.observeServiceFromOutside(observation.address, observation.kind, event, followed)}else throw new Error("A System observation scope is endpoint, traffic, or service")@@ -821,6 +826,8 @@ export default class ProcessManager extends TheLink {process.serverBecameReady(server)this.$outbound.publish("/server-ready", process.identity).catch(() => undefined)++ this.services.ready(process, "server").catch(() => undefined)})}@@ -912,7 +919,7 @@ export default class ProcessManager extends TheLink {return server}- private serverHostVisible(process: Process, domain: "program" | "process" | "connection" | "session" | "window", subject: string | null) {+ private serverHostVisible(process: Process, domain: "program" | "process" | "connection" | "session" | "service" | "window", subject: string | null) {const access = new SystemAccess(this, process)@@ -920,6 +927,8 @@ export default class ProcessManager extends TheLink {if (!subject) return false+ if (domain === "service") return this.grants(process.identity, "services", [subject])+if (domain === "program") {const program = [...this.authManager.programManager.programs.values()].find(entry => entry.program.reference === subject)?.program@@ -1313,18 +1322,17 @@ export default class ProcessManager extends TheLink {/** Explicit restart values replace their retained authoritative counterparts. */private applyClientLaunch(process: Process, window: Window, shape: StandardShape, launch: ClientLaunch) {- if (launch.title !== undefined && window.changeTitle(shape.title)) this.said(process.identity, "changeTitle", window.title)+ if (launch.title !== undefined && window.setTitle(shape.title)) this.said(process.identity, "changeTitle", window.title)- if (launch.header !== undefined && window.changeHeader(shape.header)) this.said(process.identity, "changeHeader", window.header)+ if (launch.header !== undefined && window.setHeader(shape.header)) this.said(process.identity, "changeHeader", window.header)- if (launch.frame !== undefined && window.changeFrame(shape.frame)) this.said(process.identity, "changeFrame", window.frame)+ if (launch.frame !== undefined && window.setFrame(shape.frame)) this.said(process.identity, "changeFrame", window.frame)- if (launch.transaction !== undefined) window.changeOpeningTransaction(shape.transaction)+ if (launch.transaction !== undefined && window.setTransaction(shape.transaction)) this.said(process.identity, "changeTransaction", window.transaction)if (launch.position !== undefined && launch.size !== undefined) {- const changed = window.setGeometry({ position: shape.position, size: shape.size })+ const changed = window.setGeometry({ ...shape.position, ...shape.size })if (changed.moved || changed.resized) {- this.said(process.identity, "geometry", { position: window.position, size: window.size })if (changed.moved) this.said(process.identity, "move", window.position)if (changed.resized) this.said(process.identity, "resize", window.size)}@@ -1514,28 +1522,59 @@ export default class ProcessManager extends TheLink {return endpoint === "server" ? held.server?.service === true : held.client?.service === true}- @Connect("/service/exists")- protected async serviceExists(key: unknown) {+ @Connect("/service/available")+ protected async serviceAvailable(address: unknown) {- return this.services.exists(key)+ return this.services.available(address)+ }++ @Connect("/service/list")+ protected async listServices() { return this.services.list() }++ @Connect("/service/search")+ protected async searchServices(name: unknown) {++ if (typeof name !== "string" || !name.trim()) throw new Error("A Service name is required")++ return this.services.list(name)}@Connect("/service/wait-ready")- protected async waitServiceReady(key: unknown, timeout: unknown) {+ protected async waitServiceReady(address: unknown, timeout: unknown) {- await this.services.waitReady(key, timeout, this.authManager.connectionSignal())+ await this.services.waitReady(address, timeout, this.authManager.connectionSignal())+ }++ @Connect("/service/program-metadata")+ protected async serviceProgramMetadata(address: unknown, iconSize: unknown = "medium") {++ if (!isServiceAddress(address)) throw new Error("A complete Service address is required")++ const target = this.services.target(address)++ if (!target) throw new Error("The Service is unavailable")++ const program = target.process.program+ const icon = await this.authManager.programManager.icon(program, iconSize)+ const current = this.services.target(address)++ if (!current || current.process !== target.process || current.endpoint !== target.endpoint) {+ throw new Error("The Service is unavailable")+ }++ return Object.freeze({ name: program.name, version: program.version, icon })}@Subscribe("/service/send")- protected async sendClientService(source: string, key: unknown, event: unknown, payload: unknown) {+ protected async sendClientService(source: string, address: unknown, event: unknown, payload: unknown) {- if (!isServiceKey(key) || typeof event !== "string") return+ if (!isServiceAddress(address) || typeof event !== "string") returnconst process = this.find(source)if (!process.client) return- const target = this.services.target(key)+ const target = this.services.target(address)if (target) await this.publish(process.identity, "client", target.process.identity, target.endpoint, [event, payload])}@@ -1597,17 +1636,17 @@ export default class ProcessManager extends TheLink {}@Subscribe("/frame/service/follow")- protected followClientService(pane: string, owner: string, subscription: unknown, key: unknown, scope: unknown, event: unknown) {+ protected followClientService(pane: string, owner: string, subscription: unknown, address: unknown, scope: unknown, event: unknown) {const boundary = this.clientForwarders.get(this.clientOwnerKey(this.authManager.connection(), pane))- if (boundary?.owner !== owner || typeof subscription !== "string" || !isServiceKey(key)) return+ if (boundary?.owner !== owner || typeof subscription !== "string" || !isServiceAddress(address)) returnif (scope !== "lifecycle" && scope !== "events") returnif (event !== null && typeof event !== "string") return- boundary.followService(this.services, subscription, key, scope, event)+ boundary.followService(this.services, subscription, address, scope, event)}@Subscribe("/frame/service/unfollow")@@ -1631,13 +1670,13 @@ export default class ProcessManager extends TheLink {}/** Announces one fact only through an authoritative Host registry. */- public async announceHost(domain: "program" | "process" | "connection" | "session", event: string, subject: string, ...values: unknown[]) {+ public async announceHost(domain: "program" | "process" | "connection" | "session" | "service", event: string, subject: string, ...values: unknown[]) {await this.hostTraffic.emitHost(domain, event, subject, ...values)}/** Announces one fact only to observers of an exact Program or Process subject. */- public async announceSubject(domain: "program" | "process" | "connection" | "session", event: string, subject: string, ...values: unknown[]) {+ public async announceSubject(domain: "program" | "process" | "connection" | "session" | "service", event: string, subject: string, ...values: unknown[]) {await this.hostTraffic.emitSubject(domain, event, subject, ...values)}@@ -1756,14 +1795,9 @@ export default class ProcessManager extends TheLink {const heldService = (value: unknown) => {- if (!isServiceKey(value)) throw new Error("A complete Service key is required")-- const program = value.program ?? this.services.target(value)?.process.program.identity ?? null+ if (!isServiceAddress(value)) throw new Error("A complete Service address is required")- if (program !== process.program.identity && !this.grants(process.identity, "services", program === null ? [] : [program])) {-- throw new Error("The Service represented by this key does not exist")- }+ if (!this.grants(process.identity, "services", [value.process])) throw new Error("Execution is not permitted")return value}@@ -2109,21 +2143,36 @@ export default class ProcessManager extends TheLink {if (word === "stop-current") return [await this.system.stopEndpoint(process, "server")]- if (word === "service-exists") return [this.services.exists(heldService(rest[0]))]+ if (word === "host-service-list") return [this.services.list().filter(address => this.grants(process.identity, "services", [address.process]))]++ if (word === "host-service-search") {++ const name = rest[0]++ if (typeof name !== "string" || !name.trim()) throw new Error("A Service name is required")++ return [this.grants(process.identity, "services", [name]) ? this.services.list(name) : []]+ }++ if (word === "service-available") return [this.services.available(heldService(rest[0]))]if (word === "service-wait-ready") return [await this.services.waitReady(heldService(rest[0]), rest[1])]+ if (word === "service-program-metadata") return [await this.serviceProgramMetadata(heldService(rest[0]), rest[1] as ProgramIconSize | undefined)]+if (word === "service-follow") {- const [subscription, key, scope, event] = rest+ const [subscription, address, scope, event] = rest- if (typeof subscription !== "string" || !isServiceKey(key)) return []+ if (typeof subscription !== "string" || !isServiceAddress(address)) return []if (scope !== "lifecycle" && scope !== "events") return []if (event !== null && typeof event !== "string") return []- server.followService(this.services, subscription, heldService(key), scope, event)+ if (!this.grants(process.identity, "services", [address.process])) return []++ server.followService(this.services, subscription, address, scope, event)return []}@@ -2137,11 +2186,11 @@ export default class ProcessManager extends TheLink {if (word === "service-send") {- const [key, event, payload] = rest+ const [address, event, payload] = rest- if (!isServiceKey(key) || typeof event !== "string") return []+ if (!isServiceAddress(address) || typeof event !== "string") return []- const target = this.services.target(heldService(key))+ const target = this.services.target(heldService(address))if (target) await this.publish(process.identity, "server", target.process.identity, target.endpoint, [event, payload])@@ -2150,20 +2199,20 @@ export default class ProcessManager extends TheLink {if (word === "service-ask") {- const [key, question, publicQuestion, event, payload] = rest+ const [address, question, publicQuestion, event, payload] = rest- if (!isServiceKey(key) || key.endpoint !== "server" || typeof question !== "string" || typeof publicQuestion !== "string" || typeof event !== "string") {+ if (!isServiceAddress(address) || address.endpoint !== "server" || typeof question !== "string" || typeof publicQuestion !== "string" || typeof event !== "string") {if (typeof question === "string") this.rejectQuestion(["wait", question, publicQuestion, event, payload], "A Server service question is invalid")return []}- const target = this.services.target(heldService(key), "server")+ const target = this.services.target(heldService(address), "server")if (!target?.process.server) {- this.rejectQuestion(["wait", question, publicQuestion, event, payload], "The service endpoint does not exist")+ this.rejectQuestion(["wait", question, publicQuestion, event, payload], "The Service is unavailable")return []}@@ -2229,38 +2278,38 @@ export default class ProcessManager extends TheLink {return [target.identity]}- if (word === "changeTitle") {+ if (word === "setTitle") {const target = heldWindow(rest[0]).process- await this.system.changeWindowTitle(target, String(rest[1] ?? ""))+ await this.system.setWindowTitle(target, String(rest[1] ?? ""))return [target.identity]}- if (word === "changeHeader") {+ if (word === "setHeader") {const target = heldWindow(rest[0]).process- await this.system.changeWindowHeader(target, rest[1] as boolean)+ await this.system.setWindowHeader(target, rest[1] as boolean)return [target.identity]}- if (word === "changeFrame") {+ if (word === "setFrame") {const target = heldWindow(rest[0]).process- await this.system.changeWindowFrame(target, rest[1] as never)+ await this.system.setWindowFrame(target, rest[1] as never)return [target.identity]}- if (word === "changeOpeningTransaction") {+ if (word === "setTransaction") {const target = heldWindow(rest[0]).process- await this.system.changeWindowOpeningTransaction(target, rest[1] as never)+ await this.system.setWindowTransaction(target, rest[1] as never)return [target.identity]}@@ -2967,22 +3016,22 @@ export default class ProcessManager extends TheLink {}@Subscribe("/frame/service/ask")- protected askClientService(source: string, key: unknown, values: unknown[]) {+ protected askClientService(source: string, address: unknown, values: unknown[]) {const connection = this.authManager.connection()- if (!isServiceKey(key) || key.endpoint !== "server" || typeof values[0] !== "string" || typeof values[1] !== "string" || typeof values[2] !== "string") {+ if (!isServiceAddress(address) || address.endpoint !== "server" || typeof values[0] !== "string" || typeof values[1] !== "string" || typeof values[2] !== "string") {this.rejectClientQuestion(connection, source, ["wait", ...values], "A Server service question is invalid")return}- const target = this.services.target(key, "server")+ const target = this.services.target(address, "server")if (!target || !this.retainClientQuestion(connection, source, values[0], target.process.identity)) {- this.rejectClientQuestion(connection, source, ["wait", ...values], "The service endpoint does not exist")+ this.rejectClientQuestion(connection, source, ["wait", ...values], "The Service is unavailable")return}@@ -3121,7 +3170,7 @@ export default class ProcessManager extends TheLink {return { identity, window }}- @Connect("/geometry")+ @Connect("/set-geometry")public async setGeometry(identity: string, geometry: WindowGeometry) {const window = this.mutableWindowOf(identity)@@ -3130,8 +3179,6 @@ export default class ProcessManager extends TheLink {if (!changed.moved && !changed.resized) return { identity, window }- this.said(identity, "geometry", { position: window.position, size: window.size })-if (changed.moved) this.said(identity, "move", window.position)if (changed.resized) this.said(identity, "resize", window.size)@@ -3139,48 +3186,50 @@ export default class ProcessManager extends TheLink {return { identity, window }}- @Connect("/change-title")- public async changeTitle(identity: string, title: string) {+ @Connect("/set-title")+ public async setTitle(identity: string, title: string) {const window = this.mutableWindowOf(identity)- if (!window.changeTitle(title)) return { identity, window }+ if (!window.setTitle(title)) return { identity, window }this.said(identity, "changeTitle", window.title)return { identity, window }}- @Connect("/change-header")- public async changeHeader(identity: string, header: boolean) {+ @Connect("/set-header")+ public async setHeader(identity: string, header: boolean) {const window = this.mutableWindowOf(identity)- if (!window.changeHeader(header)) return { identity, window }+ if (!window.setHeader(header)) return { identity, window }this.said(identity, "changeHeader", window.header)return { identity, window }}- @Connect("/change-frame")- public async changeFrame(identity: string, frame: import("@phreshos/core").WindowFrame) {+ @Connect("/set-frame")+ public async setFrame(identity: string, frame: import("@phreshos/core").WindowFrame) {const window = this.mutableWindowOf(identity)- if (!window.changeFrame(frame)) return { identity, window }+ if (!window.setFrame(frame)) return { identity, window }this.said(identity, "changeFrame", window.frame)return { identity, window }}- @Connect("/change-opening-transaction")- public async changeOpeningTransaction(identity: string, transaction: import("@phreshos/core").WindowTransaction) {+ @Connect("/set-transaction")+ public async setTransaction(identity: string, transaction: import("@phreshos/core").WindowTransaction) {const window = this.mutableWindowOf(identity)- window.changeOpeningTransaction(transaction)+ if (!window.setTransaction(transaction)) return { identity, window }++ this.said(identity, "changeTransaction", window.transaction)return { identity, window }}diff --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 ecc6f0b..55b2267 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@@ -3,7 +3,7 @@ import ProcessTraffic, { type Half, type TrafficKind } from "./process-traffic"import HostTraffic from "./host-traffic"import EndpointEvents from "./endpoint-events"import EndpointServices, { type ServiceScope } from "./endpoint-services"-import type { ServiceKey } from "@phreshos/core"+import type { ServiceAddress } from "@phreshos/core"import { Tunnel } from "@the-link/core"import type { ServerRuntime, Stream } from "@server/core/server-runtime"@@ -214,11 +214,11 @@ export default class ServerProcessBoundary extends TheLink {}/** Follow one exact service route for this boundary's lifetime. */- public followService(services: EndpointServices, subscription: string, key: ServiceKey, scope: ServiceScope, event: string | null) {+ public followService(services: EndpointServices, subscription: string, address: ServiceAddress, scope: ServiceScope, event: string | null) {this.unfollowService(subscription)- const stop = services.follow(key, scope, event, (word, payload) => {+ const stop = services.follow(address, scope, event, (word, payload) => {const values = event === null ? [word, payload] : [payload]@@ -371,6 +371,7 @@ export default class ServerProcessBoundary extends TheLink {: route === "host-process" || route === "process-host" ? "process": route === "host-connection" || route === "connection-host" ? "connection": route === "host-session" || route === "session-host" ? "session"+ : route === "host-service" || route === "service-host" ? "service": route === "host-end" ? "window": null@@ -380,7 +381,9 @@ export default class ServerProcessBoundary extends TheLink {this.hostSubscriptions.set(subscription, this.hostTraffic.observe(hostDomain, event, subject, (_delivery, word, ...values) => {- const eventSubject = typeof values[0] === "object" && values[0] !== null && "reference" in values[0]+ const eventSubject = hostDomain === "service" && typeof values[0] === "string"+ ? values[0]+ : typeof values[0] === "object" && values[0] !== null && "reference" in values[0]? String((values[0] as { reference: unknown }).reference): subject@@ -532,4 +535,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" | "window", subject: string | null) => boolean+export type HostVisibility = (domain: "program" | "process" | "connection" | "session" | "service" | "window", subject: string | null) => booleandiff --git a/source/server/core/link-manager/auth-manager/process-manager/window.ts b/source/server/core/link-manager/auth-manager/process-manager/window.tsindex 90300ff..498a338 100644--- a/source/server/core/link-manager/auth-manager/process-manager/window.ts+++ b/source/server/core/link-manager/auth-manager/process-manager/window.ts@@ -119,28 +119,28 @@ export default class Window implements Omit<WindowState, "front"> {/** Validates and commits a complete geometry without an intermediate state. */public setGeometry(geometry: WindowGeometry) {- validate(geometry.position.x, "x")+ validate(geometry.x, "x")- validate(geometry.position.y, "y")+ validate(geometry.y, "y")- validate(geometry.size.width, "width")+ validate(geometry.width, "width")- validate(geometry.size.height, "height")+ validate(geometry.height, "height")- const moved = this.position.x !== geometry.position.x || this.position.y !== geometry.position.y+ const moved = this.position.x !== geometry.x || this.position.y !== geometry.y- const resized = this.size.width !== geometry.size.width || this.size.height !== geometry.size.height+ const resized = this.size.width !== geometry.width || this.size.height !== geometry.heightif (!moved && !resized) return { moved, resized }- this.position = geometry.position+ this.position = { x: geometry.x, y: geometry.y }- this.size = geometry.size+ this.size = { width: geometry.width, height: geometry.height }return { moved, resized }}- public changeTitle(title: string) {+ public setTitle(title: string) {const said = String(title ?? "").trim()@@ -153,7 +153,7 @@ export default class Window implements Omit<WindowState, "front"> {return true}- public changeHeader(header: boolean) {+ public setHeader(header: boolean) {if (typeof header !== "boolean") throw new Error("Window header state must be true or false")@@ -164,7 +164,7 @@ export default class Window implements Omit<WindowState, "front"> {return true}- public changeFrame(frame: WindowFrame) {+ public setFrame(frame: WindowFrame) {const parsed = parseWindowFrame(frame)@@ -175,7 +175,7 @@ export default class Window implements Omit<WindowState, "front"> {return true}- public changeOpeningTransaction(transaction: WindowTransaction) {+ public setTransaction(transaction: WindowTransaction) {const parsed = parseWindowTransaction(transaction)diff --git a/source/server/core/link-manager/auth-manager/program-manager/program.ts b/source/server/core/link-manager/auth-manager/program-manager/program.tsindex d051fbb..51510ce 100644--- a/source/server/core/link-manager/auth-manager/program-manager/program.ts+++ b/source/server/core/link-manager/auth-manager/program-manager/program.ts@@ -4,7 +4,7 @@ import { dirname, isAbsolute, normalize, relative, resolve, sep } from "node:patimport { spawn } from "node:child_process"import { randomUUID } from "node:crypto"import { validateIcon } from "./icon"-import { parseLaunch, parseProgramDefinition, parseWindowFrame, parseWindowTransaction, type ProgramCommandChunk, type ProgramSnapshot } from "@phreshos/core"+import { defaultProgramVersion, parseLaunch, parseProgramDefinition, parseWindowFrame, parseWindowTransaction, type ProgramCommandChunk, type ProgramSnapshot } from "@phreshos/core"import { permissionCatalog, type DeclaredPermissions } from "@server/core/permissions"/**@@ -78,6 +78,11 @@ export default class Program {return this.config.name ?? this.config.identity}+ public get version() {++ return this.config.version ?? defaultProgramVersion+ }+// What its window is called when one opens. The window owns its// title afterwards; this is only what it is born with.public get title() {@@ -166,7 +171,7 @@ export default class Program {/** SDK Program record; internal references are consumed by the SDK boundary. */public record() {- const { version, description } = this.config+ const { description } = this.configconst server = this.serverconst client = this.client@@ -182,7 +187,7 @@ export default class Program {name: this.name,- version: version ?? null,+ version: this.version,description: description ?? null,@@ -412,7 +417,7 @@ function coherent(config: ProgramConfig) {// somewhere and there is nowhere to put it.if (config.client?.layer !== undefined && !layers.includes(config.client.layer)) throw new Error(`A client half's layer is one of ${layers.join(", ")}`)- return config+ return { ...config, version: config.version ?? defaultProgramVersion }}type Resolved<Half extends { start?: boolean, service?: boolean }> = Half extends unknowndiff --git a/source/server/core/permissions.ts b/source/server/core/permissions.tsindex 5bc696e..4040d92 100644--- a/source/server/core/permissions.ts+++ b/source/server/core/permissions.ts@@ -163,30 +163,6 @@ export class PermissionCatalog {this.definition(name)- if (name === "services") {-- const services = permissions.services- const programs = permissions.programs- const values = requested as readonly PermissionValue<"services">[]-- const covered = values.length === 0- ? this.grants("services", services ?? null, values)- || this.grants("programs", programs ?? null, values)- : values.every(value => (- this.grants("services", services ?? null, [value])- || this.grants("programs", programs ?? null, [value])- ))-- if (covered) return true-- // `programs` contributes authority to Services but does not become- // the Service permission's assignment. Only an exact `services`- // assignment replaces the `all` fallback for this capability.- if (services === undefined || services === null) return this.granted(permissions.all ?? null)-- return false- }-if (name === "desktopConnection") {if (this.allows("connections", [], permissions)) return true@@ -278,7 +254,7 @@ function unique(values: readonly string[]) {function valued(domain: PermissionValueDomain) {- if (domain === "program" || domain === "layer" || domain === "network" || domain === "storage") return true+ if (domain === "program" || domain === "service" || domain === "layer" || domain === "network" || domain === "storage") return trueif (domain === "none") return falsedomain satisfies never@@ -288,7 +264,7 @@ function valued(domain: PermissionValueDomain) {function valueCovers(domain: PermissionValueDomain, grant: string, requested: string) {- if (domain === "program" || domain === "layer") return grant === requested+ if (domain === "program" || domain === "service" || domain === "layer") return grant === requestedif (domain === "network") return networkScopeCovers(grant, requested)if (domain === "storage") return nativeStorageScopeCovers(grant, requested)if (domain === "none") return false@@ -308,12 +284,12 @@ export const permissionCatalog = new PermissionCatalog({services: {default: [],title: "Services",- description: "Access Services without broader authority over their Programs."+ description: "Access Services by their Process and Service name."},programs: {default: [],title: "Programs",- description: "Access every Program or selected Programs, including their Services."+ description: "Access every Program or selected Programs."},layers: {default: [],diff --git a/source/server/core/system.ts b/source/server/core/system.tsindex 0dce4f3..11ca8bc 100644--- a/source/server/core/system.ts+++ b/source/server/core/system.ts@@ -220,7 +220,7 @@ export default class System {})}- public observe(domain: "program" | "process" | "window" | "connection" | "session", event: string, subject: string | null, subscriber: (event: string, ...values: unknown[]) => void) {+ public observe(domain: "program" | "process" | "window" | "connection" | "session" | "service", event: string, subject: string | null, subscriber: (event: string, ...values: unknown[]) => void) {return this.processManager.observeHost(domain, event, subject, subscriber)}@@ -345,24 +345,24 @@ export default class System {await this.processManager.minimize(process.identity, minimized)}- public async changeWindowTitle(process: Process, title: string) {+ public async setWindowTitle(process: Process, title: string) {- await this.processManager.changeTitle(process.identity, title)+ await this.processManager.setTitle(process.identity, title)}- public async changeWindowHeader(process: Process, header: boolean) {+ public async setWindowHeader(process: Process, header: boolean) {- await this.processManager.changeHeader(process.identity, header)+ await this.processManager.setHeader(process.identity, header)}- public async changeWindowFrame(process: Process, frame: WindowFrame) {+ public async setWindowFrame(process: Process, frame: WindowFrame) {- await this.processManager.changeFrame(process.identity, frame)+ await this.processManager.setFrame(process.identity, frame)}- public async changeWindowOpeningTransaction(process: Process, transaction: WindowTransaction) {+ public async setWindowTransaction(process: Process, transaction: WindowTransaction) {- await this.processManager.changeOpeningTransaction(process.identity, transaction)+ await this.processManager.setTransaction(process.identity, transaction)}public async raiseWindow(process: Process) {@@ -379,7 +379,7 @@ export default class System {identity: program.identity,assetId: program.assetId,name: program.name,- version: program.config.version ?? null,+ version: program.version,description: program.config.description ?? null,installed: entry.installed,hasAgent: program.agentPath !== null,@@ -543,29 +543,31 @@ export default class System {return this.processManager.endpointIsServiceFromOutside(process.identity, endpoint)}- public serviceExists(key: unknown) {+ public serviceAvailable(address: unknown) {- return this.processManager.serviceExistsFromOutside(key)+ return this.processManager.serviceAvailableFromOutside(address)}- public waitServiceReady(key: unknown, timeout?: number) {+ public listServices(name?: string) { return this.processManager.listServicesFromOutside(name) }- return this.processManager.waitServiceReadyFromOutside(key, timeout)+ public waitServiceReady(address: unknown, timeout?: number) {++ return this.processManager.waitServiceReadyFromOutside(address, timeout)}- public publishService(key: unknown, event: string, payload: unknown) {+ public publishService(address: unknown, event: string, payload: unknown) {- return this.processManager.publishServiceFromOutside(key, event, payload)+ return this.processManager.publishServiceFromOutside(address, event, payload)}- public askService(key: unknown, event: string, payload: unknown, timeout = 10_000, signal?: AbortSignal) {+ public askService(address: unknown, event: string, payload: unknown, timeout = 10_000, signal?: AbortSignal) {- return this.processManager.askServiceFromOutside(key, event, payload, timeout, signal)+ return this.processManager.askServiceFromOutside(address, event, payload, timeout, signal)}- public observeService(key: unknown, scope: "lifecycle" | "events", event: string | null, subscriber: (event: string, payload: unknown) => unknown) {+ public observeService(address: unknown, scope: "lifecycle" | "events", event: string | null, subscriber: (event: string, payload: unknown) => unknown) {- return this.processManager.observeServiceFromOutside(key, scope, event, subscriber)+ return this.processManager.observeServiceFromOutside(address, scope, event, subscriber)}public get uploads() {diff --git a/source/shared/window-layers.ts b/source/shared/window-layers.tsindex 6df66a3..c6c5611 100644--- a/source/shared/window-layers.ts+++ b/source/shared/window-layers.ts@@ -44,32 +44,32 @@ export const windowLayerModel: Readonly<Record<WindowLayer, WindowLayerPresentattransactions: false}),under: Object.freeze({- readable: Object.freeze(["title", "frame", "position", "size", "minimized", "maximized", "front", "layer"] satisfies WindowPresentationProperty[]),- applicable: Object.freeze(["title", "frame", "position", "size", "minimized", "maximized", "front", "layer"] satisfies WindowPresentationProperty[]),+ readable: Object.freeze(["frame", "position", "size", "minimized", "maximized", "front", "layer"] satisfies WindowPresentationProperty[]),+ applicable: Object.freeze(["frame", "position", "size", "minimized", "maximized", "front", "layer"] satisfies WindowPresentationProperty[]),defaults: Object.freeze({ frame: false, header: false, transaction: false }),fixed: false,exclusive: false,transactions: true}),over: Object.freeze({- readable: Object.freeze(["title", "frame", "position", "size", "minimized", "maximized", "front", "layer"] satisfies WindowPresentationProperty[]),- applicable: Object.freeze(["title", "frame", "position", "size", "minimized", "maximized", "front", "layer"] satisfies WindowPresentationProperty[]),+ readable: Object.freeze(["frame", "position", "size", "minimized", "maximized", "front", "layer"] satisfies WindowPresentationProperty[]),+ applicable: Object.freeze(["frame", "position", "size", "minimized", "maximized", "front", "layer"] satisfies WindowPresentationProperty[]),defaults: Object.freeze({ frame: false, header: false, transaction: false }),fixed: false,exclusive: false,transactions: true}),wallpaper: Object.freeze({- readable: Object.freeze(["title", "layer"] satisfies WindowPresentationProperty[]),- applicable: Object.freeze(["title", "layer"] satisfies WindowPresentationProperty[]),+ readable: Object.freeze(["layer"] satisfies WindowPresentationProperty[]),+ applicable: Object.freeze(["layer"] satisfies WindowPresentationProperty[]),defaults: Object.freeze({ frame: false, header: false, transaction: false }),fixed: true,exclusive: true,transactions: false}),"start-menu": Object.freeze({- readable: Object.freeze(["title", "layer"] satisfies WindowPresentationProperty[]),- applicable: Object.freeze(["title", "layer"] satisfies WindowPresentationProperty[]),+ readable: Object.freeze(["layer"] satisfies WindowPresentationProperty[]),+ applicable: Object.freeze(["layer"] satisfies WindowPresentationProperty[]),defaults: Object.freeze({ frame: false, header: false, transaction: false }),fixed: true,exclusive: true,diff --git a/tests/client-layer-permissions.test.ts b/tests/client-layer-permissions.test.tsindex a7be639..4cb2bcf 100644--- a/tests/client-layer-permissions.test.ts+++ b/tests/client-layer-permissions.test.ts@@ -10,7 +10,7 @@ function fixture() {let permissions: Permissions = {}const program: ProgramSnapshot = {identity: "owner", reference: "program-reference", assetId: "assets", name: "Owner",- version: null, description: null, hasAgent: false, server: null,+ version: "0.0.0", description: null, hasAgent: false, server: null,client: { start: true, service: false, title: null, header: null, frame: null, transaction: null, size: null, position: null, layer: "over", minimize: null, maximize: null }}const process = { identity: "caller", reference: "process-reference", program: program.identity, name: null, startedAt: 0, options: {}, server: null, client: null }diff --git a/tests/client-permission-boundary.test.ts b/tests/client-permission-boundary.test.tsindex 85f310e..2c002e5 100644--- a/tests/client-permission-boundary.test.ts+++ b/tests/client-permission-boundary.test.ts@@ -8,7 +8,7 @@ test("Client Program creation requires all before reaching the creation boundarylet permissions: Permissions = { programs: [] }const program: ProgramSnapshot = {identity: "created", reference: "created-reference", assetId: "created-assets",- name: "Created", version: null, description: null, hasAgent: false,+ name: "Created", version: "0.0.0", description: null, hasAgent: false,server: null, client: null}const create = vi.fn(async () => program.identity)@@ -68,20 +68,24 @@ test("Program and Process discovery exposes only the accessible scope", async ()})test.each([- { owningProgram: "owner", denied: [], granted: [{}] },+ {+ owningProgram: "owner",+ denied: [{}, { services: ["unrelated"] }, { programs: [] }],+ granted: [{ services: ["main"] }, { services: [] }, { all: [] }]+ },{owningProgram: "outside",denied: [{},{ all: [], services: false },{ services: ["unrelated"] },- { programs: ["unrelated"] }+ { programs: ["unrelated"] },+ { programs: ["outside"] },+ { programs: [] }],granted: [- { services: ["outside"] },+ { services: ["main"] },{ services: [] },- { programs: ["outside"] },- { programs: [] },{ all: [] }]}@@ -92,8 +96,9 @@ test.each([}>)("Service operations expose only Services in the accessible scope for $owningProgram", async ({ owningProgram, denied, granted }) => {const destination = "6d138083-7a51-44ec-9abe-ff0194ad1e5b"let permissions: Permissions = {}- const serviceExists = vi.fn(async () => true)+ const serviceAvailable = vi.fn(async () => true)const waitServiceReady = vi.fn()+ const serviceProgramMetadata = vi.fn(async () => ({ name: "Provider", version: "0.0.0", icon: [] }))const followService = vi.fn()const sendService = vi.fn()const askService = vi.fn()@@ -104,35 +109,66 @@ test.each([["caller", { program: "owner" }],[destination, { program: owningProgram }]]),- serviceExists, waitServiceReady, followService, sendService, askService+ serviceAvailable, waitServiceReady, serviceProgramMetadata, followService, sendService, askService},grantsPermission: async (_pane: string, name: PermissionName, values: never[]) => permissionCatalog.allows(name, values, permissions)} as unknown as AuthManagerconst answer = host(auth, "caller", () => { throw new Error("unused viewport") }, () => "frame", {} as never)- for (const key of [{ program: owningProgram, process: "main", endpoint: "server" }, { process: destination, endpoint: "server" }]) {- const operations = [- ["service-exists", key],+ const key = { program: owningProgram, process: "main", endpoint: "server" } as const+ const operations = [+ ["service-available", key],["service-wait-ready", key],- ["service-follow", "subscription", key, "events", "change"],+ ["service-program-metadata", key, "small"],["service-send", key, "change", {}],["service-ask", key, "read", {}]] as const- for (const assignment of denied) {- permissions = assignment- for (const [operation, ...args] of operations) {- await expect(answer(operation, ...args)).rejects.toThrow("The Service represented by this key does not exist")- }- }- for (const assignment of granted) {- permissions = assignment- for (const [operation, ...args] of operations) await answer(operation, ...args)+ for (const assignment of denied) {+ permissions = assignment+ for (const [operation, ...args] of operations) {+ await expect(answer(operation, ...args)).rejects.toThrow("Execution is not permitted")}+ await expect(answer("service-follow", "subscription", key, "events", "change")).resolves.toEqual([])+ }+ for (const assignment of granted) {+ permissions = assignment+ for (const [operation, ...args] of operations) await answer(operation, ...args)+ await answer("service-follow", "subscription", key, "events", "change")}- for (const call of [serviceExists, waitServiceReady, followService, sendService, askService]) {- expect(call).toHaveBeenCalledTimes(granted.length * 2)+ for (const call of [serviceAvailable, waitServiceReady, serviceProgramMetadata, followService, sendService, askService]) {+ expect(call).toHaveBeenCalledTimes(granted.length)}})+test("Service discovery filters ready addresses only by Service-name authority", async () => {+ let permissions: Permissions = { programs: [] }+ const mainServer = { program: "notes", process: "main", endpoint: "server" } as const+ const mainClient = { program: "editor", process: "main", endpoint: "client" } as const+ const background = { program: "notes", process: "background", endpoint: "server" } as const+ const listServices = vi.fn(async (name?: string) => [mainServer, mainClient, background].filter(service => name === undefined || service.process === name))+ const auth = {+ programManager: { programs: new Map() },+ processManager: {+ processes: new Map([["caller", { program: "owner" }]]),+ listServices+ },+ grantsPermission: async (_pane: string, name: PermissionName, values: never[]) => permissionCatalog.allows(name, values, permissions)+ } as unknown as AuthManager+ const answer = host(auth, "caller", () => { throw new Error("unused viewport") }, () => "frame", {} as never)++ await expect(answer("host-service-list")).resolves.toEqual([[]])+ await expect(answer("host-service-search", "main")).resolves.toEqual([[]])++ permissions = { services: ["main"] }++ await expect(answer("host-service-list")).resolves.toEqual([[mainServer, mainClient]])+ await expect(answer("host-service-search", "main")).resolves.toEqual([[mainServer, mainClient]])+ await expect(answer("host-service-search", "background")).resolves.toEqual([[]])++ permissions = { services: [] }++ await expect(answer("host-service-list")).resolves.toEqual([[mainServer, mainClient, background]])+})+function program(identity: string): ProgramSnapshot {return {@@ -140,7 +176,7 @@ function program(identity: string): ProgramSnapshot {reference: `${identity}-reference`,assetId: `${identity}-assets`,name: identity,- version: null,+ version: "0.0.0",description: null,hasAgent: false,server: null,diff --git a/tests/client-system-access.test.ts b/tests/client-system-access.test.tsindex 77b8538..de99192 100644--- a/tests/client-system-access.test.ts+++ b/tests/client-system-access.test.ts@@ -42,20 +42,20 @@ test("client system access contract", async () => {const access = new SystemAccess(authManager, owner.identity)const ownProgram = { identity: "owner" }const outsideProgram = { identity: "outside" }- const ownService = { program: "owner", process: "main", endpoint: "server" } as const- const ownExactService = { process: sibling.identity, endpoint: "client" } as const- const outsideService = { program: "outside", process: "main", endpoint: "server" } as const+ const ownService = { program: "owner", process: "owner-service", endpoint: "server" } as const+ const siblingService = { program: "owner", process: "sibling-service", endpoint: "client" } as const+ const outsideService = { program: "outside", process: "outside-service", endpoint: "server" } as constassert(access.ownsProgram(ownProgram))assert(!access.ownsProgram(outsideProgram))assert(access.ownsProcess(sibling))assert(!access.ownsProcess(outside))assert.equal(await access.program(ownProgram as never), ownProgram)- assert.equal(await access.service(ownService), ownService)- assert.equal(await access.service(ownExactService), ownExactService)+ await assert.rejects(access.service(ownService), /Execution is not permitted/)+ await assert.rejects(access.service(siblingService), /Execution is not permitted/)await assert.rejects(access.program(outsideProgram as never), /Program represented by this handle does not exist/)await assert.rejects(access.process(outside), /Process represented by this handle does not exist/)- await assert.rejects(access.service(outsideService), /Service represented by this key does not exist/)+ await assert.rejects(access.service(outsideService), /Execution is not permitted/)await assert.rejects(access.requireAll(), /Execution is not permitted/)await assert.rejects(access.requireNetwork("https://api.example.com/v1/users"), /Execution is not permitted/)await assert.rejects(access.requireStorage("/Users/person/Documents/report.txt", "read"), /Execution is not permitted/)@@ -67,7 +67,7 @@ test("client system access contract", async () => {assert.equal(await access.canConnection("desktop-connection"), false)assert.equal(await access.canSession("desktop-session"), false)- permissions = { services: ["outside"] }+ permissions = { services: ["outside-service"] }assert.equal(await access.service(outsideService), outsideService)await assert.rejects(access.program(outsideProgram as never), /Program represented by this handle does not exist/)@@ -78,7 +78,7 @@ test("client system access contract", async () => {assert.equal(await access.service(outsideService), outsideService)assert.equal(await access.service(ownService), ownService)- assert.equal(await access.service(ownExactService), ownExactService)+ assert.equal(await access.service(siblingService), siblingService)await assert.rejects(access.program(outsideProgram as never), /Program represented by this handle does not exist/)await assert.rejects(access.requireAll(), /Execution is not permitted/)@@ -86,15 +86,14 @@ 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.service(outsideService), outsideService)- assert.deepEqual(await access.service({ process: outside.identity, endpoint: "server" }), { process: outside.identity, endpoint: "server" })+ await assert.rejects(access.service(outsideService), /Execution is not permitted/)await assert.rejects(access.requireAll(), /Execution is not permitted/)permissions = { programs: [] }await assert.rejects(access.requireAll(), /Execution is not permitted/)assert.equal(await access.program(outsideProgram as never), outsideProgram)- assert.equal(await access.service(outsideService), outsideService)+ await assert.rejects(access.service(outsideService), /Execution is not permitted/)permissions = { appearance: [], desktopPreferences: [], connections: [] }@@ -154,16 +153,13 @@ test("client system access contract", async () => {await access.require("uploads", [])await access.requireAll()- const unresolvedService = { process: "ec99e1e8-d13b-4fc8-89ed-eaa3f394a42f", endpoint: "server" } as constpermissions = { all: [], services: false }- assert.equal(await access.service(ownService), ownService)- assert.equal(await access.service(ownExactService), ownExactService)- await assert.rejects(access.service(unresolvedService), /Service represented by this key does not exist/)+ await assert.rejects(access.service(ownService), /Execution is not permitted/)+ await assert.rejects(access.service(siblingService), /Execution is not permitted/)permissions = { services: [] }- assert.equal(await access.service(unresolvedService), unresolvedService)- permissions = { services: ["owner"] }+ assert.equal(await access.service(outsideService), outsideService)+ permissions = { services: ["owner-service"] }assert.equal(await access.service(ownService), ownService)- assert.equal(await access.service(ownExactService), ownExactService)- await assert.rejects(access.service(outsideService), /Service represented by this key does not exist/)- await assert.rejects(access.service(unresolvedService), /Service represented by this key does not exist/)+ await assert.rejects(access.service(siblingService), /Execution is not permitted/)+ await assert.rejects(access.service(outsideService), /Execution is not permitted/)}, 120_000)diff --git a/tests/endpoint-services.test.ts b/tests/endpoint-services.test.tsindex 39287cb..73fa70c 100644--- a/tests/endpoint-services.test.ts+++ b/tests/endpoint-services.test.ts@@ -2,94 +2,59 @@ import assert from "node:assert/strict"import EndpointServices from "@server/core/link-manager/auth-manager/process-manager/endpoint-services"import Program from "@server/core/link-manager/auth-manager/program-manager/program"import type Process from "@server/core/link-manager/auth-manager/process-manager/process"-import type { ServiceKey } from "@phreshos/core"+import type { ServiceAddress } from "@phreshos/core"import { test } from "vitest"-test("endpoint services contract", async () => {- const privateProgram = new Program({- identity: "private-program",- server: { location: ".", command: "true" }- })- const documentedProgram = new Program({- identity: "documented-program",- agent: "agent.md",- server: { location: ".", command: "true" },- client: { location: "." }- })-- assert.equal(privateProgram.record().hasAgent, false)- assert.equal(documentedProgram.record().hasAgent, true)- assert.throws(() => new Program({- identity: "invalid-program",- agent: "",- server: { location: ".", command: "true" }- }), /agent documentation/)-+test("endpoint services use stable name addresses and ready availability", async () => {const program = new Program({identity: "program",server: { location: ".", command: "true" },client: { location: "." }})- const waits: string[] = []+ assert.equal(program.version, "0.0.0")function process(identity: string, name: string | null, ready = true, service = true) {- const waiters = new Set<() => void>()const server = { ready, service }return {identity,name,reference: `${identity}-reference`,program,- launch: {- server: { service },- client: { service }- },+ launch: { server: { service }, client: { service } },server,client: { service },- waitReady(endpoint: "server" | "client", notify: () => void) {-- waits.push(endpoint)- if (endpoint === "client" || server.ready) notify()- else waiters.add(notify)- return () => { waiters.delete(notify) }- },- becomeReady() {- server.ready = true- for (const notify of waiters) notify()- waiters.clear()- }+ becomeReady() { server.ready = true }} as unknown as Process & { becomeReady(): void }}- let provider = process("0b231437-513b-4907-8041-c497279c07fa", "main")-- const services = new EndpointServices(key => {- if (key.program !== undefined && key.program !== program.identity) return null- if (key.program === undefined && key.process !== provider.identity) return null- if (key.process !== provider.identity && key.process !== provider.name) return null- if ((key.endpoint === "server" ? provider.server?.service : provider.client?.service) !== true) return null- return { process: provider, endpoint: key.endpoint }- })-- const key = { program: "program", process: "main", endpoint: "server" } satisfies ServiceKey- const clientKey = { ...key, endpoint: "client" } satisfies ServiceKey- const exact = { ...key, process: provider.identity }- const global = { process: provider.identity, endpoint: "server" } satisfies ServiceKey+ let provider = process("first", "main")+ const transitions: Array<[string, ServiceAddress]> = []+ const services = new EndpointServices(+ address => address.program === program.identity+ && address.process === provider.name+ && (address.endpoint === "server" ? provider.server?.service : provider.client?.service) === true+ ? { process: provider, endpoint: address.endpoint }+ : null,+ () => [provider],+ (event, address) => { transitions.push([event, address]) }+ )+ const address = { program: "program", process: "main", endpoint: "server" } satisfies ServiceAddress+ const clientAddress = { ...address, endpoint: "client" } satisfies ServiceAddressconst lifecycle: string[] = []const publications: unknown[] = []- await assert.rejects(() => services.waitReady(key, -1), /non-negative finite number/)+ assert.throws(() => services.available({ process: "main", endpoint: "server" }), /complete Service address/)+ await assert.rejects(() => services.waitReady(address, -1), /non-negative finite number/)- services.follow(key, "lifecycle", null, event => lifecycle.push(event))- services.follow(key, "events", "change", (_event, payload) => publications.push(payload))+ services.follow(address, "lifecycle", null, event => lifecycle.push(event))+ services.follow(address, "events", "change", (_event, payload) => publications.push(payload))await services.started(provider, "server")- assert.equal(services.exists(key), true)- assert.equal(services.exists(global), true)- assert.deepEqual(lifecycle, ["start"])- await services.waitReady(key, 0)- await services.waitReady(clientKey, 0)- assert.deepEqual(waits, ["server", "client"])+ await services.started(provider, "client")+ assert.equal(services.available(address), true)+ assert.deepEqual(services.list("main"), [address, clientAddress])+ assert.deepEqual(lifecycle, ["available"])+ await services.waitReady(address, 0)await services.emit(provider, "server", "ignored", 1)await services.emit(provider, "server", "change", 2)@@ -97,32 +62,30 @@ test("endpoint services contract", async () => {provider.server = nullawait services.stopped(provider, "server", true)- assert.equal(services.exists(key), false)- assert.deepEqual(lifecycle, ["start", "stop"])- await assert.rejects(() => services.waitReady(key, 0), /timeout/)+ assert.equal(services.available(address), false)+ assert.deepEqual(lifecycle, ["available", "unavailable"])+ await assert.rejects(() => services.waitReady(address, 0), /timeout|available/)- // A name address follows a replacement, while an identity address does not.- provider = process("234448b9-4661-4bda-8028-ae75438bf5be", "main", false)+ // A stable address follows a replacement with the same Program and Process name.+ provider = process("replacement", "main", false)await services.started(provider, "server")- assert.equal(services.exists(key), true)- assert.equal(services.exists(exact), false)- assert.equal(services.exists(global), false)+ assert.equal(services.available(address), false)- const ready = services.waitReady(key, 100)+ const ready = services.waitReady(address, 100)provider.becomeReady()+ await services.ready(provider, "server")await ready+ assert.equal(services.available(address), true)- // Server and Client remain distinct coordinates for the same Process.- assert.equal(services.exists(clientKey), true)-- const unconfiguredProgram = new Program({- identity: "unconfigured",- server: { location: ".", command: "true" }- })- assert.equal(unconfiguredProgram.server?.service, false)+ // An unnamed Process is never discoverable, even when its Endpoint is configured.+ provider = process("unnamed", null)+ await services.started(provider, "server")+ assert.deepEqual(services.list(), [])- // One incarnation can override the Program default without changing the Program.- provider = process("2c6f42b0-7847-4f80-8373-0cba3f48636b", "main", true, false)+ // A running Endpoint that did not opt into Service mode remains unavailable.+ provider = process("unconfigured", "main", true, false)await services.started(provider, "server")- assert.equal(services.exists(key), false)+ assert.equal(services.available(address), false)++ assert.deepEqual(transitions.map(([event]) => event), ["available", "available", "unavailable", "available"])}, 120_000)diff --git a/tests/permissions.test.ts b/tests/permissions.test.tsindex 4cda8bf..06f88be 100644--- a/tests/permissions.test.ts+++ b/tests/permissions.test.ts@@ -126,15 +126,15 @@ test("permissions contract", async () => {assert(!catalog.allows("all", [], {}))assert(catalog.allows("services", ["browser"], { all: [] }))assert(catalog.allows("services", ["browser"], { services: ["browser"] }))- assert(catalog.allows("services", ["browser"], { programs: [] }))- assert(catalog.allows("services", [], { programs: [] }))- assert(catalog.allows("services", ["browser"], { programs: ["browser"] }))- assert(catalog.allows("services", ["browser", "editor"], { programs: ["browser"], services: ["editor"] }))+ assert(!catalog.allows("services", ["browser"], { programs: [] }))+ assert(!catalog.allows("services", [], { programs: [] }))+ assert(!catalog.allows("services", ["browser"], { programs: ["browser"] }))+ assert(!catalog.allows("services", ["browser", "editor"], { programs: ["browser"], services: ["editor"] }))assert(catalog.allows("services", ["editor"], { programs: ["browser"], services: ["editor"] }))assert(!catalog.allows("services", ["editor"], { programs: ["browser"] }))assert(!catalog.allows("services", [], { programs: ["browser"] }))assert(!catalog.allows("programs", ["browser"], { services: [] }))- assert(catalog.allows("services", ["browser"], { programs: [], services: false }))+ assert(!catalog.allows("services", ["browser"], { programs: [], services: false }))assert(catalog.allows("desktopConnection", [], { desktopConnection: [] }))assert(catalog.allows("desktopConnection", [], { connections: [] }))assert(catalog.allows("desktopConnection", [], { connections: [], desktopConnection: false }))@@ -154,7 +154,7 @@ test("permissions contract", async () => {assert.throws(() => parsePermissionName("files"), /does not know/)assert.throws(() => catalog.resolve("all", ["unknown"]), /unknown value/)assert.throws(() => catalog.resolve("appearance", ["flambo"]), /unknown value/)- assert.throws(() => catalog.resolve("services", ["Not a Program"]), /unknown value/)+ assert.throws(() => catalog.resolve("services", [" "]), /unknown value/)assert.throws(() => catalog.resolve("network", ["api.example.com"]), /unknown value/)assert.throws(() => catalog.resolve("storage", ["all:Documents"]), /unknown value/)assert.throws(() => catalog.resolve("storage", ["all,read:Documents"]), /unknown value/)diff --git a/tests/process-lifecycle.test.ts b/tests/process-lifecycle.test.tsindex f6d0ad6..5f686f4 100644--- a/tests/process-lifecycle.test.ts+++ b/tests/process-lifecycle.test.ts@@ -104,8 +104,8 @@ test("process lifecycle contract", async () => {assert.ok(process.clientEndpoint)await manager.move(process.identity, { x: 80, y: 90 })- await manager.changeHeader(process.identity, false)- await manager.changeFrame(process.identity, { radius: "full", color: "primary" })+ await manager.setHeader(process.identity, false)+ await manager.setFrame(process.identity, { radius: "full", color: "primary" })await manager.startClient(process.identity)@@ -122,7 +122,7 @@ test("process lifecycle contract", async () => {assert.equal(process.clientEndpoint.window.header, false)await manager.stopClient(process.identity)- await manager.changeHeader(process.identity, true)+ await manager.setHeader(process.identity, true)await manager.move(process.identity, { x: 140, y: 150 })await manager.startClient(process.identity, { layer: "window" })diff --git a/tests/sdk-records.test.ts b/tests/sdk-records.test.tsindex d6c552a..9edb465 100644--- a/tests/sdk-records.test.ts+++ b/tests/sdk-records.test.ts@@ -5,7 +5,7 @@ import { sdkProcess, type SdkProcessSource } from "@client/view/components/deskttest("Desktop preserves Endpoint service roles in SDK snapshots", () => {const program: ProgramSnapshot = {identity: "example", reference: "program-reference", assetId: "program-assets",- name: "Example", version: null, description: null, hasAgent: false,+ name: "Example", version: "0.0.0", description: null, hasAgent: false,server: { start: true, service: false }, client: null}for (const server of [null, { service: false }, { service: true }]) {diff --git a/tests/window-geometry.test.ts b/tests/window-geometry.test.tsindex 1bb094c..526136d 100644--- a/tests/window-geometry.test.ts+++ b/tests/window-geometry.test.ts@@ -20,15 +20,19 @@ test("window geometry contract", async () => {)assert.throws(() => authority.setGeometry({- position: { x: 40, y: 50 },- size: { width: Number.NaN, height: 240 }+ x: 40,+ y: 50,+ width: Number.NaN,+ height: 240}), /width/)assert.deepEqual(authority.position, initial.position)assert.deepEqual(authority.size, initial.size)const next = {- position: { x: "1/4", y: 30 },- size: { width: "1/2", height: 240 }+ x: "1/4",+ y: 30,+ width: "1/2",+ height: 240}const events: unknown[][] = []const echoes: unknown[][] = []@@ -50,35 +54,38 @@ test("window geometry contract", async () => {const echo = await ProcessManager.prototype.setGeometry.call(manager as unknown as ProcessManager, "process", next)- assert.deepEqual(authority.position, next.position)- assert.deepEqual(authority.size, next.size)+ const nextPosition = { x: next.x, y: next.y }+ const nextSize = { width: next.width, height: next.height }+ assert.deepEqual(authority.position, nextPosition)+ assert.deepEqual(authority.size, nextSize)assert.deepEqual(events, [- ["process", "geometry", next],- ["process", "move", next.position],- ["process", "resize", next.size]+ ["process", "move", nextPosition],+ ["process", "resize", nextSize]])- assert.deepEqual(echoes, [["/geometry", { identity: "process", window: authority }]])+ assert.deepEqual(echoes, [["/set-geometry", { identity: "process", window: authority }]])assert.equal(echo.identity, "process")assert.equal(echo.window, authority)const unchangedEvents = events.lengthawait ProcessManager.prototype.setGeometry.call(manager as unknown as ProcessManager, "process", next)- await ProcessManager.prototype.move.call(manager as unknown as ProcessManager, "process", next.position)- await ProcessManager.prototype.resize.call(manager as unknown as ProcessManager, "process", next.size)- await ProcessManager.prototype.changeTitle.call(manager as unknown as ProcessManager, "process", "Geometry")- await ProcessManager.prototype.changeHeader.call(manager as unknown as ProcessManager, "process", true)+ await ProcessManager.prototype.move.call(manager as unknown as ProcessManager, "process", nextPosition)+ await ProcessManager.prototype.resize.call(manager as unknown as ProcessManager, "process", nextSize)+ await ProcessManager.prototype.setTitle.call(manager as unknown as ProcessManager, "process", "Geometry")+ await ProcessManager.prototype.setHeader.call(manager as unknown as ProcessManager, "process", true)assert.equal(events.length, unchangedEvents)- await ProcessManager.prototype.changeHeader.call(manager as unknown as ProcessManager, "process", false)+ await ProcessManager.prototype.setHeader.call(manager as unknown as ProcessManager, "process", false)assert.equal(authority.header, false)assert.deepEqual(events.at(-1), ["process", "changeHeader", false])+ const transaction = { duration: 240, easing: "ease-out" } as const+ await ProcessManager.prototype.setTransaction.call(manager as unknown as ProcessManager, "process", transaction)+ assert.deepEqual(authority.transaction, transaction)+ assert.deepEqual(events.at(-1), ["process", "changeTransaction", transaction])+const resized = { width: "1/2", height: 260 }- await ProcessManager.prototype.setGeometry.call(manager as unknown as ProcessManager, "process", { position: next.position, size: resized })- assert.deepEqual(events.slice(-2), [- ["process", "geometry", { position: next.position, size: resized }],- ["process", "resize", resized]- ])+ await ProcessManager.prototype.setGeometry.call(manager as unknown as ProcessManager, "process", { ...nextPosition, ...resized })+ assert.deepEqual(events.at(-1), ["process", "resize", resized])const publications: unknown[][] = []const counterpart = new ClientWindow(@@ -87,25 +94,27 @@ test("window geometry contract", async () => {authority.toJSON())await counterpart.setGeometry(next)- assert.deepEqual(publications, [["/geometry", "process", next]])+ assert.deepEqual(publications, [["/set-geometry", "process", next]])+ await counterpart.setTransaction(false)+ assert.deepEqual(publications.at(-1), ["/set-transaction", "process", false])authority.minimized = trueawait ProcessManager.prototype.maximize.call(manager as unknown as ProcessManager, "process", true)assert.equal(authority.maximized, true)assert.equal(authority.minimized, true)- assert.deepEqual(authority.position, next.position)+ assert.deepEqual(authority.position, nextPosition)assert.deepEqual(authority.size, resized)assert.deepEqual(events.at(-1), ["process", "maximize", true])const maximizedEvents = events.lengthawait ProcessManager.prototype.maximize.call(manager as unknown as ProcessManager, "process", true)assert.equal(events.length, maximizedEvents)- const stored = { position: { x: 44, y: 55 }, size: { width: 440, height: 550 } }+ const stored = { x: 44, y: 55, width: 440, height: 550 }authority.setGeometry(stored)await ProcessManager.prototype.maximize.call(manager as unknown as ProcessManager, "process", false)assert.equal(authority.minimized, true)assert.equal(authority.maximized, false)- assert.deepEqual(authority.position, stored.position)- assert.deepEqual(authority.size, stored.size)+ assert.deepEqual(authority.position, { x: stored.x, y: stored.y })+ assert.deepEqual(authority.size, { width: stored.width, height: stored.height })await counterpart.maximize(true)assert.deepEqual(publications.at(-1), ["/maximize", "process", true])counterpart.follow(authority.toJSON())diff --git a/tests/window-presentation-layers.test.ts b/tests/window-presentation-layers.test.tsindex 32319d9..4b4a2ed 100644--- a/tests/window-presentation-layers.test.ts+++ b/tests/window-presentation-layers.test.ts@@ -26,20 +26,20 @@ function fixture(layer: WindowLayer) {test.each(["wallpaper", "start-menu"] as const)("%s exposes only concepts understood by its presentation", async layer => {const { own, entries, presentations } = fixture(layer)- expect(presentations.read("own", "title")).toBe("Original")expect(presentations.read("own", "layer")).toBe(layer)- for (const property of ["position", "size", "minimized", "maximized", "header", "frame", "front"] as const) {+ for (const property of ["title", "position", "size", "minimized", "maximized", "header", "frame", "front"] as const) {expect(() => presentations.read("own", property)).toThrow(new RegExp(`${layer} layer has no`))}const unsupported = [() => presentations.move("own", { x: 1, y: 2 }),() => presentations.resize("own", { width: 1, height: 2 }),- () => presentations.geometry("own", { position: { x: 1, y: 2 }, size: { width: 1, height: 2 } }),+ () => presentations.setGeometry("own", { x: 1, y: 2, width: 1, height: 2 }),() => presentations.minimize("own", true),() => presentations.maximize("own", false),- () => presentations.header("own", false),- () => presentations.frame("own", true),+ () => presentations.setTitle("own", "Changed"),+ () => presentations.setHeader("own", false),+ () => presentations.setFrame("own", true),() => presentations.raise("own")]for (const operation of unsupported) expect(operation).toThrow(new RegExp(`${layer} layer cannot apply`))@@ -51,7 +51,7 @@ test.each(["wallpaper", "start-menu"] as const)("%s exposes only concepts undersexpect(presentations.projection("own").title).toBe("Original")await presentations.follow("own")- expect(presentations.projection("own").title).toBe("Changed")+ expect(presentations.projection("own").title).toBe("Original")expect(presentations.projection("own").position).toEqual({ x: 0, y: 0 })})@@ -59,9 +59,11 @@ test.each(["under", "over"] as const)("%s presents geometry and frame without aconst { own, entries, presentations } = fixture(layer)expect(() => presentations.read("own", "header")).toThrow(new RegExp(`${layer} layer has no header`))- expect(() => presentations.header("own", false)).toThrow(new RegExp(`${layer} layer cannot apply header`))+ expect(() => presentations.read("own", "title")).toThrow(new RegExp(`${layer} layer has no title`))+ expect(() => presentations.setHeader("own", false)).toThrow(new RegExp(`${layer} layer cannot apply header`))+ expect(() => presentations.setTitle("own", "Changed")).toThrow(new RegExp(`${layer} layer cannot apply title`))- await presentations.frame("own", { color: "primary", radius: "full" })+ await presentations.setFrame("own", { color: "primary", radius: "full" })expect(presentations.read("own", "frame")).toEqual({ color: "primary", radius: "full" })await presentations.follow("own")@@ -81,7 +83,7 @@ test("a standard presentation reports its permanent frame without allowing frameconst { presentations } = fixture("window")expect(presentations.read("own", "frame")).toBe(true)- expect(() => presentations.frame("own", false)).toThrow(/window layer cannot apply frame/)+ expect(() => presentations.setFrame("own", false)).toThrow(/window layer cannot apply frame/)})test("unsupported presentation events remain silent", () => {@@ -94,5 +96,5 @@ test("unsupported presentation events remain silent", () => {presentations.follow("own")presentations.reconcile(entries)- expect(received).toEqual(["changeTitle"])+ expect(received).toEqual([])})diff --git a/tests/window-presentation.test.ts b/tests/window-presentation.test.tsindex cd6c8f7..af8b1ab 100644--- a/tests/window-presentation.test.ts+++ b/tests/window-presentation.test.ts@@ -3,7 +3,7 @@ import ClientProcessBoundary from "@client/view/components/desktop-host/client-pimport { presentationTransaction } from "@client/view/components/desktop-host/window-presentation"import WindowPresentations, { type WindowPresentationEntry } from "@client/view/components/window-manager/window-presentations"import { requireWindowPresentationTransactions } from "@shared/window-layers"-import type { WindowLayer } from "@phreshos/core"+import type { WindowLayer, WindowTransaction } from "@phreshos/core"import { test } from "vitest"test("Window presentation transactions remain independent from Appearance limits", () => {@@ -77,13 +77,41 @@ test("transactionAndWait semantics resolve on completion and reject on interruptawait presentations.move("overlay", { x: 70, y: 80 })await assert.rejects(interrupted, /interrupted/)- const changingFrame = presentations.frame("overlay", { color: "primary", radius: "full" }, request)+ const changingFrame = presentations.setFrame("overlay", { color: "primary", radius: "full" }, request)const frameRevision = presentations.projection("overlay").frameAnimation?.revisionpresentations.complete("overlay", "frame", frameRevision!)await changingFrameassert.deepEqual(presentations.state("overlay").frame, { color: "primary", radius: "full" })})+test("transaction-capable presentations use the authoritative Window transaction by default", async () => {+ const overlay = client("over")+ overlay.window.transaction = { duration: 240, easing: "ease-out" }+ const entries = new Map([+ ["overlay", { identity: "overlay:0", client: overlay }]+ ]) as unknown as ReadonlyMap<string, WindowPresentationEntry>+ const presentations = new WindowPresentations(entries, () => overlay as never)++ const first = presentations.move("overlay", { x: 20, y: 30 })+ const firstAnimation = presentations.projection("overlay").geometryAnimation+ assert.deepEqual(firstAnimation?.transaction, overlay.window.transaction)+ presentations.complete("overlay", "geometry", firstAnimation!.revision)+ await first++ overlay.window.transaction = false+ presentations.reconcile(entries)+ await presentations.move("overlay", { x: 40, y: 50 })+ assert.equal(presentations.projection("overlay").geometryAnimation, null)++ overlay.window.transaction = { duration: 180, easing: "linear" }+ presentations.reconcile(entries)+ const inherited = presentations.move("overlay", { x: 60, y: 70 }, { transaction: true, wait: true })+ const inheritedAnimation = presentations.projection("overlay").geometryAnimation+ assert.deepEqual(inheritedAnimation?.transaction, overlay.window.transaction)+ presentations.complete("overlay", "geometry", inheritedAnimation!.revision)+ await inherited+})+test("presentation geometry events expose each applied representation change", () => {const ordinary = client("window")const entries = new Map([@@ -136,7 +164,7 @@ function client(layer: WindowLayer) {title: "Window",header: layer === "window",frame: layer === "window",- transaction: false,+ transaction: false as WindowTransaction,position: { x: 0, y: 0 },size: { width: 300, height: 200 },minimized: false,diff --git a/tests/worker-runtime.test.ts b/tests/worker-runtime.test.tsindex 7c65db3..436ef21 100644--- a/tests/worker-runtime.test.ts+++ b/tests/worker-runtime.test.ts@@ -244,7 +244,7 @@ test("server runtime contract", async () => {assetId: "asset",installed: false,name: "Program",- version: null,+ version: "0.0.0",description: null,categories: [],keywords: [],