Skip to content

An open-source, self-hosted system for apps built with web technologies.

Separate services from program agent documentation

zohayrslileh88f5c558a0a2
diff --git a/package.json b/package.json
index 47c3e5b..39f5b35 100644
--- a/package.json
+++ b/package.json
@@ -30,7 +30,7 @@
"build": "vite-node scripts/build.ts",
"start": "node --run build && node dist/server/main.js",
"pack": "node --run build && vite-node scripts/pack.ts",
- "verify:contracts": "vite-node scripts/verify-client-launch.mjs && vite-node scripts/verify-process-find-or-create.mjs && vite-node scripts/verify-service-creation.mjs && vite-node scripts/verify-client-surface.mjs && vite-node scripts/verify-window-geometry.mjs && vite-node scripts/verify-readiness.mjs && vite-node scripts/verify-endpoint-services.mjs && vite-node scripts/verify-program-install.mjs && vite-node scripts/verify-host-traffic.mjs && vite-node scripts/verify-intake-address.mjs && vite-node scripts/verify-theme.mjs",
+ "verify:contracts": "vite-node scripts/verify-client-launch.mjs && vite-node scripts/verify-process-find-or-create.mjs && vite-node scripts/verify-client-surface.mjs && vite-node scripts/verify-window-geometry.mjs && vite-node scripts/verify-readiness.mjs && vite-node scripts/verify-endpoint-services.mjs && vite-node scripts/verify-program-install.mjs && vite-node scripts/verify-host-traffic.mjs && vite-node scripts/verify-intake-address.mjs && vite-node scripts/verify-theme.mjs",
"verify:distribution": "node scripts/verify-distribution.mjs",
"verify": "node --run check && node --run verify:contracts && node --run verify:distribution"
},
diff --git a/scripts/verify-endpoint-services.mjs b/scripts/verify-endpoint-services.mjs
index 0656ed8..888ba76 100644
--- a/scripts/verify-endpoint-services.mjs
+++ b/scripts/verify-endpoint-services.mjs
@@ -6,28 +6,25 @@ const privateProgram = new Program({
identity: "private-program",
server: { location: ".", startCommand: "true" }
})
-const publicProgram = new Program({
- identity: "public-program",
- server: { location: ".", startCommand: "true", serviceDocs: "server-api.md" },
- client: { location: ".", serviceDocs: "client-api.md" }
+const documentedProgram = new Program({
+ identity: "documented-program",
+ agent: "agent.md",
+ server: { location: ".", startCommand: "true" },
+ client: { location: "." }
})
-assert.equal(privateProgram.record().server.hasService, false)
-assert.equal(publicProgram.record().server.hasService, true)
-assert.equal(publicProgram.record().client.hasService, true)
+assert.equal(privateProgram.record().hasAgent, false)
+assert.equal(documentedProgram.record().hasAgent, true)
assert.throws(() => new Program({
identity: "invalid-program",
- server: { location: ".", startCommand: "true", serviceDocs: "" }
-}), /serviceDocs/)
+ agent: "",
+ server: { location: ".", startCommand: "true" }
+}), /agent documentation/)
-function process(reference, program = "program", hasService = true) {
+function process(reference, program = "program") {
return {
reference,
- program: {
- identity: program,
- server: { serviceDocs: hasService ? "server-api.md" : undefined },
- client: { serviceDocs: hasService ? "client-api.md" : undefined }
- },
+ program: { identity: program },
server: {},
client: {}
}
@@ -36,7 +33,7 @@ function process(reference, program = "program", hasService = true) {
const services = new EndpointServices()
const provider = process("provider")
const conflicting = process("conflicting")
-const privateEndpoint = process("private", "private", false)
+const independent = process("independent", "independent")
const key = { program: "program", endpoint: "server", name: "counter" }
const lifecycle = []
const publications = []
@@ -49,8 +46,9 @@ await assert.rejects(() => services.waitReady(key, -1), /non-negative finite num
assert.equal(services.enabled(key), false)
assert.equal(services.service(provider, "server"), null)
-await assert.rejects(() => services.enable(privateEndpoint, "server", "counter"), /declared no Service documentation/)
-await assert.rejects(() => services.enable(privateEndpoint, "client", "counter"), /declared no Service documentation/)
+await services.enable(independent, "server", "independent")
+assert.equal(services.enabled({ program: "independent", endpoint: "server", name: "independent" }), true)
+await services.release(independent, "server")
services.follow(key, "lifecycle", null, event => lifecycle.push(event))
services.follow(key, "lifecycle", "disable", async () => {
diff --git a/scripts/verify-program-install.mjs b/scripts/verify-program-install.mjs
index 8883a75..7d22a5c 100644
--- a/scripts/verify-program-install.mjs
+++ b/scripts/verify-program-install.mjs
@@ -13,20 +13,18 @@ try {
mkdirSync(join(source, "server"), { recursive: true })
mkdirSync(join(source, "client"), { recursive: true })
writeFileSync(join(source, "client", "index.html"), "<!doctype html>")
- writeFileSync(join(source, "server-api.md"), "Server Service")
- writeFileSync(join(source, "client-api.md"), "Client Service")
+ writeFileSync(join(source, "operating-guide.md"), "Program operating knowledge")
mkdirSync(installed)
const program = new Program({
identity: "documented-program",
+ agent: join(source, "operating-guide.md"),
server: {
location: join(source, "server"),
- serviceDocs: join(source, "server-api.md"),
startCommand: "true"
},
client: {
- location: join(source, "client"),
- serviceDocs: join(source, "client-api.md")
+ location: join(source, "client")
}
})
@@ -35,10 +33,8 @@ try {
const declaration = JSON.parse(readFileSync(join(installed, "program.json"), "utf8"))
- assert.equal(declaration.server.serviceDocs, "server-docs.md")
- assert.equal(declaration.client.serviceDocs, "client-docs.md")
- assert.equal(readFileSync(join(installed, "server-docs.md"), "utf8"), "Server Service")
- assert.equal(readFileSync(join(installed, "client-docs.md"), "utf8"), "Client Service")
+ assert.equal(declaration.agent, "agent.md")
+ assert.equal(readFileSync(join(installed, "agent.md"), "utf8"), "Program operating knowledge")
}
finally {
rmSync(temporary, { recursive: true, force: true })
diff --git a/scripts/verify-service-creation.mjs b/scripts/verify-service-creation.mjs
deleted file mode 100644
index e3694c0..0000000
--- a/scripts/verify-service-creation.mjs
+++ /dev/null
@@ -1,73 +0,0 @@
-import assert from "node:assert/strict"
-import ProcessManager from "../source/server/core/link-manager/auth-manager/process-manager/process-manager.ts"
-
-const requester = { identity: "requester" }
-const program = {
- identity: "browser",
- server: { serviceDocs: "server-docs.md" },
- client: { serviceDocs: "client-docs.md" }
-}
-
-const launches = []
-const waits = []
-let alreadyEnabled = false
-
-const manager = Object.assign(Object.create(ProcessManager.prototype), {
- processes: new Map([[requester.identity, requester]]),
- services: {
- enabled: () => alreadyEnabled,
- identity: key => `identity-${key.endpoint}`,
- waitReady: async (key, timeout) => waits.push({ key, timeout })
- },
- authManager: {
- programManager: {
- reach: identity => identity === program.identity ? program : null,
- findOrCreateProcess: async (identity, launch, parent) => {
- launches.push({ identity, launch, parent })
- }
- }
- }
-})
-
-const server = { program: "browser", endpoint: "server", name: "browser" }
-
-await manager.createAndWaitServiceReady(requester.identity, server, undefined, 1_000)
-
-assert.deepEqual(launches[0], {
- identity: "browser",
- launch: {
- name: "service:identity-server",
- server: true,
- client: false
- },
- parent: requester
-})
-assert.equal(waits[0].key, server)
-assert(waits[0].timeout >= 0 && waits[0].timeout <= 1_000)
-
-const client = { program: "browser", endpoint: "client", name: "browser-window" }
-const clientLaunch = { minimize: true }
-
-await manager.createAndWaitServiceReady(requester.identity, client, clientLaunch, 1_000)
-
-assert.deepEqual(launches[1], {
- identity: "browser",
- launch: {
- name: "service:identity-client",
- server: false,
- client: clientLaunch
- },
- parent: requester
-})
-
-await assert.rejects(
- () => manager.createAndWaitServiceReady(requester.identity, server, {}, 1_000),
- /does not accept Client launch configuration/
-)
-
-alreadyEnabled = true
-
-await manager.createAndWaitServiceReady(requester.identity, server, undefined, 1_000)
-
-assert.equal(launches.length, 2)
-assert.equal(waits.length, 2)
diff --git a/source/client/core/link-manager/auth-manager/program-manager/program-manager.ts b/source/client/core/link-manager/auth-manager/program-manager/program-manager.ts
index 4c094c6..87f5506 100644
--- a/source/client/core/link-manager/auth-manager/program-manager/program-manager.ts
+++ b/source/client/core/link-manager/auth-manager/program-manager/program-manager.ts
@@ -99,10 +99,10 @@ export default class ProgramManager extends TheLink {
return await this.$outbound.publishFirst("/icon", identity, size) as number[]
}
- /** Reads one declared Endpoint's Service documentation from authoritative Core. */
- public async docs(identity: string, endpoint: "server" | "client") {
+ /** Reads Program-specific operating knowledge from authoritative Core. */
+ public async agent(identity: string) {
- return await this.$outbound.publishFirst("/docs", identity, endpoint) as string | null
+ return await this.$outbound.publishFirst("/agent", identity) as string | null
}
@Subscribe("/install")
diff --git a/source/client/core/link-manager/auth-manager/program-manager/program.ts b/source/client/core/link-manager/auth-manager/program-manager/program.ts
index e2d84dc..47b2608 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
@@ -29,6 +29,8 @@ export default class Program {
public readonly description: string | null
+ public readonly hasAgent: boolean
+
public readonly server: HostedEntry["server"]
public readonly client: HostedEntry["client"]
@@ -51,6 +53,8 @@ export default class Program {
this.description = payload.description
+ this.hasAgent = payload.hasAgent
+
this.server = payload.server
this.client = payload.client
diff --git a/source/client/view/desktop/client-host/host.ts b/source/client/view/desktop/client-host/host.ts
index 2563894..98748df 100644
--- a/source/client/view/desktop/client-host/host.ts
+++ b/source/client/view/desktop/client-host/host.ts
@@ -439,12 +439,7 @@ export default function host(authManager: AuthManager, pane: string, desktop: ()
return [sdkProgram(program)]
}
- if (word === "endpoint-docs") {
-
- if (args[0] !== "server" && args[0] !== "client") throw new Error("A Program Endpoint is server or client")
-
- return [await programManager.docs(process().program, args[0])]
- }
+ if (word === "program-agent") return [await programManager.agent(process().program)]
// Icon bytes are requested only when this frame asks. The frame cannot
// provide an identity; its owning Process determines the Program.
diff --git a/source/client/view/desktop/client-host/sdk-records.ts b/source/client/view/desktop/client-host/sdk-records.ts
index d7af9d4..9234f97 100644
--- a/source/client/view/desktop/client-host/sdk-records.ts
+++ b/source/client/view/desktop/client-host/sdk-records.ts
@@ -36,6 +36,8 @@ export function sdkProgram(program: Program) {
description: program.description,
+ hasAgent: program.hasAgent,
+
server: program.server,
client: program.client
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.ts
index 91f5fe3..0400497 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
@@ -19,10 +19,6 @@ export default class EndpointServices extends TheLink {
public async enable(process: Process, endpoint: Half, value: unknown) {
- const declaration = endpoint === "server" ? process.program.server : process.program.client
-
- if (!declaration?.serviceDocs) throw new Error(`The ${endpoint} endpoint declared no Service documentation`)
-
const name = this.name(value)
if (!this.live(process, endpoint)) throw new Error(`The ${endpoint} endpoint is not running`)
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.ts
index fd446a0..6f35187 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
@@ -17,7 +17,7 @@ import HostTraffic from "./host-traffic"
import { failed, succeeded, type Outcome } from "@server/core/outcome"
import { endpointReference, processReference } from "./endpoint-reference"
import EndpointEvents from "./endpoint-events"
-import EndpointServices, { serviceTimeout } from "./endpoint-services"
+import EndpointServices from "./endpoint-services"
import { isPermissionName, isServiceKey, type PermissionName, type WindowGeometry, type WindowLayer } from "@phreshos/core"
/**
@@ -1054,58 +1054,6 @@ export default class ProcessManager extends TheLink {
await this.services.waitReady(key, timeout)
}
- /** Atomically creates the dedicated providing Process and awaits its exact Service. */
- public async createAndWaitServiceReady(
- source: string,
- key: unknown,
- client: unknown,
- timeout: unknown
- ) {
-
- if (!isServiceKey(key)) throw new Error("A complete service key is required")
-
- const requester = this.find(source)
- const program = this.authManager.programManager.reach(key.program)
-
- if (!program) throw new Error(`Unknown Program "${key.program}"`)
-
- const declaration = program[key.endpoint]
-
- if (!declaration?.serviceDocs) {
-
- throw new Error(`Program "${program.identity}" does not declare a ${key.endpoint} Service`)
- }
-
- if (key.endpoint === "server" && client !== undefined) {
-
- throw new Error("A Server Service does not accept Client launch configuration")
- }
-
- const milliseconds = serviceTimeout(timeout)
-
- if (this.services.enabled(key)) return
-
- const expiresAt = Date.now() + milliseconds
- const name = `service:${this.services.identity(key)}`
- const launch: Launch & { name: string } = key.endpoint === "server"
- ? { name, server: true, client: false }
- : { name, server: false, client: client as LaunchClient | undefined ?? true }
-
- await this.authManager.programManager.findOrCreateProcess(program.identity, launch, requester)
- await this.services.waitReady(key, Math.max(0, expiresAt - Date.now()))
- }
-
- @Connect("/service/create-and-wait-ready")
- protected async connectCreateAndWaitServiceReady(
- source: string,
- key: unknown,
- client: unknown,
- timeout: unknown
- ) {
-
- await this.createAndWaitServiceReady(source, key, client, timeout)
- }
-
@Subscribe("/service/send")
protected async sendClientService(source: string, key: unknown, event: unknown, payload: unknown) {
@@ -1335,11 +1283,11 @@ export default class ProcessManager extends TheLink {
if (word === "current-program") return [programManager.find(process.program.identity)]
- if (word === "endpoint-docs") {
+ if (word === "program-agent") {
const program = this.heldProgram(rest[0], process.program)
- return [await programManager.docs(program.identity, rest[1])]
+ return [await programManager.agent(program.identity)]
}
if (word === "current-process") return [processReference(process)]
@@ -1614,11 +1562,6 @@ export default class ProcessManager extends TheLink {
if (word === "service-wait-ready") return [await this.services.waitReady(rest[0], rest[1])]
- if (word === "service-create-and-wait-ready") {
-
- return [await this.createAndWaitServiceReady(process.identity, rest[0], rest[1], rest[2])]
- }
-
if (word === "service-follow") {
const [subscription, key, scope, event] = rest
diff --git a/source/server/core/link-manager/auth-manager/program-manager/config.ts b/source/server/core/link-manager/auth-manager/program-manager/config.ts
index 23878a6..22f6221 100644
--- a/source/server/core/link-manager/auth-manager/program-manager/config.ts
+++ b/source/server/core/link-manager/auth-manager/program-manager/config.ts
@@ -37,6 +37,10 @@ interface Described {
// headless Program is shown too.
icon?: string
+ // Program-specific operating knowledge for agents. Any source path is
+ // accepted here; installation canonicalizes it to agent.md.
+ agent?: string
+
// Where it keeps what it keeps. Absent means the system decides.
storage?: string
}
@@ -49,10 +53,6 @@ export interface ServerConfig {
// Whether a Process starts this endpoint by default. True when omitted.
start?: boolean
- // Markdown file documenting the Service this endpoint may expose.
- // Presence grants the endpoint permission to enable one Service.
- serviceDocs?: string
-
// Run once before the program is first started, in that directory.
installCommand?: string
@@ -73,10 +73,6 @@ export interface ClientConfig {
// Whether a Process starts this endpoint by default. True when omitted.
start?: boolean
- // Markdown file documenting the Service this endpoint may expose.
- // Presence grants the endpoint permission to enable one Service.
- serviceDocs?: string
-
// What its window is called when it opens. The window owns its title
// from then on and may change it; this is what it is born with, so
// there is no moment of showing the wrong thing while the half
diff --git a/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts b/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts
index fd0b9d8..a55388c 100644
--- a/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts
+++ b/source/server/core/link-manager/auth-manager/program-manager/program-manager.ts
@@ -222,7 +222,7 @@ export default class ProgramManager extends TheLink {
// is not holding on disk.
if (typeof source.storage !== "string") throw new Error("A created program names its storage")
- for (const [what, place] of [["storage", source.storage], ["icon", source.icon], ["server", source.server?.location], ["server serviceDocs", source.server?.serviceDocs], ["client serviceDocs", source.client?.serviceDocs]] as const) {
+ for (const [what, place] of [["storage", source.storage], ["icon", source.icon], ["agent", source.agent], ["server", source.server?.location]] as const) {
if (place === undefined) continue
@@ -415,13 +415,11 @@ export default class ProgramManager extends TheLink {
return [...await this.icons.render(this.reachOrRefuse(identity), size)]
}
- /** Reads a declared Endpoint's Service documentation before it is started. */
- @Connect("/docs")
- public async docs(identity: string, endpoint: unknown) {
+ /** Reads Program-specific operating knowledge for agents. */
+ @Connect("/agent")
+ public async agent(identity: string) {
- if (endpoint !== "server" && endpoint !== "client") throw new Error("A Program Endpoint is server or client")
-
- return this.reachOrRefuse(identity).serviceDocs(endpoint)
+ return this.reachOrRefuse(identity).agent()
}
/** Read or change the system-managed startup launch for one Program. */
@@ -1401,19 +1399,17 @@ export function copyProgram(program: Program, into: string) {
else delete config.icon
- for (const endpoint of ["server", "client"] as const) {
-
- const docs = program.serviceDocs(endpoint)
+ const agent = program.agent()
- if (docs === null) continue
+ if (agent !== null) {
- const target = `${endpoint}-docs.md`
+ writeFileSync(join(into, "agent.md"), agent)
- writeFileSync(join(into, target), docs)
-
- config[endpoint] = { ...config[endpoint] as object, serviceDocs: target }
+ config.agent = "agent.md"
}
+ else delete config.agent
+
// The description names the places the system chose. Presence is
// part of a half's declaration, so its location is never omitted.
delete config.storage
@@ -1421,7 +1417,7 @@ export function copyProgram(program: Program, into: string) {
writeFileSync(join(into, "program.json"), JSON.stringify(strip(config), null, 4))
}
-const installedParts = ["server", "client", "icon.png", "server-docs.md", "client-docs.md", "program.json"] as const
+const installedParts = ["server", "client", "icon.png", "agent.md", "program.json"] as const
// JSON has no `undefined`, and a key whose value is one would be written
// as nothing at all — so they are removed rather than left to vanish.
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.ts
index ad4c735..f9d5c8b 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
@@ -174,14 +174,17 @@ export default class Program {
return this.config.icon ? this.place(this.config.icon) : null
}
- /** Reads the documentation that declares one Endpoint's Service capability. */
- public serviceDocs(endpoint: "server" | "client") {
+ public get agentPath() {
- const declared = this.config[endpoint]?.serviceDocs
+ return this.config.agent ? this.place(this.config.agent) : null
+ }
+
+ /** Reads this Program's agent-independent operating documentation. */
+ public agent() {
- if (!declared) return null
+ if (!this.agentPath) return null
- return readFileSync(this.place(declared), "utf-8")
+ return readFileSync(this.agentPath, "utf-8")
}
/** SDK Program record; internal references are consumed by the SDK boundary. */
@@ -205,19 +208,17 @@ export default class Program {
description: description ?? null,
- server: server && {
+ hasAgent: this.agentPath !== null,
- start: server.start,
+ server: server && {
- hasService: server.serviceDocs !== undefined
+ start: server.start
},
client: client && {
start: client.start,
- hasService: client.serviceDocs !== undefined,
-
title: client.title ?? null,
size: client.size ?? null,
@@ -258,12 +259,7 @@ export default class Program {
if (this.iconPath) await validateIcon(this.iconPath)
- for (const endpoint of ["server", "client"] as const) {
-
- const declared = this.config[endpoint]?.serviceDocs
-
- if (declared && !file(this.place(declared))) throw new Error(`The ${endpoint} service documentation is not there: ${this.place(declared)}`)
- }
+ if (this.agentPath && !file(this.agentPath)) throw new Error(`The agent documentation is not there: ${this.agentPath}`)
}
@@ -302,11 +298,13 @@ function coherent(config: ProgramConfig) {
if (!config.server && !config.client) throw new Error("A program must have a server half, a client half, or both")
- for (const field of ["name", "version", "description", "icon", "storage"] as const) {
+ for (const field of ["name", "version", "description", "icon", "agent", "storage"] as const) {
if (config[field] !== undefined && typeof config[field] !== "string") throw new Error(`A program's ${field} must be text`)
}
+ if (config.agent !== undefined && config.agent.trim().length === 0) throw new Error("A program's agent documentation must be a non-empty path")
+
for (const half of ["server", "client"] as const) {
const declared = config[half]
@@ -319,7 +317,6 @@ function coherent(config: ProgramConfig) {
if (declared.start !== undefined && typeof declared.start !== "boolean") throw new Error(`A declared ${half} endpoint's start default must be true or false`)
- if (declared.serviceDocs !== undefined && (typeof declared.serviceDocs !== "string" || declared.serviceDocs.trim().length === 0)) throw new Error(`A declared ${half} endpoint's serviceDocs must be a non-empty path`)
}
if (config.client && /^https?:\/\//i.test(config.client.location)) {