@byamoah/studio-core 0.0.0-stage → 0.1.0-next.1

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 (67) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/LICENSE +202 -0
  3. package/README.md +429 -2
  4. package/bin/studio.mjs +402 -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/connect-preview.mjs +124 -0
  28. package/scripts/connection-relay.mjs +498 -0
  29. package/scripts/connector-agent.mjs +253 -0
  30. package/scripts/connector.mjs +356 -0
  31. package/scripts/content-store.mjs +97 -0
  32. package/scripts/delivery-dev.mjs +39 -0
  33. package/scripts/delivery-handler.mjs +128 -0
  34. package/scripts/dev-channel.mjs +157 -0
  35. package/scripts/dev-proxy.mjs +63 -0
  36. package/scripts/device-channel.mjs +66 -0
  37. package/scripts/discover.mjs +109 -0
  38. package/scripts/live-preview.mjs +106 -0
  39. package/scripts/network-address.mjs +35 -0
  40. package/scripts/project-build.mjs +6 -0
  41. package/scripts/project.mjs +30 -0
  42. package/scripts/publish.mjs +24 -0
  43. package/scripts/publishing-channel.mjs +200 -0
  44. package/scripts/serve.mjs +14 -0
  45. package/scripts/server.mjs +49 -0
  46. package/scripts/static-handler.mjs +86 -0
  47. package/src/adapters/react/discover.mjs +1329 -0
  48. package/src/compiler/cache-version.cjs +7 -0
  49. package/src/compiler/instrument.cjs +248 -0
  50. package/src/compiler/local-sdk.cjs +38 -0
  51. package/src/compiler/vite.mjs +26 -0
  52. package/src/contract.ts +115 -0
  53. package/src/delivery/client.ts +2 -0
  54. package/src/delivery/contract.ts +2 -0
  55. package/src/delivery/development.ts +2 -0
  56. package/src/device-contract.ts +155 -0
  57. package/src/discover.mjs +1 -0
  58. package/src/project-contract.ts +30 -0
  59. package/src/runtime/browser.ts +501 -0
  60. package/src/runtime/native.ts +245 -0
  61. package/src/runtime/refs.ts +15 -0
  62. package/src/runtime-contract.ts +77 -0
  63. package/src/state/authoring.mjs +69 -0
  64. package/src/state/collections.mjs +62 -0
  65. package/src/state/compatibility.mjs +40 -0
  66. package/src/state/compile.mjs +457 -0
  67. package/tools/build.mjs +83 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,27 @@
