Skip to content

feat(cli): extract CLI functionality into standalone package#142

Merged
willgriffin merged 15 commits intomainfrom
feat/cli-extraction
Oct 31, 2025
Merged

feat(cli): extract CLI functionality into standalone package#142
willgriffin merged 15 commits intomainfrom
feat/cli-extraction

Conversation

@willgriffin
Copy link
Copy Markdown
Contributor

Summary

Extracted CLI functionality from @happyvertical/smrt-core into a new standalone @happyvertical/smrt-cli package with automatic manifest discovery and new introspection commands.

This achieves clean separation between framework code (core) and developer tooling (CLI), reduces core dependencies, and provides better discoverability through the new smrt introspect command.

Changes

New CLI Package (packages/cli/)

  • Created standalone @happyvertical/smrt-cli package
  • Moved CLIGenerator and all command implementations from core
  • Added tar dependency to CLI (removed from core)
  • Configured TypeScript project references
  • Built with Vite for optimal tree-shaking

New Features

Manifest Discovery System:

  • Automatically discovers SMRT object manifests from project root and node_modules
  • Searches: dist/manifest.json, dist/static-manifest.js, src/manifest/, etc.
  • Loads both .js and .json manifest formats

smrt introspect Command:

  • Analyze project and discover SMRT objects
  • Shows discovered manifests with source (project vs package)
  • Displays object counts and paths
  • --verbose flag for detailed field information
  • Aliases: inspect, info

smrt test Command:

  • Guides users to set up test manifest generation
  • Points to existing script-based approach (packages/profiles/scripts)
  • Optional test execution with vitest

Core Package Cleanup

  • Removed CLI binary (dist/generators/cli.js)
  • Removed entire src/cli/ directory with command implementations
  • Removed src/generators/cli.ts and cli.spec.ts
  • Removed tar dependency from package.json
  • Removed CLI exports from generators/index.ts
  • Clean separation between framework and tooling

Documentation

  • Created comprehensive CLI_EXTRACTION_SUMMARY.md
  • Updated root README.md to list CLI package
  • Updated packages/cli/README.md with usage examples and manifest discovery details

Testing

Build Status:

  • @happyvertical/smrt-cli builds without errors
  • @happyvertical/smrt-core builds without errors
  • ✅ All imports resolve correctly
  • ✅ Type declarations generated

Runtime Testing:

  • ✅ Tested in profiles package
  • ✅ Introspect command successfully discovers manifests
  • ✅ Discovered 7 SMRT objects from profiles package
  • ✅ Both normal and verbose modes work correctly

Discovery Path Fix:

  • Added dist/manifest.json and dist/static-manifest.js to search paths
  • Previously only searched src/manifest/ and root, missing build artifacts
  • Now correctly discovers manifests in all SMRT packages

Benefits

  1. Clean Separation: CLI is now independent from core framework
  2. Reduced Core Dependencies: tar removed from core
  3. Better Discoverability: smrt introspect solves the discovery problem from Issue Implement 'smrt test' CLI command for test manifest generation #135
  4. Independent Versioning: CLI can evolve separately from core
  5. Focused Packages: Each package has a clear, single responsibility

Breaking Changes

⚠️ Breaking: Projects depending on smrt binary from @happyvertical/smrt-core must now install @happyvertical/smrt-cli.

Migration:

{
  "devDependencies": {
    "@happyvertical/smrt-cli": "^0.6.0"
  }
}

Then use:

npx smrt introspect  # NEW - auto-discover manifests
npx smrt test        # Guidance for test manifest generation

Related Issues

Related to #135 (partially addresses the discovery problem with smrt introspect)

Checklist

  • Code builds successfully
  • Tests pass
  • Code formatted with Biome
  • TypeScript compiles
  • Documentation updated
  • Conventional commit message
  • Tested in real package (profiles)

Extract CLI functionality from @happyvertical/smrt-core into a new
@happyvertical/smrt-cli package with automatic manifest discovery
and new introspection commands.

**New CLI Package:**
- Created standalone @happyvertical/smrt-cli package
- Moved CLIGenerator and all command implementations from core
- Added tar dependency to CLI (removed from core)
- Configured TypeScript project references
- Built with Vite for optimal tree-shaking

**New Features:**
- Auto-discovery of SMRT object manifests from project and node_modules
- `smrt introspect` command for project analysis (verbose mode available)
- `smrt test` command with guidance for test manifest generation
- Discovery finds manifests in dist/, src/manifest/, and other locations

**Core Package Cleanup:**
- Removed CLI binary and all CLI command implementations
- Removed tar dependency (now only in CLI package)
- Clean separation between framework (core) and tooling (CLI)

