Skip to content

emu with a q stuff#1266

Merged
mantrakp04 merged 35 commits intodevfrom
emu-with-a-q
Apr 4, 2026
Merged

emu with a q stuff#1266
mantrakp04 merged 35 commits intodevfrom
emu-with-a-q

Conversation

@mantrakp04
Copy link
Copy Markdown
Collaborator

@mantrakp04 mantrakp04 commented Mar 18, 2026

commit 5d43722575b826a8ed8dbb6b828f48eae4bca02c
Author: mantrakp04 mantrakp@gmail.com
Date: Wed Mar 18 12:27:01 2026 -0700

Add QEMU emulator snapshot functionality and reset command

- Introduced a new `emulator-qemu:reset` command in package.json to clear snapshots and force a fresh boot of the emulator.
- Enhanced the `run-emulator.sh` script to support saving and restoring snapshots, significantly reducing restart time from ~62s to ~4s.
- Implemented logic to check for existing snapshots and restore them during startup, improving the emulator's efficiency.
- Updated documentation in CLAUDE-KNOWLEDGE.md to explain the new snapshot restore process and its benefits.

These changes enhance the QEMU emulator's performance and usability for developers, providing a more efficient workflow during development.

commit 3877445bdd83cb8690da18c8520bf260d2795172
Author: mantrakp04 mantrakp@gmail.com
Date: Wed Mar 18 11:55:18 2026 -0700

Enhance QEMU emulator performance and configuration management

- Added optimizations to the QEMU emulator's app container startup process, reducing startup time from ~92s to ~62s by using qcow2 backing files and setting the working directory to /app.
- Updated the build-image.sh script to conditionally wait for background processes, improving robustness.
- Modified the run-emulator.sh script to create the disk image using qcow2 format instead of copying, enhancing efficiency.
- Adjusted the cloud-init user-data to set STACK_RUNTIME_WORK_DIR to /app, streamlining file operations during container initialization.
- Improved the entrypoint script to avoid unnecessary file copying when the working directory is set to /app.

These changes significantly enhance the performance and usability of the QEMU emulator for developers.

commit e0b86d3f1d5c08e46d0d343bc632e2a8c5777845
Author: mantrakp04 mantrakp@gmail.com
Date: Wed Mar 18 11:07:55 2026 -0700

Refactor local emulator configuration management and enhance Docker setup

- Removed redundant comments and improved code clarity in the local emulator's route handling.
- Streamlined the Dockerfile and docker-compose.yaml for better readability and maintenance.
- Updated entrypoint and initialization scripts to enhance service startup processes.
- Introduced a new common script for QEMU emulator to centralize architecture detection and firmware handling.
- Enhanced error handling in the host file bridge for improved robustness.
- Removed obsolete country code utilities to clean up the codebase.

These changes significantly improve the local emulator's configuration management and overall setup experience for developers.

commit 4fb0f93c6cc4f749a14acf0228c261e180875609
Author: mantrakp04 mantrakp@gmail.com
Date: Wed Mar 18 10:24:53 2026 -0700

Implement local emulator file bridge for enhanced configuration management

- Introduced a new host file bridge to facilitate reading and writing configuration files between the local emulator and the host system.
- Refactored the local-emulator module to utilize the file bridge for file operations, improving error handling and response validation.
- Added tests to ensure the file bridge functionality works as expected, including handling of non-existent files and writing configurations.
- Updated the run-emulator script to start the file bridge automatically, ensuring seamless integration during emulator startup.
- Enhanced documentation to reflect the new file bridge capabilities and usage instructions.

These changes significantly improve the local emulator's ability to manage configuration files, enhancing the development experience.

commit 3d18a7ce5bbf00a62a40a3f48f27856e79ecc62f
Author: mantrakp04 mantrakp@gmail.com
Date: Tue Mar 17 22:36:46 2026 -0700

Refactor QEMU local emulator setup and enhance app bundle handling

- Introduced a new script for packaging Docker images into a compressed app bundle, improving the emulator's deployment process.
- Updated build-image.sh to create a runtime configuration ISO, ensuring better management of environment settings.
- Enhanced cloud-init user-data scripts for both dev-server and deps guests, streamlining service setup and configuration.
- Improved the run-emulator.sh script to facilitate better handling of runtime configurations and dependencies.
- Adjusted the .gitignore to include .DS_Store and removed obsolete entries, cleaning up the repository.

These changes significantly enhance the local emulator's functionality and reliability for developers.

commit 8a35fb1ce79898d73e2259e256c11b6fd9b0a584
Author: mantrakp04 mantrakp@gmail.com
Date: Tue Mar 17 21:52:24 2026 -0700

Enhance local emulator functionality and configuration

- Updated package.json to improve the start-emulator command, providing clearer dashboard and backend URLs.
- Added a new wait-until-emulator-is-ready command to ensure the emulator is fully operational before proceeding.
- Refactored the local-emulator project route to streamline file existence checks and default config creation.
- Enhanced user guidance in the dashboard for local Stack config file handling.
- Updated tests to reflect changes in config file handling, ensuring non-existent files are created with default settings.
- Improved Docker configurations for the local emulator, including new environment variables and service dependencies.

These changes significantly enhance the local development experience and emulator reliability.