1
+ # @byamoah/studio-core
2
+
3
+ ## 0.1.0-next.1
4
+
5
+ ### Minor Changes
6
+
7
+ - 1253d94: Renew active development connections automatically and expire abandoned leases after inactivity. Add shared long-held editor updates and connector job waits to reduce repeated metadata, session and device requests. Make `studio connect` discover project configuration, check the running app, manage an HTTPS preview tunnel, open the private workspace and clean up owned processes on exit, with actionable startup errors.
8
+ - ecdd3db: Add an optional persistence interface to the connection relay so deployment adapters can restore active sessions after a process restart. The default Node relay remains in memory. In-flight connector jobs are not persisted.
9
+
10
+ ### Patch Changes
11
+
12
+ - @byamoah/studio-state@0.1.0-next.1
13
+
14
+ ## 0.1.0-beta.0
15
+
16
+ Initial public prerelease.
17
+
18
+ - Studio CLI for discovery, watch mode, contract checks, delivery validation and reviewed migrations.
19
+ - Generated field contracts, collection templates and TypeScript declarations.
20
+ - Babel and Vite instrumentation with browser and native inspection primitives.
21
+ - Outbound hosted connections and a standalone local development agent.
22
+ - Node server adapters for content delivery, revision storage and development relays.
23
+ - Apache-2.0 license and package integration documentation.
24
+
25
+ ### Dependencies
26
+
27
+ - 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,430 @@
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
+ Start your app's development server first. For Expo, use a separate terminal:
255
+
256
+ ```sh
257
+ EXPO_PUBLIC_STUDIO_ORIGIN=https://studio.example.com npx expo start --localhost --port 8081
258
+ ```
259
+
260
+ The environment variable configures the application's trusted web bridge origin. Restart Expo after changing it. Providers and inspection bridges still need the one-time integration described above.
261
+
262
+ Once the app server is running and `STUDIO_CONNECT_TOKEN` is configured, connecting is one command:
263
+
264
+ ```sh
265
+ npx studio connect --studio https://studio.example.com
266
+ ```
267
+
268
+ The CLI finds the nearest `studio.config.mjs` or `studio.project.mjs`, including a parent configuration in a monorepo. Its watcher updates the normal `.studio/discovery.json` manifest (or your explicit native manifest path) alongside the hosted metadata; do not run a second `studio dev` watcher for the same project. It generates metadata, checks the app server, starts an HTTPS development tunnel, establishes the hosted connection and opens your private workspace in the browser. No local Studio website is required. It never launches a simulator unless `--simulator` is explicitly supplied.
269
+
270
+ The managed tunnel uses Cloudflare's official `cloudflared` tool. A compatible installed binary is reused; otherwise a pinned binary is downloaded once, verified against the official release checksum, and cached outside the project. There is no package-install hook that downloads it. No separate Cloudflare account is required for this temporary tunnel. The tool exposes the running app development server until you stop the command. Use an existing transport with `--preview-url` if you prefer another tunnel provider.
271
+
272
+ The managed startup flow requires the updated CLI. The initial `0.1.0-beta.0` CLI requires explicit transport URLs; use the updated release or a packed development version for the behavior described here.
273
+
274
+ ### Credentials and app URL
275
+
276
+ Your Studio host supplies a provisioning token. Set `STUDIO_CONNECT_TOKEN` in the shell, or put it in a private `.env.studio.local` file in the directory where you run the command:
277
+
278
+ ```dotenv
279
+ STUDIO_CONNECT_TOKEN=your-private-host-provisioning-token
280
+ ```
281
+
282
+ Ignore that file in Git. The token is not a public application environment variable. Account-based login is not implemented by this command.
283
+
284
+ Expo projects default to `http://127.0.0.1:8081/`. For another framework or port, configure the application server once:
285
+
286
+ ```js
287
+ connection: {
288
+ name: "My App",
289
+ developmentUrl: "http://localhost:3000/",
290
+ }
291
+ ```
292
+
293
+ The full adapter's `preview.developmentUrl` also works. `--app-url` overrides either setting. The command does not start or stop an app server that you own. Missing configuration, an unreachable app, a failed tunnel and a failed host connection produce terminal errors with a next action. A failed startup cleans up the tunnel and agent. Ctrl+C closes the session, stops the owned tunnel and stops discovery; your app server keeps running.
294
+
295
+ ### Options
296
+
297
+ | Option/configuration | Purpose |
298
+ | --- | --- |
299
+ | `--project PATH` / `STUDIO_PROJECT` | Override automatic project config lookup |
300
+ | `--app-url URL` | Loopback app server to check and tunnel |
301
+ | `--preview-url URL` | Use and check an existing public HTTPS web preview instead of creating a tunnel |
302
+ | `--native-url URL` | Override the native app launch URL; Expo projects with a managed tunnel get an `exps:` link |
303
+ | `--native-only` | Intentionally skip web-server/tunnel setup and use connected-device mode |
304
+ | `--no-open` | Print the private workspace link without opening a browser |
305
+ | `--local URL` / `STUDIO_LOCAL_ORIGIN` | Reuse an existing local Studio server; supply `--app-url` for its preview or `--preview-url` |
306
+ | `STUDIO_CONNECT_TOKEN` / `--token` | Provisioning credential; prefer the environment variable or private env file |
307
+ | `STUDIO_CLOUDFLARED_BIN` | Use an explicit compatible tunnel binary |
308
+ | `STUDIO_CACHE_DIR` | Override the tool download cache directory |
309
+ | `--simulator` | Explicitly open a connection in an already booted Apple simulator |
310
+ | `STUDIO_SIMULATOR_UDID` | Simulator identifier, defaulting to `booted` |
311
+ | `--allow-http` | Permit an HTTP loopback host/preview for local testing |
312
+
313
+ For a simulator-only workflow, add `--native-only --simulator` to the connection command. On the same laptop, its launch and content URLs remain loopback addresses. Other-network phones need a working public Expo/native transport and correct app bridge integration; a remote device cannot use laptop-local URLs. An externally supplied `--native-url` remains useful for custom development clients or an independently managed transport.
314
+
315
+ ### Renewal and traffic
316
+
317
+ The session is a rolling lease, not a fixed development time limit. Authenticated connector activity extends it automatically. A browser tab alone cannot renew it. After an ungraceful disconnect, the session expires after the configured inactivity period, one hour by default. Ctrl+C explicitly revokes it immediately. Restarting a Node host without persistence ends sessions; a host with a session-storage adapter can restore them. Cloudflare's deployment adapter persists lease checkpoints.
318
+
319
+ Hosted Studio shares a single long-held `/updates` request across metadata, draft and device consumers. The server sends only changed sections (document, metadata or devices), and returns an empty response after up to 20 seconds of inactivity. The connector similarly waits up to ten seconds for jobs instead of requesting empty queues several times per second. Background browser tabs pause their update subscription; interrupted connections retry with backoff. Native telemetry can still cause legitimate updates when devices are active.
320
+
321
+ Older connectors/hosts keep compatible polling behavior. Upgrade the CLI and platform together to get the shared stream and automatic renewal. Private pairing links grant development access; share them only with intended participants. The connector is not an installed application's permanent production content endpoint. Restart it after changing configuration modules loaded at startup.
322
+
323
+ ## Validate and migrate content
324
+
325
+ Validate the same envelope used by development and production clients:
326
+
327
+ ```sh
328
+ npx --no-install studio check
329
+ npx --no-install studio validate \
330
+ --url https://content.example.com/studio/content
331
+ ```
332
+
333
+ 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.
334
+
335
+ When source changes alter the contract, review a migration before applying it:
336
+
337
+ ```sh
338
+ npx --no-install studio migrate --document ./reviewed-document.json
339
+ ```
340
+
341
+ 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.
342
+
343
+ ## Server integration exports
344
+
345
+ These Node.js adapters support custom platform and delivery hosts:
346
+
347
+ | Export | API |
348
+ | --- | --- |
349
+ | `/project` | `defineProject` and the browser project adapter contract |
350
+ | `/publishing` | `createRevisionStore` for filesystem revision persistence |
351
+ | `/delivery-handler` | `deliveryHandler` for compatible reads and authenticated publication |
352
+ | `/server` | `serveStudio` for an already built Studio website |
353
+ | `/connector` | `startConnector` for an outbound connection |
354
+ | `/connector-agent` | `createConnectorAgent` for the standalone project agent |
355
+ | `/connection-relay` | `createConnectionRelay` for hosted development sessions |
356
+
357
+ For example, mount a filesystem-backed content endpoint in a Node server:
358
+
359
+ ```js
360
+ import { createServer } from "node:http";
361
+ import { readFile } from "node:fs/promises";
362
+ import { validateStudioState } from "@byamoah/studio-state";
363
+ import { createRevisionStore } from "@byamoah/studio-core/publishing";
364
+ import { deliveryHandler } from "@byamoah/studio-core/delivery-handler";
365
+
366
+ const generated = JSON.parse(await readFile(".studio/state.contract.json", "utf8"));
367
+ const token = process.env.STUDIO_PUBLISH_TOKEN;
368
+ if (!token) throw new Error("Set STUDIO_PUBLISH_TOKEN on the server.");
369
+
370
+ const contract = {
371
+ projectId: "my-app",
372
+ schemaVersion: 1,
373
+ contractId: generated.contractId,
374
+ validate: (value) => validateStudioState(value, generated),
375
+ };
376
+ const store = createRevisionStore("./content-data", contract);
377
+ const handle = deliveryHandler({ store, contract, token, origins: [] });
378
+
379
+ createServer((req, res) => {
380
+ void handle(req, res).catch(() => {
381
+ if (!res.headersSent) res.writeHead(500);
382
+ res.end();
383
+ });
384
+ }).listen(4173, "127.0.0.1");
385
+ ```
386
+
387
+ 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.
388
+
389
+ 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.
390
+
391
+ ### Optional relay session storage
392
+
393
+ `createConnectionRelay({ token, sessionStorage })` accepts an optional asynchronous storage adapter:
394
+
395
+ ```js
396
+ const sessionStorage = {
397
+ async load() { /* return an array of previously saved session records */ return []; },
398
+ async save(record) { /* durably replace the record identified by record.id */ },
399
+ async delete(id) { /* durably delete this session */ },
400
+ };
401
+ ```
402
+
403
+ An optional `renew(id, { expires, seen })` method can persist a small lease checkpoint without rewriting a large descriptor. Without it, the relay falls back to `save`. Device-only updates stay transient; restoration clears stale device telemetry and issues a fresh update cursor.
404
+
405
+ Omitting the adapter preserves in-memory Node behavior. The relay saves resumable session records when creating connections and updating snapshots; it deletes them on revocation and expiration. Restored records rebuild empty job queues. Storage errors reject the operation. In-flight requests and queued responses are not durable and may fail across restarts.
406
+
407
+ Session records include private capability credentials. Keep storage server-side, preserve records without altering them, and restrict access. The adapter owns its storage format, transactions and retention cleanup. No hosting-provider SDK is required by this interface.
408
+
409
+ ## Troubleshooting
410
+
411
+ - **`studio` is missing:** install the package in the project and run its local executable. Check the Node version.
412
+ - **New state properties are missing:** run `studio discover`, include the type-reference file, then review diagnostics.
413
+ - **Inspection is empty:** verify the manifest matches transformed source and that host adapters/bridges are mounted. Metadata generation alone does not register rendered views.
414
+ - **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.
415
+ - **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.
416
+ - **A published revision is rejected:** validate against the exact installed build's contract rather than the newest contract alone.
417
+
418
+ ## Further reading
419
+
420
+ - [State runtime package](https://github.com/KBismark/studio/blob/main/packages/state/README.md)
421
+ - [Application integration guide](https://github.com/KBismark/studio/blob/main/docs/GETTING_STARTED.md)
422
+ - [State and composition conventions](https://github.com/KBismark/studio/blob/main/docs/STUDIO_STATE.md)
423
+
424
+ This README ships in the npm package. Repository links require access while the source repository remains private.
425
+
426
+ ## License
427
+
428
+ Copyright 2026 Bismark Yamoah.
429
+
430
+ Licensed under the [Apache License, Version 2.0](./LICENSE). This license covers this package. Dependencies retain their respective licenses.