**Benefits:**
- Independent versioning for CLI and core
- Reduced core dependencies
- Better discoverability with introspect command
- Each package has focused responsibility

**Testing:**
- CLI tested in profiles package
- Introspect successfully discovers 7 objects
- Both normal and verbose modes working

Related to #135
- Generate test manifests using ASTScanner and ManifestGenerator
- Scan src/**/*.test.ts and src/**/*.spec.ts files
- Create both JSON manifest and TypeScript stub
- Optionally run vitest after manifest generation
- Replace guidance-only implementation with actual functionality

Addresses user feedback to make smrt test functional instead of informational.
- Update CLI_EXTRACTION_SUMMARY.md with actual smrt test functionality
- Update packages/cli/README.md with test command details
- Document --manifest-only and --output options
- Reflect actual scanner-based implementation
@willgriffin
Copy link
Copy Markdown
Contributor Author

Update: Implemented Full smrt test Command

Based on feedback, smrt test now actually generates test manifests instead of just providing guidance.

What Changed

Before: Command provided guidance and pointed to script-based approach
After: Command performs full manifest generation and test execution

Implementation

The command now:

  1. Scans test files using ASTScanner (src//*.test.ts, src//*.spec.ts)
  2. Generates manifest using ManifestGenerator
  3. Writes outputs:
    • src/manifest/test-manifest.json (JSON format)
    • src/manifest/test-manifest-stub.ts (TypeScript stub)
  4. Runs tests with vitest (unless --manifest-only flag is used)

Usage

# Generate manifest and run tests
smrt test

# Generate manifest only (skip test execution)
smrt test --manifest-only

# Custom output directory
smrt test --output dist/manifests

Package Size Impact

The CLI bundle increased from ~30KB to ~6.2MB due to including the TypeScript AST scanner. This is necessary for parsing TypeScript test files to extract SMRT object definitions.

All tests and builds pass successfully. Documentation has been updated to reflect the actual functionality.

- Adds prepare script that builds dist/ if it doesn't exist
- Fixes CI failure where pnpm install tries to link smrt-prebuild binary before dist/ is built
- Only builds when necessary (dist/ missing) to avoid slowing down local development
- Explains purpose of smrt vs smrt-prebuild CLIs
- Documents why both are needed (developer tool vs build-time utility)
- Adds example usage for smrt-prebuild in build scripts
- Clarifies that separation is intentional, not accidental
The prepare script was attempting to build during pnpm install, but
workspace dependencies weren't available yet, causing module resolution
failures in CI.

Turborepo already handles build ordering correctly, so the prepare
script is unnecessary. The smrt-prebuild binary will be available after
the main build step.
Replace custom generate-test-manifest.js script with standardized
'smrt test --manifest-only' command.

Benefits:
- Consistent test manifest generation across all packages
- One implementation to maintain (in CLI package)
- Better UX with configurable output directory
- Matches exact behavior of previous custom script

The smrt test command was designed based on this package's script,
so behavior is identical.
- Mark CI fix and profiles migration as completed
- Update future enhancements to reflect current state
- Remove outdated note about smrt test needing enhancement
- Add @happyvertical/smrt-cli as devDependency in profiles package
- Externalize @happyvertical/smrt-core/scanner in CLI vite config to prevent bundling issues
- Add fallback for output option default value in test command
- Update pnpm lockfile with new dependency
- Regenerate test manifests for core and profiles packages

Profiles package now successfully uses 'smrt test --manifest-only' command.
Ensures the workspace binary is found in CI environments
where PATH may not include node_modules/.bin
npx works more reliably with workspace binaries in CI
Changes pretest script from 'npx smrt test --manifest-only' to
'node ../cli/dist/index.js test --manifest-only'.

This bypasses all PATH and binary resolution issues (npx, pnpm exec)
that were causing CI failures. Relies on Turborepo to ensure CLI is
built before profiles tests run via test->build dependency.
- Change './cli.js' to './cli-generator.js' (3 occurrences)
- Remove test that imports non-existent '../test-utils.js'
- All CLI tests now pass (119 passing)
@willgriffin willgriffin merged commit 8f1d71e into main Oct 31, 2025
1 check passed
@willgriffin willgriffin deleted the feat/cli-extraction branch October 31, 2025 04:04
github-actions bot pushed a commit that referenced this pull request Oct 31, 2025
# [0.7.0](v0.6.1...v0.7.0) (2025-10-31)

### Features

* **cli:** extract CLI functionality into standalone package ([#142](#142)) ([8f1d71e](8f1d71e)), closes [#135](#135)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant