openuispec 0.2.3 → 0.2.5

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 (34) hide show
  1. package/README.md +56 -3
  2. package/cli/index.ts +303 -12
  3. package/cli/init.ts +28 -1
  4. package/examples/social-app/AGENTS.md +11 -1
  5. package/examples/social-app/CLAUDE.md +11 -1
  6. package/examples/social-app/generated/android/social-app/app/.paparazzi-hashes.json +3 -0
  7. package/examples/social-app/generated/android/social-app/app/build.gradle.kts +2 -0
  8. package/examples/social-app/generated/android/social-app/app/src/main/java/com/social/app/ui/screens/HomeFeedScreen.kt +12 -0
  9. package/examples/social-app/generated/android/social-app/app/src/test/kotlin/com/social/app/screenshots/HomeFeedScreenshotTest.kt +34 -0
  10. package/examples/social-app/generated/android/social-app/build.gradle.kts +1 -0
  11. package/examples/social-app/generated/android/social-app/gradle/libs.versions.toml +2 -0
  12. package/examples/social-app/generated/android/social-app/gradle/wrapper/gradle-wrapper.jar +0 -0
  13. package/examples/social-app/generated/android/social-app/gradlew +239 -16
  14. package/examples/social-app/generated/android/social-app/settings.gradle.kts +4 -0
  15. package/examples/social-app/package.json +5 -4
  16. package/examples/social-app/take-web-screenshots.ts +97 -0
  17. package/examples/taskflow/.codex/config.toml +4 -0
  18. package/examples/taskflow/.mcp.json +10 -0
  19. package/examples/taskflow/AGENTS.md +105 -95
  20. package/examples/taskflow/CLAUDE.md +105 -95
  21. package/examples/todo-orbit/.codex/config.toml +4 -0
  22. package/examples/todo-orbit/.mcp.json +10 -0
  23. package/examples/todo-orbit/AGENTS.md +105 -95
  24. package/examples/todo-orbit/CLAUDE.md +105 -95
  25. package/examples/todo-orbit/generated/ios/Todo Orbit/.screenshot-uitest/Sources/ScreenshotUITest.swift +36 -0
  26. package/examples/todo-orbit/generated/ios/Todo Orbit/TodoOrbit.xcodeproj/project.pbxproj +204 -212
  27. package/examples/todo-orbit/generated/ios/Todo Orbit/project.yml +1 -0
  28. package/mcp-server/index.ts +64 -1
  29. package/mcp-server/screenshot-android.ts +462 -0
  30. package/mcp-server/screenshot-ios.ts +541 -0
  31. package/mcp-server/screenshot-shared.ts +200 -0
  32. package/mcp-server/screenshot.ts +15 -1
  33. package/package.json +3 -2
  34. package/examples/todo-orbit/generated/ios/Todo Orbit/TodoOrbit.xcodeproj/xcshareddata/xcschemes/TodoOrbit.xcscheme +0 -79
@@ -1,25 +1,248 @@
1
1
  #!/bin/sh
2
2
 
3
- # Gradle Wrapper shell script
4
- # This is a minimal wrapper script for Gradle
5
- # It will download the Gradle distribution from the URL specified in gradle-wrapper.properties
6
- # and then execute the Gradle executable.
3
+ #
4
+ # Copyright © 2015 the original authors.
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # https://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ # SPDX-License-Identifier: Apache-2.0
19
+ #
7
20
 
