@sanity/runtime-cli 17.7.1-next.g09b9981 → 17.8.0-blueprinit.g0993fa5

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/README.md +26 -21
  2. package/dist/actions/blueprinit/manifest.d.ts +34 -0
  3. package/dist/actions/blueprinit/manifest.js +107 -0
  4. package/dist/actions/blueprinit/studio.d.ts +6 -0
  5. package/dist/actions/blueprinit/studio.js +43 -0
  6. package/dist/actions/blueprinit/templates.d.ts +73 -0
  7. package/dist/actions/blueprinit/templates.js +138 -0
  8. package/dist/actions/blueprinit/workspace.d.ts +24 -0
  9. package/dist/actions/blueprinit/workspace.js +146 -0
  10. package/dist/actions/blueprints/stacks.d.ts +2 -0
  11. package/dist/actions/blueprints/stacks.js +1 -0
  12. package/dist/actions/sanity/datasets.d.ts +15 -0
  13. package/dist/actions/sanity/datasets.js +26 -0
  14. package/dist/actions/sanity/projects.d.ts +11 -0
  15. package/dist/actions/sanity/projects.js +48 -22
  16. package/dist/baseCommands.d.ts +6 -0
  17. package/dist/baseCommands.js +9 -1
  18. package/dist/commands/blueprints/stacks.d.ts +2 -1
  19. package/dist/commands/blueprints/stacks.js +14 -6
  20. package/dist/commands/init.d.ts +20 -0
  21. package/dist/commands/init.js +72 -0
  22. package/dist/constants.d.ts +2 -0
  23. package/dist/constants.js +5 -0
  24. package/dist/cores/blueprinit/adopt.d.ts +6 -0
  25. package/dist/cores/blueprinit/adopt.js +154 -0
  26. package/dist/cores/blueprinit/finish.d.ts +15 -0
  27. package/dist/cores/blueprinit/finish.js +73 -0
  28. package/dist/cores/blueprinit/fresh.d.ts +3 -0
  29. package/dist/cores/blueprinit/fresh.js +173 -0
  30. package/dist/cores/blueprinit/preview.d.ts +24 -0
  31. package/dist/cores/blueprinit/preview.js +97 -0
  32. package/dist/cores/blueprinit/prompts.d.ts +15 -0
  33. package/dist/cores/blueprinit/prompts.js +43 -0
  34. package/dist/cores/blueprinit/selection.d.ts +15 -0
  35. package/dist/cores/blueprinit/selection.js +90 -0
  36. package/dist/cores/blueprinit/stack-name.d.ts +39 -0
  37. package/dist/cores/blueprinit/stack-name.js +56 -0
  38. package/dist/cores/blueprinit/target.d.ts +33 -0
  39. package/dist/cores/blueprinit/target.js +80 -0
  40. package/dist/cores/blueprinit/types.d.ts +18 -0
  41. package/dist/cores/blueprinit/types.js +1 -0
  42. package/dist/cores/blueprinit.d.ts +7 -0
  43. package/dist/cores/blueprinit.js +55 -0
  44. package/dist/cores/blueprints/stacks.d.ts +8 -3
  45. package/dist/cores/blueprints/stacks.js +282 -85
  46. package/dist/cores/functions/test.d.ts +2 -19
  47. package/dist/cores/functions/test.js +55 -111
  48. package/dist/server/app.js +4 -6
  49. package/dist/server/static/components/payload-panel.js +1 -1
  50. package/dist/utils/display/intro.d.ts +6 -0
  51. package/dist/utils/display/intro.js +63 -0
  52. package/dist/utils/display/prompt.d.ts +4 -1
  53. package/dist/utils/display/prompt.js +16 -2
  54. package/dist/utils/external/npmjs.d.ts +7 -0
  55. package/dist/utils/external/npmjs.js +10 -0
  56. package/dist/utils/functions/child-process-wrapper.js +18 -6
  57. package/dist/utils/functions/child-runtime/durable.d.ts +18 -0
  58. package/dist/utils/functions/child-runtime/durable.js +46 -0
  59. package/dist/utils/functions/invoke/local.js +26 -9
  60. package/dist/utils/functions/invoke/resolve-invoke-type.d.ts +51 -0
  61. package/dist/utils/functions/invoke/resolve-invoke-type.js +131 -0
  62. package/dist/utils/progress.js +6 -3
  63. package/dist/utils/types.d.ts +46 -2
  64. package/oclif.manifest.json +155 -5
  65. package/package.json +1 -1
  66. package/skills/blueprints-stacks.md +14 -2
  67. package/skills/init.md +170 -0
