Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
13c0ababbb
|
||
|
|
603ed01227
|
||
|
|
bd5694dbdf
|
||
|
|
a9ede541af | ||
|
|
d71e46ade8
|
||
|
|
8dff6d8d5f
|
||
|
|
967b9ec598
|
||
|
|
d0737df0ac
|
||
|
|
97cf5e1919
|
@@ -32,25 +32,94 @@ At runtime, the app boots an embedded packer, restores project-local Studio stat
|
|||||||
|
|
||||||
## External Coding Agents (MCP)
|
## External Coding Agents (MCP)
|
||||||
|
|
||||||
Open a project and select **DEV → Copy MCP configuration**. The copied JSON is a
|
Studio includes its own `mcp --project <absolute-root>` mode. Configure the native
|
||||||
provider-neutral connection descriptor: use its `url` and `headers.Authorization`
|
client once; project grants and desktop restarts no longer require copying ports
|
||||||
in your external client's Streamable HTTP MCP setup, and provide its `projectRoot`
|
or tokens. The initial integration targets Codex on macOS.
|
||||||
and instructions to the agent. Adapt the configuration syntax to your client;
|
|
||||||
there is no embedded chat or provider-specific setup wizard.
|
|
||||||
|
|
||||||
Keep the descriptor/token private and out of versioned files and logs. The endpoint
|
1. Install/stage Studio with its bundled Java runtime (see below). New projects
|
||||||
is local to this computer. After restarting Studio, copy it again and update the
|
prepare the local client entry during scaffolding. Opening an existing project
|
||||||
client: both the port and token are ephemeral. Copying or connecting does not
|
also prepares its enabled integration automatically; Studio starts the shared
|
||||||
authorize edits or start a task.
|
MCP server itself. **DEV → Prepare assistant** retries preparation after resolving
|
||||||
|
a reported setup conflict. Opening a project does not grant agent control.
|
||||||
|
2. Open the coding client in the project directory. Trust the project and reload
|
||||||
|
MCP once if the client requests it. Studio does not alter client approval policy.
|
||||||
|
Tools can initialize/list even before the desktop is open or access is granted.
|
||||||
|
3. Open the project in Studio and grant control in DEV (save first if prompted).
|
||||||
|
Active Debug prevents granting. The connector discovers access automatically.
|
||||||
|
4. The agent acquires a task, consults project/language/SDK references, edits saved
|
||||||
|
project files with its native tools and validates through LSP/build. SDK and
|
||||||
|
external libraries remain read-only.
|
||||||
|
5. Recover uncertain operations by operationId/clientRequestId lookup within the
|
||||||
|
same task; never replay build/advance blindly. Explicitly release control when
|
||||||
|
done. Human reclaim also revokes access; stop direct external file edits separately.
|
||||||
|
|
||||||
1. Connect, discover tools, read project context and applicable language/SDK references.
|
The client invokes the same Studio artifact over stdio. It forwards to Studio's
|
||||||
2. In DEV, grant control (save all first if prompted). Active Debug prevents granting.
|
project-scoped loopback service using protected, transient
|
||||||
3. The agent acquires a task, edits saved project files using its own tools, and
|
`.studio/mcp/connection.json`. The permanent `.codex/config.toml` entry contains
|
||||||
validates through LSP/build. SDK and external libraries are consultable, read-only.
|
installed Java/classpath/root arguments, not credentials. Both local outputs are
|
||||||
4. Poll operations by operationId or clientRequestId. Recover a lost start receipt
|
ignored by Git. Unrelated client settings are preserved; tracked or conflicting
|
||||||
by lookup; never retry frame advancement blindly with a new ID.
|
Studio entries require deliberate resolution. `.studio/setup.json` preserves
|
||||||
5. The agent explicitly releases control. To interrupt, use DEV's reclaim button
|
neutral integration intent and existing runtime/editor settings.
|
||||||
and stop the external client separately: Studio cannot prevent its direct file writes.
|
|
||||||
|
After desktop restart, grant again in DEV. Keep the same client session and
|
||||||
|
configuration; old task identities and operation receipts are not restored.
|
||||||
|
DEV displays connection separately from project authority. No project-local
|
||||||
|
launcher, Python transport script or embedded chat is required.
|
||||||
|
|
||||||
|
### Reading external source code
|
||||||
|
|
||||||
|
VS Code F12 opens SDK/core and admitted libraries as read-only documents, with
|
||||||
|
hover, continued F12 and syntax highlighting. SDK/core stay bundled; no editorial
|
||||||
|
copies are created. After a source revision changes or a session ends, navigate
|
||||||
|
again instead of reusing old positions.
|
||||||
|
|
||||||
|
For MCP, use `studio_language_query` with `operation: "definition"`, then pass a
|
||||||
|
returned `prometeu-source:` URI to `operation: "readExternalSource"`. The response
|
||||||
|
contains `descriptor` and `text`; hover and definition accept the same URI within
|
||||||
|
the owning task. Another task cannot reuse it. MCP does not require VS Code open.
|
||||||
|
External or mixed edit proposals are refused in full. Library installation/cache
|
||||||
|
management is outside this feature. See the [extension guide](tools/vscode-extension/README.md).
|
||||||
|
|
||||||
|
### Installation and IntelliJ development
|
||||||
|
|
||||||
|
Build and stage the complete distribution, including its Java runtime:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./gradlew :prometeu-app:stageStudioInstallation
|
||||||
|
```
|
||||||
|
|
||||||
|
The macOS default is `~/Library/Application Support/Prometeu/Studio/current`.
|
||||||
|
Staging validates a new version before atomically changing `current`, retaining
|
||||||
|
older versions for rollback and running processes. Native client registration
|
||||||
|
uses absolute paths and argument arrays, independent of shell PATH:
|
||||||
|
|
||||||
|
```text
|
||||||
|
command: <installation>/current/runtime/bin/java
|
||||||
|
args: ["-cp", "<installation>/current/lib/*", "p.studio.app.StudioLauncher", "mcp", "--project", "<absolute-project-root>"]
|
||||||
|
```
|
||||||
|
|
||||||
|
For development, use an isolated installation:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./gradlew :prometeu-app:stageStudioInstallation -PstudioInstallationRoot=/absolute/dev-installation
|
||||||
|
```
|
||||||
|
|
||||||
|
In IntelliJ, run/debug `p.studio.app.StudioLauncher` with the `prometeu-app`
|
||||||
|
runtime classpath and VM option `-Dstudio.installationRoot=/absolute/dev-installation`.
|
||||||
|
The desktop and client-owned connector are separate JVMs. To debug the latter,
|
||||||
|
add the development-only VM argument
|
||||||
|
`-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=127.0.0.1:5005`
|
||||||
|
before `-cp` in the local MCP entry, restart that MCP process, then use IntelliJ's
|
||||||
|
**Remote JVM Debug** on localhost:5005. Do not commit this local configuration.
|
||||||
|
Because manual edits to the managed entry are protected, restore its original
|
||||||
|
content before using preparation again. Regular registration never enables JDWP.
|
||||||
|
|
||||||
|
The packaged automated gate checks bundled Java, upgrade/rollback, project paths
|
||||||
|
with spaces, minimal environment, scaffold/preparation and JavaFX startup:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./gradlew :prometeu-app:installedConnectorTest
|
||||||
|
```
|
||||||
|
|
||||||
The current production tools cover context, references, task control, LSP,
|
The current production tools cover context, references, task control, LSP,
|
||||||
build/pack, operation lookup/cancellation and headless execution (17 tools).
|
build/pack, operation lookup/cancellation and headless execution (17 tools).
|
||||||
@@ -67,7 +136,9 @@ for schemas, authorization, limits and delivery boundaries.
|
|||||||
|
|
||||||
| Symptom | Action |
|
| Symptom | Action |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| Connection rejected after Studio restarts | Copy DEV's configuration again: the token and OS-assigned endpoint are session-local. Do not publish the token. |
|
| Waiting for access / desktop restarted | Open the project and grant again in DEV. Keep the existing client configuration. |
|
||||||
|
| Stale connection / incompatible catalog | Grant fresh access, or update the installed Studio when versions differ. Do not edit transient credentials. |
|
||||||
|
| Preparation conflict | Preserve the existing client settings; resolve a tracked/user-owned/edited Studio table explicitly, then prepare again. |
|
||||||
| Acquisition rejected or project busy | Grant control in DEV first; stop manual Debug before granting. Query an existing operation instead of starting another; serialize headless calls. |
|
| Acquisition rejected or project busy | Grant control in DEV first; stop manual Debug before granting. Query an existing operation instead of starting another; serialize headless calls. |
|
||||||
| `RUNTIME_UNAVAILABLE` or handshake incompatibility | Check the project's configured runtime installation and its packaged headless command. Studio does not download a substitute. |
|
| `RUNTIME_UNAVAILABLE` or handshake incompatibility | Check the project's configured runtime installation and its packaged headless command. Studio does not download a substitute. |
|
||||||
| `NO_FRAME_AVAILABLE` | Advance at least one frame before requesting a capture. |
|
| `NO_FRAME_AVAILABLE` | Advance at least one frame before requesting a capture. |
|
||||||
@@ -118,8 +189,8 @@ acknowledge completed cleanup; control stays locked until cleanup is confirmed.
|
|||||||
The following findings are recorded for investigation after implementation; they
|
The following findings are recorded for investigation after implementation; they
|
||||||
are not considered fixed by the passing integration tests:
|
are not considered fixed by the passing integration tests:
|
||||||
|
|
||||||
- **PBS/LSP SDK navigation:** definition lookup for the bundled SDK's `Input.pad()`
|
- **PBS/LSP SDK navigation:** the historical probe of the former `Input.pad()`
|
||||||
currently returns no location. Project-source navigation and indexed SDK reference
|
API returned no location; the current input API is `Pad`/`Button` and `Touch`. Project-source navigation and indexed SDK reference
|
||||||
reads work. Investigate SDK symbol resolution separately; an empty definition
|
reads work. Investigate SDK symbol resolution separately; an empty definition
|
||||||
result is not evidence of missing runtime support or permission to edit the SDK.
|
result is not evidence of missing runtime support or permission to edit the SDK.
|
||||||
- **Build tooling:** the validation environment's JDK 25 triggers Kotlin's target-24
|
- **Build tooling:** the validation environment's JDK 25 triggers Kotlin's target-24
|
||||||
@@ -127,7 +198,7 @@ are not considered fixed by the passing integration tests:
|
|||||||
regression passes, but the toolchain/target alignment needs separate review.
|
regression passes, but the toolchain/target alignment needs separate review.
|
||||||
|
|
||||||
Cross-platform desktop coverage remains a validation boundary, not a confirmed
|
Cross-platform desktop coverage remains a validation boundary, not a confirmed
|
||||||
product defect. Desktop acceptance so far covers macOS ARM64 and Codex CLI only.
|
product defect. Baseline HTTP desktop acceptance covers macOS ARM64 and Codex CLI only. The integrated stdio flow completed its separate acceptance gates through automated validation and user-confirmed native-client, graphical-launch and IntelliJ checks; see [LSN-0077](discussion/lessons/DSC-0070-studio-persistent-mcp-connector/LSN-0077-integrated-mcp-stable-setup-and-ephemeral-access.md) for evidence provenance.
|
||||||
|
|
||||||
The first real Codex CLI acceptance run exercised editing, LSP, build/pack, input,
|
The first real Codex CLI acceptance run exercised editing, LSP, build/pack, input,
|
||||||
1,110 frames, native MCP images and explicit release. The developer confirmed the
|
1,110 frames, native MCP images and explicit release. The developer confirmed the
|
||||||
|
|||||||
+8
@@ -8,6 +8,14 @@ tags: [studio, lsp, vscode, compiler-pbs, editor, definition]
|
|||||||
|
|
||||||
# PBS go-to-definition uses editorial lookup and physical files
|
# PBS go-to-definition uses editorial lookup and physical files
|
||||||
|
|
||||||
|
> Historical policy: DEC-0062 / PLN-0141 explicitly superseded the physical-only
|
||||||
|
> definition restriction in October 2026. SDK/core and dependencies now use
|
||||||
|
> revision-bound read-only external documents for supporting clients. Compiler
|
||||||
|
> Spec 23 and Studio Spec 11 define the current contract. The original lesson below
|
||||||
|
> preserves the earlier decision; it must not be read as prohibiting today's
|
||||||
|
> external navigation. References, symbols, links and hierarchies retain their
|
||||||
|
> separately scoped contracts. See LSN-0078 for the implementation and pitfalls.
|
||||||
|
|
||||||
## Original Problem
|
## Original Problem
|
||||||
|
|
||||||
PBS editor assistance already had compiler-backed completion, hover, and signature help (`LSN-0051`). Users still could not jump from a use to a declaration. Wave 1 explicitly deferred `go to definition`.
|
PBS editor assistance already had compiler-backed completion, hover, and signature help (`LSN-0051`). Users still could not jump from a use to a declaration. Wave 1 explicitly deferred `go to definition`.
|
||||||
|
|||||||
+190
@@ -0,0 +1,190 @@
|
|||||||
|
---
|
||||||
|
id: LSN-0078
|
||||||
|
ticket: pbs-editorial-chains-sdk-navigation
|
||||||
|
title: PBS chains and revision-bound external sources
|
||||||
|
created: 2026-10-07
|
||||||
|
tags: [compiler, compiler-pbs, lsp, studio, sdk, navigation]
|
||||||
|
---
|
||||||
|
|
||||||
|
# PBS chains and revision-bound external sources
|
||||||
|
|
||||||
|
Domain owner: `compiler/pbs`. Propagation: `compiler/general` and `studio`.
|
||||||
|
DEC-0062 and PLN-0141 were implemented together. This lesson preserves the outcome
|
||||||
|
and validation after their workflow artifacts are removed.
|
||||||
|
|
||||||
|
## Original problem
|
||||||
|
|
||||||
|
Compilation supported expressions such as `Input.pad().left().down()`, but the
|
||||||
|
editorial receiver scanner only understood identifier/dot sequences. Hover,
|
||||||
|
definition, completion and signature help therefore lost the receiver after a call.
|
||||||
|
Separately, definition discarded SDK/core handles because their bundled resources
|
||||||
|
had virtual paths rather than regular files. SDK hover could succeed while F12
|
||||||
|
returned nothing. These were independent defects requiring integrated acceptance.
|
||||||
|
|
||||||
|
A third regression fixture confirmed that source discovery skipped a dependency
|
||||||
|
explicitly admitted under `.workspace`: the crawler tested every ancestor of the
|
||||||
|
absolute path against ignored directory names.
|
||||||
|
|
||||||
|
## Consolidated decision
|
||||||
|
|
||||||
|
Keep language resolution in the frontend. Share receiver typing across the four
|
||||||
|
project queries, using PBS parsing and flow semantics. Support known-return call
|
||||||
|
chains, nested arguments, typed/inferred variables, parentheses and recoverable
|
||||||
|
partial code. Unknown or ambiguous receivers stay unresolved. This changes no
|
||||||
|
language rule, compiler/linker pipeline, ABI or runtime behavior.
|
||||||
|
|
||||||
|
Expose SDK/core and admitted dependency sources as read-only in-memory documents.
|
||||||
|
SDK/core remain bundled, without editorial extraction. Libraries remain their
|
||||||
|
existing physical sources; a library inside the project directory is still an
|
||||||
|
external owner. Dependency installation, download, cache management and its future
|
||||||
|
Studio UI remain DSC-0072 / AGD-0074.
|
||||||
|
|
||||||
|
Each external document binds content, byte ranges and frontend semantic context to
|
||||||
|
the same analyzed revision. The host emits an opaque project-session URI; the
|
||||||
|
content digest is not an SDK version. VS Code and MCP share that source and
|
||||||
|
semantic authority. They do not implement another PBS resolver.
|
||||||
|
|
||||||
|
All proposals touching external sources are refused as a whole. Normal project
|
||||||
|
editing remains available. References, workspace symbols, links and hierarchies
|
||||||
|
retain their earlier physical scopes. External definition does not expand them.
|
||||||
|
|
||||||
|
## Final implementation
|
||||||
|
|
||||||
|
1. `PbsParser.parseExpression` exposes the existing expression grammar for complete
|
||||||
|
receiver fragments. `PbsEditorialSupportService` locates a fragment boundary and
|
||||||
|
delegates its type to `PbsFlowExpressionAnalyzer`. The same path serves all four
|
||||||
|
project queries, including trailing dots and unfinished arguments.
|
||||||
|
2. `SourceCrawler` tests ignored descendants relative to the explicitly admitted
|
||||||
|
traversal root. It does not admit incidental `.workspace` trees as project code.
|
||||||
|
3. `FrontendSourceDocument` carries exact text, origin, presentation metadata,
|
||||||
|
read-only ownership and opaque frontend context. Definition locations optionally
|
||||||
|
carry that source; invalid path/range combinations are rejected. PBS preserves
|
||||||
|
source ownership separately from `SourceKind.PROJECT`; external ownership wins
|
||||||
|
when paths overlap. Existing default-empty frontend capabilities remain valid.
|
||||||
|
4. `ExternalSourceRegistry` belongs to `TcpLspServerHost`, not the shared compiler
|
||||||
|
bridge. It retains source/context together, with separate consumer grants,
|
||||||
|
acknowledged uses and reconnect validation. Repeated uses in one semantic
|
||||||
|
snapshot coalesce. Another reader's release cannot invalidate a retained source.
|
||||||
|
5. LSP negotiates external support and emits `prometeu-source:` destinations only
|
||||||
|
to supporting clients. External read, retain, release and revalidate requests
|
||||||
|
share server-issued consumer identity. The bridge uses retained content for
|
||||||
|
positions, hover, definition and highlighting. Unsupported consumers keep local
|
||||||
|
physical navigation without receiving unusable external targets.
|
||||||
|
6. VS Code registers a `TextDocumentContentProvider`, assigns PBS language, routes
|
||||||
|
hover/F12/highlighting and prevents external edit commands. Disconnect preserves
|
||||||
|
displayed text but disables queries until validation; the status bar explains
|
||||||
|
unavailable external documents. Changed revisions require fresh navigation.
|
||||||
|
7. MCP adds `readExternalSource` to `studio_language_query`. Task-owned consumers
|
||||||
|
survive short-lived sockets, acknowledge returned definitions, revalidate before
|
||||||
|
reuse, and release on task return/cancellation. Cross-task/project replay is
|
||||||
|
refused. Failed navigation releases unacknowledged results; failed responses
|
||||||
|
roll back newly retained sources. No human editor is needed.
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
A project definition on `Gfx.clear` opens the bundled SDK source. Hover/F12 on its
|
||||||
|
`LowGfx.clear` call reaches the host declaration. F12 on `Color` reaches the core
|
||||||
|
resource. The same operations work through MCP by reading the returned external
|
||||||
|
URI and querying positions in that text. A dependency under `.workspace/repos/lib`
|
||||||
|
uses the same presentation and write protection.
|
||||||
|
|
||||||
|
If that library changes on disk while a document is open, the retained document's
|
||||||
|
hover/F12 still use its old AST and old text. After disconnect, revalidation against
|
||||||
|
the changed source fails; clients must navigate again for new content and ranges.
|
||||||
|
|
||||||
|
## Validation evidence
|
||||||
|
|
||||||
|
Failures were reproduced before production changes: all four chain assertions
|
||||||
|
failed, both crawler/admitted-FileTable fixtures failed, and the old bridge test
|
||||||
|
confirmed SDK hover with empty bundled definition alongside working local F12.
|
||||||
|
|
||||||
|
Final module results (2026-10-07):
|
||||||
|
|
||||||
|
| Suite | Executed successfully | Skipped |
|
||||||
|
| --- | ---: | ---: |
|
||||||
|
| PBS frontend | 245 | 0 |
|
||||||
|
| Frontend API | 27 | 0 |
|
||||||
|
| Build pipeline | 141 | 15 existing disabled cases |
|
||||||
|
| LSP | 38 | 1 opt-in development-host case in the ordinary run |
|
||||||
|
| App: AutomationLspQueries, McpContract, CompilerProjectKnowledge | 24 | 0 |
|
||||||
|
| Core: TaskLanguageQueries | 1 | 0 |
|
||||||
|
| Actual VS Code Development Host, run separately | 1 | 0 |
|
||||||
|
|
||||||
|
All 477 executed JUnit cases passed across these scoped runs. TypeScript compilation,
|
||||||
|
`discussion validate` and `git diff --check` also passed. The disabled main-project
|
||||||
|
pipeline integration test was not treated as evidence.
|
||||||
|
|
||||||
|
The actual VS Code host exercised typing refusal, declaration selection, semantic
|
||||||
|
highlighting, hover, continued F12, a physical `.workspace` library with Unicode/CRLF,
|
||||||
|
reconnection and normal project edits. Provider tests exercised cached disconnected
|
||||||
|
text, matching/changed revisions, close and canceled reads. MCP tests used the actual
|
||||||
|
TCP server independently of VS Code, including task return, aliases, mixed rename
|
||||||
|
refusal and changed revisions. Registry tests covered multiple readers, distinct
|
||||||
|
projects, last release, task/session lifetime and canceled/unopened navigation.
|
||||||
|
|
||||||
|
The source-snapshot regression changed a dependency on disk after navigation and
|
||||||
|
verified that old hover/F12 still used the original declaration and semantic context.
|
||||||
|
Dedicated write-boundary checks refuse external didChange/didSave, formatting,
|
||||||
|
rename, prepareRename and code actions, including unnegotiated identities.
|
||||||
|
|
||||||
|
Commands are preserved in the plan-derived development instructions and test owners:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
./gradlew :prometeu-compiler:frontends:prometeu-frontend-pbs:test :prometeu-compiler:prometeu-frontend-api:test :prometeu-compiler:prometeu-build-pipeline:test :prometeu-lsp:prometeu-lsp-v1:test --console=plain
|
||||||
|
./gradlew :prometeu-app:test --tests '*AutomationLspQueriesTest' --tests '*McpContractTest' --tests '*CompilerProjectKnowledgeTest' :prometeu-studio-core:test --tests '*TaskLanguageQueriesTest' --console=plain
|
||||||
|
npm --prefix tools/vscode-extension run compile
|
||||||
|
PROMETEU_VSCODE_DEV_TEST=1 ./gradlew :prometeu-lsp:prometeu-lsp-v1:test --tests '*ExternalSourceDevelopmentHostTest' --console=plain
|
||||||
|
```
|
||||||
|
|
||||||
|
Packaged Studio was excluded from the initial acceptance above. On 2026-10-07,
|
||||||
|
the user explicitly requested this additional validation. The existing
|
||||||
|
`InstalledKnowledgeTest` now launches its isolated probe with the Java runtime
|
||||||
|
from `installDist`, using distribution JARs plus test probe classes, with its working
|
||||||
|
directory and projects outside the checkout. It asserts that the frontend and LSP
|
||||||
|
bridge load from JARs and that SDK/core resources have `jar:` URLs.
|
||||||
|
|
||||||
|
The packaged gate passed:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
./gradlew :prometeu-app:installedKnowledgeTest --console=plain
|
||||||
|
```
|
||||||
|
|
||||||
|
Besides reading the installed documentation and compiling its example, it verifies
|
||||||
|
project-to-SDK, SDK-to-host and SDK-to-core definitions, matching declaration lines,
|
||||||
|
exact SDK/core text against JAR bytes, read-only bundled descriptors, SDK hover and
|
||||||
|
semantic tokens, and source revalidation after reconnect. The project contains only
|
||||||
|
its original manifest and sources after navigation: no bundled source extraction.
|
||||||
|
The first run caught an incorrect cursor position in the test fixture; calculating
|
||||||
|
the position from the source fragment fixed the fixture. No production fix was needed.
|
||||||
|
This is a packaged resource/backend gate; it does not launch the Studio desktop or
|
||||||
|
repeat the VS Code UI checks against the installed process.
|
||||||
|
|
||||||
|
## Pitfalls
|
||||||
|
|
||||||
|
- Compiler success does not prove editorial resolution. Query the four surfaces.
|
||||||
|
- A physical path under the project root is not proof of editable ownership.
|
||||||
|
- Retaining text alone is insufficient: fresh analysis can attach different meaning
|
||||||
|
to old positions. Keep the corresponding semantic context.
|
||||||
|
- MCP socket closure is not task completion. Retain consumer state independently.
|
||||||
|
- VS Code normalizes escaped URI components. The first actual-host run exposed
|
||||||
|
mismatched identities from escaped slashes; emitted URIs now use unreserved
|
||||||
|
characters and keep names separately in metadata.
|
||||||
|
- `TextEditor.edit` is an extension programming API, not user typing. The real UI
|
||||||
|
gate uses the `type` command; backend edit proposals are checked independently.
|
||||||
|
If another extension changes a virtual buffer, the provider refuses queries whose
|
||||||
|
text differs from the retained revision.
|
||||||
|
- VS Code MarkdownString properties need direct inspection; JSON serialization can
|
||||||
|
show `{}` even when hover contains valid content.
|
||||||
|
- Enriching a shared definition DTO can accidentally expand references. Keep each
|
||||||
|
surface's admission policy explicit; the compatibility suite caught this coupling.
|
||||||
|
- Do not silently drop external edits from a mixed proposal. Refuse the operation.
|
||||||
|
|
||||||
|
## References
|
||||||
|
|
||||||
|
- [Compiler Spec 23](../../../docs/specs/compiler/23.%20Compiler%20Pipeline%20Entry%20Points%20Specification.md).
|
||||||
|
- [PBS Spec 5](../../../docs/specs/compiler-languages/pbs/5.%20Manifest,%20Stdlib,%20and%20SDK%20Resolution%20Specification.md).
|
||||||
|
- [PBS Spec 8](../../../docs/specs/compiler-languages/pbs/8.%20Stdlib%20Environment%20Packaging%20and%20Loading%20Specification.md).
|
||||||
|
- [Studio Spec 11](../../../docs/specs/studio/11.%20MCP%20Tools%20and%20Project%20Knowledge%20Contract.md).
|
||||||
|
- [Extension guide](../../../tools/vscode-extension/README.md).
|
||||||
|
- [Historical physical-only policy, LSN-0068](../DSC-0039-pbs-lsp-go-to-definition/LSN-0068-pbs-go-to-definition-uses-editorial-lookup-and-physical-files.md).
|
||||||
|
- DEC-0031 / LSN-0049 still govern removal of the old embedded editor/VFS; none was restored.
|
||||||
+178
@@ -0,0 +1,178 @@
|
|||||||
|
---
|
||||||
|
id: LSN-0077
|
||||||
|
ticket: studio-persistent-mcp-connector
|
||||||
|
title: Integrated Studio MCP Through Stable Setup and Ephemeral Access
|
||||||
|
created: 2026-09-29
|
||||||
|
tags: [studio, mcp, connection, lifecycle, installation]
|
||||||
|
---
|
||||||
|
|
||||||
|
# Integrated Studio MCP: Stable Setup, Ephemeral Access
|
||||||
|
|
||||||
|
Owner: **studio**, MCP integration, project lifecycle and local installation.
|
||||||
|
DSC-0070 / DEC-0061 / PLN-0140 delivered this integration, including the user's
|
||||||
|
accepted revision for automatic preparation on project open. These identifiers
|
||||||
|
are historical references; maintained contracts are linked below. Automated
|
||||||
|
validation and the user's confirmation of final manual acceptance are recorded
|
||||||
|
separately.
|
||||||
|
|
||||||
|
## Original Problem
|
||||||
|
|
||||||
|
The original integration exposed a new HTTP port and bearer token on each Studio
|
||||||
|
restart. Developers had to configure their coding client repeatedly. Ad hoc
|
||||||
|
transport scripts then duplicated initialization, authentication and result
|
||||||
|
handling, obscuring native MCP tools and images.
|
||||||
|
|
||||||
|
The durable solution separates three lifetimes: installation, connection and
|
||||||
|
project authority. A stable client registration must not imply durable permission
|
||||||
|
to edit, and a transport interruption must not replay work.
|
||||||
|
|
||||||
|
## Consolidated Design
|
||||||
|
|
||||||
|
The distributed Studio artifact supports two modes. Normal invocation opens the
|
||||||
|
desktop. `StudioLauncher mcp --project <absolute-root>` runs a stdio connector
|
||||||
|
without JavaFX, Spring desktop composition, LSP or a second HTTP server. The coding
|
||||||
|
client owns that process; developers do not launch it manually for each project.
|
||||||
|
|
||||||
|
The desktop starts one shared loopback HTTP server. Opening a project prepares its
|
||||||
|
enabled integration automatically through the same neutral port used by scaffold
|
||||||
|
and the explicit DEV retry. An explicitly disabled integration remains disabled.
|
||||||
|
Preparation failure is visible in DEV and does not make the project unusable.
|
||||||
|
Opening a project does not publish credentials or grant control.
|
||||||
|
|
||||||
|
The macOS installation has a stable `current` reference pointing to a validated,
|
||||||
|
versioned distribution containing dependency JARs and Java. The native client
|
||||||
|
invokes the absolute installed Java path with a classpath/main/project argument
|
||||||
|
array. Updating the installation changes the reference, not every project's client
|
||||||
|
entry. Old versions remain available for rollback and existing processes.
|
||||||
|
|
||||||
|
The tradeoff is an additional lightweight JVM for stdio transport, plus managed
|
||||||
|
installation lifecycle. In return, there are no per-project launchers or copied
|
||||||
|
connector binaries, and execution does not depend on an interactive shell PATH.
|
||||||
|
|
||||||
|
## Configuration and Authority Have Different Owners
|
||||||
|
|
||||||
|
| Surface | Lifetime and responsibility |
|
||||||
|
| --- | --- |
|
||||||
|
| `.studio/setup.json` | Neutral integration intent; preserves runtime/editor settings |
|
||||||
|
| `.codex/config.toml` | Local installed command, arguments and canonical project binding; no transient credentials |
|
||||||
|
| `.studio/mcp/connection.json` | Protected, temporary discovery data published by human grant |
|
||||||
|
| Core grant/task/operation records | In-memory authority and receipts; never restored from configuration |
|
||||||
|
|
||||||
|
Preparation edits only a managed client entry, validates the result with a TOML
|
||||||
|
parser and preserves unrelated settings/comments. User-owned, edited or tracked
|
||||||
|
entries cause explicit conflicts. Initial client trust or reload may still be
|
||||||
|
required; Studio does not change approval policy.
|
||||||
|
|
||||||
|
Human grant publishes a fresh credential scoped to one canonical project root.
|
||||||
|
HTTP sessions are bound to that credential, and the server enforces scope even
|
||||||
|
for knowledge reads. Restricting only the connector would leave a direct HTTP
|
||||||
|
bypass. Acquisition still creates a separate task identity through shared Core
|
||||||
|
services.
|
||||||
|
|
||||||
|
## Publication Is Part of the Grant Transaction
|
||||||
|
|
||||||
|
Publication cannot be a best-effort snapshot listener. The neutral lifecycle port
|
||||||
|
coordinates preparation, publication, activation, invalidation and cleanup:
|
||||||
|
|
||||||
|
1. Save and verify documents under the existing handoff rules.
|
||||||
|
2. Acquire the OS publication lock and write a private temporary descriptor outside
|
||||||
|
the authority monitor.
|
||||||
|
3. Atomically publish, then activate under the grant generation fence. Acquisition
|
||||||
|
remains unavailable until the transition completes.
|
||||||
|
4. Abort failed or superseded grants and remove their provisional access.
|
||||||
|
5. Revoke credentials before asynchronous work cleanup; remove only the owned
|
||||||
|
publication and release its lock.
|
||||||
|
|
||||||
|
The lock file's inode is retained. Deleting it could let another process lock a
|
||||||
|
new inode while the first owner still holds the old one. The OS releases the lock
|
||||||
|
after a crash, allowing safe replacement of stale discovery data. Directories are
|
||||||
|
0700 and secret-bearing files 0600; Git exclusion alone is not access control.
|
||||||
|
Cleanup checks publication ownership so an old callback cannot delete newer data.
|
||||||
|
File cleanup failure must not prevent runtime cancellation.
|
||||||
|
|
||||||
|
## Reconnect Without Replaying Intent
|
||||||
|
|
||||||
|
The stdio connector initializes and lists its packaged catalog before Studio or a
|
||||||
|
grant is available. It verifies live instance, root and catalog identity before
|
||||||
|
forwarding. Calls preserve structured results and native image blocks; response
|
||||||
|
limits are separate from the smaller request limit.
|
||||||
|
|
||||||
|
Discovery and ping may be retried. Build and frame advancement must not be
|
||||||
|
resubmitted automatically after a lost response. Within the same authorized task,
|
||||||
|
recover by operationId/clientRequestId lookup. After restart, old in-memory
|
||||||
|
receipts are unavailable: report an unknown outcome and require a fresh grant/task
|
||||||
|
and an explicit next intent. Connection liveness and working/manual authority are
|
||||||
|
separate DEV states.
|
||||||
|
|
||||||
|
## Implementation Findings
|
||||||
|
|
||||||
|
- JSON-RPC numeric IDs must be compared by numeric value. Jackson can represent
|
||||||
|
the same wire number with different integer node types.
|
||||||
|
- Grant publication is asynchronous. Tests must await the transition without
|
||||||
|
blocking the JavaFX thread or assuming a button callback completes filesystem IO.
|
||||||
|
- `jlink` can generate read-only license files. Normalize staged runtime write
|
||||||
|
permissions so subsequent Gradle installation updates can replace them.
|
||||||
|
- An IntelliJ desktop can run from classes without a managed installation. A
|
||||||
|
generic “preparation incomplete” message hid this prerequisite. The specific
|
||||||
|
diagnostic now points to `:prometeu-app:stageStudioInstallation` and the optional
|
||||||
|
`studio.installationRoot` VM setting.
|
||||||
|
- Preparation belongs to project opening, not only creation or a manual DEV
|
||||||
|
button. Otherwise existing projects retain unnecessary onboarding friction.
|
||||||
|
- Capture data larger than 1 MiB must not inherit the request-body cap. The
|
||||||
|
connector bounds response size and body-read time separately.
|
||||||
|
|
||||||
|
## Verified Results and Acceptance
|
||||||
|
|
||||||
|
The full implementation gate recorded 839 passing tests, 15 existing skips and no
|
||||||
|
failures, including installation, desktop and real runtime gates. The later
|
||||||
|
missing-installation diagnostic and automatic-open revision passed their targeted
|
||||||
|
preparation, Core, app, architecture and runtime suites. Installation staging,
|
||||||
|
`git diff --check` and `discussion validate` also passed.
|
||||||
|
|
||||||
|
Process tests cover cold initialization, later grant and restart in one connector;
|
||||||
|
large images; root/session scope; stale identity/catalog rejection; lost build
|
||||||
|
response with execution count remaining one; unknown old-task receipts; concurrent
|
||||||
|
publisher JVMs and crash recovery; protected files; grant/close races; TOML
|
||||||
|
preservation; and stable installed Java across updates.
|
||||||
|
|
||||||
|
On 2026-09-29, after being asked specifically about the outstanding manual gates,
|
||||||
|
the user confirmed that all were finished. This closes the native Codex
|
||||||
|
acquire/build/image/release and reconnect-after-restart cycle, installation update
|
||||||
|
and graphical-client launch, and IntelliJ debugger attachment. The provenance of
|
||||||
|
this final evidence is **user-reported acceptance**, not an additional automated
|
||||||
|
run or an independently observed transcript. The implementation's automated
|
||||||
|
environment was macOS ARM64 with bundled Corretto 21.0.4 and Codex CLI 0.158.0
|
||||||
|
installed; that version inspection alone was not treated as native-client proof.
|
||||||
|
|
||||||
|
The prior HTTP-only acceptance from DSC-0068 was not substituted for these gates.
|
||||||
|
The first accepted integration remains Codex on macOS; other clients/platforms
|
||||||
|
and the embedded terminal are outside this delivery.
|
||||||
|
|
||||||
|
## Operational Example
|
||||||
|
|
||||||
|
Open the project in Studio. Its enabled client integration is prepared without a
|
||||||
|
separate per-project Run. Start the coding client in that project and satisfy its
|
||||||
|
initial trust/reload requirements. Grant access in DEV, acquire the task through
|
||||||
|
native tools, edit/validate, then release. After Studio restarts, grant again;
|
||||||
|
keep the client configuration unchanged. An old task is never restored.
|
||||||
|
|
||||||
|
For an IntelliJ desktop, run `p.studio.app.StudioLauncher` with the
|
||||||
|
`prometeu-app` classpath and Java 21. If a managed installation is missing, stage
|
||||||
|
it once with `./gradlew :prometeu-app:stageStudioInstallation`. An isolated
|
||||||
|
installation uses the `studio.installationRoot` desktop VM property. The MCP
|
||||||
|
stdio process remains client-owned; attach Remote JVM Debug to that process using
|
||||||
|
an explicit development-only loopback JDWP option. Do not configure the desktop
|
||||||
|
Run itself with `mcp --project` arguments.
|
||||||
|
|
||||||
|
## References
|
||||||
|
|
||||||
|
- DEC-0061 and PLN-0140: historical source decision and completed implementation
|
||||||
|
plan for DSC-0070; removed from active workflow during housekeeping.
|
||||||
|
- [Studio shell and project creation](../../../docs/specs/studio/1.%20Studio%20Shell%20and%20Workspace%20Layout%20Specification.md).
|
||||||
|
- [Project-local state and discovery](../../../docs/specs/studio/8.%20Project-Local%20Studio%20State%20Specification.md).
|
||||||
|
- [Core and adapter architecture](../../../docs/specs/studio/9.%20Studio%20Core%20and%20Adapter%20Architecture%20Specification.md).
|
||||||
|
- [DEV and authority](../../../docs/specs/studio/10.%20DEV%20and%20Automation%20Specification.md).
|
||||||
|
- [MCP contract and acceptance boundary](../../../docs/specs/studio/11.%20MCP%20Tools%20and%20Project%20Knowledge%20Contract.md).
|
||||||
|
- [Setup and IntelliJ debugging](../../../README.md).
|
||||||
|
- [DSC-0068 baseline lesson](../DSC-0068-studio-headless-runtime-ai-first/LSN-0076-ai-first-studio-through-shared-authority-and-headless-evidence.md).
|
||||||
|
- DSC-0071: the separate embedded-terminal discussion; unchanged by this work.
|
||||||
+145
@@ -0,0 +1,145 @@
|
|||||||
|
---
|
||||||
|
id: LSN-0079
|
||||||
|
ticket: compiler-pbx-registry-conformance
|
||||||
|
title: Typed common IR through production PBX admission
|
||||||
|
created: 2026-10-14
|
||||||
|
tags: [runtime-integration]
|
||||||
|
---
|
||||||
|
|
||||||
|
## Original problem and ownership
|
||||||
|
|
||||||
|
Owner: compiler/general; interfaces: compiler/pbs and studio.
|
||||||
|
|
||||||
|
The old producer carried parameter/result slot counts without complete semantic
|
||||||
|
types and emitted a retired PBX function layout. A writer-only repair could not
|
||||||
|
recover signatures, distinguish nominal identities or describe closures and
|
||||||
|
trait implementations. The fix had to cross the entire common producer chain.
|
||||||
|
|
||||||
|
This lesson consolidates AGD-0076, accepted DEC-0063 and completed PLN-0142
|
||||||
|
(DSC-0074). Those workflow artifacts were removed by housekeeping after their
|
||||||
|
normative content and evidence were propagated. The active integration umbrella
|
||||||
|
is [AGD75](../../workflow/agendas/AGD-0075-studio-runtime-readiness.md).
|
||||||
|
|
||||||
|
## Consolidated decisions
|
||||||
|
|
||||||
|
Use stable declaration references before assigning deterministic dense image
|
||||||
|
IDs. Preserve Struct/Trait nominal identity; canonicalize Builtin imports,
|
||||||
|
Array elements and Fn signatures. Names are descriptive, not nominal keys.
|
||||||
|
Parameters, results, captures, implementations and lifecycle roles are explicit
|
||||||
|
common values, preserved through IRVM, optimization and emission.
|
||||||
|
|
||||||
|
The common IR remains serializable by design, but a concrete codec was
|
||||||
|
explicitly deferred. Complete representation does not require selecting a
|
||||||
|
transport format. References avoid recursive Java object graphs and the public
|
||||||
|
contract audit rejects mutable or frontend-specific shapes.
|
||||||
|
|
||||||
|
PBS is one frontend. Optional and Result already belong to PBS's normative
|
||||||
|
language contract and have parser/semantic implementations. Defects in their
|
||||||
|
executable lowering do not justify new backend categories or rejection rules.
|
||||||
|
Their implementation and carrier choices remain frontend-owned. The user
|
||||||
|
explicitly scoped consumer migration to subsequent tickets and a single AGD75
|
||||||
|
integrated delivery. No PBS semantics were added to this backend change.
|
||||||
|
|
||||||
|
## Final implementation
|
||||||
|
|
||||||
|
- IRRegistry and FunctionMetadata represent all five type categories, ordered
|
||||||
|
signatures/captures, roles and implementations. Aggregation remaps callable
|
||||||
|
references while preserving stable type identity.
|
||||||
|
- LinkedRegistry canonicalizes imports/structural declarations deterministically
|
||||||
|
with an iterative dependency traversal. Nominal anchors permit recursion;
|
||||||
|
purely structural cycles reject.
|
||||||
|
- Lowering derives widths from semantic signatures, links typed operands and
|
||||||
|
remaps implementation targets. IRVM coherence and optimization preserve the
|
||||||
|
Registry and function metadata.
|
||||||
|
- The PBX writer emits the 32-byte header and all eight mandatory sections,
|
||||||
|
optional debug, strict UTF-8, exact function records and explicit empty capture
|
||||||
|
environments. Width caches are not serialized. Constant deduplication now
|
||||||
|
relocates PUSH_CONST indices rather than silently changing their meanings.
|
||||||
|
- Local verification decodes all function ranges, validates references and
|
||||||
|
operand categories, forbids retired/raw opcodes and analyzes reachable stack
|
||||||
|
and type facts to convergence. Conflicts become Unknown; exact semantic groups
|
||||||
|
retain provenance when available. Unknown remains subject to runtime checks.
|
||||||
|
- Production loading remains authoritative for native identity/capability/ABI,
|
||||||
|
runtime budgets and executable admission.
|
||||||
|
- Studio previously discarded error.details when a headless response rejected
|
||||||
|
boot. AutomationFailure now preserves the entire runtime error envelope,
|
||||||
|
including initialization, binding and resource details, through MCP output.
|
||||||
|
|
||||||
|
## Examples and pitfalls
|
||||||
|
|
||||||
|
A `vec2 -> vec2` function has logical arity one/one and derived slot widths two/two.
|
||||||
|
The function record writes the two TypeId lists, not the numbers two/two. A test
|
||||||
|
compares that record with independent fixed bytes from the runtime contract.
|
||||||
|
|
||||||
|
A capturing body is not a direct-call target. MAKE_CLOSURE names the body and
|
||||||
|
expected Fn type, consumes its explicit capture groups and produces a callable.
|
||||||
|
CALL_CLOSURE consumes that callable after the explicit arguments. The synthetic
|
||||||
|
frontend test proves this path without PBS source, SDK or language ASTs.
|
||||||
|
|
||||||
|
Jumps contain absolute offsets from the current function start. They are not
|
||||||
|
relative to the next PC. A taken jump to function end is a return boundary;
|
||||||
|
ordinary fallthrough is invalid. These details were checked against the actual
|
||||||
|
runtime verifier, not inferred from older emitter behavior.
|
||||||
|
|
||||||
|
Do not derive type identity from slot width, spelling or display names. Do not
|
||||||
|
claim a self-round-trip proves external conformance. Do not treat parser tests
|
||||||
|
as execution evidence or a load-only argument-taking entry as a boot test.
|
||||||
|
|
||||||
|
Initialization diagnostics have null outer executed PC. A verifier PC remains
|
||||||
|
nested in initError.load.pc; file offsets remain offsets. Preserve the original
|
||||||
|
JSON structure rather than flattening it into human-readable messages.
|
||||||
|
|
||||||
|
## Qualification evidence
|
||||||
|
|
||||||
|
Runtime: `f7d7c167531bb662a1af9d73fc326bb476bf8aa7`.
|
||||||
|
Platform: macOS 27.0.1 arm64. Rust harness uses the runtime Cargo.lock, default
|
||||||
|
load limits and NONE capabilities except the positive native case (SYSTEM).
|
||||||
|
Resource-negative cases explicitly lower Types, TemporaryBytes or Work.
|
||||||
|
Runtime checkout remained unchanged.
|
||||||
|
|
||||||
|
| Gate | Result |
|
||||||
|
| --- | --- |
|
||||||
|
| Build-pipeline suite | 178 tests: 163 passed, 15 skipped, no failures |
|
||||||
|
| Frontend-api suite | 28 passed |
|
||||||
|
| PBS suite | 245 passed; not a claim of complete executable migration |
|
||||||
|
| Headless process suite | 9 passed, including six observed runtime fault payloads |
|
||||||
|
| Architecture suite | 17 passed |
|
||||||
|
| Independent binary oracle | Exact 194-byte minimal image and fixed vec2 function bytes |
|
||||||
|
| Production loader positives | 12 admitted images, including native binding |
|
||||||
|
| Genuine execution | 11 programs: direct/common path, closures/captures, trait, Array/Dynamic, joins, roles, intrinsic and native; vec2 signature is load-only |
|
||||||
|
| Production negative corpus | 32 rejected malformed/binding/code/resource fixtures |
|
||||||
|
| Workflow and patch integrity | discussion validate and git diff --check passed |
|
||||||
|
|
||||||
|
The 15 skipped tests are older conditional integration adapters. The dedicated
|
||||||
|
production harness above ran explicitly; their skip state is not substituted
|
||||||
|
for runtime evidence. The intrinsic/native catalogue goldens are serialization
|
||||||
|
fixtures and do not claim current PBS catalogue compatibility.
|
||||||
|
|
||||||
|
Reproduce with the commands in
|
||||||
|
[the harness README](../../../tools/pbx-conformance/README.md). The harness
|
||||||
|
creates its Cargo build outside the runtime checkout and saves generated PBX and
|
||||||
|
observed JSON under the build-pipeline build directory.
|
||||||
|
|
||||||
|
## Remaining integration work
|
||||||
|
|
||||||
|
The runtime LoadReason enum has four values missing from the published headless
|
||||||
|
schema: LifecycleRole, LifecycleSignature, DuplicateLifecycleRole and
|
||||||
|
NonFiniteValue. The corpus observes the first and last. Both payloads fail the
|
||||||
|
original schema solely because of the missing enum value. The harness explicitly
|
||||||
|
reports this upstream gap, validates the original payload with that single enum
|
||||||
|
addition, and leaves the payload unchanged. It does not claim those two cases
|
||||||
|
conform to the unmodified schema. Runtime must correct the schema under AGD75.
|
||||||
|
|
||||||
|
PBS typed producer migration, Optional/Result executable lowering, catalogue
|
||||||
|
alignment, installed runtime delivery, hook selection, memcard gating and
|
||||||
|
persistence remain with their consumer tickets. The common schema and synthetic
|
||||||
|
producer work without those features. There is no legacy PBX fallback and no
|
||||||
|
slot-to-type inference to conceal an incomplete handoff.
|
||||||
|
|
||||||
|
## References
|
||||||
|
|
||||||
|
- [Typed common Registry/PBX specification](../../../docs/compiler/general/specs/typed-registry-and-pbx-v0.md)
|
||||||
|
- [Backend conformance matrix](../../../docs/specs/compiler/22.%20Backend%20Spec-to-Test%20Conformance%20Matrix.md)
|
||||||
|
- [Runtime qualification harness](../../../tools/pbx-conformance/README.md)
|
||||||
|
- Runtime sources: registry_v0.rs, program_image.rs, registry_verifier, and
|
||||||
|
devtools/headless-protocol/response.schema.json at the revision above.
|
||||||
+182
@@ -0,0 +1,182 @@
|
|||||||
|
---
|
||||||
|
id: LSN-0080
|
||||||
|
ticket: compiler-runtime-catalog-parity
|
||||||
|
title: Manual runtime catalog port and independent conformance
|
||||||
|
created: 2026-10-15
|
||||||
|
tags: [runtime-integration]
|
||||||
|
---
|
||||||
|
|
||||||
|
## Original problem and ownership
|
||||||
|
|
||||||
|
Owner: `compiler/general`; consumers: `compiler/pbs`, `vm-arch` and `studio`.
|
||||||
|
This lesson consolidates AGD-0077, accepted DEC-0064 and completed PLN-0143
|
||||||
|
(DSC-0075), including the user's explicit acceptance revision on 2026-10-15.
|
||||||
|
Their workflow files were removed after propagation and CLI housekeeping.
|
||||||
|
|
||||||
|
The runtime published 105 intrinsics with 18 fields and 15 builtin constants
|
||||||
|
occupying 16 slots. Studio had 42 intrinsic records with 12 fields, no constant
|
||||||
|
mirror and a disabled parity test. Copying the CSV could not update the compiler's
|
||||||
|
manual ABI representation, reject retired endpoints or preserve new effects.
|
||||||
|
Against the previous Studio catalog, the port added 82 identities, removed 19
|
||||||
|
and updated 23 retained identities.
|
||||||
|
|
||||||
|
## Consolidated decision
|
||||||
|
|
||||||
|
The runtime owns identities, layouts, constant values, effects and costs.
|
||||||
|
Studio imports both CSVs unchanged at an explicit target revision, inventories
|
||||||
|
the differences, then manually ports the compiler representation and consumers.
|
||||||
|
`IRVMIntrinsicDefinition` represents the runtime supported by this compiler
|
||||||
|
version. Normal compilation uses local versioned code/resources; it neither
|
||||||
|
queries the latest runtime nor depends on a sibling checkout.
|
||||||
|
|
||||||
|
Manual maintenance keeps compiler adaptations explicit and reviewable, at the
|
||||||
|
cost of maintaining a port. Active comparisons against independently exported
|
||||||
|
CSV data detect drift. Enum generation, a shared implementation library and
|
||||||
|
moving the backend were not required. An explicit provider check uses runtime
|
||||||
|
source/tests to establish behavior and export provenance. A different runtime
|
||||||
|
commit is not itself proof of incompatibility; revision and hashes identify
|
||||||
|
the evidence target without introducing version negotiation.
|
||||||
|
|
||||||
|
Read dispatch, verifier and execution tests as well as CSVs. CSV fields describe
|
||||||
|
the published shape but cannot explain all null handling, native-reference
|
||||||
|
validation, traps or charging behavior.
|
||||||
|
|
||||||
|
## Final implementation
|
||||||
|
|
||||||
|
- `IRVMIntrinsicDefinition` and `IRVMIntrinsicRegistry` cover all 105 entries and
|
||||||
|
18 published fields. Exact name/version resolution and ID lookup reject
|
||||||
|
retired identities; old IDs are not compatibility aliases.
|
||||||
|
- `IRVMBuiltinConstantDefinition` independently groups all 15 constants by
|
||||||
|
target/name/version, preserving ordered slots and exact values/bits. Its
|
||||||
|
materialization supplies common bytecode constant values.
|
||||||
|
- Lowering checks caller counts against the selected definition. IRVM validation,
|
||||||
|
emission and bytecode precheck reject unknown IDs and inconsistent signature
|
||||||
|
caches, including unknown IDs in unreachable code. Module-only IRVM emission
|
||||||
|
derives intrinsic signatures from the same target definitions.
|
||||||
|
- Explicit carrier mappings distinguish Int32, Int64, Float, Bool, String,
|
||||||
|
color and Random. Unsupported tokens fail. Static facts do not claim to prove
|
||||||
|
native handle identity or session validity; the runtime remains authoritative.
|
||||||
|
- Compiler and PBS SDK JARs package both CSVs and provenance from checked-in
|
||||||
|
mirrors at `runtime-catalog/compiler/` and `runtime-catalog/pbs-sdk/`.
|
||||||
|
Installed-resource tests validate actual JAR bytes/hashes outside the checkout.
|
||||||
|
- Active parity tests, synthetic common-IR behavior and the production runtime
|
||||||
|
harness provide separate evidence. No new PBS facade or numeric/random
|
||||||
|
algorithm was implemented in this common backend work.
|
||||||
|
|
||||||
|
## Examples and pitfalls
|
||||||
|
|
||||||
|
**A retained name can have a different ABI.** `input.touch.x/y` moved to
|
||||||
|
`0x2134/0x2135`, lost their receivers and return Int64. Resolving the name alone
|
||||||
|
is insufficient; stale caller counts must fail. Input metadata coverage does
|
||||||
|
not mean the existing PBS input syntax already lowers to these direct queries.
|
||||||
|
|
||||||
|
**Constants are not generic zero-argument intrinsics.** `mathf.pi` and
|
||||||
|
`mathf.tau` materialize Float bits `0x400921FB54442D18` and
|
||||||
|
`0x401921FB54442D18`. `vec2.zero` materializes two Float slots and has no
|
||||||
|
intrinsic ID. Some color names independently have both mechanisms, which does
|
||||||
|
not establish a rule for other constants. Pool deduplication may share the
|
||||||
|
zero value but must preserve both emitted vec2 components.
|
||||||
|
|
||||||
|
**Determinism is not purity.** All four Random intrinsics mutate guest state;
|
||||||
|
only `random.new` allocates. The tested common program aliases one generator,
|
||||||
|
discards a `next` result, then mixes `nextf`, `range` and `next`. Removing the
|
||||||
|
discarded call changes the sequence. Optimized and unoptimized executions
|
||||||
|
matched the independent seed-42 vector and each used 100 cycles/20 steps.
|
||||||
|
`random.range` preserves base cost 4, cost 8 per attempt and limit 64. The VM
|
||||||
|
performs charging; storing metadata does not create a second Java scheduler.
|
||||||
|
|
||||||
|
**Static and dispatch rules can differ.** Runtime `abi_mask` permits String
|
||||||
|
only for intrinsic String arguments, while `value_matches_abi_type` accepts
|
||||||
|
String or null in dispatch. The Studio precheck therefore rejects a proven
|
||||||
|
null at load time. The production loader confirmed that rejection with
|
||||||
|
`LOAD_INVALID_CODE/TypeMismatch`; a String `#AABBCCDD` executed to color
|
||||||
|
`0xAABBCCDD`. Random's static reference mask includes null, leaving native
|
||||||
|
handle validity to runtime checks.
|
||||||
|
|
||||||
|
Do not use a serializer of the Java enum as its own expected catalog, infer
|
||||||
|
carrier identity from slot width, disable stale fixtures to hide regressions,
|
||||||
|
or equate JAR resource parity with successful PBS or installed-host execution.
|
||||||
|
|
||||||
|
## Qualification evidence
|
||||||
|
|
||||||
|
Selected runtime: `f7d7c167531bb662a1af9d73fc326bb476bf8aa7`, clean checkout.
|
||||||
|
Host: macOS 27.0.1 arm64; JDK 25 for Studio build and JDK 21 for the installed
|
||||||
|
launcher. Provider exporter used Cargo test profile/default features; the
|
||||||
|
production VM harness used dev profile/default features and default load
|
||||||
|
limits. New catalog fixtures used NONE capabilities. Runtime was not modified.
|
||||||
|
|
||||||
|
| Artifact | SHA-256 |
|
||||||
|
| --- | --- |
|
||||||
|
| INTRINSICS.csv | `0c1bb78a9b81d1e3480ef5713f3d70f0b06772a7dfab2fd00c1f0a6364f98daa` |
|
||||||
|
| BUILTIN_CONSTANTS.csv | `e407e4718127aa7ef7b1097b5b4b67d86dd979235e73a551a7c36b628cddc039` |
|
||||||
|
|
||||||
|
| Check | Result |
|
||||||
|
| --- | --- |
|
||||||
|
| Build-pipeline suite | 187 tests: 175 passed, 12 existing skips, zero failures |
|
||||||
|
| PBS suite | 245 passed, zero failures; no claim of executable PBS migration |
|
||||||
|
| Normal catalog parity | All fields, identities, constant bits/groups and packaged hashes passed |
|
||||||
|
| Explicit provider check | Committed-source/mirror/hash comparison and real runtime exporter test passed; missing provider failed as required |
|
||||||
|
| Catalog execution corpus | Random with alias/discarded mutation, exact constants, vec2.zero and String conversion passed on the actual VM |
|
||||||
|
| Admission/availability negatives | Removed unreachable ID and proven-null String rejected; known input loaded then trapped UNAVAILABLE without hardware |
|
||||||
|
| Installed catalog gate | Passed using actual compiler/SDK JAR resources and bundled launcher outside the checkout |
|
||||||
|
| Full installed example gate | Failed before and after the port: missing typed metadata for Gfx.clear; explicit consumer handoff and acceptance revision below |
|
||||||
|
| Workflow/patch integrity | `discussion validate` and `git diff --check` passed |
|
||||||
|
|
||||||
|
The complete existing PBX harness corpus also passed with its already documented
|
||||||
|
runtime schema exceptions: LifecycleRole and NonFiniteValue remain absent from
|
||||||
|
the published fault-schema enum. The harness reports these gaps and preserves
|
||||||
|
payloads; this port does not claim the upstream schema was corrected.
|
||||||
|
|
||||||
|
Reproduce the catalog and consumer checks from the repository root:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
./gradlew :prometeu-compiler:prometeu-build-pipeline:test :prometeu-compiler:frontends:prometeu-frontend-pbs:test --console=plain
|
||||||
|
./gradlew :prometeu-app:installedKnowledgeTest --tests '*installedCompilerAndSdkCarryTheSameVerifiedCatalog' --console=plain
|
||||||
|
python3 tools/runtime-catalog/verify.py --runtime ../runtime
|
||||||
|
python3 tools/pbx-conformance/run.py --runtime ../runtime
|
||||||
|
```
|
||||||
|
|
||||||
|
## Accepted boundary and remaining consumer work
|
||||||
|
|
||||||
|
The full `:prometeu-app:installedKnowledgeTest` failed with
|
||||||
|
`LOWER_IRVM_INVALID_TYPED_REGISTRY: typed function metadata required: Gfx.clear`.
|
||||||
|
The same failure was reproduced on an independent archive of previous Studio
|
||||||
|
HEAD `bd5694dbdf5b214b4295fc8e01ddbe0ba5479599`; only diagnostic stdout was
|
||||||
|
enabled in its test probe to reveal the exact existing error.
|
||||||
|
|
||||||
|
On 2026-10-15 the user explicitly approved concluding catalog acceptance and
|
||||||
|
leaving that correction with AGD-0078. DEC-0064 and PLN-0143 recorded this precise
|
||||||
|
revision before housekeeping: the installed catalog probe is this delivery's
|
||||||
|
mandatory installed gate; the full example test remains active and failing.
|
||||||
|
All catalog, common behavior, affected module and provider-execution checks
|
||||||
|
remain required and passed. No general waiver for future failures was granted.
|
||||||
|
|
||||||
|
- AGD-0078 owns PBS typed metadata, existing input/types and vec2 source
|
||||||
|
materialization. Correct the Gfx.clear producer path and rerun the full
|
||||||
|
installed example gate; do not weaken the common typed Registry contract.
|
||||||
|
- AGD-0083 owns math/mathf facades, overloads and source constant exposure.
|
||||||
|
`PbsExecutableBodyLowerer.emitBuiltinConstFetch` still assumes an intrinsic
|
||||||
|
with one return; pi/tau require the independent constant materialization path.
|
||||||
|
- AGD-0084 owns PBS Random handles, storage, aliasing and source replay tests.
|
||||||
|
Common-IR execution provides a base, not proof of the future PBS facade.
|
||||||
|
- AGD-0080 owns actual installed-runtime Build/Play/headless qualification.
|
||||||
|
Catalog resources identify the compiler target without proving that flow.
|
||||||
|
|
||||||
|
These handoffs and the explicit acceptance revision are recorded in the active
|
||||||
|
agendas and [integration umbrella](../../workflow/agendas/AGD-0075-studio-runtime-readiness.md).
|
||||||
|
Future catalog updates must review source, imports, manual consumers, provenance
|
||||||
|
and behavior together. Roll back that set together if necessary.
|
||||||
|
|
||||||
|
## References
|
||||||
|
|
||||||
|
- [Normative catalog support](../../../docs/compiler/general/specs/runtime-catalog-support.md)
|
||||||
|
- [Typed common Registry/PBX contract](../../../docs/compiler/general/specs/typed-registry-and-pbx-v0.md)
|
||||||
|
- [VM mirror and provider verification policy](../../../docs/vm-arch/README.md)
|
||||||
|
- [Production runtime harness](../../../tools/pbx-conformance/README.md)
|
||||||
|
- Runtime sources at the recorded revision: catalog.rs, builtins.rs,
|
||||||
|
input_intrinsics.rs, math_intrinsics.rs, random_intrinsics.rs, random.rs,
|
||||||
|
registry_verifier/{heights,types}.rs and tests/numeric_contract.rs.
|
||||||
|
|
||||||
|
Workflow tooling note: the installed CLI registers an existing lesson but has
|
||||||
|
no lesson-allocation command. LSN-0080 was selected by reading the next counter;
|
||||||
|
`discussion housekeep` performed all index mutations and counter advancement.
|
||||||
+83
@@ -0,0 +1,83 @@
|
|||||||
|
---
|
||||||
|
id: LSN-0081
|
||||||
|
ticket: pbs-existing-types-input-alignment
|
||||||
|
title: PBS Typed Values and Direct Input Queries
|
||||||
|
created: 2026-10-15
|
||||||
|
tags: [compiler/pbs, runtime-integration]
|
||||||
|
---
|
||||||
|
|
||||||
|
## Context and result
|
||||||
|
|
||||||
|
Owner: **compiler/pbs**, with shared compiler IR and installed Studio consumer propagation. DSC-0076 (AGD-0078, accepted DEC-0065, completed PLN-0144) aligned existing PBS values and input with the published runtime. The original object chain exposed intermediate input objects that had no useful runtime representation. PBS also omitted exact executable function metadata, causing the full installed example to fail at `Gfx.clear` under the shared typed registry validator.
|
||||||
|
|
||||||
|
The delivered implementation replaces those chains, produces typed function metadata, preserves complete value groups, and passes both actual-runtime execution and the full installed knowledge gate. The completed agenda, decision and plan were removed through framework housekeeping; this lesson preserves their implementation evidence.
|
||||||
|
|
||||||
|
## Public selectors and direct runtime endpoints
|
||||||
|
|
||||||
|
Use a nominal selector value and a public query:
|
||||||
|
|
||||||
|
```pbs
|
||||||
|
let button = Button.A;
|
||||||
|
let pressed = Pad.pressed(button);
|
||||||
|
let frames: long = Pad.hold(button);
|
||||||
|
let x: long = Touch.x();
|
||||||
|
```
|
||||||
|
|
||||||
|
`Button` has twelve cases: Up, Down, Left, Right, A, B, X, Y, L, R, Start, Select. The four Pad operations are pressed, released, down and hold. Each public function dispatches through an exhaustive enum switch to one of the 48 zero-argument LowPad endpoints. For example, `Pad.pressed(Button.A)` reaches `LowPad.a_pressed()`, bound to `input.pad.a.pressed`. The selector is evaluated once and only the selected endpoint reads input. Obtaining or passing a Button has no input effect. Constant specialization is unnecessary for correctness.
|
||||||
|
|
||||||
|
Touch exposes pressed/released/down as Bool and hold/x/y as Int64. The implementation uses existing runtime endpoints, with no ABI or lifecycle redesign. `Input.pad().a()` and aliases of its intermediate object are removed; import diagnostics explain the replacement. Strings, integers and unrelated enums cannot substitute for Button. The source type remains nominal even though its executable carrier is Int32.
|
||||||
|
|
||||||
|
## Exact values must survive frontend lowering
|
||||||
|
|
||||||
|
The explicitly accepted integer mapping is `int` to Int32 and `long` to Int64. Integer literals default to int; an explicit long context admits Int64 literals. Conversions use existing `as` syntax. Variables of different numeric widths require explicit conversion. Pad.hold and Touch.hold/x/y therefore return long.
|
||||||
|
|
||||||
|
`PbsRuntimeTypes` connects source types and declarations to canonical registry types and exact parameter/result groups. Callable lookup includes arity so overloaded SDK functions do not overwrite each other's signatures. Existing unsupported source types retain their previous executable boundary; shared strict metadata validation was not relaxed to admit them.
|
||||||
|
|
||||||
|
Locals, parameters, calls and returns carry whole groups: vec2 uses two Float slots and pixel uses two Int64 coordinates plus color. Slot count alone never establishes type identity. Builtin constants are resolved through the shared constant catalog: vec2.zero materializes two Float zero values, without inventing a one-result intrinsic. The backend validates the declared group width against the catalog materialization.
|
||||||
|
|
||||||
|
Named application first evaluates expressions in source order, stores their complete groups, and then loads those values in parameter order. The runtime proof calls `combine apply (y: Probe.y(), x: Probe.x())`: effects record Y then X while combine receives x then y. Its final oracle is 211020.
|
||||||
|
|
||||||
|
## Qualification evidence
|
||||||
|
|
||||||
|
Qualification date: 2026-10-15; platform: Darwin arm64. Studio base revision: `603ed012272b137361ba618f6887f015f7317803` plus this delivery's working-tree changes. Runtime revision: `f7d7c167531bb662a1af9d73fc326bb476bf8aa7`. The runtime checkout was not modified. Default Gradle configuration; controlled input and no-platform configurations in the real runtime harness.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
./gradlew :prometeu-compiler:frontends:prometeu-frontend-pbs:test :prometeu-compiler:prometeu-build-pipeline:test :prometeu-compiler:prometeu-frontend-api:test :prometeu-lsp:prometeu-lsp-v1:test :prometeu-app:installedKnowledgeTest --console=plain
|
||||||
|
CARGO_TARGET_DIR=/tmp/pln144-cargo-target python3 tools/pbx-conformance/run.py --runtime ../runtime
|
||||||
|
git diff --check
|
||||||
|
discussion validate
|
||||||
|
```
|
||||||
|
|
||||||
|
| Suite | Passed | Existing skips | Failures/errors |
|
||||||
|
| --- | ---: | ---: | ---: |
|
||||||
|
| PBS frontend | 246 | 0 | 0 |
|
||||||
|
| Build pipeline | 179 | 12 | 0 |
|
||||||
|
| Frontend API | 28 | 0 | 0 |
|
||||||
|
| LSP | 38 | 1 | 0 |
|
||||||
|
| Full installed knowledge | 2 | 0 | 0 |
|
||||||
|
|
||||||
|
`PbsRuntimeAlignmentTest` generates 114 PBX programs through the production compiler, lowerer, emitter and preload verifier. The actual runtime harness loads and executes all of them:
|
||||||
|
|
||||||
|
- 48 Pad combinations using a local Button passed through a typed function, plus 48 direct constant combinations; controlled input asserts the exact returned value and exactly one selected read.
|
||||||
|
- All six Touch queries, including signed x/y values. All 102 input programs are also executed without a platform and must trap with TRAP_UNAVAILABLE.
|
||||||
|
- Twelve value/fault programs cover Int32, Int64, Float, String, color, vec2, pixel, tuple returns, named evaluation order, Int32 wrapping, checked narrowing and division by zero. Bool is covered by input queries. Registry default layouts are checked for all eight existing canonical value types.
|
||||||
|
|
||||||
|
Frontend negatives cover invalid Button arguments, mixed int/long variables, literal overflow and migration diagnostics. Existing shared tests continue to cover wrong typed signatures, stale touch signatures, unreachable removed IDs, and lifecycle assembly. The original full installed failure at `Gfx.clear` is fixed. This does not claim completion of the separate Studio desktop integration agenda. Existing upstream fault-schema gaps (LifecycleRole/NonFiniteValue) remain explicitly reported by the shared harness, without suppressing this delivery's oracles.
|
||||||
|
|
||||||
|
## Pitfalls and reusable patterns
|
||||||
|
|
||||||
|
- A dotted builtin target is already a complete catalog name: use `input.pad.a.pressed`, not a partial `a.pressed` that silently loses its owner.
|
||||||
|
- A numeric literal's context must reach calls, returns and constructors; parsing an integer into a wide host value is insufficient to give it an Int64 guest type.
|
||||||
|
- Handle the signed minimum literal before rejecting its positive magnitude. A positive value above Int64 maximum must produce a diagnostic, not become zero.
|
||||||
|
- Preserve catalog overflow behavior: Int32 addition wraps; out-of-range narrowing traps with TRAP_NUMERIC_RANGE. Do not assume all numeric operations trap on overflow.
|
||||||
|
- A switch can omit its final comparison only when exhaustive coverage is proven. Non-exhaustive statement switches must not execute an unmatched final arm.
|
||||||
|
- A catalog or structural test alone cannot prove a frontend consumer. Generate PBS programs, run the real VM, and keep the full installed example as an independent gate.
|
||||||
|
- Publish the focused canonical spec in installed knowledge as well as in the checkout. SDK exports, diagnostics, language services and examples must migrate together.
|
||||||
|
|
||||||
|
## References
|
||||||
|
|
||||||
|
- [Normative PBS input and existing-value contract](../../../docs/compiler/pbs/specs/input-and-existing-type-runtime-alignment.md)
|
||||||
|
- [Shared runtime catalog contract](../../../docs/compiler/general/specs/runtime-catalog-support.md)
|
||||||
|
- [Typed registry and PBX contract](../../../docs/compiler/general/specs/typed-registry-and-pbx-v0.md)
|
||||||
|
- [PBS source-to-PBX qualification](../../../prometeu-compiler/prometeu-build-pipeline/src/test/java/p/studio/compiler/backend/irvm/PbsRuntimeAlignmentTest.java)
|
||||||
|
- [Actual-runtime harness instructions](../../../tools/pbx-conformance/README.md)
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
# Runtime catalog support
|
||||||
|
|
||||||
|
Status: normative. Owner: `compiler/general`.
|
||||||
|
|
||||||
|
## Authority and update boundary
|
||||||
|
|
||||||
|
The runtime owns intrinsic identities, ABI layouts, effects, costs and builtin
|
||||||
|
constants. Studio MUST keep byte-identical copies of the selected provider's
|
||||||
|
`INTRINSICS.csv` and `BUILTIN_CONSTANTS.csv` under `docs/vm-arch`. The sibling
|
||||||
|
`runtime-catalog.properties` records the provider revision and SHA-256 of both
|
||||||
|
files. These mirrors are reference data, not an independent runtime contract.
|
||||||
|
|
||||||
|
An update MUST import both catalogs, inventory additions/removals and field
|
||||||
|
changes, manually port the compiler consumers, verify behavior and update the
|
||||||
|
packaged provenance together. A CSV-only change is not a completed integration.
|
||||||
|
Read the selected runtime's implementation and tests when porting behavior;
|
||||||
|
CSV fields alone do not explain dispatch, reference validation or charging.
|
||||||
|
|
||||||
|
Normal builds MUST use local versioned sources and resources. They MUST NOT
|
||||||
|
query the latest runtime or depend on a sibling runtime checkout. An explicit
|
||||||
|
provider verification command requires the recorded revision and fails when
|
||||||
|
the source is missing, modified or different. That evidence requirement does
|
||||||
|
not make a different runtime revision inherently incompatible.
|
||||||
|
|
||||||
|
## Manual intrinsic representation
|
||||||
|
|
||||||
|
`IRVMIntrinsicDefinition` is the explicit compiler representation of its runtime
|
||||||
|
target. It MUST preserve every published record and field: IDs, canonical
|
||||||
|
identity/version, owner/name, argument/result counts and layouts, determinism,
|
||||||
|
allocation, parameter names, guest-state mutation, base/fixed cycles, cost model,
|
||||||
|
attempt cycles and maximum attempts. `IRVMIntrinsicRegistry` resolves exact
|
||||||
|
identities and IDs. Retired entries MUST NOT survive as aliases.
|
||||||
|
|
||||||
|
Lowering MUST validate caller-supplied counts against the selected definition.
|
||||||
|
Validation and emission MUST reject unknown IDs and inconsistent signatures,
|
||||||
|
including unknown IDs in unreachable bytecode. A name retained by the provider
|
||||||
|
does not imply an unchanged ABI; input touch coordinates illustrate a change
|
||||||
|
from receiver-based calls to zero-argument queries.
|
||||||
|
|
||||||
|
Carrier mappings MUST be explicit. Int32 and Int64 remain distinct despite equal
|
||||||
|
slot widths. Layout order and complete groups MUST be preserved. Native color
|
||||||
|
and Random contracts MUST NOT be inferred from arbitrary one-slot integers or
|
||||||
|
references. Producer checks validate proven carrier facts; runtime admission
|
||||||
|
and execution remain authoritative for reference identity, session ownership,
|
||||||
|
platform availability and traps. Unsupported carrier tokens MUST fail explicitly.
|
||||||
|
|
||||||
|
Static intrinsic String facts MUST follow the provider verifier's String-only
|
||||||
|
mask: a proven null is rejected at load time. The dispatcher's acceptance of
|
||||||
|
null for the String ABI does not broaden that static rule. Random's static
|
||||||
|
reference mask includes null; native handle validity is still checked at runtime.
|
||||||
|
|
||||||
|
Determinism MUST NOT be interpreted as purity. In particular, all Random calls
|
||||||
|
mutate guest state. Reachable calls cannot be removed, merged or reordered in a
|
||||||
|
way that changes effects, traps or charged work, even when their results are
|
||||||
|
discarded. Variable-cost descriptors MUST remain variable: `random.range` has
|
||||||
|
base cost 4, cost 8 per attempt and a maximum of 64 attempts in the selected
|
||||||
|
contract. The runtime performs charging; Java metadata does not implement a
|
||||||
|
second scheduler or random algorithm.
|
||||||
|
|
||||||
|
## Constants
|
||||||
|
|
||||||
|
Builtin constants have their own lookup identity `(target, name, version)` and
|
||||||
|
ordered slot values. They MUST NOT be resolved by inventing an intrinsic with
|
||||||
|
the same name. Some color names have both a constant and a separately published
|
||||||
|
intrinsic; this does not establish a generic equivalence.
|
||||||
|
|
||||||
|
The manual constant representation MUST preserve all carriers and exact values.
|
||||||
|
Float constants are materialized from published IEEE-754 bits. `vec2.zero` is
|
||||||
|
two ordered Float slots and has no intrinsic ID. Materialization and emission
|
||||||
|
MUST preserve the whole group; source-language exposure remains frontend-owned.
|
||||||
|
|
||||||
|
## Distribution and conformance
|
||||||
|
|
||||||
|
The compiler JAR packages the two catalogs and provenance at
|
||||||
|
`runtime-catalog/compiler/`; the PBS SDK JAR packages the same three files at
|
||||||
|
`runtime-catalog/pbs-sdk/`. Both copies MUST derive from the checked-in mirrors
|
||||||
|
and agree byte-for-byte. The metadata identifies the represented target contract;
|
||||||
|
it does not assert that every catalog entry already has a PBS facade.
|
||||||
|
|
||||||
|
Normal tests MUST compare every manually maintained field with the independently
|
||||||
|
published CSV, verify constant bits/groups and check packaged hashes. They MUST
|
||||||
|
run without a runtime checkout and MUST NOT be disabled or silently skip parity.
|
||||||
|
Explicit provider checks also run the real runtime catalog exporter test;
|
||||||
|
parsing only one Rust table is insufficient because the catalog spans several
|
||||||
|
implementation modules.
|
||||||
|
|
||||||
|
Behavioral tests MUST cover changed signatures, retired IDs, scalar carriers,
|
||||||
|
complete groups, stateful call order and emitted values. Evidence from the
|
||||||
|
selected runtime MUST identify revision, platform and configuration and distinguish
|
||||||
|
catalog comparison, image loading and execution. PBS facade delivery and
|
||||||
|
installed-runtime qualification remain separate consumer claims.
|
||||||
|
|
||||||
|
See [typed common Registry and PBX v0](typed-registry-and-pbx-v0.md) for the
|
||||||
|
frontend/backend boundary and [mirror policy](../../../vm-arch/README.md) for
|
||||||
|
explicit verification commands.
|
||||||
|
|
||||||
|
|
||||||
|
## PBS consumer
|
||||||
|
|
||||||
|
The [PBS input and value alignment contract](../../pbs/specs/input-and-existing-type-runtime-alignment.md)
|
||||||
|
requires typed Pad/Button dispatch, direct LowPad endpoints and complete builtin
|
||||||
|
value groups. Frontend numeric literal and builtin-constant operations retain
|
||||||
|
explicit identity and width; common lowering resolves constant groups against
|
||||||
|
`IRVMBuiltinConstantDefinition` and checks the declared result width. PBS does
|
||||||
|
not introduce another catalog. Source execution and the full installed example
|
||||||
|
are separate consumer gates beyond CSV parity.
|
||||||
@@ -0,0 +1,182 @@
|
|||||||
|
# Typed common Registry and PBX v0
|
||||||
|
|
||||||
|
Status: normative. Owner: `compiler/general`. Runtime contract reference:
|
||||||
|
`runtime` revision `f7d7c167531bb662a1af9d73fc326bb476bf8aa7`,
|
||||||
|
`docs/specs/runtime/02c-program-registry-and-pbx-v0.md` and
|
||||||
|
`docs/vm-arch/ISA_CORE.md` in that repository.
|
||||||
|
|
||||||
|
## Ownership and handoff
|
||||||
|
|
||||||
|
Every executable frontend MUST provide its semantic types through the common
|
||||||
|
`IRRegistry` model and typed `FunctionMetadata`. The backend MUST NOT inspect
|
||||||
|
language ASTs, PBS names, Optional/Result syntax, or frontend-specific classes.
|
||||||
|
Language carriers and their lowering remain owned by the frontend. A carrier
|
||||||
|
can use ordinary Struct, Array, Trait, Fn and Builtin declarations without
|
||||||
|
introducing a language category in the backend.
|
||||||
|
|
||||||
|
The public model consists of immutable values and ordered `ReadOnlyList`
|
||||||
|
collections. References use explicit declaration keys and callable IDs, not
|
||||||
|
object identity or recursive object graphs. It is serializable by design;
|
||||||
|
no concrete IR codec, wire format or persistence protocol is selected.
|
||||||
|
|
||||||
|
A function declares ordered named parameters, ordered logical results, ordered
|
||||||
|
captures, a lifecycle role and an optional name. Empty names differ from absent
|
||||||
|
names. Captures are an environment, never hidden parameters. Slot counts are
|
||||||
|
derived from types; existing count fields are checked caches, not semantic
|
||||||
|
input. Missing nonempty type metadata is an invalid handoff, not a request to
|
||||||
|
infer types from counts. Optimizers MUST preserve metadata and typed operands.
|
||||||
|
|
||||||
|
## Identity and linking
|
||||||
|
|
||||||
|
TypeId, FunctionId and ImplementationId are separate dense image-local index
|
||||||
|
domains. Index zero is valid. Trait references use TypeIds; field and method
|
||||||
|
indices are local to their owner. Source declaration keys MUST identify the
|
||||||
|
same declaration across repeated module imports and distinguish unrelated
|
||||||
|
nominal declarations, even when names and shapes coincide.
|
||||||
|
|
||||||
|
Linking is deterministic. The selected physical entry is FunctionId zero;
|
||||||
|
remaining functions follow canonical module/callable/source ordering. Struct
|
||||||
|
and Trait retain nominal identity. Builtin imports deduplicate by BuiltinId,
|
||||||
|
Array by canonical element identity, and Fn by ordered parameter/result type
|
||||||
|
identities, excluding names. Forward references and recursion through nominal
|
||||||
|
anchors are valid. Pure Array/Fn cycles are invalid. Every reference must
|
||||||
|
resolve before emission. Frontends should supply only used imports.
|
||||||
|
|
||||||
|
| BuiltinId | Type | Slots |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `0x0001` | color | 1 |
|
||||||
|
| `0x0002` | vec2 | 2 |
|
||||||
|
| `0x0003` | pixel | 3 |
|
||||||
|
| `0x0010` | Int32 | 1 |
|
||||||
|
| `0x0011` | Int64 | 1 |
|
||||||
|
| `0x0012` | Float | 1 |
|
||||||
|
| `0x0013` | Bool | 1 |
|
||||||
|
| `0x0014` | String | 1 |
|
||||||
|
| `0x0015` | Dynamic | 2 |
|
||||||
|
| `0x0016` | Random | 1 |
|
||||||
|
|
||||||
|
The retired input IDs `0x0100`–`0x0102` have no aliases. Struct, Array and Fn
|
||||||
|
values occupy one reference slot; Trait values occupy two slots. Width does
|
||||||
|
not establish type identity or authorize conversion.
|
||||||
|
|
||||||
|
## Binary contract
|
||||||
|
|
||||||
|
All fields are little-endian. The header is 32 bytes: `PBX\0`, u16 version zero,
|
||||||
|
zero endian/reserved bytes, u32 section count and twenty zero reserved bytes.
|
||||||
|
Directory entries are u32 kind, file-relative offset and length. Ranges must
|
||||||
|
not overlap or overflow. The version remains zero; no legacy fallback exists.
|
||||||
|
|
||||||
|
Mandatory sections are constants (0), functions (1), Code (2), exports (4),
|
||||||
|
syscalls (5), types (6), implementations (7) and captures (8). Debug (3) is
|
||||||
|
optional. Empty tables contain a u32 zero count. Code is raw bytes, not a
|
||||||
|
counted table. An empty table set is serializable but is not an executable
|
||||||
|
program: production loading requires a valid ordinary entry.
|
||||||
|
|
||||||
|
Lists have u32 counts. Optional names use u8 presence 0/1, then u32 UTF-8 byte
|
||||||
|
length and bytes when present. UTF-8 is strict. Named types contain TypeId then
|
||||||
|
optional name; results and captures contain TypeIds without names.
|
||||||
|
|
||||||
|
| Record | Ordered payload |
|
||||||
|
| --- | --- |
|
||||||
|
| Type | u8 tag, optional name, category payload |
|
||||||
|
| Builtin (tag 0) | u32 BuiltinId |
|
||||||
|
| Struct (tag 1) | named fields |
|
||||||
|
| Array (tag 2) | u32 element TypeId |
|
||||||
|
| Trait (tag 3) | methods: optional name, parameters, results |
|
||||||
|
| Fn (tag 4) | parameters, results |
|
||||||
|
| Function | u8 role, optional name, parameters, results, u32 Code offset, length, extra locals, max temporaries |
|
||||||
|
| Implementation | u32 owner TypeId, trait TypeId, method count, ordered FunctionIds |
|
||||||
|
| Captures | function count and one ordered TypeId list per function, including empty lists |
|
||||||
|
|
||||||
|
Function Code offsets are Code-relative. Parameter/result slot counts MUST NOT
|
||||||
|
be serialized. Max temporaries zero means zero. Signature names are independent
|
||||||
|
of debug names. Constants retain tags Null 0, Int64 1, Float64 2, Boolean 3,
|
||||||
|
String 4 and Int32 5. Float payloads must be finite. Constant deduplication
|
||||||
|
requires relocating every PUSH_CONST index; changing only the table is invalid.
|
||||||
|
|
||||||
|
Roles are None 0, BeforePause 1, BeforeResume 2 and MemcardBoot 3. Nonzero roles
|
||||||
|
are unique, cannot target entry zero and cannot capture. Pause/resume have empty
|
||||||
|
signatures; MemcardBoot has `(Int64) -> Int32`. This metadata does not implement
|
||||||
|
frontend hook selection, mem.bootstrap gating or persistence.
|
||||||
|
|
||||||
|
Implementations are unique per Struct/Trait pair, complete and ordered. Each
|
||||||
|
method target has an exact signature with a concrete Struct receiver first,
|
||||||
|
followed by the trait method's explicit parameters. Targets cannot capture.
|
||||||
|
|
||||||
|
## Instructions and verification
|
||||||
|
|
||||||
|
Instructions use u16 opcodes. Jump operands are absolute u32 byte offsets from
|
||||||
|
the current function start, not displacements from the next instruction.
|
||||||
|
A taken jump to the current function end is a return boundary; ordinary
|
||||||
|
fallthrough past the end is invalid.
|
||||||
|
|
||||||
|
| Opcode | Typed operands |
|
||||||
|
| --- | --- |
|
||||||
|
| MAKE_CLOSURE `0x52` | FunctionId, Fn TypeId |
|
||||||
|
| CALL_CLOSURE `0x53` | expected Fn TypeId |
|
||||||
|
| GET_CAPTURE `0x57` | capture group index |
|
||||||
|
| CALL_TRAIT `0x58` | Trait TypeId, method index |
|
||||||
|
| DYN_PACK/UNPACK/CAN_UNPACK `0x90`–`0x92` | TypeId |
|
||||||
|
| Reference operations `0x93`–`0x96` | source TypeId, target TypeId |
|
||||||
|
| STRUCT_NEW `0xa0` | Struct TypeId |
|
||||||
|
| STRUCT_GET/SET `0xa1`–`0xa2` | Struct TypeId, field index |
|
||||||
|
| Array operations `0xa3`–`0xa6` | Array TypeId |
|
||||||
|
|
||||||
|
Direct CALL cannot target a capturing body. Closure signatures match exactly.
|
||||||
|
Retired SPAWN/YIELD/SLEEP (`0x54`–`0x56`) and raw producer SYSCALL are invalid,
|
||||||
|
even when unreachable. All function ranges must decode completely; references,
|
||||||
|
categories, operand boundaries, finite immediates and branch destinations are
|
||||||
|
checked even in unreachable instructions.
|
||||||
|
|
||||||
|
Reachable analysis uses a bounded worklist. Parameters initialize local facts;
|
||||||
|
extra locals start Null and may change type. Joins require equal temporary
|
||||||
|
heights. Equal facts survive; conflicting facts widen to Unknown. Type errors
|
||||||
|
are diagnosed after convergence. Unknown alone neither proves compatibility
|
||||||
|
nor justifies rejection. Runtime group checks remain authoritative. RET and
|
||||||
|
jump-to-end require exact result width and compatible known facts. GET/SET_LOCAL
|
||||||
|
address only parameters plus extra locals. No implicit numeric, trait or Dynamic
|
||||||
|
conversion is introduced by linking, writing or verification.
|
||||||
|
|
||||||
|
HOSTCALL references a declared canonical `(module, name, version)` identity
|
||||||
|
with exact argument/result slot ABI. Duplicate identities with conflicting ABI,
|
||||||
|
unused declarations and invalid indices are rejected. Only the runtime loader
|
||||||
|
binds capabilities and rewrites HOSTCALL to SYSCALL. Intrinsic signatures are
|
||||||
|
explicit compiler metadata; their IDs and definitive ABI remain runtime-owned.
|
||||||
|
|
||||||
|
## Bounds and diagnostics
|
||||||
|
|
||||||
|
Product ceilings: PBX 64 MiB, Code 32 MiB, 65,536 types and functions each,
|
||||||
|
262,144 implementations, 1,048,576 nested records, names 4,096 bytes individually
|
||||||
|
and 4 MiB aggregate, frame 16,384 slots and results 1,024 slots. Runtime admission
|
||||||
|
also owns retained Registry 64 MiB, scratch 128 MiB and work 268,435,456. A guest
|
||||||
|
cannot raise these limits. Java validation is not a substitute for runtime
|
||||||
|
allocation accounting or final `ValidatedProgramImage::load` admission.
|
||||||
|
|
||||||
|
Compilation failures use common LOWER_IRVM/MARSHAL stage diagnostics. Load,
|
||||||
|
binding and resource failures remain distinct from executed traps. Studio
|
||||||
|
preserves the full runtime error envelope in `AutomationFailure.runtimeError`,
|
||||||
|
including null fields and native binding details. The outer initialization
|
||||||
|
fault PC remains null. A verifier PC stays in `initError.load.pc`; a file offset
|
||||||
|
MUST NOT become an executed PC.
|
||||||
|
|
||||||
|
## Reproducible conformance
|
||||||
|
|
||||||
|
Run the focused common tests, then the production harness:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
./gradlew :prometeu-compiler:prometeu-build-pipeline:test --tests '*LinkedRegistryTest' --tests '*PbxRegistryConformanceTest' --tests '*TypedCommonPipelineTest'
|
||||||
|
python3 tools/pbx-conformance/run.py --runtime ../runtime
|
||||||
|
```
|
||||||
|
|
||||||
|
The Java tests write `build/registry-conformance` inside the build-pipeline
|
||||||
|
module. The harness builds outside the runtime checkout using its Cargo.lock,
|
||||||
|
loads Java-produced bytes, executes admitted zero-argument fixtures, validates
|
||||||
|
structured failures against the published schema and records the runtime hash,
|
||||||
|
platform, capabilities and limits. Parsing, loading and execution are separate
|
||||||
|
claims. The vec2 signature fixture is load-only; it is not a zero-argument boot.
|
||||||
|
|
||||||
|
The fixed 194-byte minimal image comes from the independent runtime test oracle.
|
||||||
|
Synthetic common IR additionally exercises linking, lowering, optimization and
|
||||||
|
emission without PBS. Frontend migration and integrated release readiness are
|
||||||
|
tracked separately in AGD75; passing common conformance does not claim complete
|
||||||
|
PBS lowering or complete Studio/runtime integration.
|
||||||
@@ -0,0 +1,136 @@
|
|||||||
|
# PBS input and existing value runtime alignment
|
||||||
|
|
||||||
|
Status: normative. Owner: `compiler/pbs`. Common ABI authority:
|
||||||
|
[typed Registry/PBX](../../general/specs/typed-registry-and-pbx-v0.md) and
|
||||||
|
[runtime catalogs](../../general/specs/runtime-catalog-support.md).
|
||||||
|
|
||||||
|
## Source types and exact carriers
|
||||||
|
|
||||||
|
| PBS source | Runtime identity | Ordered slots |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| `int` | Int32 | Int32 |
|
||||||
|
| `long` | Int64 | Int64 |
|
||||||
|
| `float` | Float | Float (binary64) |
|
||||||
|
| `bool` | Bool | Bool |
|
||||||
|
| `str` | String | String |
|
||||||
|
| builtin `color` shell | color | Int64 constrained to RGBA8888 |
|
||||||
|
| builtin `vec2` shell | vec2 | Float x, Float y |
|
||||||
|
| builtin `pixel` shell | pixel | Int64 x, Int64 y, Int64 color |
|
||||||
|
|
||||||
|
The canonical builtin metadata determines a shell's identity; its source name
|
||||||
|
is not an ABI lookup rule. Equal widths do not permit substitution. Function
|
||||||
|
metadata MUST declare ordered parameter and result identities. Slot counts are
|
||||||
|
checked caches derived from those identities. Calls, locals and returns MUST
|
||||||
|
preserve entire value groups. A vec2 is one logical value with two slots;
|
||||||
|
a named output tuple is a fixed sequence of logical results, not a heap object.
|
||||||
|
|
||||||
|
`int` and `long` are distinct. Integer literals default to `int`; explicit
|
||||||
|
`long` contexts (annotations, parameters and results) validate literals in the
|
||||||
|
Int64 range and materialize them with that carrier. Out-of-range literals MUST
|
||||||
|
be diagnosed, never replaced by zero. A typed variable does not change type
|
||||||
|
because it appears in another expected context. Mixed int/long operations
|
||||||
|
require an explicit conversion. Existing `as` syntax expresses conversion:
|
||||||
|
|
||||||
|
```pbs
|
||||||
|
let frames: long = 2147483648;
|
||||||
|
let offset: int = 10;
|
||||||
|
let wide = offset as long;
|
||||||
|
let narrow = frames as int;
|
||||||
|
```
|
||||||
|
|
||||||
|
The final conversion faults if its value is outside Int32 range. Numeric
|
||||||
|
conversions use published math/mathf conversion intrinsics, without adding
|
||||||
|
math service facades. Int32/Int64 arithmetic preserves runtime wrapping;
|
||||||
|
Float overflow and range-invalid conversions preserve runtime faults.
|
||||||
|
Defaults are owned by the runtime storage contract: numeric zero, Float +0,
|
||||||
|
Bool false, nullable String null, transparent color, zero vec2 and zero pixel.
|
||||||
|
This does not introduce implicit source-variable initialization: VM locals
|
||||||
|
start null and PBS definite-assignment rules still apply. NaN/infinity are not
|
||||||
|
valid guest numeric defaults.
|
||||||
|
|
||||||
|
## Public input API
|
||||||
|
|
||||||
|
Import `Pad`, `Button` and `Touch` from `@sdk:input`. Button is a closed nominal
|
||||||
|
PBS enum with cases Up, Down, Left, Right, A, B, X, Y, L, R, Start and Select.
|
||||||
|
It identifies a button; it does not contain input state or perform a query.
|
||||||
|
Locals and typed function parameters may carry Button values, including values
|
||||||
|
selected during execution. Strings, integer indices and unrelated enums are
|
||||||
|
not valid Button arguments.
|
||||||
|
|
||||||
|
| Public operation | Result |
|
||||||
|
| --- | --- |
|
||||||
|
| `Pad.pressed(button: Button)` | bool |
|
||||||
|
| `Pad.released(button: Button)` | bool |
|
||||||
|
| `Pad.down(button: Button)` | bool |
|
||||||
|
| `Pad.hold(button: Button)` | long, held logical frames |
|
||||||
|
| `Touch.pressed()`, `Touch.released()`, `Touch.down()` | bool |
|
||||||
|
| `Touch.hold()` | long, held logical frames |
|
||||||
|
| `Touch.x()`, `Touch.y()` | long |
|
||||||
|
|
||||||
|
```pbs
|
||||||
|
import { Pad, Button, Touch } from @sdk:input;
|
||||||
|
|
||||||
|
fn jump(button: Button) -> bool {
|
||||||
|
return Pad.pressed(button);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn held() -> long {
|
||||||
|
let jump_button = Button.A;
|
||||||
|
return Pad.hold(jump_button);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Pad dispatches to `LowPad.<button>_<query>()`, for example
|
||||||
|
`LowPad.a_pressed()`. All 48 combinations map to the published direct endpoint.
|
||||||
|
Each call MUST evaluate its selector once and execute exactly one chosen
|
||||||
|
query. It MUST NOT read unselected buttons, speculate input faults or collect
|
||||||
|
all button states. Constant specialization is optional; dynamic dispatch must
|
||||||
|
work without optimization.
|
||||||
|
|
||||||
|
All 54 VM queries take zero arguments and no receiver. Button never crosses
|
||||||
|
the intrinsic boundary as a selector. Touch x/y use current IDs 0x2134/0x2135
|
||||||
|
and Int64 results. No new device, button-state object, snapshot or multi-pad
|
||||||
|
contract is introduced. Known input without an available platform faults with
|
||||||
|
TRAP_UNAVAILABLE; it never fabricates false or zero. Unknown and retired IDs
|
||||||
|
are invalid even in unreachable code.
|
||||||
|
|
||||||
|
## Migration and diagnostics
|
||||||
|
|
||||||
|
The old Input root and intermediate InputPad/InputTouch/InputButton objects
|
||||||
|
are removed. Replace `Input.pad().a().pressed()` with
|
||||||
|
`Pad.pressed(Button.A)` and `Input.touch().x()` with `Touch.x()`.
|
||||||
|
`let button = Input.pad().a();` is invalid; `let button = Button.A;` is valid.
|
||||||
|
Migration diagnostics must point to the replacement surface. Hover, completion,
|
||||||
|
exports and examples must advertise the same API and exact return types.
|
||||||
|
When a consumer requires int coordinates, explicitly narrow a Touch result
|
||||||
|
with `as int`; do not silently change the query's ABI.
|
||||||
|
|
||||||
|
## Lowering and observable order
|
||||||
|
|
||||||
|
PBS owns source enum dispatch and typed metadata. Common code owns catalog
|
||||||
|
resolution, PBX validation and emission. The frontend MUST NOT maintain a
|
||||||
|
second intrinsic or constant catalog. SDK executable methods admit the existing
|
||||||
|
switch expression with value arms, apply and explicit numeric conversions
|
||||||
|
needed by this facade; other unsupported SDK constructs remain diagnosed.
|
||||||
|
|
||||||
|
For named application such as `f apply (y: effect_y(), x: effect_x())`, evaluate
|
||||||
|
Y then X exactly once, store complete groups in temporary locals, and reload
|
||||||
|
in x,y parameter order. Reordering expressions instead of values is invalid.
|
||||||
|
|
||||||
|
Builtin constants are groups resolved by the shared constant catalog.
|
||||||
|
`vec2.zero` materializes two Float slots; no intrinsic endpoint is invented.
|
||||||
|
Colors may use a published constant or an independently published intrinsic.
|
||||||
|
Function metadata must cover SDK wrappers such as Gfx.clear. Validation must
|
||||||
|
not infer missing identities from widths or omit the full installed example.
|
||||||
|
Preserve the existing lifecycle assembly and physical boot FunctionId zero.
|
||||||
|
|
||||||
|
## Conformance
|
||||||
|
|
||||||
|
The PBS source-to-production-PBX corpus and production runtime harness must
|
||||||
|
cover all 54 input queries with controlled input and exactly-one-query checks,
|
||||||
|
known-unavailable behavior, typed selectors, int/long boundaries and explicit
|
||||||
|
conversions, Float/String/Bool, color/vec2/pixel groups, multiple returns and
|
||||||
|
named-argument effects. Keep common registry wrong-carrier, retired-ID and stale
|
||||||
|
signature tests active. Record runtime hash, Studio revision, platform and
|
||||||
|
configuration. A catalog-only pass does not replace successful PBS execution
|
||||||
|
or `:prometeu-app:installedKnowledgeTest`.
|
||||||
@@ -296,3 +296,7 @@ This document is ready to move beyond temporary status only when:
|
|||||||
2. diagnostic identity, metadata, and attribution rules are explicit enough for conformance, including locale-agnostic token/template identity,
|
2. diagnostic identity, metadata, and attribution rules are explicit enough for conformance, including locale-agnostic token/template identity,
|
||||||
3. the backend-originated failure boundary is explicit enough that PBS-facing diagnostics can be distinguished from internal tool failures,
|
3. the backend-originated failure boundary is explicit enough that PBS-facing diagnostics can be distinguished from internal tool failures,
|
||||||
4. and cost/warning expectations are explicit where they are intended to be normative for v1.
|
4. and cost/warning expectations are explicit where they are intended to be normative for v1.
|
||||||
|
|
||||||
|
## Existing values and input runtime alignment
|
||||||
|
|
||||||
|
The [PBS input and value alignment contract](../../../compiler/pbs/specs/input-and-existing-type-runtime-alignment.md) governs int/Int32, long/Int64, exact builtin carriers, the Pad/Button/LowPad and Touch API, named-argument evaluation order, migration diagnostics and executable conformance. It supersedes older input-object and untyped executable-lowering descriptions.
|
||||||
|
|||||||
@@ -238,3 +238,7 @@ At frontend `IRBackend` emission time:
|
|||||||
4. module order in the declaration MUST propagate the explicit dependency order already derived from resolved project/module data, without sorting by `FileId`, textual module name, or synthetic callable name,
|
4. module order in the declaration MUST propagate the explicit dependency order already derived from resolved project/module data, without sorting by `FileId`, textual module name, or synthetic callable name,
|
||||||
5. PBS MUST NOT emit module init, project-init wrapper, published frame wrapper, physical entrypoint, or boot guard,
|
5. PBS MUST NOT emit module init, project-init wrapper, published frame wrapper, physical entrypoint, or boot guard,
|
||||||
6. and common lifecycle assembly remains the owner of derived artifacts, including the published wrapper that becomes the physical entrypoint and owns the final frame return.
|
6. and common lifecycle assembly remains the owner of derived artifacts, including the published wrapper that becomes the physical entrypoint and owns the final frame return.
|
||||||
|
|
||||||
|
## Existing values and input runtime alignment
|
||||||
|
|
||||||
|
The [PBS input and value alignment contract](../../../compiler/pbs/specs/input-and-existing-type-runtime-alignment.md) governs int/Int32, long/Int64, exact builtin carriers, the Pad/Button/LowPad and Touch API, named-argument evaluation order, migration diagnostics and executable conformance. It supersedes older input-object and untyped executable-lowering descriptions.
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ Rules:
|
|||||||
- `declare host` declarations are reserved to SDK/toolchain-controlled modules and are not formable in ordinary user-authored PBS source.
|
- `declare host` declarations are reserved to SDK/toolchain-controlled modules and are not formable in ordinary user-authored PBS source.
|
||||||
- `declare builtin type` declarations are reserved to SDK/toolchain-controlled modules and are not formable in ordinary user-authored PBS source.
|
- `declare builtin type` declarations are reserved to SDK/toolchain-controlled modules and are not formable in ordinary user-authored PBS source.
|
||||||
- A host owner name is not an ordinary value expression in v1 core; it is used only as a qualified host-call owner.
|
- A host owner name is not an ordinary value expression in v1 core; it is used only as a qualified host-call owner.
|
||||||
- The builtin simple types `int`, `float`, `bool`, and `str` are always present in the type namespace.
|
- The builtin simple types `int`, `long`, `float`, `bool`, and `str` are always present in the type namespace.
|
||||||
- Builtin simple types are resolved without import or declaration.
|
- Builtin simple types are resolved without import or declaration.
|
||||||
- User-authored type declarations must not reuse builtin simple type names.
|
- User-authored type declarations must not reuse builtin simple type names.
|
||||||
|
|
||||||
@@ -874,3 +874,7 @@ At minimum, deterministic static diagnostics are required for:
|
|||||||
- invalid optional intrinsic member call,
|
- invalid optional intrinsic member call,
|
||||||
- invalid builtin intrinsic member call,
|
- invalid builtin intrinsic member call,
|
||||||
- member projection on a missing named output label.
|
- member projection on a missing named output label.
|
||||||
|
|
||||||
|
## Existing values and input runtime alignment
|
||||||
|
|
||||||
|
The [PBS input and value alignment contract](../../../compiler/pbs/specs/input-and-existing-type-runtime-alignment.md) governs int/Int32, long/Int64, exact builtin carriers, the Pad/Button/LowPad and Touch API, named-argument evaluation order, migration diagnostics and executable conformance. It supersedes older input-object and untyped executable-lowering descriptions.
|
||||||
|
|||||||
+19
@@ -537,3 +537,22 @@ The current PBS design direction is:
|
|||||||
10. `declare host` remains reserved to stdlib/toolchain interface modules.
|
10. `declare host` remains reserved to stdlib/toolchain interface modules.
|
||||||
11. Reserved attributes such as `[Host(...)]` are compile-time metadata, not runtime objects.
|
11. Reserved attributes such as `[Host(...)]` are compile-time metadata, not runtime objects.
|
||||||
12. The compiler consumes `Host` metadata to produce runtime-facing host-binding artifacts defined elsewhere.
|
12. The compiler consumes `Host` metadata to produce runtime-facing host-binding artifacts defined elsewhere.
|
||||||
|
|
||||||
|
## Editorial exposure of external sources
|
||||||
|
|
||||||
|
SDK/core remain reserved bundled sources. Editorial navigation MUST NOT extract
|
||||||
|
or copy them into a project or disk cache. Compiler-known dependency sources,
|
||||||
|
including those under `.workspace`, and SDK/core are exposed as read-only external
|
||||||
|
documents with revision-consistent text, ranges and frontend semantic context.
|
||||||
|
Hover and continued definition use that retained context. Compilation, module
|
||||||
|
admission, ABI and linking rules are unchanged. See Compiler Spec 23 §8.3 and
|
||||||
|
Studio Spec 11 for the consumer protocol and atomic write restrictions (DEC-0062).
|
||||||
|
|
||||||
|
PBS project hover, definition, completion and signature help MUST share receiver
|
||||||
|
type resolution using PBS expression parsing and semantic overload rules. Coverage
|
||||||
|
includes function/method chains with known return types, nested call arguments,
|
||||||
|
explicitly typed and inferred variables, parentheses, completion after a trailing
|
||||||
|
dot and signature help during incomplete arguments. An unrelated parse error MUST
|
||||||
|
NOT invalidate a recoverable receiver. Unknown or ambiguous receivers MUST NOT
|
||||||
|
invent a type or overload. Indexing/operator-produced receivers are outside the
|
||||||
|
new coverage; existing behavior MUST NOT regress.
|
||||||
|
|||||||
+9
-5
@@ -263,13 +263,13 @@ Example:
|
|||||||
```pbs
|
```pbs
|
||||||
[BuiltinType(name="color", version=1)]
|
[BuiltinType(name="color", version=1)]
|
||||||
declare builtin type Color(
|
declare builtin type Color(
|
||||||
pub raw: int,
|
pub raw: long,
|
||||||
);
|
);
|
||||||
|
|
||||||
[BuiltinType(name="pixel", version=1)]
|
[BuiltinType(name="pixel", version=1)]
|
||||||
declare builtin type Pixel(
|
declare builtin type Pixel(
|
||||||
pub x: int,
|
pub x: long,
|
||||||
pub y: int,
|
pub y: long,
|
||||||
pub color: Color,
|
pub color: Color,
|
||||||
);
|
);
|
||||||
```
|
```
|
||||||
@@ -277,13 +277,13 @@ declare builtin type Pixel(
|
|||||||
Canonical semantic layout:
|
Canonical semantic layout:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
Pixel -> [int, int, Color]
|
Pixel -> [long, long, Color]
|
||||||
```
|
```
|
||||||
|
|
||||||
Canonical flattened slot layout:
|
Canonical flattened slot layout:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
Pixel -> [int, int, int]
|
Pixel -> [long, long, long]
|
||||||
```
|
```
|
||||||
|
|
||||||
## 13. Member Categories
|
## 13. Member Categories
|
||||||
@@ -560,3 +560,7 @@ The current temporary contract is:
|
|||||||
7. `BuiltinConst(target, name, version)` exposes VM-owned builtin constants through reserved top-level `declare const` shells.
|
7. `BuiltinConst(target, name, version)` exposes VM-owned builtin constants through reserved top-level `declare const` shells.
|
||||||
8. Builtin projections, constants, and intrinsic calls must not lower through `SYSC`, `HOSTCALL`, or `SYSCALL`.
|
8. Builtin projections, constants, and intrinsic calls must not lower through `SYSC`, `HOSTCALL`, or `SYSCALL`.
|
||||||
9. Runtime-facing intrinsic artifacts are distinct from host-binding artifacts.
|
9. Runtime-facing intrinsic artifacts are distinct from host-binding artifacts.
|
||||||
|
|
||||||
|
## Existing values and input runtime alignment
|
||||||
|
|
||||||
|
The [PBS input and value alignment contract](../../../compiler/pbs/specs/input-and-existing-type-runtime-alignment.md) governs int/Int32, long/Int64, exact builtin carriers, the Pad/Button/LowPad and Touch API, named-argument evaluation order, migration diagnostics and executable conformance. It supersedes older input-object and untyped executable-lowering descriptions.
|
||||||
|
|||||||
+10
@@ -356,3 +356,13 @@ Content hashes identify the packaged texts, not a semantic language release.
|
|||||||
Conformance MUST include reading all indexed references from installed JARs outside
|
Conformance MUST include reading all indexed references from installed JARs outside
|
||||||
the repository and compiling the shipped example against the installed SDK. No
|
the repository and compiling the shipped example against the installed SDK. No
|
||||||
network access or source checkout may be required by that reference-read path.
|
network access or source checkout may be required by that reference-read path.
|
||||||
|
|
||||||
|
## Editorial exposure of external sources
|
||||||
|
|
||||||
|
SDK/core remain reserved bundled sources. Editorial navigation MUST NOT extract
|
||||||
|
or copy them into a project or disk cache. Compiler-known dependency sources,
|
||||||
|
including those under `.workspace`, and SDK/core are exposed as read-only external
|
||||||
|
documents with revision-consistent text, ranges and frontend semantic context.
|
||||||
|
Hover and continued definition use that retained context. Compilation, module
|
||||||
|
admission, ABI and linking rules are unchanged. See Compiler Spec 23 §8.3 and
|
||||||
|
Studio Spec 11 for the consumer protocol and atomic write restrictions (DEC-0062).
|
||||||
|
|||||||
@@ -387,3 +387,7 @@ This document is ready to move beyond temporary draft status only when:
|
|||||||
3. host-call interaction rules are stated without relying on informal prose elsewhere,
|
3. host-call interaction rules are stated without relying on informal prose elsewhere,
|
||||||
4. the document can drive runtime conformance tests without decision backfill,
|
4. the document can drive runtime conformance tests without decision backfill,
|
||||||
5. the remaining TODO items are reduced to editorial integration rather than semantic uncertainty.
|
5. the remaining TODO items are reduced to editorial integration rather than semantic uncertainty.
|
||||||
|
|
||||||
|
## Existing values and input runtime alignment
|
||||||
|
|
||||||
|
The [PBS input and value alignment contract](../../../compiler/pbs/specs/input-and-existing-type-runtime-alignment.md) governs int/Int32, long/Int64, exact builtin carriers, the Pad/Button/LowPad and Touch API, named-argument evaluation order, migration diagnostics and executable conformance. It supersedes older input-object and untyped executable-lowering descriptions.
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
# Bytecode and PBX Mapping Specification
|
# Bytecode and PBX Mapping Specification
|
||||||
|
|
||||||
|
The current typed Registry/PBX v0 contract is normative in
|
||||||
|
[Typed common Registry and PBX v0](../../compiler/general/specs/typed-registry-and-pbx-v0.md).
|
||||||
|
Its complete typed function records, mandatory sections and verification rules
|
||||||
|
replace the earlier slot-only artifact baseline.
|
||||||
|
|
||||||
Status: Draft v1 (Backend Baseline)
|
Status: Draft v1 (Backend Baseline)
|
||||||
Applies to: mapping from lowered/optimized backend programs into PBX sections, bytecode-facing artifacts, and source-to-artifact invariants required by loader/verifier/runtime
|
Applies to: mapping from lowered/optimized backend programs into PBX sections, bytecode-facing artifacts, and source-to-artifact invariants required by loader/verifier/runtime
|
||||||
|
|
||||||
@@ -74,7 +79,8 @@ Emitter output must map to a `BytecodeModule` shape containing:
|
|||||||
3. `code`,
|
3. `code`,
|
||||||
4. `exports`,
|
4. `exports`,
|
||||||
5. `syscalls`,
|
5. `syscalls`,
|
||||||
6. optional `debug_info` that still satisfies v1 minimum debug obligations.
|
6. typed Registry declarations, implementations and per-function capture lists,
|
||||||
|
7. optional `debug_info` that still satisfies v1 minimum debug obligations.
|
||||||
|
|
||||||
### 6.2 Function ordering and IDs
|
### 6.2 Function ordering and IDs
|
||||||
|
|
||||||
@@ -168,7 +174,6 @@ At minimum, artifact conformance checks should assert:
|
|||||||
The following remain deferred:
|
The following remain deferred:
|
||||||
|
|
||||||
- richer optional debug/source-map formats,
|
- richer optional debug/source-map formats,
|
||||||
- additional PBX section-level contracts beyond current baseline,
|
|
||||||
- and profile-specific binary compatibility policy details beyond current v1 baseline.
|
- and profile-specific binary compatibility policy details beyond current v1 baseline.
|
||||||
|
|
||||||
## 11. Non-Goals
|
## 11. Non-Goals
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
# Compiler Verification and Safety Checks Specification
|
# Compiler Verification and Safety Checks Specification
|
||||||
|
|
||||||
|
The current typed Registry/PBX v0 contract is normative in
|
||||||
|
[Typed common Registry and PBX v0](../../compiler/general/specs/typed-registry-and-pbx-v0.md).
|
||||||
|
Its complete typed function records, mandatory sections and verification rules
|
||||||
|
replace the earlier slot-only artifact baseline.
|
||||||
|
|
||||||
Status: Draft v1 (Quality-Gate Baseline)
|
Status: Draft v1 (Quality-Gate Baseline)
|
||||||
Applies to: test-backed safety gates for common compiler stages, validation ownership across executable frontends, and integration regression safety checks against runtime
|
Applies to: test-backed safety gates for common compiler stages, validation ownership across executable frontends, and integration regression safety checks against runtime
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
# IRBackend to IRVM Lowering Specification
|
# IRBackend to IRVM Lowering Specification
|
||||||
|
|
||||||
|
The current typed Registry/PBX v0 contract is normative in
|
||||||
|
[Typed common Registry and PBX v0](../../compiler/general/specs/typed-registry-and-pbx-v0.md).
|
||||||
|
Its complete typed function records, mandatory sections and verification rules
|
||||||
|
replace the earlier slot-only artifact baseline.
|
||||||
|
|
||||||
Status: Draft v1 (Backend Baseline)
|
Status: Draft v1 (Backend Baseline)
|
||||||
Applies to: executable-backend lowering from the common `IRBackend` handoff into `IRVM`
|
Applies to: executable-backend lowering from the common `IRBackend` handoff into `IRVM`
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
# Backend Spec-to-Test Conformance Matrix
|
# Backend Spec-to-Test Conformance Matrix
|
||||||
|
|
||||||
|
The current typed Registry/PBX v0 contract is normative in
|
||||||
|
[Typed common Registry and PBX v0](../../compiler/general/specs/typed-registry-and-pbx-v0.md).
|
||||||
|
Its complete typed function records, mandatory sections and verification rules
|
||||||
|
replace the earlier slot-only artifact baseline.
|
||||||
|
|
||||||
Status: Draft v1 (Traceability Baseline)
|
Status: Draft v1 (Traceability Baseline)
|
||||||
Applies to: compiler/backend conformance traceability for canonical stage order and entrypoint-specific contracts
|
Applies to: compiler/backend conformance traceability for canonical stage order and entrypoint-specific contracts
|
||||||
|
|
||||||
@@ -140,3 +145,19 @@ Matrix integrity is enforced by automated document lint:
|
|||||||
- if `PROMETEU_MATRIX_HARD_GATE=true` and `PROMETEU_CHANGED_FILES` contains a path under conformance-relevant FE/BE prefixes,
|
- if `PROMETEU_MATRIX_HARD_GATE=true` and `PROMETEU_CHANGED_FILES` contains a path under conformance-relevant FE/BE prefixes,
|
||||||
- then this matrix file MUST be present in `PROMETEU_CHANGED_FILES`, otherwise the gate fails.
|
- then this matrix file MUST be present in `PROMETEU_CHANGED_FILES`, otherwise the gate fails.
|
||||||
- CI policy uses strict Gate I mode via `PROMETEU_GATE_I_STRICT=true` (or `CI=true`) and requires `PROMETEU_RUNTIME_CHECK_CMD` for runtime-backed evidence.
|
- CI policy uses strict Gate I mode via `PROMETEU_GATE_I_STRICT=true` (or `CI=true`) and requires `PROMETEU_RUNTIME_CHECK_CMD` for runtime-backed evidence.
|
||||||
|
|
||||||
|
## 7. Typed Registry/PBX v0 qualification (2026-10-14)
|
||||||
|
|
||||||
|
Owner: compiler/general. These rows supersede slot-only PBX coverage claims;
|
||||||
|
frontend syntax and lowering remain consumer-owned.
|
||||||
|
|
||||||
|
| Requirement | Evidence | Status | Scope |
|
||||||
|
| --- | --- | --- | --- |
|
||||||
|
| Stable declarations, nominal identity, structural deduplication and cycles | LinkedRegistryTest; IRBackendExecutableContractTest | pass | Common API and linking |
|
||||||
|
| Complete typed signatures, captures, roles and implementations | PbxRegistryConformanceTest; TypedCommonPipelineTest | pass | Common IR through emission |
|
||||||
|
| Exact PBX mandatory tables and multi-slot signatures | Independent 194-byte oracle; fixed vec2 function bytes | pass | Wire format, not a self round-trip |
|
||||||
|
| Runtime final admission and execution | tools/pbx-conformance/run.py | pass | Closure, trait, array, Dynamic, intrinsic, roles, joins, native binding; vec2 load-only |
|
||||||
|
| Invalid structures, references, code and resource refusal | tools/pbx-conformance/main.rs mutation corpus | pass | Production loader, default/lowered limits |
|
||||||
|
| Structured initialization and binding diagnostics | HeadlessProcessSessionTest; observed runtime JSON fixtures | pass | Preserves full payload through MCP, including null outer PC |
|
||||||
|
| Published schema covers current runtime reasons | Actual LifecycleRole/NonFiniteValue payloads against runtime schema | partial | Runtime enum/schema mismatch recorded in AGD75; no payload rewriting |
|
||||||
|
| PBS migration and integrated delivery | AGD75 and consumer tickets | partial | Existing PBS suite passing is not complete executable lowering evidence |
|
||||||
|
|||||||
@@ -272,7 +272,17 @@ Absent editor capabilities MUST have deterministic fallback behavior at tooling
|
|||||||
3. host protocols that can represent unsupported operations SHOULD do so explicitly;
|
3. host protocols that can represent unsupported operations SHOULD do so explicitly;
|
||||||
4. and absent editor capability MUST NOT be reported as a compiler failure.
|
4. and absent editor capability MUST NOT be reported as a compiler failure.
|
||||||
|
|
||||||
When a frontend exposes definition or navigation, each returned location MUST identify a compiler-known physical source file. A resolved symbol without a physical file MUST produce an empty definition response. Tooling MUST NOT require virtual documents, untitled buffers, or synthetic URIs for this capability.
|
When a frontend exposes definition or navigation, each returned location MUST identify a compiler-known source in the analyzed revision. Editable main-project locations use `file:`. Bundled SDK/core and ordinary dependency sources use server-issued `prometeu-source:` identities for consumers that negotiate external-source support. Ownership, not physical containment or `SourceKind.PROJECT`, determines editability. Clients without support receive only editable physical project destinations; absent frontend support retains the empty fallback. This explicitly supersedes the earlier physical-only definition policy (DEC-0062).
|
||||||
|
|
||||||
|
`FrontendLanguageService.supportsExternalSources` and `sourceDocument` are optional,
|
||||||
|
with false/empty defaults. `FrontendDefinitionLocation.source`, when present,
|
||||||
|
contains the known source's exact text, origin, name, language, read-only ownership
|
||||||
|
and opaque frontend context. Compiler contracts do not mint session URIs; that is
|
||||||
|
the project host's responsibility. The content digest is not an SDK version.
|
||||||
|
|
||||||
|
External source snapshots MUST retain the exact analyzed text, source origin and frontend semantic context together. Declaration offsets and UTF-16 protocol positions MUST be calculated from that text. The frontend owns hover and continued definition inside external documents; adapters MUST NOT resolve language semantics. SDK/core MUST remain bundled without editorial extraction. Unknown, expired, unreadable or unauthorized identities MUST report unavailable without arbitrary path fallback.
|
||||||
|
|
||||||
|
External URIs are scoped to a project-server session and a content revision, not an SDK semantic version. A project-owned registry retains snapshots per consumer, independently of transport connections. Last release or project shutdown releases text and semantic context together. Reconnection MUST revalidate before queries resume; changed revisions require fresh navigation, never old positions applied to new text. One consumer closing MUST NOT invalidate another. All edit proposals touching an external source, including physical aliases, MUST be refused atomically. References, workspace symbols, document links and hierarchies retain their existing physical scopes; external navigation does not expand them.
|
||||||
|
|
||||||
When a frontend exposes find-references, each returned usage or declaration location MUST identify a compiler-known physical source file. A cursor offset whose definition response is empty MUST produce an empty references response. Host `includeDeclaration` MAY add the canonical declaration location only when that declaration is a compiler-known physical source file; it MUST NOT invent a virtual, untitled, or synthetic location.
|
When a frontend exposes find-references, each returned usage or declaration location MUST identify a compiler-known physical source file. A cursor offset whose definition response is empty MUST produce an empty references response. Host `includeDeclaration` MAY add the canonical declaration location only when that declaration is a compiler-known physical source file; it MUST NOT invent a virtual, untitled, or synthetic location.
|
||||||
|
|
||||||
|
|||||||
@@ -142,3 +142,23 @@ This specification is complete enough when:
|
|||||||
- workspace and shell responsibilities are clearly separated;
|
- workspace and shell responsibilities are clearly separated;
|
||||||
- the shell-level expectations for workspace architecture are explicit;
|
- the shell-level expectations for workspace architecture are explicit;
|
||||||
- the baseline Studio frame is stable enough for implementation planning.
|
- the baseline Studio frame is stable enough for implementation planning.
|
||||||
|
|
||||||
|
## Project Assistant Preparation (DEC-0061)
|
||||||
|
|
||||||
|
Project creation MUST scaffold neutral agent-integration intent in
|
||||||
|
`.studio/setup.json` and invoke the same preparation port used by existing
|
||||||
|
projects in DEV. Application infrastructure resolves installed Studio and client
|
||||||
|
configuration; the wizard/Core MUST NOT serialize provider TOML or launch an
|
||||||
|
agent. Failed preparation leaves a usable project with actionable incomplete
|
||||||
|
readiness in DEV, never a false ready claim. Runtime/editor settings and unrelated
|
||||||
|
client configuration MUST survive. Preparation grants no project control.
|
||||||
|
|
||||||
|
### Automatic preparation when opening a project
|
||||||
|
|
||||||
|
Opening a project MUST prepare its enabled MCP integration using the same neutral
|
||||||
|
port as scaffold and DEV retry. Desktop composition MUST start the shared loopback
|
||||||
|
server before project sessions become available; no external command or separate
|
||||||
|
per-project desktop Run is required. Explicitly disabled integration MUST remain
|
||||||
|
disabled. Preparation failure MUST remain visible in DEV readiness without blocking
|
||||||
|
project use. Opening MUST NOT publish credentials or grant/acquire agent control.
|
||||||
|
The coding client continues to own its configured stdio process and initial trust.
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ DEV MUST expose:
|
|||||||
- the four control states, project identity, current managed operation and diagnostics;
|
- the four control states, project identity, current managed operation and diagnostics;
|
||||||
- a canonical-image canvas with session/build/logical-frame/render-frame identity and stale status;
|
- a canonical-image canvas with session/build/logical-frame/render-frame identity and stale status;
|
||||||
- a short history of Studio calls, not an independent code history;
|
- a short history of Studio calls, not an independent code history;
|
||||||
- **Copy MCP configuration**, plus short connection/use instructions when the real MCP composition is available.
|
- **Prepare assistant**, plus short connection/use instructions when the real MCP composition is available.
|
||||||
|
|
||||||
Actions MUST reflect shared service authority. DEV MUST NOT own a duplicate
|
Actions MUST reflect shared service authority. DEV MUST NOT own a duplicate
|
||||||
lock or release authority when disposing visual subscriptions. Presentation
|
lock or release authority when disposing visual subscriptions. Presentation
|
||||||
@@ -177,8 +177,7 @@ in Debug with its existing host/protocol/lifecycle, subject to symmetric guards.
|
|||||||
“Agent working” means the task has been acquired; it is not a claim to observe
|
“Agent working” means the task has been acquired; it is not a claim to observe
|
||||||
all external edits, reasoning or conversation.
|
all external edits, reasoning or conversation.
|
||||||
|
|
||||||
Without a real composed MCP endpoint, configuration copy MUST be unavailable
|
Preparation MUST report missing installation or configuration conflicts explicitly; it does not depend on a live grant or fabricate endpoint credentials. Test doubles MAY supply
|
||||||
rather than produce a fabricated endpoint or token. Test doubles MAY supply
|
|
||||||
operations/captures to isolated tests, never masquerade as product execution.
|
operations/captures to isolated tests, never masquerade as product execution.
|
||||||
|
|
||||||
## 6. Operations and Lost Responses
|
## 6. Operations and Lost Responses
|
||||||
@@ -274,19 +273,18 @@ that it uses. Capture/build correlation MUST NOT introduce code snapshots.
|
|||||||
Concrete tool names, input schemas, response envelopes and HTTP lifecycle are
|
Concrete tool names, input schemas, response envelopes and HTTP lifecycle are
|
||||||
specified in [MCP Tools and Project Knowledge Contract](11.%20MCP%20Tools%20and%20Project%20Knowledge%20Contract.md).
|
specified in [MCP Tools and Project Knowledge Contract](11.%20MCP%20Tools%20and%20Project%20Knowledge%20Contract.md).
|
||||||
|
|
||||||
The app MUST host Streamable HTTP at `127.0.0.1:<OS-assigned-port>/mcp` while
|
The desktop MUST host Streamable HTTP at `127.0.0.1:<OS-assigned-port>/mcp`.
|
||||||
Studio is open. It MUST generate a random token per Studio start, require it
|
DEC-0061 adds Studio-owned stdio discovery and one-time preparation as specified
|
||||||
on connections, validate Origin and reject unexpected origins. No remote
|
in spec 11. Each human grant publishes a fresh project-scoped credential through
|
||||||
binding, accounts, OAuth or stdio MCP bridge is part of this baseline.
|
the required lifecycle participant in spec 8. Authentication, project scope and
|
||||||
|
task identity remain separate checks. There is no global credential bypass.
|
||||||
Copied configuration MUST contain the actual endpoint/token and MUST NOT be
|
Restart invalidates old access and requires a fresh human grant, while the native
|
||||||
written to versioned files. Instructions MUST explain that restart requires
|
client's command/configuration remains unchanged. No remote binding, accounts or
|
||||||
refreshing client configuration. Copying configuration and authenticating
|
OAuth are introduced. Preparation never grants editing authority.
|
||||||
MUST NOT grant control.
|
|
||||||
|
|
||||||
| Tool group | Required capabilities | Required authority |
|
| Tool group | Required capabilities | Required authority |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- |
|
||||||
| Context/references | Project identity, languages, versions, capabilities and paginated references | Authenticated connection; no grant required |
|
| Context/references | Project identity, languages, versions, capabilities and paginated references | Project credential; no acquired task required |
|
||||||
| Control | Acquire task and release control | Prior human grant for acquisition; valid task identity for release |
|
| Control | Acquire task and release control | Prior human grant for acquisition; valid task identity for release |
|
||||||
| Language | Existing LSP diagnostics/navigation and supported capabilities | Valid project/task identity |
|
| Language | Existing LSP diagnostics/navigation and supported capabilities | Valid project/task identity |
|
||||||
| Build | Compile and pack | Valid project/task identity |
|
| Build | Compile and pack | Valid project/task identity |
|
||||||
@@ -373,7 +371,7 @@ mature gameplay library is not a prerequisite.
|
|||||||
- Pixel-art generation, full-game libraries, audio capture or deep guest introspection.
|
- Pixel-art generation, full-game libraries, audio capture or deep guest introspection.
|
||||||
- Shared editing, isolated worktrees, code snapshots/journals/checkpoints, merge/apply, divergence recovery, undo/rollback or automatic commits/clean-tree gates.
|
- Shared editing, isolated worktrees, code snapshots/journals/checkpoints, merge/apply, divergence recovery, undo/rollback or automatic commits/clean-tree gates.
|
||||||
- Replacing compiler, Packer, LSP, VM or human Debug semantics; a new general-purpose Studio source editor.
|
- Replacing compiler, Packer, LSP, VM or human Debug semantics; a new general-purpose Studio source editor.
|
||||||
- Remote MCP, accounts/OAuth, stdio MCP bridge, network runtime discovery or provider-specific connection wizard.
|
- Remote MCP, accounts/OAuth and network runtime discovery. Studio-owned stdio and local Codex preparation are the explicit DEC-0061 additions.
|
||||||
- Additional language implementation, persistent operation recovery or automatic task resumption.
|
- Additional language implementation, persistent operation recovery or automatic task resumption.
|
||||||
- Integrated discussion-framework agendas/decisions/plans in the product; those are future work, not this runtime/DEV/MCP contract.
|
- Integrated discussion-framework agendas/decisions/plans in the product; those are future work, not this runtime/DEV/MCP contract.
|
||||||
|
|
||||||
@@ -390,3 +388,14 @@ Implementation is conformant only when all phase gates hold and:
|
|||||||
7. Lost operation responses cannot duplicate execution; runtime crash cannot trigger replay or implicit authority release.
|
7. Lost operation responses cannot duplicate execution; runtime crash cannot trigger replay or implicit authority release.
|
||||||
8. Language context and indexed local references reflect real installed support and work without source checkouts.
|
8. Language context and indexed local references reflect real installed support and work without source checkouts.
|
||||||
9. Manual Debug, architecture boundaries, packaging and real-client integration pass their regression gates.
|
9. Manual Debug, architecture boundaries, packaging and real-client integration pass their regression gates.
|
||||||
|
|
||||||
|
## Integrated Connection Revision (DEC-0061)
|
||||||
|
|
||||||
|
Connection and authority MUST be displayed separately. Initialization/ping
|
||||||
|
liveness determines connection, while Core determines waiting/working/manual
|
||||||
|
control. A missing descriptor means waiting for access, not proof that Studio is
|
||||||
|
closed. Preparation reports initial client trust/reload requirements without
|
||||||
|
modifying approval policy. Revocation removes published access even before
|
||||||
|
asynchronous worker/runtime cleanup finishes. New grants never restore old task
|
||||||
|
IDs or receipts. Full integrated native-client acceptance belongs to PLN-0140;
|
||||||
|
the prior HTTP acceptance alone is insufficient.
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
## Status, Scope and Authority
|
## Status, Scope and Authority
|
||||||
|
|
||||||
Owner: **studio**, application adapter and neutral automation API. This document
|
Owner: **studio**, application adapter and neutral automation API. This document
|
||||||
formalizes DEC-0060 B5–B9 and PLN-0139 steps 15–16. It complements
|
formalizes DEC-0060 B5–B9 and the integrated connection revision in DEC-0061 (PLN-0140). It complements
|
||||||
[DEV and Automation](10.%20DEV%20and%20Automation%20Specification.md), which owns
|
[DEV and Automation](10.%20DEV%20and%20Automation%20Specification.md), which owns
|
||||||
project authority, lifecycle, captures and phase gates. It does not change those
|
project authority, lifecycle, captures and phase gates. It does not change those
|
||||||
rules or the runtime-owned headless protocol.
|
rules or the runtime-owned headless protocol.
|
||||||
@@ -11,7 +11,7 @@ rules or the runtime-owned headless protocol.
|
|||||||
The packaged machine-readable input schemas, authority classification and
|
The packaged machine-readable input schemas, authority classification and
|
||||||
examples are in `prometeu-app/src/main/resources/mcp/studio-tools-v1.json`.
|
examples are in `prometeu-app/src/main/resources/mcp/studio-tools-v1.json`.
|
||||||
Contract version is `1.0`. Catalog membership is not runtime availability:
|
Contract version is `1.0`. Catalog membership is not runtime availability:
|
||||||
`tools/list` MUST expose only composed handlers, never placeholder implementations.
|
HTTP `tools/list` MUST expose only composed handlers, never placeholder implementations. The offline Studio stdio entry MUST advertise the packaged catalog and report unavailable live capabilities explicitly.
|
||||||
Steps 17–21 connect the functional providers and DEV configuration assistance;
|
Steps 17–21 connect the functional providers and DEV configuration assistance;
|
||||||
steps 22–28 provide the real runtime gateway and integrated acceptance.
|
steps 22–28 provide the real runtime gateway and integrated acceptance.
|
||||||
|
|
||||||
@@ -23,18 +23,24 @@ initialization exchange negotiates that supported revision; no compatibility
|
|||||||
with other revisions or deprecated HTTP+SSE transport is claimed. An offered
|
with other revisions or deprecated HTTP+SSE transport is claimed. An offered
|
||||||
unsupported revision receives the supported revision in `InitializeResult`.
|
unsupported revision receives the supported revision in `InitializeResult`.
|
||||||
|
|
||||||
Each start generates a fresh 256-bit random bearer token. Every request MUST
|
Each desktop start generates a new instance identity. Each human project grant
|
||||||
include `Authorization: Bearer <token>`. Missing/wrong credentials return 401.
|
publishes a fresh 256-bit bearer credential scoped to that canonical project root.
|
||||||
There is no query-string token, OAuth, cookie authentication, remote bind option,
|
Every HTTP request MUST include `Authorization: Bearer <credential>`; missing,
|
||||||
stdio bridge or wildcard listener. The endpoint has no query parameters.
|
wrong or revoked credentials return 401. Initialized HTTP sessions MUST be bound
|
||||||
|
to that credential/root; mixing another credential with an existing session returns
|
||||||
|
403. All tools, including knowledge reads, MUST enforce the authenticated root
|
||||||
|
before dispatch. No instance-wide credential bypass is permitted.
|
||||||
|
|
||||||
|
There is no query-string token, OAuth, cookie authentication, remote bind option
|
||||||
|
or wildcard listener. The endpoint has no query parameters. Studio also provides
|
||||||
|
its own stdio mode, described below; it is part of the same artifact.
|
||||||
|
|
||||||
Native clients may omit `Origin`. If present, it MUST exactly equal the live
|
Native clients may omit `Origin`. If present, it MUST exactly equal the live
|
||||||
endpoint's origin (`http://127.0.0.1:<port>`); `null`, other ports/hosts/schemes
|
endpoint's origin (`http://127.0.0.1:<port>`); `null`, other ports/hosts/schemes
|
||||||
and multiple Origin headers fail. Host MUST match the live loopback authority.
|
and multiple Origin headers fail. Host MUST match the live loopback authority.
|
||||||
Unexpected origins/hosts return 403. No permissive browser CORS policy is emitted.
|
Unexpected origins/hosts return 403. No permissive browser CORS policy is emitted.
|
||||||
Credentials MUST NOT appear in diagnostics, exception messages, object string
|
Credentials MUST NOT appear in diagnostics, exception messages, object string
|
||||||
representations, generated reports or versioned configuration. Explicit copying
|
representations, generated reports or versioned configuration. The project discovery file is the only secret-bearing setup output; persistent client configuration and clipboard assistance MUST NOT export secrets.
|
||||||
for the external client is provided in step 21, not by logging startup secrets.
|
|
||||||
|
|
||||||
Initialization assigns a separate random `Mcp-Session-Id`. Subsequent requests
|
Initialization assigns a separate random `Mcp-Session-Id`. Subsequent requests
|
||||||
include this header and the negotiated `MCP-Protocol-Version`. The server can
|
include this header and the negotiated `MCP-Protocol-Version`. The server can
|
||||||
@@ -62,34 +68,87 @@ and [tools](https://modelcontextprotocol.io/specification/2025-06-18/server/tool
|
|||||||
contracts. Optional SSE, server-initiated requests, sampling, prompts, resource
|
contracts. Optional SSE, server-initiated requests, sampling, prompts, resource
|
||||||
subscriptions and list-change notifications are not advertised.
|
subscriptions and list-change notifications are not advertised.
|
||||||
|
|
||||||
### 1.1 DEV Connection Assistance
|
### 1.1 Integrated Studio Entry and Offline Catalog
|
||||||
|
|
||||||
DEV displays the current endpoint without credentials and provides **Copy MCP
|
`StudioLauncher mcp --project <absolute-root>` MUST dispatch before JavaFX or
|
||||||
configuration** for an open project. The neutral `AgentConnectionGuide` supplies
|
Spring desktop startup. The root MUST be canonicalized once, contain the project
|
||||||
availability and a deliberate clipboard export; JavaFX MUST NOT depend on the
|
manifest and remain bound for the process lifetime, independently of client cwd.
|
||||||
HTTP server or keep credentials in labels, diagnostics, project state or history.
|
The mode MUST NOT open a desktop, LSP, runtime or another HTTP listener. It uses
|
||||||
Connection lifecycle changes refresh availability. A closed project or stopped
|
newline-framed UTF-8 JSON-RPC on stdin/stdout; stdout is protocol-only. Requests
|
||||||
server cannot export a descriptor. Unloading DEV only unsubscribes presentation
|
are bounded to 1 MiB. EOF closes transport resources without releasing task control.
|
||||||
listeners; it does not stop the endpoint or revoke project authority.
|
|
||||||
|
|
||||||
The copied text is a provider-neutral JSON descriptor with `transport` set to
|
Initialize, initialized notification, ping and tools/list MUST work before the
|
||||||
`streamable-http`, the live `url`, `headers.Authorization`, canonical `projectRoot`
|
desktop, descriptor or grant exists. Offline descriptors come from the same
|
||||||
and `instructions`. It is not a promise of a drop-in configuration format for
|
packaged catalog as HTTP. A deterministic fingerprint covers protocol and tool
|
||||||
every external client. The developer maps URL/header fields to that client's MCP
|
schemas. Before forwarding, the connector MUST validate the descriptor, initialize
|
||||||
configuration; a provider-specific wizard remains out of scope. The secret is
|
HTTP, check instance/root/fingerprint metadata, and compare live descriptors with
|
||||||
materialized only for explicit copying and MUST NOT be written to versioned files
|
the packaged catalog. Missing handlers return unsupported capability; incompatible
|
||||||
or logs. Clipboard success/failure feedback MUST NOT repeat credential-bearing
|
protocol/schema fails explicitly rather than silently changing the client's tools.
|
||||||
content or raw exceptions. The clipboard itself is a deliberate secret export.
|
|
||||||
|
|
||||||
Copied instructions and MCP initialization guidance direct the client to discover
|
Tool calls MUST preserve structuredContent, text/error blocks and native image
|
||||||
actual tools, read project context and applicable language/SDK/library references,
|
blocks. Response bounds MUST support images above the 1 MiB request limit; the
|
||||||
wait for human grant before acquisition, edit saved files within project scope,
|
current response cap is 32 MiB, including a bounded body-read deadline. Network
|
||||||
validate with LSP/build, recover operation receipts by clientRequestId and release
|
redirects MUST NOT be followed. The connector MUST reject another project root.
|
||||||
explicitly. Missing language support is a reported limitation, not a PBS fallback.
|
|
||||||
They also explain that SDK/external libraries are read-only, revocation cannot
|
Discovery runs on calls and bounded background checks. Missing publication means
|
||||||
stop external file writes, copying grants no authority, and a Studio restart
|
waiting for access, not proof that the desktop is closed. Distinguish invalid
|
||||||
requires fresh endpoint/token configuration. No provider or model is required
|
file/permissions, stale credentials/instance, catalog incompatibility and transport
|
||||||
to test this guidance and the MCP service contract.
|
reconnection. Calls cannot wait indefinitely for a grant. No reconnect path may
|
||||||
|
resubmit a tool call. An uncertain response MUST retain available clientRequestId
|
||||||
|
correlation and instruct receipt lookup within the same authorized task. A new
|
||||||
|
desktop/task has no old receipt registry and requires a fresh human grant.
|
||||||
|
|
||||||
|
### 1.2 Stable Installation and Project Preparation
|
||||||
|
|
||||||
|
The initial delivery targets Codex on macOS. Studio owns a versioned installation
|
||||||
|
under `~/Library/Application Support/Prometeu/Studio`, with an atomic `current`
|
||||||
|
reference. Each version includes `lib` dependencies and a compatible Java runtime
|
||||||
|
under `runtime`. Validate a staged version before switching `current`; retain
|
||||||
|
previous versions for rollback and already-running processes. Failed validation
|
||||||
|
MUST leave the existing reference intact. Registered commands MUST work without
|
||||||
|
an interactive shell PATH, external JDK or developer checkout.
|
||||||
|
|
||||||
|
The client command is the absolute `current/runtime/bin/java`, with argument-array
|
||||||
|
values `-cp`, `<current>/lib/*`, `p.studio.app.StudioLauncher`, `mcp`, `--project`,
|
||||||
|
and the canonical root. No project-local executable, generated transport script,
|
||||||
|
helper binary or separate launcher installation is allowed. The desktop and
|
||||||
|
connector use the same Studio artifact. JDWP is an explicit development-only JVM
|
||||||
|
option; IntelliJ attaches to the client-owned connector process separately from
|
||||||
|
the desktop Debug configuration.
|
||||||
|
|
||||||
|
New-project scaffolding and existing-project preparation MUST use the same neutral
|
||||||
|
preparation port. `.studio/setup.json` stores integration schema/enabled/profile
|
||||||
|
intent, preserving runtime/editor settings; it contains no endpoint/credential/task.
|
||||||
|
Application infrastructure owns `.codex/config.toml` serialization. Its managed
|
||||||
|
`mcp_servers.prometeu_studio` table stores the stable command, arguments, project
|
||||||
|
cwd and cold-start timeout. Preserve all unrelated tables, comments, approval
|
||||||
|
policy and server entries byte-for-byte; validate edits with a TOML parser.
|
||||||
|
Repetition with identical values MUST be a no-op. User-owned or modified managed
|
||||||
|
entries and tracked client configuration MUST produce an actionable conflict,
|
||||||
|
never an overwrite. Keep a protected recovery copy of the previous owned block
|
||||||
|
without copying unrelated secrets. Precise ignore rules protect machine-local
|
||||||
|
client configuration and transient discovery without deleting existing rules.
|
||||||
|
|
||||||
|
Preparation MUST report incomplete writes/installations truthfully. Trust/reload
|
||||||
|
instructions apply to initial client registration only; no client trust or tool
|
||||||
|
approval may be bypassed. Grant and desktop restart MUST NOT require changing the
|
||||||
|
client configuration. A clone is prepared locally to resolve its own installation
|
||||||
|
and project paths. No global client configuration is rewritten.
|
||||||
|
|
||||||
|
### 1.3 DEV Connection Assistance
|
||||||
|
|
||||||
|
DEV MUST expose preparation/readiness through neutral API contracts and show
|
||||||
|
connection status separately from Core authority. Waiting for access, connected
|
||||||
|
and reconnecting derive from project-scoped initialization/ping activity with a
|
||||||
|
bounded liveness window; a retained HTTP session ID alone is insufficient. Working
|
||||||
|
remains an authority/operation state. DEV MUST NOT invent knowledge of a client
|
||||||
|
before it connects. A transport drop MUST NOT revoke a task or grant new control.
|
||||||
|
|
||||||
|
Preparation, labels, clipboard, diagnostics and history MUST NOT expose secrets.
|
||||||
|
Closing/hiding DEV only unsubscribes visual listeners. Human grant/reclaim and
|
||||||
|
project/application teardown retain their shared Core semantics. Instructions
|
||||||
|
cover native file edits, project knowledge, grant/acquire, validation, receipt
|
||||||
|
lookup, images and explicit release without generated transport clients.
|
||||||
|
|
||||||
## 2. Identity and Admission
|
## 2. Identity and Admission
|
||||||
|
|
||||||
@@ -101,7 +160,7 @@ prove authorization.
|
|||||||
The authority levels in the packaged catalog are:
|
The authority levels in the packaged catalog are:
|
||||||
|
|
||||||
- `authenticated`: connection authentication only; project/context/reference reads
|
- `authenticated`: connection authentication only; project/context/reference reads
|
||||||
are allowed before grant. No task token is returned by discovery.
|
need no acquired task. HTTP access still requires the project credential published by human grant. Offline catalog discovery returns no task token.
|
||||||
- `granted`: acquisition validates the prior human grant and atomically creates
|
- `granted`: acquisition validates the prior human grant and atomically creates
|
||||||
the sole task identity. The transport session ID is not that identity.
|
the sole task identity. The transport session ID is not that identity.
|
||||||
- `task`: `projectRoot` and `taskId` must identify the current acquired task.
|
- `task`: `projectRoot` and `taskId` must identify the current acquired task.
|
||||||
@@ -187,7 +246,7 @@ for one fixed port. The public LSP configuration default remains unchanged for
|
|||||||
other hosts. A manifest language change requires reopening that project's server;
|
other hosts. A manifest language change requires reopening that project's server;
|
||||||
the adapter MUST NOT send queries to a server bound to another language/root.
|
the adapter MUST NOT send queries to a server bound to another language/root.
|
||||||
|
|
||||||
Each query uses a short-lived client connection. For document requests, the
|
Each query uses a short-lived client connection. For physical document requests, the
|
||||||
adapter opens exactly the saved UTF-8 text and waits for that connection's
|
adapter opens exactly the saved UTF-8 text and waits for that connection's
|
||||||
published diagnostics before issuing the semantic query. Other dependency files
|
published diagnostics before issuing the semantic query. Other dependency files
|
||||||
are read from disk by the existing compiler bridge. A fresh connection prevents
|
are read from disk by the existing compiler bridge. A fresh connection prevents
|
||||||
@@ -207,14 +266,54 @@ Core bounds the request worker wait to 12 seconds. Documents are limited to 4 Mi
|
|||||||
of UTF-8 and task-local hierarchy state to 1024 items. These are adapter resource
|
of UTF-8 and task-local hierarchy state to 1024 items. These are adapter resource
|
||||||
guards, unrelated to the runtime's deterministic frame/watchdog semantics.
|
guards, unrelated to the runtime's deterministic frame/watchdog semantics.
|
||||||
|
|
||||||
Document URIs must resolve to known physical project/dependency source files.
|
Document URIs must resolve to known physical project/dependency source files or to an external identity owned by the current task and project.
|
||||||
Symlink targets are canonicalized before admission. External sources may be
|
Symlink targets are canonicalized before admission. External sources may be
|
||||||
queried, but edit-producing queries on read-only roots are rejected. Every URI in
|
queried, but edit-producing queries on read-only roots are rejected. Every URI in
|
||||||
returned workspace-edit proposals is checked against the same editable/read-only
|
returned workspace-edit proposals is checked against the same editable/read-only
|
||||||
scope; an unsafe proposal is rejected as a whole. File-operation edits and
|
scope; an unsafe proposal is rejected as a whole. File-operation edits and
|
||||||
executable commands are not offered; `workspace/applyEdit` is always refused.
|
executable commands are not offered; `workspace/applyEdit` is always refused.
|
||||||
No query writes a file. Virtual SDK declarations may not have physical definition
|
No query writes a file. `readExternalSource` reads the exact registered external
|
||||||
locations in the existing LSP; indexed SDK references remain available instead.
|
revision; hover and definition on its URI use the retained frontend semantic
|
||||||
|
context. Indexed SDK reference tools remain separate and available. MCP needs no
|
||||||
|
VS Code connection and MUST retain its consumer across short-lived query sockets.
|
||||||
|
Task return/cancellation releases that task's external uses; project shutdown
|
||||||
|
invalidates all identities. Cross-task/project replay is refused.
|
||||||
|
|
||||||
|
### External-source protocol (DEC-0062)
|
||||||
|
|
||||||
|
Initialize negotiates `capabilities.experimental.prometeuExternalSources: true`;
|
||||||
|
the server advertises the same flag only when supported. External definitions use
|
||||||
|
`prometeu-source:` URIs minted by the project host. A descriptor carries `uri`,
|
||||||
|
`revision` (content digest), `origin`, `name`, `languageId` and `readOnly: true`.
|
||||||
|
Locations carry ordinary LSP UTF-16 ranges over that exact source text.
|
||||||
|
|
||||||
|
The `prometeu/readExternalSource`, `prometeu/retainExternalSource`,
|
||||||
|
`prometeu/releaseExternalSource` and `prometeu/revalidateExternalSource` requests
|
||||||
|
carry `uri` and a server-issued `consumerId`. Initialize returns that identity in
|
||||||
|
`capabilities.experimental.prometeuExternalConsumerId`. Reconnecting clients pass
|
||||||
|
it as `initializationOptions.prometeuExternalConsumerId`; MCP also requests
|
||||||
|
`initializationOptions.prometeuExternalPersistentConsumer: true` on first use.
|
||||||
|
`releaseExternalSource` with `uri: null` releases the consumer and all its sources.
|
||||||
|
A read or explicit retain acknowledges a navigation result; unacknowledged results
|
||||||
|
are released when the socket closes. MCP acknowledges returned definitions before
|
||||||
|
closing its query connection and rolls back newly retained results on failure.
|
||||||
|
Read-only edit refusal uses LSP error `-32010`, mapped to MCP `READ_ONLY_SCOPE`.
|
||||||
|
Consumer identity is scoped to the
|
||||||
|
project session; the MCP adapter additionally binds it to its authorized task.
|
||||||
|
Read returns the descriptor plus `text`. Retain/release are idempotent per consumer.
|
||||||
|
Revalidation confirms the same admitted origin and revision before queries resume;
|
||||||
|
a changed revision reports unavailable and requires new navigation. Unknown,
|
||||||
|
expired, unauthorized and unreadable sources are explicit errors, never disk reads
|
||||||
|
chosen by client paths. Consumers are created by the server, not caller-selected.
|
||||||
|
|
||||||
|
VS Code uses a read-only text content provider, with the source language and no
|
||||||
|
save-back path. Disconnect may leave the immutable text visible, but blocks
|
||||||
|
semantic queries until revalidation. No content-change event may replace the old
|
||||||
|
revision under old positions. Closing the last consumer releases the snapshot;
|
||||||
|
one reader closing must not invalidate another reader. Edit operations and mixed
|
||||||
|
workspace edits are rejected in their entirety, including physical aliases.
|
||||||
|
Packaged Studio validation is excluded from this delivery; development tests must
|
||||||
|
exercise both VS Code and independent MCP navigation.
|
||||||
|
|
||||||
## 4. Result, Error and Operation Contracts
|
## 4. Result, Error and Operation Contracts
|
||||||
|
|
||||||
@@ -335,7 +434,7 @@ reference provider, not a Studio-maintained language specification.
|
|||||||
|
|
||||||
`studio_project_context` resolves an exact, canonical root registered by an open
|
`studio_project_context` resolves an exact, canonical root registered by an open
|
||||||
project session. It does not use the focused window, accept a source-directory
|
project session. It does not use the focused window, accept a source-directory
|
||||||
path as a project root, acquire a manual lease, or require an AI grant. A session
|
path as a project root, acquire a manual lease, or acquire task authority. The HTTP boundary separately requires the grant-published project credential. A session
|
||||||
is discoverable only after successful opening and until closure begins.
|
is discoverable only after successful opening and until closure begins.
|
||||||
Unregistered/closed roots return `PROJECT_NOT_OPEN`.
|
Unregistered/closed roots return `PROJECT_NOT_OPEN`.
|
||||||
|
|
||||||
@@ -395,8 +494,7 @@ example references identify their SDK major and target; unsupported selections
|
|||||||
MUST NOT silently reuse another SDK/target. Numbered spec/draft revisions and the
|
MUST NOT silently reuse another SDK/target. Numbered spec/draft revisions and the
|
||||||
reference-index schema revision MUST NOT be reported as language/compiler versions.
|
reference-index schema revision MUST NOT be reported as language/compiler versions.
|
||||||
|
|
||||||
`studio_reference_read` is authenticated but does not require a control grant or
|
`studio_reference_read` is authenticated but does not require an acquired task; the transport still requires a grant-published project credential. It resolves the explicit open root and its current saved manifest selection
|
||||||
task. It resolves the explicit open root and its current saved manifest selection
|
|
||||||
on every read. Changing SDK/target can invalidate previously advertised IDs.
|
on every read. Changing SDK/target can invalidate previously advertised IDs.
|
||||||
Only IDs in that project's installed index can be read, including when other
|
Only IDs in that project's installed index can be read, including when other
|
||||||
languages/providers are installed globally. SDK and external-library texts remain
|
languages/providers are installed globally. SDK and external-library texts remain
|
||||||
@@ -442,7 +540,7 @@ The production registry composes all 17 tools as of step 23, including headless
|
|||||||
handlers bound to the actual `HeadlessProcessGateway`. Missing project runtime
|
handlers bound to the actual `HeadlessProcessGateway`. Missing project runtime
|
||||||
configuration fails at boot with `RUNTIME_UNAVAILABLE`; tool discovery does not
|
configuration fails at boot with `RUNTIME_UNAVAILABLE`; tool discovery does not
|
||||||
grant authority or launch a process. No fake runtime is shipped.
|
grant authority or launch a process. No fake runtime is shipped.
|
||||||
DEV configuration-copy is connected as of step 21. The automated HTTP conformance
|
The former configuration-copy flow is superseded by DEC-0061 permanent preparation and grant-time discovery. The automated HTTP conformance
|
||||||
gate exercises all 17 tool contracts using real project knowledge/LSP and test-only
|
gate exercises all 17 tool contracts using real project knowledge/LSP and test-only
|
||||||
build/runtime ports; a separate HTTP test uses the real compiler/packer. This
|
build/runtime ports; a separate HTTP test uses the real compiler/packer. This
|
||||||
completes MCP-phase conformance. The packaged-runtime gate additionally exercises
|
completes MCP-phase conformance. The packaged-runtime gate additionally exercises
|
||||||
@@ -461,8 +559,8 @@ are also checked. Rebuilding changes pixels/build identity and visibly marks the
|
|||||||
old capture stale. Images remain in memory; window screenshots are not evidence.
|
old capture stale. Images remain in memory; window screenshots are not evidence.
|
||||||
|
|
||||||
The fixture uses supported project-source LSP definition/symbol navigation and
|
The fixture uses supported project-source LSP definition/symbol navigation and
|
||||||
indexed SDK reads. A probe of the installed SDK's `Input.pad()` definition returns
|
indexed SDK reads. The historical probe of the former SDK `Input.pad()` definition returned
|
||||||
an empty result with the current language service; the gate does not claim SDK
|
an empty result (the current facade is Pad/Button and Touch); the gate does not claim SDK
|
||||||
symbol navigation where no location is returned. This is a language tooling
|
symbol navigation where no location is returned. This is a language tooling
|
||||||
limitation, not a headless or MCP execution fallback.
|
limitation, not a headless or MCP execution fallback.
|
||||||
|
|
||||||
@@ -493,3 +591,26 @@ cycles using the extracted Studio ZIP. The latter verified listener closure and
|
|||||||
old-credential rejection after restart. API/Core and JavaFX MUST NOT import
|
old-credential rejection after restart. API/Core and JavaFX MUST NOT import
|
||||||
MCP/HTTP implementations; architecture tests enforce it. Consolidated acceptance
|
MCP/HTTP implementations; architecture tests enforce it. Consolidated acceptance
|
||||||
evidence and deferred findings live in the DSC-0068 lesson, not in temporary logs.
|
evidence and deferred findings live in the DSC-0068 lesson, not in temporary logs.
|
||||||
|
|
||||||
|
### Integrated Connection Acceptance (DEC-0061)
|
||||||
|
|
||||||
|
Prior DSC-0068 native-client evidence covers the original HTTP flow only. The
|
||||||
|
integrated flow additionally requires a real native Codex session initialized
|
||||||
|
before grant, unchanged configuration through desktop restart/new grant, native
|
||||||
|
images/build/release, scaffold and existing-project preparation, installation
|
||||||
|
update and graphical launch, plus IntelliJ connector attachment. Automated
|
||||||
|
fixtures cannot substitute for these gates. PLN-0140 completed automated validation
|
||||||
|
and the user confirmed all outstanding manual gates on 2026-09-29. The manual
|
||||||
|
confirmation is user-reported acceptance, not an independently observed test run.
|
||||||
|
[LSN-0077](../../../discussion/lessons/DSC-0070-studio-persistent-mcp-connector/LSN-0077-integrated-mcp-stable-setup-and-ephemeral-access.md)
|
||||||
|
preserves the result and evidence provenance after workflow housekeeping.
|
||||||
|
|
||||||
|
### Automatic preparation when opening a project
|
||||||
|
|
||||||
|
Opening a project MUST prepare its enabled MCP integration using the same neutral
|
||||||
|
port as scaffold and DEV retry. Desktop composition MUST start the shared loopback
|
||||||
|
server before project sessions become available; no external command or separate
|
||||||
|
per-project desktop Run is required. Explicitly disabled integration MUST remain
|
||||||
|
disabled. Preparation failure MUST remain visible in DEV readiness without blocking
|
||||||
|
project use. Opening MUST NOT publish credentials or grant/acquire agent control.
|
||||||
|
The coding client continues to own its configured stdio process and initial trust.
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ The main session-restoration store MUST NOT include:
|
|||||||
- heavy operational output;
|
- heavy operational output;
|
||||||
- recomputable results that do not represent session restoration state.
|
- recomputable results that do not represent session restoration state.
|
||||||
|
|
||||||
Under DEC-0060, automation grants, task/control identities, active runtime sessions and the task-local operation/deduplication registry MUST NOT be persisted or restored through `.studio/state.json` or `.studio/setup.json`. Reopening a project MUST start under manual control. Restoring DEV as the selected workspace is presentation restoration, not permission to resume work. MCP connection credentials MUST NOT be stored in versioned files; they are regenerated on Studio restart. See the [DEV and Automation Specification](10.%20DEV%20and%20Automation%20Specification.md).
|
Under DEC-0060, automation grants, task/control identities, active runtime sessions and the task-local operation/deduplication registry MUST NOT be persisted or restored through `.studio/state.json` or `.studio/setup.json`. Reopening a project MUST start under manual control. Restoring DEV as the selected workspace is presentation restoration, not permission to resume work. MCP connection credentials MUST NOT be stored in versioned files; they are regenerated for every project grant and never restored on restart. See the [DEV and Automation Specification](10.%20DEV%20and%20Automation%20Specification.md).
|
||||||
|
|
||||||
`Project-local activity` and project-local setup may still live under `.studio/`, but they are separate persistence concerns and not part of the main session-restoration store defined here.
|
`Project-local activity` and project-local setup may still live under `.studio/`, but they are separate persistence concerns and not part of the main session-restoration store defined here.
|
||||||
|
|
||||||
@@ -105,3 +105,36 @@ This specification is complete enough when:
|
|||||||
- accepted and excluded categories are explicit;
|
- accepted and excluded categories are explicit;
|
||||||
- load, restore, save, and fallback timing are explicit;
|
- load, restore, save, and fallback timing are explicit;
|
||||||
- and the ownership boundary with `StudioProjectSession` is normatively locked.
|
- and the ownership boundary with `StudioProjectSession` is normatively locked.
|
||||||
|
|
||||||
|
## Integrated MCP Discovery (DEC-0061)
|
||||||
|
|
||||||
|
`.studio/setup.json` MUST carry neutral `agentIntegration` intent with
|
||||||
|
`schemaVersion:1`, `enabled` and `clientProfile`. Preserve runtime and editor
|
||||||
|
fields. This intent is configuration, not readiness or authorization. Machine-local
|
||||||
|
resolved client configuration is a separate preparation output.
|
||||||
|
|
||||||
|
The transient descriptor is `.studio/mcp/connection.json`, limited to 16 KiB.
|
||||||
|
Schema v1 requires integral `schemaVersion:1` and nonempty string `instanceId`,
|
||||||
|
`projectRoot`, `endpoint`, `credential`, `catalogFingerprint`. Root MUST match the
|
||||||
|
connector's canonical root. Endpoint MUST be `http://127.0.0.1:<port>/mcp`, with
|
||||||
|
no userinfo, query, fragment or redirect. Grant/task IDs and receipts are forbidden.
|
||||||
|
|
||||||
|
On macOS `.studio/mcp` MUST be owned by the current user with mode 0700;
|
||||||
|
descriptor, lock and temporary files MUST be 0600 before secrets are written.
|
||||||
|
Reject symlinked/unsafe paths and tracked descriptor targets. Add precise ignore
|
||||||
|
rules idempotently without changing unrelated project permissions or files.
|
||||||
|
|
||||||
|
Ownership MUST use an OS-held lock on the stable `publication.lock` inode; do
|
||||||
|
not delete the lock file on ordinary cleanup. A second live publisher fails. A
|
||||||
|
crashed process releases its lock through the OS; a new owner may atomically
|
||||||
|
replace stale content. Write a protected same-directory temporary file and
|
||||||
|
atomically rename it. Cleanup checks both instance and publication generation
|
||||||
|
so an old callback cannot remove newer discovery data.
|
||||||
|
|
||||||
|
Publication is a required grant lifecycle participant, not a swallowed observer.
|
||||||
|
Prepare/publish occur outside the Core monitor; authority activation uses a
|
||||||
|
generation fence. Acquisition cannot succeed until publication and grant both
|
||||||
|
commit. Failure aborts credentials/files and reports a failed grant. Revoke/close
|
||||||
|
invalidate credentials before asynchronous work cleanup, then remove owned
|
||||||
|
publication and release ownership. File cleanup failure MUST NOT prevent runtime
|
||||||
|
cancellation. An already-admitted release response MUST remain deliverable.
|
||||||
|
|||||||
@@ -114,9 +114,9 @@ The JavaFX module MUST NOT directly invoke compiler implementations, `p.packer`,
|
|||||||
|
|
||||||
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.
|
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 random per-Studio-start token, validate Origin and reject unexpected origins, and stop with Studio. Connection authentication MUST NOT grant project/task authority. The token MUST NOT be stored in versioned files, and restart requires refreshed client configuration.
|
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, OAuth, or a stdio MCP bridge. 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.
|
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.
|
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.
|
||||||
|
|
||||||
@@ -178,3 +178,17 @@ The architecture is conformant only when all of the following hold together:
|
|||||||
- migrating the Studio to Rust, Electron, Tauri, or a parallel rewrite;
|
- migrating the Studio to Rust, Electron, Tauri, or a parallel rewrite;
|
||||||
- redesigning compiler, Packer, LSP, or runtime semantics;
|
- redesigning compiler, Packer, LSP, or runtime semantics;
|
||||||
- introducing microservices or durable event infrastructure.
|
- 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.
|
||||||
|
|||||||
@@ -84,3 +84,14 @@ Normative reminders:
|
|||||||
- the Studio backend is exposed through neutral API contracts shared by JavaFX and the local MCP adapter, without duplicated authority or orchestration;
|
- the Studio backend is exposed through neutral API contracts shared by JavaFX and the local MCP adapter, without duplicated authority or orchestration;
|
||||||
- Spring Boot remains the desktop composition root with the narrow DEC-0060 local MCP HTTP exception; Spring Modulith still verifies the JavaFX-free `p.studio.core` boundary;
|
- Spring Boot remains the desktop composition root with the narrow DEC-0060 local MCP HTTP exception; Spring Modulith still verifies the JavaFX-free `p.studio.core` boundary;
|
||||||
- `p.studio.Container`, `AppContainer`, and the mixed `prometeu-studio` module are not valid final architecture.
|
- `p.studio.Container`, `AppContainer`, and the mixed `prometeu-studio` module are not valid final architecture.
|
||||||
|
|
||||||
|
## Integrated MCP connection
|
||||||
|
|
||||||
|
DEC-0061 revises the baseline with Studio-owned `mcp --project` mode, grant-time
|
||||||
|
project discovery, scoped HTTP credentials, one-time scaffold/preparation and a
|
||||||
|
stable installation with bundled Java. Specs 8–11 define the lifecycle and
|
||||||
|
transport boundaries; spec 1 defines project creation. PLN-0140 is complete;
|
||||||
|
automated results and user-confirmed manual acceptance are consolidated in
|
||||||
|
[LSN-0077](../../../discussion/lessons/DSC-0070-studio-persistent-mcp-connector/LSN-0077-integrated-mcp-stable-setup-and-ephemeral-access.md).
|
||||||
|
The earlier HTTP evidence was not substituted for these gates. The embedded
|
||||||
|
terminal remains separate.
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
target,name,version,slot,carrier,bits_or_value
|
||||||
|
color,black,1,0,Int64,255
|
||||||
|
color,blue,1,0,Int64,65535
|
||||||
|
color,cyan,1,0,Int64,16777215
|
||||||
|
color,gray,1,0,Int64,2155905279
|
||||||
|
color,green,1,0,Int64,16711935
|
||||||
|
color,indigo,1,0,Int64,1258324735
|
||||||
|
color,magenta,1,0,Int64,4278255615
|
||||||
|
color,orange,1,0,Int64,4286578943
|
||||||
|
color,red,1,0,Int64,4278190335
|
||||||
|
color,transparent,1,0,Int64,0
|
||||||
|
color,white,1,0,Int64,4294967295
|
||||||
|
color,yellow,1,0,Int64,4294902015
|
||||||
|
mathf,pi,1,0,Float,0x400921FB54442D18
|
||||||
|
mathf,tau,1,0,Float,0x401921FB54442D18
|
||||||
|
vec2,zero,1,0,Float,0x0000000000000000
|
||||||
|
vec2,zero,1,1,Float,0x0000000000000000
|
||||||
|
+106
-43
@@ -1,43 +1,106 @@
|
|||||||
final_id_hex,final_id_dec,canonical_name,canonical_version,owner,name,arg_slots,ret_slots,arg_layout,ret_layout,deterministic,may_allocate
|
final_id_hex,final_id_dec,canonical_name,canonical_version,owner,name,arg_slots,ret_slots,arg_layout,ret_layout,deterministic,may_allocate,parameter_names,cost_cycles,mutates_guest_state,cost_model,attempt_cost_cycles,max_attempts
|
||||||
0x1000,4096,vec2.dot,1,vec2,dot,4,1,float|float|float|float,float,true,false
|
0x1000,4096,vec2.dot,1,vec2,dot,4,1,Float|Float|Float|Float,Float,true,false,ax|ay|bx|by,10,false,fixed,0,0
|
||||||
0x1001,4097,vec2.length,1,vec2,length,2,1,float|float,float,true,false
|
0x1001,4097,vec2.length,1,vec2,length,2,1,Float|Float,Float,true,false,x|y,40,false,fixed,0,0
|
||||||
0x1100,4352,color.from_raw,1,color,from_raw,1,1,int,builtin:color,true,false
|
0x1100,4352,color.from_raw,1,color,from_raw,1,1,Int64,builtin:color,true,false,raw,1,false,fixed,0,0
|
||||||
0x1101,4353,color.rgb,1,color,rgb,3,1,int|int|int,builtin:color,true,false
|
0x1101,4353,color.rgb,1,color,rgb,3,1,Int64|Int64|Int64,builtin:color,true,false,r|g|b,1,false,fixed,0,0
|
||||||
0x1102,4354,color.rgba,1,color,rgba,4,1,int|int|int|int,builtin:color,true,false
|
0x1102,4354,color.rgba,1,color,rgba,4,1,Int64|Int64|Int64|Int64,builtin:color,true,false,r|g|b|a,1,false,fixed,0,0
|
||||||
0x1103,4355,color.html_rgba,1,color,html_rgba,1,1,str,builtin:color,true,false
|
0x1103,4355,color.html_rgba,1,color,html_rgba,1,1,String,builtin:color,true,false,value,1,false,fixed,0,0
|
||||||
0x1104,4356,color.gray_scale,1,color,gray_scale,1,1,int,builtin:color,true,false
|
0x1104,4356,color.gray_scale,1,color,gray_scale,1,1,Int64,builtin:color,true,false,value,1,false,fixed,0,0
|
||||||
0x1105,4357,color.hex,1,color,hex,1,1,builtin:color,int,true,false
|
0x1105,4357,color.hex,1,color,hex,1,1,builtin:color,Int64,true,false,color,1,false,fixed,0,0
|
||||||
0x1106,4358,color.alpha,1,color,alpha,1,1,builtin:color,int,true,false
|
0x1106,4358,color.alpha,1,color,alpha,1,1,builtin:color,Int64,true,false,color,1,false,fixed,0,0
|
||||||
0x1120,4384,color.black,1,color,black,0,1,,builtin:color,true,false
|
0x1120,4384,color.black,1,color,black,0,1,,builtin:color,true,false,,1,false,fixed,0,0
|
||||||
0x1121,4385,color.white,1,color,white,0,1,,builtin:color,true,false
|
0x1121,4385,color.white,1,color,white,0,1,,builtin:color,true,false,,1,false,fixed,0,0
|
||||||
0x1122,4386,color.red,1,color,red,0,1,,builtin:color,true,false
|
0x1122,4386,color.red,1,color,red,0,1,,builtin:color,true,false,,1,false,fixed,0,0
|
||||||
0x1123,4387,color.green,1,color,green,0,1,,builtin:color,true,false
|
0x1123,4387,color.green,1,color,green,0,1,,builtin:color,true,false,,1,false,fixed,0,0
|
||||||
0x1124,4388,color.blue,1,color,blue,0,1,,builtin:color,true,false
|
0x1124,4388,color.blue,1,color,blue,0,1,,builtin:color,true,false,,1,false,fixed,0,0
|
||||||
0x1125,4389,color.yellow,1,color,yellow,0,1,,builtin:color,true,false
|
0x1125,4389,color.yellow,1,color,yellow,0,1,,builtin:color,true,false,,1,false,fixed,0,0
|
||||||
0x1126,4390,color.orange,1,color,orange,0,1,,builtin:color,true,false
|
0x1126,4390,color.orange,1,color,orange,0,1,,builtin:color,true,false,,1,false,fixed,0,0
|
||||||
0x1127,4391,color.indigo,1,color,indigo,0,1,,builtin:color,true,false
|
0x1127,4391,color.indigo,1,color,indigo,0,1,,builtin:color,true,false,,1,false,fixed,0,0
|
||||||
0x1128,4392,color.gray,1,color,gray,0,1,,builtin:color,true,false
|
0x1128,4392,color.gray,1,color,gray,0,1,,builtin:color,true,false,,1,false,fixed,0,0
|
||||||
0x1129,4393,color.cyan,1,color,cyan,0,1,,builtin:color,true,false
|
0x1129,4393,color.cyan,1,color,cyan,0,1,,builtin:color,true,false,,1,false,fixed,0,0
|
||||||
0x112A,4394,color.magenta,1,color,magenta,0,1,,builtin:color,true,false
|
0x112A,4394,color.magenta,1,color,magenta,0,1,,builtin:color,true,false,,1,false,fixed,0,0
|
||||||
0x112B,4395,color.transparent,1,color,transparent,0,1,,builtin:color,true,false
|
0x112B,4395,color.transparent,1,color,transparent,0,1,,builtin:color,true,false,,1,false,fixed,0,0
|
||||||
0x2000,8192,input.pad,1,input,pad,0,1,,builtin:input.pad,true,false
|
0x2100,8448,input.pad.up.pressed,1,input.pad.up,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
0x2001,8193,input.touch,1,input,touch,0,1,,builtin:input.touch,true,false
|
0x2101,8449,input.pad.up.released,1,input.pad.up,released,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
0x2010,8208,input.pad.up,1,input.pad,up,1,1,builtin:input.pad,builtin:input.button,true,false
|
0x2102,8450,input.pad.up.down,1,input.pad.up,down,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
0x2011,8209,input.pad.down,1,input.pad,down,1,1,builtin:input.pad,builtin:input.button,true,false
|
0x2103,8451,input.pad.up.hold,1,input.pad.up,hold,0,1,,Int64,true,false,,1,false,fixed,0,0
|
||||||
0x2012,8210,input.pad.left,1,input.pad,left,1,1,builtin:input.pad,builtin:input.button,true,false
|
0x2104,8452,input.pad.down.pressed,1,input.pad.down,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
0x2013,8211,input.pad.right,1,input.pad,right,1,1,builtin:input.pad,builtin:input.button,true,false
|
0x2105,8453,input.pad.down.released,1,input.pad.down,released,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
0x2014,8212,input.pad.a,1,input.pad,a,1,1,builtin:input.pad,builtin:input.button,true,false
|
0x2106,8454,input.pad.down.down,1,input.pad.down,down,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
0x2015,8213,input.pad.b,1,input.pad,b,1,1,builtin:input.pad,builtin:input.button,true,false
|
0x2107,8455,input.pad.down.hold,1,input.pad.down,hold,0,1,,Int64,true,false,,1,false,fixed,0,0
|
||||||
0x2016,8214,input.pad.x,1,input.pad,x,1,1,builtin:input.pad,builtin:input.button,true,false
|
0x2108,8456,input.pad.left.pressed,1,input.pad.left,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
0x2017,8215,input.pad.y,1,input.pad,y,1,1,builtin:input.pad,builtin:input.button,true,false
|
0x2109,8457,input.pad.left.released,1,input.pad.left,released,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
0x2018,8216,input.pad.l,1,input.pad,l,1,1,builtin:input.pad,builtin:input.button,true,false
|
0x210A,8458,input.pad.left.down,1,input.pad.left,down,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
0x2019,8217,input.pad.r,1,input.pad,r,1,1,builtin:input.pad,builtin:input.button,true,false
|
0x210B,8459,input.pad.left.hold,1,input.pad.left,hold,0,1,,Int64,true,false,,1,false,fixed,0,0
|
||||||
0x201A,8218,input.pad.start,1,input.pad,start,1,1,builtin:input.pad,builtin:input.button,true,false
|
0x210C,8460,input.pad.right.pressed,1,input.pad.right,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
0x201B,8219,input.pad.select,1,input.pad,select,1,1,builtin:input.pad,builtin:input.button,true,false
|
0x210D,8461,input.pad.right.released,1,input.pad.right,released,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
0x2020,8224,input.touch.button,1,input.touch,button,1,1,builtin:input.touch,builtin:input.button,true,false
|
0x210E,8462,input.pad.right.down,1,input.pad.right,down,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
0x2021,8225,input.touch.x,1,input.touch,x,1,1,builtin:input.touch,int,true,false
|
0x210F,8463,input.pad.right.hold,1,input.pad.right,hold,0,1,,Int64,true,false,,1,false,fixed,0,0
|
||||||
0x2022,8226,input.touch.y,1,input.touch,y,1,1,builtin:input.touch,int,true,false
|
0x2110,8464,input.pad.a.pressed,1,input.pad.a,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
0x2030,8240,input.button.pressed,1,input.button,pressed,1,1,builtin:input.button,bool,true,false
|
0x2111,8465,input.pad.a.released,1,input.pad.a,released,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
0x2031,8241,input.button.released,1,input.button,released,1,1,builtin:input.button,bool,true,false
|
0x2112,8466,input.pad.a.down,1,input.pad.a,down,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
0x2032,8242,input.button.down,1,input.button,down,1,1,builtin:input.button,bool,true,false
|
0x2113,8467,input.pad.a.hold,1,input.pad.a,hold,0,1,,Int64,true,false,,1,false,fixed,0,0
|
||||||
0x2033,8243,input.button.hold,1,input.button,hold,1,1,builtin:input.button,int,true,false
|
0x2114,8468,input.pad.b.pressed,1,input.pad.b,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
|
0x2115,8469,input.pad.b.released,1,input.pad.b,released,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
|
0x2116,8470,input.pad.b.down,1,input.pad.b,down,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
|
0x2117,8471,input.pad.b.hold,1,input.pad.b,hold,0,1,,Int64,true,false,,1,false,fixed,0,0
|
||||||
|
0x2118,8472,input.pad.x.pressed,1,input.pad.x,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
|
0x2119,8473,input.pad.x.released,1,input.pad.x,released,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
|
0x211A,8474,input.pad.x.down,1,input.pad.x,down,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
|
0x211B,8475,input.pad.x.hold,1,input.pad.x,hold,0,1,,Int64,true,false,,1,false,fixed,0,0
|
||||||
|
0x211C,8476,input.pad.y.pressed,1,input.pad.y,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
|
0x211D,8477,input.pad.y.released,1,input.pad.y,released,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
|
0x211E,8478,input.pad.y.down,1,input.pad.y,down,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
|
0x211F,8479,input.pad.y.hold,1,input.pad.y,hold,0,1,,Int64,true,false,,1,false,fixed,0,0
|
||||||
|
0x2120,8480,input.pad.l.pressed,1,input.pad.l,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
|
0x2121,8481,input.pad.l.released,1,input.pad.l,released,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
|
0x2122,8482,input.pad.l.down,1,input.pad.l,down,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
|
0x2123,8483,input.pad.l.hold,1,input.pad.l,hold,0,1,,Int64,true,false,,1,false,fixed,0,0
|
||||||
|
0x2124,8484,input.pad.r.pressed,1,input.pad.r,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
|
0x2125,8485,input.pad.r.released,1,input.pad.r,released,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
|
0x2126,8486,input.pad.r.down,1,input.pad.r,down,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
|
0x2127,8487,input.pad.r.hold,1,input.pad.r,hold,0,1,,Int64,true,false,,1,false,fixed,0,0
|
||||||
|
0x2128,8488,input.pad.start.pressed,1,input.pad.start,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
|
0x2129,8489,input.pad.start.released,1,input.pad.start,released,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
|
0x212A,8490,input.pad.start.down,1,input.pad.start,down,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
|
0x212B,8491,input.pad.start.hold,1,input.pad.start,hold,0,1,,Int64,true,false,,1,false,fixed,0,0
|
||||||
|
0x212C,8492,input.pad.select.pressed,1,input.pad.select,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
|
0x212D,8493,input.pad.select.released,1,input.pad.select,released,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
|
0x212E,8494,input.pad.select.down,1,input.pad.select,down,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
|
0x212F,8495,input.pad.select.hold,1,input.pad.select,hold,0,1,,Int64,true,false,,1,false,fixed,0,0
|
||||||
|
0x2130,8496,input.touch.button.pressed,1,input.touch.button,pressed,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
|
0x2131,8497,input.touch.button.released,1,input.touch.button,released,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
|
0x2132,8498,input.touch.button.down,1,input.touch.button,down,0,1,,Bool,true,false,,1,false,fixed,0,0
|
||||||
|
0x2133,8499,input.touch.button.hold,1,input.touch.button,hold,0,1,,Int64,true,false,,1,false,fixed,0,0
|
||||||
|
0x2134,8500,input.touch.x,1,input.touch,x,0,1,,Int64,true,false,,1,false,fixed,0,0
|
||||||
|
0x2135,8501,input.touch.y,1,input.touch,y,0,1,,Int64,true,false,,1,false,fixed,0,0
|
||||||
|
0x3000,12288,math.i32.min,1,math.i32,min,2,1,Int32|Int32,Int32,true,false,a|b,2,false,fixed,0,0
|
||||||
|
0x3001,12289,math.i32.max,1,math.i32,max,2,1,Int32|Int32,Int32,true,false,a|b,2,false,fixed,0,0
|
||||||
|
0x3002,12290,math.i32.clamp,1,math.i32,clamp,3,1,Int32|Int32|Int32,Int32,true,false,value|min|max,4,false,fixed,0,0
|
||||||
|
0x3003,12291,math.i32.abs,1,math.i32,abs,1,1,Int32,Int32,true,false,value,2,false,fixed,0,0
|
||||||
|
0x3004,12292,math.i64.min,1,math.i64,min,2,1,Int64|Int64,Int64,true,false,a|b,2,false,fixed,0,0
|
||||||
|
0x3005,12293,math.i64.max,1,math.i64,max,2,1,Int64|Int64,Int64,true,false,a|b,2,false,fixed,0,0
|
||||||
|
0x3006,12294,math.i64.clamp,1,math.i64,clamp,3,1,Int64|Int64|Int64,Int64,true,false,value|min|max,4,false,fixed,0,0
|
||||||
|
0x3007,12295,math.i64.abs,1,math.i64,abs,1,1,Int64,Int64,true,false,value,2,false,fixed,0,0
|
||||||
|
0x3008,12296,mathf.min,1,mathf,min,2,1,Float|Float,Float,true,false,a|b,2,false,fixed,0,0
|
||||||
|
0x3009,12297,mathf.max,1,mathf,max,2,1,Float|Float,Float,true,false,a|b,2,false,fixed,0,0
|
||||||
|
0x300A,12298,mathf.clamp,1,mathf,clamp,3,1,Float|Float|Float,Float,true,false,value|min|max,4,false,fixed,0,0
|
||||||
|
0x300B,12299,mathf.abs,1,mathf,abs,1,1,Float,Float,true,false,value,2,false,fixed,0,0
|
||||||
|
0x300C,12300,mathf.floor,1,mathf,floor,1,1,Float,Float,true,false,value,4,false,fixed,0,0
|
||||||
|
0x300D,12301,mathf.ceil,1,mathf,ceil,1,1,Float,Float,true,false,value,4,false,fixed,0,0
|
||||||
|
0x300E,12302,mathf.trunc,1,mathf,trunc,1,1,Float,Float,true,false,value,4,false,fixed,0,0
|
||||||
|
0x300F,12303,mathf.round,1,mathf,round,1,1,Float,Float,true,false,value,4,false,fixed,0,0
|
||||||
|
0x3010,12304,mathf.sqrt,1,mathf,sqrt,1,1,Float,Float,true,false,value,16,false,fixed,0,0
|
||||||
|
0x3011,12305,mathf.sin,1,mathf,sin,1,1,Float,Float,true,false,angle,32,false,fixed,0,0
|
||||||
|
0x3012,12306,mathf.cos,1,mathf,cos,1,1,Float,Float,true,false,angle,32,false,fixed,0,0
|
||||||
|
0x3013,12307,mathf.atan2,1,mathf,atan2,2,1,Float|Float,Float,true,false,y|x,48,false,fixed,0,0
|
||||||
|
0x3014,12308,math.i32.to_i64,1,math.i32,to_i64,1,1,Int32,Int64,true,false,value,2,false,fixed,0,0
|
||||||
|
0x3015,12309,math.i64.to_i32,1,math.i64,to_i32,1,1,Int64,Int32,true,false,value,2,false,fixed,0,0
|
||||||
|
0x3016,12310,math.i32.to_float,1,math.i32,to_float,1,1,Int32,Float,true,false,value,2,false,fixed,0,0
|
||||||
|
0x3017,12311,math.i64.to_float,1,math.i64,to_float,1,1,Int64,Float,true,false,value,2,false,fixed,0,0
|
||||||
|
0x3018,12312,mathf.to_i32,1,mathf,to_i32,1,1,Float,Int32,true,false,value,2,false,fixed,0,0
|
||||||
|
0x3019,12313,mathf.to_i64,1,mathf,to_i64,1,1,Float,Int64,true,false,value,2,false,fixed,0,0
|
||||||
|
0x4000,16384,random.new,1,random,new,1,1,Int64,builtin:Random,true,true,seed,32,true,fixed,0,0
|
||||||
|
0x4001,16385,random.next,1,random,next,1,1,builtin:Random,Int64,true,false,rng,8,true,fixed,0,0
|
||||||
|
0x4002,16386,random.nextf,1,random,nextf,1,1,builtin:Random,Float,true,false,rng,12,true,fixed,0,0
|
||||||
|
0x4003,16387,random.range,1,random,range,3,1,builtin:Random|Int64|Int64,Int64,true,false,rng|min|max,4,true,random_rejection_v1,8,64
|
||||||
|
|||||||
|
+24
-1
@@ -10,6 +10,7 @@ Canonical runtime sources:
|
|||||||
- `../runtime/docs/vm-arch/ARCHITECTURE.md`
|
- `../runtime/docs/vm-arch/ARCHITECTURE.md`
|
||||||
- `../runtime/docs/vm-arch/ISA_CORE.md`
|
- `../runtime/docs/vm-arch/ISA_CORE.md`
|
||||||
- `../runtime/docs/vm-arch/INTRINSICS.csv`
|
- `../runtime/docs/vm-arch/INTRINSICS.csv`
|
||||||
|
- `../runtime/docs/vm-arch/BUILTIN_CONSTANTS.csv`
|
||||||
|
|
||||||
When these mirrors are retained, an integration change that updates a canonical
|
When these mirrors are retained, an integration change that updates a canonical
|
||||||
runtime source MUST update the corresponding Studio mirror in the same logical
|
runtime source MUST update the corresponding Studio mirror in the same logical
|
||||||
@@ -19,9 +20,10 @@ change. Verify synchronization from the Studio repository root with:
|
|||||||
diff -u docs/vm-arch/ARCHITECTURE.md ../runtime/docs/vm-arch/ARCHITECTURE.md
|
diff -u docs/vm-arch/ARCHITECTURE.md ../runtime/docs/vm-arch/ARCHITECTURE.md
|
||||||
diff -u docs/vm-arch/ISA_CORE.md ../runtime/docs/vm-arch/ISA_CORE.md
|
diff -u docs/vm-arch/ISA_CORE.md ../runtime/docs/vm-arch/ISA_CORE.md
|
||||||
diff -u docs/vm-arch/INTRINSICS.csv ../runtime/docs/vm-arch/INTRINSICS.csv
|
diff -u docs/vm-arch/INTRINSICS.csv ../runtime/docs/vm-arch/INTRINSICS.csv
|
||||||
|
diff -u docs/vm-arch/BUILTIN_CONSTANTS.csv ../runtime/docs/vm-arch/BUILTIN_CONSTANTS.csv
|
||||||
```
|
```
|
||||||
|
|
||||||
All three commands MUST exit successfully with no output before a change claims
|
All four commands MUST exit successfully with no output before a change claims
|
||||||
that the mirrors are synchronized. If the runtime repository is not available
|
that the mirrors are synchronized. If the runtime repository is not available
|
||||||
in the same checkout, synchronization evidence must be produced against the
|
in the same checkout, synchronization evidence must be produced against the
|
||||||
canonical runtime revision before merging.
|
canonical runtime revision before merging.
|
||||||
@@ -30,3 +32,24 @@ Compiler-owned transformation contracts remain under `docs/specs/compiler`.
|
|||||||
Those specifications define `IRBackend -> IRVM -> PBX` emission, but they MUST
|
Those specifications define `IRBackend -> IRVM -> PBX` emission, but they MUST
|
||||||
conform to the runtime-owned PBX and ISA contracts and MUST NOT redefine runtime
|
conform to the runtime-owned PBX and ISA contracts and MUST NOT redefine runtime
|
||||||
execution semantics.
|
execution semantics.
|
||||||
|
|
||||||
|
## Catalog provenance
|
||||||
|
|
||||||
|
`runtime-catalog.properties` identifies the selected provider revision and hashes
|
||||||
|
of both CSVs. The compiler and PBS SDK package these artifacts with their own
|
||||||
|
resource namespaces. Catalog synchronization alone does not claim the other
|
||||||
|
architecture mirrors are synchronized or that all PBS facades are implemented.
|
||||||
|
|
||||||
|
Run the explicit source/exporter verification from the Studio root:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
python3 tools/runtime-catalog/verify.py --runtime ../runtime
|
||||||
|
```
|
||||||
|
|
||||||
|
This command requires a clean checkout of the recorded provider revision, compares
|
||||||
|
committed bytes and hashes, and runs its real catalog exporter parity test with
|
||||||
|
build output in a temporary directory. Missing or different evidence sources fail
|
||||||
|
explicitly. Ordinary builds and local catalog tests never invoke this command.
|
||||||
|
|
||||||
|
The manual port and consumer requirements are defined in
|
||||||
|
[Runtime catalog support](../compiler/general/specs/runtime-catalog-support.md).
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
runtime.revision=f7d7c167531bb662a1af9d73fc326bb476bf8aa7
|
||||||
|
INTRINSICS.csv.sha256=0c1bb78a9b81d1e3480ef5713f3d70f0b06772a7dfab2fd00c1f0a6364f98daa
|
||||||
|
BUILTIN_CONSTANTS.csv.sha256=e407e4718127aa7ef7b1097b5b4b67d86dd979235e73a551a7c36b628cddc039
|
||||||
Vendored
+11
-6
@@ -27,17 +27,22 @@ pipeline {
|
|||||||
--no-daemon
|
--no-daemon
|
||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
junit testResults: '**/build/test-results/test/TEST-*.xml'
|
||||||
|
}
|
||||||
|
withChecks(name: 'JaCoCo Coverage', includeStage: false) {
|
||||||
recordCoverage(tools: [[parser: 'JACOCO', pattern: "build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml"]],
|
recordCoverage(tools: [[parser: 'JACOCO', pattern: "build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml"]],
|
||||||
id: 'jacoco',
|
id: 'jacoco',
|
||||||
name: 'JaCoCo Coverage',
|
name: 'JaCoCo Coverage',
|
||||||
|
checksName: 'JaCoCo Coverage',
|
||||||
|
sourceDirectories: [[path: 'glob:**/src/main/java']],
|
||||||
|
sourceCodeEncoding: 'UTF-8',
|
||||||
sourceCodeRetention: 'EVERY_BUILD',
|
sourceCodeRetention: 'EVERY_BUILD',
|
||||||
qualityGates: [
|
qualityGates: [
|
||||||
[threshold: 50.0, metric: 'CLASS', baseline: 'PROJECT', unstable: true],
|
[threshold: 50.0, metric: 'CLASS', baseline: 'PROJECT', criticality: 'UNSTABLE'],
|
||||||
[threshold: 50.0, metric: 'METHOD', baseline: 'PROJECT', unstable: true],
|
[threshold: 50.0, metric: 'METHOD', baseline: 'PROJECT', criticality: 'UNSTABLE'],
|
||||||
[threshold: 50.0, metric: 'LINE', baseline: 'PROJECT', unstable: true],
|
[threshold: 50.0, metric: 'LINE', baseline: 'PROJECT', criticality: 'UNSTABLE'],
|
||||||
[threshold: 50.0, metric: 'INSTRUCTION', baseline: 'PROJECT', unstable: true],
|
[threshold: 50.0, metric: 'INSTRUCTION', baseline: 'PROJECT', criticality: 'UNSTABLE'],
|
||||||
[threshold: 40.0, metric: 'BRANCH', baseline: 'PROJECT', unstable: true]])
|
[threshold: 40.0, metric: 'BRANCH', baseline: 'PROJECT', criticality: 'UNSTABLE']])
|
||||||
junit testResults: '**/build/test-results/test/TEST-*.xml'
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // Test
|
} // Test
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ spring-boot = "3.5.16"
|
|||||||
spring-modulith = "1.4.13"
|
spring-modulith = "1.4.13"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
|
tomlj = { group = "org.tomlj", name = "tomlj", version = "1.1.1" }
|
||||||
javafx-controls = { group = "org.openjfx", name = "javafx-controls", version.ref = "javafx" }
|
javafx-controls = { group = "org.openjfx", name = "javafx-controls", version.ref = "javafx" }
|
||||||
javafx-fxml = { group = "org.openjfx", name = "javafx-fxml", version.ref = "javafx" }
|
javafx-fxml = { group = "org.openjfx", name = "javafx-fxml", version.ref = "javafx" }
|
||||||
richtextfx = { group = "org.fxmisc.richtext", name = "richtextfx", version.ref = "richtextfx" }
|
richtextfx = { group = "org.fxmisc.richtext", name = "richtextfx", version.ref = "richtextfx" }
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
implementation(libs.tomlj)
|
||||||
implementation(project(":prometeu-infra"))
|
implementation(project(":prometeu-infra"))
|
||||||
implementation(project(":prometeu-lsp:prometeu-lsp-api"))
|
implementation(project(":prometeu-lsp:prometeu-lsp-api"))
|
||||||
implementation(project(":prometeu-lsp:prometeu-lsp-v1"))
|
implementation(project(":prometeu-lsp:prometeu-lsp-v1"))
|
||||||
@@ -26,6 +27,36 @@ application {
|
|||||||
mainClass = "p.studio.app.StudioLauncher"
|
mainClass = "p.studio.app.StudioLauncher"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val studioJava = javaToolchains.launcherFor { languageVersion = JavaLanguageVersion.of(21) }
|
||||||
|
val studioRuntime = layout.buildDirectory.dir("studio-runtime")
|
||||||
|
val assembleStudioRuntime by tasks.registering(Exec::class) {
|
||||||
|
val jdk = studioJava.get().metadata.installationPath.asFile
|
||||||
|
inputs.property("jdk", jdk.absolutePath)
|
||||||
|
outputs.dir(studioRuntime)
|
||||||
|
doFirst { delete(studioRuntime) }
|
||||||
|
// jlink license files can be read-only; Gradle Sync must be able to refresh the installed image.
|
||||||
|
doLast {
|
||||||
|
studioRuntime.get().asFile.walkTopDown().filter { it.isFile }.forEach {
|
||||||
|
check(it.setWritable(true, true)) { "Cannot normalize staged runtime permissions" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
commandLine(jdk.resolve("bin/jlink"), "--add-modules", "ALL-MODULE-PATH", "--strip-debug", "--no-header-files",
|
||||||
|
"--no-man-pages", "--output", studioRuntime.get().asFile)
|
||||||
|
}
|
||||||
|
distributions {
|
||||||
|
main { contents { from(assembleStudioRuntime) { into("runtime") } } }
|
||||||
|
}
|
||||||
|
tasks.register<JavaExec>("stageStudioInstallation") {
|
||||||
|
group = "application"
|
||||||
|
description = "Stages and validates the bundled Studio/Java installation; no project launcher is created."
|
||||||
|
dependsOn(tasks.named("installDist"))
|
||||||
|
classpath = sourceSets["main"].runtimeClasspath
|
||||||
|
mainClass = "p.studio.app.install.ManagedStudioInstallation"
|
||||||
|
args(layout.buildDirectory.dir("install/prometeu-app").get().asFile.absolutePath,
|
||||||
|
providers.gradleProperty("studioInstallationRoot").getOrElse(
|
||||||
|
"${System.getProperty("user.home")}/Library/Application Support/Prometeu/Studio"))
|
||||||
|
}
|
||||||
|
|
||||||
javafx {
|
javafx {
|
||||||
version = libs.versions.javafx.get()
|
version = libs.versions.javafx.get()
|
||||||
modules("javafx.controls", "javafx.fxml")
|
modules("javafx.controls", "javafx.fxml")
|
||||||
@@ -77,3 +108,20 @@ tasks.register<Test>("headlessMcpDesktopTest") {
|
|||||||
systemProperty("java.awt.headless", "false")
|
systemProperty("java.awt.headless", "false")
|
||||||
systemProperty("studio.test.runtimeInstall", providers.gradleProperty("studioRuntimeInstall").getOrElse(""))
|
systemProperty("studio.test.runtimeInstall", providers.gradleProperty("studioRuntimeInstall").getOrElse(""))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Subprocess tests exercise the actual Studio main and OS ownership boundaries.
|
||||||
|
tasks.withType<Test>().configureEach {
|
||||||
|
systemProperty("studio.test.classpath", sourceSets["test"].runtimeClasspath.asPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.named<Test>("test") { exclude("**/InstalledConnectorTest.class") }
|
||||||
|
tasks.register<Test>("installedConnectorTest") {
|
||||||
|
group = "verification"
|
||||||
|
description = "Validates installed Java, stable updates, project preparation and JavaFX startup (requires a display)."
|
||||||
|
dependsOn(tasks.named("installDist"))
|
||||||
|
testClassesDirs = sourceSets["test"].output.classesDirs
|
||||||
|
classpath = sourceSets["test"].runtimeClasspath
|
||||||
|
useJUnitPlatform()
|
||||||
|
include("**/InstalledConnectorTest.class")
|
||||||
|
systemProperty("studio.test.distribution", layout.buildDirectory.dir("install/prometeu-app").get().asFile.absolutePath)
|
||||||
|
}
|
||||||
|
|||||||
@@ -230,13 +230,16 @@ public class StudioApplicationConfiguration {
|
|||||||
@Bean(destroyMethod = "close")
|
@Bean(destroyMethod = "close")
|
||||||
DefaultProjectSessionFactory projectSessionFactory(ProjectLocalStudioStateStore stateStore,
|
DefaultProjectSessionFactory projectSessionFactory(ProjectLocalStudioStateStore stateStore,
|
||||||
ProjectLocalStudioSetupStore setupStore, LspLifecyclePort lsp,
|
ProjectLocalStudioSetupStore setupStore, LspLifecyclePort lsp,
|
||||||
p.studio.core.project.ProjectAccessRegistry access, OperationExecutor operations) {
|
p.studio.core.project.ProjectAccessRegistry access, OperationExecutor operations,
|
||||||
return new DefaultProjectSessionFactory(stateStore, setupStore, lsp, access, operations);
|
p.studio.api.automation.AutomationConnectionLifecycle connections,
|
||||||
|
p.studio.api.automation.AgentIntegrationPreparation preparation) {
|
||||||
|
return new DefaultProjectSessionFactory(stateStore, setupStore, lsp, access, operations, connections, preparation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
ProjectCatalog projectCatalog(ObjectMapper mapper, ProjectLocalStudioSetupStore setupStore) {
|
ProjectCatalog projectCatalog(ObjectMapper mapper, ProjectLocalStudioSetupStore setupStore,
|
||||||
return new ProjectCatalogService(resolveDefaultProjectsRoot(), mapper, setupStore);
|
p.studio.api.automation.AgentIntegrationPreparation preparation) {
|
||||||
|
return new ProjectCatalogService(resolveDefaultProjectsRoot(), mapper, setupStore, preparation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@@ -340,10 +343,19 @@ public class StudioApplicationConfiguration {
|
|||||||
return new p.studio.app.mcp.LocalMcpServer(mapper, tools);
|
return new p.studio.app.mcp.LocalMcpServer(mapper, tools);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
p.studio.api.automation.AutomationConnectionLifecycle connectionLifecycle(p.studio.app.mcp.LocalMcpServer server, ObjectMapper mapper) {
|
||||||
|
return new p.studio.app.mcp.ProjectConnectionPublisher(server, mapper);
|
||||||
|
}
|
||||||
|
@Bean
|
||||||
|
p.studio.api.automation.AgentIntegrationPreparation agentPreparation(ObjectMapper mapper) {
|
||||||
|
return new p.studio.app.mcp.StudioAgentPreparation(p.studio.app.install.ManagedStudioInstallation.defaultRoot(), mapper);
|
||||||
|
}
|
||||||
@Bean
|
@Bean
|
||||||
p.studio.api.automation.AgentConnectionGuide connectionGuide(p.studio.app.mcp.LocalMcpServer server,
|
p.studio.api.automation.AgentConnectionGuide connectionGuide(p.studio.app.mcp.LocalMcpServer server,
|
||||||
p.studio.core.project.ProjectAccessRegistry projects, ObjectMapper mapper) {
|
p.studio.core.project.ProjectAccessRegistry projects, ObjectMapper mapper,
|
||||||
return new p.studio.app.mcp.McpConnectionGuide(server, projects, mapper);
|
p.studio.api.automation.AgentIntegrationPreparation preparation) {
|
||||||
|
return new p.studio.app.mcp.McpConnectionGuide(server, projects, mapper, preparation);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Path resolveDefaultProjectsRoot() {
|
private static Path resolveDefaultProjectsRoot() {
|
||||||
|
|||||||
@@ -7,6 +7,11 @@ public final class StudioLauncher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
if (args.length > 0 && "mcp".equals(args[0])) {
|
||||||
|
try { p.studio.app.mcp.stdio.StudioMcpStdio.main(args); }
|
||||||
|
catch (Exception failure) { System.err.println("Studio MCP could not start. Check --project, the manifest and installation."); System.exit(1); }
|
||||||
|
return;
|
||||||
|
}
|
||||||
Application.launch(App.class, args);
|
Application.launch(App.class, args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package p.studio.app.install;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/** One versioned application installation; client entries always refer to current. */
|
||||||
|
public final class ManagedStudioInstallation {
|
||||||
|
public static final class MissingInstallation extends IOException {
|
||||||
|
public MissingInstallation() {
|
||||||
|
super("Studio installation is missing. In the Studio checkout, run ./gradlew :prometeu-app:stageStudioInstallation, then prepare the assistant again. If using an isolated installation, set -Dstudio.installationRoot to that installation in the desktop VM options.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private ManagedStudioInstallation() { }
|
||||||
|
public static Path defaultRoot() {
|
||||||
|
return Path.of(System.getProperty("studio.installationRoot", Path.of(System.getProperty("user.home"),
|
||||||
|
"Library", "Application Support", "Prometeu", "Studio").toString())).toAbsolutePath();
|
||||||
|
}
|
||||||
|
public static void ensureAvailable(Path base) throws Exception {
|
||||||
|
if (Files.isExecutable(base.resolve("current/runtime/bin/java")) && Files.isDirectory(base.resolve("current/lib"))) return;
|
||||||
|
Path location = Path.of(ManagedStudioInstallation.class.getProtectionDomain().getCodeSource().getLocation().toURI());
|
||||||
|
if (!Files.isRegularFile(location) || !Files.isDirectory(location.getParent().getParent().resolve("runtime")))
|
||||||
|
throw new MissingInstallation();
|
||||||
|
install(location.getParent().getParent(), base);
|
||||||
|
}
|
||||||
|
public static synchronized Path install(Path source, Path base) throws Exception {
|
||||||
|
source = source.toRealPath(); Files.createDirectories(base.resolve("versions"));
|
||||||
|
Path version = base.resolve("versions").resolve(UUID.randomUUID().toString());
|
||||||
|
Files.createDirectory(version);
|
||||||
|
for (String part : List.of("lib", "runtime")) {
|
||||||
|
if (!Files.isDirectory(source.resolve(part))) throw new IOException("Incomplete Studio distribution");
|
||||||
|
try (var paths = Files.walk(source.resolve(part))) {
|
||||||
|
for (Path from : paths.toList()) {
|
||||||
|
Path to = version.resolve(source.relativize(from));
|
||||||
|
if (Files.isDirectory(from)) Files.createDirectories(to);
|
||||||
|
else Files.copy(from, to, StandardCopyOption.COPY_ATTRIBUTES);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var process = new ProcessBuilder(version.resolve("runtime/bin/java").toString(), "-cp", version.resolve("lib/*").toString(),
|
||||||
|
"p.studio.app.install.StudioInstallationProbe").redirectError(ProcessBuilder.Redirect.DISCARD).redirectOutput(ProcessBuilder.Redirect.DISCARD).start();
|
||||||
|
if (!process.waitFor(30, TimeUnit.SECONDS)) { process.destroyForcibly(); throw new IOException("Installation validation timed out"); }
|
||||||
|
if (process.exitValue() != 0) throw new IOException("Installation validation failed");
|
||||||
|
Path link = base.resolve(".current-" + UUID.randomUUID());
|
||||||
|
try { Files.createSymbolicLink(link, base.toAbsolutePath().relativize(version.toAbsolutePath()));
|
||||||
|
Files.move(link, base.resolve("current"), StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
} finally { Files.deleteIfExists(link); }
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
if (args.length != 2) throw new IllegalArgumentException("distribution and installation root required");
|
||||||
|
install(Path.of(args[0]), Path.of(args[1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package p.studio.app.install;
|
||||||
|
|
||||||
|
/** Packaging health check; it never starts the GUI or opens projects. */
|
||||||
|
public final class StudioInstallationProbe {
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
var catalog = new p.studio.app.mcp.McpToolCatalog(new com.fasterxml.jackson.databind.ObjectMapper());
|
||||||
|
if (catalog.names().isEmpty()) throw new IllegalStateException("Missing catalog");
|
||||||
|
for (String type : java.util.List.of("javafx.application.Application", "javafx.fxml.FXMLLoader",
|
||||||
|
"p.studio.app.App", "java.net.http.HttpClient", "com.sun.net.httpserver.HttpServer", "org.tomlj.Toml"))
|
||||||
|
Class.forName(type, false, StudioInstallationProbe.class.getClassLoader());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,8 @@ import p.studio.api.automation.*;
|
|||||||
import p.studio.api.project.ProjectCatalog;
|
import p.studio.api.project.ProjectCatalog;
|
||||||
import p.studio.core.language.LanguageQueryPort;
|
import p.studio.core.language.LanguageQueryPort;
|
||||||
import p.studio.lsp.api.LspServerLifecycle;
|
import p.studio.lsp.api.LspServerLifecycle;
|
||||||
|
import p.studio.lsp.services.protocol.ExternalSourceLanguageServer;
|
||||||
|
import org.eclipse.lsp4j.jsonrpc.Launcher;
|
||||||
|
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.nio.file.*;
|
import java.nio.file.*;
|
||||||
@@ -24,7 +26,7 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
|||||||
private final ObjectMapper mapper;
|
private final ObjectMapper mapper;
|
||||||
private final com.google.gson.Gson gson = new MessageJsonHandler(Map.of()).getGson();
|
private final com.google.gson.Gson gson = new MessageJsonHandler(Map.of()).getGson();
|
||||||
private final Map<TaskIdentity, Map<String, CallHierarchyItem>> items = new ConcurrentHashMap<>();
|
private final Map<TaskIdentity, Map<String, CallHierarchyItem>> items = new ConcurrentHashMap<>();
|
||||||
private static final Set<String> OPERATIONS = Set.of("diagnostics", "completion", "hover", "signatureHelp", "definition",
|
private static final Set<String> OPERATIONS = Set.of("readExternalSource", "diagnostics", "completion", "hover", "signatureHelp", "definition",
|
||||||
"references", "documentSymbols", "workspaceSymbols", "prepareRename", "rename", "codeActions", "formatting",
|
"references", "documentSymbols", "workspaceSymbols", "prepareRename", "rename", "codeActions", "formatting",
|
||||||
"documentLinks", "foldingRanges", "selectionRanges", "prepareCallHierarchy", "incomingCalls", "outgoingCalls", "semanticTokens");
|
"documentLinks", "foldingRanges", "selectionRanges", "prepareCallHierarchy", "incomingCalls", "outgoingCalls", "semanticTokens");
|
||||||
private static final Set<String> EDITS = Set.of("completion", "prepareRename", "rename", "codeActions", "formatting");
|
private static final Set<String> EDITS = Set.of("completion", "prepareRename", "rename", "codeActions", "formatting");
|
||||||
@@ -33,7 +35,47 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
|||||||
this.lifecycle = lifecycle; this.projects = projects; this.knowledge = knowledge; this.mapper = mapper;
|
this.lifecycle = lifecycle; this.projects = projects; this.knowledge = knowledge; this.mapper = mapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void endTask(TaskIdentity task) { items.remove(task); }
|
private record ExternalTask(String consumer, p.studio.lsp.messages.LspServerEndpoint endpoint,
|
||||||
|
p.studio.lsp.messages.LspProjectContext binding, Set<String> uris) {}
|
||||||
|
private final Map<TaskIdentity, ExternalTask> externalTasks = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
@Override public void endTask(TaskIdentity task) {
|
||||||
|
items.remove(task);
|
||||||
|
final var state = externalTasks.remove(task);
|
||||||
|
if (state == null) return;
|
||||||
|
final var workers = Executors.newCachedThreadPool();
|
||||||
|
try (var socket = new Socket()) {
|
||||||
|
socket.connect(new InetSocketAddress(state.endpoint().host(), state.endpoint().port()), 2000);
|
||||||
|
final var client = new QuietClient();
|
||||||
|
final var launcher = new Launcher.Builder<ExternalSourceLanguageServer>().setLocalService(client)
|
||||||
|
.setRemoteInterface(ExternalSourceLanguageServer.class).setInput(socket.getInputStream())
|
||||||
|
.setOutput(socket.getOutputStream()).setExecutorService(workers).create();
|
||||||
|
final var listening = launcher.startListening();
|
||||||
|
try {
|
||||||
|
final var server = launcher.getRemoteProxy();
|
||||||
|
final var init = new InitializeParams();
|
||||||
|
init.setRootUri(state.binding().projectRoot().toUri().toString());
|
||||||
|
init.setCapabilities(new ClientCapabilities());
|
||||||
|
init.getCapabilities().setExperimental(Map.of("prometeuExternalSources", true));
|
||||||
|
init.setInitializationOptions(Map.of("prometeuExternalConsumerId", state.consumer()));
|
||||||
|
server.initialize(init).get(2, TimeUnit.SECONDS);
|
||||||
|
server.releaseExternalSource(new ExternalSourceLanguageServer.Request(state.consumer(), null)).get(2, TimeUnit.SECONDS);
|
||||||
|
} finally { listening.cancel(true); }
|
||||||
|
} catch (Exception failure) {
|
||||||
|
// A closed project host has already released its registry. Other cleanup
|
||||||
|
// failures are surfaced instead of silently reporting a successful task end.
|
||||||
|
if (lifecycle.endpoint(state.binding()).isPresent())
|
||||||
|
throw new IllegalStateException("Could not release task external sources", failure);
|
||||||
|
} finally { workers.shutdownNow(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class QuietClient implements LanguageClient {
|
||||||
|
public void telemetryEvent(Object event) {}
|
||||||
|
public void publishDiagnostics(PublishDiagnosticsParams event) {}
|
||||||
|
public void showMessage(MessageParams message) {}
|
||||||
|
public CompletableFuture<MessageActionItem> showMessageRequest(ShowMessageRequestParams request) { return CompletableFuture.completedFuture(null); }
|
||||||
|
public void logMessage(MessageParams message) {}
|
||||||
|
}
|
||||||
|
|
||||||
@Override public Map<String, Object> query(TaskIdentity task, String operation, Map<String, Object> parameters) throws Exception {
|
@Override public Map<String, Object> query(TaskIdentity task, String operation, Map<String, Object> parameters) throws Exception {
|
||||||
if (!OPERATIONS.contains(operation)) throw failure(AutomationFailure.Code.UNSUPPORTED_CAPABILITY, "Unsupported language operation: " + operation);
|
if (!OPERATIONS.contains(operation)) throw failure(AutomationFailure.Code.UNSUPPORTED_CAPABILITY, "Unsupported language operation: " + operation);
|
||||||
@@ -55,7 +97,15 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
|||||||
uri = params.path("uri").asText(null);
|
uri = params.path("uri").asText(null);
|
||||||
if (uri == null) throw new IllegalArgumentException("uri is required");
|
if (uri == null) throw new IllegalArgumentException("uri is required");
|
||||||
}
|
}
|
||||||
Path document = uri == null ? null : sourcePath(context, uri);
|
final boolean external = uri != null && uri.startsWith("prometeu-source:");
|
||||||
|
if (external) {
|
||||||
|
final var state = externalTasks.get(task);
|
||||||
|
if (state == null || !state.uris().contains(uri)) throw failure(AutomationFailure.Code.OUTSIDE_PROJECT_SCOPE, "Unknown task-owned external source");
|
||||||
|
if (EDITS.contains(operation)) throw failure(AutomationFailure.Code.READ_ONLY_SCOPE, "External sources are read-only");
|
||||||
|
if (!Set.of("readExternalSource", "hover", "definition").contains(operation))
|
||||||
|
throw failure(AutomationFailure.Code.UNSUPPORTED_CAPABILITY, "Operation is unavailable for external documents");
|
||||||
|
} else if (operation.equals("readExternalSource")) throw new IllegalArgumentException("An external source URI is required");
|
||||||
|
Path document = uri == null || external ? null : sourcePath(context, uri);
|
||||||
if (document != null && EDITS.contains(operation)) requireEditable(context, document.toUri().toString());
|
if (document != null && EDITS.contains(operation)) requireEditable(context, document.toUri().toString());
|
||||||
String source = null;
|
String source = null;
|
||||||
if (document != null) {
|
if (document != null) {
|
||||||
@@ -83,14 +133,28 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
|||||||
return CompletableFuture.completedFuture(new ApplyWorkspaceEditResponse(false));
|
return CompletableFuture.completedFuture(new ApplyWorkspaceEditResponse(false));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var launcher = LSPLauncher.createClientLauncher(client, socket.getInputStream(), socket.getOutputStream(), workers, consumer -> consumer);
|
var launcher = new Launcher.Builder<ExternalSourceLanguageServer>().setLocalService(client)
|
||||||
|
.setRemoteInterface(ExternalSourceLanguageServer.class).setInput(socket.getInputStream())
|
||||||
|
.setOutput(socket.getOutputStream()).setExecutorService(workers).create();
|
||||||
var listening = launcher.startListening();
|
var listening = launcher.startListening();
|
||||||
|
final var server = launcher.getRemoteProxy();
|
||||||
|
final var acquired = new HashSet<String>();
|
||||||
|
boolean succeeded = false;
|
||||||
try {
|
try {
|
||||||
var server = launcher.getRemoteProxy();
|
|
||||||
var initialize = new InitializeParams();
|
var initialize = new InitializeParams();
|
||||||
initialize.setRootUri(binding.projectRoot().toUri().toString());
|
initialize.setRootUri(binding.projectRoot().toUri().toString());
|
||||||
initialize.setCapabilities(new ClientCapabilities());
|
initialize.setCapabilities(new ClientCapabilities());
|
||||||
|
initialize.getCapabilities().setExperimental(Map.of("prometeuExternalSources", true));
|
||||||
|
final var previous = externalTasks.get(task);
|
||||||
|
initialize.setInitializationOptions(previous == null
|
||||||
|
? Map.of("prometeuExternalPersistentConsumer", true)
|
||||||
|
: Map.of("prometeuExternalConsumerId", previous.consumer(), "prometeuExternalPersistentConsumer", true));
|
||||||
var capabilities = await(server.initialize(initialize), deadline).getCapabilities();
|
var capabilities = await(server.initialize(initialize), deadline).getCapabilities();
|
||||||
|
final var experimental = gson.toJsonTree(capabilities.getExperimental());
|
||||||
|
if (experimental.isJsonObject() && experimental.getAsJsonObject().has("prometeuExternalConsumerId")) {
|
||||||
|
final String consumer = experimental.getAsJsonObject().get("prometeuExternalConsumerId").getAsString();
|
||||||
|
externalTasks.putIfAbsent(task, new ExternalTask(consumer, endpoint, binding, ConcurrentHashMap.newKeySet()));
|
||||||
|
}
|
||||||
server.initialized(new InitializedParams());
|
server.initialized(new InitializedParams());
|
||||||
requireCapability(operation, capabilities);
|
requireCapability(operation, capabilities);
|
||||||
List<Diagnostic> currentDiagnostics = List.of();
|
List<Diagnostic> currentDiagnostics = List.of();
|
||||||
@@ -99,9 +163,17 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
|||||||
server.getTextDocumentService().didOpen(new DidOpenTextDocumentParams(new TextDocumentItem(uri, primary.id(), 1, source)));
|
server.getTextDocumentService().didOpen(new DidOpenTextDocumentParams(new TextDocumentItem(uri, primary.id(), 1, source)));
|
||||||
currentDiagnostics = await(diagnostics, deadline);
|
currentDiagnostics = await(diagnostics, deadline);
|
||||||
}
|
}
|
||||||
|
if (external) {
|
||||||
|
final var request = new ExternalSourceLanguageServer.Request(externalTasks.get(task).consumer(), uri);
|
||||||
|
source = await(server.revalidateExternalSource(request), deadline).text();
|
||||||
|
if (source.getBytes(java.nio.charset.StandardCharsets.UTF_8).length > 4 * 1024 * 1024)
|
||||||
|
throw failure(AutomationFailure.Code.LIMIT_EXCEEDED, "External source exceeds 4 MiB");
|
||||||
|
}
|
||||||
var text = server.getTextDocumentService();
|
var text = server.getTextDocumentService();
|
||||||
var id = uri == null ? null : new TextDocumentIdentifier(uri);
|
var id = uri == null ? null : new TextDocumentIdentifier(uri);
|
||||||
Object result = switch (operation) {
|
Object result = switch (operation) {
|
||||||
|
case "readExternalSource" -> await(server.readExternalSource(
|
||||||
|
new ExternalSourceLanguageServer.Request(externalTasks.get(task).consumer(), uri)), deadline);
|
||||||
case "diagnostics" -> currentDiagnostics;
|
case "diagnostics" -> currentDiagnostics;
|
||||||
case "hover" -> await(text.hover(new HoverParams(id, position(params.path("position"), source))), deadline);
|
case "hover" -> await(text.hover(new HoverParams(id, position(params.path("position"), source))), deadline);
|
||||||
case "completion" -> await(text.completion(new CompletionParams(id, position(params.path("position"), source))), deadline);
|
case "completion" -> await(text.completion(new CompletionParams(id, position(params.path("position"), source))), deadline);
|
||||||
@@ -136,6 +208,17 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
|||||||
};
|
};
|
||||||
var wire = mapper.readTree(gson.toJson(result));
|
var wire = mapper.readTree(gson.toJson(result));
|
||||||
validateEdits(context, wire);
|
validateEdits(context, wire);
|
||||||
|
if (operation.equals("definition") && externalTasks.containsKey(task)) {
|
||||||
|
final var returned = new HashSet<String>();
|
||||||
|
rememberExternalUris(returned, wire);
|
||||||
|
acquired.addAll(returned);
|
||||||
|
acquired.removeAll(externalTasks.get(task).uris());
|
||||||
|
for (String externalUri : returned) {
|
||||||
|
await(server.retainExternalSource(new ExternalSourceLanguageServer.Request(
|
||||||
|
externalTasks.get(task).consumer(), externalUri)), deadline);
|
||||||
|
externalTasks.get(task).uris().add(externalUri);
|
||||||
|
}
|
||||||
|
}
|
||||||
var limitations = new ArrayList<String>();
|
var limitations = new ArrayList<String>();
|
||||||
if (operation.equals("codeActions") && wire.isArray()) {
|
if (operation.equals("codeActions") && wire.isArray()) {
|
||||||
for (var action : wire) if (action.has("command")) {
|
for (var action : wire) if (action.has("command")) {
|
||||||
@@ -147,11 +230,30 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
|||||||
var output = new LinkedHashMap<String, Object>();
|
var output = new LinkedHashMap<String, Object>();
|
||||||
output.put("operation", operation); output.put("result", mapper.convertValue(wire, Object.class));
|
output.put("operation", operation); output.put("result", mapper.convertValue(wire, Object.class));
|
||||||
output.put("limitations", limitations);
|
output.put("limitations", limitations);
|
||||||
|
succeeded = true;
|
||||||
return Collections.unmodifiableMap(output);
|
return Collections.unmodifiableMap(output);
|
||||||
} finally { listening.cancel(true); }
|
} finally {
|
||||||
|
if (!succeeded && !acquired.isEmpty() && externalTasks.containsKey(task)) {
|
||||||
|
final var state = externalTasks.get(task);
|
||||||
|
final boolean interrupted = Thread.interrupted();
|
||||||
|
try {
|
||||||
|
for (String acquiredUri : acquired) {
|
||||||
|
state.uris().remove(acquiredUri);
|
||||||
|
server.releaseExternalSource(new ExternalSourceLanguageServer.Request(state.consumer(), acquiredUri))
|
||||||
|
.get(500, TimeUnit.MILLISECONDS);
|
||||||
|
}
|
||||||
|
} finally { if (interrupted) Thread.currentThread().interrupt(); }
|
||||||
|
}
|
||||||
|
listening.cancel(true);
|
||||||
|
}
|
||||||
} finally { workers.shutdownNow(); }
|
} finally { workers.shutdownNow(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void rememberExternalUris(Set<String> uris, com.fasterxml.jackson.databind.JsonNode node) {
|
||||||
|
if (node.isObject() && node.path("uri").asText().startsWith("prometeu-source:")) uris.add(node.path("uri").asText());
|
||||||
|
if (node.isContainerNode()) node.forEach(child -> rememberExternalUris(uris, child));
|
||||||
|
}
|
||||||
|
|
||||||
private void addItemIds(TaskIdentity task, com.fasterxml.jackson.databind.JsonNode node) {
|
private void addItemIds(TaskIdentity task, com.fasterxml.jackson.databind.JsonNode node) {
|
||||||
if (node.isObject() && node.has("uri") && node.has("selectionRange") && node.has("name") && node.has("kind")) {
|
if (node.isObject() && node.has("uri") && node.has("selectionRange") && node.has("name") && node.has("kind")) {
|
||||||
var stored = items.computeIfAbsent(task, ignored -> new ConcurrentHashMap<>());
|
var stored = items.computeIfAbsent(task, ignored -> new ConcurrentHashMap<>());
|
||||||
@@ -163,6 +265,12 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void requireCapability(String operation, ServerCapabilities caps) {
|
private static void requireCapability(String operation, ServerCapabilities caps) {
|
||||||
|
if (operation.equals("readExternalSource")) {
|
||||||
|
final var raw = new com.google.gson.Gson().toJsonTree(caps.getExperimental());
|
||||||
|
if (!raw.isJsonObject() || !raw.getAsJsonObject().has("prometeuExternalSources"))
|
||||||
|
throw failure(AutomationFailure.Code.UNSUPPORTED_CAPABILITY, "LSP does not advertise external sources");
|
||||||
|
return;
|
||||||
|
}
|
||||||
Object capability = switch (operation) {
|
Object capability = switch (operation) {
|
||||||
case "diagnostics" -> caps.getTextDocumentSync();
|
case "diagnostics" -> caps.getTextDocumentSync();
|
||||||
case "hover" -> caps.getHoverProvider(); case "completion" -> caps.getCompletionProvider();
|
case "hover" -> caps.getHoverProvider(); case "completion" -> caps.getCompletionProvider();
|
||||||
@@ -233,6 +341,7 @@ public final class AutomationLspQueries implements LanguageQueryPort {
|
|||||||
catch (ExecutionException failure) {
|
catch (ExecutionException failure) {
|
||||||
if (failure.getCause() instanceof org.eclipse.lsp4j.jsonrpc.ResponseErrorException response) {
|
if (failure.getCause() instanceof org.eclipse.lsp4j.jsonrpc.ResponseErrorException response) {
|
||||||
int code = response.getResponseError().getCode();
|
int code = response.getResponseError().getCode();
|
||||||
|
if (code == -32010) throw failure(AutomationFailure.Code.READ_ONLY_SCOPE, response.getResponseError().getMessage());
|
||||||
if (code == -32602) throw new IllegalArgumentException("LSP rejected query parameters");
|
if (code == -32602) throw new IllegalArgumentException("LSP rejected query parameters");
|
||||||
if (code == -32601 || code == -32600)
|
if (code == -32601 || code == -32600)
|
||||||
throw failure(AutomationFailure.Code.UNSUPPORTED_CAPABILITY, response.getResponseError().getMessage());
|
throw failure(AutomationFailure.Code.UNSUPPORTED_CAPABILITY, response.getResponseError().getMessage());
|
||||||
|
|||||||
@@ -20,7 +20,22 @@ public final class LocalMcpServer implements AutoCloseable {
|
|||||||
private static final int MAX_CONNECTION_SESSIONS = 128;
|
private static final int MAX_CONNECTION_SESSIONS = 128;
|
||||||
private final ObjectMapper mapper;
|
private final ObjectMapper mapper;
|
||||||
private final McpToolRegistry tools;
|
private final McpToolRegistry tools;
|
||||||
private final Map<String, AtomicBoolean> sessions = new ConcurrentHashMap<>();
|
private record Session(ProjectCredentials.Credential credential, AtomicBoolean initialized, java.util.concurrent.atomic.AtomicLong lastSeen) { }
|
||||||
|
private final Map<String, Session> sessions = new ConcurrentHashMap<>();
|
||||||
|
private final ProjectCredentials credentials = new ProjectCredentials();
|
||||||
|
private volatile String instanceId;
|
||||||
|
public ProjectCredentials credentials() { return credentials; }
|
||||||
|
public String instanceId() { return instanceId; }
|
||||||
|
public synchronized void activateCredential(String instance, ProjectCredentials.Credential credential) {
|
||||||
|
if (server == null || !Objects.equals(instanceId, instance)) throw new IllegalStateException("Studio instance changed");
|
||||||
|
credential.activate();
|
||||||
|
}
|
||||||
|
public String catalogFingerprint() { return tools.catalogFingerprint(); }
|
||||||
|
public boolean connected(java.nio.file.Path root) {
|
||||||
|
long now = System.nanoTime();
|
||||||
|
return sessions.values().stream().anyMatch(s -> s.initialized.get() && s.credential.active() && s.credential.root().equals(root)
|
||||||
|
&& now - s.lastSeen.get() < TimeUnit.SECONDS.toNanos(10));
|
||||||
|
}
|
||||||
private final SecureRandom random = new SecureRandom();
|
private final SecureRandom random = new SecureRandom();
|
||||||
private HttpServer server;
|
private HttpServer server;
|
||||||
private ExecutorService executor;
|
private ExecutorService executor;
|
||||||
@@ -42,7 +57,8 @@ public final class LocalMcpServer implements AutoCloseable {
|
|||||||
this.tools = Objects.requireNonNull(tools);
|
this.tools = Objects.requireNonNull(tools);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void start() throws IOException {
|
public void start() throws IOException {
|
||||||
|
synchronized (this) {
|
||||||
if (server != null) return;
|
if (server != null) return;
|
||||||
// No configurable bind address: remote and wildcard exposure cannot be enabled accidentally.
|
// No configurable bind address: remote and wildcard exposure cannot be enabled accidentally.
|
||||||
var next = HttpServer.create(new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 0), 32);
|
var next = HttpServer.create(new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 0), 32);
|
||||||
@@ -50,38 +66,41 @@ public final class LocalMcpServer implements AutoCloseable {
|
|||||||
Thread.ofPlatform().daemon().name("studio-mcp-", 1).factory(), new ThreadPoolExecutor.AbortPolicy());
|
Thread.ofPlatform().daemon().name("studio-mcp-", 1).factory(), new ThreadPoolExecutor.AbortPolicy());
|
||||||
var timers = Executors.newSingleThreadScheduledExecutor(Thread.ofPlatform().daemon().name("studio-mcp-deadlines").factory());
|
var timers = Executors.newSingleThreadScheduledExecutor(Thread.ofPlatform().daemon().name("studio-mcp-deadlines").factory());
|
||||||
try {
|
try {
|
||||||
connection = new Connection(URI.create("http://127.0.0.1:" + next.getAddress().getPort() + "/mcp"), secret());
|
instanceId = UUID.randomUUID().toString();
|
||||||
|
connection = new Connection(URI.create("http://127.0.0.1:" + next.getAddress().getPort() + "/mcp"));
|
||||||
deadlines = timers;
|
deadlines = timers;
|
||||||
next.createContext("/mcp", this::handle);
|
next.createContext("/mcp", this::handle);
|
||||||
next.setExecutor(workers);
|
next.setExecutor(workers);
|
||||||
next.start();
|
next.start();
|
||||||
|
timers.scheduleWithFixedDelay(() -> connectionListeners.forEach(LocalMcpServer::notifyConnectionListener), 2, 2, TimeUnit.SECONDS);
|
||||||
executor = workers; server = next;
|
executor = workers; server = next;
|
||||||
connectionListeners.forEach(LocalMcpServer::notifyConnectionListener);
|
|
||||||
} catch (RuntimeException failure) {
|
} catch (RuntimeException failure) {
|
||||||
next.stop(0); workers.shutdownNow(); timers.shutdownNow(); connection = null;
|
next.stop(0); workers.shutdownNow(); timers.shutdownNow(); connection = null;
|
||||||
throw failure;
|
throw failure;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
connectionListeners.forEach(LocalMcpServer::notifyConnectionListener);
|
||||||
|
}
|
||||||
public Connection connection() {
|
public Connection connection() {
|
||||||
var current = connection;
|
var current = connection;
|
||||||
if (current == null) throw new IllegalStateException("MCP is not running");
|
if (current == null) throw new IllegalStateException("MCP is not running");
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
public synchronized boolean isRunning() { return server != null; }
|
public synchronized boolean isRunning() { return server != null; }
|
||||||
@Override public synchronized void close() {
|
@Override public void close() {
|
||||||
|
synchronized (this) {
|
||||||
if (server == null) return;
|
if (server == null) return;
|
||||||
connection = null; server.stop(0); server = null;
|
connection = null; server.stop(0); server = null;
|
||||||
sessions.clear(); executor.shutdownNow(); deadlines.shutdownNow();
|
sessions.clear(); credentials.clear(); executor.shutdownNow(); deadlines.shutdownNow();
|
||||||
|
}
|
||||||
connectionListeners.forEach(LocalMcpServer::notifyConnectionListener);
|
connectionListeners.forEach(LocalMcpServer::notifyConnectionListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Only explicit connection/configuration consumers may obtain the bearer token; never log it. */
|
/** Public endpoint metadata contains no credential. */
|
||||||
public static final class Connection {
|
public static final class Connection {
|
||||||
private final URI endpoint;
|
private final URI endpoint;
|
||||||
private final String token;
|
private Connection(URI endpoint) { this.endpoint = endpoint; }
|
||||||
private Connection(URI endpoint, String token) { this.endpoint = endpoint; this.token = token; }
|
|
||||||
public URI endpoint() { return endpoint; }
|
public URI endpoint() { return endpoint; }
|
||||||
public String authorizationHeader() { return "Bearer " + token; }
|
|
||||||
@Override public String toString() { return "LocalMcpConnection[endpoint=" + endpoint + ", credentials=REDACTED]"; }
|
@Override public String toString() { return "LocalMcpConnection[endpoint=" + endpoint + ", credentials=REDACTED]"; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,13 +120,17 @@ public final class LocalMcpServer implements AutoCloseable {
|
|||||||
|| !authority.equals(single(headers, "Host"))
|
|| !authority.equals(single(headers, "Host"))
|
||||||
|| origin != null && !("http://" + authority).equals(origin)) { empty(exchange, 403); return; }
|
|| origin != null && !("http://" + authority).equals(origin)) { empty(exchange, 403); return; }
|
||||||
String authorization = single(headers, "Authorization");
|
String authorization = single(headers, "Authorization");
|
||||||
if (authorization == null || !MessageDigest.isEqual(current.authorizationHeader().getBytes(StandardCharsets.UTF_8), authorization.getBytes(StandardCharsets.UTF_8))) {
|
var credential = credentials.authenticate(authorization);
|
||||||
|
if (credential == null) {
|
||||||
empty(exchange, 401); return;
|
empty(exchange, 401); return;
|
||||||
}
|
}
|
||||||
String version = single(headers, "MCP-Protocol-Version");
|
String version = single(headers, "MCP-Protocol-Version");
|
||||||
if (version != null && !PROTOCOL_VERSION.equals(version)) { empty(exchange, 400); return; }
|
if (version != null && !PROTOCOL_VERSION.equals(version)) { empty(exchange, 400); return; }
|
||||||
String sessionId = single(headers, "Mcp-Session-Id");
|
String sessionId = single(headers, "Mcp-Session-Id");
|
||||||
AtomicBoolean initialized = sessionId == null ? null : sessions.get(sessionId);
|
var session = sessionId == null ? null : sessions.get(sessionId);
|
||||||
|
if (session != null && session.credential != credential) { empty(exchange, 403); return; }
|
||||||
|
AtomicBoolean initialized = session == null ? null : session.initialized;
|
||||||
|
if (session != null) session.lastSeen.set(System.nanoTime());
|
||||||
if (sessionId != null && initialized == null) { empty(exchange, 404); return; }
|
if (sessionId != null && initialized == null) { empty(exchange, 404); return; }
|
||||||
String method = exchange.getRequestMethod();
|
String method = exchange.getRequestMethod();
|
||||||
if (method.equals("GET")) { exchange.getResponseHeaders().set("Allow", "POST, DELETE"); empty(exchange, 405); return; }
|
if (method.equals("GET")) { exchange.getResponseHeaders().set("Allow", "POST, DELETE"); empty(exchange, 405); return; }
|
||||||
@@ -148,14 +171,16 @@ public final class LocalMcpServer implements AutoCloseable {
|
|||||||
send(exchange, 400, error(id.isMissingNode() ? NullNode.instance : id, -32602, "Invalid initialization")); return;
|
send(exchange, 400, error(id.isMissingNode() ? NullNode.instance : id, -32602, "Invalid initialization")); return;
|
||||||
}
|
}
|
||||||
synchronized (sessions) {
|
synchronized (sessions) {
|
||||||
|
sessions.values().removeIf(s -> !s.credential.active());
|
||||||
if (sessions.size() >= MAX_CONNECTION_SESSIONS) { empty(exchange, 503); return; }
|
if (sessions.size() >= MAX_CONNECTION_SESSIONS) { empty(exchange, 503); return; }
|
||||||
sessionId = secret(); sessions.put(sessionId, new AtomicBoolean());
|
sessionId = secret(); sessions.put(sessionId, new Session(credential, new AtomicBoolean(), new java.util.concurrent.atomic.AtomicLong(System.nanoTime())));
|
||||||
}
|
}
|
||||||
exchange.getResponseHeaders().set("Mcp-Session-Id", sessionId);
|
exchange.getResponseHeaders().set("Mcp-Session-Id", sessionId);
|
||||||
var result = mapper.createObjectNode().put("protocolVersion", PROTOCOL_VERSION);
|
var result = mapper.createObjectNode().put("protocolVersion", PROTOCOL_VERSION);
|
||||||
result.putObject("capabilities").putObject("tools").put("listChanged", false);
|
result.putObject("capabilities").putObject("tools").put("listChanged", false);
|
||||||
result.putObject("serverInfo").put("name", "prometeu-studio-mcp").put("version", "1.0");
|
result.putObject("serverInfo").put("name", "prometeu-studio-mcp").put("version", "1.0");
|
||||||
result.put("instructions", McpConnectionGuide.INSTRUCTIONS);
|
result.put("instructions", McpConnectionGuide.INSTRUCTIONS);
|
||||||
|
result.putObject("_meta").put("instanceId", instanceId).put("projectRoot", credential.root().toString()).put("catalogFingerprint", tools.catalogFingerprint());
|
||||||
send(exchange, 200, response(id, result)); return;
|
send(exchange, 200, response(id, result)); return;
|
||||||
}
|
}
|
||||||
if (initialized == null) { empty(exchange, 400); return; }
|
if (initialized == null) { empty(exchange, 400); return; }
|
||||||
@@ -174,7 +199,18 @@ public final class LocalMcpServer implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
case "tools/call" -> {
|
case "tools/call" -> {
|
||||||
if (!params.path("name").isTextual()) throw new IllegalArgumentException("Missing tool name");
|
if (!params.path("name").isTextual()) throw new IllegalArgumentException("Missing tool name");
|
||||||
yield tools.call(params.get("name").asText(), params.get("arguments")).wire();
|
var arguments = params.get("arguments");
|
||||||
|
if (arguments == null || !arguments.path("projectRoot").isTextual()) throw new IllegalArgumentException("Missing root");
|
||||||
|
java.nio.file.Path requested;
|
||||||
|
try { requested = java.nio.file.Path.of(arguments.path("projectRoot").asText());
|
||||||
|
if (!requested.isAbsolute()) throw new IllegalArgumentException("Relative root");
|
||||||
|
requested = requested.toRealPath();
|
||||||
|
} catch (java.io.IOException | RuntimeException invalid) { throw new IllegalArgumentException("Invalid root"); }
|
||||||
|
if (!credential.active() || !credential.root().equals(requested)) {
|
||||||
|
yield McpToolResult.failure(mapper, new p.studio.api.automation.AutomationFailure(
|
||||||
|
p.studio.api.automation.AutomationFailure.Code.OUTSIDE_PROJECT_SCOPE, "Connection is bound to another project or no longer authorized")).wire();
|
||||||
|
}
|
||||||
|
yield tools.call(params.get("name").asText(), arguments).wire();
|
||||||
}
|
}
|
||||||
default -> null;
|
default -> null;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,12 +7,11 @@ import p.studio.core.project.ProjectAccessRegistry;
|
|||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
/** Builds a provider-neutral connection descriptor from the live server, only on explicit export. */
|
/** Projects connection liveness and permanent setup independently of task authority. */
|
||||||
public final class McpConnectionGuide implements AgentConnectionGuide {
|
public final class McpConnectionGuide implements AgentConnectionGuide {
|
||||||
public static final String INSTRUCTIONS = """
|
public static final String INSTRUCTIONS = """
|
||||||
Configure your external coding client's MCP connection using the url and Authorization header below.
|
Use the Studio tools for this project. Wait for the developer to grant access in DEV, then acquire control.
|
||||||
This is a provider-neutral descriptor, not a provider-specific configuration file.
|
The installed Studio connector discovers the connection automatically; do not write transport scripts or copy tokens.
|
||||||
Keep the token private; do not commit this descriptor, write it into project files or include it in logs.
|
|
||||||
Connect and list available tools. Read studio_project_context for the explicit projectRoot and consult
|
Connect and list available tools. Read studio_project_context for the explicit projectRoot and consult
|
||||||
studio_reference_read for the declared languages, SDK and libraries before editing as needed.
|
studio_reference_read for the declared languages, SDK and libraries before editing as needed.
|
||||||
Do not assume PBS or another language when support/documentation is missing; report the limitation.
|
Do not assume PBS or another language when support/documentation is missing; report the limitation.
|
||||||
@@ -26,25 +25,42 @@ public final class McpConnectionGuide implements AgentConnectionGuide {
|
|||||||
Observe headless images/state when those tools are available, and explicitly studio_control_release
|
Observe headless images/state when those tools are available, and explicitly studio_control_release
|
||||||
when finished. On revocation stop external edits too: Studio cannot stop your native file writes.
|
when finished. On revocation stop external edits too: Studio cannot stop your native file writes.
|
||||||
Existing edits are preserved. Git/review/recovery remain the developer's responsibility.
|
Existing edits are preserved. Git/review/recovery remain the developer's responsibility.
|
||||||
Recopy and update your client's connection after Studio restart: endpoint and token are ephemeral.
|
After Studio restart, wait for a fresh human grant. The connector reconnects automatically; old task identities are invalid.
|
||||||
""";
|
""";
|
||||||
private final LocalMcpServer server;
|
private final LocalMcpServer server;
|
||||||
private final ProjectAccessRegistry projects;
|
private final ProjectAccessRegistry projects;
|
||||||
private final ObjectMapper mapper;
|
private final ObjectMapper mapper;
|
||||||
|
private final p.studio.api.automation.AgentIntegrationPreparation preparation;
|
||||||
public McpConnectionGuide(LocalMcpServer server, ProjectAccessRegistry projects, ObjectMapper mapper) {
|
public McpConnectionGuide(LocalMcpServer server, ProjectAccessRegistry projects, ObjectMapper mapper) {
|
||||||
this.server = server; this.projects = projects; this.mapper = mapper;
|
this(server, projects, mapper, new StudioAgentPreparation(p.studio.app.install.ManagedStudioInstallation.defaultRoot(), mapper));
|
||||||
}
|
}
|
||||||
|
public McpConnectionGuide(LocalMcpServer server, ProjectAccessRegistry projects, ObjectMapper mapper,
|
||||||
|
p.studio.api.automation.AgentIntegrationPreparation preparation) {
|
||||||
|
this.server = server; this.projects = projects; this.mapper = mapper; this.preparation = preparation;
|
||||||
|
}
|
||||||
|
@Override public boolean supportsPreparation() { return true; }
|
||||||
@Override public Optional<String> endpoint() {
|
@Override public Optional<String> endpoint() {
|
||||||
try { return Optional.of(server.connection().endpoint().toString()); }
|
try { return Optional.of(server.connection().endpoint().toString()); }
|
||||||
catch (IllegalStateException unavailable) { return Optional.empty(); }
|
catch (IllegalStateException unavailable) { return Optional.empty(); }
|
||||||
}
|
}
|
||||||
@Override public String configuration(Path root) {
|
@Override public String configuration(Path root) {
|
||||||
Path canonical = projects.requireOpenRoot(root);
|
Path canonical = projects.requireOpenRoot(root);
|
||||||
var live = server.connection();
|
return "Run the installed Studio in mcp --project mode for " + canonical + "\n" + INSTRUCTIONS;
|
||||||
var value = mapper.createObjectNode().put("transport", "streamable-http").put("url", live.endpoint().toString());
|
}
|
||||||
value.putObject("headers").put("Authorization", live.authorizationHeader());
|
@Override public p.studio.api.automation.AgentIntegrationPreparation.Result prepare(Path root) {
|
||||||
value.put("projectRoot", canonical.toString()).put("instructions", INSTRUCTIONS);
|
return preparation.prepare(projects.requireOpenRoot(root));
|
||||||
return value.toPrettyString();
|
}
|
||||||
|
@Override public p.studio.api.automation.AgentIntegrationPreparation.Result preparationStatus(Path root) {
|
||||||
|
return preparation.status(projects.requireOpenRoot(root));
|
||||||
|
}
|
||||||
|
@Override public State state(Path root) {
|
||||||
|
try {
|
||||||
|
Path canonical = projects.requireOpenRoot(root);
|
||||||
|
if (!server.isRunning()) return State.UNAVAILABLE;
|
||||||
|
if (server.connected(canonical)) return State.CONNECTED;
|
||||||
|
var control = projects.requireAutomation(canonical).snapshot().state();
|
||||||
|
return control == p.studio.api.automation.ControlState.AGENT_WORKING ? State.RECONNECTING : State.WAITING_FOR_ACCESS;
|
||||||
|
} catch (RuntimeException unavailable) { return State.UNAVAILABLE; }
|
||||||
}
|
}
|
||||||
@Override public OperationSubscription subscribe(Runnable changed) { return server.onConnectionChanged(changed); }
|
@Override public OperationSubscription subscribe(Runnable changed) { return server.onConnectionChanged(changed); }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,14 @@ public final class McpToolCatalog {
|
|||||||
} catch (IOException failure) { throw new IllegalStateException("Cannot read packaged MCP contract", failure); }
|
} catch (IOException failure) { throw new IllegalStateException("Cannot read packaged MCP contract", failure); }
|
||||||
}
|
}
|
||||||
public Set<String> names() { return definitions.keySet(); }
|
public Set<String> names() { return definitions.keySet(); }
|
||||||
|
public String fingerprint() {
|
||||||
|
try {
|
||||||
|
var digest = java.security.MessageDigest.getInstance("SHA-256");
|
||||||
|
digest.update(LocalMcpServer.PROTOCOL_VERSION.getBytes(java.nio.charset.StandardCharsets.UTF_8));
|
||||||
|
definitions.keySet().stream().sorted().forEach(name -> digest.update(descriptor(name).toString().getBytes(java.nio.charset.StandardCharsets.UTF_8)));
|
||||||
|
return java.util.HexFormat.of().formatHex(digest.digest());
|
||||||
|
} catch (java.security.NoSuchAlgorithmException impossible) { throw new IllegalStateException(impossible); }
|
||||||
|
}
|
||||||
public JsonNode definition(String name) {
|
public JsonNode definition(String name) {
|
||||||
var definition = definitions.get(name);
|
var definition = definitions.get(name);
|
||||||
if (definition == null) throw new IllegalArgumentException("Unknown tool");
|
if (definition == null) throw new IllegalArgumentException("Unknown tool");
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ public final class McpToolRegistry {
|
|||||||
catalog.names().stream().filter(handlers::containsKey).forEach(name -> descriptors.add(catalog.descriptor(name)));
|
catalog.names().stream().filter(handlers::containsKey).forEach(name -> descriptors.add(catalog.descriptor(name)));
|
||||||
return descriptors;
|
return descriptors;
|
||||||
}
|
}
|
||||||
|
public String catalogFingerprint() { return catalog.fingerprint(); }
|
||||||
public McpToolResult call(String name, JsonNode arguments) {
|
public McpToolResult call(String name, JsonNode arguments) {
|
||||||
var handler = handlers.get(name);
|
var handler = handlers.get(name);
|
||||||
if (handler == null) throw new IllegalArgumentException("Unknown or unavailable tool");
|
if (handler == null) throw new IllegalArgumentException("Unknown or unavailable tool");
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package p.studio.app.mcp;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.*;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.nio.file.*;
|
||||||
|
import java.nio.file.attribute.PosixFilePermissions;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import static java.nio.file.LinkOption.NOFOLLOW_LINKS;
|
||||||
|
|
||||||
|
/** Local discovery data is untrusted until paths, permissions and live identity are verified. */
|
||||||
|
public final class ProjectConnectionFiles {
|
||||||
|
public static final String RELATIVE = ".studio/mcp/connection.json";
|
||||||
|
private static final Set<java.nio.file.attribute.PosixFilePermission> FILE_MODE = PosixFilePermissions.fromString("rw-------");
|
||||||
|
private ProjectConnectionFiles() { }
|
||||||
|
public static Path directory(Path root) throws IOException {
|
||||||
|
Path studio = root.resolve(".studio"), directory = studio.resolve("mcp");
|
||||||
|
safeDirectory(studio, false); safeDirectory(directory, true); return directory;
|
||||||
|
}
|
||||||
|
private static void safeDirectory(Path path, boolean privateDirectory) throws IOException {
|
||||||
|
if (!Files.exists(path, NOFOLLOW_LINKS)) Files.createDirectory(path, PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rwx------")));
|
||||||
|
if (Files.isSymbolicLink(path) || !Files.isDirectory(path, NOFOLLOW_LINKS)) throw new IOException("Unsafe connection directory");
|
||||||
|
if (privateDirectory) requirePrivate(path, true);
|
||||||
|
}
|
||||||
|
public static void requirePrivate(Path path, boolean directory) throws IOException {
|
||||||
|
if (Files.isSymbolicLink(path) || !(directory ? Files.isDirectory(path, NOFOLLOW_LINKS) : Files.isRegularFile(path, NOFOLLOW_LINKS)))
|
||||||
|
throw new IOException("Unsafe connection file");
|
||||||
|
var expected = directory ? PosixFilePermissions.fromString("rwx------") : FILE_MODE;
|
||||||
|
if (!Files.getPosixFilePermissions(path, NOFOLLOW_LINKS).equals(expected)
|
||||||
|
|| !Files.getOwner(path, NOFOLLOW_LINKS).equals(Files.getOwner(Path.of(System.getProperty("user.home")))))
|
||||||
|
throw new IOException("Connection permissions must be restricted to the current user");
|
||||||
|
}
|
||||||
|
public static void atomicPrivateWrite(Path target, byte[] bytes) throws IOException {
|
||||||
|
if (Files.exists(target, NOFOLLOW_LINKS)) requirePrivate(target, false);
|
||||||
|
var temp = Files.createTempFile(target.getParent(), ".connection-", ".tmp", PosixFilePermissions.asFileAttribute(FILE_MODE));
|
||||||
|
try { Files.write(temp, bytes); Files.move(temp, target, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING); }
|
||||||
|
finally { Files.deleteIfExists(temp); }
|
||||||
|
}
|
||||||
|
public static boolean tracked(Path root, String relative) throws IOException {
|
||||||
|
try {
|
||||||
|
var process = new ProcessBuilder("git", "-C", root.toString(), "ls-files", "-z", "--", relative).redirectError(ProcessBuilder.Redirect.DISCARD).start();
|
||||||
|
if (!process.waitFor(5, TimeUnit.SECONDS)) { process.destroyForcibly(); throw new IOException("Git check timed out"); }
|
||||||
|
if (process.exitValue() != 0 && process.exitValue() != 128) throw new IOException("Cannot verify file tracking");
|
||||||
|
return process.getInputStream().read() != -1;
|
||||||
|
} catch (InterruptedException interrupted) { Thread.currentThread().interrupt(); throw new IOException("Git check interrupted"); }
|
||||||
|
}
|
||||||
|
public static void ignore(Path root, String relative) throws IOException {
|
||||||
|
Path path = root.resolve(".gitignore");
|
||||||
|
if (Files.isSymbolicLink(path)) throw new IOException("Unsafe ignore file");
|
||||||
|
String old = Files.exists(path) ? Files.readString(path) : "";
|
||||||
|
String rule = "/" + relative;
|
||||||
|
if (old.lines().anyMatch(rule::equals)) return;
|
||||||
|
Files.writeString(path, old + (old.isEmpty() || old.endsWith("\n") ? "" : "\n") + rule + "\n");
|
||||||
|
}
|
||||||
|
public static Descriptor read(Path root, ObjectMapper mapper) throws IOException {
|
||||||
|
Path path = root.resolve(RELATIVE);
|
||||||
|
if (Files.isSymbolicLink(root.resolve(".studio"))) throw new IOException("Unsafe discovery path");
|
||||||
|
requirePrivate(path.getParent(), true); requirePrivate(path, false);
|
||||||
|
byte[] bytes;
|
||||||
|
try (var input = Files.newInputStream(path, NOFOLLOW_LINKS)) { bytes = input.readNBytes(16 * 1024 + 1); }
|
||||||
|
if (bytes.length > 16 * 1024) throw new IOException("Connection descriptor too large");
|
||||||
|
var json = mapper.readTree(bytes);
|
||||||
|
if (json == null || !json.path("schemaVersion").isIntegralNumber() || !json.path("schemaVersion").canConvertToInt() || json.path("schemaVersion").asInt(-1) != 1) throw new IOException("Unsupported connection schema");
|
||||||
|
for (String field : Set.of("instanceId", "projectRoot", "endpoint", "credential", "catalogFingerprint"))
|
||||||
|
if (!json.path(field).isTextual() || json.path(field).asText().isBlank()) throw new IOException("Invalid connection descriptor");
|
||||||
|
try {
|
||||||
|
if (!Path.of(json.path("projectRoot").asText()).equals(root)) throw new IOException("Connection project mismatch");
|
||||||
|
URI endpoint = URI.create(json.path("endpoint").asText());
|
||||||
|
if (!"http".equals(endpoint.getScheme()) || !"127.0.0.1".equals(endpoint.getHost()) || endpoint.getPort() < 1
|
||||||
|
|| endpoint.getPort() > 65535 || !"/mcp".equals(endpoint.getRawPath()) || endpoint.getRawQuery() != null
|
||||||
|
|| endpoint.getRawFragment() != null || endpoint.getUserInfo() != null) throw new IOException("Invalid loopback endpoint");
|
||||||
|
return new Descriptor(endpoint, json.path("instanceId").asText(), json.path("credential").asText(), json.path("catalogFingerprint").asText());
|
||||||
|
} catch (IllegalArgumentException invalid) { throw new IOException("Invalid connection descriptor"); }
|
||||||
|
}
|
||||||
|
public record Descriptor(URI endpoint, String instanceId, String credential, String catalogFingerprint) {
|
||||||
|
@Override public String toString() { return "ProjectConnectionDescriptor[REDACTED]"; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package p.studio.app.mcp;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import p.studio.api.automation.AutomationConnectionLifecycle;
|
||||||
|
import java.nio.channels.*;
|
||||||
|
import java.nio.file.*;
|
||||||
|
import java.nio.file.attribute.PosixFilePermissions;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/** The lock inode outlives a publication. Its OS lock, not a stale PID/file, establishes ownership. */
|
||||||
|
public final class ProjectConnectionPublisher implements AutomationConnectionLifecycle {
|
||||||
|
private final LocalMcpServer server;
|
||||||
|
private final ObjectMapper mapper;
|
||||||
|
public ProjectConnectionPublisher(LocalMcpServer server, ObjectMapper mapper) { this.server = server; this.mapper = mapper; }
|
||||||
|
@Override public Publication prepare(Path projectRoot) throws Exception {
|
||||||
|
Path root = projectRoot.toRealPath();
|
||||||
|
final String instance = server.instanceId();
|
||||||
|
final var endpoint = server.connection().endpoint();
|
||||||
|
if (ProjectConnectionFiles.tracked(root, ProjectConnectionFiles.RELATIVE)) throw new IllegalStateException("Connection file is tracked");
|
||||||
|
ProjectConnectionFiles.ignore(root, ".studio/mcp/");
|
||||||
|
Path directory = ProjectConnectionFiles.directory(root), lockPath = directory.resolve("publication.lock");
|
||||||
|
if (Files.exists(lockPath, LinkOption.NOFOLLOW_LINKS)) ProjectConnectionFiles.requirePrivate(lockPath, false);
|
||||||
|
var channel = FileChannel.open(lockPath, Set.of(StandardOpenOption.CREATE, StandardOpenOption.WRITE, LinkOption.NOFOLLOW_LINKS),
|
||||||
|
PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rw-------")));
|
||||||
|
FileLock lock;
|
||||||
|
try { lock = channel.tryLock(); if (lock == null) throw new AutomationConnectionLifecycle.OwnershipConflict(); }
|
||||||
|
catch (OverlappingFileLockException conflict) { channel.close(); throw new AutomationConnectionLifecycle.OwnershipConflict(); }
|
||||||
|
catch (Exception conflict) { channel.close(); throw conflict; }
|
||||||
|
var credential = server.credentials().prepare(root);
|
||||||
|
return new Publication() {
|
||||||
|
private boolean published, closed;
|
||||||
|
public void publish() throws Exception {
|
||||||
|
var value = mapper.createObjectNode().put("schemaVersion", 1).put("instanceId", instance)
|
||||||
|
.put("projectRoot", root.toString()).put("endpoint", endpoint.toString())
|
||||||
|
.put("credential", credential.secret()).put("catalogFingerprint", server.catalogFingerprint());
|
||||||
|
ProjectConnectionFiles.atomicPrivateWrite(directory.resolve("connection.json"), mapper.writeValueAsBytes(value)); published = true;
|
||||||
|
}
|
||||||
|
public void activate() { server.activateCredential(instance, credential); }
|
||||||
|
public void invalidate() { credential.invalidate(); }
|
||||||
|
public synchronized void close() throws Exception {
|
||||||
|
if (closed) return; closed = true; invalidate();
|
||||||
|
try {
|
||||||
|
if (published && Files.exists(directory.resolve("connection.json"), LinkOption.NOFOLLOW_LINKS)) {
|
||||||
|
var current = ProjectConnectionFiles.read(root, mapper);
|
||||||
|
if (instance.equals(current.instanceId()) && credential.secret().equals(current.credential()))
|
||||||
|
Files.delete(directory.resolve("connection.json"));
|
||||||
|
}
|
||||||
|
} finally { try { lock.release(); } finally { channel.close(); } }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package p.studio.app.mcp;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
/** Memory-only authentication; never a substitute for the Core grant/task checks. */
|
||||||
|
public final class ProjectCredentials {
|
||||||
|
private final Map<String, Credential> credentials = new ConcurrentHashMap<>();
|
||||||
|
public Credential prepare(Path root) {
|
||||||
|
byte[] bytes = new byte[32]; new SecureRandom().nextBytes(bytes);
|
||||||
|
var credential = new Credential(root, Base64.getUrlEncoder().withoutPadding().encodeToString(bytes));
|
||||||
|
credentials.put(credential.secret, credential); return credential;
|
||||||
|
}
|
||||||
|
public Credential authenticate(String header) {
|
||||||
|
if (header == null || !header.startsWith("Bearer ")) return null;
|
||||||
|
String token = header.substring(7);
|
||||||
|
var found = credentials.get(token);
|
||||||
|
return found != null && found.active && MessageDigest.isEqual(token.getBytes(StandardCharsets.UTF_8),
|
||||||
|
found.secret.getBytes(StandardCharsets.UTF_8)) ? found : null;
|
||||||
|
}
|
||||||
|
public void clear() { credentials.values().forEach(Credential::invalidate); credentials.clear(); }
|
||||||
|
public final class Credential {
|
||||||
|
private final Path root;
|
||||||
|
private final String secret;
|
||||||
|
private volatile boolean active;
|
||||||
|
private boolean invalidated;
|
||||||
|
private Credential(Path root, String secret) { this.root = root; this.secret = secret; }
|
||||||
|
public Path root() { return root; }
|
||||||
|
public String secret() { return secret; }
|
||||||
|
public synchronized void activate() {
|
||||||
|
if (invalidated) throw new IllegalStateException("Credential invalidated");
|
||||||
|
active = true;
|
||||||
|
}
|
||||||
|
public synchronized void invalidate() { active = false; invalidated = true; credentials.remove(secret, this); }
|
||||||
|
public boolean active() { return active; }
|
||||||
|
@Override public String toString() { return "ProjectCredential[REDACTED]"; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
package p.studio.app.mcp;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import p.studio.api.automation.AgentIntegrationPreparation;
|
||||||
|
import p.studio.app.install.ManagedStudioInstallation;
|
||||||
|
import java.nio.file.*;
|
||||||
|
import java.nio.file.attribute.PosixFilePermissions;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.*;
|
||||||
|
import org.tomlj.Toml;
|
||||||
|
|
||||||
|
/** Only the managed entry is edited; unrelated client configuration remains byte-for-byte intact. */
|
||||||
|
public final class StudioAgentPreparation implements AgentIntegrationPreparation {
|
||||||
|
private final Path installation;
|
||||||
|
private final ObjectMapper mapper;
|
||||||
|
private final Map<Path, Result> preparationFailures = new java.util.concurrent.ConcurrentHashMap<>();
|
||||||
|
private static final String BEGIN = "# Studio managed MCP entry ";
|
||||||
|
private static final String END = "# End Studio managed MCP entry\n";
|
||||||
|
public StudioAgentPreparation(Path installation, ObjectMapper mapper) { this.installation = installation; this.mapper = mapper; }
|
||||||
|
@Override public synchronized Result prepare(Path projectRoot) {
|
||||||
|
var result = prepareLocal(projectRoot);
|
||||||
|
Path key = preparationKey(projectRoot);
|
||||||
|
if (result.ready()) preparationFailures.remove(key); else preparationFailures.put(key, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
private Result prepareLocal(Path projectRoot) {
|
||||||
|
try {
|
||||||
|
Path root = projectRoot.toRealPath();
|
||||||
|
if (!Files.isRegularFile(root.resolve("prometeu.json"))) return new Result(false, "Project manifest not found.");
|
||||||
|
if (ProjectConnectionFiles.tracked(root, ".codex/config.toml"))
|
||||||
|
return new Result(false, "Client configuration is tracked. Keep machine-specific registration local before preparing this project.");
|
||||||
|
Path directory = root.resolve(".codex"), config = directory.resolve("config.toml");
|
||||||
|
if (Files.isSymbolicLink(directory) || Files.isSymbolicLink(config)) return new Result(false, "Client configuration path is unsafe.");
|
||||||
|
String old = Files.exists(config) ? Files.readString(config) : "";
|
||||||
|
String next = merge(old, entry(root));
|
||||||
|
ManagedStudioInstallation.ensureAvailable(installation);
|
||||||
|
Files.createDirectories(directory);
|
||||||
|
ProjectConnectionFiles.ignore(root, ".codex/config.toml");
|
||||||
|
ProjectConnectionFiles.ignore(root, ".studio/mcp/");
|
||||||
|
if (!old.equals(next)) {
|
||||||
|
int previous = old.indexOf(BEGIN);
|
||||||
|
if (previous >= 0) {
|
||||||
|
ProjectConnectionFiles.ignore(root, ".codex/.studio-mcp.previous.toml");
|
||||||
|
String owned = old.substring(previous, old.indexOf(END, previous) + END.length());
|
||||||
|
ProjectConnectionFiles.atomicPrivateWrite(directory.resolve(".studio-mcp.previous.toml"), owned.getBytes(StandardCharsets.UTF_8));
|
||||||
|
}
|
||||||
|
Path temporary = Files.createTempFile(directory, ".studio-config-", ".tmp", PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rw-------")));
|
||||||
|
try { Files.writeString(temporary, next); Files.move(temporary, config, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING); }
|
||||||
|
finally { Files.deleteIfExists(temporary); }
|
||||||
|
}
|
||||||
|
Path studio = root.resolve(".studio");
|
||||||
|
if (Files.isSymbolicLink(studio)) throw new IllegalStateException("Unsafe setup directory");
|
||||||
|
Files.createDirectories(studio);
|
||||||
|
Path setup = studio.resolve("setup.json");
|
||||||
|
if (Files.isSymbolicLink(setup)) throw new IllegalStateException("Unsafe setup file");
|
||||||
|
var value = Files.exists(setup) ? mapper.readTree(Files.readAllBytes(setup)) : mapper.createObjectNode();
|
||||||
|
if (!(value instanceof com.fasterxml.jackson.databind.node.ObjectNode object)) throw new IllegalStateException("Invalid setup");
|
||||||
|
object.putObject("agentIntegration").put("schemaVersion", 1).put("enabled", true).put("clientProfile", "codex");
|
||||||
|
String setupText = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(object);
|
||||||
|
if (!Files.exists(setup) || !Files.readString(setup).equals(setupText)) {
|
||||||
|
Path temporary = Files.createTempFile(studio, ".setup-", ".tmp");
|
||||||
|
try { Files.writeString(temporary, setupText); Files.move(temporary, setup, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING); }
|
||||||
|
finally { Files.deleteIfExists(temporary); }
|
||||||
|
}
|
||||||
|
return new Result(true, "Assistant prepared. Trust this project in your client and reload MCP once if requested. Then grant access in DEV; no token copying or restart reconfiguration is needed.");
|
||||||
|
} catch (ManagedStudioInstallation.MissingInstallation missing) { return new Result(false, missing.getMessage()); }
|
||||||
|
catch (Conflict conflict) { return new Result(false, conflict.getMessage()); }
|
||||||
|
catch (Exception failure) { return new Result(false, "Preparation incomplete. Check the Studio installation and project/configuration permissions; existing client settings were not deliberately replaced."); }
|
||||||
|
}
|
||||||
|
@Override public Result status(Path projectRoot) {
|
||||||
|
var failure = preparationFailures.get(preparationKey(projectRoot));
|
||||||
|
if (failure != null) return failure;
|
||||||
|
try {
|
||||||
|
Path root = projectRoot.toRealPath(), config = root.resolve(".codex/config.toml");
|
||||||
|
if (Files.isSymbolicLink(config.getParent()) || Files.isSymbolicLink(config))
|
||||||
|
return new Result(false, "Unsafe client configuration path. Prepare the assistant after resolving it.");
|
||||||
|
if (!Files.isRegularFile(config)) return new Result(false, "Assistant setup is incomplete. Prepare the assistant for this project.");
|
||||||
|
String old = Files.readString(config);
|
||||||
|
if (!old.equals(merge(old, entry(root))) || !Files.isExecutable(installation.resolve("current/runtime/bin/java")))
|
||||||
|
return new Result(false, "Assistant setup is incomplete. Prepare the assistant from an installed Studio.");
|
||||||
|
return new Result(true, "Assistant prepared. Trust this project in your client and reload MCP once if requested.");
|
||||||
|
} catch (Conflict conflict) { return new Result(false, conflict.getMessage()); }
|
||||||
|
catch (Exception unavailable) { return new Result(false, "Assistant setup could not be verified. Prepare the assistant again."); }
|
||||||
|
}
|
||||||
|
private static Path preparationKey(Path root) {
|
||||||
|
try { return root.toRealPath(); }
|
||||||
|
catch (java.io.IOException missing) { return root.toAbsolutePath().normalize(); }
|
||||||
|
}
|
||||||
|
public String entry(Path root) throws Exception {
|
||||||
|
Path current = installation.resolve("current").toAbsolutePath();
|
||||||
|
return "[mcp_servers.prometeu_studio]\ncommand = " + quote(current.resolve("runtime/bin/java").toString())
|
||||||
|
+ "\nargs = " + mapper.writeValueAsString(List.of("-cp", current.resolve("lib/*").toString(), "p.studio.app.StudioLauncher", "mcp", "--project", root.toString()))
|
||||||
|
+ "\ncwd = " + quote(root.toString()) + "\nstartup_timeout_sec = 20\ntool_timeout_sec = 90\n";
|
||||||
|
}
|
||||||
|
private String quote(String text) throws Exception { return mapper.writeValueAsString(text); }
|
||||||
|
static String merge(String old, String entry) throws Exception {
|
||||||
|
if (Toml.parse(old).hasErrors()) throw new Conflict("Existing client TOML is invalid; repair it before preparation.");
|
||||||
|
String block = BEGIN + hash(entry) + "\n" + entry + END;
|
||||||
|
int start = old.indexOf(BEGIN), end = old.indexOf(END);
|
||||||
|
String next;
|
||||||
|
if (start >= 0) {
|
||||||
|
int body = old.indexOf('\n', start) + 1;
|
||||||
|
if (start > 0 && old.charAt(start - 1) != '\n' || body == 0 || end < body || old.indexOf(BEGIN, body) >= 0 || !old.substring(start + BEGIN.length(), body - 1).equals(hash(old.substring(body, end))))
|
||||||
|
throw new Conflict("The Studio MCP entry was edited. Resolve the managed-entry conflict explicitly.");
|
||||||
|
next = old.substring(0, start) + block + old.substring(end + END.length());
|
||||||
|
} else {
|
||||||
|
if (end >= 0 || Toml.parse(old).contains("mcp_servers.prometeu_studio")) throw new Conflict("A user-owned Studio MCP entry already exists; resolve it explicitly.");
|
||||||
|
next = old + (old.isEmpty() || old.endsWith("\n") ? "" : "\n") + block;
|
||||||
|
}
|
||||||
|
if (Toml.parse(next).hasErrors()) throw new Conflict("Client configuration conflicts with the Studio entry; nothing was overwritten.");
|
||||||
|
var actual = Toml.parse(next).getTable("mcp_servers.prometeu_studio");
|
||||||
|
var expected = Toml.parse(entry).getTable("mcp_servers.prometeu_studio");
|
||||||
|
if (actual == null || expected == null || !actual.keySet().equals(expected.keySet())
|
||||||
|
|| !Objects.equals(actual.getString("command"), expected.getString("command"))
|
||||||
|
|| !Objects.equals(actual.getString("cwd"), expected.getString("cwd"))
|
||||||
|
|| !Objects.equals(actual.getLong("startup_timeout_sec"), expected.getLong("startup_timeout_sec"))
|
||||||
|
|| !Objects.equals(actual.getLong("tool_timeout_sec"), expected.getLong("tool_timeout_sec"))
|
||||||
|
|| actual.getArray("args") == null || !actual.getArray("args").toList().equals(expected.getArray("args").toList()))
|
||||||
|
throw new Conflict("The managed Studio table conflicts with other client settings; resolve it explicitly.");
|
||||||
|
return next;
|
||||||
|
}
|
||||||
|
private static String hash(String text) throws Exception { return HexFormat.of().formatHex(java.security.MessageDigest.getInstance("SHA-256").digest(text.getBytes(StandardCharsets.UTF_8))); }
|
||||||
|
private static final class Conflict extends Exception { Conflict(String text) { super(text); } }
|
||||||
|
}
|
||||||
@@ -0,0 +1,170 @@
|
|||||||
|
package p.studio.app.mcp.stdio;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.*;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
import p.studio.app.mcp.*;
|
||||||
|
import java.io.*;
|
||||||
|
import java.net.http.*;
|
||||||
|
import java.nio.file.*;
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/** Owns only HTTP transport. Never retries a tools/call or creates task authority. */
|
||||||
|
final class StudioMcpConnection implements AutoCloseable {
|
||||||
|
private final Path root;
|
||||||
|
private final ObjectMapper mapper;
|
||||||
|
private final McpToolCatalog catalog;
|
||||||
|
private final HttpClient client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(2)).followRedirects(HttpClient.Redirect.NEVER).build();
|
||||||
|
private ProjectConnectionFiles.Descriptor descriptor;
|
||||||
|
private String session;
|
||||||
|
private Set<String> available = Set.of();
|
||||||
|
// Diagnostic correlation only: Core remains the sole validator of task authority.
|
||||||
|
private final LinkedHashMap<String, String> observedTaskInstances = new LinkedHashMap<>();
|
||||||
|
private long sequence;
|
||||||
|
private volatile String status = "WAITING_FOR_ACCESS";
|
||||||
|
StudioMcpConnection(Path root, ObjectMapper mapper, McpToolCatalog catalog) { this.root = root; this.mapper = mapper; this.catalog = catalog; }
|
||||||
|
String status() { return status; }
|
||||||
|
synchronized void probe() {
|
||||||
|
try { connect(); exchange("ping", mapper.createObjectNode(), true, 3); status = "CONNECTED"; }
|
||||||
|
catch (Exception failure) { disconnect(); }
|
||||||
|
}
|
||||||
|
synchronized JsonNode call(String tool, JsonNode arguments) {
|
||||||
|
boolean dispatched = false;
|
||||||
|
try {
|
||||||
|
catalog.validateArguments(tool, arguments);
|
||||||
|
try {
|
||||||
|
if (!Path.of(arguments.path("projectRoot").asText()).toRealPath().equals(root))
|
||||||
|
return failure("OUTSIDE_PROJECT_SCOPE", "The connector is bound to another project.");
|
||||||
|
} catch (IOException inaccessible) { return failure("INVALID_REQUEST", "Project root cannot be resolved."); }
|
||||||
|
connect();
|
||||||
|
String taskInstance = observedTaskInstances.get(arguments.path("taskId").asText());
|
||||||
|
if (tool.equals("studio_operation_get") && taskInstance != null && !taskInstance.equals(descriptor.instanceId()))
|
||||||
|
return failure("OUTCOME_UNKNOWN", "Studio restarted; this task's in-memory receipts are unavailable. Obtain a fresh grant/task and decide the next intent explicitly; do not replay the old operation.");
|
||||||
|
if (!available.contains(tool)) return failure("UNSUPPORTED_CAPABILITY", "The live Studio does not provide this tool.");
|
||||||
|
var params = mapper.createObjectNode().put("name", tool).set("arguments", arguments);
|
||||||
|
dispatched = true;
|
||||||
|
var response = exchange("tools/call", params, true, 70);
|
||||||
|
if (response.has("error")) throw new ProtocolFailure(response.get("error"));
|
||||||
|
status = "CONNECTED";
|
||||||
|
var result = response.required("result");
|
||||||
|
if (tool.equals("studio_control_acquire") && !result.path("isError").asBoolean()) {
|
||||||
|
String task = result.path("structuredContent").path("value").path("taskId").asText();
|
||||||
|
if (!task.isBlank()) {
|
||||||
|
observedTaskInstances.put(task, descriptor.instanceId());
|
||||||
|
if (observedTaskInstances.size() > 64) observedTaskInstances.remove(observedTaskInstances.keySet().iterator().next());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} catch (ProtocolFailure protocol) { throw protocol;
|
||||||
|
} catch (IllegalArgumentException invalid) {
|
||||||
|
return failure("INVALID_REQUEST", "Invalid tool arguments or project root.");
|
||||||
|
} catch (Exception unavailable) {
|
||||||
|
disconnect();
|
||||||
|
var result = failure(dispatched ? "OUTCOME_UNKNOWN" : status,
|
||||||
|
dispatched ? "Response unavailable; do not replay. For the same authorized task, look up operationId/clientRequestId. After Studio restart, obtain a new grant; old receipts may be unavailable."
|
||||||
|
: guidance());
|
||||||
|
if (dispatched && arguments != null && arguments.path("clientRequestId").isTextual())
|
||||||
|
((ObjectNode) result.path("structuredContent").path("error")).put("clientRequestId", arguments.path("clientRequestId").asText());
|
||||||
|
((ObjectNode) result.path("content").get(0)).put("text", result.path("structuredContent").toString());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private String guidance() {
|
||||||
|
return switch (status) {
|
||||||
|
case "VERSION_INCOMPATIBLE" -> "Studio and its installed connector are incompatible; update the installation.";
|
||||||
|
case "STALE_CONNECTION" -> "Connection credentials are stale or invalid; grant access again in DEV.";
|
||||||
|
case "INVALID_DESCRIPTOR" -> "Project connection data or permissions are invalid; prepare the project again.";
|
||||||
|
default -> "Open Studio and this project, then grant access in DEV. The connection will be discovered without restarting this client.";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
private void connect() throws Exception {
|
||||||
|
ProjectConnectionFiles.Descriptor next;
|
||||||
|
try { next = ProjectConnectionFiles.read(root, mapper); }
|
||||||
|
catch (NoSuchFileException absent) { status = "WAITING_FOR_ACCESS"; throw absent; }
|
||||||
|
catch (IOException invalid) {
|
||||||
|
status = Files.exists(root.resolve(ProjectConnectionFiles.RELATIVE)) ? "INVALID_DESCRIPTOR" : "WAITING_FOR_ACCESS";
|
||||||
|
throw invalid;
|
||||||
|
}
|
||||||
|
if (!catalog.fingerprint().equals(next.catalogFingerprint())) { status = "VERSION_INCOMPATIBLE"; throw new IOException("Incompatible catalog"); }
|
||||||
|
if (session != null && next.equals(descriptor)) return;
|
||||||
|
descriptor = next; session = null; status = "RECONNECTING";
|
||||||
|
var params = mapper.createObjectNode().put("protocolVersion", LocalMcpServer.PROTOCOL_VERSION);
|
||||||
|
params.putObject("capabilities"); params.putObject("clientInfo").put("name", "studio-project-connector").put("version", "1");
|
||||||
|
var result = exchange("initialize", params, true, 5).required("result");
|
||||||
|
if (!LocalMcpServer.PROTOCOL_VERSION.equals(result.path("protocolVersion").asText())
|
||||||
|
|| !catalog.fingerprint().equals(result.path("_meta").path("catalogFingerprint").asText())) {
|
||||||
|
status = "VERSION_INCOMPATIBLE"; throw new IOException("Incompatible protocol");
|
||||||
|
}
|
||||||
|
if (!next.instanceId().equals(result.path("_meta").path("instanceId").asText())
|
||||||
|
|| !root.toString().equals(result.path("_meta").path("projectRoot").asText())) {
|
||||||
|
status = "STALE_CONNECTION"; throw new IOException("Wrong instance");
|
||||||
|
}
|
||||||
|
exchange("notifications/initialized", mapper.createObjectNode(), false, 5);
|
||||||
|
var descriptors = exchange("tools/list", mapper.createObjectNode(), true, 5).path("result").path("tools");
|
||||||
|
if (!descriptors.isArray()) throw new IOException("Invalid catalog");
|
||||||
|
var names = new HashSet<String>();
|
||||||
|
for (var tool : descriptors) {
|
||||||
|
String name = tool.path("name").asText();
|
||||||
|
if (!catalog.names().contains(name) || !catalog.descriptor(name).equals(tool) || !names.add(name)) {
|
||||||
|
status = "VERSION_INCOMPATIBLE"; throw new IOException("Incompatible tools");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
available = Set.copyOf(names); status = "CONNECTED";
|
||||||
|
}
|
||||||
|
private JsonNode exchange(String method, JsonNode params, boolean responseExpected, int seconds) throws Exception {
|
||||||
|
var message = mapper.createObjectNode().put("jsonrpc", "2.0").put("method", method);
|
||||||
|
if (responseExpected) message.put("id", ++sequence);
|
||||||
|
message.set("params", params);
|
||||||
|
var request = HttpRequest.newBuilder(descriptor.endpoint()).timeout(Duration.ofSeconds(seconds))
|
||||||
|
.header("Authorization", "Bearer " + descriptor.credential()).header("Content-Type", "application/json")
|
||||||
|
.header("Accept", "application/json, text/event-stream").header("MCP-Protocol-Version", LocalMcpServer.PROTOCOL_VERSION);
|
||||||
|
if (session != null) request.header("Mcp-Session-Id", session);
|
||||||
|
var pending = client.sendAsync(request.POST(HttpRequest.BodyPublishers.ofString(message.toString())).build(),
|
||||||
|
info -> boundedBody());
|
||||||
|
HttpResponse<byte[]> response;
|
||||||
|
try { response = pending.get(seconds, java.util.concurrent.TimeUnit.SECONDS); }
|
||||||
|
catch (Exception failure) { pending.cancel(true); throw failure; }
|
||||||
|
if (response.statusCode() != 200 && response.statusCode() != 202) {
|
||||||
|
if (response.statusCode() == 401 || response.statusCode() == 403 || response.statusCode() == 404) status = "STALE_CONNECTION";
|
||||||
|
throw new IOException("Connection rejected");
|
||||||
|
}
|
||||||
|
response.headers().firstValue("Mcp-Session-Id").ifPresent(value -> session = value);
|
||||||
|
if (method.equals("initialize") && session == null) throw new IOException("Missing session identity");
|
||||||
|
if (!responseExpected) return mapper.nullNode();
|
||||||
|
var json = mapper.readTree(response.body());
|
||||||
|
if (json == null || !"2.0".equals(json.path("jsonrpc").asText()) || !json.path("id").isIntegralNumber() || !message.get("id").bigIntegerValue().equals(json.path("id").bigIntegerValue())
|
||||||
|
|| json.has("result") == json.has("error")) throw new IOException("Invalid response");
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
private static HttpResponse.BodySubscriber<byte[]> boundedBody() {
|
||||||
|
return new HttpResponse.BodySubscriber<>() {
|
||||||
|
final HttpResponse.BodySubscriber<byte[]> delegate = HttpResponse.BodySubscribers.ofByteArray();
|
||||||
|
java.util.concurrent.Flow.Subscription subscription;
|
||||||
|
long bytes;
|
||||||
|
public java.util.concurrent.CompletionStage<byte[]> getBody() { return delegate.getBody(); }
|
||||||
|
public void onSubscribe(java.util.concurrent.Flow.Subscription value) { subscription = value; delegate.onSubscribe(value); }
|
||||||
|
public void onNext(List<java.nio.ByteBuffer> buffers) {
|
||||||
|
for (var buffer : buffers) bytes += buffer.remaining();
|
||||||
|
if (bytes > 32L * 1024 * 1024) { subscription.cancel(); delegate.onError(new IOException("Response too large")); }
|
||||||
|
else delegate.onNext(buffers);
|
||||||
|
}
|
||||||
|
public void onError(Throwable failure) { delegate.onError(failure); }
|
||||||
|
public void onComplete() { delegate.onComplete(); }
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private ObjectNode failure(String code, String message) {
|
||||||
|
var value = mapper.createObjectNode().put("isError", true);
|
||||||
|
var data = value.putObject("structuredContent").put("status", "error");
|
||||||
|
data.putObject("error").put("code", code).put("message", message);
|
||||||
|
value.putArray("content").addObject().put("type", "text").put("text", data.toString());
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
static final class ProtocolFailure extends RuntimeException {
|
||||||
|
final JsonNode error;
|
||||||
|
ProtocolFailure(JsonNode error) { super("Studio protocol error"); this.error = error.deepCopy(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
private void disconnect() { if (status.equals("CONNECTED")) status = "RECONNECTING"; session = null; available = Set.of(); }
|
||||||
|
@Override public void close() { client.shutdownNow(); }
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
package p.studio.app.mcp.stdio;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.*;
|
||||||
|
import p.studio.app.mcp.*;
|
||||||
|
import java.io.*;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.*;
|
||||||
|
import java.util.concurrent.*;
|
||||||
|
|
||||||
|
/** A mode of Studio itself; no JavaFX, Spring, HTTP listener or agent runtime is started here. */
|
||||||
|
public final class StudioMcpStdio {
|
||||||
|
private StudioMcpStdio() { }
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
if (args.length != 3 || !"mcp".equals(args[0]) || !"--project".equals(args[1]) || !Path.of(args[2]).isAbsolute())
|
||||||
|
throw new IllegalArgumentException("Usage: mcp --project <absolute-project-root>");
|
||||||
|
Path root = Path.of(args[2]).toRealPath();
|
||||||
|
if (!Files.isRegularFile(root.resolve("prometeu.json"))) throw new IllegalArgumentException("Project manifest not found");
|
||||||
|
run(root, System.in, System.out);
|
||||||
|
}
|
||||||
|
public static void run(Path root, InputStream input, OutputStream output) throws Exception {
|
||||||
|
var mapper = new ObjectMapper().enable(JsonParser.Feature.STRICT_DUPLICATE_DETECTION).enable(DeserializationFeature.FAIL_ON_TRAILING_TOKENS);
|
||||||
|
mapper.getFactory().setStreamReadConstraints(com.fasterxml.jackson.core.StreamReadConstraints.builder().maxStringLength(32 * 1024 * 1024).build());
|
||||||
|
var catalog = new McpToolCatalog(mapper);
|
||||||
|
var timer = Executors.newSingleThreadScheduledExecutor(Thread.ofPlatform().daemon().name("studio-mcp-discovery").factory());
|
||||||
|
try (var connection = new StudioMcpConnection(root, mapper, catalog)) {
|
||||||
|
timer.scheduleWithFixedDelay(connection::probe, 0, 2, TimeUnit.SECONDS);
|
||||||
|
boolean initialized = false, negotiated = false;
|
||||||
|
var line = new ByteArrayOutputStream(); int next;
|
||||||
|
while ((next = input.read()) != -1) {
|
||||||
|
if (next != '\n') {
|
||||||
|
if (line.size() >= 1024 * 1024) throw new IOException("MCP request exceeds limit");
|
||||||
|
line.write(next); continue;
|
||||||
|
}
|
||||||
|
JsonNode message;
|
||||||
|
try { message = mapper.readTree(StandardCharsets.UTF_8.newDecoder().decode(java.nio.ByteBuffer.wrap(line.toByteArray())).toString()); }
|
||||||
|
catch (Exception malformed) { line.reset(); write(output, error(mapper, mapper.nullNode(), -32700, "Invalid JSON")); continue; }
|
||||||
|
line.reset();
|
||||||
|
if (message == null || !message.isObject() || !message.path("jsonrpc").isTextual() || !"2.0".equals(message.path("jsonrpc").asText())
|
||||||
|
|| !message.path("method").isTextual() || message.has("id") && !(message.path("id").isTextual() || message.path("id").isIntegralNumber())) {
|
||||||
|
write(output, error(mapper, mapper.nullNode(), -32600, "Invalid request")); continue;
|
||||||
|
}
|
||||||
|
String method = message.path("method").asText();
|
||||||
|
if (!message.has("id")) { if (negotiated && "notifications/initialized".equals(method)) initialized = true; continue; }
|
||||||
|
var id = message.get("id"); JsonNode result;
|
||||||
|
if (method.equals("initialize") && !negotiated) {
|
||||||
|
var params = message.path("params");
|
||||||
|
if (!params.path("protocolVersion").isTextual() || !params.path("capabilities").isObject() || !params.path("clientInfo").isObject()) {
|
||||||
|
write(output, error(mapper, id, -32602, "Invalid initialization")); continue;
|
||||||
|
}
|
||||||
|
var value = mapper.createObjectNode().put("protocolVersion", LocalMcpServer.PROTOCOL_VERSION);
|
||||||
|
value.putObject("capabilities").putObject("tools").put("listChanged", false);
|
||||||
|
value.putObject("serverInfo").put("name", "prometeu-studio").put("version", "1");
|
||||||
|
value.put("instructions", McpConnectionGuide.INSTRUCTIONS + "\nProject root: " + root);
|
||||||
|
result = value; negotiated = true;
|
||||||
|
} else if (!initialized) { write(output, error(mapper, id, -32600, "Initialization required")); continue; }
|
||||||
|
else if (method.equals("ping")) result = mapper.createObjectNode();
|
||||||
|
else if (method.equals("tools/list")) {
|
||||||
|
var value = mapper.createObjectNode(); var tools = value.putArray("tools");
|
||||||
|
catalog.names().forEach(name -> tools.add(catalog.descriptor(name))); result = value;
|
||||||
|
} else if (method.equals("tools/call")) {
|
||||||
|
String tool = message.path("params").path("name").asText();
|
||||||
|
var arguments = message.path("params").path("arguments");
|
||||||
|
try { catalog.validateArguments(tool, arguments); }
|
||||||
|
catch (IllegalArgumentException invalid) { write(output, error(mapper, id, -32602, "Invalid tool arguments")); continue; }
|
||||||
|
try { result = connection.call(tool, arguments); }
|
||||||
|
catch (StudioMcpConnection.ProtocolFailure protocol) {
|
||||||
|
var reply = mapper.createObjectNode().put("jsonrpc", "2.0"); reply.set("id", id); reply.set("error", protocol.error);
|
||||||
|
write(output, reply); continue;
|
||||||
|
}
|
||||||
|
} else { write(output, error(mapper, id, -32601, "Method not found")); continue; }
|
||||||
|
var reply = mapper.createObjectNode().put("jsonrpc", "2.0"); reply.set("id", id); reply.set("result", result); write(output, reply);
|
||||||
|
}
|
||||||
|
} finally { timer.shutdownNow(); }
|
||||||
|
}
|
||||||
|
private static JsonNode error(ObjectMapper mapper, JsonNode id, int code, String text) {
|
||||||
|
var reply = mapper.createObjectNode().put("jsonrpc", "2.0"); reply.set("id", id);
|
||||||
|
reply.putObject("error").put("code", code).put("message", text); return reply;
|
||||||
|
}
|
||||||
|
private static void write(OutputStream output, JsonNode value) throws IOException {
|
||||||
|
output.write(value.toString().getBytes(StandardCharsets.UTF_8)); output.write('\n'); output.flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -245,7 +245,9 @@ final class HeadlessProcessSession implements HeadlessGateway.Session {
|
|||||||
default -> AutomationFailure.Code.INFRASTRUCTURE_FAILURE;
|
default -> AutomationFailure.Code.INFRASTRUCTURE_FAILURE;
|
||||||
};
|
};
|
||||||
pending.remove(item.id);
|
pending.remove(item.id);
|
||||||
item.result.completeExceptionally(new AutomationException(code, "Runtime " + error.path("code").asText() + ": " + error.path("message").asText()));
|
Map<String, Object> runtimeError = mapper.convertValue(error, new com.fasterxml.jackson.core.type.TypeReference<>() {});
|
||||||
|
item.result.completeExceptionally(new AutomationException(new AutomationFailure(code,
|
||||||
|
"Runtime " + error.path("code").asText() + ": " + error.path("message").asText(), runtimeError)));
|
||||||
} else {
|
} else {
|
||||||
var result = message.get("result");
|
var result = message.get("result");
|
||||||
if (item.command.equals("cancel") && (!result.path("requested").isBoolean() || !result.path("requested").booleanValue()
|
if (item.command.equals("cancel") && (!result.path("requested").isBoolean() || !result.path("requested").booleanValue()
|
||||||
|
|||||||
@@ -367,7 +367,7 @@
|
|||||||
{
|
{
|
||||||
"name": "studio_language_query",
|
"name": "studio_language_query",
|
||||||
"authority": "task",
|
"authority": "task",
|
||||||
"description": "Query supported project LSP capabilities after synchronizing saved files. Returns refactoring proposals, never applies edits.",
|
"description": "Query project LSP capabilities using saved project files or task-owned read-only external sources. readExternalSource reads an external URI returned by definition; hover and definition can continue inside it. Returns refactoring proposals, never applies edits.",
|
||||||
"inputSchema": {
|
"inputSchema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|||||||
@@ -40,6 +40,12 @@ class DevDesktopTest {
|
|||||||
completed.get(10, TimeUnit.SECONDS);
|
completed.get(10, TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void awaitWaiting(AutomationSession authority) throws Exception {
|
||||||
|
long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(5);
|
||||||
|
while (authority.snapshot().state() != ControlState.WAITING_FOR_AGENT && System.nanoTime() < deadline) Thread.sleep(5);
|
||||||
|
assertEquals(ControlState.WAITING_FOR_AGENT, authority.snapshot().state());
|
||||||
|
}
|
||||||
|
|
||||||
@Test void devDebugNavigationBackgroundProjectionAndDisposal() throws Exception {
|
@Test void devDebugNavigationBackgroundProjectionAndDisposal() throws Exception {
|
||||||
var pool = Executors.newSingleThreadExecutor();
|
var pool = Executors.newSingleThreadExecutor();
|
||||||
var authority = new DefaultAutomationSession(root, new ExecutorOperationExecutor(pool));
|
var authority = new DefaultAutomationSession(root, new ExecutorOperationExecutor(pool));
|
||||||
@@ -70,6 +76,9 @@ class DevDesktopTest {
|
|||||||
assertEquals(1, subscriptions.get());
|
assertEquals(1, subscriptions.get());
|
||||||
assertTrue(((Button) dev[0].rootNode().lookup("#dev-mcp-config")).isDisabled());
|
assertTrue(((Button) dev[0].rootNode().lookup("#dev-mcp-config")).isDisabled());
|
||||||
((Button) dev[0].rootNode().lookup("#dev-grant")).fire();
|
((Button) dev[0].rootNode().lookup("#dev-grant")).fire();
|
||||||
|
});
|
||||||
|
awaitWaiting(authority);
|
||||||
|
fx(() -> {
|
||||||
assertEquals(ControlState.WAITING_FOR_AGENT, authority.snapshot().state());
|
assertEquals(ControlState.WAITING_FOR_AGENT, authority.snapshot().state());
|
||||||
host[0].change(WorkspaceId.DEBUG); assertEquals(0, subscriptions.get());
|
host[0].change(WorkspaceId.DEBUG); assertEquals(0, subscriptions.get());
|
||||||
assertEquals(ControlState.WAITING_FOR_AGENT, authority.snapshot().state());
|
assertEquals(ControlState.WAITING_FOR_AGENT, authority.snapshot().state());
|
||||||
@@ -96,8 +105,8 @@ class DevDesktopTest {
|
|||||||
locale.setLocale(java.util.Locale.forLanguageTag("pt-BR"));
|
locale.setLocale(java.util.Locale.forLanguageTag("pt-BR"));
|
||||||
host[0].deactivateCurrentWorkspace(); assertEquals(0, subscriptions.get());
|
host[0].deactivateCurrentWorkspace(); assertEquals(0, subscriptions.get());
|
||||||
authority.grant(false); locale.setLocale(java.util.Locale.ENGLISH);
|
authority.grant(false); locale.setLocale(java.util.Locale.ENGLISH);
|
||||||
assertEquals(ControlState.WAITING_FOR_AGENT, authority.snapshot().state());
|
|
||||||
});
|
});
|
||||||
|
awaitWaiting(authority);
|
||||||
} finally {
|
} finally {
|
||||||
fx(() -> { if (host[0] != null) host[0].deactivateCurrentWorkspace(); if (stage[0] != null) stage[0].close(); });
|
fx(() -> { if (host[0] != null) host[0].deactivateCurrentWorkspace(); if (stage[0] != null) stage[0].close(); });
|
||||||
authority.closeAsync().toCompletableFuture().get(5, TimeUnit.SECONDS); pool.shutdownNow();
|
authority.closeAsync().toCompletableFuture().get(5, TimeUnit.SECONDS); pool.shutdownNow();
|
||||||
@@ -120,56 +129,39 @@ class DevDesktopTest {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test void copiesLiveConnectionWithoutGrantOrCredentialDisplayAndRefreshesAvailability() throws Exception {
|
@Test void preparesConnectionWithoutGrantAndRemainsAvailableWhenTransportStops() throws Exception {
|
||||||
var mapper = new com.fasterxml.jackson.databind.ObjectMapper();
|
var mapper = new com.fasterxml.jackson.databind.ObjectMapper();
|
||||||
var projects = new p.studio.core.project.ProjectAccessRegistry();
|
var projects = new p.studio.core.project.ProjectAccessRegistry();
|
||||||
var savedClipboard = new java.util.HashMap<javafx.scene.input.DataFormat, Object>();
|
var prepared = new CompletableFuture<Void>();
|
||||||
var copied = new java.util.concurrent.atomic.AtomicReference<String>();
|
|
||||||
var view = new DevWorkspace[1]; var stage = new Stage[1];
|
var view = new DevWorkspace[1]; var stage = new Stage[1];
|
||||||
try (var pool = Executors.newSingleThreadExecutor();
|
try (var pool = Executors.newSingleThreadExecutor();
|
||||||
var server = new p.studio.app.mcp.LocalMcpServer(mapper, new p.studio.app.mcp.McpToolRegistry(
|
var server = new p.studio.app.mcp.LocalMcpServer(mapper, new p.studio.app.mcp.McpToolRegistry(
|
||||||
new p.studio.app.mcp.McpToolCatalog(mapper), mapper, java.util.Map.of()))) {
|
new p.studio.app.mcp.McpToolCatalog(mapper), mapper, java.util.Map.of()))) {
|
||||||
var authority = new DefaultAutomationSession(root, new ExecutorOperationExecutor(pool));
|
var authority = new DefaultAutomationSession(root, new ExecutorOperationExecutor(pool));
|
||||||
var registration = projects.register(root, authority::enterManual, () -> !authority.snapshot().closed(), authority);
|
var registration = projects.register(root, authority::enterManual, () -> !authority.snapshot().closed(), authority);
|
||||||
var guide = new p.studio.app.mcp.McpConnectionGuide(server, projects, mapper);
|
var guide = new p.studio.app.mcp.McpConnectionGuide(server, projects, mapper, project -> {
|
||||||
|
prepared.complete(null);
|
||||||
|
return new p.studio.api.automation.AgentIntegrationPreparation.Result(true, "Prepared; trust/reload once.");
|
||||||
|
});
|
||||||
server.start();
|
server.start();
|
||||||
try {
|
try {
|
||||||
fx(() -> {
|
fx(() -> {
|
||||||
var clipboard = javafx.scene.input.Clipboard.getSystemClipboard();
|
|
||||||
clipboard.getContentTypes().forEach(type -> savedClipboard.put(type, clipboard.getContent(type)));
|
|
||||||
var project = new ProjectReference("Connection smoke", "1", "pbs", 1, ProjectTarget.Game, root);
|
var project = new ProjectReference("Connection smoke", "1", "pbs", 1, ProjectTarget.Game, root);
|
||||||
view[0] = new DevWorkspace(project, authority, new I18nService(), new StudioEventBus(), guide);
|
view[0] = new DevWorkspace(project, authority, new I18nService(), new StudioEventBus(), guide);
|
||||||
stage[0] = new Stage(); stage[0].setScene(new Scene(new VBox(view[0].rootNode()), 1050, 800)); stage[0].show();
|
stage[0] = new Stage(); stage[0].setScene(new Scene(new VBox(view[0].rootNode()), 1050, 800)); stage[0].show();
|
||||||
view[0].load();
|
view[0].load();
|
||||||
var button = (Button) view[0].rootNode().lookup("#dev-mcp-config"); assertFalse(button.isDisabled());
|
var button = (Button) view[0].rootNode().lookup("#dev-mcp-config"); assertFalse(button.isDisabled()); button.fire();
|
||||||
button.fire(); copied.set(clipboard.getString());
|
});
|
||||||
|
prepared.get(5, TimeUnit.SECONDS);
|
||||||
assertEquals(ControlState.MANUAL, authority.snapshot().state());
|
assertEquals(ControlState.MANUAL, authority.snapshot().state());
|
||||||
assertEquals(server.connection().endpoint().toString(), ((Label) view[0].rootNode().lookup("#dev-mcp-endpoint")).getText());
|
|
||||||
assertTrue(view[0].rootNode().lookupAll(".label").stream().filter(n -> n instanceof Label)
|
|
||||||
.noneMatch(n -> ((Label) n).getText().contains(server.connection().authorizationHeader())));
|
|
||||||
});
|
|
||||||
var first = mapper.readTree(copied.get());
|
|
||||||
assertTrue(server.connection().authorizationHeader().equals(first.path("headers").path("Authorization").asText()));
|
|
||||||
assertEquals(root.toRealPath().toString(), first.path("projectRoot").asText());
|
|
||||||
server.close();
|
server.close();
|
||||||
fx(() -> assertTrue(((Button) view[0].rootNode().lookup("#dev-mcp-config")).isDisabled()));
|
fx(() -> assertFalse(((Button) view[0].rootNode().lookup("#dev-mcp-config")).isDisabled()));
|
||||||
server.start(); authority.grant(false).toCompletableFuture().join();
|
server.start(); authority.grant(false).toCompletableFuture().join();
|
||||||
fx(() -> {
|
|
||||||
var button = (Button) view[0].rootNode().lookup("#dev-mcp-config"); assertFalse(button.isDisabled());
|
|
||||||
button.fire(); copied.set(javafx.scene.input.Clipboard.getSystemClipboard().getString());
|
|
||||||
assertEquals(ControlState.WAITING_FOR_AGENT, authority.snapshot().state());
|
assertEquals(ControlState.WAITING_FOR_AGENT, authority.snapshot().state());
|
||||||
});
|
|
||||||
var next = mapper.readTree(copied.get());
|
|
||||||
assertFalse(first.path("headers").equals(next.path("headers")));
|
|
||||||
assertTrue(server.connection().authorizationHeader().equals(next.path("headers").path("Authorization").asText()));
|
|
||||||
authority.closeAsync().toCompletableFuture().get(5, TimeUnit.SECONDS);
|
authority.closeAsync().toCompletableFuture().get(5, TimeUnit.SECONDS);
|
||||||
fx(() -> assertTrue(((Button) view[0].rootNode().lookup("#dev-mcp-config")).isDisabled()));
|
fx(() -> assertTrue(((Button) view[0].rootNode().lookup("#dev-mcp-config")).isDisabled()));
|
||||||
} finally {
|
} finally {
|
||||||
fx(() -> {
|
fx(() -> { if (view[0] != null) view[0].unLoad(); if (stage[0] != null) stage[0].close(); });
|
||||||
if (view[0] != null) view[0].unLoad();
|
|
||||||
if (stage[0] != null) stage[0].close();
|
|
||||||
javafx.scene.input.Clipboard.getSystemClipboard().setContent(savedClipboard);
|
|
||||||
});
|
|
||||||
authority.closeAsync().toCompletableFuture().get(5, TimeUnit.SECONDS); registration.close();
|
authority.closeAsync().toCompletableFuture().get(5, TimeUnit.SECONDS); registration.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ public final class InstalledKnowledgeProbe {
|
|||||||
check(provider.getClass().getProtectionDomain().getCodeSource().getLocation().getPath().endsWith(".jar"), "Frontend must come from installed JAR");
|
check(provider.getClass().getProtectionDomain().getCodeSource().getLocation().getPath().endsWith(".jar"), "Frontend must come from installed JAR");
|
||||||
check(CompilerProjectKnowledge.class.getProtectionDomain().getCodeSource().getLocation().getPath().endsWith(".jar"), "App must come from installed JAR");
|
check(CompilerProjectKnowledge.class.getProtectionDomain().getCodeSource().getLocation().getPath().endsWith(".jar"), "App must come from installed JAR");
|
||||||
check(!Files.exists(Path.of("settings.gradle.kts")) && !Files.exists(Path.of("docs")), "No repository in working directory");
|
check(!Files.exists(Path.of("settings.gradle.kts")) && !Files.exists(Path.of("docs")), "No repository in working directory");
|
||||||
|
verifyRuntimeCatalogs(provider.getClass().getClassLoader());
|
||||||
|
if (arguments.length == 1 && arguments[0].equals("--catalog-only")) return;
|
||||||
Path root = Files.createDirectory(Path.of("example")).toRealPath();
|
Path root = Files.createDirectory(Path.of("example")).toRealPath();
|
||||||
var docs = provider.documentation().orElseThrow().references(1, p.studio.AppMode.Game);
|
var docs = provider.documentation().orElseThrow().references(1, p.studio.AppMode.Game);
|
||||||
for (var reference : docs) {
|
for (var reference : docs) {
|
||||||
@@ -49,9 +51,10 @@ public final class InstalledKnowledgeProbe {
|
|||||||
check(actual.toString().equals(reference.text()), "Incorrect installed reference: " + reference.id());
|
check(actual.toString().equals(reference.text()), "Incorrect installed reference: " + reference.id());
|
||||||
}
|
}
|
||||||
var result = BuilderPipelineService.INSTANCE.compile(
|
var result = BuilderPipelineService.INSTANCE.compile(
|
||||||
BuilderPipelineContext.fromConfig(new BuilderPipelineConfig(false, root.toString())), LogAggregator.empty());
|
BuilderPipelineContext.fromConfig(new BuilderPipelineConfig(false, root.toString())), LogAggregator.stdout());
|
||||||
check(result.diagnostics().stream().noneMatch(issue -> issue.isError()), "Example must compile without errors");
|
check(result.diagnostics().stream().noneMatch(issue -> issue.isError()), "Example must compile without errors");
|
||||||
check(result.bytecodeBytes().length > 0, "Example must produce bytecode");
|
check(result.bytecodeBytes().length > 0, "Example must produce bytecode");
|
||||||
|
verifyExternalSources(provider.getClass().getClassLoader());
|
||||||
registration.unsubscribe();
|
registration.unsubscribe();
|
||||||
System.out.println("Installed knowledge verified: " + docs.size() + " references; example compiled");
|
System.out.println("Installed knowledge verified: " + docs.size() + " references; example compiled");
|
||||||
}
|
}
|
||||||
@@ -59,4 +62,88 @@ public final class InstalledKnowledgeProbe {
|
|||||||
private static void check(boolean condition, String message) {
|
private static void check(boolean condition, String message) {
|
||||||
if (!condition) throw new AssertionError(message);
|
if (!condition) throw new AssertionError(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void verifyRuntimeCatalogs(ClassLoader loader) throws Exception {
|
||||||
|
var names = java.util.List.of("INTRINSICS.csv", "BUILTIN_CONSTANTS.csv", "runtime-catalog.properties");
|
||||||
|
var compiler = new java.util.HashMap<String, byte[]>();
|
||||||
|
for (var name : names) {
|
||||||
|
for (var owner : java.util.List.of("compiler", "pbs-sdk")) {
|
||||||
|
var resource = loader.getResource("runtime-catalog/" + owner + "/" + name);
|
||||||
|
check(resource != null && resource.getProtocol().equals("jar"), "Missing installed catalog: " + owner + "/" + name);
|
||||||
|
try (var stream = resource.openStream()) {
|
||||||
|
var bytes = stream.readAllBytes();
|
||||||
|
if (owner.equals("compiler")) compiler.put(name, bytes);
|
||||||
|
else check(java.util.Arrays.equals(compiler.get(name), bytes), "Compiler/SDK contract mismatch: " + name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var properties = new java.util.Properties();
|
||||||
|
properties.load(new java.io.ByteArrayInputStream(compiler.get("runtime-catalog.properties")));
|
||||||
|
check(properties.getProperty("runtime.revision").matches("[0-9a-f]{40}"), "Missing target revision");
|
||||||
|
for (var name : names.subList(0, 2)) {
|
||||||
|
var digest = java.util.HexFormat.of().formatHex(java.security.MessageDigest.getInstance("SHA-256").digest(compiler.get(name)));
|
||||||
|
check(digest.equals(properties.getProperty(name + ".sha256")), "Packaged catalog hash mismatch: " + name);
|
||||||
|
}
|
||||||
|
System.out.println("Installed compiler/SDK catalog identity verified: " + properties.getProperty("runtime.revision"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void verifyExternalSources(ClassLoader loader) throws Exception {
|
||||||
|
var resource = loader.getResource("game/stdlib/1/sdk/gfx/main.pbs");
|
||||||
|
check(resource != null && resource.getProtocol().equals("jar"), "SDK must be read from a JAR URL");
|
||||||
|
check(p.studio.lsp.services.compiler.CompilerLanguageServiceBridge.class.getProtectionDomain()
|
||||||
|
.getCodeSource().getLocation().getPath().endsWith(".jar"), "LSP bridge must come from installed JAR");
|
||||||
|
Path root = Files.createDirectory(Path.of("external-sources")).toRealPath();
|
||||||
|
Files.createDirectories(root.resolve("src"));
|
||||||
|
Files.writeString(root.resolve("prometeu.json"), """
|
||||||
|
{"name":"app","version":"1.0.0","language":"pbs","stdlib":"1","target":"Game","dependencies":[]}
|
||||||
|
""");
|
||||||
|
String source = "import { Gfx } from @sdk:gfx;\nfn main() -> void { Gfx.clear(0); }\n";
|
||||||
|
Path file = Files.writeString(root.resolve("src/main.pbs"), source);
|
||||||
|
Files.writeString(root.resolve("src/mod.barrel"), "pub fn main() -> void;\n");
|
||||||
|
var context = new p.studio.lsp.messages.LspProjectContext("installed", "pbs", root);
|
||||||
|
var bridge = new p.studio.lsp.services.compiler.CompilerLanguageServiceBridge();
|
||||||
|
try (var registry = new p.studio.lsp.services.compiler.ExternalSourceRegistry()) {
|
||||||
|
String consumer = registry.connect(null, false);
|
||||||
|
int[] sdkUse = position(source, "Gfx.clear", "Gfx.".length());
|
||||||
|
var targets = bridge.navigation(context, file.toUri().toString(), source, sdkUse[0], sdkUse[1], registry, consumer).locations();
|
||||||
|
check(targets.size() == 1, "Packaged SDK definition must resolve");
|
||||||
|
String uri = targets.getFirst().uri();
|
||||||
|
check(uri.startsWith("prometeu-source:"), "SDK must use a virtual URI");
|
||||||
|
var content = registry.read(consumer, uri);
|
||||||
|
check(content.descriptor().readOnly() && content.descriptor().origin().equals("bundled"), "Bundled SDK must be read-only");
|
||||||
|
try (var stream = resource.openStream()) {
|
||||||
|
check(content.text().equals(new String(stream.readAllBytes(), java.nio.charset.StandardCharsets.UTF_8)), "SDK text must exactly match JAR bytes");
|
||||||
|
}
|
||||||
|
int[] hostUse = position(content.text(), "LowGfx.clear", "LowGfx.".length());
|
||||||
|
check(bridge.externalHover(context, uri, hostUse[0], hostUse[1], registry, consumer).markdown().contains("clear"), "SDK hover must work");
|
||||||
|
var host = bridge.navigation(context, uri, null, hostUse[0], hostUse[1], registry, consumer).locations().getFirst();
|
||||||
|
check(registry.read(consumer, host.uri()).text().split("\n")[host.startLine()].contains("clear"), "SDK to host definition range must match");
|
||||||
|
check(!bridge.externalSemanticTokens(context, uri, registry, consumer).tokens().isEmpty(), "SDK semantic highlighting must work");
|
||||||
|
int[] colorUse = position(content.text(), "color: Color", 7);
|
||||||
|
var core = bridge.navigation(context, uri, null, colorUse[0], colorUse[1], registry, consumer).locations().getFirst();
|
||||||
|
var coreContent = registry.read(consumer, core.uri());
|
||||||
|
check(coreContent.descriptor().readOnly() && coreContent.descriptor().name().replace('\\', '/').contains("core/color"), "SDK to core definition must resolve");
|
||||||
|
var coreResource = loader.getResource("game/stdlib/1/core/color/main.pbs");
|
||||||
|
check(coreResource != null && coreResource.getProtocol().equals("jar"), "Core must be read from a JAR URL");
|
||||||
|
try (var stream = coreResource.openStream()) {
|
||||||
|
check(coreContent.text().equals(new String(stream.readAllBytes(), java.nio.charset.StandardCharsets.UTF_8)), "Core text must exactly match JAR bytes");
|
||||||
|
}
|
||||||
|
check(coreContent.text().split("\n")[core.startLine()].contains("Color"), "Core definition range must match");
|
||||||
|
registry.disconnect(consumer);
|
||||||
|
registry.connect(consumer, false);
|
||||||
|
check(registry.revalidate(consumer, uri, path -> bridge.currentSource(context, path)).text().equals(content.text()), "Bundled source must revalidate after reconnect");
|
||||||
|
}
|
||||||
|
try (var files = Files.walk(root)) {
|
||||||
|
check(files.filter(Files::isRegularFile).map(root::relativize).map(Path::toString).collect(java.util.stream.Collectors.toSet())
|
||||||
|
.equals(java.util.Set.of("prometeu.json", "src/main.pbs", "src/mod.barrel")), "Navigation must not extract bundled sources into the project");
|
||||||
|
}
|
||||||
|
System.out.println("Packaged external sources verified: JAR bytes, SDK/host/core navigation, hover, tokens, read-only, reconnect, no extraction");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int[] position(String text, String needle, int offset) {
|
||||||
|
int index = text.indexOf(needle);
|
||||||
|
check(index >= 0, "Missing source fragment: " + needle);
|
||||||
|
String prefix = text.substring(0, index + offset);
|
||||||
|
return new int[] {(int) prefix.chars().filter(c -> c == '\n').count(), prefix.length() - prefix.lastIndexOf('\n') - 1};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,17 @@ class InstalledKnowledgeTest {
|
|||||||
@TempDir Path outsideRepository;
|
@TempDir Path outsideRepository;
|
||||||
|
|
||||||
@Test void installedJarsProvideAllReferencesAndCompileTheExampleOutsideTheCheckout() throws Exception {
|
@Test void installedJarsProvideAllReferencesAndCompileTheExampleOutsideTheCheckout() throws Exception {
|
||||||
|
String log = runProbe();
|
||||||
|
assertTrue(log.contains("references; example compiled"), log);
|
||||||
|
assertTrue(log.contains("Packaged external sources verified"), log);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test void installedCompilerAndSdkCarryTheSameVerifiedCatalog() throws Exception {
|
||||||
|
String log = runProbe("--catalog-only");
|
||||||
|
assertTrue(log.contains("Installed compiler/SDK catalog identity verified"), log);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String runProbe(String... arguments) throws Exception {
|
||||||
Path distribution = Path.of(System.getProperty("studio.test.distribution"));
|
Path distribution = Path.of(System.getProperty("studio.test.distribution"));
|
||||||
String jars;
|
String jars;
|
||||||
try (var files = Files.list(distribution.resolve("lib"))) {
|
try (var files = Files.list(distribution.resolve("lib"))) {
|
||||||
@@ -20,14 +31,16 @@ class InstalledKnowledgeTest {
|
|||||||
}
|
}
|
||||||
String probeClasses = Path.of(InstalledKnowledgeProbe.class.getProtectionDomain().getCodeSource().getLocation().toURI()).toString();
|
String probeClasses = Path.of(InstalledKnowledgeProbe.class.getProtectionDomain().getCodeSource().getLocation().toURI()).toString();
|
||||||
Path output = outsideRepository.resolve("probe.log");
|
Path output = outsideRepository.resolve("probe.log");
|
||||||
var process = new ProcessBuilder(Path.of(System.getProperty("java.home"), "bin", "java").toString(),
|
var command = new java.util.ArrayList<>(java.util.List.of(distribution.resolve("runtime/bin/java").toString(),
|
||||||
"-cp", jars + java.io.File.pathSeparator + probeClasses, InstalledKnowledgeProbe.class.getName())
|
"-cp", jars + java.io.File.pathSeparator + probeClasses, InstalledKnowledgeProbe.class.getName()));
|
||||||
|
command.addAll(java.util.List.of(arguments));
|
||||||
|
var process = new ProcessBuilder(command)
|
||||||
.directory(outsideRepository.toFile()).redirectErrorStream(true).redirectOutput(output.toFile()).start();
|
.directory(outsideRepository.toFile()).redirectErrorStream(true).redirectOutput(output.toFile()).start();
|
||||||
try {
|
try {
|
||||||
assertTrue(process.waitFor(45, TimeUnit.SECONDS), "Installed knowledge probe timed out");
|
assertTrue(process.waitFor(45, TimeUnit.SECONDS), "Installed knowledge probe timed out");
|
||||||
String log = Files.readString(output);
|
String log = Files.readString(output);
|
||||||
assertEquals(0, process.exitValue(), log);
|
assertEquals(0, process.exitValue(), log);
|
||||||
assertTrue(log.contains("references; example compiled"), log);
|
return log;
|
||||||
} finally { if (process.isAlive()) process.destroyForcibly().waitFor(); }
|
} finally { if (process.isAlive()) process.destroyForcibly().waitFor(); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
package p.studio.app.install;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
|
import p.studio.app.mcp.StudioAgentPreparation;
|
||||||
|
import p.studio.core.project.*;
|
||||||
|
import p.studio.api.project.*;
|
||||||
|
import java.nio.file.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class InstalledConnectorTest {
|
||||||
|
@TempDir Path temporary;
|
||||||
|
@Test void bundledJavaAndStableUpdateWorkWithSpacesMinimalEnvironmentAndBothPreparationPaths() throws Exception {
|
||||||
|
Path base = temporary.resolve("Application Support/Studio");
|
||||||
|
Path source = Path.of(System.getProperty("studio.test.distribution"));
|
||||||
|
Path first = ManagedStudioInstallation.install(source, base);
|
||||||
|
var mapper = new ObjectMapper();
|
||||||
|
var preparation = new StudioAgentPreparation(base, mapper);
|
||||||
|
var catalog = new ProjectCatalogService(temporary, mapper, new ProjectLocalStudioSetupStore(mapper), preparation);
|
||||||
|
var scaffold = catalog.createProject(new ProjectCreationRequest("Scaffold Game", temporary, "pbs", 1, ProjectTarget.Game, "src", 8, "/my/runtime"));
|
||||||
|
assertTrue(preparation.status(scaffold.rootPath()).ready());
|
||||||
|
Path existing = Files.createDirectory(temporary.resolve("Existing Project"));
|
||||||
|
Files.copy(scaffold.rootPath().resolve("prometeu.json"), existing.resolve("prometeu.json"));
|
||||||
|
Files.createDirectory(existing.resolve(".studio"));
|
||||||
|
Files.writeString(existing.resolve(".studio/setup.json"), "{\"runtimePath\":\"/preserved/runtime\",\"custom\":42}");
|
||||||
|
Files.createDirectory(existing.resolve(".codex"));
|
||||||
|
String custom = "# preserve\napproval_policy = \"on-request\"\n[mcp_servers.other]\ncommand = \"other\"\n";
|
||||||
|
Files.writeString(existing.resolve(".codex/config.toml"), custom);
|
||||||
|
assertTrue(preparation.prepare(existing).ready());
|
||||||
|
var config = existing.resolve(".codex/config.toml");
|
||||||
|
String stable = Files.readString(config); var modified = Files.getLastModifiedTime(config);
|
||||||
|
assertTrue(stable.startsWith(custom)); assertTrue(preparation.prepare(existing).ready());
|
||||||
|
assertEquals(stable, Files.readString(config)); assertEquals(modified, Files.getLastModifiedTime(config));
|
||||||
|
var setup = mapper.readTree(Files.readString(existing.resolve(".studio/setup.json")));
|
||||||
|
assertEquals(42, setup.path("custom").asInt()); assertEquals("/preserved/runtime", setup.path("runtimePath").asText());
|
||||||
|
assertFalse(Files.exists(existing.resolve(".studio/mcp/connection.json")));
|
||||||
|
runConnector(base, existing);
|
||||||
|
Path second = ManagedStudioInstallation.install(source, base);
|
||||||
|
assertNotEquals(first, second); assertTrue(Files.isDirectory(first));
|
||||||
|
assertEquals(second.toRealPath(), base.resolve("current").toRealPath());
|
||||||
|
assertEquals(stable, Files.readString(config)); runConnector(base, existing);
|
||||||
|
assertThrows(Exception.class, () -> ManagedStudioInstallation.install(existing, base));
|
||||||
|
assertEquals(second.toRealPath(), base.resolve("current").toRealPath()); runConnector(base, existing);
|
||||||
|
// Test fixture only: installed runtime/lib must load and start JavaFX, without checkout application classes.
|
||||||
|
String fixtures = Path.of(DesktopProbe.class.getProtectionDomain().getCodeSource().getLocation().toURI()).toString();
|
||||||
|
var desktop = minimal(base.resolve("current/runtime/bin/java").toString(), "-cp", base.resolve("current/lib/*") + java.io.File.pathSeparator + fixtures,
|
||||||
|
DesktopProbe.class.getName()).redirectError(temporary.resolve("desktop.stderr").toFile()).start();
|
||||||
|
try { assertTrue(desktop.waitFor(20, TimeUnit.SECONDS)); assertEquals(0, desktop.exitValue(), Files.readString(temporary.resolve("desktop.stderr"))); }
|
||||||
|
finally { desktop.destroyForcibly(); }
|
||||||
|
}
|
||||||
|
void runConnector(Path base, Path root) throws Exception {
|
||||||
|
var process = minimal(base.resolve("current/runtime/bin/java").toString(), "-cp", base.resolve("current/lib/*").toString(),
|
||||||
|
"p.studio.app.StudioLauncher", "mcp", "--project", root.toRealPath().toString()).start();
|
||||||
|
try {
|
||||||
|
String input = "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"initialize\",\"params\":{\"protocolVersion\":\"2025-06-18\",\"capabilities\":{},\"clientInfo\":{\"name\":\"installed-test\",\"version\":\"1\"}}}\n";
|
||||||
|
process.getOutputStream().write(input.getBytes(java.nio.charset.StandardCharsets.UTF_8)); process.getOutputStream().close();
|
||||||
|
assertTrue(process.waitFor(15, TimeUnit.SECONDS)); assertEquals(0, process.exitValue());
|
||||||
|
assertEquals("prometeu-studio", new ObjectMapper().readTree(process.getInputStream()).path("result").path("serverInfo").path("name").asText());
|
||||||
|
} finally { process.destroyForcibly(); }
|
||||||
|
}
|
||||||
|
ProcessBuilder minimal(String... args) {
|
||||||
|
var builder = new ProcessBuilder(args).directory(temporary.toFile());
|
||||||
|
builder.environment().clear(); builder.environment().put("PATH", "/usr/bin:/bin"); builder.environment().put("HOME", System.getProperty("user.home"));
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
public static class DesktopProbe {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
javafx.application.Platform.startup(() -> {
|
||||||
|
try {
|
||||||
|
var stage = new javafx.stage.Stage(); stage.setScene(new javafx.scene.Scene(new javafx.scene.control.Label("Installed Studio JavaFX")));
|
||||||
|
stage.show(); stage.close(); System.exit(0);
|
||||||
|
} catch (Throwable failure) { System.exit(2); }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,6 +18,7 @@ import java.util.concurrent.*;
|
|||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
class AutomationLspQueriesTest {
|
class AutomationLspQueriesTest {
|
||||||
|
String httpAuthorization;
|
||||||
@TempDir Path temporary;
|
@TempDir Path temporary;
|
||||||
final ObjectMapper mapper = new ObjectMapper();
|
final ObjectMapper mapper = new ObjectMapper();
|
||||||
final ExecutorService workers = Executors.newCachedThreadPool();
|
final ExecutorService workers = Executors.newCachedThreadPool();
|
||||||
@@ -53,6 +54,36 @@ class AutomationLspQueriesTest {
|
|||||||
Map<String, Object> at(int line, int character) {
|
Map<String, Object> at(int line, int character) {
|
||||||
return Map.of("uri", source.toUri().toString(), "position", Map.of("line", line, "character", character));
|
return Map.of("uri", source.toUri().toString(), "position", Map.of("line", line, "character", character));
|
||||||
}
|
}
|
||||||
|
@Test void bundledSourcesAreReadableAcrossConnectionsAndOwnedByTheTask() throws Exception {
|
||||||
|
Files.writeString(source, "import { Gfx } from @sdk:gfx;\nfn main() -> void { Gfx.clear(0); }\n");
|
||||||
|
Files.writeString(source.resolveSibling("mod.barrel"), "pub fn main() -> void;\n");
|
||||||
|
acquire();
|
||||||
|
final var definition = query("definition", at(1, 24)).path("result");
|
||||||
|
assertFalse(definition.isEmpty(), definition.toString());
|
||||||
|
final String uri = definition.get(0).path("uri").asText();
|
||||||
|
assertTrue(uri.startsWith("prometeu-source:"), uri);
|
||||||
|
final var content = query("readExternalSource", Map.of("uri", uri)).path("result");
|
||||||
|
assertTrue(content.path("descriptor").path("readOnly").asBoolean());
|
||||||
|
assertEquals("bundled", content.path("descriptor").path("origin").asText());
|
||||||
|
final String text = content.path("text").asText();
|
||||||
|
final int offset = text.indexOf("LowGfx.clear") + "LowGfx.".length();
|
||||||
|
assertTrue(offset > "LowGfx.".length());
|
||||||
|
final String prefix = text.substring(0, offset);
|
||||||
|
final var position = Map.of("line", (int) prefix.chars().filter(c -> c == '\n').count(),
|
||||||
|
"character", offset - prefix.lastIndexOf('\n') - 1);
|
||||||
|
final var request = Map.<String, Object>of("uri", uri, "position", position);
|
||||||
|
assertTrue(query("hover", request).path("result").toString().contains("clear"));
|
||||||
|
final var host = query("definition", request).path("result");
|
||||||
|
assertFalse(host.isEmpty());
|
||||||
|
assertTrue(query("readExternalSource", Map.of("uri", host.get(0).path("uri").asText()))
|
||||||
|
.path("result").path("text").asText().contains("declare host LowGfx"));
|
||||||
|
assertEquals(AutomationFailure.Code.READ_ONLY_SCOPE, assertThrows(AutomationException.class,
|
||||||
|
() -> query("formatting", request)).failure().code());
|
||||||
|
session.automation().reclaim().toCompletableFuture().join();
|
||||||
|
acquire();
|
||||||
|
assertEquals(AutomationFailure.Code.OUTSIDE_PROJECT_SCOPE, assertThrows(AutomationException.class,
|
||||||
|
() -> query("readExternalSource", Map.of("uri", uri))).failure().code());
|
||||||
|
}
|
||||||
@Test void diagnosticsAndNavigationSeeSavedChangesOverTheActualServer() throws Exception {
|
@Test void diagnosticsAndNavigationSeeSavedChangesOverTheActualServer() throws Exception {
|
||||||
acquire();
|
acquire();
|
||||||
assertTrue(query("diagnostics", at(0, 0)).path("result").isArray());
|
assertTrue(query("diagnostics", at(0, 0)).path("result").isArray());
|
||||||
@@ -134,6 +165,8 @@ class AutomationLspQueriesTest {
|
|||||||
try (var server = new p.studio.app.mcp.LocalMcpServer(mapper, tools);
|
try (var server = new p.studio.app.mcp.LocalMcpServer(mapper, tools);
|
||||||
var client = java.net.http.HttpClient.newHttpClient()) {
|
var client = java.net.http.HttpClient.newHttpClient()) {
|
||||||
server.start();
|
server.start();
|
||||||
|
var credential = server.credentials().prepare(root.toRealPath());
|
||||||
|
credential.activate(); httpAuthorization = "Bearer " + credential.secret();
|
||||||
var initialize = mapper.createObjectNode().put("jsonrpc", "2.0").put("id", 1).put("method", "initialize");
|
var initialize = mapper.createObjectNode().put("jsonrpc", "2.0").put("id", 1).put("method", "initialize");
|
||||||
var setup = initialize.putObject("params").put("protocolVersion", "2025-06-18");
|
var setup = initialize.putObject("params").put("protocolVersion", "2025-06-18");
|
||||||
setup.putObject("capabilities"); setup.putObject("clientInfo").put("name", "language-test").put("version", "1");
|
setup.putObject("capabilities"); setup.putObject("clientInfo").put("name", "language-test").put("version", "1");
|
||||||
@@ -155,7 +188,7 @@ class AutomationLspQueriesTest {
|
|||||||
private java.net.http.HttpResponse<String> post(java.net.http.HttpClient client, p.studio.app.mcp.LocalMcpServer server,
|
private java.net.http.HttpResponse<String> post(java.net.http.HttpClient client, p.studio.app.mcp.LocalMcpServer server,
|
||||||
String connection, JsonNode body) throws Exception {
|
String connection, JsonNode body) throws Exception {
|
||||||
var request = java.net.http.HttpRequest.newBuilder(server.connection().endpoint()).timeout(java.time.Duration.ofSeconds(15))
|
var request = java.net.http.HttpRequest.newBuilder(server.connection().endpoint()).timeout(java.time.Duration.ofSeconds(15))
|
||||||
.header("Authorization", server.connection().authorizationHeader()).header("Content-Type", "application/json")
|
.header("Authorization", httpAuthorization).header("Content-Type", "application/json")
|
||||||
.header("Accept", "application/json, text/event-stream").header("MCP-Protocol-Version", "2025-06-18");
|
.header("Accept", "application/json, text/event-stream").header("MCP-Protocol-Version", "2025-06-18");
|
||||||
if (connection != null) request.header("Mcp-Session-Id", connection);
|
if (connection != null) request.header("Mcp-Session-Id", connection);
|
||||||
return client.send(request.POST(java.net.http.HttpRequest.BodyPublishers.ofString(body.toString())).build(), java.net.http.HttpResponse.BodyHandlers.ofString());
|
return client.send(request.POST(java.net.http.HttpRequest.BodyPublishers.ofString(body.toString())).build(), java.net.http.HttpResponse.BodyHandlers.ofString());
|
||||||
@@ -183,26 +216,43 @@ class AutomationLspQueriesTest {
|
|||||||
assertTrue(cleaned.get());
|
assertTrue(cleaned.get());
|
||||||
assertEquals(ControlState.MANUAL, session.automation().snapshot().state());
|
assertEquals(ControlState.MANUAL, session.automation().snapshot().state());
|
||||||
}
|
}
|
||||||
@Test void externalDependencyNavigationIsReadableButRefactoringIsReadOnly() throws Exception {
|
@org.junit.jupiter.params.ParameterizedTest
|
||||||
Path lib = Files.createDirectories(temporary.resolve("lib")).toRealPath();
|
@org.junit.jupiter.params.provider.ValueSource(booleans = {false, true})
|
||||||
|
void externalDependencyNavigationIsReadableButRefactoringIsReadOnly(boolean inWorkspace) throws Exception {
|
||||||
|
Path lib = Files.createDirectories(inWorkspace ? root.resolve(".workspace/repos/lib") : temporary.resolve("lib")).toRealPath();
|
||||||
manifest(lib, "lib", List.of());
|
manifest(lib, "lib", List.of());
|
||||||
Path module = Files.createDirectories(lib.resolve("src/shared"));
|
Path module = Files.createDirectories(lib.resolve("src/shared"));
|
||||||
Path declaration = module.resolve("main.pbs");
|
Path declaration = module.resolve("main.pbs");
|
||||||
Files.writeString(declaration, "fn answer() -> int { return 42; }\n");
|
Files.writeString(declaration, "// á 😀\r\nfn answer() -> int { return helper(); }\r\nfn helper() -> int { return 42; }\r\n");
|
||||||
Files.writeString(module.resolve("mod.barrel"), "pub fn answer() -> int;\n");
|
Files.writeString(module.resolve("mod.barrel"), "pub fn answer() -> int;\n");
|
||||||
manifest(root, "app", List.of(Map.of("path", "../lib")));
|
manifest(root, "app", List.of(Map.of("path", inWorkspace ? ".workspace/repos/lib" : "../lib")));
|
||||||
Files.createDirectories(root.resolve(".workspace/repos")); Files.writeString(root.resolve(".workspace/repos/registry.json"), "{}");
|
Files.createDirectories(root.resolve(".workspace/repos")); Files.writeString(root.resolve(".workspace/repos/registry.json"), "{}");
|
||||||
Files.writeString(source, "import { answer } from @lib:shared;\nfn main() -> int { return answer(); }\n");
|
Files.writeString(source, "import { answer } from @lib:shared;\nfn main() -> int { return answer(); }\n");
|
||||||
Files.writeString(source.resolveSibling("mod.barrel"), "pub fn main() -> int;\n");
|
Files.writeString(source.resolveSibling("mod.barrel"), "pub fn main() -> int;\n");
|
||||||
acquire();
|
acquire();
|
||||||
var locations = query("definition", at(1, 26)).path("result");
|
var locations = query("definition", at(1, 26)).path("result");
|
||||||
assertFalse(locations.isEmpty(), locations.toString());
|
assertFalse(locations.isEmpty(), locations.toString());
|
||||||
assertEquals(declaration.toUri().toString(), locations.get(0).path("uri").asText());
|
assertTrue(locations.get(0).path("uri").asText().startsWith("prometeu-source:"));
|
||||||
|
assertEquals(Files.readString(declaration), query("readExternalSource", Map.of("uri", locations.get(0).path("uri").asText())).path("result").path("text").asText());
|
||||||
|
final String externalUri = locations.get(0).path("uri").asText();
|
||||||
|
assertEquals(1, locations.get(0).path("range").path("start").path("line").asInt());
|
||||||
|
final var nested = query("definition", Map.of("uri", externalUri, "position", Map.of("line", 1, "character", 28))).path("result");
|
||||||
|
assertFalse(nested.isEmpty(), nested.toString());
|
||||||
|
assertEquals(2, nested.get(0).path("range").path("start").path("line").asInt());
|
||||||
assertEquals("documentSymbols", query("documentSymbols", Map.of("uri", declaration.toUri().toString())).path("operation").asText());
|
assertEquals("documentSymbols", query("documentSymbols", Map.of("uri", declaration.toUri().toString())).path("operation").asText());
|
||||||
assertEquals(AutomationFailure.Code.READ_ONLY_SCOPE, assertThrows(AutomationException.class,
|
assertEquals(AutomationFailure.Code.READ_ONLY_SCOPE, assertThrows(AutomationException.class,
|
||||||
() -> query("formatting", Map.of("uri", declaration.toUri().toString()))).failure().code());
|
() -> query("formatting", Map.of("uri", declaration.toUri().toString()))).failure().code());
|
||||||
|
final Path alias = Files.createSymbolicLink(root.resolve("src/dependency-alias.pbs"), declaration);
|
||||||
|
assertEquals(AutomationFailure.Code.READ_ONLY_SCOPE, assertThrows(AutomationException.class,
|
||||||
|
() -> query("formatting", Map.of("uri", alias.toUri().toString()))).failure().code());
|
||||||
var rename = new HashMap<>(at(1, 26)); rename.put("newName", "renamed");
|
var rename = new HashMap<>(at(1, 26)); rename.put("newName", "renamed");
|
||||||
assertEquals(AutomationFailure.Code.READ_ONLY_SCOPE, assertThrows(AutomationException.class, () -> query("rename", rename)).failure().code());
|
assertEquals(AutomationFailure.Code.READ_ONLY_SCOPE, assertThrows(AutomationException.class, () -> query("rename", rename)).failure().code());
|
||||||
|
final String oldText = Files.readString(declaration);
|
||||||
|
Files.writeString(declaration, "// changed revision\n" + oldText);
|
||||||
|
assertThrows(AutomationException.class, () -> query("readExternalSource", Map.of("uri", externalUri)));
|
||||||
|
final var renewed = query("definition", at(1, 26)).path("result");
|
||||||
|
assertNotEquals(externalUri, renewed.get(0).path("uri").asText());
|
||||||
|
assertEquals(2, renewed.get(0).path("range").path("start").path("line").asInt());
|
||||||
}
|
}
|
||||||
private void manifest(Path path, String name, List<?> dependencies) throws Exception {
|
private void manifest(Path path, String name, List<?> dependencies) throws Exception {
|
||||||
mapper.writeValue(path.resolve("prometeu.json").toFile(), Map.of("name", name, "version", "1.0.0", "language", "pbs", "stdlib", "1", "target", "Game", "dependencies", dependencies));
|
mapper.writeValue(path.resolve("prometeu.json").toFile(), Map.of("name", name, "version", "1.0.0", "language", "pbs", "stdlib", "1", "target", "Game", "dependencies", dependencies));
|
||||||
|
|||||||
@@ -15,6 +15,12 @@ class LocalMcpServerTest {
|
|||||||
final HttpClient client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(3)).build();
|
final HttpClient client = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(3)).build();
|
||||||
LocalMcpServer server;
|
LocalMcpServer server;
|
||||||
String session;
|
String session;
|
||||||
|
@org.junit.jupiter.api.io.TempDir java.nio.file.Path root;
|
||||||
|
String authorization;
|
||||||
|
void authorize(java.nio.file.Path project) throws Exception {
|
||||||
|
var credential = server.credentials().prepare(project.toRealPath());
|
||||||
|
credential.activate(); authorization = "Bearer " + credential.secret();
|
||||||
|
}
|
||||||
AtomicInteger calls;
|
AtomicInteger calls;
|
||||||
|
|
||||||
@BeforeEach void start() throws Exception {
|
@BeforeEach void start() throws Exception {
|
||||||
@@ -22,7 +28,7 @@ class LocalMcpServerTest {
|
|||||||
server = new LocalMcpServer(mapper, new McpToolRegistry(new McpToolCatalog(mapper), mapper, Map.of(
|
server = new LocalMcpServer(mapper, new McpToolRegistry(new McpToolCatalog(mapper), mapper, Map.of(
|
||||||
"studio_project_context", args -> { calls.incrementAndGet(); return McpToolResult.success(mapper, mapper.createObjectNode().put("projectRoot", args.get("projectRoot").asText())); },
|
"studio_project_context", args -> { calls.incrementAndGet(); return McpToolResult.success(mapper, mapper.createObjectNode().put("projectRoot", args.get("projectRoot").asText())); },
|
||||||
"studio_control_acquire", args -> McpToolResult.failure(mapper, new AutomationFailure(AutomationFailure.Code.NOT_GRANTED, "Human grant required")))));
|
"studio_control_acquire", args -> McpToolResult.failure(mapper, new AutomationFailure(AutomationFailure.Code.NOT_GRANTED, "Human grant required")))));
|
||||||
server.start();
|
server.start(); authorize(root);
|
||||||
}
|
}
|
||||||
@AfterEach void close() { server.close(); client.close(); }
|
@AfterEach void close() { server.close(); client.close(); }
|
||||||
HttpResponse<String> request(String method, URI uri, String body, String token, String origin, String protocol, String sessionId) throws Exception {
|
HttpResponse<String> request(String method, URI uri, String body, String token, String origin, String protocol, String sessionId) throws Exception {
|
||||||
@@ -35,7 +41,7 @@ class LocalMcpServerTest {
|
|||||||
return client.send(request.method(method, body == null ? HttpRequest.BodyPublishers.noBody() : HttpRequest.BodyPublishers.ofString(body)).build(), HttpResponse.BodyHandlers.ofString());
|
return client.send(request.method(method, body == null ? HttpRequest.BodyPublishers.noBody() : HttpRequest.BodyPublishers.ofString(body)).build(), HttpResponse.BodyHandlers.ofString());
|
||||||
}
|
}
|
||||||
HttpResponse<String> post(String body) throws Exception {
|
HttpResponse<String> post(String body) throws Exception {
|
||||||
return request("POST", server.connection().endpoint(), body, server.connection().authorizationHeader(), null, LocalMcpServer.PROTOCOL_VERSION, session);
|
return request("POST", server.connection().endpoint(), body.replace("/project", root.toRealPath().toString()), authorization, null, LocalMcpServer.PROTOCOL_VERSION, session);
|
||||||
}
|
}
|
||||||
static String init() { return "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"initialize\",\"params\":{\"protocolVersion\":\"2025-06-18\",\"clientInfo\":{\"name\":\"test-client\",\"version\":\"1\"},\"capabilities\":{}}}"; }
|
static String init() { return "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"initialize\",\"params\":{\"protocolVersion\":\"2025-06-18\",\"clientInfo\":{\"name\":\"test-client\",\"version\":\"1\"},\"capabilities\":{}}}"; }
|
||||||
void initialize() throws Exception {
|
void initialize() throws Exception {
|
||||||
@@ -51,11 +57,11 @@ class LocalMcpServerTest {
|
|||||||
var response = post("{\"jsonrpc\":\"2.0\",\"id\":3,\"method\":\"tools/call\",\"params\":{\"name\":\"studio_project_context\",\"arguments\":{\"projectRoot\":\"/project\"}}}");
|
var response = post("{\"jsonrpc\":\"2.0\",\"id\":3,\"method\":\"tools/call\",\"params\":{\"name\":\"studio_project_context\",\"arguments\":{\"projectRoot\":\"/project\"}}}");
|
||||||
assertEquals(200, response.statusCode()); assertEquals(1, calls.get());
|
assertEquals(200, response.statusCode()); assertEquals(1, calls.get());
|
||||||
assertEquals("ok", mapper.readTree(response.body()).path("result").path("structuredContent").path("status").asText());
|
assertEquals("ok", mapper.readTree(response.body()).path("result").path("structuredContent").path("status").asText());
|
||||||
assertEquals(200, request("DELETE", server.connection().endpoint(), null, server.connection().authorizationHeader(), null, null, session).statusCode());
|
assertEquals(200, request("DELETE", server.connection().endpoint(), null, authorization, null, null, session).statusCode());
|
||||||
assertEquals(404, post("{\"jsonrpc\":\"2.0\",\"id\":4,\"method\":\"ping\"}").statusCode());
|
assertEquals(404, post("{\"jsonrpc\":\"2.0\",\"id\":4,\"method\":\"ping\"}").statusCode());
|
||||||
}
|
}
|
||||||
@Test void authAndOriginAreCheckedBeforeProtocolOrTools() throws Exception {
|
@Test void authAndOriginAreCheckedBeforeProtocolOrTools() throws Exception {
|
||||||
var endpoint = server.connection().endpoint(); var token = server.connection().authorizationHeader();
|
var endpoint = server.connection().endpoint(); var token = authorization;
|
||||||
assertEquals("127.0.0.1", endpoint.getHost()); assertTrue(endpoint.getPort() > 0);
|
assertEquals("127.0.0.1", endpoint.getHost()); assertTrue(endpoint.getPort() > 0);
|
||||||
assertEquals(401, request("POST", endpoint, init(), null, null, null, null).statusCode());
|
assertEquals(401, request("POST", endpoint, init(), null, null, null, null).statusCode());
|
||||||
assertEquals(401, request("POST", endpoint, init(), "Bearer wrong", null, null, null).statusCode());
|
assertEquals(401, request("POST", endpoint, init(), "Bearer wrong", null, null, null).statusCode());
|
||||||
@@ -66,10 +72,10 @@ class LocalMcpServerTest {
|
|||||||
assertFalse(server.connection().toString().contains(token.substring(7)));
|
assertFalse(server.connection().toString().contains(token.substring(7)));
|
||||||
}
|
}
|
||||||
@Test void restartChangesCredentialsInvalidatesConnectionsAndDoesNotPersistThem() throws Exception {
|
@Test void restartChangesCredentialsInvalidatesConnectionsAndDoesNotPersistThem() throws Exception {
|
||||||
initialize(); var old = server.connection(); server.close();
|
initialize(); var old = authorization; server.close();
|
||||||
assertFalse(server.isRunning()); assertThrows(IllegalStateException.class, server::connection);
|
assertFalse(server.isRunning()); assertThrows(IllegalStateException.class, server::connection);
|
||||||
server.start(); assertFalse(old.authorizationHeader().equals(server.connection().authorizationHeader()));
|
server.start(); authorize(root); assertFalse(old.equals(authorization));
|
||||||
assertEquals(401, request("POST", server.connection().endpoint(), init(), old.authorizationHeader(), null, null, null).statusCode());
|
assertEquals(401, request("POST", server.connection().endpoint(), init(), old, null, null, null).statusCode());
|
||||||
assertEquals(404, post(init()).statusCode());
|
assertEquals(404, post(init()).statusCode());
|
||||||
session = null; initialize();
|
session = null; initialize();
|
||||||
}
|
}
|
||||||
@@ -81,13 +87,13 @@ class LocalMcpServerTest {
|
|||||||
assertEquals(400, post("{\"jsonrpc\":\"2.0\",\"method\":123}").statusCode());
|
assertEquals(400, post("{\"jsonrpc\":\"2.0\",\"method\":123}").statusCode());
|
||||||
assertEquals(400, post("{\"jsonrpc\":\"2.0\",\"id\":1,\"id\":2,\"method\":\"ping\"}").statusCode());
|
assertEquals(400, post("{\"jsonrpc\":\"2.0\",\"id\":1,\"id\":2,\"method\":\"ping\"}").statusCode());
|
||||||
assertEquals(400, post("{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"ping\"} {}").statusCode());
|
assertEquals(400, post("{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"ping\"} {}").statusCode());
|
||||||
assertEquals(400, request("POST", server.connection().endpoint(), init(), server.connection().authorizationHeader(), null, "unknown", session).statusCode());
|
assertEquals(400, request("POST", server.connection().endpoint(), init(), authorization, null, "unknown", session).statusCode());
|
||||||
var bad = post("{\"jsonrpc\":\"2.0\",\"id\":3,\"method\":\"tools/call\",\"params\":{\"name\":\"studio_project_context\",\"arguments\":{\"projectRoot\":\"relative\"}}}");
|
var bad = post("{\"jsonrpc\":\"2.0\",\"id\":3,\"method\":\"tools/call\",\"params\":{\"name\":\"studio_project_context\",\"arguments\":{\"projectRoot\":\"relative\"}}}");
|
||||||
assertEquals(-32602, mapper.readTree(bad.body()).path("error").path("code").intValue()); assertEquals(0, calls.get());
|
assertEquals(-32602, mapper.readTree(bad.body()).path("error").path("code").intValue()); assertEquals(0, calls.get());
|
||||||
assertEquals(413, post(" ".repeat(1024 * 1024 + 1)).statusCode());
|
assertEquals(413, post(" ".repeat(1024 * 1024 + 1)).statusCode());
|
||||||
}
|
}
|
||||||
@Test void exactEndpointNoSseAndInitializationAreEnforced() throws Exception {
|
@Test void exactEndpointNoSseAndInitializationAreEnforced() throws Exception {
|
||||||
var endpoint = server.connection().endpoint(); var token = server.connection().authorizationHeader();
|
var endpoint = server.connection().endpoint(); var token = authorization;
|
||||||
assertEquals(400, post("{\"jsonrpc\":\"2.0\",\"id\":3,\"method\":\"tools/list\"}").statusCode());
|
assertEquals(400, post("{\"jsonrpc\":\"2.0\",\"id\":3,\"method\":\"tools/list\"}").statusCode());
|
||||||
var initialized = post(init()); session = initialized.headers().firstValue("Mcp-Session-Id").orElseThrow();
|
var initialized = post(init()); session = initialized.headers().firstValue("Mcp-Session-Id").orElseThrow();
|
||||||
assertEquals(-32600, mapper.readTree(post("{\"jsonrpc\":\"2.0\",\"id\":3,\"method\":\"tools/list\"}").body()).path("error").path("code").asInt());
|
assertEquals(-32600, mapper.readTree(post("{\"jsonrpc\":\"2.0\",\"id\":3,\"method\":\"tools/list\"}").body()).path("error").path("code").asInt());
|
||||||
@@ -117,7 +123,7 @@ class LocalMcpServerTest {
|
|||||||
server.close();
|
server.close();
|
||||||
server = new LocalMcpServer(mapper, new McpToolRegistry(new McpToolCatalog(mapper), mapper,
|
server = new LocalMcpServer(mapper, new McpToolRegistry(new McpToolCatalog(mapper), mapper,
|
||||||
McpProjectKnowledgeTools.handlers(knowledge, mapper)));
|
McpProjectKnowledgeTools.handlers(knowledge, mapper)));
|
||||||
server.start();
|
server.start(); authorize(root);
|
||||||
initialize();
|
initialize();
|
||||||
var call = mapper.createObjectNode().put("jsonrpc", "2.0").put("id", 2).put("method", "tools/call");
|
var call = mapper.createObjectNode().put("jsonrpc", "2.0").put("id", 2).put("method", "tools/call");
|
||||||
call.putObject("params").put("name", "studio_project_context").putObject("arguments").put("projectRoot", root.toString());
|
call.putObject("params").put("name", "studio_project_context").putObject("arguments").put("projectRoot", root.toString());
|
||||||
@@ -153,13 +159,13 @@ class LocalMcpServerTest {
|
|||||||
var connection = server.connection();
|
var connection = server.connection();
|
||||||
try (var socket = new java.net.Socket("127.0.0.1", connection.endpoint().getPort())) {
|
try (var socket = new java.net.Socket("127.0.0.1", connection.endpoint().getPort())) {
|
||||||
socket.setSoTimeout(3000);
|
socket.setSoTimeout(3000);
|
||||||
String request = "POST /mcp HTTP/1.1\r\nHost: evil.example\r\nAuthorization: " + connection.authorizationHeader()
|
String request = "POST /mcp HTTP/1.1\r\nHost: evil.example\r\nAuthorization: " + authorization
|
||||||
+ "\r\nContent-Length: 0\r\nConnection: close\r\n\r\n";
|
+ "\r\nContent-Length: 0\r\nConnection: close\r\n\r\n";
|
||||||
socket.getOutputStream().write(request.getBytes(java.nio.charset.StandardCharsets.UTF_8));
|
socket.getOutputStream().write(request.getBytes(java.nio.charset.StandardCharsets.UTF_8));
|
||||||
var status = new java.io.BufferedReader(new java.io.InputStreamReader(socket.getInputStream())).readLine();
|
var status = new java.io.BufferedReader(new java.io.InputStreamReader(socket.getInputStream())).readLine();
|
||||||
assertTrue(status.contains("403"));
|
assertTrue(status.contains("403"));
|
||||||
}
|
}
|
||||||
var request = HttpRequest.newBuilder(connection.endpoint()).header("Authorization", connection.authorizationHeader())
|
var request = HttpRequest.newBuilder(connection.endpoint()).header("Authorization", authorization)
|
||||||
.header("Origin", "http://" + connection.endpoint().getRawAuthority()).header("Origin", "https://evil.example")
|
.header("Origin", "http://" + connection.endpoint().getRawAuthority()).header("Origin", "https://evil.example")
|
||||||
.POST(HttpRequest.BodyPublishers.ofString(init())).build();
|
.POST(HttpRequest.BodyPublishers.ofString(init())).build();
|
||||||
assertEquals(403, client.send(request, HttpResponse.BodyHandlers.discarding()).statusCode());
|
assertEquals(403, client.send(request, HttpResponse.BodyHandlers.discarding()).statusCode());
|
||||||
@@ -167,13 +173,29 @@ class LocalMcpServerTest {
|
|||||||
|
|
||||||
@Test void contentNegotiationAcceptsWeightedTypesAndRejectsInvalidUtf8() throws Exception {
|
@Test void contentNegotiationAcceptsWeightedTypesAndRejectsInvalidUtf8() throws Exception {
|
||||||
var connection = server.connection();
|
var connection = server.connection();
|
||||||
var request = HttpRequest.newBuilder(connection.endpoint()).header("Authorization", connection.authorizationHeader())
|
var request = HttpRequest.newBuilder(connection.endpoint()).header("Authorization", authorization)
|
||||||
.header("Accept", "application/json;q=1, text/event-stream;q=0.5").header("Content-Type", "application/json")
|
.header("Accept", "application/json;q=1, text/event-stream;q=0.5").header("Content-Type", "application/json")
|
||||||
.POST(HttpRequest.BodyPublishers.ofString(init())).build();
|
.POST(HttpRequest.BodyPublishers.ofString(init())).build();
|
||||||
assertEquals(200, client.send(request, HttpResponse.BodyHandlers.discarding()).statusCode());
|
assertEquals(200, client.send(request, HttpResponse.BodyHandlers.discarding()).statusCode());
|
||||||
var invalid = HttpRequest.newBuilder(connection.endpoint()).header("Authorization", connection.authorizationHeader())
|
var invalid = HttpRequest.newBuilder(connection.endpoint()).header("Authorization", authorization)
|
||||||
.header("Accept", "application/json, text/event-stream").header("Content-Type", "application/json")
|
.header("Accept", "application/json, text/event-stream").header("Content-Type", "application/json")
|
||||||
.POST(HttpRequest.BodyPublishers.ofByteArray(new byte[]{(byte) 0xc3, (byte) 0x28})).build();
|
.POST(HttpRequest.BodyPublishers.ofByteArray(new byte[]{(byte) 0xc3, (byte) 0x28})).build();
|
||||||
assertEquals(400, client.send(invalid, HttpResponse.BodyHandlers.discarding()).statusCode());
|
assertEquals(400, client.send(invalid, HttpResponse.BodyHandlers.discarding()).statusCode());
|
||||||
}
|
}
|
||||||
|
@Test void projectCredentialsCannotCrossRootsOrReuseAnotherSession() throws Exception {
|
||||||
|
initialize();
|
||||||
|
var other = java.nio.file.Files.createDirectory(root.resolve("other")).toRealPath();
|
||||||
|
var credential = server.credentials().prepare(other); credential.activate();
|
||||||
|
var wire = "{\"jsonrpc\":\"2.0\",\"id\":4,\"method\":\"tools/list\"}";
|
||||||
|
assertEquals(403, request("POST", server.connection().endpoint(), wire, "Bearer " + credential.secret(), null,
|
||||||
|
LocalMcpServer.PROTOCOL_VERSION, session).statusCode());
|
||||||
|
var call = mapper.createObjectNode().put("jsonrpc", "2.0").put("id", 5).put("method", "tools/call");
|
||||||
|
call.putObject("params").put("name", "studio_project_context").putObject("arguments").put("projectRoot", other.toString());
|
||||||
|
var reply = mapper.readTree(post(call.toString()).body());
|
||||||
|
assertEquals("OUTSIDE_PROJECT_SCOPE", reply.path("result").path("structuredContent").path("error").path("code").asText());
|
||||||
|
assertEquals(0, calls.get());
|
||||||
|
server.credentials().authenticate(authorization).invalidate();
|
||||||
|
assertEquals(401, post(wire).statusCode());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,38 +15,34 @@ import static org.junit.jupiter.api.Assertions.*;
|
|||||||
|
|
||||||
class McpConnectionGuideTest {
|
class McpConnectionGuideTest {
|
||||||
@TempDir Path root;
|
@TempDir Path root;
|
||||||
@Test void exportsLiveProjectDescriptorWithoutGrantAndTracksRestartWithoutRetainingSecrets() throws Exception {
|
@Test void preparationIsStableAndSeparateFromAuthority() throws Exception {
|
||||||
var mapper = new ObjectMapper(); var projects = new ProjectAccessRegistry();
|
var mapper = new ObjectMapper(); var projects = new ProjectAccessRegistry();
|
||||||
try (var workers = Executors.newSingleThreadExecutor();
|
try (var workers = Executors.newSingleThreadExecutor();
|
||||||
var server = new LocalMcpServer(mapper, new McpToolRegistry(new McpToolCatalog(mapper), mapper, Map.of()))) {
|
var server = new LocalMcpServer(mapper, new McpToolRegistry(new McpToolCatalog(mapper), mapper, Map.of()))) {
|
||||||
var authority = new DefaultAutomationSession(root, new ExecutorOperationExecutor(workers));
|
var authority = new DefaultAutomationSession(root, new ExecutorOperationExecutor(workers));
|
||||||
var registration = projects.register(root, authority::enterManual, () -> !authority.snapshot().closed(), authority);
|
var registration = projects.register(root, authority::enterManual, () -> !authority.snapshot().closed(), authority);
|
||||||
var guide = new McpConnectionGuide(server, projects, mapper);
|
var prepared = new AtomicInteger();
|
||||||
assertTrue(guide.endpoint().isEmpty());
|
var canonical = root.toRealPath();
|
||||||
assertThrows(IllegalStateException.class, () -> guide.configuration(root));
|
var guide = new McpConnectionGuide(server, projects, mapper, project -> {
|
||||||
var notifications = new AtomicInteger();
|
assertEquals(canonical, project); prepared.incrementAndGet();
|
||||||
var subscription = guide.subscribe(notifications::incrementAndGet);
|
return new AgentIntegrationPreparation.Result(true, "Prepared; trust/reload once.");
|
||||||
server.start(); assertEquals(2, notifications.get());
|
});
|
||||||
var descriptor = mapper.readTree(guide.configuration(root));
|
assertEquals(AgentConnectionGuide.State.UNAVAILABLE, guide.state(root));
|
||||||
assertEquals(server.connection().endpoint().toString(), descriptor.path("url").asText());
|
var stable = guide.configuration(root);
|
||||||
assertEquals(root.toRealPath().toString(), descriptor.path("projectRoot").asText());
|
assertTrue(guide.prepare(root).ready()); assertEquals(1, prepared.get());
|
||||||
// Do not put bearer credentials into assertion diagnostics.
|
|
||||||
assertTrue(server.connection().authorizationHeader().equals(descriptor.path("headers").path("Authorization").asText()));
|
|
||||||
assertFalse(guide.toString().contains(descriptor.path("headers").path("Authorization").asText()));
|
|
||||||
assertEquals(ControlState.MANUAL, authority.snapshot().state());
|
assertEquals(ControlState.MANUAL, authority.snapshot().state());
|
||||||
assertNull(authority.snapshot().task());
|
assertNull(authority.snapshot().task());
|
||||||
|
server.start();
|
||||||
|
assertEquals(AgentConnectionGuide.State.WAITING_FOR_ACCESS, guide.state(root));
|
||||||
|
assertFalse(stable.contains("Bearer"));
|
||||||
for (var instruction : List.of("studio_project_context", "studio_reference_read", "studio_control_acquire", "studio_control_release",
|
for (var instruction : List.of("studio_project_context", "studio_reference_read", "studio_control_acquire", "studio_control_release",
|
||||||
"studio_language_query", "studio_build_start", "clientRequestId", "read-only", "restart", "native file writes"))
|
"studio_language_query", "studio_build_start", "clientRequestId", "read-only", "restart", "native file writes"))
|
||||||
assertTrue(descriptor.path("instructions").asText().contains(instruction));
|
assertTrue(stable.contains(instruction));
|
||||||
var old = server.connection(); server.close(); assertEquals(3, notifications.get()); assertTrue(guide.endpoint().isEmpty());
|
server.close(); server.start(); assertEquals(stable, guide.configuration(root));
|
||||||
server.start(); assertEquals(4, notifications.get());
|
|
||||||
var fresh = mapper.readTree(guide.configuration(root));
|
|
||||||
assertTrue(fresh.path("headers").path("Authorization").asText().equals(server.connection().authorizationHeader()));
|
|
||||||
assertFalse(fresh.path("headers").path("Authorization").asText().equals(old.authorizationHeader()));
|
|
||||||
assertThrows(AutomationException.class, () -> guide.configuration(root.resolve("unopened")));
|
assertThrows(AutomationException.class, () -> guide.configuration(root.resolve("unopened")));
|
||||||
authority.closeAsync().toCompletableFuture().join();
|
authority.closeAsync().toCompletableFuture().join();
|
||||||
assertThrows(AutomationException.class, () -> guide.configuration(root));
|
assertThrows(AutomationException.class, () -> guide.configuration(root));
|
||||||
registration.close(); subscription.close(); server.close(); assertEquals(4, notifications.get());
|
registration.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import java.util.function.*;
|
|||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
class McpTaskToolsTest {
|
class McpTaskToolsTest {
|
||||||
|
String httpAuthorization;
|
||||||
@TempDir Path root;
|
@TempDir Path root;
|
||||||
final ObjectMapper mapper = new ObjectMapper();
|
final ObjectMapper mapper = new ObjectMapper();
|
||||||
final ExecutorService workers = Executors.newCachedThreadPool();
|
final ExecutorService workers = Executors.newCachedThreadPool();
|
||||||
@@ -243,6 +244,8 @@ class McpTaskToolsTest {
|
|||||||
compose(shipper);
|
compose(shipper);
|
||||||
try (var server = new LocalMcpServer(mapper, tools); var client = java.net.http.HttpClient.newHttpClient()) {
|
try (var server = new LocalMcpServer(mapper, tools); var client = java.net.http.HttpClient.newHttpClient()) {
|
||||||
server.start();
|
server.start();
|
||||||
|
var credential = server.credentials().prepare(root.toRealPath());
|
||||||
|
credential.activate(); httpAuthorization = "Bearer " + credential.secret();
|
||||||
var initialize = mapper.createObjectNode().put("jsonrpc", "2.0").put("id", 1).put("method", "initialize");
|
var initialize = mapper.createObjectNode().put("jsonrpc", "2.0").put("id", 1).put("method", "initialize");
|
||||||
var params = initialize.putObject("params").put("protocolVersion", "2025-06-18");
|
var params = initialize.putObject("params").put("protocolVersion", "2025-06-18");
|
||||||
params.putObject("capabilities"); params.putObject("clientInfo").put("name", "task-test").put("version", "1");
|
params.putObject("capabilities"); params.putObject("clientInfo").put("name", "task-test").put("version", "1");
|
||||||
@@ -281,6 +284,8 @@ class McpTaskToolsTest {
|
|||||||
try (var server = new LocalMcpServer(mapper, new McpToolRegistry(new McpToolCatalog(mapper), mapper, handlers));
|
try (var server = new LocalMcpServer(mapper, new McpToolRegistry(new McpToolCatalog(mapper), mapper, handlers));
|
||||||
var client = java.net.http.HttpClient.newHttpClient()) {
|
var client = java.net.http.HttpClient.newHttpClient()) {
|
||||||
server.start();
|
server.start();
|
||||||
|
var credential = server.credentials().prepare(root.toRealPath());
|
||||||
|
credential.activate(); httpAuthorization = "Bearer " + credential.secret();
|
||||||
var unauthorized = java.net.http.HttpRequest.newBuilder(server.connection().endpoint()).POST(java.net.http.HttpRequest.BodyPublishers.ofString("{}"))
|
var unauthorized = java.net.http.HttpRequest.newBuilder(server.connection().endpoint()).POST(java.net.http.HttpRequest.BodyPublishers.ofString("{}"))
|
||||||
.timeout(java.time.Duration.ofSeconds(5)).build();
|
.timeout(java.time.Duration.ofSeconds(5)).build();
|
||||||
assertEquals(401, client.send(unauthorized, java.net.http.HttpResponse.BodyHandlers.discarding()).statusCode());
|
assertEquals(401, client.send(unauthorized, java.net.http.HttpResponse.BodyHandlers.discarding()).statusCode());
|
||||||
@@ -315,7 +320,7 @@ class McpTaskToolsTest {
|
|||||||
var captured = httpCall(client, server, first, "studio_headless_capture", args()); value(captured);
|
var captured = httpCall(client, server, first, "studio_headless_capture", args()); value(captured);
|
||||||
assertArrayEquals(session.snapshot().capture().png(), Base64.getDecoder().decode(captured.path("content").get(1).path("data").asText()));
|
assertArrayEquals(session.snapshot().capture().png(), Base64.getDecoder().decode(captured.path("content").get(1).path("data").asText()));
|
||||||
var deleted = java.net.http.HttpRequest.newBuilder(server.connection().endpoint()).DELETE()
|
var deleted = java.net.http.HttpRequest.newBuilder(server.connection().endpoint()).DELETE()
|
||||||
.header("Authorization", server.connection().authorizationHeader()).header("Mcp-Session-Id", first).build();
|
.header("Authorization", httpAuthorization).header("Mcp-Session-Id", first).build();
|
||||||
assertEquals(200, client.send(deleted, java.net.http.HttpResponse.BodyHandlers.discarding()).statusCode());
|
assertEquals(200, client.send(deleted, java.net.http.HttpResponse.BodyHandlers.discarding()).statusCode());
|
||||||
assertEquals(ControlState.AGENT_WORKING, session.snapshot().state());
|
assertEquals(ControlState.AGENT_WORKING, session.snapshot().state());
|
||||||
String reconnected = connect(client, server);
|
String reconnected = connect(client, server);
|
||||||
@@ -367,7 +372,7 @@ class McpTaskToolsTest {
|
|||||||
}
|
}
|
||||||
java.net.http.HttpResponse<String> post(java.net.http.HttpClient client, LocalMcpServer server, String connection, JsonNode body) throws Exception {
|
java.net.http.HttpResponse<String> post(java.net.http.HttpClient client, LocalMcpServer server, String connection, JsonNode body) throws Exception {
|
||||||
var request = java.net.http.HttpRequest.newBuilder(server.connection().endpoint()).timeout(java.time.Duration.ofSeconds(10))
|
var request = java.net.http.HttpRequest.newBuilder(server.connection().endpoint()).timeout(java.time.Duration.ofSeconds(10))
|
||||||
.header("Authorization", server.connection().authorizationHeader()).header("Content-Type", "application/json")
|
.header("Authorization", httpAuthorization).header("Content-Type", "application/json")
|
||||||
.header("Accept", "application/json, text/event-stream").header("MCP-Protocol-Version", "2025-06-18");
|
.header("Accept", "application/json, text/event-stream").header("MCP-Protocol-Version", "2025-06-18");
|
||||||
if (connection != null) request.header("Mcp-Session-Id", connection);
|
if (connection != null) request.header("Mcp-Session-Id", connection);
|
||||||
return client.send(request.POST(java.net.http.HttpRequest.BodyPublishers.ofString(body.toString())).build(), java.net.http.HttpResponse.BodyHandlers.ofString());
|
return client.send(request.POST(java.net.http.HttpRequest.BodyPublishers.ofString(body.toString())).build(), java.net.http.HttpResponse.BodyHandlers.ofString());
|
||||||
|
|||||||
@@ -0,0 +1,115 @@
|
|||||||
|
package p.studio.app.mcp;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.junit.jupiter.api.*;
|
||||||
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
|
import java.nio.file.*;
|
||||||
|
import java.nio.file.attribute.PosixFilePermissions;
|
||||||
|
import java.util.Map;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class ProjectConnectionPublisherTest {
|
||||||
|
@TempDir Path temporary;
|
||||||
|
final ObjectMapper mapper = new ObjectMapper();
|
||||||
|
LocalMcpServer server;
|
||||||
|
Path root;
|
||||||
|
@BeforeEach void start() throws Exception {
|
||||||
|
root = temporary.toRealPath();
|
||||||
|
server = new LocalMcpServer(mapper, new McpToolRegistry(new McpToolCatalog(mapper), mapper, Map.of())); server.start();
|
||||||
|
}
|
||||||
|
@AfterEach void stop() { server.close(); }
|
||||||
|
@Test void publishesPrivatelyOnlyActivatesExplicitlyAndCleansUpOwnedGeneration() throws Exception {
|
||||||
|
Files.writeString(root.resolve(".gitignore"), "# existing\n/build/\n");
|
||||||
|
var publisher = new ProjectConnectionPublisher(server, mapper);
|
||||||
|
var publication = publisher.prepare(root);
|
||||||
|
publication.publish();
|
||||||
|
var descriptor = ProjectConnectionFiles.read(root, mapper);
|
||||||
|
assertNull(server.credentials().authenticate("Bearer " + descriptor.credential()));
|
||||||
|
publication.activate();
|
||||||
|
assertEquals(root, server.credentials().authenticate("Bearer " + descriptor.credential()).root());
|
||||||
|
var file = root.resolve(ProjectConnectionFiles.RELATIVE);
|
||||||
|
assertEquals(PosixFilePermissions.fromString("rw-------"), Files.getPosixFilePermissions(file));
|
||||||
|
assertEquals(PosixFilePermissions.fromString("rwx------"), Files.getPosixFilePermissions(file.getParent()));
|
||||||
|
assertFalse(descriptor.toString().contains(descriptor.credential()));
|
||||||
|
assertThrows(Exception.class, () -> publisher.prepare(root));
|
||||||
|
publication.invalidate(); assertNull(server.credentials().authenticate("Bearer " + descriptor.credential()));
|
||||||
|
publication.close(); assertFalse(Files.exists(file)); assertTrue(Files.exists(file.resolveSibling("publication.lock")));
|
||||||
|
try (var next = publisher.prepare(root)) {
|
||||||
|
next.publish(); next.activate(); publication.close();
|
||||||
|
assertTrue(Files.exists(file));
|
||||||
|
assertNotEquals(descriptor.credential(), ProjectConnectionFiles.read(root, mapper).credential());
|
||||||
|
}
|
||||||
|
assertEquals("# existing\n/build/\n/.studio/mcp/\n", Files.readString(root.resolve(".gitignore")));
|
||||||
|
}
|
||||||
|
@Test void unsafePathsAndPermissionsNeverPublishSecrets() throws Exception {
|
||||||
|
Path destination = Files.createDirectory(root.resolve("outside"));
|
||||||
|
Files.createSymbolicLink(root.resolve(".studio"), destination);
|
||||||
|
assertThrows(Exception.class, () -> new ProjectConnectionPublisher(server, mapper).prepare(root));
|
||||||
|
assertFalse(Files.exists(destination.resolve("mcp")));
|
||||||
|
Files.delete(root.resolve(".studio"));
|
||||||
|
Path directory = ProjectConnectionFiles.directory(root);
|
||||||
|
Files.setPosixFilePermissions(directory, PosixFilePermissions.fromString("rwxr-xr-x"));
|
||||||
|
assertThrows(Exception.class, () -> new ProjectConnectionPublisher(server, mapper).prepare(root));
|
||||||
|
}
|
||||||
|
@Test void malformedDescriptorsNeverSupplyAnArbitraryEndpoint() throws Exception {
|
||||||
|
try (var publication = new ProjectConnectionPublisher(server, mapper).prepare(root)) {
|
||||||
|
publication.publish();
|
||||||
|
Path path = root.resolve(ProjectConnectionFiles.RELATIVE);
|
||||||
|
var valid = mapper.readTree(Files.readString(path));
|
||||||
|
for (String endpoint : java.util.List.of("https://example.com/mcp", "http://127.0.0.1:123/mcp?x=1", "http://localhost:123/mcp")) {
|
||||||
|
var bad = valid.deepCopy(); ((com.fasterxml.jackson.databind.node.ObjectNode) bad).put("endpoint", endpoint);
|
||||||
|
Files.writeString(path, bad.toString()); assertThrows(Exception.class, () -> ProjectConnectionFiles.read(root, mapper));
|
||||||
|
}
|
||||||
|
Files.writeString(path, valid.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Test void osLockRejectsAnotherJvmAndCrashAllowsRecoveryWithoutUnlinkingLock() throws Exception {
|
||||||
|
Process owner = ownerProcess();
|
||||||
|
try {
|
||||||
|
assertEquals("READY", java.util.concurrent.CompletableFuture.supplyAsync(() -> {
|
||||||
|
try { return owner.inputReader().readLine(); } catch (java.io.IOException failure) { throw new java.io.UncheckedIOException(failure); }
|
||||||
|
}).get(10, java.util.concurrent.TimeUnit.SECONDS));
|
||||||
|
var lock = root.resolve(".studio/mcp/publication.lock");
|
||||||
|
var inode = Files.readAttributes(lock, java.nio.file.attribute.BasicFileAttributes.class).fileKey();
|
||||||
|
Process conflict = ownerProcess();
|
||||||
|
try { assertTrue(conflict.waitFor(10, java.util.concurrent.TimeUnit.SECONDS)); assertEquals(2, conflict.exitValue()); }
|
||||||
|
finally { conflict.destroyForcibly(); }
|
||||||
|
owner.destroyForcibly(); assertTrue(owner.waitFor(10, java.util.concurrent.TimeUnit.SECONDS));
|
||||||
|
assertTrue(Files.exists(root.resolve(ProjectConnectionFiles.RELATIVE)));
|
||||||
|
try (var recovered = new ProjectConnectionPublisher(server, mapper).prepare(root)) {
|
||||||
|
recovered.publish(); recovered.activate();
|
||||||
|
assertEquals(server.instanceId(), ProjectConnectionFiles.read(root, mapper).instanceId());
|
||||||
|
assertEquals(inode, Files.readAttributes(lock, java.nio.file.attribute.BasicFileAttributes.class).fileKey());
|
||||||
|
}
|
||||||
|
} finally { owner.destroyForcibly(); }
|
||||||
|
}
|
||||||
|
@Test void trackedDiscoveryTargetIsRejectedWithoutWritingCredentials() throws Exception {
|
||||||
|
var directory = ProjectConnectionFiles.directory(root);
|
||||||
|
var target = directory.resolve("connection.json"); Files.writeString(target, "tracked placeholder");
|
||||||
|
for (var command : java.util.List.of(java.util.List.of("git", "init", "-q"), java.util.List.of("git", "add", "-f", ProjectConnectionFiles.RELATIVE))) {
|
||||||
|
var process = new ProcessBuilder(command).directory(root.toFile()).redirectError(ProcessBuilder.Redirect.DISCARD).start();
|
||||||
|
assertTrue(process.waitFor(5, java.util.concurrent.TimeUnit.SECONDS)); assertEquals(0, process.exitValue());
|
||||||
|
}
|
||||||
|
assertThrows(Exception.class, () -> new ProjectConnectionPublisher(server, mapper).prepare(root));
|
||||||
|
assertEquals("tracked placeholder", Files.readString(target));
|
||||||
|
assertFalse(Files.exists(directory.resolve("publication.lock")));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Process ownerProcess() throws Exception {
|
||||||
|
return new ProcessBuilder(Path.of(System.getProperty("java.home"), "bin/java").toString(), "-cp",
|
||||||
|
System.getProperty("studio.test.classpath"), Owner.class.getName(), root.toString())
|
||||||
|
.redirectError(ProcessBuilder.Redirect.DISCARD).start();
|
||||||
|
}
|
||||||
|
public static class Owner {
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
var mapper = new ObjectMapper();
|
||||||
|
try (var server = new LocalMcpServer(mapper, new McpToolRegistry(new McpToolCatalog(mapper), mapper, Map.of()))) {
|
||||||
|
server.start();
|
||||||
|
try (var publication = new ProjectConnectionPublisher(server, mapper).prepare(Path.of(args[0]))) {
|
||||||
|
publication.publish(); publication.activate(); System.out.println("READY"); System.out.flush(); System.in.read();
|
||||||
|
} catch (Exception conflict) { System.exit(2); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package p.studio.app.mcp;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
|
import java.nio.file.*;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class StudioAgentPreparationTest {
|
||||||
|
@TempDir Path temporary;
|
||||||
|
@Test void preservesUnrelatedTomlAndRejectsUserOwnedOrEditedEntry() throws Exception {
|
||||||
|
var preparation = new StudioAgentPreparation(temporary.resolve("Application Support/Studio"), new ObjectMapper());
|
||||||
|
String entry = preparation.entry(temporary.toRealPath());
|
||||||
|
String custom = "# keep exactly\napproval_policy = \"on-request\"\n[mcp_servers.custom]\ncommand = \"custom\"\n";
|
||||||
|
String merged = StudioAgentPreparation.merge(custom, entry);
|
||||||
|
assertTrue(merged.startsWith(custom)); assertEquals(merged, StudioAgentPreparation.merge(merged, entry));
|
||||||
|
assertFalse(merged.contains("credential")); assertFalse(merged.contains("connection.json"));
|
||||||
|
assertThrows(Exception.class, () -> StudioAgentPreparation.merge("[mcp_servers.prometeu_studio]\ncommand=\"mine\"\n", entry));
|
||||||
|
assertThrows(Exception.class, () -> StudioAgentPreparation.merge(merged.replace("startup_timeout_sec = 20", "startup_timeout_sec = 30"), entry));
|
||||||
|
String updated = StudioAgentPreparation.merge(merged, preparation.entry(temporary.resolve("another project")));
|
||||||
|
assertTrue(updated.startsWith(custom)); assertTrue(updated.contains("another project"));
|
||||||
|
}
|
||||||
|
@Test void absentInstallationReportsIncompleteAndDoesNotModifyClientConfig() throws Exception {
|
||||||
|
Files.writeString(temporary.resolve("prometeu.json"), "{}");
|
||||||
|
Files.createDirectory(temporary.resolve(".codex"));
|
||||||
|
Path config = temporary.resolve(".codex/config.toml"); Files.writeString(config, "# preserve\n");
|
||||||
|
var preparation = new StudioAgentPreparation(temporary.resolve("missing"), new ObjectMapper());
|
||||||
|
var result = preparation.prepare(temporary);
|
||||||
|
assertFalse(result.ready()); assertEquals("# preserve\n", Files.readString(config));
|
||||||
|
assertTrue(result.message().contains("Studio installation is missing"));
|
||||||
|
assertTrue(result.message().contains(":prometeu-app:stageStudioInstallation"));
|
||||||
|
assertTrue(result.message().contains("-Dstudio.installationRoot"));
|
||||||
|
assertFalse(Files.exists(temporary.resolve(".studio/mcp")));
|
||||||
|
assertEquals(result, preparation.status(temporary.toRealPath()));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,204 @@
|
|||||||
|
package p.studio.app.mcp.stdio;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.*;
|
||||||
|
import org.junit.jupiter.api.*;
|
||||||
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
|
import p.studio.app.mcp.*;
|
||||||
|
import java.io.*;
|
||||||
|
import java.nio.file.*;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.*;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class StudioMcpStdioTest {
|
||||||
|
@TempDir Path temporary;
|
||||||
|
final ObjectMapper mapper = new ObjectMapper();
|
||||||
|
Path root;
|
||||||
|
@BeforeEach void project() throws Exception { root = temporary.toRealPath(); Files.writeString(root.resolve("prometeu.json"), "{}"); }
|
||||||
|
LocalMcpServer server(AtomicInteger calls, String image) {
|
||||||
|
return new LocalMcpServer(mapper, new McpToolRegistry(new McpToolCatalog(mapper), mapper, Map.of("studio_project_context", args -> {
|
||||||
|
calls.incrementAndGet();
|
||||||
|
return McpToolResult.successWithCapture(mapper, mapper.createObjectNode().put("projectRoot", args.path("projectRoot").asText()),
|
||||||
|
new p.studio.api.automation.CanonicalCapture("session", "build", 1, 1, 1, 1, 1, Base64.getDecoder().decode(image)), false);
|
||||||
|
})));
|
||||||
|
}
|
||||||
|
@Test void coldProcessDiscoversLaterGrantPreservesLargeImagesAndSurvivesRestart() throws Exception {
|
||||||
|
var count = new AtomicInteger(); String pixels = "A".repeat(1024 * 1024 + 100);
|
||||||
|
try (var process = new Connector(root); var server = server(count, pixels)) {
|
||||||
|
process.initialize();
|
||||||
|
assertEquals(17, process.request("tools/list", mapper.createObjectNode()).path("result").path("tools").size());
|
||||||
|
var waiting = process.call("studio_project_context", root);
|
||||||
|
assertEquals("WAITING_FOR_ACCESS", waiting.path("structuredContent").path("error").path("code").asText());
|
||||||
|
assertFalse(Files.exists(root.resolve(".studio")));
|
||||||
|
server.start();
|
||||||
|
var publisher = new ProjectConnectionPublisher(server, mapper);
|
||||||
|
try (var publication = publisher.prepare(root)) {
|
||||||
|
publication.publish(); publication.activate();
|
||||||
|
var result = process.call("studio_project_context", root);
|
||||||
|
assertFalse(result.path("isError").asBoolean(), result.path("structuredContent").toString());
|
||||||
|
assertEquals(pixels, result.path("content").get(1).path("data").asText());
|
||||||
|
assertEquals(root.toString(), result.path("structuredContent").path("value").path("projectRoot").asText());
|
||||||
|
Path other = Files.createDirectory(root.resolve("other"));
|
||||||
|
assertEquals("OUTSIDE_PROJECT_SCOPE", process.call("studio_project_context", other).path("structuredContent").path("error").path("code").asText());
|
||||||
|
assertEquals(1, count.get());
|
||||||
|
}
|
||||||
|
server.close(); server.start();
|
||||||
|
assertEquals("WAITING_FOR_ACCESS", process.call("studio_project_context", root).path("structuredContent").path("error").path("code").asText());
|
||||||
|
try (var fresh = publisher.prepare(root)) {
|
||||||
|
fresh.publish(); fresh.activate();
|
||||||
|
assertFalse(process.call("studio_project_context", root).path("isError").asBoolean());
|
||||||
|
assertEquals(2, count.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Test void invalidArgumentsAndMalformedLinesDoNotLaunchDesktopOrBreakCorrelation() throws Exception {
|
||||||
|
try (var connector = new Connector(root)) {
|
||||||
|
connector.send("{bad json}");
|
||||||
|
assertEquals(-32700, connector.read().path("error").path("code").asInt());
|
||||||
|
connector.initialize();
|
||||||
|
assertEquals(-32601, connector.request("no-method", mapper.createObjectNode()).path("error").path("code").asInt());
|
||||||
|
assertTrue(connector.request("ping", mapper.createObjectNode()).has("result"));
|
||||||
|
}
|
||||||
|
var process = new ProcessBuilder(java(), "-cp", classpath(), "p.studio.app.StudioLauncher", "mcp", "--project", "relative")
|
||||||
|
.redirectError(ProcessBuilder.Redirect.DISCARD).start();
|
||||||
|
assertTrue(process.waitFor(10, TimeUnit.SECONDS)); assertNotEquals(0, process.exitValue());
|
||||||
|
assertEquals(0, process.getInputStream().readAllBytes().length);
|
||||||
|
}
|
||||||
|
@Test void lostBuildResponseIsNotReplayedAndReceiptCanBeLookedUpAfterReconnect() throws Exception {
|
||||||
|
var builds = new AtomicInteger(); var mapper = this.mapper;
|
||||||
|
var handlers = Map.<String, java.util.function.Function<JsonNode, McpToolResult>>of(
|
||||||
|
"studio_build_start", args -> { builds.incrementAndGet(); return McpToolResult.success(mapper, mapper.createObjectNode().put("operationId", "op-1")); },
|
||||||
|
"studio_operation_get", args -> McpToolResult.success(mapper, mapper.createObjectNode().put("operationId", "op-1")));
|
||||||
|
try (var server = new LocalMcpServer(mapper, new McpToolRegistry(new McpToolCatalog(mapper), mapper, handlers));
|
||||||
|
var transport = java.net.http.HttpClient.newHttpClient()) {
|
||||||
|
server.start();
|
||||||
|
var proxy = com.sun.net.httpserver.HttpServer.create(new java.net.InetSocketAddress("127.0.0.1", 0), 0);
|
||||||
|
var dropped = new java.util.concurrent.atomic.AtomicBoolean();
|
||||||
|
proxy.createContext("/mcp", exchange -> {
|
||||||
|
try (exchange) {
|
||||||
|
var bytes = exchange.getRequestBody().readAllBytes();
|
||||||
|
var incoming = mapper.readTree(bytes);
|
||||||
|
var request = java.net.http.HttpRequest.newBuilder(server.connection().endpoint());
|
||||||
|
for (String header : List.of("Authorization", "Content-Type", "Accept", "Mcp-Session-Id", "MCP-Protocol-Version")) {
|
||||||
|
String value = exchange.getRequestHeaders().getFirst(header); if (value != null) request.header(header, value);
|
||||||
|
}
|
||||||
|
var response = transport.send(request.POST(java.net.http.HttpRequest.BodyPublishers.ofByteArray(bytes)).build(), java.net.http.HttpResponse.BodyHandlers.ofByteArray());
|
||||||
|
if (incoming.path("params").path("name").asText().equals("studio_build_start") && dropped.compareAndSet(false, true)) {
|
||||||
|
exchange.sendResponseHeaders(200, 100); return; // Committed tool, intentionally incomplete transport response.
|
||||||
|
}
|
||||||
|
response.headers().firstValue("Mcp-Session-Id").ifPresent(value -> exchange.getResponseHeaders().set("Mcp-Session-Id", value));
|
||||||
|
exchange.sendResponseHeaders(response.statusCode(), response.body().length == 0 ? -1 : response.body().length);
|
||||||
|
exchange.getResponseBody().write(response.body());
|
||||||
|
} catch (InterruptedException interrupted) { Thread.currentThread().interrupt(); }
|
||||||
|
});
|
||||||
|
proxy.start();
|
||||||
|
try (var publication = new ProjectConnectionPublisher(server, mapper).prepare(root);
|
||||||
|
var connection = new StudioMcpConnection(root, mapper, new McpToolCatalog(mapper))) {
|
||||||
|
publication.publish(); publication.activate();
|
||||||
|
var path = root.resolve(ProjectConnectionFiles.RELATIVE);
|
||||||
|
var descriptor = (com.fasterxml.jackson.databind.node.ObjectNode) mapper.readTree(Files.readString(path));
|
||||||
|
descriptor.put("endpoint", "http://127.0.0.1:" + proxy.getAddress().getPort() + "/mcp"); Files.writeString(path, descriptor.toString());
|
||||||
|
var args = mapper.createObjectNode().put("projectRoot", root.toString()).put("taskId", "task").put("clientRequestId", "intent-1");
|
||||||
|
var unknown = connection.call("studio_build_start", args);
|
||||||
|
assertEquals("OUTCOME_UNKNOWN", unknown.path("structuredContent").path("error").path("code").asText());
|
||||||
|
assertEquals("intent-1", unknown.path("structuredContent").path("error").path("clientRequestId").asText());
|
||||||
|
connection.probe(); assertEquals(1, builds.get());
|
||||||
|
var recovered = connection.call("studio_operation_get", args);
|
||||||
|
assertEquals("op-1", recovered.path("structuredContent").path("value").path("operationId").asText());
|
||||||
|
assertEquals(1, builds.get());
|
||||||
|
} finally { proxy.stop(0); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test void restartedInstanceCannotClaimRecoveryOfOldTaskReceipts() throws Exception {
|
||||||
|
var calls = new AtomicInteger();
|
||||||
|
var handlers = Map.<String, java.util.function.Function<JsonNode, McpToolResult>>of(
|
||||||
|
"studio_control_acquire", args -> McpToolResult.success(mapper, mapper.createObjectNode().put("taskId", UUID.randomUUID().toString())),
|
||||||
|
"studio_operation_get", args -> { calls.incrementAndGet(); return McpToolResult.success(mapper, mapper.createObjectNode().put("operationId", "fresh")); });
|
||||||
|
try (var server = new LocalMcpServer(mapper, new McpToolRegistry(new McpToolCatalog(mapper), mapper, handlers));
|
||||||
|
var connection = new StudioMcpConnection(root, mapper, new McpToolCatalog(mapper))) {
|
||||||
|
server.start(); var publisher = new ProjectConnectionPublisher(server, mapper);
|
||||||
|
String task;
|
||||||
|
try (var publication = publisher.prepare(root)) {
|
||||||
|
publication.publish(); publication.activate();
|
||||||
|
task = connection.call("studio_control_acquire", mapper.createObjectNode().put("projectRoot", root.toString()))
|
||||||
|
.path("structuredContent").path("value").path("taskId").asText();
|
||||||
|
}
|
||||||
|
server.close(); server.start();
|
||||||
|
try (var publication = publisher.prepare(root)) {
|
||||||
|
publication.publish(); publication.activate();
|
||||||
|
var old = mapper.createObjectNode().put("projectRoot", root.toString()).put("taskId", task).put("clientRequestId", "old");
|
||||||
|
assertEquals("OUTCOME_UNKNOWN", connection.call("studio_operation_get", old).path("structuredContent").path("error").path("code").asText());
|
||||||
|
assertEquals(0, calls.get());
|
||||||
|
String fresh = connection.call("studio_control_acquire", mapper.createObjectNode().put("projectRoot", root.toString()))
|
||||||
|
.path("structuredContent").path("value").path("taskId").asText();
|
||||||
|
old.put("taskId", fresh);
|
||||||
|
assertFalse(connection.call("studio_operation_get", old).path("isError").asBoolean()); assertEquals(1, calls.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test void staleIdentityAndCatalogMismatchAreRejectedBeforeToolDispatch() throws Exception {
|
||||||
|
var calls = new AtomicInteger();
|
||||||
|
try (var server = server(calls, "AAAA")) {
|
||||||
|
server.start();
|
||||||
|
try (var publication = new ProjectConnectionPublisher(server, mapper).prepare(root)) {
|
||||||
|
publication.publish(); publication.activate();
|
||||||
|
Path path = root.resolve(ProjectConnectionFiles.RELATIVE);
|
||||||
|
String valid = Files.readString(path);
|
||||||
|
try {
|
||||||
|
for (String field : List.of("instanceId", "catalogFingerprint")) {
|
||||||
|
var invalid = (com.fasterxml.jackson.databind.node.ObjectNode) mapper.readTree(valid); invalid.put(field, "outdated");
|
||||||
|
Files.writeString(path, invalid.toString());
|
||||||
|
try (var connection = new StudioMcpConnection(root, mapper, new McpToolCatalog(mapper))) {
|
||||||
|
var result = connection.call("studio_project_context", mapper.createObjectNode().put("projectRoot", root.toString()));
|
||||||
|
assertEquals(field.equals("instanceId") ? "STALE_CONNECTION" : "VERSION_INCOMPATIBLE",
|
||||||
|
result.path("structuredContent").path("error").path("code").asText());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertEquals(0, calls.get());
|
||||||
|
} finally { Files.writeString(path, valid); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static String java() { return Path.of(System.getProperty("java.home"), "bin/java").toString(); }
|
||||||
|
static String classpath() { return System.getProperty("studio.test.classpath"); }
|
||||||
|
final class Connector implements AutoCloseable {
|
||||||
|
final Process process;
|
||||||
|
final BufferedReader reader;
|
||||||
|
final BufferedWriter writer;
|
||||||
|
final ExecutorService reads = Executors.newSingleThreadExecutor();
|
||||||
|
final Path errors;
|
||||||
|
int sequence;
|
||||||
|
Connector(Path project) throws Exception {
|
||||||
|
errors = Files.createTempFile(temporary, "stdio-", ".stderr");
|
||||||
|
process = new ProcessBuilder(java(), "-cp", classpath(), "p.studio.app.StudioLauncher", "mcp", "--project", project.toString())
|
||||||
|
.directory(temporary.toFile()).redirectError(errors.toFile()).start();
|
||||||
|
reader = process.inputReader(); writer = process.outputWriter();
|
||||||
|
}
|
||||||
|
void send(String value) throws Exception { writer.write(value); writer.newLine(); writer.flush(); }
|
||||||
|
JsonNode read() throws Exception {
|
||||||
|
String line = reads.submit(reader::readLine).get(15, TimeUnit.SECONDS);
|
||||||
|
assertNotNull(line, Files.readString(errors)); return mapper.readTree(line);
|
||||||
|
}
|
||||||
|
JsonNode request(String method, JsonNode params) throws Exception {
|
||||||
|
var value = mapper.createObjectNode().put("jsonrpc", "2.0").put("id", ++sequence).put("method", method); value.set("params", params);
|
||||||
|
send(value.toString()); var response = read(); assertEquals(sequence, response.path("id").asInt()); return response;
|
||||||
|
}
|
||||||
|
void initialize() throws Exception {
|
||||||
|
var params = mapper.createObjectNode().put("protocolVersion", "2025-06-18"); params.putObject("capabilities"); params.putObject("clientInfo").put("name", "process-test").put("version", "1");
|
||||||
|
assertEquals("2025-06-18", request("initialize", params).path("result").path("protocolVersion").asText());
|
||||||
|
send("{\"jsonrpc\":\"2.0\",\"method\":\"notifications/initialized\"}");
|
||||||
|
}
|
||||||
|
JsonNode call(String name, Path root) throws Exception {
|
||||||
|
var params = mapper.createObjectNode().put("name", name); params.putObject("arguments").put("projectRoot", root.toString());
|
||||||
|
return request("tools/call", params).path("result");
|
||||||
|
}
|
||||||
|
public void close() throws Exception {
|
||||||
|
try { writer.close(); assertTrue(process.waitFor(10, TimeUnit.SECONDS), "EOF must terminate the connector"); assertEquals(0, process.exitValue(), Files.readString(errors)); }
|
||||||
|
finally { process.destroyForcibly(); reads.shutdownNow(); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -50,7 +50,15 @@ public final class HeadlessFixture {
|
|||||||
var request = MAPPER.readTree(line); String id = request.path("requestId").asText(), command = request.path("command").asText();
|
var request = MAPPER.readTree(line); String id = request.path("requestId").asText(), command = request.path("command").asText();
|
||||||
switch (command) {
|
switch (command) {
|
||||||
case "initialize" -> response(id, MAPPER.createObjectNode().setAll(Map.of("protocolVersion", hello.path("protocolVersion"), "capabilities", hello.path("capabilities"))));
|
case "initialize" -> response(id, MAPPER.createObjectNode().setAll(Map.of("protocolVersion", hello.path("protocolVersion"), "capabilities", hello.path("capabilities"))));
|
||||||
case "boot", "reset" -> response(id, state());
|
case "boot", "reset" -> {
|
||||||
|
if (mode.startsWith("load-fault-")) {
|
||||||
|
var resource = "/runtime/fault-" + mode.substring("load-fault-".length()) + ".json";
|
||||||
|
var fault = MAPPER.readTree(HeadlessFixture.class.getResourceAsStream(resource));
|
||||||
|
var error = MAPPER.createObjectNode().put("code", "boot_failed").put("message", "Runtime rejected cartridge");
|
||||||
|
error.putObject("details").set("fault", fault);
|
||||||
|
emit(MAPPER.createObjectNode().put("type", "response").put("sessionId", "fixture").put("requestId", id).set("error", error));
|
||||||
|
} else response(id, state());
|
||||||
|
}
|
||||||
case "get_state" -> { if (!mode.equals("hang-call")) response(id, state()); }
|
case "get_state" -> { if (!mode.equals("hang-call")) response(id, state()); }
|
||||||
case "get_fault" -> response(id, MAPPER.nullNode());
|
case "get_fault" -> response(id, MAPPER.nullNode());
|
||||||
case "advance" -> {
|
case "advance" -> {
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ class HeadlessMcpDesktopTest {
|
|||||||
LocalMcpServer server;
|
LocalMcpServer server;
|
||||||
HttpClient client;
|
HttpClient client;
|
||||||
String connection, task, build, session;
|
String connection, task, build, session;
|
||||||
|
String authorization = "Bearer unavailable";
|
||||||
Path installation, source;
|
Path installation, source;
|
||||||
DevWorkspace dev;
|
DevWorkspace dev;
|
||||||
Stage stage;
|
Stage stage;
|
||||||
@@ -76,9 +77,9 @@ class HeadlessMcpDesktopTest {
|
|||||||
stage = new Stage(); stage.setTitle("Real MCP / headless / DEV conformance");
|
stage = new Stage(); stage.setTitle("Real MCP / headless / DEV conformance");
|
||||||
stage.setScene(new Scene((javafx.scene.Parent) dev.rootNode(), 1000, 800)); stage.show(); dev.load();
|
stage.setScene(new Scene((javafx.scene.Parent) dev.rootNode(), 1000, 800)); stage.show(); dev.load();
|
||||||
});
|
});
|
||||||
connect();
|
|
||||||
}
|
}
|
||||||
void connect() throws Exception {
|
void connect() throws Exception {
|
||||||
|
authorization = "Bearer " + p.studio.app.mcp.ProjectConnectionFiles.read(root, mapper).credential();
|
||||||
connection = null;
|
connection = null;
|
||||||
var initialize = request("initialize");
|
var initialize = request("initialize");
|
||||||
var params = initialize.putObject("params").put("protocolVersion", "2025-06-18");
|
var params = initialize.putObject("params").put("protocolVersion", "2025-06-18");
|
||||||
@@ -96,8 +97,15 @@ class HeadlessMcpDesktopTest {
|
|||||||
assertTrue(owned.stream().noneMatch(ProcessHandle::isAlive), "No managed runtime may survive the test");
|
assertTrue(owned.stream().noneMatch(ProcessHandle::isAlive), "No managed runtime may survive the test");
|
||||||
}
|
}
|
||||||
|
|
||||||
void acquire() throws Exception {
|
void grant() throws Exception {
|
||||||
fx(() -> ((Button) dev.rootNode().lookup("#dev-grant")).fire());
|
fx(() -> ((Button) dev.rootNode().lookup("#dev-grant")).fire());
|
||||||
|
long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(10);
|
||||||
|
while (project.automation().snapshot().state() != ControlState.WAITING_FOR_AGENT && System.nanoTime() < deadline) Thread.sleep(10);
|
||||||
|
assertEquals(ControlState.WAITING_FOR_AGENT, project.automation().snapshot().state());
|
||||||
|
connect();
|
||||||
|
}
|
||||||
|
void acquire() throws Exception {
|
||||||
|
grant();
|
||||||
task = value(call("studio_control_acquire", args())).path("taskId").asText();
|
task = value(call("studio_control_acquire", args())).path("taskId").asText();
|
||||||
}
|
}
|
||||||
void prepareLongRun() throws Exception {
|
void prepareLongRun() throws Exception {
|
||||||
@@ -121,7 +129,7 @@ class HeadlessMcpDesktopTest {
|
|||||||
prepareLongRun();
|
prepareLongRun();
|
||||||
var receipt = startRunning("cancel-me");
|
var receipt = startRunning("cancel-me");
|
||||||
var delete = HttpRequest.newBuilder(server.connection().endpoint()).DELETE()
|
var delete = HttpRequest.newBuilder(server.connection().endpoint()).DELETE()
|
||||||
.header("Authorization", server.connection().authorizationHeader()).header("Mcp-Session-Id", connection).build();
|
.header("Authorization", authorization).header("Mcp-Session-Id", connection).build();
|
||||||
assertEquals(200, client.send(delete, HttpResponse.BodyHandlers.discarding()).statusCode());
|
assertEquals(200, client.send(delete, HttpResponse.BodyHandlers.discarding()).statusCode());
|
||||||
client.close(); client = HttpClient.newHttpClient(); connect();
|
client.close(); client = HttpClient.newHttpClient(); connect();
|
||||||
assertEquals(ControlState.AGENT_WORKING, project.automation().snapshot().state());
|
assertEquals(ControlState.AGENT_WORKING, project.automation().snapshot().state());
|
||||||
@@ -159,7 +167,7 @@ class HeadlessMcpDesktopTest {
|
|||||||
refreshEntered.get(10, TimeUnit.SECONDS);
|
refreshEntered.get(10, TimeUnit.SECONDS);
|
||||||
assertEquals(ControlState.RETURNING_CONTROL, project.automation().snapshot().state());
|
assertEquals(ControlState.RETURNING_CONTROL, project.automation().snapshot().state());
|
||||||
assertFalse(project.automation().snapshot().manualAllowed());
|
assertFalse(project.automation().snapshot().manualAllowed());
|
||||||
assertEquals("INVALID_TASK", call("studio_operation_get", args().put("clientRequestId", "revoked")).path("structuredContent").path("error").path("code").asText());
|
assertEquals(401, post(request("ping")).statusCode());
|
||||||
assertSame(lastCapture, project.automation().snapshot().capture(), "Revoked work must not publish a late frame");
|
assertSame(lastCapture, project.automation().snapshot().capture(), "Revoked work must not publish a late frame");
|
||||||
refreshGate.complete(null);
|
refreshGate.complete(null);
|
||||||
assertEquals(ControlState.MANUAL, project.automation().snapshot().state());
|
assertEquals(ControlState.MANUAL, project.automation().snapshot().state());
|
||||||
@@ -169,19 +177,19 @@ class HeadlessMcpDesktopTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test void waitingRevokeProjectCloseAndReopenNeverRestoreAuthority() throws Exception {
|
@Test void waitingRevokeProjectCloseAndReopenNeverRestoreAuthority() throws Exception {
|
||||||
fx(() -> ((Button) dev.rootNode().lookup("#dev-grant")).fire());
|
grant();
|
||||||
fx(() -> ((Button) dev.rootNode().lookup("#dev-reclaim")).fire());
|
fx(() -> ((Button) dev.rootNode().lookup("#dev-reclaim")).fire());
|
||||||
assertEquals(ControlState.MANUAL, project.automation().snapshot().state());
|
assertEquals(ControlState.MANUAL, project.automation().snapshot().state());
|
||||||
assertEquals("NOT_GRANTED", call("studio_control_acquire", args()).path("structuredContent").path("error").path("code").asText());
|
assertEquals(401, post(request("ping")).statusCode());
|
||||||
prepareLongRun(); startRunning("close-project");
|
prepareLongRun(); startRunning("close-project");
|
||||||
fx(dev::unLoad);
|
fx(dev::unLoad);
|
||||||
assertEquals(ControlState.AGENT_WORKING, project.automation().snapshot().state(), "DEV does not own task lifetime");
|
assertEquals(ControlState.AGENT_WORKING, project.automation().snapshot().state(), "DEV does not own task lifetime");
|
||||||
project.close();
|
project.close();
|
||||||
assertTrue(owned.stream().noneMatch(ProcessHandle::isAlive));
|
assertTrue(owned.stream().noneMatch(ProcessHandle::isAlive));
|
||||||
assertEquals("PROJECT_NOT_OPEN", call("studio_operation_get", args().put("clientRequestId", "close-project")).path("structuredContent").path("error").path("code").asText());
|
assertEquals(401, post(request("ping")).statusCode());
|
||||||
project = app.getBean(ProjectSessionFactory.class).open(project.projectReference());
|
project = app.getBean(ProjectSessionFactory.class).open(project.projectReference());
|
||||||
assertEquals(ControlState.MANUAL, project.automation().snapshot().state());
|
assertEquals(ControlState.MANUAL, project.automation().snapshot().state());
|
||||||
assertEquals("INVALID_TASK", call("studio_build_start", args().put("clientRequestId", "late")).path("structuredContent").path("error").path("code").asText());
|
assertEquals(401, post(request("ping")).statusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test void applicationContextShutdownClosesActiveProjectAndRuntime() throws Exception {
|
@Test void applicationContextShutdownClosesActiveProjectAndRuntime() throws Exception {
|
||||||
@@ -270,20 +278,20 @@ class HeadlessMcpDesktopTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test void fullHttpLoopMatchesRawRuntimePixelsAndDisplayedDevAcrossResetAndRebuild() throws Exception {
|
@Test void fullHttpLoopMatchesRawRuntimePixelsAndDisplayedDevAcrossResetAndRebuild() throws Exception {
|
||||||
|
assertEquals(401, post(request("ping")).statusCode());
|
||||||
|
grant();
|
||||||
assertEquals(17, mapper.readTree(post(request("tools/list")).body()).path("result").path("tools").size());
|
assertEquals(17, mapper.readTree(post(request("tools/list")).body()).path("result").path("tools").size());
|
||||||
assertTrue(value(call("studio_project_context", args())).path("languages").toString().contains("pbs"));
|
assertTrue(value(call("studio_project_context", args())).path("languages").toString().contains("pbs"));
|
||||||
value(call("studio_reference_read", args().put("referenceId", "pbs:quickstart").put("limit", 100)));
|
value(call("studio_reference_read", args().put("referenceId", "pbs:quickstart").put("limit", 100)));
|
||||||
var sdk = value(call("studio_reference_read", args().put("referenceId", "pbs:sdk:game:1:sdk/input/main.pbs").put("limit", 1000)));
|
var sdk = value(call("studio_reference_read", args().put("referenceId", "pbs:sdk:game:1:sdk/input/main.pbs").put("limit", 1000)));
|
||||||
assertTrue(sdk.toString().contains("InputPad"), "Consult installed SDK source through the indexed read-only reference");
|
assertTrue(sdk.toString().contains("LowPad"), "Consult installed SDK source through the indexed read-only reference");
|
||||||
assertEquals("NOT_GRANTED", call("studio_control_acquire", args()).path("structuredContent").path("error").path("code").asText());
|
|
||||||
fx(() -> ((Button) dev.rootNode().lookup("#dev-grant")).fire());
|
|
||||||
assertEquals(ControlState.WAITING_FOR_AGENT, project.automation().snapshot().state());
|
assertEquals(ControlState.WAITING_FOR_AGENT, project.automation().snapshot().state());
|
||||||
task = value(call("studio_control_acquire", args())).path("taskId").asText();
|
task = value(call("studio_control_acquire", args())).path("taskId").asText();
|
||||||
assertFalse(task.isBlank());
|
assertFalse(task.isBlank());
|
||||||
// Agent-native edit of the installed example; SDK remains unchanged.
|
// Agent-native edit of the installed example; SDK remains unchanged.
|
||||||
String edited = Files.readString(source).replace("import { Gfx } from @sdk:gfx;",
|
String edited = Files.readString(source).replace("import { Gfx } from @sdk:gfx;",
|
||||||
"import { Gfx } from @sdk:gfx;\nimport { Input } from @sdk:input;")
|
"import { Gfx } from @sdk:gfx;\nimport { Pad, Button, Touch } from @sdk:input;")
|
||||||
.replace("x = x + 1;", "if (Input.pad().right().down()) { x = x + 3; } else { x = x + 1; }");
|
.replace("x = x + 1;", "if (Pad.down(Button.Right)) { x = x + 3; } else { x = x + 1; }");
|
||||||
Files.writeString(source, edited);
|
Files.writeString(source, edited);
|
||||||
var query = args().put("operation", "diagnostics"); query.putObject("parameters").put("uri", source.toUri().toString());
|
var query = args().put("operation", "diagnostics"); query.putObject("parameters").put("uri", source.toUri().toString());
|
||||||
assertTrue(value(call("studio_language_query", query)).path("result").isEmpty());
|
assertTrue(value(call("studio_language_query", query)).path("result").isEmpty());
|
||||||
@@ -442,7 +450,7 @@ class HeadlessMcpDesktopTest {
|
|||||||
}
|
}
|
||||||
HttpResponse<String> post(JsonNode body) throws Exception {
|
HttpResponse<String> post(JsonNode body) throws Exception {
|
||||||
var request = HttpRequest.newBuilder(server.connection().endpoint()).timeout(Duration.ofSeconds(15))
|
var request = HttpRequest.newBuilder(server.connection().endpoint()).timeout(Duration.ofSeconds(15))
|
||||||
.header("Authorization", server.connection().authorizationHeader()).header("Content-Type", "application/json")
|
.header("Authorization", authorization).header("Content-Type", "application/json")
|
||||||
.header("Accept", "application/json, text/event-stream").header("MCP-Protocol-Version", "2025-06-18");
|
.header("Accept", "application/json, text/event-stream").header("MCP-Protocol-Version", "2025-06-18");
|
||||||
if (connection != null) request.header("Mcp-Session-Id", connection);
|
if (connection != null) request.header("Mcp-Session-Id", connection);
|
||||||
return client.send(request.POST(HttpRequest.BodyPublishers.ofString(body.toString())).build(), HttpResponse.BodyHandlers.ofString());
|
return client.send(request.POST(HttpRequest.BodyPublishers.ofString(body.toString())).build(), HttpResponse.BodyHandlers.ofString());
|
||||||
|
|||||||
@@ -18,6 +18,20 @@ class HeadlessProcessSessionTest {
|
|||||||
var session = new HeadlessProcessSession(process, new ObjectMapper(), HeadlessFixture.limits(mode), "build"); sessions.add(session); return session;
|
var session = new HeadlessProcessSession(process, new ObjectMapper(), HeadlessFixture.limits(mode), "build"); sessions.add(session); return session;
|
||||||
}
|
}
|
||||||
@AfterEach void cleanup() { sessions.forEach(session -> session.abort("test cleanup")); }
|
@AfterEach void cleanup() { sessions.forEach(session -> session.abort("test cleanup")); }
|
||||||
|
@Test void productionLoadDiagnosticsSurviveBootFailureAndMcpSerialization() throws Exception {
|
||||||
|
var mapper = new ObjectMapper();
|
||||||
|
for (String fixture : List.of("resource", "invalid-role", "retired-opcode", "native", "native-abi", "unknown-native")) {
|
||||||
|
var session = start("load-fault-" + fixture);
|
||||||
|
var failure = assertThrows(AutomationException.class, () -> session.initializeAndBoot(root)).failure();
|
||||||
|
var fault = mapper.readTree(getClass().getResourceAsStream("/runtime/fault-" + fixture + ".json"));
|
||||||
|
var error = mapper.valueToTree(failure.runtimeError());
|
||||||
|
assertEquals(fault, error.path("details").path("fault"));
|
||||||
|
assertTrue(error.path("details").path("fault").path("pc").isNull());
|
||||||
|
var wire = p.studio.app.mcp.McpToolResult.failure(mapper, failure).wire();
|
||||||
|
assertEquals(fault, wire.path("structuredContent").path("error").path("runtimeError").path("details").path("fault"));
|
||||||
|
assertThrows(UnsupportedOperationException.class, () -> failure.runtimeError().put("code", "changed"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@Test void fragmentedProtocolPreservesUnsignedFrameIdentityLayoutAndSeparateStderr() throws Exception {
|
@Test void fragmentedProtocolPreservesUnsignedFrameIdentityLayoutAndSeparateStderr() throws Exception {
|
||||||
var session = start("normal"); session.initializeAndBoot(root);
|
var session = start("normal"); session.initializeAndBoot(root);
|
||||||
var outcome = session.advance(3, ignored -> {});
|
var outcome = session.advance(3, ignored -> {});
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"initError": {
|
||||||
|
"code": "registry_load_failed",
|
||||||
|
"load": {
|
||||||
|
"code": "LOAD_INVALID_REGISTRY",
|
||||||
|
"function": 0,
|
||||||
|
"id_domain": null,
|
||||||
|
"limit": null,
|
||||||
|
"member": null,
|
||||||
|
"offset": 136,
|
||||||
|
"pc": null,
|
||||||
|
"reason": "LifecycleRole",
|
||||||
|
"record": 0,
|
||||||
|
"referenced_id": null,
|
||||||
|
"requested": null,
|
||||||
|
"resource": null,
|
||||||
|
"section": 1
|
||||||
|
},
|
||||||
|
"message": "RegistryLoadFailed(LoadFailure { code: InvalidRegistry, reason: LifecycleRole, section: Some(1), offset: Some(136), record: Some(0), member: None, id_domain: None, referenced_id: None, function: Some(0), pc: None, resource: None, requested: None, limit: None })"
|
||||||
|
},
|
||||||
|
"kind": "vm_init",
|
||||||
|
"pc": null,
|
||||||
|
"summary": "Conformance fixture"
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
{
|
||||||
|
"initError": {
|
||||||
|
"binding": {
|
||||||
|
"declared_arg_slots": 1,
|
||||||
|
"declared_ret_slots": 1,
|
||||||
|
"expected_arg_slots": 0,
|
||||||
|
"expected_ret_slots": 1,
|
||||||
|
"module": "system",
|
||||||
|
"name": "has_cart",
|
||||||
|
"reason": "abi_mismatch",
|
||||||
|
"version": 1
|
||||||
|
},
|
||||||
|
"code": "loader_patch_failed",
|
||||||
|
"message": "LoaderPatchFailed(ResolveFailed(AbiMismatch { module: \"system\", name: \"has_cart\", version: 1, declared_arg_slots: 1, declared_ret_slots: 1, expected_arg_slots: 0, expected_ret_slots: 1 }))"
|
||||||
|
},
|
||||||
|
"kind": "vm_init",
|
||||||
|
"pc": null,
|
||||||
|
"summary": "Conformance fixture"
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"initError": {
|
||||||
|
"binding": {
|
||||||
|
"module": "system",
|
||||||
|
"name": "has_cart",
|
||||||
|
"provided": 0,
|
||||||
|
"reason": "missing_capability",
|
||||||
|
"required": 1,
|
||||||
|
"version": 1
|
||||||
|
},
|
||||||
|
"code": "loader_patch_failed",
|
||||||
|
"message": "LoaderPatchFailed(ResolveFailed(MissingCapability { required: 1, provided: 0, module: \"system\", name: \"has_cart\", version: 1 }))"
|
||||||
|
},
|
||||||
|
"kind": "vm_init",
|
||||||
|
"pc": null,
|
||||||
|
"summary": "Conformance fixture"
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"initError": {
|
||||||
|
"code": "registry_load_failed",
|
||||||
|
"load": {
|
||||||
|
"code": "LOAD_RESOURCE_LIMIT",
|
||||||
|
"function": null,
|
||||||
|
"id_domain": null,
|
||||||
|
"limit": 0,
|
||||||
|
"member": null,
|
||||||
|
"offset": null,
|
||||||
|
"pc": null,
|
||||||
|
"reason": "Limit",
|
||||||
|
"record": null,
|
||||||
|
"referenced_id": null,
|
||||||
|
"requested": 32,
|
||||||
|
"resource": "Work",
|
||||||
|
"section": null
|
||||||
|
},
|
||||||
|
"message": "RegistryLoadFailed(LoadFailure { code: ResourceLimit, reason: Limit, section: None, offset: None, record: None, member: None, id_domain: None, referenced_id: None, function: None, pc: None, resource: Some(Work), requested: Some(32), limit: Some(0) })"
|
||||||
|
},
|
||||||
|
"kind": "vm_init",
|
||||||
|
"pc": null,
|
||||||
|
"summary": "Conformance fixture"
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"initError": {
|
||||||
|
"code": "registry_load_failed",
|
||||||
|
"load": {
|
||||||
|
"code": "LOAD_INVALID_CODE",
|
||||||
|
"function": 0,
|
||||||
|
"id_domain": null,
|
||||||
|
"limit": null,
|
||||||
|
"member": null,
|
||||||
|
"offset": null,
|
||||||
|
"pc": 0,
|
||||||
|
"reason": "Truncated",
|
||||||
|
"record": null,
|
||||||
|
"referenced_id": null,
|
||||||
|
"requested": null,
|
||||||
|
"resource": null,
|
||||||
|
"section": 2
|
||||||
|
},
|
||||||
|
"message": "RegistryLoadFailed(LoadFailure { code: InvalidCode, reason: Truncated, section: Some(2), offset: None, record: None, member: None, id_domain: None, referenced_id: None, function: Some(0), pc: Some(0), resource: None, requested: None, limit: None })"
|
||||||
|
},
|
||||||
|
"kind": "vm_init",
|
||||||
|
"pc": null,
|
||||||
|
"summary": "Conformance fixture"
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"initError": {
|
||||||
|
"binding": {
|
||||||
|
"module": "system",
|
||||||
|
"name": "missing",
|
||||||
|
"reason": "unknown_syscall",
|
||||||
|
"version": 1
|
||||||
|
},
|
||||||
|
"code": "loader_patch_failed",
|
||||||
|
"message": "LoaderPatchFailed(ResolveFailed(UnknownSyscall { module: \"system\", name: \"missing\", version: 1 }))"
|
||||||
|
},
|
||||||
|
"kind": "vm_init",
|
||||||
|
"pc": null,
|
||||||
|
"summary": "Conformance fixture"
|
||||||
|
}
|
||||||
@@ -13,9 +13,11 @@ dependencies {
|
|||||||
|
|
||||||
// Build-time projection of owner-maintained sources; no second normative copy is edited by Studio.
|
// Build-time projection of owner-maintained sources; no second normative copy is edited by Studio.
|
||||||
val pbsSpecs = rootProject.layout.projectDirectory.dir("docs/specs/compiler-languages/pbs")
|
val pbsSpecs = rootProject.layout.projectDirectory.dir("docs/specs/compiler-languages/pbs")
|
||||||
|
val pbsAlignmentSpecs = rootProject.layout.projectDirectory.dir("docs/compiler/pbs/specs")
|
||||||
val pbsResources = layout.projectDirectory.dir("src/main/resources")
|
val pbsResources = layout.projectDirectory.dir("src/main/resources")
|
||||||
val generatePbsKnowledge by tasks.registering(Sync::class) {
|
val generatePbsKnowledge by tasks.registering(Sync::class) {
|
||||||
from(pbsSpecs) { include("*.md"); into("pbs-knowledge/specs") }
|
from(pbsSpecs) { include("*.md"); into("pbs-knowledge/specs") }
|
||||||
|
from(pbsAlignmentSpecs) { include("*.md"); into("pbs-knowledge/specs") }
|
||||||
into(layout.buildDirectory.dir("generated/pbsKnowledge"))
|
into(layout.buildDirectory.dir("generated/pbsKnowledge"))
|
||||||
inputs.files(fileTree(pbsResources) { include("game/stdlib/**/*.pbs", "game/stdlib/**/*.barrel", "pbs-knowledge/examples/**") })
|
inputs.files(fileTree(pbsResources) { include("game/stdlib/**/*.pbs", "game/stdlib/**/*.barrel", "pbs-knowledge/examples/**") })
|
||||||
doLast {
|
doLast {
|
||||||
@@ -27,7 +29,7 @@ val generatePbsKnowledge by tasks.registering(Sync::class) {
|
|||||||
entries.add(linkedMapOf("id" to id, "title" to title, "kind" to kind,
|
entries.add(linkedMapOf("id" to id, "title" to title, "kind" to kind,
|
||||||
"resource" to resource, "sha256" to digest, "sdkVersion" to sdk, "target" to target))
|
"resource" to resource, "sha256" to digest, "sdkVersion" to sdk, "target" to target))
|
||||||
}
|
}
|
||||||
pbsSpecs.asFile.listFiles()!!.filter { it.extension == "md" }.sortedBy { it.name }.forEach { source ->
|
(pbsSpecs.asFile.listFiles()!!.toList() + (pbsAlignmentSpecs.asFile.listFiles()?.toList() ?: emptyList())).filter { it.extension == "md" }.sortedBy { it.name }.forEach { source ->
|
||||||
val chapter = source.name.substringBefore(". ")
|
val chapter = source.name.substringBefore(". ")
|
||||||
val quickstart = source.name == "README.md"
|
val quickstart = source.name == "README.md"
|
||||||
entry(if (quickstart) "pbs:quickstart" else "pbs:spec:$chapter",
|
entry(if (quickstart) "pbs:quickstart" else "pbs:spec:$chapter",
|
||||||
@@ -54,3 +56,10 @@ val generatePbsKnowledge by tasks.registering(Sync::class) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
sourceSets.main { resources.srcDir(generatePbsKnowledge) }
|
sourceSets.main { resources.srcDir(generatePbsKnowledge) }
|
||||||
|
|
||||||
|
tasks.named<ProcessResources>("processResources") {
|
||||||
|
from(rootProject.layout.projectDirectory.dir("docs/vm-arch")) {
|
||||||
|
include("INTRINSICS.csv", "BUILTIN_CONSTANTS.csv", "runtime-catalog.properties")
|
||||||
|
into("runtime-catalog/pbs-sdk")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+43
-3
@@ -32,6 +32,7 @@ import p.studio.compiler.services.FrontendDocumentLink;
|
|||||||
import p.studio.compiler.services.FrontendFoldingRange;
|
import p.studio.compiler.services.FrontendFoldingRange;
|
||||||
import p.studio.compiler.services.FrontendSelectionRange;
|
import p.studio.compiler.services.FrontendSelectionRange;
|
||||||
import p.studio.compiler.services.FrontendDefinitionLocation;
|
import p.studio.compiler.services.FrontendDefinitionLocation;
|
||||||
|
import p.studio.compiler.services.FrontendSourceDocument;
|
||||||
import p.studio.compiler.services.FrontendDocumentRequest;
|
import p.studio.compiler.services.FrontendDocumentRequest;
|
||||||
import p.studio.compiler.services.FrontendDocumentSymbol;
|
import p.studio.compiler.services.FrontendDocumentSymbol;
|
||||||
import p.studio.compiler.services.FrontendRenameEdit;
|
import p.studio.compiler.services.FrontendRenameEdit;
|
||||||
@@ -63,6 +64,38 @@ import java.util.Objects;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public final class PBSFrontendLanguageService implements FrontendLanguageService {
|
public final class PBSFrontendLanguageService implements FrontendLanguageService {
|
||||||
|
@Override
|
||||||
|
public boolean supportsExternalSources() { return true; }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<FrontendSourceDocument> sourceDocument(
|
||||||
|
final FrontendDocumentRequest request,
|
||||||
|
final FrontendEditorialContext context,
|
||||||
|
final Path path) {
|
||||||
|
if (!(context.projectSurface() instanceof PbsSemanticReadSurface surface)
|
||||||
|
|| !(context.sourceFiles() instanceof FileTableReader files)) return Optional.empty();
|
||||||
|
FrontendSourceDocument projectSource = null;
|
||||||
|
for (final var entry : surface.astByFile().entrySet()) {
|
||||||
|
final var handle = files.get(entry.getKey());
|
||||||
|
if (handle == null || !handle.getCanonPath().toAbsolutePath().normalize().equals(path.toAbsolutePath().normalize())) continue;
|
||||||
|
final var text = handle.readUtf8();
|
||||||
|
if (text.isEmpty()) return Optional.empty();
|
||||||
|
final boolean bundled = surface.sourceKindByFile().get(entry.getKey()) == SourceKind.SDK_INTERFACE;
|
||||||
|
final Path owner = surface.ownerRootByFile().get(entry.getKey());
|
||||||
|
final boolean external = bundled || owner == null || !owner.toAbsolutePath().normalize().equals(request.projectRoot().toAbsolutePath().normalize());
|
||||||
|
final var source = new FrontendSourceDocument(path, text.orElseThrow(),
|
||||||
|
bundled ? "bundled" : external ? "dependency" : "project",
|
||||||
|
handle.getRelativePath().toString(), "pbs", external,
|
||||||
|
new FrontendEditorialContext(entry.getValue(),
|
||||||
|
surface.supplementalTopDeclsByFile().getOrDefault(entry.getKey(), ReadOnlyList.empty()),
|
||||||
|
context.semanticContext(), files, surface));
|
||||||
|
// A dependency may physically overlap a project source root. External
|
||||||
|
// ownership wins even if another file-table entry treats it as local.
|
||||||
|
if (external) return Optional.of(source);
|
||||||
|
projectSource = source;
|
||||||
|
}
|
||||||
|
return Optional.ofNullable(projectSource);
|
||||||
|
}
|
||||||
private final PbsEditorialSupportService editorialSupportService;
|
private final PbsEditorialSupportService editorialSupportService;
|
||||||
private final PBSSemanticTokenProvider semanticTokenProvider;
|
private final PBSSemanticTokenProvider semanticTokenProvider;
|
||||||
|
|
||||||
@@ -257,7 +290,12 @@ public final class PBSFrontendLanguageService implements FrontendLanguageService
|
|||||||
typedSupplementalTopDecls,
|
typedSupplementalTopDecls,
|
||||||
feSurfaceContext,
|
feSurfaceContext,
|
||||||
offset)) {
|
offset)) {
|
||||||
toFrontendLocation(location, fileTable).ifPresent(locations::add);
|
final var handle = fileTable.get(location.span().getFileId());
|
||||||
|
if (handle != null) {
|
||||||
|
sourceDocument(request, editorialContext, handle.getCanonPath()).ifPresent(source ->
|
||||||
|
locations.add(new FrontendDefinitionLocation(source.path(),
|
||||||
|
toOffset(location.span().getStart()), toOffset(location.span().getEnd()), source)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return List.copyOf(locations);
|
return List.copyOf(locations);
|
||||||
}
|
}
|
||||||
@@ -401,14 +439,16 @@ public final class PBSFrontendLanguageService implements FrontendLanguageService
|
|||||||
}
|
}
|
||||||
final LinkedHashMap<String, FrontendRenameEdit> edits = new LinkedHashMap<>();
|
final LinkedHashMap<String, FrontendRenameEdit> edits = new LinkedHashMap<>();
|
||||||
for (final PbsEditorialLocation site : planned.sites()) {
|
for (final PbsEditorialLocation site : planned.sites()) {
|
||||||
toFrontendLocation(site, fileTable).ifPresent(location ->
|
final var mapped = toFrontendLocation(site, fileTable);
|
||||||
|
if (mapped.isEmpty()) return FrontendRenameResult.refused("rename requires a non-editable source");
|
||||||
|
final var location = mapped.orElseThrow();
|
||||||
edits.putIfAbsent(
|
edits.putIfAbsent(
|
||||||
frontendLocationKey(location),
|
frontendLocationKey(location),
|
||||||
new FrontendRenameEdit(
|
new FrontendRenameEdit(
|
||||||
location.path(),
|
location.path(),
|
||||||
location.startOffset(),
|
location.startOffset(),
|
||||||
location.endOffset(),
|
location.endOffset(),
|
||||||
newName)));
|
newName));
|
||||||
}
|
}
|
||||||
if (edits.isEmpty()) {
|
if (edits.isEmpty()) {
|
||||||
return FrontendRenameResult.refused("not renameable");
|
return FrontendRenameResult.refused("not renameable");
|
||||||
|
|||||||
+1
-1
@@ -25,7 +25,7 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public final class PBSSemanticTokenProvider implements FrontendSemanticTokenProvider {
|
public final class PBSSemanticTokenProvider implements FrontendSemanticTokenProvider {
|
||||||
private static final Set<String> BUILTIN_TYPE_NAMES = Set.of("int", "float", "bool", "string", "i32", "i64", "f32", "f64");
|
private static final Set<String> BUILTIN_TYPE_NAMES = Set.of("int", "long", "float", "bool", "string", "i32", "i64", "f32", "f64");
|
||||||
private static final int DEFAULT_STDLIB_VERSION = 1;
|
private static final int DEFAULT_STDLIB_VERSION = 1;
|
||||||
private static final AppMode DEFAULT_TARGET = AppMode.Game;
|
private static final AppMode DEFAULT_TARGET = AppMode.Game;
|
||||||
private static final ResourceStdlibEnvironmentResolver STDLIB_RESOLVER = new ResourceStdlibEnvironmentResolver();
|
private static final ResourceStdlibEnvironmentResolver STDLIB_RESOLVER = new ResourceStdlibEnvironmentResolver();
|
||||||
|
|||||||
+1
-1
@@ -234,7 +234,7 @@ public final class PbsFrontendCompiler {
|
|||||||
effectiveModulePool,
|
effectiveModulePool,
|
||||||
ReadOnlyList.wrap(callableSignatures),
|
ReadOnlyList.wrap(callableSignatures),
|
||||||
executableLowering.intrinsicPool(),
|
executableLowering.intrinsicPool(),
|
||||||
lifecycleDeclaration);
|
lifecycleDeclaration, executableLowering.registry());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String callableShapeSurfaceOf(final PbsAst.FunctionDecl functionDecl) {
|
public String callableShapeSurfaceOf(final PbsAst.FunctionDecl functionDecl) {
|
||||||
|
|||||||
+7
-1
@@ -43,6 +43,12 @@ public final class PbsModuleVisibilityValidator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String inputMigrationHint(String module, String name) {
|
||||||
|
return "@sdk:input".equals(module) && java.util.Set.of("Input", "InputType", "InputPad", "InputTouch", "InputButton").contains(name)
|
||||||
|
? "; migrate to Pad.pressed/released/down/hold(Button.A) or Touch queries. Intermediate input objects are no longer values."
|
||||||
|
: "";
|
||||||
|
}
|
||||||
|
|
||||||
private ModuleExports validateModule(
|
private ModuleExports validateModule(
|
||||||
final ModuleUnit module,
|
final ModuleUnit module,
|
||||||
final NameTable nameTable,
|
final NameTable nameTable,
|
||||||
@@ -219,7 +225,7 @@ public final class PbsModuleVisibilityValidator {
|
|||||||
PbsLinkErrors.E_LINK_IMPORT_SYMBOL_UNRESOLVED.name(),
|
PbsLinkErrors.E_LINK_IMPORT_SYMBOL_UNRESOLVED.name(),
|
||||||
"Symbol '%s' does not exist in module %s".formatted(
|
"Symbol '%s' does not exist in module %s".formatted(
|
||||||
importItem.name(),
|
importItem.name(),
|
||||||
displayModule(targetModule)),
|
displayModule(targetModule)) + inputMigrationHint(displayModule(targetModule), importItem.name()),
|
||||||
importItem.span());
|
importItem.span());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
+195
-50
@@ -28,7 +28,7 @@ final class PbsExecutableBodyLowerer {
|
|||||||
final PbsExecutableMetadataIndex metadataIndex,
|
final PbsExecutableMetadataIndex metadataIndex,
|
||||||
final PbsExecutableCallableRegistry callableRegistry,
|
final PbsExecutableCallableRegistry callableRegistry,
|
||||||
final IntrinsicTable intrinsicIdTable) {
|
final IntrinsicTable intrinsicIdTable) {
|
||||||
final var localSlotByNameId = initialLocalSlots(functionDecl, nameTable);
|
final var localSlotByNameId = initialLocalSlots(functionDecl, nameTable, metadataIndex.types());
|
||||||
final var localOwnerByNameId = initialLocalOwners(functionDecl, nameTable, metadataIndex);
|
final var localOwnerByNameId = initialLocalOwners(functionDecl, nameTable, metadataIndex);
|
||||||
final var context = new PbsExecutableLoweringContext(
|
final var context = new PbsExecutableLoweringContext(
|
||||||
diagnostics,
|
diagnostics,
|
||||||
@@ -38,11 +38,13 @@ final class PbsExecutableBodyLowerer {
|
|||||||
intrinsicIdTable,
|
intrinsicIdTable,
|
||||||
localSlotByNameId,
|
localSlotByNameId,
|
||||||
localOwnerByNameId,
|
localOwnerByNameId,
|
||||||
functionDecl.parameters().size());
|
functionDecl.parameters().stream().mapToInt(p -> metadataIndex.types().slots(p.typeRef())).sum());
|
||||||
|
for (var parameter : functionDecl.parameters()) context.localTypes.put(parameter.name(), parameter.typeRef());
|
||||||
|
context.returnType = functionDecl.returnType();
|
||||||
final var terminated = lowerBlock(functionDecl.body(), context);
|
final var terminated = lowerBlock(functionDecl.body(), context);
|
||||||
finalizeFunctionInstructions(functionDecl, context, terminated);
|
finalizeFunctionInstructions(functionDecl, context, terminated);
|
||||||
|
|
||||||
final var returnSlots = returnSlotsFor(functionDecl);
|
final var returnSlots = functionDecl.returnKind() == PbsAst.ReturnKind.PLAIN ? context.types().slots(functionDecl.returnType()) : 0;
|
||||||
final int maxStackSlots;
|
final int maxStackSlots;
|
||||||
try {
|
try {
|
||||||
maxStackSlots = stackAnalyzer.analyzeMaxStackSlots(ReadOnlyList.wrap(context.instructions()), returnSlots);
|
maxStackSlots = stackAnalyzer.analyzeMaxStackSlots(ReadOnlyList.wrap(context.instructions()), returnSlots);
|
||||||
@@ -56,7 +58,7 @@ final class PbsExecutableBodyLowerer {
|
|||||||
functionDecl.span());
|
functionDecl.span());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final var localSlots = Math.max(0, context.nextLocalSlot() - functionDecl.parameters().size());
|
final var localSlots = Math.max(0, context.nextLocalSlot() - functionDecl.parameters().stream().mapToInt(p -> context.types().slots(p.typeRef())).sum());
|
||||||
return new PbsLoweredExecutableBody(
|
return new PbsLoweredExecutableBody(
|
||||||
ReadOnlyList.wrap(context.instructions()),
|
ReadOnlyList.wrap(context.instructions()),
|
||||||
localSlots,
|
localSlots,
|
||||||
@@ -65,10 +67,12 @@ final class PbsExecutableBodyLowerer {
|
|||||||
|
|
||||||
private Map<NameId, Integer> initialLocalSlots(
|
private Map<NameId, Integer> initialLocalSlots(
|
||||||
final PbsAst.FunctionDecl functionDecl,
|
final PbsAst.FunctionDecl functionDecl,
|
||||||
final NameTable nameTable) {
|
final NameTable nameTable, final PbsRuntimeTypes types) {
|
||||||
final var localSlotByNameId = new HashMap<NameId, Integer>();
|
final var localSlotByNameId = new HashMap<NameId, Integer>();
|
||||||
for (var paramIndex = 0; paramIndex < functionDecl.parameters().size(); paramIndex++) {
|
int slot = 0;
|
||||||
localSlotByNameId.put(nameTable.register(functionDecl.parameters().get(paramIndex).name()), paramIndex);
|
for (var parameter : functionDecl.parameters()) {
|
||||||
|
localSlotByNameId.put(nameTable.register(parameter.name()), slot);
|
||||||
|
slot += types.slots(parameter.typeRef());
|
||||||
}
|
}
|
||||||
return localSlotByNameId;
|
return localSlotByNameId;
|
||||||
}
|
}
|
||||||
@@ -155,7 +159,9 @@ final class PbsExecutableBodyLowerer {
|
|||||||
final var localOwner = callsiteEmitter.resolveExpressionOwnerForLowering(letStatement.initializer(), context);
|
final var localOwner = callsiteEmitter.resolveExpressionOwnerForLowering(letStatement.initializer(), context);
|
||||||
final var tupleProjection = tupleProjectionOf(letStatement.initializer(), context);
|
final var tupleProjection = tupleProjectionOf(letStatement.initializer(), context);
|
||||||
final var valueSlots = Math.max(1, materializedValueSlots(letStatement.initializer(), context));
|
final var valueSlots = Math.max(1, materializedValueSlots(letStatement.initializer(), context));
|
||||||
lowerExpression(letStatement.initializer(), context);
|
final var localType = letStatement.explicitType() != null ? letStatement.explicitType() : expressionType(letStatement.initializer(), context);
|
||||||
|
lowerExpected(letStatement.initializer(), localType, context);
|
||||||
|
context.localTypes.put(letStatement.name(), localType);
|
||||||
final var localSlot = context.declareLocalSlots(letStatement.name(), valueSlots);
|
final var localSlot = context.declareLocalSlots(letStatement.name(), valueSlots);
|
||||||
context.bindLocalOwner(letStatement.name(), localOwner);
|
context.bindLocalOwner(letStatement.name(), localOwner);
|
||||||
context.bindLocalTupleProjection(letStatement.name(), tupleProjection);
|
context.bindLocalTupleProjection(letStatement.name(), tupleProjection);
|
||||||
@@ -185,7 +191,7 @@ final class PbsExecutableBodyLowerer {
|
|||||||
final var localOwner = callsiteEmitter.resolveExpressionOwnerForLowering(assignStatement.value(), context);
|
final var localOwner = callsiteEmitter.resolveExpressionOwnerForLowering(assignStatement.value(), context);
|
||||||
final var tupleProjection = tupleProjectionOf(assignStatement.value(), context);
|
final var tupleProjection = tupleProjectionOf(assignStatement.value(), context);
|
||||||
final var valueSlots = Math.max(1, materializedValueSlots(assignStatement.value(), context));
|
final var valueSlots = Math.max(1, materializedValueSlots(assignStatement.value(), context));
|
||||||
lowerExpression(assignStatement.value(), context);
|
lowerExpected(assignStatement.value(), context.localTypes.getOrDefault(target.rootName(), context.types().values.get(target.rootName())), context);
|
||||||
if (targetLocalSlot != null) {
|
if (targetLocalSlot != null) {
|
||||||
context.bindLocalOwner(target.rootName(), localOwner);
|
context.bindLocalOwner(target.rootName(), localOwner);
|
||||||
context.bindLocalTupleProjection(target.rootName(), tupleProjection);
|
context.bindLocalTupleProjection(target.rootName(), tupleProjection);
|
||||||
@@ -200,7 +206,7 @@ final class PbsExecutableBodyLowerer {
|
|||||||
} else {
|
} else {
|
||||||
emitGetGlobal(targetGlobalSlot, assignStatement.span(), context);
|
emitGetGlobal(targetGlobalSlot, assignStatement.span(), context);
|
||||||
}
|
}
|
||||||
lowerExpression(assignStatement.value(), context);
|
lowerExpected(assignStatement.value(), context.localTypes.getOrDefault(target.rootName(), context.types().values.get(target.rootName())), context);
|
||||||
emitBinaryOperatorInstruction(compoundAssignBinaryOperator(assignStatement.operator()), assignStatement.span(), context);
|
emitBinaryOperatorInstruction(compoundAssignBinaryOperator(assignStatement.operator()), assignStatement.span(), context);
|
||||||
if (targetLocalSlot != null) {
|
if (targetLocalSlot != null) {
|
||||||
context.bindLocalOwner(target.rootName(), "");
|
context.bindLocalOwner(target.rootName(), "");
|
||||||
@@ -235,7 +241,7 @@ final class PbsExecutableBodyLowerer {
|
|||||||
final PbsAst.ReturnStatement returnStatement,
|
final PbsAst.ReturnStatement returnStatement,
|
||||||
final PbsExecutableLoweringContext context) {
|
final PbsExecutableLoweringContext context) {
|
||||||
if (returnStatement.value() != null) {
|
if (returnStatement.value() != null) {
|
||||||
lowerExpression(returnStatement.value(), context);
|
lowerExpected(returnStatement.value(), context.returnType, context);
|
||||||
}
|
}
|
||||||
context.instructions().add(new IRBackendExecutableFunction.Instruction(
|
context.instructions().add(new IRBackendExecutableFunction.Instruction(
|
||||||
IRBackendExecutableFunction.InstructionKind.RET,
|
IRBackendExecutableFunction.InstructionKind.RET,
|
||||||
@@ -363,10 +369,7 @@ final class PbsExecutableBodyLowerer {
|
|||||||
}
|
}
|
||||||
switch (expression) {
|
switch (expression) {
|
||||||
case PbsAst.CallExpr callExpr -> lowerCallExpression(callExpr, context);
|
case PbsAst.CallExpr callExpr -> lowerCallExpression(callExpr, context);
|
||||||
case PbsAst.ApplyExpr applyExpr -> {
|
case PbsAst.ApplyExpr applyExpr -> lowerApply(applyExpr, context);
|
||||||
lowerExpression(applyExpr.callee(), context);
|
|
||||||
lowerExpression(applyExpr.argument(), context);
|
|
||||||
}
|
|
||||||
case PbsAst.BinaryExpr binaryExpr -> {
|
case PbsAst.BinaryExpr binaryExpr -> {
|
||||||
lowerExpression(binaryExpr.left(), context);
|
lowerExpression(binaryExpr.left(), context);
|
||||||
lowerExpression(binaryExpr.right(), context);
|
lowerExpression(binaryExpr.right(), context);
|
||||||
@@ -381,36 +384,36 @@ final class PbsExecutableBodyLowerer {
|
|||||||
lowerExpression(elseExpr.fallbackExpression(), context);
|
lowerExpression(elseExpr.fallbackExpression(), context);
|
||||||
}
|
}
|
||||||
case PbsAst.IfExpr ifExpr -> lowerIfExpression(ifExpr, context);
|
case PbsAst.IfExpr ifExpr -> lowerIfExpression(ifExpr, context);
|
||||||
case PbsAst.SwitchExpr switchExpr -> lowerUnsupportedExpression(
|
case PbsAst.SwitchExpr switchExpr -> lowerSwitch(switchExpr, context);
|
||||||
switchExpr.selector(),
|
|
||||||
"switch expression is not lowerable in executable lowering v1",
|
|
||||||
switchExpr.span(),
|
|
||||||
context);
|
|
||||||
case PbsAst.HandleExpr handleExpr -> lowerUnsupportedExpression(
|
case PbsAst.HandleExpr handleExpr -> lowerUnsupportedExpression(
|
||||||
handleExpr.value(),
|
handleExpr.value(),
|
||||||
"handle expression is not lowerable in executable lowering v1",
|
"handle expression is not lowerable in executable lowering v1",
|
||||||
handleExpr.span(),
|
handleExpr.span(),
|
||||||
context);
|
context);
|
||||||
case PbsAst.AsExpr asExpr -> lowerExpression(asExpr.expression(), context);
|
case PbsAst.AsExpr asExpr -> lowerConversion(asExpr, context);
|
||||||
case PbsAst.MemberExpr memberExpr -> lowerMemberExpression(memberExpr, context);
|
case PbsAst.MemberExpr memberExpr -> lowerMemberExpression(memberExpr, context);
|
||||||
case PbsAst.PropagateExpr propagateExpr -> lowerExpression(propagateExpr.expression(), context);
|
case PbsAst.PropagateExpr propagateExpr -> lowerExpression(propagateExpr.expression(), context);
|
||||||
case PbsAst.GroupExpr groupExpr -> lowerExpression(groupExpr.expression(), context);
|
case PbsAst.GroupExpr groupExpr -> lowerExpression(groupExpr.expression(), context);
|
||||||
case PbsAst.NewExpr newExpr -> lowerExpressionList(newExpr.arguments(), context);
|
case PbsAst.NewExpr newExpr -> {
|
||||||
|
var fields = context.types().fields.get(newExpr.typeName());
|
||||||
|
for(int i=0; i<newExpr.arguments().size(); i++) lowerExpected(newExpr.arguments().get(i), fields != null && i < fields.size() ? fields.get(i).typeRef() : null, context);
|
||||||
|
}
|
||||||
case PbsAst.BindExpr bindExpr -> lowerExpression(bindExpr.contextExpression(), context);
|
case PbsAst.BindExpr bindExpr -> lowerExpression(bindExpr.contextExpression(), context);
|
||||||
case PbsAst.SomeExpr someExpr -> lowerExpression(someExpr.value(), context);
|
case PbsAst.SomeExpr someExpr -> lowerExpression(someExpr.value(), context);
|
||||||
case PbsAst.OkExpr okExpr -> lowerExpression(okExpr.value(), context);
|
case PbsAst.OkExpr okExpr -> lowerExpression(okExpr.value(), context);
|
||||||
case PbsAst.TupleExpr tupleExpr -> {
|
case PbsAst.TupleExpr tupleExpr -> {
|
||||||
for (final var item : tupleExpr.items()) {
|
var expected = context.expectedType;
|
||||||
lowerExpression(item.expression(), context);
|
for (int index=0; index<tupleExpr.items().size(); index++) {
|
||||||
|
var item=tupleExpr.items().get(index);
|
||||||
|
var fieldType=expected != null && expected.kind()==PbsAst.TypeRefKind.NAMED_TUPLE && index<expected.fields().size() ? expected.fields().get(index).typeRef() : null;
|
||||||
|
lowerExpected(item.expression(), fieldType, context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case PbsAst.BlockExpr blockExpr -> lowerBlock(blockExpr.block(), context);
|
case PbsAst.BlockExpr blockExpr -> lowerBlock(blockExpr.block(), context);
|
||||||
case PbsAst.IdentifierExpr identifierExpr -> lowerIdentifierExpression(identifierExpr, context);
|
case PbsAst.IdentifierExpr identifierExpr -> lowerIdentifierExpression(identifierExpr, context);
|
||||||
case PbsAst.IntLiteralExpr intLiteralExpr -> lowerIntLiteral(intLiteralExpr, context);
|
case PbsAst.IntLiteralExpr intLiteralExpr -> lowerIntLiteral(intLiteralExpr, context);
|
||||||
case PbsAst.FloatLiteralExpr ignored -> {
|
case PbsAst.FloatLiteralExpr literal -> emitLiteral(IRBackendExecutableFunction.InstructionKind.PUSH_F64, Double.toString(literal.value()), literal.span(), context);
|
||||||
}
|
case PbsAst.BoundedLiteralExpr literal -> emitPushI32(literal.value(), literal.span(), context);
|
||||||
case PbsAst.BoundedLiteralExpr ignored -> {
|
|
||||||
}
|
|
||||||
case PbsAst.StringLiteralExpr stringLiteralExpr -> emitPushConst(stringLiteralExpr.value(), stringLiteralExpr.span(), context);
|
case PbsAst.StringLiteralExpr stringLiteralExpr -> emitPushConst(stringLiteralExpr.value(), stringLiteralExpr.span(), context);
|
||||||
case PbsAst.BoolLiteralExpr boolLiteralExpr -> emitPushBool(boolLiteralExpr.value(), boolLiteralExpr.span(), context);
|
case PbsAst.BoolLiteralExpr boolLiteralExpr -> emitPushBool(boolLiteralExpr.value(), boolLiteralExpr.span(), context);
|
||||||
case PbsAst.ThisExpr ignored -> {
|
case PbsAst.ThisExpr ignored -> {
|
||||||
@@ -437,7 +440,10 @@ final class PbsExecutableBodyLowerer {
|
|||||||
final PbsExecutableLoweringContext context) {
|
final PbsExecutableLoweringContext context) {
|
||||||
final var hostBinding = callsiteEmitter.resolveUniqueHostBinding(callExpr, context);
|
final var hostBinding = callsiteEmitter.resolveUniqueHostBinding(callExpr, context);
|
||||||
if (hostBinding == null || hostBinding.assetLoweringParam() == null) {
|
if (hostBinding == null || hostBinding.assetLoweringParam() == null) {
|
||||||
lowerExpressionList(callExpr.arguments(), context);
|
final var signature = context.types().signatures.get(PbsRuntimeTypes.path(callExpr.callee())+"#"+callExpr.arguments().size());
|
||||||
|
for (int i=0; i<callExpr.arguments().size(); i++) {
|
||||||
|
lowerExpected(callExpr.arguments().get(i), signature != null && i < signature.parameters().size() ? signature.parameters().get(i).typeRef() : null, context);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < callExpr.arguments().size(); i++) {
|
for (int i = 0; i < callExpr.arguments().size(); i++) {
|
||||||
@@ -476,6 +482,10 @@ final class PbsExecutableBodyLowerer {
|
|||||||
private void lowerMemberExpression(
|
private void lowerMemberExpression(
|
||||||
final PbsAst.MemberExpr memberExpr,
|
final PbsAst.MemberExpr memberExpr,
|
||||||
final PbsExecutableLoweringContext context) {
|
final PbsExecutableLoweringContext context) {
|
||||||
|
if (memberExpr.receiver() instanceof PbsAst.IdentifierExpr owner) {
|
||||||
|
final var enumValue = context.types().enumValue(owner.name(), memberExpr.memberName());
|
||||||
|
if (enumValue != null) { emitPushI32(enumValue, memberExpr.span(), context); return; }
|
||||||
|
}
|
||||||
final var assetReference = flattenAssetReference(memberExpr);
|
final var assetReference = flattenAssetReference(memberExpr);
|
||||||
if (assetReference != null) {
|
if (assetReference != null) {
|
||||||
final var assetId = context.resolveAssetId(assetReference);
|
final var assetId = context.resolveAssetId(assetReference);
|
||||||
@@ -492,6 +502,15 @@ final class PbsExecutableBodyLowerer {
|
|||||||
if (memberExpr.receiver() instanceof PbsAst.IdentifierExpr identifierExpr) {
|
if (memberExpr.receiver() instanceof PbsAst.IdentifierExpr identifierExpr) {
|
||||||
final var tupleProjection = context.resolveLocalTupleProjection(identifierExpr.name());
|
final var tupleProjection = context.resolveLocalTupleProjection(identifierExpr.name());
|
||||||
final var localSlot = context.resolveLocalSlot(identifierExpr.name());
|
final var localSlot = context.resolveLocalSlot(identifierExpr.name());
|
||||||
|
var type = context.localTypes.get(identifierExpr.name());
|
||||||
|
var fields = type == null ? null : context.types().fields.get(type.name());
|
||||||
|
if (fields != null && localSlot != null) {
|
||||||
|
int offset = 0;
|
||||||
|
for (var field : fields) {
|
||||||
|
if (field.name().equals(memberExpr.memberName())) { emitLoadLocalSlots(localSlot + offset, context.types().slots(field.typeRef()), memberExpr.span(), context); return; }
|
||||||
|
offset += context.types().slots(field.typeRef());
|
||||||
|
}
|
||||||
|
}
|
||||||
if (tupleProjection != null && localSlot != null) {
|
if (tupleProjection != null && localSlot != null) {
|
||||||
final var fieldProjection = tupleProjection.fieldsByLabel().get(memberExpr.memberName());
|
final var fieldProjection = tupleProjection.fieldsByLabel().get(memberExpr.memberName());
|
||||||
if (fieldProjection != null) {
|
if (fieldProjection != null) {
|
||||||
@@ -562,7 +581,7 @@ final class PbsExecutableBodyLowerer {
|
|||||||
if (tupleProjection != null) {
|
if (tupleProjection != null) {
|
||||||
emitLoadLocalSlots(slot, tupleProjection.slotCount(), identifierExpr.span(), context);
|
emitLoadLocalSlots(slot, tupleProjection.slotCount(), identifierExpr.span(), context);
|
||||||
} else {
|
} else {
|
||||||
emitGetLocal(slot, identifierExpr.span(), context);
|
emitLoadLocalSlots(slot, Math.max(1, context.types().slots(context.localTypes.get(identifierExpr.name()))), identifierExpr.span(), context);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -586,18 +605,10 @@ final class PbsExecutableBodyLowerer {
|
|||||||
final p.studio.compiler.models.IRReservedMetadata.BuiltinConstSurface builtinConst,
|
final p.studio.compiler.models.IRReservedMetadata.BuiltinConstSurface builtinConst,
|
||||||
final p.studio.compiler.source.Span span,
|
final p.studio.compiler.source.Span span,
|
||||||
final PbsExecutableLoweringContext context) {
|
final PbsExecutableLoweringContext context) {
|
||||||
final var canonicalName = builtinConst.canonicalTarget() + "." + builtinConst.canonicalName();
|
context.instructions().add(new IRBackendExecutableFunction.Instruction(IRBackendExecutableFunction.InstructionKind.BUILTIN_CONST,
|
||||||
context.instructions().add(new IRBackendExecutableFunction.Instruction(
|
ModuleId.none(), "", null, null, null,
|
||||||
IRBackendExecutableFunction.InstructionKind.CALL_INTRINSIC,
|
builtinConst.canonicalTarget() + "." + builtinConst.canonicalName() + "@" + builtinConst.canonicalVersion(), "", null,
|
||||||
"",
|
context.types().slots(context.types().values.get(builtinConst.sourceConstName())), span));
|
||||||
null,
|
|
||||||
new IRBackendExecutableFunction.IntrinsicCallMetadata(
|
|
||||||
canonicalName,
|
|
||||||
builtinConst.canonicalVersion(),
|
|
||||||
context.intrinsicIdTable().register(canonicalName, builtinConst.canonicalVersion())),
|
|
||||||
0,
|
|
||||||
1,
|
|
||||||
span));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String flattenAssetReference(final PbsAst.Expression expression) {
|
private String flattenAssetReference(final PbsAst.Expression expression) {
|
||||||
@@ -622,7 +633,7 @@ final class PbsExecutableBodyLowerer {
|
|||||||
}
|
}
|
||||||
return switch (expression) {
|
return switch (expression) {
|
||||||
case PbsAst.CallExpr callExpr -> callsiteEmitter.returnSlotsOf(callExpr, context);
|
case PbsAst.CallExpr callExpr -> callsiteEmitter.returnSlotsOf(callExpr, context);
|
||||||
case PbsAst.ApplyExpr ignored -> 0;
|
case PbsAst.ApplyExpr apply -> callsiteEmitter.returnSlotsOf(applyCall(apply), context);
|
||||||
case PbsAst.BinaryExpr ignored -> 1;
|
case PbsAst.BinaryExpr ignored -> 1;
|
||||||
case PbsAst.UnaryExpr ignored -> 1;
|
case PbsAst.UnaryExpr ignored -> 1;
|
||||||
case PbsAst.ElseExpr elseExpr ->
|
case PbsAst.ElseExpr elseExpr ->
|
||||||
@@ -633,7 +644,7 @@ final class PbsExecutableBodyLowerer {
|
|||||||
Math.max(
|
Math.max(
|
||||||
blockValueSlots(ifExpr.thenBlock(), context),
|
blockValueSlots(ifExpr.thenBlock(), context),
|
||||||
materializedValueSlots(ifExpr.elseExpression(), context));
|
materializedValueSlots(ifExpr.elseExpression(), context));
|
||||||
case PbsAst.SwitchExpr ignored -> 0;
|
case PbsAst.SwitchExpr sw -> sw.arms().isEmpty() ? 0 : blockValueSlots(sw.arms().getFirst().block(), context);
|
||||||
case PbsAst.HandleExpr ignored -> 0;
|
case PbsAst.HandleExpr ignored -> 0;
|
||||||
case PbsAst.AsExpr asExpr -> materializedValueSlots(asExpr.expression(), context);
|
case PbsAst.AsExpr asExpr -> materializedValueSlots(asExpr.expression(), context);
|
||||||
case PbsAst.MemberExpr memberExpr -> {
|
case PbsAst.MemberExpr memberExpr -> {
|
||||||
@@ -642,6 +653,9 @@ final class PbsExecutableBodyLowerer {
|
|||||||
yield 1;
|
yield 1;
|
||||||
}
|
}
|
||||||
if (memberExpr.receiver() instanceof PbsAst.IdentifierExpr identifierExpr) {
|
if (memberExpr.receiver() instanceof PbsAst.IdentifierExpr identifierExpr) {
|
||||||
|
var type = context.localTypes.get(identifierExpr.name());
|
||||||
|
var fields = type == null ? null : context.types().fields.get(type.name());
|
||||||
|
if (fields != null) for (var field : fields) if (field.name().equals(memberExpr.memberName())) yield context.types().slots(field.typeRef());
|
||||||
final var tupleProjection = context.resolveLocalTupleProjection(identifierExpr.name());
|
final var tupleProjection = context.resolveLocalTupleProjection(identifierExpr.name());
|
||||||
if (tupleProjection != null) {
|
if (tupleProjection != null) {
|
||||||
final var fieldProjection = tupleProjection.fieldsByLabel().get(memberExpr.memberName());
|
final var fieldProjection = tupleProjection.fieldsByLabel().get(memberExpr.memberName());
|
||||||
@@ -650,6 +664,7 @@ final class PbsExecutableBodyLowerer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (memberExpr.receiver() instanceof PbsAst.IdentifierExpr owner && context.types().enumValue(owner.name(), memberExpr.memberName()) != null) yield 1;
|
||||||
yield materializedValueSlots(memberExpr.receiver(), context);
|
yield materializedValueSlots(memberExpr.receiver(), context);
|
||||||
}
|
}
|
||||||
case PbsAst.PropagateExpr propagateExpr -> materializedValueSlots(propagateExpr.expression(), context);
|
case PbsAst.PropagateExpr propagateExpr -> materializedValueSlots(propagateExpr.expression(), context);
|
||||||
@@ -670,8 +685,8 @@ final class PbsExecutableBodyLowerer {
|
|||||||
case PbsAst.IntLiteralExpr ignored -> 1;
|
case PbsAst.IntLiteralExpr ignored -> 1;
|
||||||
case PbsAst.StringLiteralExpr ignoredString -> 1;
|
case PbsAst.StringLiteralExpr ignoredString -> 1;
|
||||||
case PbsAst.BoolLiteralExpr ignoredBool -> 1;
|
case PbsAst.BoolLiteralExpr ignoredBool -> 1;
|
||||||
case PbsAst.FloatLiteralExpr ignoredFloat -> 0;
|
case PbsAst.FloatLiteralExpr ignoredFloat -> 1;
|
||||||
case PbsAst.BoundedLiteralExpr ignoredBounded -> 0;
|
case PbsAst.BoundedLiteralExpr ignoredBounded -> 1;
|
||||||
case PbsAst.ThisExpr ignoredThis -> 0;
|
case PbsAst.ThisExpr ignoredThis -> 0;
|
||||||
case PbsAst.NoneExpr ignoredNone -> 0;
|
case PbsAst.NoneExpr ignoredNone -> 0;
|
||||||
case PbsAst.ErrExpr ignoredErr -> 0;
|
case PbsAst.ErrExpr ignoredErr -> 0;
|
||||||
@@ -712,11 +727,11 @@ final class PbsExecutableBodyLowerer {
|
|||||||
private int identifierValueSlots(
|
private int identifierValueSlots(
|
||||||
final PbsAst.IdentifierExpr identifierExpr,
|
final PbsAst.IdentifierExpr identifierExpr,
|
||||||
final PbsExecutableLoweringContext context) {
|
final PbsExecutableLoweringContext context) {
|
||||||
if (!producesIdentifierValue(identifierExpr, context)) {
|
var constant = context.builtinConstByNameId().get(context.nameTable().register(identifierExpr.name()));
|
||||||
return 0;
|
if (constant != null) return context.types().slots(context.types().values.get(identifierExpr.name()));
|
||||||
}
|
if (!producesIdentifierValue(identifierExpr, context)) return 0;
|
||||||
final var tupleProjection = context.resolveLocalTupleProjection(identifierExpr.name());
|
final var tupleProjection = context.resolveLocalTupleProjection(identifierExpr.name());
|
||||||
return tupleProjection == null ? 1 : tupleProjection.slotCount();
|
return tupleProjection == null ? Math.max(1, context.types().slots(expressionType(identifierExpr, context))) : tupleProjection.slotCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
private PbsTupleProjection tupleProjectionOf(
|
private PbsTupleProjection tupleProjectionOf(
|
||||||
@@ -774,6 +789,10 @@ final class PbsExecutableBodyLowerer {
|
|||||||
private void lowerIntLiteral(
|
private void lowerIntLiteral(
|
||||||
final PbsAst.IntLiteralExpr intLiteralExpr,
|
final PbsAst.IntLiteralExpr intLiteralExpr,
|
||||||
final PbsExecutableLoweringContext context) {
|
final PbsExecutableLoweringContext context) {
|
||||||
|
if (context.expectedType != null && "long".equals(context.types().canonical(context.expectedType))) {
|
||||||
|
emitLiteral(IRBackendExecutableFunction.InstructionKind.PUSH_I64, Long.toString(intLiteralExpr.value()), intLiteralExpr.span(), context);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (intLiteralExpr.value() < Integer.MIN_VALUE || intLiteralExpr.value() > Integer.MAX_VALUE) {
|
if (intLiteralExpr.value() < Integer.MIN_VALUE || intLiteralExpr.value() > Integer.MAX_VALUE) {
|
||||||
reportUnsupportedLowering(
|
reportUnsupportedLowering(
|
||||||
"int literal exceeds i32 lowering range: " + intLiteralExpr.value(),
|
"int literal exceeds i32 lowering range: " + intLiteralExpr.value(),
|
||||||
@@ -784,6 +803,132 @@ final class PbsExecutableBodyLowerer {
|
|||||||
emitPushI32((int) intLiteralExpr.value(), intLiteralExpr.span(), context);
|
emitPushI32((int) intLiteralExpr.value(), intLiteralExpr.span(), context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private PbsAst.CallExpr applyCall(PbsAst.ApplyExpr apply) {
|
||||||
|
var argument = apply.argument();
|
||||||
|
while (argument instanceof PbsAst.GroupExpr group) argument = group.expression();
|
||||||
|
var values = argument instanceof PbsAst.TupleExpr tuple ? tuple.items().stream().map(PbsAst.TupleItem::expression).toList()
|
||||||
|
: argument instanceof PbsAst.UnitExpr ? java.util.List.<PbsAst.Expression>of() : java.util.List.of(argument);
|
||||||
|
return new PbsAst.CallExpr(apply.callee(), ReadOnlyList.wrap(values), apply.span());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void lowerApply(PbsAst.ApplyExpr apply, PbsExecutableLoweringContext c) {
|
||||||
|
var call = applyCall(apply);
|
||||||
|
var argument = apply.argument();
|
||||||
|
while (argument instanceof PbsAst.GroupExpr group) argument = group.expression();
|
||||||
|
if (!(argument instanceof PbsAst.TupleExpr tuple) || tuple.items().isEmpty() || tuple.items().getFirst().label() == null) {
|
||||||
|
lowerCallExpression(call, c); return;
|
||||||
|
}
|
||||||
|
var signature = c.types().signatures.get(PbsRuntimeTypes.path(call.callee())+"#"+call.arguments().size());
|
||||||
|
if(signature == null) { reportUnsupportedLowering("Named application requires a resolved signature", apply.span(), c); return; }
|
||||||
|
var slots = new java.util.HashMap<String,Integer>();
|
||||||
|
for(var item:tuple.items()) {
|
||||||
|
var parameter = signature.parameters().stream().filter(p -> p.name().equals(item.label())).findFirst().orElse(null);
|
||||||
|
if(parameter == null || slots.containsKey(item.label())) { reportUnsupportedLowering("Unknown or duplicate named argument: "+item.label(), item.span(), c); return; }
|
||||||
|
// Evaluate source order once, then reorder complete value groups, never expressions.
|
||||||
|
lowerExpected(item.expression(), parameter.typeRef(), c);
|
||||||
|
int width = c.types().slots(parameter.typeRef());
|
||||||
|
int slot = c.declareLocalSlots(c.nextLabel("argument"), width);
|
||||||
|
emitStoreLocalSlots(slot, width, item.span(), c);
|
||||||
|
slots.put(item.label(), slot);
|
||||||
|
}
|
||||||
|
for(var parameter:signature.parameters()) {
|
||||||
|
var slot=slots.get(parameter.name());
|
||||||
|
if(slot==null) { reportUnsupportedLowering("Missing named argument: "+parameter.name(), apply.span(), c); return; }
|
||||||
|
emitLoadLocalSlots(slot,c.types().slots(parameter.typeRef()),apply.span(),c);
|
||||||
|
}
|
||||||
|
callsiteEmitter.emitCallsite(call,c);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void lowerExpected(PbsAst.Expression expression, PbsAst.TypeRef expected, PbsExecutableLoweringContext context) {
|
||||||
|
var previous = context.expectedType;
|
||||||
|
context.expectedType = expected;
|
||||||
|
try { lowerExpression(expression, context); } finally { context.expectedType = previous; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private PbsAst.TypeRef expressionType(PbsAst.Expression e, PbsExecutableLoweringContext c) {
|
||||||
|
if (e instanceof PbsAst.IdentifierExpr i) return c.localTypes.getOrDefault(i.name(), c.types().values.get(i.name()));
|
||||||
|
if (e instanceof PbsAst.GroupExpr g) return expressionType(g.expression(), c);
|
||||||
|
if (e instanceof PbsAst.AsExpr a) return PbsRuntimeTypes.type(a.contractName());
|
||||||
|
if (e instanceof PbsAst.UnaryExpr u) return java.util.Set.of("!", "not").contains(u.operator()) ? PbsRuntimeTypes.type("bool") : expressionType(u.expression(), c);
|
||||||
|
if (e instanceof PbsAst.BinaryExpr b) return java.util.Set.of("==", "!=", "<", "<=", ">", ">=", "&&", "||", "and", "or").contains(b.operator()) ? PbsRuntimeTypes.type("bool") : expressionType(b.left(), c);
|
||||||
|
if (e instanceof PbsAst.IfExpr branch) return expressionType(branch.thenBlock().tailExpression(), c);
|
||||||
|
if (e instanceof PbsAst.SwitchExpr branch && !branch.arms().isEmpty()) return expressionType(branch.arms().getFirst().block().tailExpression(), c);
|
||||||
|
if (e instanceof PbsAst.ApplyExpr apply) return expressionType(applyCall(apply), c);
|
||||||
|
if (e instanceof PbsAst.NewExpr value) return PbsRuntimeTypes.type(value.typeName());
|
||||||
|
if (e instanceof PbsAst.CallExpr call) {
|
||||||
|
var sig = c.types().signatures.get(PbsRuntimeTypes.path(call.callee())+"#"+call.arguments().size());
|
||||||
|
return sig == null ? null : sig.returnType();
|
||||||
|
}
|
||||||
|
if (e instanceof PbsAst.MemberExpr m && m.receiver() instanceof PbsAst.IdentifierExpr i) {
|
||||||
|
if (c.types().enums.containsKey(i.name())) return PbsRuntimeTypes.type(i.name());
|
||||||
|
var owner = c.localTypes.get(i.name());
|
||||||
|
var fields = owner == null ? null : c.types().fields.get(owner.name());
|
||||||
|
if (fields != null) for (var field : fields) if (field.name().equals(m.memberName())) return field.typeRef();
|
||||||
|
if (owner != null && owner.kind() == PbsAst.TypeRefKind.NAMED_TUPLE)
|
||||||
|
for (var field : owner.fields()) if (field.label().equals(m.memberName())) return field.typeRef();
|
||||||
|
}
|
||||||
|
if (e instanceof PbsAst.IntLiteralExpr || e instanceof PbsAst.BoundedLiteralExpr) return PbsRuntimeTypes.type("int");
|
||||||
|
if (e instanceof PbsAst.FloatLiteralExpr) return PbsRuntimeTypes.type("float");
|
||||||
|
if (e instanceof PbsAst.BoolLiteralExpr) return PbsRuntimeTypes.type("bool");
|
||||||
|
if (e instanceof PbsAst.StringLiteralExpr) return PbsRuntimeTypes.type("str");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void lowerConversion(PbsAst.AsExpr expr, PbsExecutableLoweringContext c) {
|
||||||
|
var source = c.types().canonical(expressionType(expr.expression(), c));
|
||||||
|
var target = expr.contractName();
|
||||||
|
lowerExpected(expr.expression(), null, c);
|
||||||
|
if (source.equals(target)) return;
|
||||||
|
String name = switch(source + "->" + target) {
|
||||||
|
case "int->long" -> "math.i32.to_i64"; case "long->int" -> "math.i64.to_i32";
|
||||||
|
case "int->float" -> "math.i32.to_float"; case "long->float" -> "math.i64.to_float";
|
||||||
|
case "float->int" -> "mathf.to_i32"; case "float->long" -> "mathf.to_i64";
|
||||||
|
default -> null;
|
||||||
|
};
|
||||||
|
if (name == null) { reportUnsupportedLowering("Unsupported conversion " + source + " -> " + target, expr.span(), c); return; }
|
||||||
|
c.instructions().add(new IRBackendExecutableFunction.Instruction(IRBackendExecutableFunction.InstructionKind.CALL_INTRINSIC,
|
||||||
|
"", null, new IRBackendExecutableFunction.IntrinsicCallMetadata(name, 1, c.intrinsicIdTable().register(name, 1)), 1, 1, expr.span()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void lowerSwitch(PbsAst.SwitchExpr expr, PbsExecutableLoweringContext c) {
|
||||||
|
var slot = c.declareLocalSlot(c.nextLabel("switch_value"));
|
||||||
|
lowerExpected(expr.selector(), null, c);
|
||||||
|
emitSetLocal(slot, expr.span(), c);
|
||||||
|
var end = c.nextLabel("switch_end");
|
||||||
|
var selectorType = expressionType(expr.selector(), c);
|
||||||
|
var enumDecl = selectorType == null ? null : c.types().enums.get(selectorType.name());
|
||||||
|
var coveredCases = new java.util.HashSet<String>();
|
||||||
|
var coveredBooleans = new java.util.HashSet<Boolean>();
|
||||||
|
for (var arm : expr.arms()) {
|
||||||
|
if (arm.pattern() instanceof PbsAst.EnumCaseSwitchPattern pattern) coveredCases.add(pattern.path().segments().get(1));
|
||||||
|
if (arm.pattern() instanceof PbsAst.LiteralSwitchPattern pattern && pattern.literal() instanceof PbsAst.BoolLiteralExpr literal) coveredBooleans.add(literal.value());
|
||||||
|
}
|
||||||
|
boolean exhaustive = enumDecl != null && enumDecl.cases().stream().allMatch(item -> coveredCases.contains(item.name())) || coveredBooleans.size() == 2;
|
||||||
|
for (int i=0; i<expr.arms().size(); i++) {
|
||||||
|
var arm = expr.arms().get(i);
|
||||||
|
var next = c.nextLabel("switch_next");
|
||||||
|
boolean last = i == expr.arms().size()-1;
|
||||||
|
boolean checked = !(arm.pattern() instanceof PbsAst.WildcardSwitchPattern) && !(last && exhaustive);
|
||||||
|
if (checked) {
|
||||||
|
emitGetLocal(slot, expr.span(), c);
|
||||||
|
if (arm.pattern() instanceof PbsAst.EnumCaseSwitchPattern pattern) {
|
||||||
|
var value = c.types().enumValue(pattern.path().segments().get(0), pattern.path().segments().get(1));
|
||||||
|
emitPushI32(value, pattern.span(), c);
|
||||||
|
} else if (arm.pattern() instanceof PbsAst.LiteralSwitchPattern literal) lowerExpected(literal.literal(), expressionType(expr.selector(), c), c);
|
||||||
|
emitBinaryOperatorInstruction("==", expr.span(), c);
|
||||||
|
emitJump(IRBackendExecutableFunction.InstructionKind.JMP_IF_FALSE, next, expr.span(), c);
|
||||||
|
}
|
||||||
|
lowerBlock(arm.block(), c);
|
||||||
|
if (!last) emitJump(IRBackendExecutableFunction.InstructionKind.JMP, end, arm.span(), c);
|
||||||
|
if (checked) emitLabel(next, arm.span(), c);
|
||||||
|
}
|
||||||
|
emitLabel(end, expr.span(), c);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void emitLiteral(IRBackendExecutableFunction.InstructionKind kind, String value, p.studio.compiler.source.Span span, PbsExecutableLoweringContext c) {
|
||||||
|
c.instructions().add(new IRBackendExecutableFunction.Instruction(kind, ModuleId.none(), "", null, null, null, value, "", null, null, span));
|
||||||
|
}
|
||||||
|
|
||||||
private void lowerCallsiteReceiver(
|
private void lowerCallsiteReceiver(
|
||||||
final PbsAst.Expression callee,
|
final PbsAst.Expression callee,
|
||||||
final PbsExecutableLoweringContext context) {
|
final PbsExecutableLoweringContext context) {
|
||||||
|
|||||||
+13
-3
@@ -201,7 +201,7 @@ final class PbsExecutableCallsiteEmitter {
|
|||||||
final PbsAst.CallExpr callExpr,
|
final PbsAst.CallExpr callExpr,
|
||||||
final PbsExecutableLoweringContext context,
|
final PbsExecutableLoweringContext context,
|
||||||
final IRReservedMetadata.HostMethodBinding host) {
|
final IRReservedMetadata.HostMethodBinding host) {
|
||||||
final var effectiveArgSlots = callExpr.arguments().size() + implicitReceiverArgSlots(callExpr.callee(), context);
|
final var effectiveArgSlots = argumentSlots(callExpr, context) + implicitReceiverArgSlots(callExpr.callee(), context);
|
||||||
context.instructions().add(new IRBackendExecutableFunction.Instruction(
|
context.instructions().add(new IRBackendExecutableFunction.Instruction(
|
||||||
IRBackendExecutableFunction.InstructionKind.CALL_HOST,
|
IRBackendExecutableFunction.InstructionKind.CALL_HOST,
|
||||||
"",
|
"",
|
||||||
@@ -251,7 +251,7 @@ final class PbsExecutableCallsiteEmitter {
|
|||||||
reportUnsupportedLowering("executable lowering resolved callable without signature metadata", callExpr.span(), context);
|
reportUnsupportedLowering("executable lowering resolved callable without signature metadata", callExpr.span(), context);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final var effectiveArgSlots = callExpr.arguments().size() + implicitReceiverArgSlots(callExpr.callee(), context);
|
final var effectiveArgSlots = argumentSlots(callExpr, context) + implicitReceiverArgSlots(callExpr.callee(), context);
|
||||||
context.instructions().add(new IRBackendExecutableFunction.Instruction(
|
context.instructions().add(new IRBackendExecutableFunction.Instruction(
|
||||||
IRBackendExecutableFunction.InstructionKind.CALL_FUNC,
|
IRBackendExecutableFunction.InstructionKind.CALL_FUNC,
|
||||||
calleeSignature.moduleId(),
|
calleeSignature.moduleId(),
|
||||||
@@ -411,13 +411,23 @@ final class PbsExecutableCallsiteEmitter {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int argumentSlots(PbsAst.CallExpr call, PbsExecutableLoweringContext context) {
|
||||||
|
var signature = context.types().signatures.get(PbsRuntimeTypes.path(call.callee())+"#"+call.arguments().size());
|
||||||
|
return signature == null ? call.arguments().size() : signature.parameters().stream().mapToInt(p -> context.types().slots(p.typeRef())).sum();
|
||||||
|
}
|
||||||
|
|
||||||
private int implicitReceiverArgSlots(
|
private int implicitReceiverArgSlots(
|
||||||
final PbsAst.Expression callee,
|
final PbsAst.Expression callee,
|
||||||
final PbsExecutableLoweringContext context) {
|
final PbsExecutableLoweringContext context) {
|
||||||
if (!(callee instanceof PbsAst.MemberExpr memberExpr)) {
|
if (!(callee instanceof PbsAst.MemberExpr memberExpr)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return receiverProducesRuntimeValue(memberExpr.receiver(), context) ? 1 : 0;
|
if (!receiverProducesRuntimeValue(memberExpr.receiver(), context)) return 0;
|
||||||
|
return switch (resolveExpressionOwner(memberExpr.receiver(), context)) {
|
||||||
|
case "vec2" -> 2;
|
||||||
|
case "pixel" -> 3;
|
||||||
|
default -> 1;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean receiverProducesRuntimeValue(
|
private boolean receiverProducesRuntimeValue(
|
||||||
|
|||||||
+4
@@ -22,6 +22,10 @@ final class PbsExecutableLoweringContext {
|
|||||||
private final Map<NameId, String> localOwnerByNameId;
|
private final Map<NameId, String> localOwnerByNameId;
|
||||||
private final ArrayList<IRBackendExecutableFunction.Instruction> instructions = new ArrayList<>();
|
private final ArrayList<IRBackendExecutableFunction.Instruction> instructions = new ArrayList<>();
|
||||||
private final ArrayDeque<PbsLoopTargets> loopTargets = new ArrayDeque<>();
|
private final ArrayDeque<PbsLoopTargets> loopTargets = new ArrayDeque<>();
|
||||||
|
final Map<String, p.studio.compiler.pbs.ast.PbsAst.TypeRef> localTypes = new HashMap<>();
|
||||||
|
p.studio.compiler.pbs.ast.PbsAst.TypeRef expectedType;
|
||||||
|
p.studio.compiler.pbs.ast.PbsAst.TypeRef returnType;
|
||||||
|
PbsRuntimeTypes types() { return metadataIndex.types(); }
|
||||||
private int nextLabelId = 0;
|
private int nextLabelId = 0;
|
||||||
private int nextLocalSlot;
|
private int nextLocalSlot;
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -18,7 +18,8 @@ public class PbsExecutableLoweringModels {
|
|||||||
public record PbsExecutableLoweringResult(
|
public record PbsExecutableLoweringResult(
|
||||||
ReadOnlyList<IRBackendExecutableFunction> executableFunctions,
|
ReadOnlyList<IRBackendExecutableFunction> executableFunctions,
|
||||||
ReadOnlyList<CallableSignatureRef> callableSignatures,
|
ReadOnlyList<CallableSignatureRef> callableSignatures,
|
||||||
ReadOnlyList<IntrinsicReference> intrinsicPool) {
|
ReadOnlyList<IntrinsicReference> intrinsicPool,
|
||||||
|
p.studio.compiler.models.registry.IRRegistry registry) {
|
||||||
}
|
}
|
||||||
|
|
||||||
record PbsLowerableCallable(
|
record PbsLowerableCallable(
|
||||||
@@ -42,6 +43,7 @@ public class PbsExecutableLoweringModels {
|
|||||||
}
|
}
|
||||||
|
|
||||||
record PbsExecutableMetadataIndex(
|
record PbsExecutableMetadataIndex(
|
||||||
|
PbsRuntimeTypes types,
|
||||||
Map<NameId, List<IRReservedMetadata.HostMethodBinding>> hostByMethodName,
|
Map<NameId, List<IRReservedMetadata.HostMethodBinding>> hostByMethodName,
|
||||||
Map<String, String> builtinCanonicalBySourceType,
|
Map<String, String> builtinCanonicalBySourceType,
|
||||||
Map<NameId, String> builtinConstOwnerByNameId,
|
Map<NameId, String> builtinConstOwnerByNameId,
|
||||||
|
|||||||
+9
-4
@@ -47,6 +47,10 @@ public final class PbsExecutableLoweringService {
|
|||||||
nameTable,
|
nameTable,
|
||||||
metadataIndex.builtinCanonicalBySourceType(),
|
metadataIndex.builtinCanonicalBySourceType(),
|
||||||
importedCallables);
|
importedCallables);
|
||||||
|
for (var entry : callableRegistry.callableSignatureByCallableId().entrySet()) {
|
||||||
|
var signature = metadataIndex.types().signatures.get(entry.getValue().callableName()+"#"+entry.getValue().arity());
|
||||||
|
if (signature != null) callableRegistry.returnSlotsByCallableId().put(entry.getKey(), signature.returnKind() == PbsAst.ReturnKind.PLAIN ? metadataIndex.types().slots(signature.returnType()) : 0);
|
||||||
|
}
|
||||||
final var intrinsicIdTable = new IntrinsicTable();
|
final var intrinsicIdTable = new IntrinsicTable();
|
||||||
final var executableFunctions = new ArrayList<IRBackendExecutableFunction>(callableRegistry.localCallables().size());
|
final var executableFunctions = new ArrayList<IRBackendExecutableFunction>(callableRegistry.localCallables().size());
|
||||||
|
|
||||||
@@ -72,7 +76,7 @@ public final class PbsExecutableLoweringService {
|
|||||||
return new PbsExecutableLoweringResult(
|
return new PbsExecutableLoweringResult(
|
||||||
ReadOnlyList.wrap(executableFunctions),
|
ReadOnlyList.wrap(executableFunctions),
|
||||||
callableRegistry.callableSignatures(),
|
callableRegistry.callableSignatures(),
|
||||||
ReadOnlyList.wrap(intrinsicPool));
|
ReadOnlyList.wrap(intrinsicPool), metadataIndex.types().registry());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String callableShapeSurfaceOf(final PbsAst.FunctionDecl functionDecl) {
|
public String callableShapeSurfaceOf(final PbsAst.FunctionDecl functionDecl) {
|
||||||
@@ -110,12 +114,13 @@ public final class PbsExecutableLoweringService {
|
|||||||
functionCallableId,
|
functionCallableId,
|
||||||
safeToInt(functionDecl.span().getStart()),
|
safeToInt(functionDecl.span().getStart()),
|
||||||
safeToInt(functionDecl.span().getEnd()),
|
safeToInt(functionDecl.span().getEnd()),
|
||||||
functionDecl.parameters().size(),
|
functionDecl.parameters().stream().mapToInt(p -> metadataIndex.types().slots(p.typeRef())).sum(),
|
||||||
loweredBody.localSlots(),
|
loweredBody.localSlots(),
|
||||||
callableRegistry.returnSlotsByCallableId().getOrDefault(functionCallableId, 0),
|
functionDecl.returnKind() == PbsAst.ReturnKind.PLAIN ? metadataIndex.types().slots(functionDecl.returnType()) : 0,
|
||||||
loweredBody.maxStackSlots(),
|
loweredBody.maxStackSlots(),
|
||||||
loweredBody.instructions(),
|
loweredBody.instructions(),
|
||||||
functionDecl.span());
|
functionDecl.span(),
|
||||||
|
metadataIndex.types().metadata(functionDecl));
|
||||||
}
|
}
|
||||||
|
|
||||||
private int safeToInt(final long value) {
|
private int safeToInt(final long value) {
|
||||||
|
|||||||
+1
@@ -48,6 +48,7 @@ final class PbsExecutableMetadataIndexFactory {
|
|||||||
intrinsicReturnOwnerByCanonical,
|
intrinsicReturnOwnerByCanonical,
|
||||||
diagnostics);
|
diagnostics);
|
||||||
return new PbsExecutableMetadataIndex(
|
return new PbsExecutableMetadataIndex(
|
||||||
|
new PbsRuntimeTypes(ast, supplementalTopDecls, builtinCanonicalBySourceType),
|
||||||
hostByMethodName,
|
hostByMethodName,
|
||||||
builtinCanonicalBySourceType,
|
builtinCanonicalBySourceType,
|
||||||
builtinConstOwnerByNameId,
|
builtinConstOwnerByNameId,
|
||||||
|
|||||||
+2
-1
@@ -38,7 +38,8 @@ final class PbsExecutableStackAnalyzer {
|
|||||||
var outHeight = incomingHeightByInstruction.get(index);
|
var outHeight = incomingHeightByInstruction.get(index);
|
||||||
|
|
||||||
switch (instruction.kind()) {
|
switch (instruction.kind()) {
|
||||||
case PUSH_I32, PUSH_BOOL, PUSH_CONST, GET_LOCAL, GET_GLOBAL -> outHeight += 1;
|
case PUSH_I32, PUSH_I64, PUSH_F64, PUSH_BOOL, PUSH_CONST, GET_LOCAL, GET_GLOBAL -> outHeight += 1;
|
||||||
|
case BUILTIN_CONST -> outHeight += instruction.expectedRetSlots();
|
||||||
case POP, SET_LOCAL, SET_GLOBAL -> {
|
case POP, SET_LOCAL, SET_GLOBAL -> {
|
||||||
if (outHeight <= 0) {
|
if (outHeight <= 0) {
|
||||||
throw new ExecutableLoweringAnalysisException(
|
throw new ExecutableLoweringAnalysisException(
|
||||||
|
|||||||
+92
@@ -0,0 +1,92 @@
|
|||||||
|
package p.studio.compiler.pbs.lowering;
|
||||||
|
|
||||||
|
import p.studio.compiler.models.registry.IRRegistry;
|
||||||
|
import p.studio.compiler.pbs.ast.PbsAst;
|
||||||
|
import p.studio.compiler.source.Span;
|
||||||
|
import p.studio.utilities.structures.ReadOnlyList;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/** PBS-owned source identities and layouts; never inferred from slot widths. */
|
||||||
|
final class PbsRuntimeTypes {
|
||||||
|
final Map<String, String> builtinNames;
|
||||||
|
final Map<String, ReadOnlyList<PbsAst.BuiltinFieldDecl>> fields = new HashMap<>();
|
||||||
|
final Map<String, PbsAst.EnumDecl> enums = new HashMap<>();
|
||||||
|
final Map<String, PbsAst.FunctionSignature> signatures = new HashMap<>();
|
||||||
|
final Map<String, PbsAst.TypeRef> values = new HashMap<>();
|
||||||
|
private final Map<Integer, IRRegistry.TypeDeclaration> used = new TreeMap<>();
|
||||||
|
|
||||||
|
PbsRuntimeTypes(PbsAst.File ast, ReadOnlyList<PbsAst.TopDecl> supplemental, Map<String,String> builtins) {
|
||||||
|
builtinNames = builtins;
|
||||||
|
var declarations = new ArrayList<>(ast.topDecls().asList());
|
||||||
|
declarations.addAll(supplemental.asList());
|
||||||
|
for (var decl : declarations) {
|
||||||
|
if (decl instanceof PbsAst.EnumDecl e) enums.put(e.name(), e);
|
||||||
|
if (decl instanceof PbsAst.ConstDecl c) values.put(c.name(), c.explicitType());
|
||||||
|
if (decl instanceof PbsAst.GlobalDecl g) values.put(g.name(), g.explicitType());
|
||||||
|
if (decl instanceof PbsAst.FunctionDecl f) addSignature(f.name(), f);
|
||||||
|
if (decl instanceof PbsAst.ServiceDecl s) for (var f : s.methods()) addSignature(s.name()+"."+f.name(), f);
|
||||||
|
if (decl instanceof PbsAst.BuiltinTypeDecl b) {
|
||||||
|
fields.put(b.name(), b.fields());
|
||||||
|
for(var f:b.signatures()) signatures.put(b.name()+"."+f.name()+"#"+f.parameters().size(), f);
|
||||||
|
}
|
||||||
|
if (decl instanceof PbsAst.HostDecl h) for(var f:h.signatures()) signatures.put(h.name()+"."+f.name()+"#"+f.parameters().size(), f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void addSignature(String name, PbsAst.FunctionDecl f) {
|
||||||
|
signatures.put(name+"#"+f.parameters().size(), new PbsAst.FunctionSignature(f.name(), f.parameters(), f.returnKind(), f.returnType(), f.resultErrorType(), f.attributes(), f.span()));
|
||||||
|
}
|
||||||
|
static PbsAst.TypeRef type(String name) { return PbsAst.TypeRef.simple(name, Span.none()); }
|
||||||
|
String canonical(PbsAst.TypeRef t) {
|
||||||
|
if(t==null) return "void";
|
||||||
|
if(t.kind()==PbsAst.TypeRefKind.GROUP) return canonical(t.inner());
|
||||||
|
return builtinNames.getOrDefault(t.name(), t.name());
|
||||||
|
}
|
||||||
|
int slots(PbsAst.TypeRef t) {
|
||||||
|
if(t==null || t.kind()==PbsAst.TypeRefKind.UNIT) return 0;
|
||||||
|
if(t.kind()==PbsAst.TypeRefKind.GROUP) return slots(t.inner());
|
||||||
|
if(t.kind()==PbsAst.TypeRefKind.NAMED_TUPLE) return t.fields().stream().mapToInt(f->slots(f.typeRef())).sum();
|
||||||
|
return switch(canonical(t)) { case "vec2" -> 2; case "pixel" -> 3; default -> 1; };
|
||||||
|
}
|
||||||
|
IRRegistry.TypeRef registryType(PbsAst.TypeRef t) {
|
||||||
|
int id = switch(canonical(t)) {
|
||||||
|
case "int" -> 0x10; case "long" -> 0x11; case "float" -> 0x12;
|
||||||
|
case "bool" -> 0x13; case "str" -> 0x14;
|
||||||
|
case "color" -> 1; case "vec2" -> 2; case "pixel" -> 3;
|
||||||
|
default -> { if(enums.containsKey(t.name())) yield 0x10;
|
||||||
|
throw new UnsupportedOperationException("Unsupported PBS runtime type: "+t.name()); }
|
||||||
|
};
|
||||||
|
var ref=IRRegistry.TypeRef.builtin(id);
|
||||||
|
used.putIfAbsent(id,new IRRegistry.TypeDeclaration(ref,null,new IRRegistry.Builtin(id)));
|
||||||
|
return ref;
|
||||||
|
}
|
||||||
|
List<IRRegistry.TypeRef> results(PbsAst.TypeRef t) {
|
||||||
|
if(t==null || t.kind()==PbsAst.TypeRefKind.UNIT) return List.of();
|
||||||
|
if(t.kind()==PbsAst.TypeRefKind.GROUP) return results(t.inner());
|
||||||
|
if(t.kind()==PbsAst.TypeRefKind.NAMED_TUPLE) return t.fields().stream().flatMap(f->results(f.typeRef()).stream()).toList();
|
||||||
|
return List.of(registryType(t));
|
||||||
|
}
|
||||||
|
IRRegistry.FunctionMetadata metadata(PbsAst.FunctionDecl f) {
|
||||||
|
// Preserve the pre-existing unsupported executable boundary for types outside this port.
|
||||||
|
// The common backend still rejects missing typed metadata; never infer a carrier by width.
|
||||||
|
try { return supportedMetadata(f); } catch (UnsupportedOperationException unsupported) { return null; }
|
||||||
|
}
|
||||||
|
private IRRegistry.FunctionMetadata supportedMetadata(PbsAst.FunctionDecl f) {
|
||||||
|
var params=new ArrayList<IRRegistry.NamedType>();
|
||||||
|
for(var p:f.parameters()) for(var type:results(p.typeRef())) params.add(new IRRegistry.NamedType(type,p.name()));
|
||||||
|
var returns=f.returnKind()==PbsAst.ReturnKind.PLAIN ? results(f.returnType()) : List.<IRRegistry.TypeRef>of();
|
||||||
|
return IRRegistry.FunctionMetadata.ordinary(new IRRegistry.Signature(ReadOnlyList.wrap(params),ReadOnlyList.wrap(returns)));
|
||||||
|
}
|
||||||
|
IRRegistry registry() { return new IRRegistry(ReadOnlyList.wrap(new ArrayList<>(used.values())),ReadOnlyList.empty()); }
|
||||||
|
Integer enumValue(String owner,String label) {
|
||||||
|
var e=enums.get(owner); if(e==null) return null;
|
||||||
|
int index=0;
|
||||||
|
for(var c:e.cases()) { if(c.name().equals(label)) return c.explicitValue()==null?index:Math.toIntExact(c.explicitValue()); index++; }
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
static String path(PbsAst.Expression e) {
|
||||||
|
if(e instanceof PbsAst.IdentifierExpr i) return i.name();
|
||||||
|
if(e instanceof PbsAst.MemberExpr m) {var owner=path(m.receiver());return owner==null?null:owner+"."+m.memberName();}
|
||||||
|
if(e instanceof PbsAst.GroupExpr g) return path(g.expression());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
@@ -45,6 +45,7 @@ final class PbsExprLiteralSupport {
|
|||||||
try {
|
try {
|
||||||
return Long.parseLong(text);
|
return Long.parseLong(text);
|
||||||
} catch (NumberFormatException ignored) {
|
} catch (NumberFormatException ignored) {
|
||||||
|
context.report(cursor.previous(), ParseErrors.E_PARSE_EXPECTED_TOKEN, "Integer literal is outside the Int64 range");
|
||||||
return 0L;
|
return 0L;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -159,6 +159,11 @@ final class PbsExprParser {
|
|||||||
private PbsAst.Expression parseUnary() {
|
private PbsAst.Expression parseUnary() {
|
||||||
if (cursor.match(PbsTokenKind.BANG, PbsTokenKind.MINUS, PbsTokenKind.NOT)) {
|
if (cursor.match(PbsTokenKind.BANG, PbsTokenKind.MINUS, PbsTokenKind.NOT)) {
|
||||||
final var operator = cursor.previous();
|
final var operator = cursor.previous();
|
||||||
|
if (operator.kind() == PbsTokenKind.MINUS && cursor.check(PbsTokenKind.INT_LITERAL)
|
||||||
|
&& (cursor.peek().lexeme().equals("9223372036854775808") || cursor.peek().lexeme().equals("2147483648"))) {
|
||||||
|
final var literal = cursor.advance();
|
||||||
|
return new PbsAst.IntLiteralExpr(Long.parseLong("-" + literal.lexeme()), span(operator.start(), literal.end()));
|
||||||
|
}
|
||||||
final var right = parseUnary();
|
final var right = parseUnary();
|
||||||
return new PbsAst.UnaryExpr(operator.lexeme(), right, span(operator.start(), right.span().getEnd()));
|
return new PbsAst.UnaryExpr(operator.lexeme(), right, span(operator.start(), right.span().getEnd()));
|
||||||
}
|
}
|
||||||
|
|||||||
+12
@@ -19,6 +19,7 @@ public final class PbsParser {
|
|||||||
private final PbsTokenCursor cursor;
|
private final PbsTokenCursor cursor;
|
||||||
private final PbsTopLevelParser topLevelParser;
|
private final PbsTopLevelParser topLevelParser;
|
||||||
private final PbsBlockParser blockParser;
|
private final PbsBlockParser blockParser;
|
||||||
|
private final PbsExprParser expressionParser;
|
||||||
|
|
||||||
private PbsParser(
|
private PbsParser(
|
||||||
final ReadOnlyList<PbsToken> tokens,
|
final ReadOnlyList<PbsToken> tokens,
|
||||||
@@ -29,6 +30,7 @@ public final class PbsParser {
|
|||||||
this.cursor = context.cursor();
|
this.cursor = context.cursor();
|
||||||
|
|
||||||
final var exprParser = new PbsExprParser(context, this::parseExpressionSurfaceBlock);
|
final var exprParser = new PbsExprParser(context, this::parseExpressionSurfaceBlock);
|
||||||
|
this.expressionParser = exprParser;
|
||||||
final var attributeParser = new PbsAttributeParser(context, this::isTopLevelRestartToken);
|
final var attributeParser = new PbsAttributeParser(context, this::isTopLevelRestartToken);
|
||||||
final var typeParser = new PbsTypeParser(context);
|
final var typeParser = new PbsTypeParser(context);
|
||||||
|
|
||||||
@@ -64,6 +66,16 @@ public final class PbsParser {
|
|||||||
return topLevelParser.parseFile();
|
return topLevelParser.parseFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Parses a complete expression fragment using the same grammar as a source file. */
|
||||||
|
public static PbsAst.Expression parseExpression(
|
||||||
|
final ReadOnlyList<PbsToken> tokens,
|
||||||
|
final FileId fileId,
|
||||||
|
final p.studio.compiler.source.diagnostics.DiagnosticSink diagnostics) {
|
||||||
|
final var parser = new PbsParser(tokens, fileId, diagnostics, ParseMode.ORDINARY);
|
||||||
|
final var expression = parser.expressionParser.parseExpression();
|
||||||
|
return parser.cursor.isAtEnd() && !diagnostics.hasErrors() ? expression : null;
|
||||||
|
}
|
||||||
|
|
||||||
private PbsAst.Block parseExpressionSurfaceBlock(final String message) {
|
private PbsAst.Block parseExpressionSurfaceBlock(final String message) {
|
||||||
return blockParser.parseBlock(message);
|
return blockParser.parseBlock(message);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -8,7 +8,7 @@ import p.studio.utilities.structures.ReadOnlyList;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public final class PbsBuiltinLayoutResolver {
|
public final class PbsBuiltinLayoutResolver {
|
||||||
private static final Set<String> BUILTIN_SCALAR_TYPES = Set.of("int", "float", "bool", "str");
|
private static final Set<String> BUILTIN_SCALAR_TYPES = Set.of("int", "long", "float", "bool", "str");
|
||||||
|
|
||||||
private enum ResolveState {
|
private enum ResolveState {
|
||||||
UNVISITED,
|
UNVISITED,
|
||||||
|
|||||||
+12
@@ -357,6 +357,18 @@ public final class PbsDeclarationSemanticsValidator {
|
|||||||
validateSdkExecutableExpression(argument, diagnostics);
|
validateSdkExecutableExpression(argument, diagnostics);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case PbsAst.ApplyExpr apply -> {
|
||||||
|
validateSdkExecutableExpression(apply.callee(), diagnostics);
|
||||||
|
validateSdkExecutableExpression(apply.argument(), diagnostics);
|
||||||
|
}
|
||||||
|
case PbsAst.AsExpr conversion -> validateSdkExecutableExpression(conversion.expression(), diagnostics);
|
||||||
|
case PbsAst.SwitchExpr switchExpr -> {
|
||||||
|
validateSdkExecutableExpression(switchExpr.selector(), diagnostics);
|
||||||
|
for (var arm : switchExpr.arms()) {
|
||||||
|
for (var statement : arm.block().statements()) validateSdkExecutableStatement(statement, diagnostics);
|
||||||
|
validateSdkExecutableExpression(arm.block().tailExpression(), diagnostics);
|
||||||
|
}
|
||||||
|
}
|
||||||
case PbsAst.MemberExpr memberExpr ->
|
case PbsAst.MemberExpr memberExpr ->
|
||||||
validateSdkExecutableExpression(memberExpr.receiver(), diagnostics);
|
validateSdkExecutableExpression(memberExpr.receiver(), diagnostics);
|
||||||
case PbsAst.GroupExpr groupExpr ->
|
case PbsAst.GroupExpr groupExpr ->
|
||||||
|
|||||||
+35
-1
@@ -5,6 +5,7 @@ import p.studio.compiler.pbs.ast.PbsAst;
|
|||||||
import p.studio.compiler.pbs.lexer.PbsLexer;
|
import p.studio.compiler.pbs.lexer.PbsLexer;
|
||||||
import p.studio.compiler.pbs.lexer.PbsToken;
|
import p.studio.compiler.pbs.lexer.PbsToken;
|
||||||
import p.studio.compiler.pbs.lexer.PbsTokenKind;
|
import p.studio.compiler.pbs.lexer.PbsTokenKind;
|
||||||
|
import p.studio.compiler.pbs.parser.PbsParser;
|
||||||
import p.studio.compiler.source.Span;
|
import p.studio.compiler.source.Span;
|
||||||
import p.studio.compiler.source.diagnostics.DiagnosticSink;
|
import p.studio.compiler.source.diagnostics.DiagnosticSink;
|
||||||
import p.studio.compiler.source.identifiers.FileId;
|
import p.studio.compiler.source.identifiers.FileId;
|
||||||
@@ -15,7 +16,7 @@ import java.util.*;
|
|||||||
import static p.studio.compiler.pbs.semantics.PbsFlowSemanticSupport.*;
|
import static p.studio.compiler.pbs.semantics.PbsFlowSemanticSupport.*;
|
||||||
|
|
||||||
public final class PbsEditorialSupportService {
|
public final class PbsEditorialSupportService {
|
||||||
private static final Set<String> BUILTIN_TYPE_NAMES = Set.of("int", "float", "bool", "str", "string", "i32", "i64", "f32", "f64");
|
private static final Set<String> BUILTIN_TYPE_NAMES = Set.of("int", "long", "float", "bool", "str", "string", "i32", "i64", "f32", "f64");
|
||||||
private static final List<String> KEYWORDS = List.of(
|
private static final List<String> KEYWORDS = List.of(
|
||||||
"fn", "declare", "let", "const", "global", "struct", "service", "host", "contract", "enum", "error", "callback",
|
"fn", "declare", "let", "const", "global", "struct", "service", "host", "contract", "enum", "error", "callback",
|
||||||
"if", "else", "switch", "for", "until", "step", "while", "break", "continue", "return",
|
"if", "else", "switch", "for", "until", "step", "while", "break", "continue", "return",
|
||||||
@@ -1396,6 +1397,11 @@ public final class PbsEditorialSupportService {
|
|||||||
private TypeView resolveReceiverTypeBeforeDot(
|
private TypeView resolveReceiverTypeBeforeDot(
|
||||||
final int dotTokenIndex,
|
final int dotTokenIndex,
|
||||||
final ScopeState scopeState) {
|
final ScopeState scopeState) {
|
||||||
|
final PbsAst.Expression receiver = receiverExpressionBefore(dotTokenIndex);
|
||||||
|
if (receiver != null) {
|
||||||
|
return analyzeExpressionType(receiver, scopeState.scope(), null,
|
||||||
|
scopeState.returnType(), scopeState.resultErrorName(), scopeState.receiverType());
|
||||||
|
}
|
||||||
final List<String> segments = resolveChainSegmentsEndingAt(dotTokenIndex - 1);
|
final List<String> segments = resolveChainSegmentsEndingAt(dotTokenIndex - 1);
|
||||||
if (segments.isEmpty()) {
|
if (segments.isEmpty()) {
|
||||||
return TypeView.unknown();
|
return TypeView.unknown();
|
||||||
@@ -1407,6 +1413,34 @@ public final class PbsEditorialSupportService {
|
|||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private PbsAst.Expression receiverExpressionBefore(final int dotTokenIndex) {
|
||||||
|
// Locate only the fragment boundary here; grammar and overload selection
|
||||||
|
// remain in the existing PBS parser and flow expression analyzer.
|
||||||
|
int start = dotTokenIndex;
|
||||||
|
int depth = 0;
|
||||||
|
for (int index = dotTokenIndex - 1; index >= 0; index--) {
|
||||||
|
final var kind = token(index).kind();
|
||||||
|
if (kind == PbsTokenKind.COMMENT) { start = index; continue; }
|
||||||
|
if (kind == PbsTokenKind.RIGHT_PAREN) {
|
||||||
|
depth++;
|
||||||
|
} else if (kind == PbsTokenKind.LEFT_PAREN) {
|
||||||
|
if (depth == 0) break;
|
||||||
|
depth--;
|
||||||
|
} else if (depth == 0 && kind != PbsTokenKind.IDENTIFIER
|
||||||
|
&& kind != PbsTokenKind.DOT && kind != PbsTokenKind.THIS
|
||||||
|
&& kind != PbsTokenKind.NEW) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
start = index;
|
||||||
|
}
|
||||||
|
if (start == dotTokenIndex || depth != 0) return null;
|
||||||
|
final var fragment = new ArrayList<PbsToken>();
|
||||||
|
for (int index = start; index < dotTokenIndex; index++) fragment.add(token(index));
|
||||||
|
final int end = token(dotTokenIndex).start();
|
||||||
|
fragment.add(new PbsToken(PbsTokenKind.EOF, "", end, end));
|
||||||
|
return PbsParser.parseExpression(ReadOnlyList.wrap(fragment), ast.span().getFileId(), DiagnosticSink.empty());
|
||||||
|
}
|
||||||
|
|
||||||
private TypeView resolveBaseChainType(
|
private TypeView resolveBaseChainType(
|
||||||
final String baseName,
|
final String baseName,
|
||||||
final ScopeState scopeState) {
|
final ScopeState scopeState) {
|
||||||
|
|||||||
+27
-3
@@ -29,15 +29,19 @@ final class PbsFlowCallableResolutionAnalyzer {
|
|||||||
final PbsFlowExpressionContext context) {
|
final PbsFlowExpressionContext context) {
|
||||||
final var callee = analyzeTargetExpression(callExpr.callee(), context, ExprUse.CALL_TARGET);
|
final var callee = analyzeTargetExpression(callExpr.callee(), context, ExprUse.CALL_TARGET);
|
||||||
|
|
||||||
|
final var expectedInputs = callee.callables().size() == 1 ? callee.callables().getFirst().inputTypes() : java.util.List.<TypeView>of();
|
||||||
final TypeView argumentType;
|
final TypeView argumentType;
|
||||||
if (callExpr.arguments().isEmpty()) {
|
if (callExpr.arguments().isEmpty()) {
|
||||||
argumentType = TypeView.unit();
|
argumentType = TypeView.unit();
|
||||||
} else if (callExpr.arguments().size() == 1) {
|
} else if (callExpr.arguments().size() == 1) {
|
||||||
argumentType = analyzeValueExpression(callExpr.arguments().getFirst(), context, null).type();
|
argumentType = analyzeValueExpression(callExpr.arguments().getFirst(), context, expectedInputs.size() == 1 ? expectedInputs.getFirst() : null).type();
|
||||||
} else {
|
} else {
|
||||||
final var fields = new ArrayList<TupleField>(callExpr.arguments().size());
|
final var fields = new ArrayList<TupleField>(callExpr.arguments().size());
|
||||||
|
int argumentIndex = 0;
|
||||||
for (final var argument : callExpr.arguments()) {
|
for (final var argument : callExpr.arguments()) {
|
||||||
final var itemType = analyzeValueExpression(argument, context, null).type();
|
final var expected = argumentIndex < expectedInputs.size() ? expectedInputs.get(argumentIndex) : null;
|
||||||
|
argumentIndex++;
|
||||||
|
final var itemType = analyzeValueExpression(argument, context, expected).type();
|
||||||
fields.add(new TupleField(null, itemType));
|
fields.add(new TupleField(null, itemType));
|
||||||
}
|
}
|
||||||
argumentType = TypeView.tuple(fields);
|
argumentType = TypeView.tuple(fields);
|
||||||
@@ -56,7 +60,27 @@ final class PbsFlowCallableResolutionAnalyzer {
|
|||||||
final PbsAst.ApplyExpr applyExpr,
|
final PbsAst.ApplyExpr applyExpr,
|
||||||
final PbsFlowExpressionContext context) {
|
final PbsFlowExpressionContext context) {
|
||||||
final var callee = analyzeTargetExpression(applyExpr.callee(), context, ExprUse.APPLY_TARGET);
|
final var callee = analyzeTargetExpression(applyExpr.callee(), context, ExprUse.APPLY_TARGET);
|
||||||
final var argument = analyzeValueExpression(applyExpr.argument(), context, null).type();
|
TypeView argument;
|
||||||
|
if (applyExpr.argument() instanceof PbsAst.TupleExpr tuple && !tuple.items().isEmpty()
|
||||||
|
&& tuple.items().getFirst().label() != null && callee.callables().size() == 1) {
|
||||||
|
var candidate = callee.callables().getFirst();
|
||||||
|
var byName = new java.util.HashMap<String, TypeView>();
|
||||||
|
for (var item : tuple.items()) {
|
||||||
|
var parameter = candidate.parameters().stream().filter(p -> p.name().equals(item.label())).findFirst().orElse(null);
|
||||||
|
if (parameter == null || byName.containsKey(item.label())) {
|
||||||
|
Diagnostics.error(context.diagnostics(), "E_SEM_NAMED_ARGUMENT", "Unknown or duplicate named argument: " + item.label(), item.span());
|
||||||
|
}
|
||||||
|
byName.put(item.label(), analyzeValueExpression(item.expression(), context, parameter == null ? null : parameter.type()).type());
|
||||||
|
}
|
||||||
|
var fields = new ArrayList<TupleField>();
|
||||||
|
for (var parameter : candidate.parameters()) {
|
||||||
|
if (!byName.containsKey(parameter.name())) Diagnostics.error(context.diagnostics(), "E_SEM_NAMED_ARGUMENT", "Missing named argument: " + parameter.name(), applyExpr.span());
|
||||||
|
fields.add(new TupleField(parameter.name(), byName.getOrDefault(parameter.name(), TypeView.unknown())));
|
||||||
|
}
|
||||||
|
argument = TypeView.tuple(fields);
|
||||||
|
} else {
|
||||||
|
argument = analyzeValueExpression(applyExpr.argument(), context, callee.callables().size() == 1 && callee.callables().getFirst().inputTypes().size() == 1 ? callee.callables().getFirst().inputTypes().getFirst() : null).type();
|
||||||
|
}
|
||||||
|
|
||||||
return resolveCallableApplication(
|
return resolveCallableApplication(
|
||||||
applyExpr.span(),
|
applyExpr.span(),
|
||||||
|
|||||||
+8
@@ -35,6 +35,7 @@ final class PbsFlowSemanticSupport {
|
|||||||
UNKNOWN,
|
UNKNOWN,
|
||||||
UNIT,
|
UNIT,
|
||||||
INT,
|
INT,
|
||||||
|
LONG,
|
||||||
FLOAT,
|
FLOAT,
|
||||||
BOOL,
|
BOOL,
|
||||||
STR,
|
STR,
|
||||||
@@ -77,6 +78,10 @@ final class PbsFlowSemanticSupport {
|
|||||||
return new TypeView(Kind.INT, "int", List.of(), null, null, List.of(), null);
|
return new TypeView(Kind.INT, "int", List.of(), null, null, List.of(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static TypeView longType() {
|
||||||
|
return new TypeView(Kind.LONG, "long", List.of(), null, null, List.of(), null);
|
||||||
|
}
|
||||||
|
|
||||||
static TypeView floatType() {
|
static TypeView floatType() {
|
||||||
return new TypeView(Kind.FLOAT, "float", List.of(), null, null, List.of(), null);
|
return new TypeView(Kind.FLOAT, "float", List.of(), null, null, List.of(), null);
|
||||||
}
|
}
|
||||||
@@ -543,6 +548,9 @@ final class PbsFlowSemanticSupport {
|
|||||||
case UNIT -> TypeView.unit();
|
case UNIT -> TypeView.unit();
|
||||||
case SELF, ERROR -> TypeView.unknown();
|
case SELF, ERROR -> TypeView.unknown();
|
||||||
case SIMPLE -> {
|
case SIMPLE -> {
|
||||||
|
if ("long".equals(typeRef.name())) {
|
||||||
|
yield TypeView.longType();
|
||||||
|
}
|
||||||
if ("int".equals(typeRef.name())) {
|
if ("int".equals(typeRef.name())) {
|
||||||
yield TypeView.intType();
|
yield TypeView.intType();
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-7
@@ -41,7 +41,11 @@ final class PbsFlowStructuralExpressionAnalyzer {
|
|||||||
final var model = context.model();
|
final var model = context.model();
|
||||||
final var diagnostics = context.diagnostics();
|
final var diagnostics = context.diagnostics();
|
||||||
|
|
||||||
if (expression instanceof PbsAst.IntLiteralExpr) {
|
if (expression instanceof PbsAst.IntLiteralExpr literal) {
|
||||||
|
if (expectedType != null && expectedType.kind() == Kind.LONG) return ExprResult.type(TypeView.longType());
|
||||||
|
if (literal.value() < Integer.MIN_VALUE || literal.value() > Integer.MAX_VALUE) {
|
||||||
|
Diagnostics.error(diagnostics, "E_SEM_INTEGER_RANGE", "Integer literal exceeds int range; use an explicit long context", literal.span());
|
||||||
|
}
|
||||||
return ExprResult.type(TypeView.intType());
|
return ExprResult.type(TypeView.intType());
|
||||||
}
|
}
|
||||||
if (expression instanceof PbsAst.FloatLiteralExpr) {
|
if (expression instanceof PbsAst.FloatLiteralExpr) {
|
||||||
@@ -119,8 +123,11 @@ final class PbsFlowStructuralExpressionAnalyzer {
|
|||||||
}
|
}
|
||||||
if (expression instanceof PbsAst.TupleExpr tupleExpr) {
|
if (expression instanceof PbsAst.TupleExpr tupleExpr) {
|
||||||
final var fields = new ArrayList<TupleField>(tupleExpr.items().size());
|
final var fields = new ArrayList<TupleField>(tupleExpr.items().size());
|
||||||
|
int itemIndex=0;
|
||||||
for (final var item : tupleExpr.items()) {
|
for (final var item : tupleExpr.items()) {
|
||||||
final var value = analyzeValueExpression(item.expression(), context, null).type();
|
var fieldExpected=expectedType != null && expectedType.kind()==Kind.TUPLE && itemIndex<expectedType.tupleFields().size() ? expectedType.tupleFields().get(itemIndex).type() : null;
|
||||||
|
itemIndex++;
|
||||||
|
final var value = analyzeValueExpression(item.expression(), context, fieldExpected).type();
|
||||||
fields.add(new TupleField(item.label(), value));
|
fields.add(new TupleField(item.label(), value));
|
||||||
}
|
}
|
||||||
return ExprResult.type(TypeView.tuple(fields));
|
return ExprResult.type(TypeView.tuple(fields));
|
||||||
@@ -129,18 +136,22 @@ final class PbsFlowStructuralExpressionAnalyzer {
|
|||||||
return ExprResult.type(blockAnalysisDelegate.analyze(blockExpr.block(), context, context.valueContext()));
|
return ExprResult.type(blockAnalysisDelegate.analyze(blockExpr.block(), context, context.valueContext()));
|
||||||
}
|
}
|
||||||
if (expression instanceof PbsAst.UnaryExpr unaryExpr) {
|
if (expression instanceof PbsAst.UnaryExpr unaryExpr) {
|
||||||
final var operand = analyzeValueExpression(unaryExpr.expression(), context, null).type();
|
final var operand = analyzeValueExpression(unaryExpr.expression(), context, expectedType).type();
|
||||||
if ("!".equals(unaryExpr.operator()) || "not".equals(unaryExpr.operator())) {
|
if ("!".equals(unaryExpr.operator()) || "not".equals(unaryExpr.operator())) {
|
||||||
return ExprResult.type(TypeView.bool());
|
return ExprResult.type(TypeView.bool());
|
||||||
}
|
}
|
||||||
if ("-".equals(unaryExpr.operator()) && (typeOps.isInt(operand) || typeOps.isFloat(operand))) {
|
if ("-".equals(unaryExpr.operator()) && (typeOps.isInt(operand) || operand.kind() == Kind.LONG || typeOps.isFloat(operand))) {
|
||||||
return ExprResult.type(operand);
|
return ExprResult.type(operand);
|
||||||
}
|
}
|
||||||
return ExprResult.type(TypeView.unknown());
|
return ExprResult.type(TypeView.unknown());
|
||||||
}
|
}
|
||||||
if (expression instanceof PbsAst.BinaryExpr binaryExpr) {
|
if (expression instanceof PbsAst.BinaryExpr binaryExpr) {
|
||||||
final var left = analyzeValueExpression(binaryExpr.left(), context, null).type();
|
final var left = analyzeValueExpression(binaryExpr.left(), context, expectedType != null && expectedType.kind()==Kind.LONG ? expectedType : null).type();
|
||||||
final var right = analyzeValueExpression(binaryExpr.right(), context, null).type();
|
final var right = analyzeValueExpression(binaryExpr.right(), context, expectedType != null && expectedType.kind()==Kind.LONG ? expectedType : null).type();
|
||||||
|
if ((left.kind() == Kind.LONG || right.kind() == Kind.LONG) && left.kind() != right.kind()
|
||||||
|
&& left.kind() != Kind.UNKNOWN && right.kind() != Kind.UNKNOWN) {
|
||||||
|
Diagnostics.error(diagnostics, "E_SEM_NUMERIC_TYPE_MISMATCH", "Mixed numeric types require an explicit as conversion", binaryExpr.span());
|
||||||
|
}
|
||||||
return ExprResult.type(typeOps.inferBinaryResult(binaryExpr.operator(), left, right));
|
return ExprResult.type(typeOps.inferBinaryResult(binaryExpr.operator(), left, right));
|
||||||
}
|
}
|
||||||
if (expression instanceof PbsAst.NoneExpr noneExpr) {
|
if (expression instanceof PbsAst.NoneExpr noneExpr) {
|
||||||
@@ -167,7 +178,13 @@ final class PbsFlowStructuralExpressionAnalyzer {
|
|||||||
return ExprResult.type(TypeView.unknown());
|
return ExprResult.type(TypeView.unknown());
|
||||||
}
|
}
|
||||||
if (expression instanceof PbsAst.AsExpr asExpr) {
|
if (expression instanceof PbsAst.AsExpr asExpr) {
|
||||||
analyzeValueExpression(asExpr.expression(), context, null);
|
final var source = analyzeValueExpression(asExpr.expression(), context, null).type();
|
||||||
|
if ("int".equals(asExpr.contractName()) || "long".equals(asExpr.contractName()) || "float".equals(asExpr.contractName())) {
|
||||||
|
if (source.kind() != Kind.INT && source.kind() != Kind.LONG && source.kind() != Kind.FLOAT && source.kind() != Kind.UNKNOWN) {
|
||||||
|
Diagnostics.error(diagnostics, "E_SEM_NUMERIC_TYPE_MISMATCH", "Numeric conversion requires a numeric operand", asExpr.span());
|
||||||
|
}
|
||||||
|
return ExprResult.type(typeOps.typeFromTypeRef(PbsAst.TypeRef.simple(asExpr.contractName(), asExpr.span()), model, null));
|
||||||
|
}
|
||||||
if (model.contracts.containsKey(asExpr.contractName())) {
|
if (model.contracts.containsKey(asExpr.contractName())) {
|
||||||
return ExprResult.type(TypeView.contract(asExpr.contractName()));
|
return ExprResult.type(TypeView.contract(asExpr.contractName()));
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-2
@@ -15,6 +15,9 @@ final class PbsFlowTypeOps {
|
|||||||
if (isFloat(left) || isFloat(right)) {
|
if (isFloat(left) || isFloat(right)) {
|
||||||
return TypeView.floatType();
|
return TypeView.floatType();
|
||||||
}
|
}
|
||||||
|
if (left.kind() == Kind.LONG && right.kind() == Kind.LONG) {
|
||||||
|
return TypeView.longType();
|
||||||
|
}
|
||||||
if (isInt(left) && isInt(right)) {
|
if (isInt(left) && isInt(right)) {
|
||||||
return TypeView.intType();
|
return TypeView.intType();
|
||||||
}
|
}
|
||||||
@@ -46,7 +49,7 @@ final class PbsFlowTypeOps {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return switch (actual.kind()) {
|
return switch (actual.kind()) {
|
||||||
case UNIT, INT, FLOAT, BOOL, STR -> true;
|
case UNIT, INT, LONG, FLOAT, BOOL, STR -> true;
|
||||||
case STRUCT, SERVICE, CONTRACT, CALLBACK, ENUM, ERROR, TYPE_REF, ASSET_NAMESPACE -> actual.name().equals(expected.name());
|
case STRUCT, SERVICE, CONTRACT, CALLBACK, ENUM, ERROR, TYPE_REF, ASSET_NAMESPACE -> actual.name().equals(expected.name());
|
||||||
case ADDRESSABLE -> true;
|
case ADDRESSABLE -> true;
|
||||||
case OPTIONAL -> compatible(actual.inner(), expected.inner());
|
case OPTIONAL -> compatible(actual.inner(), expected.inner());
|
||||||
@@ -116,7 +119,7 @@ final class PbsFlowTypeOps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean isScalarComparable(final TypeView type) {
|
boolean isScalarComparable(final TypeView type) {
|
||||||
return isBool(type) || isInt(type) || isFloat(type) || isStr(type);
|
return type.kind() == Kind.LONG || isBool(type) || isInt(type) || isFloat(type) || isStr(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isUnit(final TypeView type) {
|
boolean isUnit(final TypeView type) {
|
||||||
@@ -172,6 +175,9 @@ final class PbsFlowTypeOps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private TypeView simpleType(final String name, final Model model) {
|
private TypeView simpleType(final String name, final Model model) {
|
||||||
|
if ("long".equals(name)) {
|
||||||
|
return TypeView.longType();
|
||||||
|
}
|
||||||
if ("int".equals(name)) {
|
if ("int".equals(name)) {
|
||||||
return TypeView.intType();
|
return TypeView.intType();
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -11,7 +11,7 @@ final class PbsInlineHintSurfaceFormatter {
|
|||||||
return switch (type.kind()) {
|
return switch (type.kind()) {
|
||||||
case UNKNOWN, ASSET_NAMESPACE -> null;
|
case UNKNOWN, ASSET_NAMESPACE -> null;
|
||||||
case UNIT -> "void";
|
case UNIT -> "void";
|
||||||
case INT, FLOAT, BOOL, STR -> type.name();
|
case INT, LONG, FLOAT, BOOL, STR -> type.name();
|
||||||
case STRUCT,
|
case STRUCT,
|
||||||
SERVICE,
|
SERVICE,
|
||||||
CONTRACT,
|
CONTRACT,
|
||||||
|
|||||||
+7
@@ -132,11 +132,16 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
|
|||||||
final Map<FileId, ReadOnlyList<p.studio.compiler.pbs.ast.PbsAst.TopDecl>> supplementalTopDeclsByFile = new LinkedHashMap<>();
|
final Map<FileId, ReadOnlyList<p.studio.compiler.pbs.ast.PbsAst.TopDecl>> supplementalTopDeclsByFile = new LinkedHashMap<>();
|
||||||
final Map<FileId, ReadOnlyList<PbsInlineHintSurface>> inlineHintsByFile = new LinkedHashMap<>();
|
final Map<FileId, ReadOnlyList<PbsInlineHintSurface>> inlineHintsByFile = new LinkedHashMap<>();
|
||||||
final Map<FileId, SourceKind> sourceKindByFile = new LinkedHashMap<>();
|
final Map<FileId, SourceKind> sourceKindByFile = new LinkedHashMap<>();
|
||||||
|
final Map<FileId, Path> ownerRootByFile = new LinkedHashMap<>();
|
||||||
for (final var entry : importedSemanticContexts.entrySet()) {
|
for (final var entry : importedSemanticContexts.entrySet()) {
|
||||||
supplementalTopDeclsByFile.put(entry.getKey(), entry.getValue().supplementalTopDecls());
|
supplementalTopDeclsByFile.put(entry.getKey(), entry.getValue().supplementalTopDecls());
|
||||||
}
|
}
|
||||||
for (final var parsedSourceFile : assembly.parsedSourceFiles()) {
|
for (final var parsedSourceFile : assembly.parsedSourceFiles()) {
|
||||||
astByFile.put(parsedSourceFile.fileId(), parsedSourceFile.ast());
|
astByFile.put(parsedSourceFile.fileId(), parsedSourceFile.ast());
|
||||||
|
final var sourceHandle = ctx.fileTable.get(parsedSourceFile.fileId());
|
||||||
|
if (sourceHandle != null && parsedSourceFile.sourceKind() != SourceKind.SDK_INTERFACE) {
|
||||||
|
ownerRootByFile.put(parsedSourceFile.fileId(), ctx.projectTable.get(sourceHandle.getProjectId()).getRootPath());
|
||||||
|
}
|
||||||
sourceKindByFile.put(
|
sourceKindByFile.put(
|
||||||
parsedSourceFile.fileId(),
|
parsedSourceFile.fileId(),
|
||||||
parsedSourceFile.sourceKind() == null ? SourceKind.PROJECT : parsedSourceFile.sourceKind());
|
parsedSourceFile.sourceKind() == null ? SourceKind.PROJECT : parsedSourceFile.sourceKind());
|
||||||
@@ -158,6 +163,7 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
|
|||||||
Map.copyOf(supplementalTopDeclsByFile),
|
Map.copyOf(supplementalTopDeclsByFile),
|
||||||
Map.copyOf(inlineHintsByFile),
|
Map.copyOf(inlineHintsByFile),
|
||||||
Map.copyOf(sourceKindByFile),
|
Map.copyOf(sourceKindByFile),
|
||||||
|
Map.copyOf(ownerRootByFile),
|
||||||
physicalModuleFiles,
|
physicalModuleFiles,
|
||||||
moduleCompletionLabels(ctx, physicalModuleFiles));
|
moduleCompletionLabels(ctx, physicalModuleFiles));
|
||||||
}
|
}
|
||||||
@@ -225,6 +231,7 @@ public class PBSFrontendPhaseService implements FrontendPhaseService {
|
|||||||
Map<FileId, ReadOnlyList<p.studio.compiler.pbs.ast.PbsAst.TopDecl>> supplementalTopDeclsByFile,
|
Map<FileId, ReadOnlyList<p.studio.compiler.pbs.ast.PbsAst.TopDecl>> supplementalTopDeclsByFile,
|
||||||
Map<FileId, ReadOnlyList<PbsInlineHintSurface>> inlineHintsByFile,
|
Map<FileId, ReadOnlyList<PbsInlineHintSurface>> inlineHintsByFile,
|
||||||
Map<FileId, SourceKind> sourceKindByFile,
|
Map<FileId, SourceKind> sourceKindByFile,
|
||||||
|
Map<FileId, Path> ownerRootByFile,
|
||||||
Map<ModuleReference, Path> physicalModuleFileByReference,
|
Map<ModuleReference, Path> physicalModuleFileByReference,
|
||||||
List<String> moduleCompletionLabels) {
|
List<String> moduleCompletionLabels) {
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -315,7 +315,7 @@ final class PbsImportedSemanticContextService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean isPrimitiveTypeName(final String typeName) {
|
private boolean isPrimitiveTypeName(final String typeName) {
|
||||||
return "int".equals(typeName)
|
return "long".equals(typeName) || "int".equals(typeName)
|
||||||
|| "float".equals(typeName)
|
|| "float".equals(typeName)
|
||||||
|| "bool".equals(typeName)
|
|| "bool".equals(typeName)
|
||||||
|| "str".equals(typeName)
|
|| "str".equals(typeName)
|
||||||
|
|||||||
+7
-7
@@ -3,7 +3,7 @@ Represents a packed RGBA color.
|
|||||||
""")]
|
""")]
|
||||||
[BuiltinType(name = "color", version = 1)]
|
[BuiltinType(name = "color", version = 1)]
|
||||||
declare builtin type Color(
|
declare builtin type Color(
|
||||||
pub raw: int
|
pub raw: long
|
||||||
) {
|
) {
|
||||||
[Doc(markdown = """
|
[Doc(markdown = """
|
||||||
Builds a color from its packed integer representation.
|
Builds a color from its packed integer representation.
|
||||||
@@ -11,7 +11,7 @@ declare builtin type Color(
|
|||||||
- `raw`: packed color value.
|
- `raw`: packed color value.
|
||||||
""")]
|
""")]
|
||||||
[IntrinsicCall(name = "from_raw", version = 1)]
|
[IntrinsicCall(name = "from_raw", version = 1)]
|
||||||
fn from_raw(raw: int) -> Color;
|
fn from_raw(raw: long) -> Color;
|
||||||
|
|
||||||
[Doc(markdown = """
|
[Doc(markdown = """
|
||||||
Builds an opaque color from red, green, and blue channels.
|
Builds an opaque color from red, green, and blue channels.
|
||||||
@@ -21,7 +21,7 @@ declare builtin type Color(
|
|||||||
- `b`: blue channel.
|
- `b`: blue channel.
|
||||||
""")]
|
""")]
|
||||||
[IntrinsicCall(name = "rgb", version = 1)]
|
[IntrinsicCall(name = "rgb", version = 1)]
|
||||||
fn rgb(r: int, g: int, b: int) -> Color;
|
fn rgb(r: long, g: long, b: long) -> Color;
|
||||||
|
|
||||||
[Doc(markdown = """
|
[Doc(markdown = """
|
||||||
Builds a color from red, green, blue, and alpha channels.
|
Builds a color from red, green, blue, and alpha channels.
|
||||||
@@ -32,7 +32,7 @@ declare builtin type Color(
|
|||||||
- `a`: alpha channel.
|
- `a`: alpha channel.
|
||||||
""")]
|
""")]
|
||||||
[IntrinsicCall(name = "rgba", version = 1)]
|
[IntrinsicCall(name = "rgba", version = 1)]
|
||||||
fn rgba(r: int, g: int, b: int, a: int) -> Color;
|
fn rgba(r: long, g: long, b: long, a: long) -> Color;
|
||||||
|
|
||||||
[Doc(markdown = """
|
[Doc(markdown = """
|
||||||
Parses a CSS-style RGBA color string.
|
Parses a CSS-style RGBA color string.
|
||||||
@@ -48,19 +48,19 @@ declare builtin type Color(
|
|||||||
- `value`: grayscale channel value.
|
- `value`: grayscale channel value.
|
||||||
""")]
|
""")]
|
||||||
[IntrinsicCall(name = "gray_scale", version = 1)]
|
[IntrinsicCall(name = "gray_scale", version = 1)]
|
||||||
fn gray_scale(value: int) -> Color;
|
fn gray_scale(value: long) -> Color;
|
||||||
|
|
||||||
[Doc(markdown = """
|
[Doc(markdown = """
|
||||||
Returns the packed RGB portion of this color.
|
Returns the packed RGB portion of this color.
|
||||||
""")]
|
""")]
|
||||||
[IntrinsicCall(name = "hex", version = 1)]
|
[IntrinsicCall(name = "hex", version = 1)]
|
||||||
fn hex() -> int;
|
fn hex() -> long;
|
||||||
|
|
||||||
[Doc(markdown = """
|
[Doc(markdown = """
|
||||||
Returns the alpha channel of this color.
|
Returns the alpha channel of this color.
|
||||||
""")]
|
""")]
|
||||||
[IntrinsicCall(name = "alpha", version = 1)]
|
[IntrinsicCall(name = "alpha", version = 1)]
|
||||||
fn alpha() -> int;
|
fn alpha() -> long;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Doc(markdown = """
|
[Doc(markdown = """
|
||||||
|
|||||||
+192
-158
@@ -1,171 +1,205 @@
|
|||||||
[Doc(markdown = """
|
declare enum Button(Up, Down, Left, Right, A, B, X, Y, L, R, Start, Select);
|
||||||
Root input device provider.
|
|
||||||
""")]
|
|
||||||
[BuiltinType(name = "input", version = 1)]
|
|
||||||
declare builtin type InputType() {
|
|
||||||
[Doc(markdown = """
|
|
||||||
Returns the gamepad input state.
|
|
||||||
""")]
|
|
||||||
[IntrinsicCall(name = "pad", version = 1)]
|
|
||||||
fn pad() -> InputPad;
|
|
||||||
|
|
||||||
[Doc(markdown = """
|
|
||||||
Returns the touch input state.
|
|
||||||
""")]
|
|
||||||
[IntrinsicCall(name = "touch", version = 1)]
|
|
||||||
fn touch() -> InputTouch;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Doc(markdown = """
|
[Doc(markdown = """
|
||||||
Represents the current gamepad state.
|
Direct zero-argument gamepad queries. Prefer Pad with a typed Button in game code.
|
||||||
""")]
|
""")]
|
||||||
[BuiltinType(name = "input.pad", version = 1)]
|
[BuiltinType(name = "input.pad", version = 1)]
|
||||||
declare builtin type InputPad() {
|
declare builtin type LowPad() {
|
||||||
[Doc(markdown = """
|
[IntrinsicCall(name = "input.pad.up.pressed", version = 1)]
|
||||||
Returns the up directional button.
|
fn up_pressed() -> bool;
|
||||||
""")]
|
[IntrinsicCall(name = "input.pad.up.released", version = 1)]
|
||||||
[IntrinsicCall(name = "up", version = 1)]
|
fn up_released() -> bool;
|
||||||
fn up() -> InputButton;
|
[IntrinsicCall(name = "input.pad.up.down", version = 1)]
|
||||||
|
fn up_down() -> bool;
|
||||||
[Doc(markdown = """
|
[IntrinsicCall(name = "input.pad.up.hold", version = 1)]
|
||||||
Returns the down directional button.
|
fn up_hold() -> long;
|
||||||
""")]
|
[IntrinsicCall(name = "input.pad.down.pressed", version = 1)]
|
||||||
[IntrinsicCall(name = "down", version = 1)]
|
fn down_pressed() -> bool;
|
||||||
fn down() -> InputButton;
|
[IntrinsicCall(name = "input.pad.down.released", version = 1)]
|
||||||
|
fn down_released() -> bool;
|
||||||
[Doc(markdown = """
|
[IntrinsicCall(name = "input.pad.down.down", version = 1)]
|
||||||
Returns the left directional button.
|
fn down_down() -> bool;
|
||||||
""")]
|
[IntrinsicCall(name = "input.pad.down.hold", version = 1)]
|
||||||
[IntrinsicCall(name = "left", version = 1)]
|
fn down_hold() -> long;
|
||||||
fn left() -> InputButton;
|
[IntrinsicCall(name = "input.pad.left.pressed", version = 1)]
|
||||||
|
fn left_pressed() -> bool;
|
||||||
[Doc(markdown = """
|
[IntrinsicCall(name = "input.pad.left.released", version = 1)]
|
||||||
Returns the right directional button.
|
fn left_released() -> bool;
|
||||||
""")]
|
[IntrinsicCall(name = "input.pad.left.down", version = 1)]
|
||||||
[IntrinsicCall(name = "right", version = 1)]
|
fn left_down() -> bool;
|
||||||
fn right() -> InputButton;
|
[IntrinsicCall(name = "input.pad.left.hold", version = 1)]
|
||||||
|
fn left_hold() -> long;
|
||||||
[Doc(markdown = """
|
[IntrinsicCall(name = "input.pad.right.pressed", version = 1)]
|
||||||
Returns the A action button.
|
fn right_pressed() -> bool;
|
||||||
""")]
|
[IntrinsicCall(name = "input.pad.right.released", version = 1)]
|
||||||
[IntrinsicCall(name = "a", version = 1)]
|
fn right_released() -> bool;
|
||||||
fn a() -> InputButton;
|
[IntrinsicCall(name = "input.pad.right.down", version = 1)]
|
||||||
|
fn right_down() -> bool;
|
||||||
[Doc(markdown = """
|
[IntrinsicCall(name = "input.pad.right.hold", version = 1)]
|
||||||
Returns the B action button.
|
fn right_hold() -> long;
|
||||||
""")]
|
[IntrinsicCall(name = "input.pad.a.pressed", version = 1)]
|
||||||
[IntrinsicCall(name = "b", version = 1)]
|
fn a_pressed() -> bool;
|
||||||
fn b() -> InputButton;
|
[IntrinsicCall(name = "input.pad.a.released", version = 1)]
|
||||||
|
fn a_released() -> bool;
|
||||||
[Doc(markdown = """
|
[IntrinsicCall(name = "input.pad.a.down", version = 1)]
|
||||||
Returns the X action button.
|
fn a_down() -> bool;
|
||||||
""")]
|
[IntrinsicCall(name = "input.pad.a.hold", version = 1)]
|
||||||
[IntrinsicCall(name = "x", version = 1)]
|
fn a_hold() -> long;
|
||||||
fn x() -> InputButton;
|
[IntrinsicCall(name = "input.pad.b.pressed", version = 1)]
|
||||||
|
fn b_pressed() -> bool;
|
||||||
[Doc(markdown = """
|
[IntrinsicCall(name = "input.pad.b.released", version = 1)]
|
||||||
Returns the Y action button.
|
fn b_released() -> bool;
|
||||||
""")]
|
[IntrinsicCall(name = "input.pad.b.down", version = 1)]
|
||||||
[IntrinsicCall(name = "y", version = 1)]
|
fn b_down() -> bool;
|
||||||
fn y() -> InputButton;
|
[IntrinsicCall(name = "input.pad.b.hold", version = 1)]
|
||||||
|
fn b_hold() -> long;
|
||||||
[Doc(markdown = """
|
[IntrinsicCall(name = "input.pad.x.pressed", version = 1)]
|
||||||
Returns the left shoulder button.
|
fn x_pressed() -> bool;
|
||||||
""")]
|
[IntrinsicCall(name = "input.pad.x.released", version = 1)]
|
||||||
[IntrinsicCall(name = "l", version = 1)]
|
fn x_released() -> bool;
|
||||||
fn l() -> InputButton;
|
[IntrinsicCall(name = "input.pad.x.down", version = 1)]
|
||||||
|
fn x_down() -> bool;
|
||||||
[Doc(markdown = """
|
[IntrinsicCall(name = "input.pad.x.hold", version = 1)]
|
||||||
Returns the right shoulder button.
|
fn x_hold() -> long;
|
||||||
""")]
|
[IntrinsicCall(name = "input.pad.y.pressed", version = 1)]
|
||||||
[IntrinsicCall(name = "r", version = 1)]
|
fn y_pressed() -> bool;
|
||||||
fn r() -> InputButton;
|
[IntrinsicCall(name = "input.pad.y.released", version = 1)]
|
||||||
|
fn y_released() -> bool;
|
||||||
[Doc(markdown = """
|
[IntrinsicCall(name = "input.pad.y.down", version = 1)]
|
||||||
Returns the start button.
|
fn y_down() -> bool;
|
||||||
""")]
|
[IntrinsicCall(name = "input.pad.y.hold", version = 1)]
|
||||||
[IntrinsicCall(name = "start", version = 1)]
|
fn y_hold() -> long;
|
||||||
fn start() -> InputButton;
|
[IntrinsicCall(name = "input.pad.l.pressed", version = 1)]
|
||||||
|
fn l_pressed() -> bool;
|
||||||
[Doc(markdown = """
|
[IntrinsicCall(name = "input.pad.l.released", version = 1)]
|
||||||
Returns the select button.
|
fn l_released() -> bool;
|
||||||
""")]
|
[IntrinsicCall(name = "input.pad.l.down", version = 1)]
|
||||||
[IntrinsicCall(name = "select", version = 1)]
|
fn l_down() -> bool;
|
||||||
fn select() -> InputButton;
|
[IntrinsicCall(name = "input.pad.l.hold", version = 1)]
|
||||||
|
fn l_hold() -> long;
|
||||||
|
[IntrinsicCall(name = "input.pad.r.pressed", version = 1)]
|
||||||
|
fn r_pressed() -> bool;
|
||||||
|
[IntrinsicCall(name = "input.pad.r.released", version = 1)]
|
||||||
|
fn r_released() -> bool;
|
||||||
|
[IntrinsicCall(name = "input.pad.r.down", version = 1)]
|
||||||
|
fn r_down() -> bool;
|
||||||
|
[IntrinsicCall(name = "input.pad.r.hold", version = 1)]
|
||||||
|
fn r_hold() -> long;
|
||||||
|
[IntrinsicCall(name = "input.pad.start.pressed", version = 1)]
|
||||||
|
fn start_pressed() -> bool;
|
||||||
|
[IntrinsicCall(name = "input.pad.start.released", version = 1)]
|
||||||
|
fn start_released() -> bool;
|
||||||
|
[IntrinsicCall(name = "input.pad.start.down", version = 1)]
|
||||||
|
fn start_down() -> bool;
|
||||||
|
[IntrinsicCall(name = "input.pad.start.hold", version = 1)]
|
||||||
|
fn start_hold() -> long;
|
||||||
|
[IntrinsicCall(name = "input.pad.select.pressed", version = 1)]
|
||||||
|
fn select_pressed() -> bool;
|
||||||
|
[IntrinsicCall(name = "input.pad.select.released", version = 1)]
|
||||||
|
fn select_released() -> bool;
|
||||||
|
[IntrinsicCall(name = "input.pad.select.down", version = 1)]
|
||||||
|
fn select_down() -> bool;
|
||||||
|
[IntrinsicCall(name = "input.pad.select.hold", version = 1)]
|
||||||
|
fn select_hold() -> long;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Doc(markdown = """
|
[Doc(markdown = """
|
||||||
Represents the current touch input state.
|
Queries the selected gamepad button at the time of the call.
|
||||||
|
""")]
|
||||||
|
declare service Pad {
|
||||||
|
[Doc(markdown = """
|
||||||
|
Queries pressed for the selected button. Only that endpoint is executed.
|
||||||
|
""")]
|
||||||
|
fn pressed(button: Button) -> bool {
|
||||||
|
return switch button {
|
||||||
|
Button.Up: { LowPad.up_pressed() },
|
||||||
|
Button.Down: { LowPad.down_pressed() },
|
||||||
|
Button.Left: { LowPad.left_pressed() },
|
||||||
|
Button.Right: { LowPad.right_pressed() },
|
||||||
|
Button.A: { LowPad.a_pressed() },
|
||||||
|
Button.B: { LowPad.b_pressed() },
|
||||||
|
Button.X: { LowPad.x_pressed() },
|
||||||
|
Button.Y: { LowPad.y_pressed() },
|
||||||
|
Button.L: { LowPad.l_pressed() },
|
||||||
|
Button.R: { LowPad.r_pressed() },
|
||||||
|
Button.Start: { LowPad.start_pressed() },
|
||||||
|
Button.Select: { LowPad.select_pressed() },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
[Doc(markdown = """
|
||||||
|
Queries released for the selected button. Only that endpoint is executed.
|
||||||
|
""")]
|
||||||
|
fn released(button: Button) -> bool {
|
||||||
|
return switch button {
|
||||||
|
Button.Up: { LowPad.up_released() },
|
||||||
|
Button.Down: { LowPad.down_released() },
|
||||||
|
Button.Left: { LowPad.left_released() },
|
||||||
|
Button.Right: { LowPad.right_released() },
|
||||||
|
Button.A: { LowPad.a_released() },
|
||||||
|
Button.B: { LowPad.b_released() },
|
||||||
|
Button.X: { LowPad.x_released() },
|
||||||
|
Button.Y: { LowPad.y_released() },
|
||||||
|
Button.L: { LowPad.l_released() },
|
||||||
|
Button.R: { LowPad.r_released() },
|
||||||
|
Button.Start: { LowPad.start_released() },
|
||||||
|
Button.Select: { LowPad.select_released() },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
[Doc(markdown = """
|
||||||
|
Queries down for the selected button. Only that endpoint is executed.
|
||||||
|
""")]
|
||||||
|
fn down(button: Button) -> bool {
|
||||||
|
return switch button {
|
||||||
|
Button.Up: { LowPad.up_down() },
|
||||||
|
Button.Down: { LowPad.down_down() },
|
||||||
|
Button.Left: { LowPad.left_down() },
|
||||||
|
Button.Right: { LowPad.right_down() },
|
||||||
|
Button.A: { LowPad.a_down() },
|
||||||
|
Button.B: { LowPad.b_down() },
|
||||||
|
Button.X: { LowPad.x_down() },
|
||||||
|
Button.Y: { LowPad.y_down() },
|
||||||
|
Button.L: { LowPad.l_down() },
|
||||||
|
Button.R: { LowPad.r_down() },
|
||||||
|
Button.Start: { LowPad.start_down() },
|
||||||
|
Button.Select: { LowPad.select_down() },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
[Doc(markdown = """
|
||||||
|
Queries hold for the selected button. Only that endpoint is executed.
|
||||||
|
""")]
|
||||||
|
fn hold(button: Button) -> long {
|
||||||
|
return switch button {
|
||||||
|
Button.Up: { LowPad.up_hold() },
|
||||||
|
Button.Down: { LowPad.down_hold() },
|
||||||
|
Button.Left: { LowPad.left_hold() },
|
||||||
|
Button.Right: { LowPad.right_hold() },
|
||||||
|
Button.A: { LowPad.a_hold() },
|
||||||
|
Button.B: { LowPad.b_hold() },
|
||||||
|
Button.X: { LowPad.x_hold() },
|
||||||
|
Button.Y: { LowPad.y_hold() },
|
||||||
|
Button.L: { LowPad.l_hold() },
|
||||||
|
Button.R: { LowPad.r_hold() },
|
||||||
|
Button.Start: { LowPad.start_hold() },
|
||||||
|
Button.Select: { LowPad.select_hold() },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Doc(markdown = """
|
||||||
|
Queries the current touch contact and coordinates.
|
||||||
""")]
|
""")]
|
||||||
[BuiltinType(name = "input.touch", version = 1)]
|
[BuiltinType(name = "input.touch", version = 1)]
|
||||||
declare builtin type InputTouch() {
|
declare builtin type Touch() {
|
||||||
[Doc(markdown = """
|
[IntrinsicCall(name = "input.touch.button.pressed", version = 1)]
|
||||||
Returns the touch contact as a button state.
|
|
||||||
""")]
|
|
||||||
[IntrinsicCall(name = "button", version = 1)]
|
|
||||||
fn button() -> InputButton;
|
|
||||||
|
|
||||||
[Doc(markdown = """
|
|
||||||
Returns the current touch x coordinate.
|
|
||||||
""")]
|
|
||||||
[IntrinsicCall(name = "x", version = 1)]
|
|
||||||
fn x() -> int;
|
|
||||||
|
|
||||||
[Doc(markdown = """
|
|
||||||
Returns the current touch y coordinate.
|
|
||||||
""")]
|
|
||||||
[IntrinsicCall(name = "y", version = 1)]
|
|
||||||
fn y() -> int;
|
|
||||||
}
|
|
||||||
|
|
||||||
[Doc(markdown = """
|
|
||||||
Represents one digital input button.
|
|
||||||
""")]
|
|
||||||
[BuiltinType(name = "input.button", version = 1)]
|
|
||||||
declare builtin type InputButton() {
|
|
||||||
[Doc(markdown = """
|
|
||||||
Returns true on the frame where the button becomes down.
|
|
||||||
""")]
|
|
||||||
[IntrinsicCall(name = "pressed", version = 1)]
|
|
||||||
fn pressed() -> bool;
|
fn pressed() -> bool;
|
||||||
|
[IntrinsicCall(name = "input.touch.button.released", version = 1)]
|
||||||
[Doc(markdown = """
|
|
||||||
Returns true on the frame where the button becomes up.
|
|
||||||
""")]
|
|
||||||
[IntrinsicCall(name = "released", version = 1)]
|
|
||||||
fn released() -> bool;
|
fn released() -> bool;
|
||||||
|
[IntrinsicCall(name = "input.touch.button.down", version = 1)]
|
||||||
[Doc(markdown = """
|
|
||||||
Returns true while the button is currently down.
|
|
||||||
""")]
|
|
||||||
[IntrinsicCall(name = "down", version = 1)]
|
|
||||||
fn down() -> bool;
|
fn down() -> bool;
|
||||||
|
[IntrinsicCall(name = "input.touch.button.hold", version = 1)]
|
||||||
[Doc(markdown = """
|
fn hold() -> long;
|
||||||
Returns how long the button has been held.
|
[IntrinsicCall(name = "x", version = 1)]
|
||||||
""")]
|
fn x() -> long;
|
||||||
[IntrinsicCall(name = "hold", version = 1)]
|
[IntrinsicCall(name = "y", version = 1)]
|
||||||
fn hold() -> int;
|
fn y() -> long;
|
||||||
}
|
|
||||||
|
|
||||||
[Doc(markdown = """
|
|
||||||
High-level access to player input devices.
|
|
||||||
""")]
|
|
||||||
declare service Input
|
|
||||||
{
|
|
||||||
[Doc(markdown = """
|
|
||||||
Returns the gamepad input state.
|
|
||||||
""")]
|
|
||||||
fn pad() -> InputPad
|
|
||||||
{
|
|
||||||
return InputType.pad();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Doc(markdown = """
|
|
||||||
Returns the touch input state.
|
|
||||||
""")]
|
|
||||||
fn touch() -> InputTouch
|
|
||||||
{
|
|
||||||
return InputType.touch();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user