8
- # For more info see https://gradle.org/docs/current/userguide/gradle_wrapper.html
21
+ ##############################################################################
22
+ #
23
+ # Gradle start up script for POSIX generated by Gradle.
24
+ #
25
+ # Important for running:
26
+ #
27
+ # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
28
+ # noncompliant, but you have some other compliant shell such as ksh or
29
+ # bash, then to run this script, type that shell name before the whole
30
+ # command line, like:
31
+ #
32
+ # ksh Gradle
33
+ #
34
+ # Busybox and similar reduced shells will NOT work, because this script
35
+ # requires all of these POSIX shell features:
36
+ # * functions;
37
+ # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
38
+ # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
39
+ # * compound commands having a testable exit status, especially «case»;
40
+ # * various built-in commands including «command», «set», and «ulimit».
41
+ #
42
+ # Important for patching:
43
+ #
44
+ # (2) This script targets any POSIX shell, so it avoids extensions provided
45
+ # by Bash, Ksh, etc; in particular arrays are avoided.
46
+ #
47
+ # The "traditional" practice of packing multiple parameters into a
48
+ # space-separated string is a well documented source of bugs and security
49
+ # problems, so this is (mostly) avoided, by progressively accumulating
50
+ # options in "$@", and eventually passing that to Java.
51
+ #
52
+ # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
53
+ # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
54
+ # see the in-line comments for details.
55
+ #
56
+ # There are tweaks for specific operating systems such as AIX, CygWin,
57
+ # Darwin, MinGW, and NonStop.
58
+ #
59
+ # (3) This script is generated from the Groovy template
60
+ # https://github.com/gradle/gradle/blob/b5fe9efed6cae7b9f2fbdb2d380fb69af16bb752/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
61
+ # within the Gradle project.
62
+ #
63
+ # You can find Gradle at https://github.com/gradle/gradle/.
64
+ #
65
+ ##############################################################################
9
66
 
