Skip to content

A local-first multi-agent app development platform, built on PenguinHarness

11.2 KB
Raw Blame

The server is a module tree, checked by signature before it boots

  • Date: 2026-08-29
  • Type: refactor
  • Scope: core, server, web, tooling
  • PR: #543, #599, #546
  • Breaking: yes — the @prismshadow/penguin-server package no longer exports AppDeps, buildAppDeps or createApp; the activate(ctx) plugin contract is replaced by Plugin { modules }

中文版

The business surface of the server — every service, every repo, every route group, the session runtime, the terminal manager — is now a tree (packages/server/src/platform.ts) of the classes themselves — there is no modules/ directory; each node is declared in the file of the thing it is. Most nodes are components: a service or repo class that exports itself. @Component() on the class — a node is named by its class, AuthService is the node AuthService, so nothing is named twice — one @Use() field per dependency, typed by the class or interface it needs — @Use() private readonly users!: UsersRepo — and injected before the optional setup(); the class's public surface is its interface. A module is the other kind of node: a class that exports other things, @Module({ contributes?, context?, children? }) with @Provide() sessions!: Sessions fields assigned in setup(). Both may carry @Bind("agents.memory") memoryRoutes!: Hono for a contribution's code half and park() for state. AuthService and the module that only existed to construct it are the same class now; the modules/<name>/ wrapper directories for repos and plain services are gone, and so are their Pick<Impl, …> interface classes — a consumer names the component class itself, or declares the narrow interface it needs where it consumes it (abstract class ScheduleTaskRunner extends Interface<…>() {}, declared beside the scheduler). pnpm gen:ifaces reads the decorators and field annotations statically — never executing the file — into the same table as the interfaces, projecting a component's public members as its contract; the booter checks each class against that table (a field it does not know is a stale-table error), so the tree is checked before any class code runs, then created in dependency order. A component wanted outside a tree — a script, a test — is built with wire(Cls, { …fields }).

Interfaces at signature level

A component's interface is its class, projected; anything else is an abstract class extends Interface<…>(), wherever it is declared. pnpm gen:ifaces projects every such interface into packages/server/src/ifaces.json — parameters and return types included, not just method names; named data types are emitted once and referenced, so a recursive type is a reference to itself. The table is generated, not committed: typecheck, build, test and the deploy script regenerate it. A requirement is satisfied by Go's rule: every method the consumer names exists on the provider with an assignable signature (parameters contravariant, returns covariant). A module may declare the narrow interface it needs where it consumes it; the scheduler's ScheduleTaskRunner is one, satisfied by the session runtime's wider SessionManager.

