@byamoah/studio-core 0.0.0-stage → 0.1.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE +202 -0
  3. package/README.md +379 -2
  4. package/bin/studio.mjs +401 -0
  5. package/dist/contract.d.ts +144 -0
  6. package/dist/contract.js +1 -0
  7. package/dist/delivery/client.d.ts +2 -0
  8. package/dist/delivery/client.js +2 -0
  9. package/dist/delivery/contract.d.ts +2 -0
  10. package/dist/delivery/contract.js +2 -0
  11. package/dist/delivery/development.d.ts +2 -0
  12. package/dist/delivery/development.js +2 -0
  13. package/dist/device-contract.d.ts +54 -0
  14. package/dist/device-contract.js +84 -0
  15. package/dist/project-contract.d.ts +19 -0
  16. package/dist/project-contract.js +11 -0
  17. package/dist/runtime/browser.d.ts +14 -0
  18. package/dist/runtime/browser.js +425 -0
  19. package/dist/runtime/native.d.ts +47 -0
  20. package/dist/runtime/native.js +168 -0
  21. package/dist/runtime/refs.d.ts +5 -0
  22. package/dist/runtime/refs.js +13 -0
  23. package/dist/runtime-contract.d.ts +36 -0
  24. package/dist/runtime-contract.js +35 -0
  25. package/package.json +76 -4
  26. package/scripts/build-preview.mjs +73 -0
  27. package/scripts/connection-relay.mjs +411 -0
  28. package/scripts/connector-agent.mjs +251 -0
  29. package/scripts/connector.mjs +315 -0
  30. package/scripts/content-store.mjs +97 -0
  31. package/scripts/delivery-dev.mjs +39 -0
  32. package/scripts/delivery-handler.mjs +128 -0
  33. package/scripts/dev-channel.mjs +150 -0
  34. package/scripts/dev-proxy.mjs +63 -0
  35. package/scripts/device-channel.mjs +66 -0
  36. package/scripts/discover.mjs +109 -0
  37. package/scripts/live-preview.mjs +106 -0
  38. package/scripts/network-address.mjs +35 -0
  39. package/scripts/project-build.mjs +6 -0
  40. package/scripts/project.mjs +30 -0
  41. package/scripts/publish.mjs +24 -0
  42. package/scripts/publishing-channel.mjs +200 -0
  43. package/scripts/serve.mjs +14 -0
  44. package/scripts/server.mjs +49 -0
  45. package/scripts/static-handler.mjs +86 -0
  46. package/src/adapters/react/discover.mjs +1329 -0
  47. package/src/compiler/cache-version.cjs +7 -0
  48. package/src/compiler/instrument.cjs +248 -0
  49. package/src/compiler/local-sdk.cjs +38 -0
  50. package/src/compiler/vite.mjs +26 -0
  51. package/src/contract.ts +115 -0
  52. package/src/delivery/client.ts +2 -0
  53. package/src/delivery/contract.ts +2 -0
  54. package/src/delivery/development.ts +2 -0
  55. package/src/device-contract.ts +155 -0
  56. package/src/discover.mjs +1 -0
  57. package/src/project-contract.ts +30 -0
  58. package/src/runtime/browser.ts +501 -0
  59. package/src/runtime/native.ts +245 -0
  60. package/src/runtime/refs.ts +15 -0
  61. package/src/runtime-contract.ts +77 -0
  62. package/src/state/authoring.mjs +69 -0
  63. package/src/state/collections.mjs +62 -0
  64. package/src/state/compatibility.mjs +40 -0
  65. package/src/state/compile.mjs +457 -0
  66. package/tools/build.mjs +83 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # @byamoah/studio-core