@@ -14,7 +14,7 @@ export interface ActionResponse {
14
14
  error: string | null;
15
15
  }
16
16
  /** @internal */
17
- export type FunctionGroqResource = BlueprintDocumentFunctionResource | BlueprintMediaLibraryAssetFunctionResource;
17
+ export type FunctionGroqResource = BlueprintDocumentFunctionResource | BlueprintMediaLibraryAssetFunctionResource | BlueprintDurableFunctionResource;
18
18
  export type FunctionResource = FunctionGroqResource | BlueprintPubSubFunctionResource | BlueprintScheduledFunctionResource | BlueprintSyncTagInvalidateFunctionResource | BlueprintDurableFunctionResource;
19
19
  /** Function resources that declare an `event`; PubSub functions are triggered by other functions */
20
20
  export type EventFunctionResource = Exclude<FunctionResource, BlueprintPubSubFunctionResource>;
@@ -111,7 +111,7 @@ export interface InvokeNonGroqPayloadOptions {
111
111
  export type InvokePayloadOptions = InvokeGroqPayloadOptions | InvokeNonGroqPayloadOptions;
112
112
  export type InvokePayloadMetadata = Pick<InvokeGroqPayloadOptions, 'event' | 'before' | 'after'> | Pick<InvokeNonGroqPayloadOptions, 'event'>;
113
113
  export type EventType = 'create' | 'update' | 'delete';
114
- export type NonGroqEventType = 'scheduled' | 'nested';
114
+ export type NonGroqEventType = 'plain' | 'nested' | 'durable';
115
115
  export declare function isEventType(arg: string): arg is EventType;
116
116
  /** @internal */
117
117
  export interface InvokeGroqContextOptions {
@@ -161,6 +161,8 @@ export interface InvokeExecutionOptions {
161
161
  depth?: number;
162
162
  /** Function names already on the invoke call stack (innermost last), used to detect cycles. @internal */
163
163
  callStack?: string[];
164
+ /** Stream a durable step transition to the caller. @internal */
165
+ onStepEvent?: (event: DurableStepEvent) => void;
164
166
  }
165
167
  /**
166
168
  * Re-entrant callback that executes a named function from the blueprint on behalf
@@ -178,6 +180,7 @@ export type ParentToChildMessage = {
178
180
  type: 'start';
179
181
  srcPath: string;
180
182
  payload: unknown;
183
+ isDurable?: boolean;
181
184
  } | {
182
185
  type: 'invoke-response';
183
186
  id: string;
@@ -190,6 +193,9 @@ export type ParentToChildMessage = {
190
193
  id: string;
191
194
  ok: false;
192
195
  error: InvocationError;
196
+ } | {
197
+ type: 'step-event';
198
+ event: DurableStepEvent;
193
199
  };
194
200
  /**
195
201
  * IPC messages sent from a function child process back up to the parent.
@@ -202,12 +208,16 @@ export type ChildToParentMessage = {
202
208
  id: string;
203
209
  name: string;
204
210
  payload: Record<string, unknown>;
211
+ isDurable?: boolean;
205
212
  } | {
206
213
  type: 'result';
207
214
  json?: JsonInvocationResponse;
208
215
  logs?: string;
209
216
  errorLogs?: string;
210
217
  error?: InvocationError;
218
+ } | {
219
+ type: 'step-event';
220
+ event: DurableStepEvent;
211
221
  };
212
222
  /** @internal */
213
223
  export interface InvocationResponse {
@@ -290,4 +300,38 @@ export type Warning = {
290
300
  code: string;
291
301
  suggestions: string[];
292
302
  };
303
+ /** @internal */
304
+ export type DurableOperationSteps = 'run';
305
+ /** @internal */
306
+ export type DurableStepPhase = 'start' | 'complete' | 'error';
307
+ /**
308
+ * Represents a single step in a durable operation
309
+ */
310
+ export interface DurableStepEvent {
311
+ name: string;
312
+ kind: DurableOperationSteps;
313
+ phase: DurableStepPhase;
314
+ output?: unknown;
315
+ error?: InvocationError;
316
+ durationMs?: number;
317
+ }
318
+ export interface FunctionTestFlags {
319
+ data?: string;
320
+ event?: string;
321
+ file?: string;
322
+ timeout?: number;
323
+ api?: string;
324
+ dataset?: string;
325
+ 'project-id'?: string;
326
+ 'organization-id'?: string;
327
+ 'document-id'?: string;
328
+ 'with-user-token'?: boolean;
329
+ 'data-before'?: string;
330
+ 'data-after'?: string;
331
+ 'file-before'?: string;
332
+ 'file-after'?: string;
333
+ 'document-id-before'?: string;
334
+ 'document-id-after'?: string;
335
+ 'media-library-id'?: string;
336
+ }
293
337
  export {};
@@ -1,5 +1,141 @@
1
1
  {
2
2
  "commands": {
3
+ "init": {
4
+ "aliases": [],
5
+ "args": {
6
+ "directory": {
7
+ "description": "Directory to initialize. Interactive runs are asked for one instead.",
8
+ "name": "directory",
9
+ "required": false
10
+ }
11
+ },
12
+ "description": "Scaffolds a Blueprint, Studio, and starter function around an existing Sanity project.\n\nPass a directory to scaffold into it. Without one, an interactive run asks where the files go.\n\nThis hidden command is an experiment; its interface and generated files are not stable.",
13
+ "examples": [
14
+ "<%= config.bin %> <%= command.id %>",
15
+ "<%= config.bin %> <%= command.id %> ./my-workspace",
16
+ "<%= config.bin %> <%= command.id %> --yes",
17
+ "<%= config.bin %> <%= command.id %> --project-id <id> --dataset <name> --yes"
18
+ ],
19
+ "flags": {
20
+ "json": {
21
+ "description": "Format output as json",
22
+ "name": "json",
23
+ "allowNo": false,
24
+ "type": "boolean"
25
+ },
26
+ "path": {
27
+ "aliases": [
28
+ "blueprint-path"
29
+ ],
30
+ "char": "p",
31
+ "description": "Path to a Blueprint file or directory containing one",
32
+ "env": "SANITY_BLUEPRINT_PATH",
33
+ "hidden": true,
34
+ "name": "path",
35
+ "hasDynamicHelp": false,
36
+ "multiple": false,
37
+ "type": "option"
38
+ },
39
+ "trace": {
40
+ "description": "Trace output",
41
+ "hidden": true,
42
+ "name": "trace",
43
+ "allowNo": false,
44
+ "type": "boolean"
45
+ },
46
+ "validate-resources": {
47
+ "description": "Validate resources",
48
+ "hidden": true,
49
+ "name": "validate-resources",
50
+ "allowNo": true,
51
+ "type": "boolean"
52
+ },
53
+ "verbose": {
54
+ "description": "Verbose output",
55
+ "hidden": true,
56
+ "name": "verbose",
57
+ "allowNo": false,
58
+ "type": "boolean"
59
+ },
60
+ "llms": {
61
+ "aliases": [
62
+ "skill"
63
+ ],
64
+ "description": "Show agent-oriented guidance for this command",
65
+ "hidden": true,
66
+ "name": "llms",
67
+ "allowNo": false,
68
+ "type": "boolean"
69
+ },
70
+ "yes": {
71
+ "char": "y",
72
+ "description": "Skip confirmation prompts",
73
+ "name": "yes",
74
+ "allowNo": false,
75
+ "type": "boolean"
76
+ },
77
+ "organization-id": {
78
+ "aliases": [
79
+ "organization",
80
+ "organizationId",
81
+ "org"
82
+ ],
83
+ "description": "Organization to use when the account has several",
84
+ "name": "organization-id",
85
+ "hasDynamicHelp": false,
86
+ "multiple": false,
87
+ "type": "option"
88
+ },
89
+ "project-id": {
90
+ "aliases": [
91
+ "project",
92
+ "projectId"
93
+ ],
94
+ "description": "Project to use when the organization has several",
95
+ "name": "project-id",
96
+ "hasDynamicHelp": false,
97
+ "multiple": false,
98
+ "type": "option"
99
+ },
100
+ "dataset": {
101
+ "description": "Dataset to attach",
102
+ "name": "dataset",
103
+ "hasDynamicHelp": false,
104
+ "multiple": false,
105
+ "type": "option"
106
+ },
107
+ "stack-name": {
108
+ "description": "Name for the new organization-scoped Stack, and the hosted Studio slug",
109
+ "name": "stack-name",
110
+ "hasDynamicHelp": false,
111
+ "multiple": false,
112
+ "type": "option"
113
+ },
114
+ "studio-name": {
115
+ "description": "Blueprint-local name for the Studio resource and its directory",
116
+ "name": "studio-name",
117
+ "hasDynamicHelp": false,
118
+ "multiple": false,
119
+ "type": "option"
120
+ }
121
+ },
122
+ "hasDynamicHelp": false,
123
+ "hidden": true,
124
+ "hiddenAliases": [],
125
+ "id": "init",
126
+ "pluginAlias": "@sanity/runtime-cli",
127
+ "pluginName": "@sanity/runtime-cli",
128
+ "pluginType": "core",
129
+ "strict": true,
130
+ "summary": "Experimental blueprints-first project init",
131
+ "enableJsonFlag": true,
132
+ "isESM": true,
133
+ "relativePath": [
134
+ "dist",
135
+ "commands",
136
+ "init.js"
137
+ ]
138
+ },
3
139
  "blueprints:add": {
4
140
  "aliases": [],
5
141
  "args": {
@@ -1556,9 +1692,10 @@
1556
1692
  "blueprints:stacks": {
1557
1693
  "aliases": [],
1558
1694
  "args": {},
1559
- "description": "Shows all Stacks associated with a project or organization. By default, lists Stacks scoped to the local Blueprint.\n\nUse this to discover existing Stacks you can scope a local Blueprint to (using 'blueprints config --edit'), or to audit what's deployed across your project.\n\nUse --include-projects with --organization-id to also list Stacks from all projects within the organization.",
1695
+ "description": "Shows all Stacks associated with a project or organization. By default, lists Stacks scoped to the local Blueprint.\n\nUse this to discover existing Stacks you can scope a local Blueprint to (using 'blueprints config --edit'), or to audit what's deployed across your project.\n\nWithout a scope, prompts for an organization or project. Use --all to list Stacks across every organization and project you can access, or --include-projects with --organization-id for one organization and its projects.",
1560
1696
  "examples": [
1561
1697
  "<%= config.bin %> <%= command.id %>",
1698
+ "<%= config.bin %> <%= command.id %> --all",
1562
1699
  "<%= config.bin %> <%= command.id %> --project-id <projectId>",
1563
1700
  "<%= config.bin %> <%= command.id %> --organization-id <organizationId>",
1564
1701
  "<%= config.bin %> <%= command.id %> --organization-id <organizationId> --include-projects"
@@ -1620,7 +1757,8 @@
1620
1757
  "description": "Sanity project ID used to scope Blueprint and Stack",
1621
1758
  "exclusive": [
1622
1759
  "organization-id",
1623
- "include-projects"
1760
+ "include-projects",
1761
+ "all"
1624
1762
  ],
1625
1763
  "name": "project-id",
1626
1764
  "hasDynamicHelp": false,
@@ -1635,7 +1773,8 @@
1635
1773
  ],
1636
1774
  "description": "Sanity organization ID used to scope Blueprint and Stack",
1637
1775
  "exclusive": [
1638
- "project-id"
1776
+ "project-id",
1777
+ "all"
1639
1778
  ],
1640
1779
  "name": "organization-id",
1641
1780
  "hasDynamicHelp": false,
@@ -1650,6 +1789,17 @@
1650
1789
  "name": "include-projects",
1651
1790
  "allowNo": false,
1652
1791
  "type": "boolean"
1792
+ },
1793
+ "all": {
1794
+ "description": "List Stacks from every organization and project you have access to",
1795
+ "exclusive": [
1796
+ "project-id",
1797
+ "organization-id",
1798
+ "include-projects"
1799
+ ],
1800
+ "name": "all",
1801
+ "allowNo": false,
1802
+ "type": "boolean"
1653
1803
  }
1654
1804
  },
1655
1805
  "hasDynamicHelp": false,
@@ -1662,7 +1812,7 @@
1662
1812
  "summary": "List remote Stack deployments for your project or organization",
1663
1813
  "enableJsonFlag": true,
1664
1814
  "needs": [
1665
- "scope"
1815
+ "token"
1666
1816
  ],
1667
1817
  "isESM": true,
1668
1818
  "relativePath": [
@@ -3127,5 +3277,5 @@
3127
3277
  ]
3128
3278
  }
3129
3279
  },
3130
- "version": "17.7.1-next.g09b9981"
3280
+ "version": "17.8.0-blueprinit.g0993fa5"
3131
3281
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sanity/runtime-cli",
3
3
  "description": "Sanity's Runtime CLI for Blueprints and Functions",
4
- "version": "17.7.1-next.g09b9981",
4
+ "version": "17.8.0-blueprinit.g0993fa5",
5
5
  "author": "Sanity Runtime Team",
6
6
  "type": "module",
7
7
  "license": "MIT",
@@ -17,7 +17,9 @@ npx @sanity/cli blueprints stacks --project-id PROJECT_ID --json
17
17
  npx @sanity/cli blueprints stacks --organization-id ORGANIZATION_ID --json
18
18
  ```
19
19
 
20
- The JSON result contains `stacks`, `scopeType`, and `scopeId`; each entry carries `resourceCount` rather than a full `resources` array. Zero results prints `No stacks found` and emits no JSON. Match both the Stack and its scope; names alone may be ambiguous.
20
+ Always pass a scope flag or `--all` when automating. With no scope to resolve the command prompts for an organization, then for a project if you pick project scope; without a terminal, or with `--json`, it fails with a missing-scope error instead.
21
+
22
+ The JSON result contains `stacks`, `scopeType`, and `scopeId`; each entry carries `resourceCount` rather than a full `resources` array. Zero results prints `No stacks found`, and under `--json` returns an empty `stacks` array. Match both the Stack and its scope; names alone may be ambiguous.
21
23
 
22
24
  To also include Stacks scoped to the organization's projects:
23
25
 
@@ -25,4 +27,14 @@ To also include Stacks scoped to the organization's projects:
25
27
  npx @sanity/cli blueprints stacks --organization-id ORGANIZATION_ID --include-projects --json
26
28
  ```
27
29
 
28
- `--include-projects` requires `--organization-id`, cannot be combined with `--project-id`, and only queries the organization's first 50 projects. This command does not change the local Blueprint target; use `blueprints config --edit` for that.
30
+ `--include-projects` requires `--organization-id`, cannot be combined with `--project-id`, and only queries the organization's first 50 projects.
31
+
32
+ To sweep every organization and project the token can reach:
33
+
34
+ ```sh
35
+ npx @sanity/cli blueprints stacks --all --json
36
+ ```
37
+
38
+ `--all` cannot be combined with the scope flags or `--include-projects`. It is best effort: scopes that return an error are skipped and reported as a count, and only the first 200 projects are queried. Its JSON result contains `stacks` and no top-level `scopeType`/`scopeId`; read each entry's own `scopeType` and `scopeId` instead.
39
+
40
+ This command does not change the local Blueprint target; use `blueprints config --edit` for that.
package/skills/init.md ADDED
@@ -0,0 +1,170 @@
1
+ # init
2
+
3
+ Use `init` to scaffold a Blueprint around an existing Sanity project. The command is
4
+ experimental, hidden from root help, and available from the `blueprinit` npm dist-tag.
5
+
6
+ Use it for demos and evaluation, not as a stable project initializer. Its flags, generated files,
7
+ and resource model may change.
8
+
9
+ ## Know what it does
10
+
11
+ `init` uses an existing Sanity organization, project, and dataset. It writes local Blueprint
12
+ files, then creates an empty organization-scoped Stack. The generated Blueprint attaches the
13
+ project and dataset and declares resources for a later deployment.
14
+
15
+ It does not create an organization, project, or dataset. It does not deploy the attached resources,
16
+ CORS origin, Studio, or Function. Those changes happen only if `blueprints deploy` is run later.
17
+
18
+ ## Inspect the target directory
19
+
20
+ Pass the directory as an argument, or run the command from the directory that should contain the
21
+ Blueprint. Without an argument an interactive run asks where the files go; an unattended run keeps
22
+ the current directory.
23
+
24
+ Before running:
25
+
26
+ 1. Check the working tree and existing files. Do not discard unrelated user changes.
27
+ 2. Look for a root `sanity.blueprint.*` file. If one exists, use the existing Blueprint instead of
28
+ initializing again.
29
+ 3. Look for a root `sanity.config.*` file. Its presence selects the Studio adoption flow.
30
+ 4. Confirm the user asked to initialize this directory. The command writes files and creates a
31
+ remote Stack.
32
+ 5. Confirm the user is signed in. If needed, have them run:
33
+
34
+ ```sh
35
+ npx sanity login
36
+ ```
37
+
38
+ The account must have at least one organization, one project in the selected organization, and one
39
+ dataset in the selected project.
40
+
41
+ Interactive runs show the Blueprint resources, hosted Studio URL, local changes, and remote Stack
42
+ action before the confirmation prompt. Project and dataset attachment plus CORS, Studio, and
43
+ Function creation remain pending until a later deployment.
44
+
45
+ ## Choose the flow
46
+
47
+ - **Existing Blueprint with a configured Stack:** Exit without changes and use
48
+ `blueprints config --edit` or `blueprints doctor`.
49
+ - **Existing Blueprint without a configured Stack:** Finish setup with `blueprints init`; it can
50
+ connect the existing manifest without rewriting it.
51
+ - **Root Studio config:** Adopt the Studio in place. Read literal `projectId` and `dataset` strings
52
+ from `sanity.config.*`, falling back to `sanity.cli.*`. Do not move the Studio.
53
+ - **Fresh workspace:** Create a Blueprint, an npm-workspace Studio, and a starter `set-slug`
54
+ document function.
55
+
56
+ Do not rewrite a Studio config merely to make adoption work unless the user asks. Dynamic
57
+ `projectId` or `dataset` values built from environment variables or imports cannot be detected.
58
+
59
+ For an existing Blueprint, inspect it with:
60
+
61
+ ```sh
62
+ npx @sanity/runtime-cli@blueprinit blueprints doctor
63
+ ```
64
+
65
+ ## Run unattended
66
+
67
+ When the organization and project IDs are known, run this from the target directory:
68
+
69
+ ```sh
70
+ npx @sanity/runtime-cli@blueprinit init --yes \
71
+ --organization-id <organization-id> \
72
+ --project-id <project-id> \
73
+ --dataset <dataset-name>
74
+ ```
75
+
76
+ Replace all placeholders with real values. The project must belong to the organization, and the
77
+ dataset must belong to the project. Do not guess any value.
78
+
79
+ `--yes` skips confirmation. Without explicit values, an unattended run stops when the account has
80
+ several organizations, projects, or datasets. Ask the user for the missing value or have them run
81
+ the command interactively.
82
+
83
+ Use `--stack-name <name>` and `--studio-name <name>` when those generated names need to be stable.
84
+ The command normalizes both names to lowercase kebab case.
85
+
86
+ The Stack name defaults to `<project>-<dataset>` and is also the hosted Studio slug, so it must be
87
+ available across every Sanity organization. No API reports whether a slug is free, so a taken one
88
+ fails during `blueprints deploy`.
89
+
90
+ The Studio name is a Blueprint-local resource name and its directory under `studios/`. It defaults
91
+ to `studio`. Every other generated name carries its resource type, so the defaults cannot collide.
92
+ A dataset named `studio`, or `--studio-name production` against a `production` dataset, does
93
+ collide; the command names the repeated value and writes nothing.
94
+
95
+ When `SANITY_INTERNAL_ENV=staging`, the generated Studio URL and CORS origin use
96
+ `https://<stack-name>.studio.sanity.work`. Other environments use
97
+ `https://<stack-name>.sanity.studio`.
98
+
99
+ For interactive organization, project, dataset, Stack-name, and confirmation prompts, have the
100
+ user run:
101
+
102
+ ```sh
103
+ npx @sanity/runtime-cli@blueprinit init
104
+ ```
105
+
106
+ When the project has several datasets, the interactive command prompts for one and lists
107
+ `production` first. Report the selected dataset from the command output.
108
+
109
+ ## Review the result
110
+
111
+ A successful fresh run creates or updates:
112
+
113
+ ```text
114
+ .
115
+ ├── .sanity/blueprint.config.json
116
+ ├── sanity.blueprint.ts
117
+ ├── package.json
118
+ ├── functions/
119
+ │ └── set-slug/
120
+ └── studios/
121
+ └── studio/
122
+ ```
123
+
124
+ The command also creates or updates `.gitignore`. It preserves existing package metadata and adds
125
+ the required npm workspaces and `@sanity/blueprints` dependency.
126
+
127
+ The generated Studio matches `sanity init`: the same `sanity`, `@sanity/vision`, `react`,
128
+ `react-dom`, `styled-components`, `@types/react`, and `typescript` versions, the same
129
+ `tsconfig.json`, and `visionTool()` beside `structureTool()`. `sanity` and `@sanity/vision` are
130
+ resolved from the registry at scaffold time, so no version is written into this repository.
131
+ The Studio has no `deploy` script, because the Blueprint deploys it.
132
+
133
+ An adopted Studio stays at the repository root. The command adds the Blueprint, Blueprint config,
134
+ dependency, and `.gitignore` entry, but does not generate the starter Function.
135
+
136
+ After the command exits:
137
+
138
+ 1. Confirm the output names the expected organization, project, and dataset.
139
+ 2. Confirm `.sanity/blueprint.config.json` exists. Its presence means Stack creation completed.
140
+ 3. Review `sanity.blueprint.ts`, including the Studio slug and credentialed CORS origin, plus
141
+ `package.json`, `.gitignore`, and the working-tree diff.
142
+ 4. Report the Stack ID and every created or modified path.
143
+
144
+ Do not deploy as part of initialization unless the user separately asks for deployment. To continue
145
+ after reviewing the scaffold, install dependencies and preview the deployment:
146
+
147
+ ```sh
148
+ npm install
149
+ npx @sanity/runtime-cli@blueprinit blueprints plan
150
+ ```
151
+
152
+ Treat dependency installation and planning as separate follow-up actions when they were not part of
153
+ the user's request.
154
+
155
+ ## Handle failures
156
+
157
+ - **`No Sanity session found.`** Stop and ask the user to run `npx sanity login`. Authentication
158
+ fails before files are written.
159
+ - **Multiple organizations or projects found.** Rerun with the matching `--organization-id` and
160
+ `--project-id`. Selection fails before files are written.
161
+ - **No datasets found.** Ask the user to create or choose a project with a dataset. The command does
162
+ not create datasets.
163
+ - **Could not read `projectId` and `dataset`.** The detected Studio config does not contain both
164
+ values as string literals. Pass explicit `--project-id` and `--dataset` values or report the config
165
+ file and let the user decide whether to change it.
166
+ - **Refusing to overwrite an existing path.** Inspect the reported Studio or Function directory.
167
+ Do not delete or replace it without the user's direction.
168
+ - **Stack quota or duplicate-name error.** Local scaffold files may already exist while
169
+ `.sanity/blueprint.config.json` does not. Resolve the Stack error, then run the recovery command
170
+ printed by `init`, which is `blueprints init`. It connects the existing manifest without rewriting it.