Host objects (AbortSignal, Request, a class of this package written as Opaque<"Name">) compare by name only — and the name is always qualified by the package that declares the type (@types/node#Request, @prismshadow/penguin-core#Resources), so the same word in two packages is two identities. Mapped types (Pick<…>, Record<…>) are projected as the shapes they are, an alias with methods as an interface under the alias's name.

Contributions are manifest data

A route group is a line in a manifest — "HttpModule.routes": [{ id: "agents.memory", prefix: "/api/…", auth: "user", order: 190 }] — and the module binds the handler by that id. The http module assembles the whole surface from those lines; adding an endpoint no longer touches a central route table. Sandbox backends and messaging connectors enter through the same kind of slot.

Plugins are modules

A plugin package is a set of modules, written the way the platform's own are: @Component / @Module classes with @Use / @Provide / @Bind fields. Its manifests are generated — the package's build runs gen-ifaces and ships ifaces.json beside its package.json — the table is the package's module payload, a plugin is a plugin by being listed; the default export is { modules: [<class>, …] }, each class checked against that table at load, and the modules boot as children of the platform's tree at every App creation. The activate(ctx) contract — initialize / create events, PenguinInterface, PenguinContext — is gone; what it registered (a sandbox backend, a workflow factory) is now a contribution or a provided interface, and what it reached (terminals, sandbox) is a requirement checked at signature level. The four sandbox backends are converted. A hand-written manifest (a workflow package's) may leave out an empty requires, provides, contributes or children.

Mechanisms, not implementations: the runtime split and the end of Overrides

The single RuntimeModule that exported ten unrelated things is gone: each claimed capability is a node of its own (RuntimeConfig, RuntimeDb, RuntimeChannels, RuntimeProxy, RuntimeHmr, RuntimeDesktop, RuntimeAuthState, RuntimeResourceGroups), and what most nodes actually wanted from the config is its own mechanism, Paths (root). Time is a mechanism (Clock, SystemClock), so is the log (Log, ConsoleLog), password hashing (PasswordHasher, ScryptHasher), the messaging pacing knobs (MessagingTuning), each connector's network transport (FeishuSdkHandle, TelegramTransportHandle, QQTransportHandle, QQScanTransportHandle), the session loader and title generator (SessionLoaders, TitleGenerators) and the update check's network (HttpFetch). A component says what it implements — class SystemClock implements Clock — and the generator records it; a provider that declares the interface wins the wiring over one that merely has the shape.

BuildDepsOverrides — the bag of test doubles that thirteen production nodes read at boot — is deleted. A test stands in for a node instead: bootAppDeps(config, [[SystemClock, { now }]]), a list of replacements the platform boots in place of the classes they name, checked against the same table as the classes themselves. createTestApp keeps its option names and turns them into replacements.

Every dependency is a mechanism

packages/server/src/mechanisms/*.ts declares the mechanisms the tree is made of — identity (Users, AuthSessions, Auth, Admin), projects (Projects, Members, AgentIndex, Access, ProjectLifecycle, ProjectConfigStore, ModelOAuth), sessions (SessionIndex, Goals, SessionOrigins, Schedules, Scheduling), observability (ErrorLog, Errors, UsageStore, UsageRecording, UsageQueries), traces, workspace, agents, settings, messaging — as interface classes with full signatures, apart from what implements them. Each implementation says so (class UsersRepo implements Users); every @Use field, every route's dependency type and every service's dependency type names the mechanism. AuthService requires Users, AuthSessions, AuthState, Clock, PasswordHasher and its own InitialProjectProvisioner — nothing about SQLite, nothing about the runtime. gen-ifaces refuses a @Use field typed by a component class, so the rule holds without review; the count went from 102 of 189 to 0 of 192.

Groups that export

The root has fourteen children, not seventy-four: RuntimeModule, SettingsModule, IdentityModule, ProjectsModule, SessionRuntimeModule, ObservabilityModule, TracesModule, AgentsModule, WorkspaceModule, MessagingHubModule, ApiModule, plus the sandbox, terminal and machines modules and Startup. A group is @Module({ children, exports }): its exports are the interfaces its children offer the rest of the tree, forwarded from the child that declares each; everything else in the group — the repos, the seams a test replaces, the route components — is visible only inside it (the kernel's visibility is lexical: siblings and the ancestors' siblings, never an ancestor). A whole group is replaceable, and so is any node in one. Ordering follows the exported child, not the group, so two groups may need each other's children without a cycle. The generator resolves every requirement to the module that will provide it and records it as from — the table now says which module a node depends on, and the page shows who depends on whom.

An extension replaces any node

package.json#penguin.replaces lists manifests under the names of the nodes they stand in for — a component, a module, a whole group with children and exports of its own — and the default export's replaces carries their code. Nothing about a stand-in is checked when it is put in place: the platform builds the tree with the stand-in where the class would have been, and the tree is checked as one before any node runs — every requirement resolved at signature level, every exported alias resolved to a child, every provision present on the instance. A stand-in that offers less than its consumers need is refused by name (ServerSettingsRepo: api 'Settings' does not satisfy 'Settings': missing [getAttachmentLimitsMb], SettingsModule: exports 'Settings' but no child provides it), and the App does not boot; two extensions replacing the same node is a load-time conflict. Production code and the test helpers read the tree through the groups' exports, never an implementation node by name, so a replaced node is what everyone gets.

The table as a page

pnpm ifaces:page renders ifaces.json into one self-contained HTML page (dist-ifaces/index.html): the module tree, every node's requires / provides / contributes, every interface at signature level, with the table's sha256 in the title and the JSON beside it.

Compatibility

The platform node's parked document keeps its version: the module tree's documents are an added modules field, and the pty handle ids and sandbox settings are still written where the first platforms parked them — so a data root a newer platform has parked on still boots any older platform pushed to it, terminals and confinement intact.

AppDeps, buildAppDeps and createApp are gone from @prismshadow/penguin-server, and so is the activate(ctx) plugin form: an installed plugin written against it fails to load with "the default export is not a Plugin" until it is rewritten as modules. A test that needs a service reaches it through flattenForTests(boot) in the server's test helpers, or through boot.tree.api(module, alias) — a component's alias is its class name (tree.api("AuthService", "AuthService")); a slot is <Class>.<slot> (HttpModule.routes, SandboxModule.providers). Service and repo classes no longer take their dependencies in the constructor: new UsersRepo(db) becomes wire(UsersRepo, { db }) from @prismshadow/penguin-core/kernel.