10
- if [ -f "gradle/wrapper/gradle-wrapper.properties" ]; then
11
- DIST_URL=$(grep distributionUrl gradle/wrapper/gradle-wrapper.properties | cut -d'=' -f2 | sed 's/\\//g')
12
- else
13
- echo "gradle/wrapper/gradle-wrapper.properties not found"
67
+ # Attempt to set APP_HOME
68
+
69
+ # Resolve links: $0 may be a link
70
+ app_path=$0
71
+
72
+ # Need this for daisy-chained symlinks.
73
+ while
74
+ APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
75
+ [ -h "$app_path" ]
76
+ do
77
+ ls=$( ls -ld "$app_path" )
78
+ link=${ls#*' -> '}
79
+ case $link in #(
80
+ /*) app_path=$link ;; #(
81
+ *) app_path=$APP_HOME$link ;;
82
+ esac
83
+ done
84
+
85
+ # This is normally unused
86
+ # shellcheck disable=SC2034
87
+ APP_BASE_NAME=${0##*/}
88
+ # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
89
+ APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
90
+
91
+ # Use the maximum available, or set MAX_FD != -1 to use that value.
92
+ MAX_FD=maximum
93
+
94
+ warn () {
95
+ echo "$*"
96
+ } >&2
97
+
98
+ die () {
99
+ echo
100
+ echo "$*"
101
+ echo
14
102
  exit 1
103
+ } >&2
104
+
105
+ # OS specific support (must be 'true' or 'false').
106
+ cygwin=false
107
+ msys=false
108
+ darwin=false
109
+ nonstop=false
110
+ case "$( uname )" in #(
111
+ CYGWIN* ) cygwin=true ;; #(
112
+ Darwin* ) darwin=true ;; #(
113
+ MSYS* | MINGW* ) msys=true ;; #(
114
+ NONSTOP* ) nonstop=true ;;
115
+ esac
116
+
117
+
118
+
119
+ # Determine the Java command to use to start the JVM.
120
+ if [ -n "$JAVA_HOME" ] ; then
121
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
122
+ # IBM's JDK on AIX uses strange locations for the executables
123
+ JAVACMD=$JAVA_HOME/jre/sh/java
124
+ else
125
+ JAVACMD=$JAVA_HOME/bin/java
126
+ fi
127
+ if [ ! -x "$JAVACMD" ] ; then
128
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
129
+
130
+ Please set the JAVA_HOME variable in your environment to match the
131
+ location of your Java installation."
132
+ fi
133
+ else
134
+ JAVACMD=java
135
+ if ! command -v java >/dev/null 2>&1
136
+ then
137
+ die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
138
+
139
+ Please set the JAVA_HOME variable in your environment to match the
140
+ location of your Java installation."
141
+ fi
142
+ fi
143
+
144
+ # Increase the maximum file descriptors if we can.
145
+ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
146
+ case $MAX_FD in #(
147
+ max*)
148
+ # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
149
+ # shellcheck disable=SC2039,SC3045
150
+ MAX_FD=$( ulimit -H -n ) ||
151
+ warn "Could not query maximum file descriptor limit"
152
+ esac
153
+ case $MAX_FD in #(
154
+ '' | soft) :;; #(
155
+ *)
156
+ # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
157
+ # shellcheck disable=SC2039,SC3045
158
+ ulimit -n "$MAX_FD" ||
159
+ warn "Could not set maximum file descriptor limit to $MAX_FD"
160
+ esac
161
+ fi
162
+
163
+ # Collect all arguments for the java command, stacking in reverse order:
164
+ # * args from the command line
165
+ # * the main class name
166
+ # * -classpath
167
+ # * -D...appname settings
168
+ # * --module-path (only if needed)
169
+ # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
170
+
171
+ # For Cygwin or MSYS, switch paths to Windows format before running java
172
+ if "$cygwin" || "$msys" ; then
173
+ APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
174
+
175
+ JAVACMD=$( cygpath --unix "$JAVACMD" )
176
+
177
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
178
+ for arg do
179
+ if
180
+ case $arg in #(
181
+ -*) false ;; # don't mess with options #(
182
+ /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
183
+ [ -e "$t" ] ;; #(
184
+ *) false ;;
185
+ esac
186
+ then
187
+ arg=$( cygpath --path --ignore --mixed "$arg" )
188
+ fi
189
+ # Roll the args list around exactly as many times as the number of
190
+ # args, so each arg winds up back in the position where it started, but
191
+ # possibly modified.
192
+ #
193
+ # NB: a `for` loop captures its iteration list before it begins, so
194
+ # changing the positional parameters here affects neither the number of
195
+ # iterations, nor the values presented in `arg`.
196
+ shift # remove old arg
197
+ set -- "$@" "$arg" # push replacement arg
198
+ done
199
+ fi
200
+
201
+
202
+ # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
203
+ DEFAULT_JVM_OPTS='-Dfile.encoding=UTF-8 "-Xmx64m" "-Xms64m"'
204
+
205
+ # Collect all arguments for the java command:
206
+ # * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
207
+ # and any embedded shellness will be escaped.
208
+ # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
209
+ # treated as '${Hostname}' itself on the command line.
210
+
211
+ set -- \
212
+ "-Dorg.gradle.appname=$APP_BASE_NAME" \
213
+ -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
214
+ "$@"
215
+
216
+ # Stop when "xargs" is not available.
217
+ if ! command -v xargs >/dev/null 2>&1
218
+ then
219
+ die "xargs is not available"
15
220
  fi
16
221
 
17
- echo "Downloading Gradle from $DIST_URL if needed..."
18
- # Use gradle's own mechanism if possible, but here we just simulate.
19
- # In a real environment, you would use 'gradle wrapper' to generate these files.
222
+ # Use "xargs" to parse quoted args.
223
+ #
224
+ # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
225
+ #
226
+ # In Bash we could simply go:
227
+ #
228
+ # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
229
+ # set -- "${ARGS[@]}" "$@"
230
+ #
231
+ # but POSIX shell has neither arrays nor command substitution, so instead we
232
+ # post-process each arg (as a line of input to sed) to backslash-escape any
233
+ # character that might be a shell metacharacter, then use eval to reverse
234
+ # that process (while maintaining the separation between arguments), and wrap
235
+ # the whole thing up as a single "set" statement.
236
+ #
237
+ # This will of course break if any of these variables contains a newline or
238
+ # an unmatched quote.
239
+ #
20
240
 
21
- # Since I can't fully emulate the binary gradle-wrapper.jar logic here,
22
- # I'll provide the script and you can run it.
23
- # To actually 'sync' (resolve dependencies), you need the gradle-wrapper.jar as well.
241
+ eval "set -- $(
242
+ printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
243
+ xargs -n1 |
244
+ sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
245
+ tr '\n' ' '
246
+ )" '"$@"'
24
247
 
25
- echo "Warning: gradle-wrapper.jar is required in gradle/wrapper/ directory to run this script."
248
+ exec "$JAVACMD" "$@"
@@ -21,3 +21,7 @@ dependencyResolutionManagement {
21
21
 
22
22
  rootProject.name = "social-app"
23
23
  include(":app")
24
+
25
+
26
+
27
+
@@ -4,9 +4,10 @@
4
4
  "version": "0.0.0",
5
5
  "description": "OpenUISpec test project wired to the local ../openuispec checkout",
6
6
  "scripts": {
7
- "openuispec": "node --import ./../openuispec/node_modules/tsx/dist/loader.mjs ./../openuispec/cli/index.ts",
8
- "validate": "node --import ./../openuispec/node_modules/tsx/dist/loader.mjs ./../openuispec/cli/index.ts validate",
9
- "validate:semantic": "node --import ./../openuispec/node_modules/tsx/dist/loader.mjs ./../openuispec/cli/index.ts validate semantic",
10
- "status": "node --import ./../openuispec/node_modules/tsx/dist/loader.mjs ./../openuispec/cli/index.ts status"
7
+ "openuispec": "node --import ./../../node_modules/tsx/dist/loader.mjs ./../../cli/index.ts",
8
+ "validate": "node --import ./../../node_modules/tsx/dist/loader.mjs ./../../cli/index.ts validate",
9
+ "validate:semantic": "node --import ./../../node_modules/tsx/dist/loader.mjs ./../../cli/index.ts validate semantic",
10
+ "status": "node --import ./../../node_modules/tsx/dist/loader.mjs ./../../cli/index.ts status",
11
+ "screenshots:web": "node --import ./../../node_modules/tsx/dist/loader.mjs ./take-web-screenshots.ts"
11
12
  }
12
13
  }