commit 3910ed4bc40bbb37340c1c316c24c2826ba372bd
Author: mantrakp04 mantrakp@gmail.com
Date: Tue Mar 17 19:59:36 2026 -0700

Remove unused stash-0.patch file to clean up the repository.

commit 74146d974458037a7a9590120a524629a1a6a162
Author: mantrakp04 mantrakp@gmail.com
Date: Tue Mar 17 19:58:46 2026 -0700

Enhance QEMU local emulator with app bundle support and runtime configuration

- Introduced a new script to package the backend and dashboard assets into a standalone app bundle for the QEMU emulator.
- Updated the build-image.sh script to create an ISO containing the app bundle, ensuring the guest image includes the full runtime.
- Modified cloud-init user-data to handle the new app bundle and runtime configuration, improving the setup process for local development.
- Enhanced the run-emulator.sh script to prepare and mount the runtime configuration ISO, facilitating better environment management for the emulator.
- Updated the user-data to include necessary environment variables for the stack application, ensuring seamless integration during startup.

These changes significantly improve the local emulator's functionality and ease of use for developers.

commit 9e865a1cf524398bc58f00e0836278775c4ae936
Author: mantrakp04 mantrakp@gmail.com
Date: Tue Mar 17 16:50:45 2026 -0700

Enhance local emulator setup with new services and configurations

- Added Docker support for a local emulator, integrating PostgreSQL, Redis, Inbucket, Svix, ClickHouse, MinIO, and QStash.
- Introduced new scripts for managing the emulator lifecycle, including build and run commands.
- Implemented cloud-init provisioning for automatic service setup on first boot.
- Updated package.json with new commands for emulator management and added dotenv-cli for environment variable management.
- Added tests for OAuth authorization flow to return JSON responses.
- Included configuration files for ClickHouse and user management.

This commit significantly improves the local development experience by providing a comprehensive emulator environment.

Summary by CodeRabbit

  • New Features

    • Local QEMU-based emulator for development and testing.
    • CLI commands to manage emulator (start/stop/reset/status/pull/list-releases).
    • Emulator status UI page to monitor local services.
  • Documentation

    • Comprehensive emulator setup and usage guide added.
  • Bug Fixes / Improvements

    • Improved emulator config handling and host-mounted path support.
    • Added end-to-end and CLI tests for emulator workflows.
  • Chores

    • CI workflow to build, test, and publish emulator images; runtime scripts and packaging.

commit 5d43722575b826a8ed8dbb6b828f48eae4bca02c
Author: mantrakp04 <mantrakp@gmail.com>
Date:   Wed Mar 18 12:27:01 2026 -0700

    Add QEMU emulator snapshot functionality and reset command

    - Introduced a new `emulator-qemu:reset` command in package.json to clear snapshots and force a fresh boot of the emulator.
    - Enhanced the `run-emulator.sh` script to support saving and restoring snapshots, significantly reducing restart time from ~62s to ~4s.
    - Implemented logic to check for existing snapshots and restore them during startup, improving the emulator's efficiency.
    - Updated documentation in CLAUDE-KNOWLEDGE.md to explain the new snapshot restore process and its benefits.

    These changes enhance the QEMU emulator's performance and usability for developers, providing a more efficient workflow during development.

commit 3877445bdd83cb8690da18c8520bf260d2795172
Author: mantrakp04 <mantrakp@gmail.com>
Date:   Wed Mar 18 11:55:18 2026 -0700

    Enhance QEMU emulator performance and configuration management

    - Added optimizations to the QEMU emulator's app container startup process, reducing startup time from ~92s to ~62s by using qcow2 backing files and setting the working directory to /app.
    - Updated the build-image.sh script to conditionally wait for background processes, improving robustness.
    - Modified the run-emulator.sh script to create the disk image using qcow2 format instead of copying, enhancing efficiency.
    - Adjusted the cloud-init user-data to set STACK_RUNTIME_WORK_DIR to /app, streamlining file operations during container initialization.
    - Improved the entrypoint script to avoid unnecessary file copying when the working directory is set to /app.

    These changes significantly enhance the performance and usability of the QEMU emulator for developers.

commit e0b86d3f1d5c08e46d0d343bc632e2a8c5777845
Author: mantrakp04 <mantrakp@gmail.com>
Date:   Wed Mar 18 11:07:55 2026 -0700

    Refactor local emulator configuration management and enhance Docker setup

    - Removed redundant comments and improved code clarity in the local emulator's route handling.
    - Streamlined the Dockerfile and docker-compose.yaml for better readability and maintenance.
    - Updated entrypoint and initialization scripts to enhance service startup processes.
    - Introduced a new common script for QEMU emulator to centralize architecture detection and firmware handling.
    - Enhanced error handling in the host file bridge for improved robustness.
    - Removed obsolete country code utilities to clean up the codebase.

    These changes significantly improve the local emulator's configuration management and overall setup experience for developers.

commit 4fb0f93c6cc4f749a14acf0228c261e180875609
Author: mantrakp04 <mantrakp@gmail.com>
Date:   Wed Mar 18 10:24:53 2026 -0700

    Implement local emulator file bridge for enhanced configuration management

    - Introduced a new host file bridge to facilitate reading and writing configuration files between the local emulator and the host system.
    - Refactored the local-emulator module to utilize the file bridge for file operations, improving error handling and response validation.
    - Added tests to ensure the file bridge functionality works as expected, including handling of non-existent files and writing configurations.
    - Updated the run-emulator script to start the file bridge automatically, ensuring seamless integration during emulator startup.
    - Enhanced documentation to reflect the new file bridge capabilities and usage instructions.

    These changes significantly improve the local emulator's ability to manage configuration files, enhancing the development experience.

commit 3d18a7ce5bbf00a62a40a3f48f27856e79ecc62f
Author: mantrakp04 <mantrakp@gmail.com>
Date:   Tue Mar 17 22:36:46 2026 -0700

    Refactor QEMU local emulator setup and enhance app bundle handling

    - Introduced a new script for packaging Docker images into a compressed app bundle, improving the emulator's deployment process.
    - Updated build-image.sh to create a runtime configuration ISO, ensuring better management of environment settings.
    - Enhanced cloud-init user-data scripts for both dev-server and deps guests, streamlining service setup and configuration.
    - Improved the run-emulator.sh script to facilitate better handling of runtime configurations and dependencies.
    - Adjusted the .gitignore to include .DS_Store and removed obsolete entries, cleaning up the repository.

    These changes significantly enhance the local emulator's functionality and reliability for developers.

commit 8a35fb1ce79898d73e2259e256c11b6fd9b0a584
Author: mantrakp04 <mantrakp@gmail.com>
Date:   Tue Mar 17 21:52:24 2026 -0700

    Enhance local emulator functionality and configuration

    - Updated package.json to improve the start-emulator command, providing clearer dashboard and backend URLs.
    - Added a new wait-until-emulator-is-ready command to ensure the emulator is fully operational before proceeding.
    - Refactored the local-emulator project route to streamline file existence checks and default config creation.
    - Enhanced user guidance in the dashboard for local Stack config file handling.
    - Updated tests to reflect changes in config file handling, ensuring non-existent files are created with default settings.
    - Improved Docker configurations for the local emulator, including new environment variables and service dependencies.

    These changes significantly enhance the local development experience and emulator reliability.

commit 3910ed4bc40bbb37340c1c316c24c2826ba372bd
Author: mantrakp04 <mantrakp@gmail.com>
Date:   Tue Mar 17 19:59:36 2026 -0700

    Remove unused stash-0.patch file to clean up the repository.

commit 74146d974458037a7a9590120a524629a1a6a162
Author: mantrakp04 <mantrakp@gmail.com>
Date:   Tue Mar 17 19:58:46 2026 -0700

    Enhance QEMU local emulator with app bundle support and runtime configuration

    - Introduced a new script to package the backend and dashboard assets into a standalone app bundle for the QEMU emulator.
    - Updated the build-image.sh script to create an ISO containing the app bundle, ensuring the guest image includes the full runtime.
    - Modified cloud-init user-data to handle the new app bundle and runtime configuration, improving the setup process for local development.
    - Enhanced the run-emulator.sh script to prepare and mount the runtime configuration ISO, facilitating better environment management for the emulator.
    - Updated the user-data to include necessary environment variables for the stack application, ensuring seamless integration during startup.

    These changes significantly improve the local emulator's functionality and ease of use for developers.

commit 9e865a1cf524398bc58f00e0836278775c4ae936
Author: mantrakp04 <mantrakp@gmail.com>
Date:   Tue Mar 17 16:50:45 2026 -0700

    Enhance local emulator setup with new services and configurations

    - Added Docker support for a local emulator, integrating PostgreSQL, Redis, Inbucket, Svix, ClickHouse, MinIO, and QStash.
    - Introduced new scripts for managing the emulator lifecycle, including build and run commands.
    - Implemented cloud-init provisioning for automatic service setup on first boot.
    - Updated package.json with new commands for emulator management and added dotenv-cli for environment variable management.
    - Added tests for OAuth authorization flow to return JSON responses.
    - Included configuration files for ClickHouse and user management.

    This commit significantly improves the local development experience by providing a comprehensive emulator environment.
@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 18, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
stack-auth-hosted-components Ready Ready Preview, Comment Apr 3, 2026 11:00pm
stack-backend Ready Ready Preview, Comment Apr 3, 2026 11:00pm
stack-dashboard Ready Ready Preview, Comment Apr 3, 2026 11:00pm
stack-demo Ready Ready Preview, Comment Apr 3, 2026 11:00pm
stack-docs Ready Ready Preview, Comment Apr 3, 2026 11:00pm

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 18, 2026

📝 Walkthrough

Walkthrough

Adds a QEMU-based local emulator: build/test/publish workflows, QEMU tooling and cloud-init for VM images, an all-in-one runtime Docker image and supervisord orchestration, CLI commands and e2e tests, backend path resolution for host-mounted configs, demo health-check UI, and supporting scripts/docs.

Changes

