Skip to content

Implement cx new project template scaffolding#765

Open
Da7-Tech wants to merge 1 commit into
cxlinux-ai:mainfrom
Da7-Tech:implement-cx-new-templates
Open

Implement cx new project template scaffolding#765
Da7-Tech wants to merge 1 commit into
cxlinux-ai:mainfrom
Da7-Tech:implement-cx-new-templates

Conversation

@Da7-Tech
Copy link
Copy Markdown

@Da7-Tech Da7-Tech commented May 20, 2026

Summary

  • replace the cx new stub with working project scaffolding
  • add the requested python, rust, node, react, nextjs, fastapi, go, and docker templates
  • support cx new --list, positional names, --name, --dir, default template inference, safe project name validation, and Python .venv creation fallback
  • add unit coverage for registered templates, path validation, identifier sanitization, default --name usage, and rendering every template without leftover placeholders

Fixes #708

Testing

  • cargo fmt -- wezterm/src/cli/new.rs
  • git diff --check -- wezterm/src/cli/new.rs
  • cargo test --manifest-path /Users/raif/Documents/Codex/2026-05-20/goal-200-8-8-200/verify-new-command/Cargo.toml (6 passed)

I also tried cargo test -p cx-terminal cli::new in the source workspace, but Cargo fails before compiling this change because the existing optional hrm-ai git dependency points at revision 8bdce0fe12d8d84370e1d70d904bb9daee654c0a, which could not be fetched/authenticated in this environment.

Summary by CodeRabbit

  • New Features
    • Project scaffolding via new command with full template support
    • --list flag to display available templates
    • Automatic template inference based on project context
    • Optional Python virtual environment creation for applicable templates

Review Change Stack

@Da7-Tech Da7-Tech requested a review from a team as a code owner May 20, 2026 02:01
Copilot AI review requested due to automatic review settings May 20, 2026 02:01
@github-actions
Copy link
Copy Markdown
Contributor

CLA Verification Failed

The following contributors have not signed the Contributor License Agreement:

  • @Da7-Tech (Da7-Tech, 286182457+Da7-Tech@users.noreply.github.com)

How to Sign

  1. Read the CLA document
  2. Open a CLA signature request
  3. A maintainer will add you to the signers list
  4. Comment recheck on this PR to re-run verification

This check runs automatically. Maintainers can update .github/cla-signers.json to add signers.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5c1ace47-3013-4dd6-92c9-83686000b7d4

📥 Commits

Reviewing files that changed from the base of the PR and between bf87c78 and 4798761.

📒 Files selected for processing (1)
  • wezterm/src/cli/new.rs

📝 Walkthrough

Walkthrough

The cx new command is reimplemented from a stub into a full project-scaffolding system. NewCommand gains a positional project_name and --list flag. The run() method orchestrates template selection, context generation with name sanitization, filesystem preparation, file rendering with placeholder substitution, and optional Python venv creation. Eight templates (Python, Rust, Node, React, Next.js, FastAPI, Go, Docker) are registered with embedded file contents and per-template instructions.

Changes

Project Scaffolding Implementation

Layer / File(s) Summary
Command Interface and Orchestration
wezterm/src/cli/new.rs (lines 6–131)
NewCommand struct adds project_name positional argument and --list flag. The run() method implements template selection/inference, name resolution, validation, and error handling for duplicate/missing inputs.
Template Models and Context Generation
wezterm/src/cli/new.rs (lines 133–232)
Template and TemplateFile data structures, TemplateContext generation with sanitization for package/module/crate names, plus helpers to list, look up, infer defaults, and validate project names.
File Rendering and Sanitization
wezterm/src/cli/new.rs (lines 300–358, 235–277)
Placeholder rendering ({{...}} → values), package-name and identifier sanitization, directory readiness checks, and template file writing with parent directory creation and error context.
Python Virtual Environment Creation
wezterm/src/cli/new.rs (lines 278–299)
Optional venv setup via python3 -m venv for Python templates, with fallback .venv directory and README on failure.
Template Registry and Definitions
wezterm/src/cli/new.rs (lines 359–878)
Eight bundled templates (Python, Rust, Node, React, Next.js, FastAPI, Go, Docker) with embedded file lists, placeholder-bearing contents, next-step instructions, and venv flags.
Test Coverage
wezterm/src/cli/new.rs (lines 879–994)
Tests for template registration, project-name validation (rejects path-like inputs), context sanitization, rendered output placeholder removal, default-template behavior with --name flag, and Rust template output; includes temp directory helpers.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐰 From stubbed-out dreams comes templates bright,
Eight projects scaffolded just right!
Python, Rust, and Node align,
Rendering placeholders line by line. 🎉
New projects bloom in seconds flat—
Hop along, dear rabbit in that hat!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR implements all 8 required templates (python, rust, node, react, nextjs, fastapi, go, docker) with template scaffolding logic, cx new --list support, and unit tests; however, BSL 1.1 headers are not mentioned and cx ask integration is not addressed. Add BSL 1.1 headers to source files and implement integration with cx ask pattern matching as specified in issue #708 acceptance criteria.
Docstring Coverage ⚠️ Warning Docstring coverage is 52.38% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: implementing project template scaffolding for the cx new command, which was previously a stub.
Out of Scope Changes check ✅ Passed All changes are scoped to implementing the cx new template scaffolding feature in wezterm/src/cli/new.rs and related template infrastructure, with no extraneous modifications.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Implements the cx new CLI command to scaffold new projects from a set of built-in templates.

