Files
prometeu-studio/docs/specs/studio/9. Studio Core and Adapter Architecture Specification.md
T
bquarkz bf31184d4d feat(pbs): add sprite animation and shared Studio authoring
Implement DEC-0084 with factory-only Sprite/Animator structs, complete result
lowering, validated animation sidecars, generated PBS factories and JavaFX/MCP
authoring through shared services.

Qualify native dev/release with ordinary and optimized producers, zero-allocation
playback, private-cycle reclamation, canonical Composer pixels, installed JARs
and JavaFX lifecycle. Preserve the runtime checkout and existing host ABI.
2026-11-05 15:16:07 +00:00

202 lines
14 KiB
Markdown

# Studio Core and Adapter Architecture Specification
## Status
Active
## Applies To
- `prometeu-studio-api`
- `prometeu-studio-core`
- `prometeu-studio-ui-javafx`
- `prometeu-app`
- integrations with compiler, Packer, LSP, and the runtime
## Purpose
Define the physical and functional boundary that makes the Studio consumable by interchangeable human and automation adapters without coupling application behavior to JavaFX, Spring, or a specific external provider.
## Authority and Precedence
This specification implements `DEC-0059` and the accepted `DEC-0060` AI-first baseline. It is the normative architecture reference for the Studio split. DEC-0060 adds shared automation services and the narrowly scoped local MCP server exception below; it does not replace the module boundaries or dependency direction.
The [DEV and Automation Specification](10.%20DEV%20and%20Automation%20Specification.md) defines project authority, document handoff, operations, captures and delivery gates. More specific domain specs MUST preserve the dependency direction defined here. Normative requirements describe the target contract, not a claim that every delivery phase is already implemented.
## Architectural Model
The Studio is a set of project and tooling services consumed by adapters:
```text
JavaFX UI ──> Studio API <── local MCP adapter <── external coding agent
│
▼
Studio Core
▲
│
application/infrastructure adapters
```
JavaFX is the human adapter; DEV is its authorization and observation workspace. The local MCP adapter exposes the same neutral services to an external coding agent. Neither adapter MAY simulate the other adapter's UI or duplicate project authority, build/pack or execution orchestration. The external client owns the agent, chat, model/provider credentials and coding loop.
## Physical Modules
1. `prometeu-studio-api` MUST contain toolkit-neutral contracts, commands, queries, DTOs, diagnostics, results, events, and operation contracts.
2. `prometeu-studio-core` MUST contain JavaFX-free application services, sessions, policies, orchestration, and Studio-owned use-case implementations.
3. `prometeu-studio-ui-javafx` MUST contain visual workspaces, controls, dialogs, bindings, navigation, presentation projections, theme application, localization binding, and JavaFX-thread dispatch.
4. `prometeu-app` MUST contain the desktop entry point, Spring composition, concrete integration adapters, lifecycle, and packaging.
Gradle is the physical classpath boundary. Spring Modulith verifies the functional modules rooted exclusively at `p.studio.core`; it does not replace the Gradle modules.
The legacy mixed `prometeu-studio` module and the static `p.studio.Container` service locator MUST NOT exist in the final architecture.
## API Neutrality
The public Studio API MUST be plain Java and MUST NOT depend on:
- JavaFX;
- Spring Framework, Spring Boot, or Spring Modulith;
- HTTP, AI, MCP, or provider SDKs;
- concrete runtime-wire or MCP transport DTOs;
- concrete compiler, Packer, LSP, or runtime implementations;
- `p.studio.core` or `p.studio.ui.javafx` internals.
Public contracts MUST NOT expose `Stage`, `Scene`, `Node`, JavaFX properties, controls, `Task`, `ApplicationContext`, Spring events, or provider-specific implementation types.
Expected failures MUST use domain status, diagnostics, and typed results. A universal `Result<T>` abstraction MUST NOT be introduced.
## Core Rules
Core classes MUST be POJOs with constructor injection and MUST remain testable without a Spring context.
The core module MUST NOT:
- depend on JavaFX or UI packages;
- depend on HTTP/MCP SDKs, Spring, or concrete external protocol DTOs;
- call `Platform.runLater`;
- perform navigation or workspace selection;
- use presentation severity or visual state as domain semantics;
- obtain dependencies from a static holder or `ApplicationContext` lookup.
The functional core modules are:
- `project`: project identity, catalog, creation, paths, setup, and restoration state;
- `session`: open-project lifecycle, project-scoped automation authority, document handoff, ordered cleanup, execution ownership, and the LSP lifecycle port;
- `assets`: Studio-owned asset projections, metadata, policies, non-visual sessions, validation, and workflow orchestration;
- `shipper`: build/pack coordination, manifest generation, artifacts, and neutral logs/results;
- `runtime`: runtime settings, handshake, process/client lifecycle, canonical capture contracts, and technical logs; human Debug and headless automation retain distinct protocol/lifecycle boundaries;
- `execution`: play/stop and automation operation state, cancellation, shutdown, and orchestration of shipper and runtime.
The functional dependency direction MUST remain:
```text
assets --> project
shipper --> project
runtime --> project
execution --> project, shipper, runtime
session --> project, execution, LSP port
```
Session-owned authority lifetime MUST NOT introduce reverse functional dependencies from `assets`, `shipper`, `runtime` or `execution` to the concrete `session` module. Service entry points MUST receive the shared authority through neutral contracts and composition, not reach into JavaFX or concrete session implementations. Document-handoff participants likewise use neutral contracts; their presentation buffers remain adapter-owned.
Manual Debug and project mutation MUST enforce the same project authority as automation. Disabled UI buttons alone are not authorization. Grant, acquisition, operation completion and authority return MUST remain distinct lifecycle facts.
## JavaFX Adapter Rules
The JavaFX module MUST depend on Studio API contracts rather than core or provider implementations. It owns visual state, UI events, navigation, FX-thread transitions, CSS, fonts, locale bindings, and lifecycle of visual objects.
JavaFX controls and dialogs MUST be constructed by UI factories or composition roots. They MUST NOT become Spring singletons by default.
Presentation-only drafts and projections MAY remain in the JavaFX module. Rules that determine project, asset, build, runtime, or semantic outcomes MUST live behind neutral API contracts and core services.
The JavaFX module MUST NOT directly invoke compiler implementations, `p.packer`, LSP implementations, runtime implementations, or filesystem orchestration.
## Spring Composition
Spring Boot MUST be used only by `prometeu-app` for desktop composition and lifecycle. `WebApplicationType.NONE` remains a valid composition mode with an explicitly managed local HTTP adapter. Conformance MUST NOT impose an unconditional absence of a web server that would forbid the DEC-0060 MCP exception.
The sole accepted HTTP-server use is an in-process MCP Streamable HTTP endpoint at `127.0.0.1:<OS-assigned-port>/mcp`. The application/infrastructure adapter MUST own its transport dependencies and lifecycle. It MUST require a fresh grant-published project credential, validate project/session scope and Origin, and stop with Studio. Connection authentication MUST NOT grant project/task authority. Credentials MUST NOT be stored in versioned files. Restart requires a fresh human grant, while the stable client configuration remains unchanged.
This exception does not authorize a web UI, remote binding, general-purpose web application, accounts or OAuth. DEC-0061 explicitly adds the Studio-owned stdio mode and local client preparation. HTTP/MCP dependencies MUST NOT enter API/Core or the JavaFX adapter. Spring Data, Spring AI and durable event infrastructure remain outside the accepted architecture.
Spring configuration MAY create core services, infrastructure adapters, and a JavaFX composition factory. It MUST NOT use field injection, context lookup, broad service bags, or a replacement static container.
The desktop entry point MUST retain the JavaFX composition root and close it before closing the Spring context. Closing that root MUST be idempotent and MUST close any active or asynchronously opening project session, execution surface, loading window, project window, and launcher window before provider beans and executors are destroyed.
Spring Modulith verification MUST use `p.studio.core` as its exclusive application root and MUST run as an architecture gate.
## External Integration Rule
An integration MUST use the provider's public API directly when that API is stable, neutral, use-case oriented, and safe to compose and test. A redundant gateway that merely mirrors such an API MUST NOT be created.
A narrow consumer-owned gateway MUST be used when the available integration is concrete, static, infrastructure-oriented, unstable, excessively broad, or leaks lifecycle and implementation details. Its implementation belongs in `prometeu-app` or another explicit infrastructure adapter.
| Studio consumer | Provider | Required boundary |
| --- | --- | --- |
| `assets` | `p.packer` | Stable public Packer API directly; narrow assets-owned gateway only when necessary |
| `shipper` | compiler and `p.packer` | Stable public APIs or a narrow shipper-owned compiler gateway |
| `session` | LSP | Neutral session-owned lifecycle port |
| `runtime` | external runtime/process | Narrow runtime-owned gateway |
| JavaFX UI | Studio | Studio API only |
| MCP adapter | Studio | Studio API only; transport DTO translation belongs to infrastructure |
The headless gateway MUST start `prometeu headless --stdio` from the configured runtime installation and map the runtime-owned JSONL contract to neutral results. It MUST NOT reuse the human DevTools connection, introduce a native Rust/Java binding, search/download another runtime, or redefine firmware/VM semantics. Runtime process supervision and the existing project LSP client belong to application/infrastructure adapters, not UI controls.
`p.packer` remains an autonomous domain and MUST NOT depend on any `p.studio` package. Studio MUST NOT copy or assume ownership of Packer semantics.
## Commands, Events, and Operations
Commands and queries requiring an immediate response MUST use direct service calls. In-process events MAY communicate facts that require no response, and each application event MUST be owned by the functional module that owns the fact.
Selection, navigation, attach/detach, and visual lifecycle events remain UI-local.
Long-running build, pack, runtime, and execution work MUST expose a neutral operation contract with stable identity, observable snapshot, standard-Java asynchronous completion, cancellation, updates, and a typed result.
Core services MUST submit such work through the neutral `OperationExecutor` port. `prometeu-app` owns the executor-backed implementation and its thread lifecycle; JavaFX consumes `OperationHandle` completion and snapshots and performs only the required FX-thread projection.
Automation MUST reuse this operation boundary. Task authority is separate from operation success, guest fault, infrastructure failure or cancellation. Revocation MUST invalidate task authority before stopping managed work, refreshing open documents and releasing manual control. Closing the project or application MUST perform that cleanup; changing the active workspace MUST NOT.
Build and advance admission MUST return a promptly queryable operation identity. Task-scoped, in-memory `clientRequestId` deduplication MUST live behind the shared services, not in a second MCP orchestrator. Runtime `requestId` is wire correlation and MUST NOT be treated as that deduplication mechanism. Late calls/results MUST NOT restore revoked authority.
## Conformance Gates
The architecture is conformant only when all of the following hold together:
- API and core compile without JavaFX, Spring, HTTP/MCP SDKs or concrete transport DTO dependencies;
- UI has no dependency on core or concrete external providers;
- `ApplicationModules.verify()` succeeds for the exclusive `p.studio.core` root;
- the desktop application boots and shuts down with no web exposure other than the authorized loopback MCP endpoint, whose transport is lifecycle-managed by the app;
- MCP and JavaFX consume shared authorization and operations; grant/Debug exclusion and cleanup are enforced in services;
- `Container`, `AppContainer`, compatibility allowlists, and the mixed module are absent;
- unit, integration, architecture, packaging, and desktop smoke tests pass;
- no service locator or context lookup replaces the removed static container.
## Non-Goals
- embedding an agent, chat or provider adapter;
- adding a second orchestration/authorization implementation inside MCP;
- replacing JavaFX with a web UI;
- migrating the Studio to Rust, Electron, Tauri, or a parallel rewrite;
- redesigning compiler, Packer, LSP, or runtime semantics;
- introducing microservices or durable event infrastructure.
## Integrated MCP Connection Boundary (DEC-0061)
The same Studio application artifact MUST support `mcp --project` over stdio
before desktop composition. It connects to the existing loopback HTTP adapter;
it MUST NOT implement separate authority, operations, language services or runtime
semantics. Offline catalog loading does not initialize the desktop graph.
API exposes neutral preparation/readiness and connection-publication lifecycle
ports. Core orchestrates save, publication commit/abort, grant, revocation and
shutdown through those ports. Application infrastructure owns credentials, file
locks/atomic discovery, HTTP identity checks, TOML preparation and managed
installation/runtime packaging. JavaFX consumes neutral status and actions only.
Filesystem publication MUST NOT run under a long-held authority monitor.
## Animation integration contract
Glyph-bank animation authoring, generated-source navigation, strict task-scoped MCP tools and preview use the shared animation service and validation contract. UI/MCP preserve project authority, expected revisions, conflict/cancellation/revocation and document handoff. Persist only the canonical animation sidecar; keep generated PBS read-only and neutral services independent of JavaFX/transports.
See the [complete animation contract](12.%20Animation%20Authoring%20Specification.md).