Cohort / File(s) Summary
CI / Release
​.github/workflows/qemu-emulator-build.yaml
New GitHub Actions workflow to build, test, and publish QEMU emulator QCOW2 artifacts for amd64/arm64 with artifact upload and GitHub Release creation.
QEMU tooling & runtime
docker/local-emulator/Dockerfile, docker/local-emulator/entrypoint.sh, docker/local-emulator/init-services.sh, docker/local-emulator/start-app.sh, docker/local-emulator/supervisord.conf, docker/local-emulator/clickhouse-config.xml, docker/local-emulator/clickhouse-users.xml
Adds all-in-one runtime image, init/entrypoint scripts, supervisord config, and ClickHouse configs for orchestrating services inside the emulator container.
QEMU image build & runner
docker/local-emulator/qemu/common.sh, docker/local-emulator/qemu/build-image.sh, docker/local-emulator/qemu/run-emulator.sh, docker/local-emulator/qemu/cloud-init/emulator/*, docker/local-emulator/qemu/README.md, docker/local-emulator/qemu/*.{gitignore,images/.gitignore}
New QEMU helper, image builder, runtime manager, cloud-init user-data/meta-data, README and image directory ignore rules — implements build, provision, start/stop/status/reset and packaging of qcow2 images.
Emulator env generation
docker/local-emulator/generate-env-development.mjs, .gitignore, .dockerignore
Adds script to generate/validate .env.development for emulator, and ignore entries for emulator artifacts and generated env file.
CLI & tests
packages/stack-cli/src/commands/emulator.ts, packages/stack-cli/src/index.ts, apps/e2e/tests/general/cli.test.ts
Registers new emulator CLI group (pull/start/stop/reset/status/list-releases), integrates gh-run/asset downloads, and adds emulator-specific e2e CLI tests for help/output and arch validation.
Backend local-emulator support
apps/backend/src/lib/local-emulator.ts, apps/backend/src/lib/local-emulator.test.ts, apps/backend/src/app/api/latest/internal/local-emulator/project/route.tsx, apps/backend/prisma/seed.ts
Adds LOCAL_EMULATOR_HOST_MOUNT_ROOT env constant and resolveEmulatorPath() to read/write configs from a host-mount root, supports base64 config override, changes ENOENT handling to return {}, tightens write behavior when host-mount is set; adds tests and a permission grant in seed.
Demo health UI
examples/demo/src/app/api/emulator-status/route.ts, examples/demo/src/app/emulator-status/page.tsx
New API route and client page to poll and report emulator service health, latencies, and summary counts.
Node scripts & packaging
package.json, claude/CLAUDE-KNOWLEDGE.md, docker/local-emulator/* (docs/scripts)
Adds npm scripts for emulator workflows, documents QEMU startup regression investigation, and ships supporting docs/scripts.
Small import / server tweaks
apps/dashboard/.../page-client.tsx, docker/server/entrypoint.sh
Minor import reorder; server entrypoint now respects STACK_RUNTIME_WORK_DIR and skips redundant copy when equal to /app.

Sequence Diagram(s)

sequenceDiagram
    actor Host
    participant QEMU as QEMU VM
    participant CloudInit as cloud-init (user-data)
    participant Docker as Docker (in-VM)
    participant Services as Supervisord Services
    participant App as Stack Container

    Host->>QEMU: Start VM with cloud-init ISO + bundle
    QEMU->>CloudInit: Execute user-data (install+configure)
    CloudInit->>Docker: Enable/start Docker
    CloudInit->>Docker: Load bundled image (img.tgz)
    Docker->>Services: Start dependency containers via supervisord
    CloudInit->>Services: Run init scripts (create DBs/buckets)
    Services-->>Docker: Health endpoints become available
    CloudInit->>App: Launch stack-local-emulator container
    App->>Services: Connect to Postgres/Redis/ClickHouse/MinIO
    Services-->>App: Dependencies ready
    App-->>QEMU: Emit STACK_CLOUD_INIT_DONE and shutdown
    QEMU-->>Host: VM provisioning complete (qcow2 ready)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • Local emulator base #1233 — Directly related: overlaps local-emulator files and features (backend local-emulator changes and QEMU tooling).
  • Stack CLI #1227 — Related: changes to CLI package and e2e CLI tests touching emulator commands.

Suggested reviewers

  • N2D4
  • nams1570

Poem

🐰 In burrows bright I build a VM nest,

QEMU hops in, containers rest,
cloud-init spins the yarn so neat,
services wake on forwarded feet,
now Stack runs local — carrots for all to test.

🚥 Pre-merge checks | ❌ 3

❌ Failed checks (1 warning, 2 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 1.52% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'emu with a q stuff' is vague and does not clearly convey the main changes in the pull request. Use a more descriptive title that summarizes the primary change, such as 'Add QEMU-based local emulator with snapshot support' or 'Implement QEMU emulator with performance optimizations'.
Description check ❓ Inconclusive The description provides detailed commit messages but does not follow the expected template structure with clear sections for context, changes, and testing. Rewrite the description to follow the repository's template, organizing information into clear sections such as 'What', 'Why', 'How', and 'Testing' to improve clarity and consistency.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch emu-with-a-q

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

- Unified the QEMU emulator setup by consolidating the previously separate VM roles (deps and dev-server) into a single VM, simplifying the architecture and reducing complexity.
- Updated the `build-image.sh` script to adjust resource allocations and streamline image building processes.
- Enhanced the `prepare-image-bundle.sh` script to support multiple Docker images, improving the packaging of emulator components.
- Refactored cloud-init configurations to use a single definition for the emulator, improving maintainability and clarity.
- Updated documentation in CLAUDE-KNOWLEDGE.md to reflect changes in the emulator's architecture and cloud-init usage.

These changes significantly enhance the QEMU emulator's usability and performance for developers.
…file bridge

- Removed the `readConfigFileContentIfExists` and `writeConfigToFile` functions from the local emulator module, simplifying file handling.
- Updated the `readConfigFromFile` function to utilize environment variables for configuration content, enhancing flexibility.
- Refactored tests to align with the new configuration management approach, ensuring accurate validation of file reading and handling.
- Consolidated Docker environment variables into a new `base.env` file for improved organization and maintainability.
- Removed the host file bridge script and related logic, streamlining the emulator's architecture and reducing complexity.

These changes significantly enhance the local emulator's usability and maintainability for developers.
- Updated the local emulator Dockerfile to include a multi-stage build process, improving dependency management and reducing image size.
- Added Node.js build stages and integrated pnpm for package management, enhancing build efficiency.
- Implemented a migration-pruner stage to remove unnecessary node_modules, optimizing runtime performance.
- Refined the server Dockerfile to utilize pruned node_modules for runtime, ensuring a leaner image.
- Enhanced entrypoint and initialization scripts for better service startup processes.
- Updated exposed ports to include backend and dashboard services, improving accessibility.

These changes significantly improve the Docker setup for both local emulator and server, enhancing performance and maintainability.
- Updated the `build-image.sh` script to simplify the Docker image list, focusing on the main emulator image.
- Enhanced the image compression process by adding progress logging during the conversion to qcow2 format.
- Improved the `run-emulator.sh` script to provide real-time feedback while saving snapshots, enhancing user experience.

These changes streamline the build process and improve the usability of the emulator's snapshot functionality.
@mantrakp04 mantrakp04 changed the title Squashed commit of the following: emu with a q stuff Mar 19, 2026
- Renamed and restructured the Docker Compose configuration to unify the local emulator services into a single `stack-local` service, simplifying the architecture.
- Updated the Dockerfile to include a multi-stage build process for the local emulator, integrating the backend and dashboard into a single image.
- Introduced a new `start-app.sh` script to manage service initialization and health checks, ensuring all dependencies are ready before starting the application.
- Enhanced the cloud-init user-data script to streamline the setup process and improve service management.
- Removed obsolete service definitions and scripts, reducing complexity and improving maintainability.

These changes significantly enhance the local emulator's usability and performance for developers.
- Introduced a new function to generate a fingerprint of the base QEMU image, allowing for detection of changes since the last snapshot.
- Updated snapshot handling logic to discard stale snapshots if the base image has changed, improving reliability and efficiency.
- Enhanced the `run-emulator.sh` script to save the fingerprint after a snapshot is created, ensuring accurate tracking of image state.

These changes enhance the snapshot management process in the QEMU emulator, providing better consistency and performance for developers.
- Updated `stack.config.ts` to enable various application features including authentication, emails, teams, RBAC, API keys, webhooks, and launch checklist.
- Modified `seed.ts` to grant team permissions for the local emulator admin user, improving access control.
- Adjusted `run-emulator.sh` to allow auto-detection of the configuration file, enhancing usability.
- Updated `.gitignore` to include the new `run/` directory, ensuring cleaner repository management.

These changes improve the local emulator's configuration management and user experience for developers.
- Updated `stack.config.ts` to enable password sign-in for authentication.
- Refactored `config.tsx` to include functionality for writing configuration changes back to the local emulator's config file.
- Introduced `writeConfigToFile` and `getLocalEmulatorFilePath` functions in `local-emulator.ts` to improve file handling and path resolution.
- Enhanced `run-emulator.sh` to support mounting the host filesystem, facilitating better integration with the local environment.

These changes improve the local emulator's configuration management and usability for developers.
mantrakp04 and others added 3 commits March 19, 2026 11:29
- Introduced a new GitHub Actions workflow for building and publishing QEMU emulator images, triggered on pushes to main and dev branches, as well as pull requests.
- Added a new `emulator` command in the Stack CLI to manage QEMU emulator operations, including pulling images, starting, stopping, and checking status.
- Implemented functionality for downloading emulator images from GitHub Releases and managing snapshots, enhancing the local development experience.

These changes significantly improve the automation and usability of the QEMU emulator for developers.
- Modified `stack.config.ts` to adjust authentication settings, enabling OTP and passkey sign-ins while disabling password sign-in.
- Updated the GitHub Actions workflow for the QEMU emulator to improve the start and stop commands, enhancing clarity in the process.
- Refactored the CLI commands for the emulator, removing snapshot options and streamlining the pull command for image downloads.
- Added new tests for the emulator CLI to validate help and argument parsing, ensuring a better developer experience.

These changes improve the configuration management and usability of the QEMU emulator for developers.
…mands

- Deleted `stack.config.ts` and `CLAUDE-KNOWLEDGE.md` as they are no longer needed.
- Refactored the `local-emulator.ts` to improve error handling and type definitions.
- Updated the `header.tsx` component to remove the Emulator Status link, simplifying the navigation.
- Enhanced the `emulator.ts` CLI commands for better readability and maintainability.

These changes improve the overall structure and usability of the emulator and related components.
…tus reporting

- Modified `build-image.sh` and `run-emulator.sh` to check for write permissions on `/dev/kvm` instead of existence, enhancing compatibility with various environments.
- Added status tracking for services in `run-emulator.sh`, allowing for better error handling and reporting during emulator status checks.

These changes enhance the reliability and usability of the QEMU emulator setup.
- Updated `local-emulator.ts` to explicitly cast the module evaluation result to `Record<string, unknown>`, improving type safety.
- Enhanced `emulator.ts` architecture detection with clearer case structures for better readability and maintainability.

These changes improve code clarity and type management in the local emulator setup.
- Added functionality to write an empty configuration file if none exists when processing a project in `route.tsx`.
- Updated `readConfigFromFile` in `local-emulator.ts` to support reading configuration from an environment variable, improving flexibility in configuration management.
- Ensured the directory structure is created when writing configuration files, enhancing file handling robustness.

These changes improve the local emulator's configuration management and usability for developers.
Copy link
Copy Markdown
Contributor

@N2D4 N2D4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is really cool, i love the github releases approach and how it's integrated into the CLI. left some comments

- Introduced file existence checks in the local emulator project route to ensure the specified config file is present before proceeding with project creation.
- Updated the `setBranchConfigOverride` function to streamline writing configurations directly to the file when the local emulator is enabled, improving reliability.
- Refactored the `readConfigFromFile` function to handle empty file scenarios by writing a default config, enhancing user experience.
- Adjusted related tests to reflect changes in error handling and file creation logic, ensuring robust validation of local emulator functionality.

These updates improve the local emulator's configuration management and enhance the overall developer experience.
- Updated local emulator scripts to standardize command names and improve clarity, changing references from `generate-local-emulator-env` to `emulator:generate-env` and similar adjustments for other commands.
- Introduced a new configuration file (`stack.config.ts`) to centralize authentication and team settings, enhancing the management of user permissions and onboarding processes.
- Removed the outdated `.env.development` file to streamline environment handling, ensuring that the local emulator relies on generated configurations.
- Adjusted documentation and example usage to reflect the new command structure and configuration file, improving developer experience.

These changes enhance the usability and maintainability of the local emulator setup, providing a clearer structure for configuration and command usage.
- Updated the local emulator scripts to streamline command usage, replacing the previous docker-compose setup with a QEMU-based approach for improved performance and simplicity.
- Removed the outdated `docker-compose.yaml` file and adjusted related scripts to utilize QEMU for running the emulator, enhancing clarity and maintainability.
- Enhanced the GitHub Actions workflow to include a smoke test for the emulator, ensuring that services are healthy after startup.
- Updated environment variable handling in the emulator scripts to reflect new port configurations, improving service accessibility.
- Adjusted documentation to reflect the new emulator commands and usage patterns, providing clearer guidance for developers.

These changes improve the usability and reliability of the local emulator setup, facilitating a smoother development experience.
- Updated the GitHub Actions workflow to include specific paths for the QEMU emulator build, ensuring that changes in the local emulator directory trigger the workflow.
- Added a new README.md file for the QEMU local emulator, detailing its architecture, usage, and scripts for building and running the emulator, improving clarity for developers.
- Documented the build process and optimizations taken, providing comprehensive guidance for users on how to utilize the local emulator effectively.

These changes improve the usability and maintainability of the QEMU emulator setup, facilitating a smoother development experience.
@mantrakp04
Copy link
Copy Markdown
Collaborator Author

@greptile-ai review

- Replaced the 'run' command expectation with 'start' in the emulator help output.
- Removed the test for 'emulator build' help as it is no longer relevant.
- Updated error message for invalid architecture in the 'emulator pull' test to improve clarity.

These changes enhance the accuracy and relevance of the CLI tests for the emulator functionality.
Comment thread stack.config.ts Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (4)
examples/demo/src/app/api/emulator-status/route.ts (1)

5-11: Unused protocol field in ServiceCheck type.

The protocol field is defined but never used—all services are HTTP and the checkHttp function is always called. Consider removing it to avoid dead code, or implement TCP checking if you plan to support non-HTTP services.

🧹 Suggested cleanup
 type ServiceCheck = {
   name: string;
   description: string;
   port: number;
-  protocol: 'http' | 'tcp';
   httpPath?: string;
 };

And remove protocol: 'http', from each service definition.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/demo/src/app/api/emulator-status/route.ts` around lines 5 - 11, The
ServiceCheck type declares a unused protocol field and each service still sets
protocol: 'http' while only checkHttp is ever called; remove dead code by
deleting the protocol property from the ServiceCheck type and removing protocol:
'http' from all service objects (or alternatively implement TCP support by
adding a checkTcp function and branching in the health loop to call checkTcp
when protocol === 'tcp'); update any references to ServiceCheck and the
health-check loop (e.g., checkHttp) accordingly so there are no leftover
protocol usages.
examples/demo/src/app/emulator-status/page.tsx (1)

67-68: Unsafe type cast bypasses runtime validation.

The as StatusResponse cast assumes the API response matches the expected shape without validation. Per coding guidelines, type casts should be avoided. If the API response changes or returns an error, this could lead to silent failures downstream.

Consider adding basic validation or using a schema validator:

🛡️ Suggested improvement with basic validation
   const fetchStatus = useCallback(async () => {
     try {
       const res = await fetch('/api/emulator-status', { cache: 'no-store' });
+      if (!res.ok) {
+        throw new Error(`HTTP ${res.status}`);
+      }
       const json = await res.json();
-      setData(json as StatusResponse);
-    } catch {
-      // keep last known state
+      // Basic shape validation
+      if (!json || typeof json !== 'object' || !Array.isArray(json.services)) {
+        throw new Error('Invalid response shape');
+      }
+      setData(json as StatusResponse);
+    } catch (error) {
+      console.error('Failed to fetch emulator status:', error);
+      // keep last known state on error
     } finally {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/demo/src/app/emulator-status/page.tsx` around lines 67 - 68, The
code unsafely casts the fetch result to StatusResponse (json as StatusResponse)
bypassing runtime validation; change setData(json as StatusResponse) to validate
the parsed json before setting state—use a small validator function or a schema
(e.g., Zod) to check required fields of StatusResponse after const json = await
res.json(), and only call setData(validated) when validation passes, otherwise
handle the error path (set an error state, log, or setData(undefined/null)).
Ensure you reference the parsed value (json), the state setter (setData) and the
expected type (StatusResponse) when adding the validation and error handling.
docker/local-emulator/qemu/README.md (1)

7-20: Consider adding language identifiers to fenced code blocks.

The ASCII diagrams on Lines 7 and 110 could use a language identifier (e.g., text or plaintext) to satisfy markdownlint MD040. This is a minor formatting nit.

📝 Proposed fix
-```
+```text
 Host machine
  └─ QEMU VM (Debian 13 cloud image)
-```
+```text
 qemu/
 ├── build-image.sh          # Image builder
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docker/local-emulator/qemu/README.md` around lines 7 - 20, The two fenced
ASCII-diagram blocks (the one starting with "Host machine" and the one starting
with "qemu/") lack language identifiers; update each opening fence from ``` to
```text (or ```plaintext) so markdownlint rule MD040 is satisfied and the
diagrams are treated as plain text. Locate the blocks in
docker/local-emulator/qemu/README.md and add the language token to both opening
fences.
apps/backend/src/lib/local-emulator.ts (1)

66-66: Add type annotation or comment for any in catch clause.

Line 66 uses catch (e: any) without explanation. Per coding guidelines, when using any, leave a comment explaining why and how errors are still flagged. Consider using unknown with a type guard instead.

♻️ Suggested fix using unknown with type guard
-    } catch (e: any) {
-      if (e?.code === "ENOENT") {
+    } catch (e: unknown) {
+      // Node.js fs errors have a `code` property for error classification
+      if (e instanceof Error && (e as NodeJS.ErrnoException).code === "ENOENT") {
         return {};
       }
       throw e;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/backend/src/lib/local-emulator.ts` at line 66, The catch clause
currently uses catch (e: any); change it to catch (e: unknown) and add a small
type-guard before using e (e.g. if (e instanceof Error) { /* use e.message */ }
else { /* handle non-Error case */ }) so runtime error properties are accessed
safely, or if you must keep any add a one-line comment explaining why any is
required and how errors are validated; update the catch block around the
local-emulator error handling to use the type-guard pattern and reference the
existing catch variable name e for clarity.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@apps/backend/src/lib/local-emulator.ts`:
- Line 66: The catch clause currently uses catch (e: any); change it to catch
(e: unknown) and add a small type-guard before using e (e.g. if (e instanceof
Error) { /* use e.message */ } else { /* handle non-Error case */ }) so runtime
error properties are accessed safely, or if you must keep any add a one-line
comment explaining why any is required and how errors are validated; update the
catch block around the local-emulator error handling to use the type-guard
pattern and reference the existing catch variable name e for clarity.

In `@docker/local-emulator/qemu/README.md`:
- Around line 7-20: The two fenced ASCII-diagram blocks (the one starting with
"Host machine" and the one starting with "qemu/") lack language identifiers;
update each opening fence from ``` to ```text (or ```plaintext) so markdownlint
rule MD040 is satisfied and the diagrams are treated as plain text. Locate the
blocks in docker/local-emulator/qemu/README.md and add the language token to
both opening fences.