@@ -0,0 +1,97 @@
1
+ import { mkdirSync, writeFileSync } from "node:fs";
2
+ import { join, resolve } from "node:path";
3
+ import { Client } from "@modelcontextprotocol/sdk/client";
4
+ import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
5
+
6
+ type ImageContent = {
7
+ type: "image";
8
+ data: string;
9
+ mimeType: string;
10
+ };
11
+
12
+ type TextContent = {
13
+ type: "text";
14
+ text: string;
15
+ };
16
+
17
+ type WebCapture = {
18
+ name: string;
19
+ route: string;
20
+ };
21
+
22
+ const OUTPUT_DIR = resolve("generated/web/social-app/screenshots");
23
+ const VIEWPORT = { width: 1366, height: 900 };
24
+ const captures: WebCapture[] = [
25
+ { name: "home", route: "/home" },
26
+ { name: "discover", route: "/discover" },
27
+ { name: "notifications", route: "/notifications" },
28
+ { name: "messages", route: "/messages" },
29
+ { name: "profile", route: "/profile" },
30
+ { name: "profile-edit", route: "/profile/edit" },
31
+ { name: "settings", route: "/settings" },
32
+ { name: "create", route: "/create" },
33
+ { name: "search-editorial-ui-posts", route: "/search?query=Editorial%20UI&tab=posts" },
34
+ { name: "post-post-1", route: "/posts/post-1" },
35
+ { name: "user-lina", route: "/u/user-lina" },
36
+ { name: "chat-conversation-1", route: "/chat/conversation-1" },
37
+ ];
38
+
39
+ function getImageData(content: Array<ImageContent | TextContent>): string {
40
+ const image = content.find((item): item is ImageContent => item.type === "image");
41
+ if (!image) {
42
+ throw new Error("Screenshot tool did not return image data.");
43
+ }
44
+ return image.data;
45
+ }
46
+
47
+ function getText(content: Array<ImageContent | TextContent>): string | null {
48
+ const text = content.find((item): item is TextContent => item.type === "text");
49
+ return text?.text ?? null;
50
+ }
51
+
52
+ async function main() {
53
+ mkdirSync(OUTPUT_DIR, { recursive: true });
54
+
55
+ const transport = new StdioClientTransport({
56
+ command: "npm",
57
+ args: ["run", "openuispec", "--", "mcp"],
58
+ cwd: process.cwd(),
59
+ stderr: "inherit",
60
+ });
61
+
62
+ const client = new Client(
63
+ { name: "social-app-screenshot-runner", version: "0.1.0" },
64
+ { capabilities: {} },
65
+ );
66
+
67
+ await client.connect(transport);
68
+
69
+ try {
70
+ for (const capture of captures) {
71
+ const result = await client.callTool({
72
+ name: "openuispec_screenshot",
73
+ arguments: {
74
+ route: capture.route,
75
+ viewport: VIEWPORT,
76
+ wait_for: 1200,
77
+ full_page: true,
78
+ },
79
+ });
80
+
81
+ if (result.isError) {
82
+ throw new Error(`Failed to capture ${capture.route}: ${getText(result.content as Array<ImageContent | TextContent>) ?? "Unknown tool error"}`);
83
+ }
84
+
85
+ const outputPath = join(OUTPUT_DIR, `${capture.name}.png`);
86
+ writeFileSync(outputPath, Buffer.from(getImageData(result.content as Array<ImageContent | TextContent>), "base64"));
87
+ console.log(`saved ${outputPath}`);
88
+ }
89
+ } finally {
90
+ await transport.close();
91
+ }
92
+ }
93
+
94
+ main().catch((error) => {
95
+ console.error(error instanceof Error ? error.message : error);
96
+ process.exitCode = 1;
97
+ });
@@ -0,0 +1,4 @@
1
+
2
+ [mcp_servers.openuispec]
3
+ command = "openuispec"
4
+ args = ["mcp"]
@@ -0,0 +1,10 @@
1
+ {
2
+ "mcpServers": {
3
+ "openuispec": {
4
+ "command": "openuispec",
5
+ "args": [
6
+ "mcp"
7
+ ]
8
+ }
9
+ }
10
+ }
@@ -1,114 +1,124 @@
1
1
  <!-- openuispec-rules-start -->
2
- <!-- openuispec-rules-version: 0.1.29 -->
2
+ <!-- openuispec-rules-version: 0.2.4 -->
3
3
  # OpenUISpec — AI Assistant Rules
4
4
  # ================================
5
5
  # This project uses OpenUISpec to define UI as a semantic spec.
6
6
  # Spec files are the single source of truth for all UI across platforms.
7
7
  # Targets: "ios", "android", "web"
8
8
 
