@mizen-labs/cli 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Mizen contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,352 @@
1
- # Temporary Holding Version
1
+ # @mizen-labs/cli
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
+ [CLI documentation](https://ui.mizen-labs.dev/docs/cli/).
4
+
5
+ An unpublished CLI candidate for Mizen. The first commands discover components
6
+ from a bundled snapshot of the same metadata and guidance used by the docs.
7
+ Discovery works offline without reading the consumer project. Doctor reads local
8
+ project metadata and supported setup files. Discovery and doctor do not modify project files. Init previews changes by default;
9
+ only an explicit --yes applies them.
10
+
11
+ ## Run in this workspace
12
+
13
+ ```sh
14
+ pnpm --filter @mizen-labs/cli build
15
+ node packages/cli/dist/cli.js --help
16
+ ```
17
+
18
+ Run these commands from the repository root during development:
19
+
20
+ ```sh
21
+ node packages/cli/dist/cli.js search approval
22
+ node packages/cli/dist/cli.js info button
23
+ node packages/cli/dist/cli.js info diagram --json
24
+ ```
25
+
26
+ ## Try the archive
27
+
28
+ ```sh
29
+ pnpm --filter @mizen-labs/cli pack --out /tmp/mizen-cli.tgz
30
+ # In a consumer project:
31
+ npm install -D /tmp/mizen-cli.tgz
32
+ npx --no-install mizen search forms
33
+ ```
34
+
35
+ Do not use a public `@latest` command yet. No npm release is available.
36
+ Node must satisfy `>=22.18.0 <23 || >=24.11.0`.
37
+
38
+ ## Commands
39
+
40
+ - `mizen search [query]`: match all query words against names, slugs, categories,
41
+ descriptions, and usage guidance. No query lists every component in slug order.
42
+ - `mizen info <component>`: show the documented API, entry point, status, guidance,
43
+ and available contracts or usage examples. Accepts a slug or spaced name.
44
+ - `mizen doctor [--cwd <directory>] [--workspace] [--strict]`: inspect a target application.
45
+ - `mizen init [--cwd <directory>] [--dry-run] [--yes]`: preview or apply setup.
46
+ - `mizen --help` and `mizen --version`: show command help and CLI version.
47
+
48
+ `--json` emits one JSON document to stdout. Human errors go to stderr. JSON errors
49
+ go to stdout, with no additional text on stderr. Exit status remains nonzero.
50
+
51
+ Success envelope:
52
+
53
+ ```json
54
+ {"schemaVersion":1,"command":"info","data":{"uiVersion":"0.1.0","component":{}}}
55
+ ```
56
+
57
+ The empty component above represents the full registry entry. Search data contains
58
+ `query`, `uiVersion`, and `components`. Info data contains `uiVersion` and
59
+ `component`. Component records always include the documented subpath and docs
60
+ route. API sections, contracts, and examples are present only when documented.
61
+ The catalog is bundled at CLI build time; it does not inspect your installed UI.
62
+
63
+ Results print on stdout. With `--json`, an error prints one line on stderr and
64
+ stdout stays empty:
65
+
66
+ ```json
67
+ {"schemaVersion":1,"error":{"reason":"not_found","message":"Couldn't find component buton. Did you mean button?","data":{"suggestion":"button"},"next":[{"argv":["mizen","info","button"],"command":"mizen info button"}]}}
68
+ ```
69
+
70
+ `reason` is stable; `message` is the human headline, so never parse it. `next`
71
+ lists commands that move forward, and `data` holds structured detail such as a
72
+ suggestion or the doctor diagnostic behind an init conflict.
73
+
74
+ | Exit | Meaning | Reasons |
75
+ | --- | --- | --- |
76
+ | 0 | Success, including an empty search, a plan, and no changes needed | — |
77
+ | 1 | A failure: not found, a conflict, a failed check or install, or a bug | `not_found`, `project_not_found`, `conflict`, `recovery_required`, `internal_error`; doctor and init reports |
78
+ | 2 | Invalid usage or missing input | `unknown_command`, `unknown_option`, `invalid_arguments`, `missing_name` |
79
+
80
+ Use fields and reasons for automation; human wording may change. Schema version
81
+ 1 is a pre-release contract. Breaking changes require a new schema version.
82
+
83
+ ## Verify
84
+
85
+ ```sh
86
+ pnpm --filter @mizen-labs/cli test
87
+ pnpm --filter @mizen-labs/cli lint
88
+ pnpm --filter @mizen-labs/cli typecheck
89
+ ```
90
+
91
+ Tests install the packed archive in a temporary app. They verify catalog parity,
92
+ failure codes, project preservation, and independent execution. Installation may
93
+ need network access for declared dependencies; the installed commands work offline.
94
+
95
+ ```sh
96
+ MIZEN_PACKED_CONSUMER=1 pnpm --filter @mizen-labs/cli test
97
+ ```
98
+
99
+ The opt-in checkpoint installs the packed UI into the Next.js and TanStack Start
100
+ fixtures, then runs strict doctor checks. The separate production/browser checkpoint
101
+ also covers plain React + Vite in JSX and TSX.
102
+
103
+
104
+ ## Doctor
105
+
106
+ ```sh
107
+ node packages/cli/dist/cli.js doctor --cwd apps/my-app
108
+ node packages/cli/dist/cli.js doctor --cwd apps/my-app --strict --json
109
+ ```
110
+
111
+ Doctor finds the nearest app manifest. Without `--workspace`, workspace roots require
112
+ an explicit app path. It reports the installed framework version, Node and React peer compatibility,
113
+ React/ReactDOM version agreement, module identity, package-manager lockfiles and
114
+ packageManager declarations, and supported setup declarations.
115
+
116
+ Configuration and source are parsed, never imported or executed. The first syntax
117
+ checks cover Next App Router roots, TanStack Start roots, and React/Vite client entries. They inspect literal configuration,
118
+ simple unmodified configuration bindings, and Vite defineConfig object arguments.
119
+ Custom wrappers, computed settings, indirect stylesheet pipelines, and delegated
120
+ providers can remain unverified. A passing syntax check describes a declaration;
121
+ it does not prove runtime delivery, hydration, or first-paint behavior.
122
+
123
+ The report contains `project`, `status`, `summary`, and ordered `diagnostics`.
124
+ Each diagnostic has a stable `id`, `status` (`pass`, `error`, or `unverified`),
125
+ `message`, evidence paths, and repair guidance when needed. Reports can also include
126
+ `framework` and `uiVersion` after target discovery.
127
+
128
+ Report status is `healthy`, `incomplete`, or `failed`. Confirmed errors exit 1.
129
+ Unverified checks exit 0 by default; `--strict` makes them exit 1. Doctor still emits
130
+ a complete report with `command: "doctor"`, rather than an error envelope. Unsupported
131
+ or custom setups receive explicit limitations and manual review steps.
132
+
133
+ ### Workspace reports
134
+
135
+ ```sh
136
+ mizen doctor --workspace --cwd .
137
+ mizen doctor --workspace --cwd . --strict --json
138
+ ```
139
+
140
+ Workspace discovery starts at `--cwd` and finds the nearest ancestor declaration.
141
+ It supports npm `workspaces` arrays or package lists and `pnpm-workspace.yaml`.
142
+ The pnpm declaration takes precedence. Conflicting declarations remain unverified.
143
+ The root package is included. An omitted pnpm package list selects only the root.
144
+
145
+ Each supported Next.js, TanStack Start, or React/Vite app gets its own report.
146
+ Libraries are listed with skip reasons. Malformed manifests do not stop other apps.
147
+ Unsupported or ambiguous apps, linked directories, and patterns outside the root
148
+ remain unverified. Discovery reads files without invoking managers or repository hooks.
149
+ Inspect external or linked apps explicitly with `--cwd` without `--workspace`.
150
+
151
+ Workspace JSON adds `workspace`, `apps`, and `skipped` to the doctor payload.
152
+ The flat diagnostics include each app's `project`; summary counts cover that flat list.
153
+ No detected apps produces an incomplete report. Existing exit codes and `--strict`
154
+ behavior apply. `init` still requires one explicit application target.
155
+
156
+
157
+ Doctor and init load their syntax and HTML parsers only when requested. Discovery keeps
158
+ its existing startup path. This adds runtime dependencies to support accurate
159
+ checks; the CLI no longer has a zero-dependency claim.
160
+
161
+
162
+ ## Init
163
+
164
+ Init configures an existing Next.js App Router, TanStack Start, or plain React + Vite application.
165
+ Install the framework and matching React/ReactDOM versions first. It does not
166
+ create an application, select a font, or replace existing document defaults.
167
+
168
+ Until publication, pack a matching UI archive from this repository:
169
+
170
+ ```sh
171
+ pnpm --filter @mizen-labs/ui pack --out /tmp/mizen-ui.tgz
172
+ node packages/cli/dist/cli.js init --cwd /path/to/app --package /tmp/mizen-ui.tgz --dry-run
173
+ node packages/cli/dist/cli.js init --cwd /path/to/app --package /tmp/mizen-ui.tgz --yes
174
+ ```
175
+
176
+ An installed, declared Mizen package matching the CLI catalog needs no `--package`.
177
+ Archives must contain `@mizen-labs/ui` at the catalog version. Init inspects the archive
178
+ without extracting it and records its SHA-256 for a check before application.
179
+ The current reader bounds archive size at 50 MB and manifest size at 1 MB.
180
+
181
+ The default command returns a plan without applying it. `--dry-run` also prevents
182
+ application when combined with `--yes`. Nothing prompts in unattended runs.
183
+ `--json` emits one versioned document, including the exact source changes, unified
184
+ diffs, and the dependency command. `--yes` accepts that generated plan; it cannot
185
+ bypass a conflict. Source previews can contain local application code.
186
+
187
+ Supported dependency writes use npm or pnpm. Lockfiles and packageManager declarations
188
+ must agree. With no lockfile or declaration, pass `--package-manager npm` or
189
+ `--package-manager pnpm`. Yarn and Bun remain diagnostic-only until their write paths
190
+ have equivalent evidence. Dependency installation skips lifecycle scripts and retains
191
+ development tools even under NODE_ENV=production. Package-manager resolution can
192
+ change package.json, lockfiles, and node_modules; their exact resulting diffs cannot
193
+ be known before installation. Source diffs are determined in advance.
194
+
195
+ Add `--feature diagram` to install the archive's optional Pele peer. Other optional
196
+ integrations are not installed speculatively. Existing incompatible peers require
197
+ manual resolution; init does not replace React or choose an upgrade policy.
198
+
199
+ Init uses syntax ranges to add stylesheet imports, default theme bootstrap, hydration
200
+ warning handling, and the required bundling entry. Existing comments, directives,
201
+ provider aliases, metadata, fonts, and unrelated settings remain intact. The first
202
+ write path supports literal configuration and conventional root functions. Wrapped
203
+ exports, namespace theme composition, shadowed theme imports, computed head links,
204
+ and conflicting theme placement require manual setup. The command stops before
205
+ installing dependencies when those source conflicts are detected.
206
+
207
+ After installation, doctor checks dependencies. Source files are staged before
208
+ ordered atomic replacements. Contents are checked again before each replacement.
209
+ A second successful init is a no-op and still runs doctor. Init does not lock external
210
+ editors or provide an atomic transaction across a package manager and several files.
211
+
212
+ Application creates `.mizen-init-journal.json` with POSIX mode `0600`. Windows uses
213
+ the directory's inherited ACL; this mode does not provide owner-only Windows access. It records
214
+ original and proposed source text for recovery and is removed after success or a
215
+ handled installation failure. If installation fails, source files stay unchanged;
216
+ dependency changes may remain. If post-edit verification fails, source edits roll
217
+ back when their contents still match. Rollback refuses to discard detected caller
218
+ changes. An unexpected interruption retains the journal and blocks another init.
219
+ Review its before/after records, restore or finish the recorded source edits, repair
220
+ dependency installation as needed, then remove the journal and rerun doctor.
221
+
222
+ Init JSON data contains `status`, `plan`, `verification`, and `message`. Status is
223
+ `planned`, `unchanged`, `applied`, `install-failed`, or `verification-failed`. Plans
224
+ include the project, framework, source edits, optional install command, original
225
+ manifest text, optional read-only inputs, and UI version. Conflicts use the standard error envelope. Failed
226
+ install/verification reports exit 1 and describe retained dependency changes.
227
+
228
+
229
+ ### Plain React + Vite
230
+
231
+ The same init command supports the default create-vite React JSX and TSX templates.
232
+ It reads index.html, checks its active module entry, then adds the compiled CSS
233
+ import, synchronous initializeTheme call, and ThemeProvider to src/main.jsx or src/main.tsx. Existing StrictMode,
234
+ application providers, CSS imports, and comments stay intact. A provider already
235
+ covering the mounted tree is reused.
236
+
237
+ ```sh
238
+ node packages/cli/dist/cli.js init --cwd /path/to/vite-app --package /tmp/mizen-ui.tgz --dry-run
239
+ node packages/cli/dist/cli.js init --cwd /path/to/vite-app --package /tmp/mizen-ui.tgz --yes
240
+ node packages/cli/dist/cli.js doctor --cwd /path/to/vite-app --strict
241
+ ```
242
+
243
+ initializeTheme from @mizen-labs/ui/theme/initialize applies the initial theme before
244
+ React mounts. It shares root-theme behavior with ThemeProvider; subsequent changes
245
+ belong to the provider. Custom initialization options (storage, storageKey, defaultTheme)
246
+ must match provider options. Init stops for manual review when existing custom props
247
+ have no explicit bootstrap. A stale UI archive without the initializer is rejected;
248
+ rebuild and pack the current UI candidate.
249
+
250
+ This client-only path adds no SSR ThemeScript or ssr.noExternal setting.
251
+ Vite configuration and index.html source stay unchanged. The plan records
252
+ index.html as a read-only input and checks it again before writing source files.
253
+ Plain Vite needs no framework-specific Mizen configuration.
254
+
255
+ The first path recognizes a single index.html module entry at src/main.jsx,
256
+ src/main.tsx, src/main.js, or src/main.ts using top-level
257
+ createRoot(...).render(<App />), including imported aliases and ReactDOM namespaces.
258
+ Custom roots, multiple entry modules, non-JSX rendering, and partial provider
259
+ coverage require manual review. HTML comments and template contents do not count
260
+ as active entries. React SSR frameworks retain their own detection and setup paths.
261
+
262
+ Both JSX/npm and TSX/pnpm consumers pass packed-CLI initialization, repeat invocation,
263
+ production builds, and Chromium checks for the first app-frame theme, theme switching,
264
+ counter interaction, and dialogs. TypeScript consumers also compile strictly.
265
+
266
+ ### Platform and release checks
267
+
268
+ The CI workflow defines the OS/Node matrix.
269
+ `pnpm release:check` at the repository root packs UI and CLI, verifies isolated npm
270
+ and pnpm consumers, and saves archives with checksums and consumer lockfiles.
271
+ It does not publish. Hosted Linux and Windows evidence remains pending until CI runs.
272
+
273
+ Package-manager commands use cross-spawn to resolve Windows `.cmd` shims. Init
274
+ captures installation output synchronously, within its existing two-minute timeout,
275
+ so machine-readable commands still emit one JSON document. No progress events are
276
+ streamed during installation.
277
+
278
+ ### Command help and recovery
279
+
280
+ Each command has its own options, examples, and scope:
281
+
282
+ ```sh
283
+ mizen search --help
284
+ mizen info --help
285
+ mizen doctor --help
286
+ mizen init --help
287
+ mizen init --help --json
288
+ ```
289
+
290
+ Help returns before inspecting the app or installing dependencies, including when
291
+ `--yes` is present. Help and version reporting do not load the catalog, so they
292
+ remain usable if it is missing or damaged. Unknown commands remain usage errors. Options for another
293
+ command and missing arguments explain which help page to use. Global `--help`
294
+ lists commands and common options. JSON help keeps command `help` and data `usage`;
295
+ the usage text now describes the selected command.
296
+
297
+ Failed init verification prints its diagnostic IDs, evidence paths, and repair
298
+ steps. App-target and package-manager conflicts also retain their file evidence
299
+ and recovery instructions. The CLI does not apply a repair automatically. Error
300
+ codes and process exits remain the automation contract; human wording can change.
301
+ Arguments after `--` remain literal, including `--help` and `--json`.
302
+
303
+ ### JSON output schema
304
+
305
+ The package includes a local Draft-07 JSON Schema at
306
+ `@mizen-labs/cli/schema/v1.json`, with identifier `urn:mizen:cli:output:v1`.
307
+ It covers help, version, search, info, doctor, init, and errors. No network request
308
+ is needed to resolve it. For example, in Node with your own validator:
309
+
310
+ ```js
311
+ import Ajv from "ajv";
312
+ import schema from "@mizen-labs/cli/schema/v1.json" with { type: "json" };
313
+
314
+ const validate = new Ajv({ strict: true }).compile(schema);
315
+ const response = JSON.parse(stdout);
316
+ if (!validate(response)) {
317
+ throw new Error(JSON.stringify(validate.errors));
318
+ }
319
+ ```
320
+
321
+ The envelope is fixed. Payload objects allow additive fields; known fields keep
322
+ their declared types. `definitions` also provides `HelpOutput`, `VersionOutput`,
323
+ `SearchOutput`, `InfoOutput`, `DoctorOutput`, `InitOutput`, and `ErrorOutput` for
324
+ clients that need a specific command's shape. Component contracts remain open
325
+ objects because the docs define their component-specific content.
326
+
327
+ Validate the complete JSON response and check the process exit separately. Doctor
328
+ failures use a doctor report with exit 1. Init installation/verification failures
329
+ use an init report with exit 1. They do not become error envelopes. Other failures
330
+ use the documented error envelope. Schema version 1 remains a prerelease contract;
331
+ breaking changes require a new schema version.
332
+
333
+ Tests validate actual responses across all documented components, diagnostic
334
+ fixtures, init plans, application, conflicts, and recovery. Archive tests resolve
335
+ the schema through the installed package export. Ajv is a development dependency;
336
+ the CLI runtime does not load a validator or validate its own output on each run.
337
+
338
+ ## Maintainer benchmarks
339
+
340
+ From the repository root:
341
+
342
+ ```sh
343
+ pnpm benchmark:cli
344
+ pnpm benchmark:cli --from /absolute/path/to/saved/cli-benchmark-directory
345
+ ```
346
+
347
+ The harness measures fresh installed CLI processes for help, search, info, and a
348
+ healthy React/Vite doctor target. It records 20 samples per command, first-run and
349
+ warmup timings, package sizes, machine details, hashes, and locked replay inputs.
350
+ Reports live under `artifacts/benchmarks/`. Package CI adds a job summary and
351
+ uploads the reports for each OS/Node pair. Results are informational; no timing
352
+ threshold is enforced.
@@ -0,0 +1 @@
1
+ export {};