In `@examples/demo/src/app/api/emulator-status/route.ts`:
- Around line 5-11: The ServiceCheck type declares a unused protocol field and
each service still sets protocol: 'http' while only checkHttp is ever called;
remove dead code by deleting the protocol property from the ServiceCheck type
and removing protocol: 'http' from all service objects (or alternatively
implement TCP support by adding a checkTcp function and branching in the health
loop to call checkTcp when protocol === 'tcp'); update any references to
ServiceCheck and the health-check loop (e.g., checkHttp) accordingly so there
are no leftover protocol usages.

In `@examples/demo/src/app/emulator-status/page.tsx`:
- Around line 67-68: The code unsafely casts the fetch result to StatusResponse
(json as StatusResponse) bypassing runtime validation; change setData(json as
StatusResponse) to validate the parsed json before setting state—use a small
validator function or a schema (e.g., Zod) to check required fields of
StatusResponse after const json = await res.json(), and only call
setData(validated) when validation passes, otherwise handle the error path (set
an error state, log, or setData(undefined/null)). Ensure you reference the
parsed value (json), the state setter (setData) and the expected type
(StatusResponse) when adding the validation and error handling.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bb105994-3416-4f3a-bf37-78015cd9423c

📥 Commits

Reviewing files that changed from the base of the PR and between 4be8a82 and 0f3daeb.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (20)
  • .dockerignore
  • .github/workflows/qemu-emulator-build.yaml
  • .gitignore
  • apps/backend/prisma/seed.ts
  • apps/backend/src/app/api/latest/internal/local-emulator/project/route.tsx
  • apps/backend/src/lib/local-emulator.test.ts
  • apps/backend/src/lib/local-emulator.ts
  • apps/dashboard/src/app/(main)/(protected)/(outside-dashboard)/projects/page-client.tsx
  • apps/e2e/tests/general/cli.test.ts
  • claude/CLAUDE-KNOWLEDGE.md
  • docker/local-emulator/generate-env-development.mjs
  • docker/local-emulator/qemu/README.md
  • docker/local-emulator/qemu/build-image.sh
  • docker/local-emulator/qemu/cloud-init/emulator/user-data
  • docker/local-emulator/qemu/run-emulator.sh
  • examples/demo/src/app/api/emulator-status/route.ts
  • examples/demo/src/app/emulator-status/page.tsx
  • package.json
  • packages/stack-cli/src/commands/emulator.ts
  • stack.config.ts