2
+
3
+ ## 0.1.0-beta.0
4
+
5
+ Initial public prerelease.
6
+
7
+ - Studio CLI for discovery, watch mode, contract checks, delivery validation and reviewed migrations.
8
+ - Generated field contracts, collection templates and TypeScript declarations.
9
+ - Babel and Vite instrumentation with browser and native inspection primitives.
10
+ - Outbound hosted connections and a standalone local development agent.
11
+ - Node server adapters for content delivery, revision storage and development relays.
12
+ - Apache-2.0 license and package integration documentation.
13
+
14
+ ### Dependencies
15
+
16
+ - Depends on `@byamoah/studio-state@0.1.0-beta.0`.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,380 @@
1
- # Temporary Holding Version
1
+ # @byamoah/studio-core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Discovery, generated types, inspection primitives and development connections for applications using Studio.
4
+
5
+ The CLI finds supported Studio state references in React and React Native source, generates a compatibility contract and TypeScript declarations, and keeps authoring metadata synchronized with the project. Runtime adapters let an application expose its rendered elements to Studio inspection. An outbound connector links a local project to a hosted Studio platform.
6
+
7
+ This package is developer tooling and integration infrastructure. It is not the Studio website, a replacement application server, or a mechanism for downloading new native components.
8
+
9
+ ## Installation
10
+
11
+ Requires Node.js **22.18 or later**. Use the React version already installed by the consuming application.
12
+
13
+ ```sh
14
+ npm install @byamoah/studio-core@next @byamoah/studio-state@next
15
+ ```
16
+
17
+ The initial release is a prerelease distributed under `next`. Use matching versions of both packages. Keep `studio-core` as an application dependency if application code imports its runtime modules; use a development dependency only when it is exclusively a build-time CLI.
18
+
19
+ Use the installed executable through package scripts or `npx --no-install studio`. This avoids accidentally resolving an unrelated registry package named `studio`.
20
+
21
+ ## Quick start
22
+
23
+ Run in the application root:
24
+
25
+ ```sh
26
+ npx --no-install studio init
27
+ ```
28
+
29
+ This creates `studio.config.mjs` and `studio-env.d.ts`. It does not create an application provider, install inspection bridges or start the Studio website. Existing configuration is not overwritten.
30
+
31
+ Configure the project:
32
+
33
+ ```js
34
+ // studio.config.mjs
35
+ import { fileURLToPath } from "node:url";
36
+
37
+ export default {
38
+ projectId: "my-app",
39
+ root: fileURLToPath(new URL("./", import.meta.url)),
40
+ routesDir: "src/app",
41
+ generatedDir: ".studio",
42
+ connection: {
43
+ name: "My App",
44
+ channel: "studio:my-app:preview",
45
+ },
46
+ state: {
47
+ authoring: {
48
+ snapshotFile: new URL(".studio/content.snapshot.json", import.meta.url),
49
+ draftFile: new URL(".studio/draft.json", import.meta.url),
50
+ },
51
+ },
52
+ };
53
+ ```
54
+
55
+ Use a stable project ID and the actual route directory. `src/app` above is a route-based application example. Discovery currently targets supported React/React Native source patterns; support for an arbitrary navigation framework is not implied by installation.
56
+
57
+ Read editable values in a screen:
58
+
59
+ ```tsx
60
+ import { Text } from "react-native";
61
+ import { useStudioContext } from "@byamoah/studio-state/react";
62
+
63
+ export default function Home() {
64
+ const std = useStudioContext();
65
+ return (
66
+ <Text style={{ color: std.theme.color.heading }}>
67
+ {std.screens.home.title}
68
+ </Text>
69
+ );
70
+ }
71
+ ```
72
+
73
+ Then generate:
74
+
75
+ ```sh
76
+ npx --no-install studio discover
77
+ ```
78
+
79
+ Ensure `studio-env.d.ts` is included in TypeScript. It references the generated declaration file. Newly introduced fields can be unresolved until generation runs. Do not manually declare every editable field or edit generated types.
80
+
81
+ Add convenient scripts to your application:
82
+
83
+ ```json
84
+ {
85
+ "scripts": {
86
+ "studio": "studio discover",
87
+ "studio:watch": "studio dev",
88
+ "studio:check": "studio check"
89
+ }
90
+ }
91
+ ```
92
+
93
+ Run `npm run studio:watch` while authoring. Mount a state or delivery provider above content-dependent screens; see the companion [state package README](https://github.com/KBismark/studio/blob/main/packages/state/README.md) for complete provider, loading and delivery examples.
94
+
95
+ ## CLI reference
96
+
97
+ | Command | Behavior |
98
+ | --- | --- |
99
+ | `studio init` | Create initial configuration and type reference files in the current directory |
100
+ | `studio discover` | Discover source bindings and write generated artifacts once |
101
+ | `studio dev` | Generate and continue watching source changes |
102
+ | `studio check` | Generate and exit unsuccessfully when contract diagnostics exist |
103
+ | `studio validate --url URL` | Fetch and validate a delivery envelope against the generated contract |
104
+ | `studio migrate --document FILE` | Apply a reviewed authoring document with backups and validation |
105
+ | `studio connect --studio URL` | Connect the local project to a hosted Studio platform |
106
+ | `studio help` | Print command usage |
107
+
108
+ `check` writes generated artifacts; it is not a read-only lint command. Discovery does not run your application, launch Metro, publish content or perform TypeScript checking.
109
+
110
+ ### Configuration selection
111
+
112
+ For discovery, watch, check, validate and migrate, selection is:
113
+
114
+ 1. `--project PATH` or `--config PATH`.
115
+ 2. `STUDIO_PROJECT`.
116
+ 3. `studio.config.mjs` in the current directory.
117
+
118
+ A full `studio.project.mjs` can supply discovery/state configuration alongside platform-specific adapters. The CLI reads `project.discovery` when present, otherwise the top-level discovery configuration.
119
+
120
+ ```sh
121
+ npx --no-install studio check --project ./studio.project.mjs
122
+ npx --no-install studio dev --config ./studio.config.mjs
123
+ ```
124
+
125
+ ### Generated artifacts
126
+
127
+ The configured generated directory contains artifacts including:
128
+
129
+ | Artifact | Purpose |
130
+ | --- | --- |
131
+ | `discovery.json` | Screen, source and element metadata used by inspection/instrumentation |
132
+ | `identity.registry.json` | Persistent source identity registry |
133
+ | `state.contract.json` | Inferred fields, collections, compatibility ID and diagnostics |
134
+ | `studio.generated.d.ts` | Generated declarations referenced by the app |
135
+ | `studio.document.d.ts` | Generated document shape |
136
+ | `content.snapshot.json` | Authoring snapshot when configured at this location |
137
+ | `contract-history/` | Archived contracts and original authoring snapshots when contracts change |
138
+
139
+ Paths can differ in a full project configuration. Keep the discovery manifest path consistent across the compiler, Babel plugin and application bridge. Do not delete authored draft files casually: they contain edits, rather than disposable compiler output. Back up project content and registry data as part of your development workflow.
140
+
141
+ ## What discovery understands
142
+
143
+ Editable fields come from supported uses of `useStudioContext`, `useStudioListItem`, repeats and registered blocks. Discovery follows imported bindings; `std` is a readable variable convention, not a globally reserved JavaScript identifier.
144
+
145
+ Use direct property references in UI expressions and supported style properties. Collection items use stable string IDs. A component alias is resolved where its implementation can be analyzed; an unknown wrapper, ambiguous source or runtime-selected key may not provide enough information for an editable binding. Inspect diagnostics rather than assuming every expression can be inferred.
146
+
147
+ For a repeatable template:
148
+
149
+ ```tsx
150
+ import { Text, View } from "react-native";
151
+ import * as Studio from "@byamoah/studio-state/react";
152
+
153
+ function Card({ id }: Studio.RepeatItemProps) {
154
+ const std = Studio.useStudioContext();
155
+ const card = Studio.useStudioListItem(std.screens.home.cards, id);
156
+ return <Text>{card.title}</Text>;
157
+ }
158
+
159
+ export default function Home() {
160
+ const std = Studio.useStudioContext();
161
+ return (
162
+ <View>
163
+ <Studio.Repeat items={std.screens.home.cards} template={Card} />
164
+ </View>
165
+ );
166
+ }
167
+ ```
168
+
169
+ The source reference declares the editable collection. Its schema and creation template are inferred from supported item usage. There is no second manually maintained list of field paths. Run discovery again when adding new fields, variants or slots. Structural updates can instantiate only components already registered and shipped in the application.
170
+
171
+ ## Preview and inspection integration
172
+
173
+ A running app plus generated metadata does not automatically implement click-to-inspect. Integration has three distinct layers:
174
+
175
+ 1. **Content:** a provider exposes the current validated document. Native draft delivery uses a delivery client; an iframe bridge also needs a setter for validated preview documents.
176
+ 2. **Instrumentation:** source elements receive compiler metadata before JSX/source positions are transformed.
177
+ 3. **Runtime bridge:** application host adapters register rendered elements, handle navigation and focus, and exchange validated messages with Studio.
178
+
179
+ Keep inspection and device command processing in development or explicitly opted-in preview builds. Installed production applications can still fetch published content without exposing editor controls.
180
+
181
+ ### Babel instrumentation
182
+
183
+ Add the exported plugin to the application's existing Babel configuration. Merge it with framework-required presets and plugins:
184
+
185
+ ```js
186
+ const path = require("node:path");
187
+ const projectRoot = __dirname;
188
+ const manifestFile = path.join(projectRoot, ".studio/discovery.json");
189
+ const inspect = process.env.NODE_ENV === "development" ||
190
+ process.env.STUDIO_PREVIEW === "1";
191
+
192
+ const studioPlugins = inspect
193
+ ? [[require.resolve("@byamoah/studio-core/babel"), {
194
+ projectRoot,
195
+ manifestFile,
196
+ }]]
197
+ : [];
198
+
199
+ // Include studioPlugins in your framework's Babel plugins before source
200
+ // coordinates are changed. Generate manifestFile before the first build.
201
+ ```
202
+
203
+ This plugin attaches metadata; it does not replace the application's components with inspectable wrappers. Host adapters must consume the metadata and preserve forwarded refs, explicit props and cleanup behavior. Exclude adapter implementation files with `excludeFiles` if needed to avoid instrumenting the adapter itself.
204
+
205
+ ### Vite instrumentation
206
+
207
+ For an application using Vite, put instrumentation before the framework's JSX transform:
208
+
209
+ ```ts
210
+ import { defineConfig } from "vite";
211
+ import react from "@vitejs/plugin-react";
212
+ import { studioInstrumentation } from "@byamoah/studio-core/vite";
213
+ import { fileURLToPath } from "node:url";
214
+
215
+ const projectRoot = fileURLToPath(new URL("./", import.meta.url));
216
+
217
+ export default defineConfig(({ mode }) => ({
218
+ plugins: [
219
+ ...(mode === "development" ? [studioInstrumentation({
220
+ projectRoot,
221
+ manifestFile: fileURLToPath(new URL(".studio/discovery.json", import.meta.url)),
222
+ })] : []),
223
+ react(),
224
+ ],
225
+ }));
226
+ ```
227
+
228
+ An exported preview can opt into the same instrumentation explicitly. Do not expose inspection in ordinary release builds by accident.
229
+
230
+ ### Runtime adapters
231
+
232
+ | Export | Responsibility |
233
+ | --- | --- |
234
+ | `/runtime/browser` | Register DOM hosts and create a browser inspector |
235
+ | `/runtime/native` | Register measurable native hosts/scroll containers, pick and focus elements |
236
+ | `/runtime/refs` | Attach and clean up object/callback refs |
237
+ | `/runtime-contract` | Metadata, selection and focus types |
238
+ | `/device-contract` | Device command/status contracts and validation |
239
+
240
+ Registration returns cleanup functions. Unregister on unmount/ref replacement. For repeats, bind metadata to the actual item instance before registering. Hidden or virtualized content needs route navigation and reveal/scroll callbacks before it can be focused.
241
+
242
+ The web bridge must check the parent window, trusted Studio origin, channel, session and build identity before accepting commands or documents. The native bridge must process commands for its own device/build, acknowledge them, and report route and delivery status. Mount the native connection bridge outside the content loading boundary so an empty first launch can still connect.
243
+
244
+ There is not yet a single framework-neutral installation command that generates all of this bridge code. These exports are the supported primitives for that one-time integration.
245
+
246
+ ### Local SDK development with Metro
247
+
248
+ `/metro` exports `withLocalStudioSDK(config, { packageRoot, appRoot })` for working on a linked local copy of `studio-state` while preserving the application's React instance. `packageRoot` points to the state package directory. Registry-installed applications normally do not need this helper.
249
+
250
+ `/cache-version` exports `studioCacheVersion(base, buildId)` to associate transformed modules with the discovery build. It accepts a generated 64-character hexadecimal build ID. Restart Metro after changing Babel/Metro configuration; regenerate metadata before the first instrumented run.
251
+
252
+ ## Connect a local project to hosted Studio
253
+
254
+ Your laptop makes an outbound connection. The hosted platform does not need direct inbound access to the laptop's filesystem or LAN address.
255
+
256
+ ```sh
257
+ # Set STUDIO_CONNECT_TOKEN in your shell using the provisioning token
258
+ # supplied by the Studio host. Do not commit it.
259
+ npx --no-install studio connect \
260
+ --studio https://studio.example.com \
261
+ --project ./studio.config.mjs
262
+ ```
263
+
264
+ Without `--local`, the command starts a loopback development agent, generates project metadata and watches supported source changes. It prints a private editor link. Keep the process running while editing and stop it with Ctrl+C when finished.
265
+
266
+ To reuse an existing local Studio development server:
267
+
268
+ ```sh
269
+ npx --no-install studio connect \
270
+ --studio https://studio.example.com \
271
+ --local http://localhost:5173
272
+ ```
273
+
274
+ | Option/configuration | Purpose |
275
+ | --- | --- |
276
+ | `--project PATH` / `STUDIO_PROJECT` | Project config for the standalone agent |
277
+ | `--local URL` / `STUDIO_LOCAL_ORIGIN` | Reuse an existing loopback Studio server |
278
+ | `STUDIO_CONNECT_TOKEN` / `--token` | Hosted provisioning credential; prefer the environment variable |
279
+ | `--preview-url URL` | Public web URL of the running app for iframe preview |
280
+ | `--native-url URL` | Public native app launch URL, such as an Expo tunnel link |
281
+ | `--simulator` | Open the local development link in an already booted Apple simulator |
282
+ | `STUDIO_SIMULATOR_UDID` | Simulator identifier; defaults to `booted` |
283
+ | `--allow-http` | Allow an HTTP loopback host for local testing |
284
+
285
+ `--preview-url` and `--native-url` do not create tunnels. Supply URLs from a separately configured tunnel supporting your development server's HTTP and WebSocket traffic. Hosted HTTPS pages need a reachable HTTPS web preview. Configure the application bridge to trust the hosted Studio origin. React Native applications still run through their normal development server.
286
+
287
+ For a simulator on the laptop, use loopback addresses. For a phone on the same LAN, use the laptop's reachable network address. For devices on different networks, use publicly reachable app-development and Studio connection URLs. A remote phone cannot access the laptop through `localhost`.
288
+
289
+ Private connection links grant development access; share them only with intended participants. Current relay sessions are in memory, expire, and need reconnection after host restart. The connector is development infrastructure, not the installed application's permanent production content endpoint. Restart it after changing configuration or adapter modules that are loaded at startup.
290
+
291
+ ## Validate and migrate content
292
+
293
+ Validate the same envelope used by development and production clients:
294
+
295
+ ```sh
296
+ npx --no-install studio check
297
+ npx --no-install studio validate \
298
+ --url https://content.example.com/studio/content
299
+ ```
300
+
301
+ Validation adds the generated project and contract identifiers to the request, checks the envelope and document, and runs an application validator when provided by the full project adapter. Use `--allow-http` only for development. Keep older compatible publications available to applications with earlier contracts.
302
+
303
+ When source changes alter the contract, review a migration before applying it:
304
+
305
+ ```sh
306
+ npx --no-install studio migrate --document ./reviewed-document.json
307
+ ```
308
+
309
+ The file is a complete candidate document, not a mapping specification. The command requires the configured authoring draft path, validates against the target generated contract, backs up existing authoring data, writes the candidate and regenerates. A failure restores the prior authoring files. Applying a migration does not publish it.
310
+
311
+ ## Server integration exports
312
+
313
+ These Node.js adapters support custom platform and delivery hosts:
314
+
315
+ | Export | API |
316
+ | --- | --- |
317
+ | `/project` | `defineProject` and the browser project adapter contract |
318
+ | `/publishing` | `createRevisionStore` for filesystem revision persistence |
319
+ | `/delivery-handler` | `deliveryHandler` for compatible reads and authenticated publication |
320
+ | `/server` | `serveStudio` for an already built Studio website |
321
+ | `/connector` | `startConnector` for an outbound connection |
322
+ | `/connector-agent` | `createConnectorAgent` for the standalone project agent |
323
+ | `/connection-relay` | `createConnectionRelay` for hosted development sessions |
324
+
325
+ For example, mount a filesystem-backed content endpoint in a Node server:
326
+
327
+ ```js
328
+ import { createServer } from "node:http";
329
+ import { readFile } from "node:fs/promises";
330
+ import { validateStudioState } from "@byamoah/studio-state";
331
+ import { createRevisionStore } from "@byamoah/studio-core/publishing";
332
+ import { deliveryHandler } from "@byamoah/studio-core/delivery-handler";
333
+
334
+ const generated = JSON.parse(await readFile(".studio/state.contract.json", "utf8"));
335
+ const token = process.env.STUDIO_PUBLISH_TOKEN;
336
+ if (!token) throw new Error("Set STUDIO_PUBLISH_TOKEN on the server.");
337
+
338
+ const contract = {
339
+ projectId: "my-app",
340
+ schemaVersion: 1,
341
+ contractId: generated.contractId,
342
+ validate: (value) => validateStudioState(value, generated),
343
+ };
344
+ const store = createRevisionStore("./content-data", contract);
345
+ const handle = deliveryHandler({ store, contract, token, origins: [] });
346
+
347
+ createServer((req, res) => {
348
+ void handle(req, res).catch(() => {
349
+ if (!res.headersSent) res.writeHead(500);
350
+ res.end();
351
+ });
352
+ }).listen(4173, "127.0.0.1");
353
+ ```
354
+
355
+ The read endpoint is `/v1/projects/my-app/schemas/1/published.json`; clients send their contract identifier. Supply exact browser origins in `origins` when web clients need CORS. Place a production server behind HTTPS, use durable storage, and keep publisher credentials server-side. The filesystem store is intended for a single persistent server; distributed hosting needs storage and concurrency integration appropriate to that environment. These Node adapters are not automatically Cloudflare Worker-compatible merely because the website can be hosted there.
356
+
357
+ The package contains runtime modules and declarations, but not a prebuilt Studio website. Running `/server` requires a separate platform build and project configuration. Hosted connection provisioning and project publication use separate credentials.
358
+
359
+ ## Troubleshooting
360
+
361
+ - **`studio` is missing:** install the package in the project and run its local executable. Check the Node version.
362
+ - **New state properties are missing:** run `studio discover`, include the type-reference file, then review diagnostics.
363
+ - **Inspection is empty:** verify the manifest matches transformed source and that host adapters/bridges are mounted. Metadata generation alone does not register rendered views.
364
+ - **Source edits do not change an embedded preview:** a static export must be rebuilt. A live preview must point to the running app development server, not an old export.
365
+ - **Connection works locally but not on a phone:** check bind address, LAN reachability or tunnel URLs. A localhost link is usable only by that machine.
366
+ - **A published revision is rejected:** validate against the exact installed build's contract rather than the newest contract alone.
367
+
368
+ ## Further reading
369
+
370
+ - [State runtime package](https://github.com/KBismark/studio/blob/main/packages/state/README.md)
371
+ - [Application integration guide](https://github.com/KBismark/studio/blob/main/docs/GETTING_STARTED.md)
372
+ - [State and composition conventions](https://github.com/KBismark/studio/blob/main/docs/STUDIO_STATE.md)
373
+
374
+ This README ships in the npm package. Repository links require access while the source repository remains private.
375
+
376
+ ## License
377
+
378
+ Copyright 2026 Bismark Yamoah.
379
+
380
+ Licensed under the [Apache License, Version 2.0](./LICENSE). This license covers this package. Dependencies retain their respective licenses.