9
- ## IMPORTANTRead the specification before working with spec files
9
+ ## MANDATORYUI work requires OpenUISpec tools
10
+
11
+ When the user's request involves UI — screens, navigation, layout, tokens, flows, localization,
12
+ or any visual/structural change — you MUST use the OpenUISpec tools before writing any code.
13
+
14
+ ### MCP Tools (use these when available)
15
+
16
+ Call these MCP tools directly. They return structured JSON with everything you need.
17
+
18
+ **Pre-generation:**
19
+ 1. Call `openuispec_prepare` with the target platform — returns spec context, platform config, constraints.
20
+ 2. Call `openuispec_read_specs` to load spec file contents. Use these as the AUTHORITATIVE source.
21
+ 3. If spec changes are needed, update spec files FIRST, then call `openuispec_check`.
22
+ 4. Generate or update the platform UI code based on the spec contents.
23
+
24
+ **Post-generation (EVERY TIME after writing UI code):**
25
+ 5. Call `openuispec_check` to validate spec integrity.
26
+ 6. Call `openuispec_read_specs` for the screens/contracts you just generated code for.
27
+ 7. Audit your generated code against the spec. For each screen, verify:
28
+ - Every field/action in the spec has a corresponding UI element
29
+ - Token values (colors, spacing, radii) match exactly — no approximations
30
+ - Contract `must_handle` states are all implemented (loading, error, empty, etc.)
31
+ - Adaptive breakpoints match the spec's `size_classes`
32
+ - Locale keys match `$t:` references
33
+ - Navigation targets match flow definitions
34
+ 8. Report any real gaps found and fix them before finishing.
35
+
36
+ **Creating new spec files:**
37
+ - Call `openuispec_spec_types` to discover available spec types.
38
+ - Call `openuispec_spec_schema` with the specific type to get the full JSON schema.
39
+ - Write the spec file following the schema exactly.
40
+
41
+ **Focused getters (prefer these for incremental edits over `read_specs`):**
42
+ - `openuispec_get_screen(name)` — single screen spec
43
+ - `openuispec_get_contract(name, variant?)` — single contract, optionally one variant
44
+ - `openuispec_get_tokens(category)` — single token category (color, typography, spacing, etc.)
45
+ - `openuispec_get_locale(locale, keys?)` — single locale file, optionally filtered keys
46
+ - `openuispec_check(target, screens?, contracts?)` — scoped audit for specific screens/contracts
47
+
48
+ Use `read_specs` for full-project generation; use focused getters when editing one screen or contract.
49
+
50
+ **Other tools:**
51
+ - `openuispec_status` — cross-target summary, good starting point
52
+ - `openuispec_drift` with `explain: true` — property-level spec changes
53
+ - `openuispec_validate` — schema-only validation by group
54
+
55
+ ### CLI fallback (when MCP is not available)
56
+
57
+ If MCP tools are not available, use these CLI commands with `--json` flag:
58
+ - `openuispec prepare --target <t> --json` — build AI-ready work bundle
59
+ - `openuispec check --target <t> --json` — composite validation
60
+ - `openuispec status --json` — cross-target status
61
+ - `openuispec drift --target <t> --explain --json` — semantic drift
62
+ - `openuispec validate [group...] --json` — schema validation
63
+ - `openuispec read-specs [paths...]` — read spec file contents
64
+ - `openuispec get-screen <name>` — get a single screen spec
65
+ - `openuispec get-contract <name> [--variant v]` — get a contract spec
66
+ - `openuispec get-tokens <category>` — get tokens for a category
67
+ - `openuispec get-locale <locale> [--keys k1,k2]` — get a locale file
68
+ - `openuispec spec-types` — list available spec types
69
+ - `openuispec spec-schema <type>` — get JSON schema for a spec type
70
+ - `openuispec screenshot --route /path` — screenshot the web app
71
+ - `openuispec screenshot-android [--project-dir path]` — screenshot Android app
72
+ - `openuispec screenshot-ios [--project-dir path]` — screenshot iOS app
73
+
74
+ ### Other CLI commands
75
+ - `openuispec init` — scaffold a new spec project
76
+ - `openuispec drift --snapshot --target <t>` — snapshot current state (only after UI code is updated)
77
+ - `openuispec configure-target <t>` — configure target platform stack
78
+ - `openuispec update-rules` — update AI rules to match installed package version
79
+
80
+ ## Spec format reference
10
81
 
11
- The spec format, file schemas, and generation rules are defined in the installed `openuispec` package.
12
- You MUST read the reference files listed below before creating, editing, or generating from any spec file.
13
- Do NOT guess the file format — skipping this step will produce invalid YAML that fails validation.
82
+ The spec format, schemas, and generation rules are in the installed `openuispec` package.
83
+ You MUST read the reference files before creating or editing spec files do NOT guess the format.
14
84
 
15
- **Find the package in this order:**
16
- 1. `node_modules/openuispec/` (project dependency)
17
- 2. Run `npm root -g` → `<prefix>/openuispec/` (global install)
18
- 3. Online: `https://openuispec.rsteam.uz/llms-full.txt` (if not installed)
85
+ **Find the package:** `node_modules/openuispec/` or run `npm root -g` → `<prefix>/openuispec/`.
86
+ **Online fallback:** `https://openuispec.rsteam.uz/llms-full.txt`
19
87
 
20
- **Reference files inside the package (read in this order):**
21
- 1. `README.md` — schema tables, file format reference, root wrapper keys
22
- 2. `spec/openuispec-v0.1.md` — full specification (contracts, layout, expressions, adaptive, etc.)
23
- 3. `examples/taskflow/openuispec/` — complete working example with all file types
88
+ **Reference files (read in order):**
89
+ 1. `README.md` — schema tables, file format, root wrapper keys
90
+ 2. `spec/openuispec-v0.1.md` — full specification
91
+ 3. `examples/taskflow/openuispec/` — complete working example
24
92
  4. `schema/` — JSON Schemas for every file type
25
93
 
26
- These files are updated with each package version. Always read from the installed package,
27
- not from cached or memorized content, to ensure you use the latest spec.
94
+ ## Spec location
95
+ - Spec root: `openuispec/` read `openuispec/openuispec.yaml` first for actual paths.
96
+ - Default dirs: tokens/, screens/, flows/, contracts/, platform/, locales/
28
97
 
29
- ## What is OpenUISpec
30
- OpenUISpec is a YAML-based spec format that describes an app's UI semantically — tokens, screens, flows, and platform overrides. AI reads the spec and generates native code (SwiftUI, Compose, React). AI reads native code and updates the spec. The spec is the sync layer between platforms.
98
+ ## When to start from spec vs platform code
31
99
 
32
- ## Spec location
33
- - Spec root: `openuispec/`
34
- - Manifest: `openuispec/openuispec.yaml` always read this first.
35
- - Tokens: `openuispec/tokens/`
36
- - Screens: `openuispec/screens/`
37
- - Flows: `openuispec/flows/`
38
- - Contracts: `openuispec/contracts/`
39
- - Platform: `openuispec/platform/`
40
- - Locales: `openuispec/locales/`
100
+ **Spec-first** (use `openuispec_prepare` or `openuispec prepare`):
101
+ - Screen structure, navigation, fields, actions, validation, data binding changes
102
+ - Token, variant, contract, flow, or localization changes
103
+ - Changes affecting multiple platforms
104
+ - Requests in product/UI terms
41
105
 
42
- **Note:** These are the default paths. Actual paths are in `includes:` in `openuispec.yaml` and may use relative paths. Always read `openuispec.yaml` to find the real directories.
106
+ **Platform-first** (skip spec tools):
107
+ - Platform-specific polish (iOS-only, Android-only, web-only)
108
+ - Local bug fixes that don't alter shared semantic behavior
43
109
 
44
110
  ## If spec directories are empty (first-time setup)