Changes:

  • Replaces the prior stub with functional project scaffolding (templated file writing, directory validation, and optional Python venv creation).
  • Adds CLI ergonomics: positional project name, --list template listing, and default-template inference.
  • Adds unit tests covering template registration, name validation, rendering, and basic command execution.

Comment thread wezterm/src/cli/new.rs
Comment on lines +6 to +10
// CX Terminal: Create new projects from templates.
//
// This module provides the `new` command for creating new projects
// from predefined templates. Templates include common project types
// like Rust, Python, Node.js, and more.
Comment thread wezterm/src/cli/new.rs
},
TemplateFile {
path: "src/{{python_module}}/__init__.py",
contents: r#""""{{project_name}} package."""
Comment thread wezterm/src/cli/new.rs
Comment on lines +278 to +292
fn create_python_venv(target_dir: &Path) -> Result<()> {
let venv_dir = target_dir.join(".venv");
let status = Command::new("python3")
.args(["-m", "venv", ".venv"])
.current_dir(target_dir)
.status();

match status {
Ok(status) if status.success() => Ok(()),
_ => {
fs::create_dir_all(&venv_dir)
.with_context(|| format!("failed to create {}", venv_dir.display()))?;
fs::write(
venv_dir.join("README.md"),
"Create the virtual environment with:\n\n```bash\npython3 -m venv .venv\n```\n",
Comment thread wezterm/src/cli/new.rs
Comment on lines +24 to +26
/// cx-terminal new rust my-project
/// cx-terminal new python --name my-project --dir /path/to/projects
/// cx-terminal new --list
Comment thread wezterm/src/cli/new.rs
Comment on lines +199 to +200
} else if current_dir.join("package.json").exists() {
"node"
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements the new command, transitioning it from a stub to a functional project scaffolding tool. It introduces a template system supporting various languages and frameworks (Rust, Python, Node, etc.), project name validation, and automatic directory setup. Feedback focused on improving documentation syntax, optimizing template storage using lazy initialization, ensuring consistency in virtual environment creation for Python-based templates, and clarifying placeholder usage in Docker configurations.

Comment thread wezterm/src/cli/new.rs
Comment on lines +6 to +10
// CX Terminal: Create new projects from templates.
//
// This module provides the `new` command for creating new projects
// from predefined templates. Templates include common project types
// like Rust, Python, Node.js, and more.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The module-level comments should use the //! syntax for documentation that applies to the entire module, which will be picked up by rustdoc. This was also the style used previously in this file.

Suggested change
// CX Terminal: Create new projects from templates.
//
// This module provides the `new` command for creating new projects
// from predefined templates. Templates include common project types
// like Rust, Python, Node.js, and more.
//! CX Terminal: Create new projects from templates.
//!
//! This module provides the `new` command for creating new projects
//! from predefined templates. Templates include common project types
//! like Rust, Python, Node.js, and more.

Comment thread wezterm/src/cli/new.rs
sanitized
}

fn templates() -> Vec<Template> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The templates() function constructs a large Vec<Template> every time it's called. This can be inefficient, as it involves heap allocations and processing for all template definitions on each call.

Since the templates are static, this vector should be created only once. You can use once_cell::sync::Lazy to ensure the vector is initialized lazily and stored in a static variable.

Here's how you could refactor it:

use once_cell::sync::Lazy; // Add to imports

static TEMPLATES: Lazy<Vec<Template>> = Lazy::new(|| {
    vec![
        // ... all template definitions here ...
    ]
});

fn templates() -> &'static [Template] {
    &TEMPLATES
}

You would also need to update functions that call templates() (like find_template and print_available_templates) to work with a slice &[Template] instead of an owned Vec<Template>. For example, find_template would need to .cloned() the result.

Comment thread wezterm/src/cli/new.rs
Comment on lines +742 to +748
create_python_venv: false,
next_steps: vec![
"cd {{project_name}}",
"python3 -m venv .venv && source .venv/bin/activate",
"pip install -r requirements.txt",
"uvicorn app.main:app --reload",
],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The fastapi template is configured with create_python_venv: false, which is inconsistent with the python template (create_python_venv: true). Both are Python-based projects, and automatically creating the virtual environment provides a better and more consistent user experience.

I suggest setting create_python_venv: true for the fastapi template and updating the next_steps to reflect that the venv is already created.

Suggested change
create_python_venv: false,
next_steps: vec![
"cd {{project_name}}",
"python3 -m venv .venv && source .venv/bin/activate",
"pip install -r requirements.txt",
"uvicorn app.main:app --reload",
],
create_python_venv: true,
next_steps: vec![
"cd {{project_name}}",
"source .venv/bin/activate",
"pip install -r requirements.txt",
"uvicorn app.main:app --reload",
],

Comment thread wezterm/src/cli/new.rs
TemplateFile {
path: "docker-compose.yml",
contents: r#"services:
{{python_module}}:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The service name in the docker-compose.yml for the docker template is using {{python_module}}. This placeholder is typically for sanitized Python module names (e.g., my_app) and is confusing in a generic Docker template.

For better clarity and convention, you should use {{package_name}} (e.g., my-app), which is also used for the container_name.

Suggested change
{{python_module}}:
{{package_name}}:

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.

[FEATURE] Implement cx new project template scaffolding

2 participants