✅ Files skipped from review due to trivial changes (5)
  • .gitignore
  • .dockerignore
  • apps/dashboard/src/app/(main)/(protected)/(outside-dashboard)/projects/page-client.tsx
  • claude/CLAUDE-KNOWLEDGE.md
  • apps/backend/src/lib/local-emulator.test.ts
🚧 Files skipped from review as they are similar to previous changes (6)
  • apps/backend/prisma/seed.ts
  • apps/e2e/tests/general/cli.test.ts
  • apps/backend/src/app/api/latest/internal/local-emulator/project/route.tsx
  • package.json
  • docker/local-emulator/qemu/cloud-init/emulator/user-data
  • packages/stack-cli/src/commands/emulator.ts

@mantrakp04 mantrakp04 enabled auto-merge (squash) April 2, 2026 00:18
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
.github/workflows/qemu-emulator-build.yaml (1)

92-102: Test job only covers amd64 architecture.

The test matrix only includes amd64. This means arm64 images are built but not smoke-tested before publish. If this is intentional (e.g., due to emulation overhead or runner availability), consider adding a comment to document why arm64 testing is skipped.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/qemu-emulator-build.yaml around lines 92 - 102, The test
job "test" currently only includes arch: amd64 in the matrix, so arm64 images
are not smoke-tested; either add a second matrix entry (e.g., include: - arch:
arm64) to run the smoke test for arm64 as well, or if skipping arm64 is
intentional, add a clear inline comment above the "test" job or the matrix
explaining why arm64 is excluded (e.g., emulation overhead/runner availability)
so the omission is documented; update the "test" job's matrix.include or add the
explanatory comment near the matrix definition accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In @.github/workflows/qemu-emulator-build.yaml:
- Around line 92-102: The test job "test" currently only includes arch: amd64 in
the matrix, so arm64 images are not smoke-tested; either add a second matrix
entry (e.g., include: - arch: arm64) to run the smoke test for arm64 as well, or
if skipping arm64 is intentional, add a clear inline comment above the "test"
job or the matrix explaining why arm64 is excluded (e.g., emulation
overhead/runner availability) so the omission is documented; update the "test"
job's matrix.include or add the explanatory comment near the matrix definition
accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 67fc87aa-d530-4679-9e68-bb32542fdbdc