45
- This means the project has existing UI code but hasn't been specced yet. Your job:
46
-
47
- 1. **Read the spec first** — find and read `spec/openuispec-v0.1.md` from the installed package.
48
- 2. **Find existing screens** — scan the codebase for UI screen files.
49
- 3. **Create stubs** — for each screen, create `openuispec/screens/<name>.yaml` with:
50
- ```yaml
51
- screen_name:
52
- semantic: "Brief description of what this screen does"
53
- status: stub
54
- layout:
55
- type: scroll_vertical
56
- ```
57
- 4. **Extract tokens** — scan for colors, fonts, spacing and create files in `openuispec/tokens/`.
58
- 5. **Update the manifest** — fill in `data_model`, `api.endpoints`, and `generation.code_roots.backend` in `openuispec/openuispec.yaml`.
59
-
60
- ## OpenUISpec Source Of Truth
61
-
62
- OpenUISpec spec files are the primary source of truth for UI behavior across platforms.
63
-
64
- ### Start from spec when:
65
- - the request changes screen structure
66
- - the request changes navigation
67
- - the request changes fields, actions, validation, or data binding
68
- - the request changes tokens, variants, contracts, flows, or localization
69
- - the request affects more than one platform
70
- - the request is phrased in product/UI terms rather than platform-code terms
71
-
72
- Spec-first workflow:
73
- 1. Read `openuispec/openuispec.yaml` and the relevant spec files first.
74
- 2. Update the spec first.
75
- 3. Update the affected generated/native UI code to match the spec.
76
- 4. Run `openuispec validate`.
77
- 5. Run `openuispec validate semantic`.
78
- 6. Run `openuispec drift --target <target> --explain` to inspect semantic changes since that target's baseline.
79
- 7. Run `openuispec prepare --target <target>` to build the target work bundle for that target. In `bootstrap` mode it provides first-generation constraints; in `update` mode it provides drift-based update scope.
80
- If the target stack was filled from defaults, stop and ask the user to confirm or change it before implementation.
81
- 8. Verify the affected UI targets build/run if possible.
82
- 9. Only then run `openuispec drift --snapshot --target <target>` for affected targets, after that target output directory exists.
83
- 10. Run `openuispec drift --target <target> --explain` again to confirm no spec changes remain for that target.
84
- 11. Use `openuispec status` to see which other targets are still behind the updated spec.
85
-
86
- ### Start from platform code when:
87
- - the change is platform-specific polish
88
- - the change is a local bug fix that does not alter shared semantic behavior
89
- - the request explicitly asks for an iOS-only, Android-only, or web-only adjustment
90
-
91
- Platform-first workflow:
92
- 1. Update native/platform code.
93
- 2. If the change affects shared semantics, sync the spec afterward.
94
- 3. If the change is intentionally platform-specific, document it in `platform/*.yaml` when appropriate.
95
-
96
- ### Never do this:
97
- - Do not snapshot drift immediately after changing spec unless the UI code has also been updated.
98
- - Do not treat `openuispec drift` as proof that generated UI matches the spec.
99
- - Do not skip `--explain` / `prepare` when another platform needs to catch up with shared spec changes.
100
- - Do not modify generated UI without checking whether the spec must change first.
101
- - Do not use `configure-target --defaults` as silent approval for implementation. Ask the user to confirm the stack first.
102
111
 
103
- ## CLI commands
104
- - `openuispec init` scaffold a new spec project
105
- - `openuispec validate [group...]` validate spec files against schemas
106
- - `openuispec validate semantic` run semantic cross-reference linting
107
- - `openuispec drift --target <t>` — check for spec drift
108
- - `openuispec drift --target <t> --explain` explain semantic spec drift since the target baseline
109
- - `openuispec drift --snapshot --target <t>` — snapshot current state after the target output exists
110
- - `openuispec prepare --target <t>` — build the target work bundle and check whether stack confirmation is still pending
111
- - `openuispec status` show cross-target baseline/drift status
112
- - `openuispec update-rules` update AI rules to match installed package version
113
- - `openuispec drift --all` — include stubs in drift check
112
+ Read `spec/openuispec-v0.1.md` from the package first, then:
113
+ 1. Scan codebase for UI screens create `openuispec/screens/<name>.yaml` as `status: stub`
114
+ 2. Extract tokens (colors, fonts, spacing) `openuispec/tokens/`
115
+ 3. Create contract extensions `openuispec/contracts/`
116
+ 4. Create locale files `openuispec/locales/<locale>.json`
117
+ 5. Fill in `data_model`, `api.endpoints` in `openuispec/openuispec.yaml`
118
+
119
+ ## Rules
120
+ - Do not snapshot drift unless the UI code has also been updated.
121
+ - Do not modify generated UI without checking whether the spec must change first.
122
+ - Do not use `configure-target --defaults` as silent approval ask the user to confirm.
123
+ - Always read spec format from the installed package, not from cached/memorized content.
114
124
  <!-- openuispec-rules-end -->