📥 Commits

Reviewing files that changed from the base of the PR and between 26254c4 and 7daea68.

📒 Files selected for processing (1)
  • .github/workflows/qemu-emulator-build.yaml

@mantrakp04 mantrakp04 merged commit ce49eae into dev Apr 4, 2026
36 of 37 checks passed
@mantrakp04 mantrakp04 deleted the emu-with-a-q branch April 4, 2026 00:33
promptless Bot added a commit that referenced this pull request Apr 6, 2026
Expands the self-host documentation to cover the new QEMU-based local
emulator introduced in PR #1266. Adds documentation for:

- QEMU emulator prerequisites and installation
- CLI commands (pull, start, stop, reset, status, list-releases)
- Bundled services and port mappings
- Hardware acceleration notes
- Integration with local emulator mode for config file-based projects

Also adds code examples for emulator CLI commands.
@promptless
Copy link
Copy Markdown
Contributor

promptless Bot commented Apr 6, 2026

Promptless prepared a documentation update related to this change.

Triggered by PR #1266

Added comprehensive documentation for the new QEMU-based local emulator feature, including prerequisites, CLI commands (pull, start, stop, reset, status), bundled services, port mappings, and hardware acceleration notes.

Review at https://app.gopromptless.ai/suggestions/e512a23b-bb38-4a3b-b5af-965d918b07d9

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.

3 participants