Skip to content

fix: cli create command directory display and cleanup on interruption #5321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from

Conversation

yungalgo
Copy link
Member

@yungalgo yungalgo commented Jun 30, 2025

Fix CLI create command directory display and cleanup on interruption

Problem

Two minor bugs with the elizaos create command:

  1. Confusing directory display: When creating a project/plugin, the confirmation prompt showed "Create plugin 'testing' in plugin-testing?" instead of the actual directory name (e.g., "Create 'plugin-testing' in Desktop?")

  2. Abandoned directories on Ctrl-C: Pressing Ctrl-C during bun install during a plugin or project installation left partially created directories behind, requiring manual cleanup

Solution

  1. Directory display: Added getDisplayDirectory() helper that gives the current directory name and simplifies absolute paths to just the directory name

  2. Cleanup on interruption: Implemented withCleanupOnInterrupt() wrapper that:

    • Registers signal handlers (SIGINT/SIGTERM) before creating directories
    • Tracks directory creation state to avoid removing pre-existing directories
    • Automatically removes partially created directories on interruption
    • Shows red-colored cleanup messages for visibility

Details

Implementation

  • Signal handlers are registered at the create function level, ensuring cleanup even when child processes (like bun install) receive signals directly
  • Handlers are properly removed on success to prevent memory leaks
  • Simplified installDependencies and buildProject functions since cleanup is now handled at a higher level

Files Changed

  • src/commands/create/actions/creators.ts - Added cleanup wrapper and updated all create functions
  • src/commands/create/actions/setup.ts - Simplified after moving cleanup logic up
  • src/utils/helpers.ts - Added getDisplayDirectory() helper
  • tests/commands/create.test.ts - Added test for cleanup behavior

Testing

Run the full test suite:

bun test tests/commands/create.test.ts

Manual test:

bun run dist/index.js create test-plugin --type plugin
# Press Ctrl-C during "Installing dependencies..."
# Directory should be cleaned up automatically

Summary by CodeRabbit

  • New Features

    • Improved project creation process to automatically clean up incomplete directories if interrupted or if an error occurs.
    • Enhanced user prompts to display more user-friendly directory names.
  • Bug Fixes

    • Prevents leftover incomplete directories when project creation is interrupted or fails.
  • Tests

    • Added tests to verify directory cleanup when project creation is interrupted (e.g., via Ctrl-C).

@yungalgo yungalgo requested review from wtfsayo and Copilot June 30, 2025 13:51
@yungalgo yungalgo self-assigned this Jun 30, 2025
@yungalgo yungalgo added the 1.x V2 label Jun 30, 2025
@yungalgo yungalgo added this to Eliza Jun 30, 2025
Copy link
Contributor

coderabbitai bot commented Jun 30, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Robust cleanup logic was added to the project and plugin creation commands, ensuring incomplete directories are removed if the process is interrupted or fails. A utility for user-friendly directory display was introduced, dependency installation was refactored for better signal handling, and a test verifies cleanup on interruption.

Changes

File(s) Change Summary
.../create/actions/creators.ts Added withCleanupOnInterrupt for cleanup on interruption; updated creation functions to use it; improved prompt directory display.
.../create/actions/setup.ts Replaced runBunCommand with direct execa call for dependency install; improved signal handling and comments.
.../utils/build-project.ts Updated comments and JSDoc to clarify cleanup responsibility; no logic changes.
.../utils/helpers.ts Added getDisplayDirectory utility for user-friendly directory names in prompts.
.../tests/commands/create.test.ts Added test to verify directory cleanup when creation is interrupted by SIGINT.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant OS

    User->>CLI: Run create command
    CLI->>CLI: Call withCleanupOnInterrupt
    CLI->>CLI: Start project/plugin creation
    CLI->>CLI: Install dependencies (execa bun install)
    OS-->>CLI: (Possible SIGINT/SIGTERM)
    alt Interrupted or Error
        CLI->>CLI: Cleanup handler deletes target directory
    else Success
        CLI->>CLI: Complete creation
    end
    CLI->>User: Show result
Loading

Suggested reviewers

  • wtfsayo

Poem

When projects are born but cut short by fate,
Cleanup now sweeps up before it’s too late.
Directories vanish, no mess left behind,
Prompts are more friendly, with clarity in mind.
Tests prove it works—onwards we go,
Tidier journeys for all in the flow! 🚀

✨ Finishing Touches
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch fix/cli-create-cleanup

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

graphite-app bot commented Jun 30, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • merge-queue-hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@yungalgo
Copy link
Member Author

@coderabbitai full review

Copilot

This comment was marked as outdated.

Copy link
Contributor

coderabbitai bot commented Jun 30, 2025

✅ Actions performed

Full review triggered.

Copy link
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.

Actionable comments posted: 4

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 00b8177 and b842754.

📒 Files selected for processing (5)
  • packages/cli/src/commands/create/actions/creators.ts (8 hunks)
  • packages/cli/src/commands/create/actions/setup.ts (3 hunks)
  • packages/cli/src/utils/build-project.ts (2 hunks)
  • packages/cli/src/utils/helpers.ts (1 hunks)
  • packages/cli/tests/commands/create.test.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: wtfsayo
PR: elizaOS/eliza#0
File: :0-0
Timestamp: 2025-01-18T14:10:19.334Z
Learning: PR #2485 includes significant changes beyond the initially described chat-bubble and version.sh updates, including a new plugin-di package, Solana plugin updates, and i18n improvements.
Learnt from: CR
PR: elizaOS/eliza#0
File: packages/cli/src/utils/upgrade/CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:49.972Z
Learning: Applies to packages/cli/src/utils/upgrade/**/*.{ts,tsx} : Ensure proper plugin structure by exporting a Plugin object with name, version, actions, providers, evaluators, and services.
Learnt from: CR
PR: elizaOS/eliza#0
File: packages/cli/src/utils/upgrade/CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:49.972Z
Learning: Applies to packages/cli/src/utils/upgrade/**/*.{test,spec}.{ts,tsx} : Create comprehensive unit and integration tests: test all actions, providers, evaluators, service initialization and lifecycle, event handling, memory operations, and error handling.
packages/cli/src/utils/helpers.ts (5)
Learnt from: CR
PR: elizaOS/eliza#0
File: .cursorrules:0-0
Timestamp: 2025-06-30T09:27:56.759Z
Learning: Applies to **/*.{ts,tsx} : Descriptive variable and function names
Learnt from: wtfsayo
PR: elizaOS/eliza#2389
File: packages/client-direct/src/api.ts:181-191
Timestamp: 2025-01-17T12:46:49.173Z
Learning: When implementing file storage in the character system, ensure the target directory exists using `fs.promises.mkdir` with `recursive: true` option, and use `elizaLogger` for proper error logging instead of console.log.
Learnt from: CR
PR: elizaOS/eliza#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:32.208Z
Learning: Applies to packages/{cli,client,app,server,api-client,plugin-bootstrap,plugin-sql,plugin-starter,project-starter,project-tee-starter,autodoc,docs,create-eliza}/src/**/*.{ts,tsx} : Use `@elizaos/core` for imports in package code, and `packages/core` for internal references
Learnt from: CR
PR: elizaOS/eliza#0
File: packages/cli/src/utils/upgrade/CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:49.972Z
Learning: Applies to packages/cli/src/utils/upgrade/**/*.{ts,tsx} : All @elizaos imports must be updated to use the new paths (e.g., import { logger } from '@elizaos/core'; instead of import { elizaLogger } from '@elizaos/core';).
Learnt from: wtfsayo
PR: elizaOS/eliza#0
File: :0-0
Timestamp: 2025-01-16T10:45:27.955Z
Learning: The AgentKit plugin for Eliza supports Base Sepolia network and provides integration with CDP AgentKit tools for managing NFTs and tokens. The implementation includes proper error handling, wallet data persistence, and comprehensive context templates for natural language interactions.
packages/cli/src/utils/build-project.ts (15)
Learnt from: CR
PR: elizaOS/eliza#0
File: .cursorrules:0-0
Timestamp: 2025-06-30T09:27:56.759Z
Learning: Applies to **/*.{ts,tsx} : Don't comment change notes
Learnt from: CR
PR: elizaOS/eliza#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:32.208Z
Learning: Applies to **/*.{ts,tsx} : Comment complex logic, but do not comment change notes
Learnt from: CR
PR: elizaOS/eliza#0
File: .cursorrules:0-0
Timestamp: 2025-06-30T09:27:56.759Z
Learning: Applies to **/*.{ts,tsx} : Never omit code or add an "// ..." as it risks breaking the codebase
Learnt from: CR
PR: elizaOS/eliza#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:32.208Z
Learning: Applies to **/*.{ts,tsx} : Never omit code or add '// ...' as it risks breaking the codebase
Learnt from: CR
PR: elizaOS/eliza#0
File: .cursorrules:0-0
Timestamp: 2025-06-30T09:27:56.759Z
Learning: Applies to **/*.{ts,tsx} : Comment complex logic
Learnt from: CR
PR: elizaOS/eliza#0
File: packages/cli/src/utils/upgrade/CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:49.972Z
Learning: Applies to packages/cli/src/utils/upgrade/**/*.{ts,tsx} : Ensure proper plugin structure by exporting a Plugin object with name, version, actions, providers, evaluators, and services.
Learnt from: CR
PR: elizaOS/eliza#0
File: packages/cli/src/utils/upgrade/CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:49.972Z
Learning: Applies to packages/cli/src/utils/upgrade/**/*.{ts,tsx} : Update all type references: Account → Entity, userId → entityId, room → world (agent-side abstraction only), IAgentRuntime → AgentRuntime.
Learnt from: CR
PR: elizaOS/eliza#0
File: packages/cli/src/utils/upgrade/CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:49.972Z
Learning: Applies to packages/cli/src/utils/upgrade/**/package.json : Update package.json dependencies to use '@elizaos/core' version ^1.0.0 and update scripts to use vitest and tsup.
Learnt from: CR
PR: elizaOS/eliza#0
File: packages/cli/src/utils/upgrade/CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:49.972Z
Learning: Applies to packages/cli/src/utils/upgrade/**/*.{ts,tsx} : Implement proper event emission and handling using this.runtime.emit and this.runtime.on.
Learnt from: CR
PR: elizaOS/eliza#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:32.208Z
Learning: Applies to packages/cli/src/index.ts : CLI entry point must be in `packages/cli/src/index.ts`
Learnt from: CR
PR: elizaOS/eliza#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:32.208Z
Learning: Do not use the `elizaos` CLI within the `eliza` monorepo itself; use `bun` commands for monorepo development
Learnt from: CR
PR: elizaOS/eliza#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:32.208Z
Learning: Applies to **/*.test.{ts,tsx} : Use Bun's built-in test runner for all tests
Learnt from: CR
PR: elizaOS/eliza#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:32.208Z
Learning: NEVER USE `npm` OR `pnpm` for package management or script execution; ALWAYS USE `bun`
Learnt from: wtfsayo
PR: elizaOS/eliza#0
File: :0-0
Timestamp: 2025-06-22T17:42:23.153Z
Learning: In the elizaOS/eliza repository, always use bun:test for testing instead of jest or vitest. Import testing utilities from 'bun:test' rather than '@jest/globals' or other testing frameworks.
Learnt from: CR
PR: elizaOS/eliza#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:32.208Z
Learning: Applies to **/!(*.e2e).test.{ts,tsx} : Unit tests must use Bun test with standard primitives
packages/cli/tests/commands/create.test.ts (10)
Learnt from: CR
PR: elizaOS/eliza#0
File: packages/cli/src/utils/upgrade/CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:49.972Z
Learning: Applies to packages/cli/src/utils/upgrade/**/*.{test,spec}.{ts,tsx} : Create comprehensive unit and integration tests: test all actions, providers, evaluators, service initialization and lifecycle, event handling, memory operations, and error handling.
Learnt from: CR
PR: elizaOS/eliza#0
File: .cursorrules:0-0
Timestamp: 2025-06-30T09:27:56.759Z
Learning: Applies to **/*.test.{ts,tsx} : Verify tests are complete and passing before declaring changes correct
Learnt from: CR
PR: elizaOS/eliza#0
File: packages/cli/src/utils/upgrade/CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:49.972Z
Learning: Applies to packages/cli/src/utils/upgrade/**/*.{ts,tsx} : Ensure proper plugin structure by exporting a Plugin object with name, version, actions, providers, evaluators, and services.
Learnt from: CR
PR: elizaOS/eliza#0
File: .cursorrules:0-0
Timestamp: 2025-06-30T09:27:56.759Z
Learning: Applies to **/*.{ts,tsx} : Work on files until they are perfect, looping testing and fixing until all tests pass
Learnt from: CR
PR: elizaOS/eliza#0
File: .cursorrules:0-0
Timestamp: 2025-06-30T09:27:56.759Z
Learning: Applies to **/{unit,component}/**/*.test.{ts,tsx} : Unit tests use vitest with standard primitives and test individual components in isolation
Learnt from: CR
PR: elizaOS/eliza#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:32.208Z
Learning: Applies to **/!(*.e2e).test.{ts,tsx} : Unit tests must use Bun test with standard primitives
Learnt from: CR
PR: elizaOS/eliza#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:32.208Z
Learning: Applies to **/*.test.{ts,tsx} : Use Bun's built-in test runner for all tests
Learnt from: simsaidev
PR: elizaOS/eliza#2614
File: packages/client-simsai/src/index.ts:0-0
Timestamp: 2025-01-21T17:38:50.416Z
Learning: Stop methods in clients should include comprehensive error handling with try-catch blocks, proper cleanup (e.g., calling stop on all sub-components), error logging, and success confirmation logs. Example pattern:
```typescript
try {
  await cleanup1();
  await cleanup2();
  log.info("Cleanup successful");
} catch (error) {
  log.error("Cleanup failed:", error);
  throw error;
}
```
Learnt from: wtfsayo
PR: elizaOS/eliza#0
File: :0-0
Timestamp: 2025-06-22T17:42:23.153Z
Learning: In the elizaOS/eliza repository, always use bun:test for testing instead of jest or vitest. Import testing utilities from 'bun:test' rather than '@jest/globals' or other testing frameworks.
Learnt from: CR
PR: elizaOS/eliza#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:32.208Z
Learning: Applies to **/*.e2e.test.{ts,tsx} : E2E tests must use actual runtime with real integrations
packages/cli/src/commands/create/actions/setup.ts (14)
Learnt from: CR
PR: elizaOS/eliza#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:32.208Z
Learning: Applies to packages/cli/src/index.ts : CLI entry point must be in `packages/cli/src/index.ts`
Learnt from: CR
PR: elizaOS/eliza#0
File: packages/cli/src/utils/upgrade/CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:49.972Z
Learning: Applies to packages/cli/src/utils/upgrade/**/*.{ts,tsx} : All @elizaos imports must be updated to use the new paths (e.g., import { logger } from '@elizaos/core'; instead of import { elizaLogger } from '@elizaos/core';).
Learnt from: CR
PR: elizaOS/eliza#0
File: packages/cli/src/utils/upgrade/CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:49.972Z
Learning: Applies to packages/cli/src/utils/upgrade/**/*.{ts,tsx} : Implement proper event emission and handling using this.runtime.emit and this.runtime.on.
Learnt from: CR
PR: elizaOS/eliza#0
File: packages/cli/src/utils/upgrade/CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:49.972Z
Learning: Applies to packages/cli/src/utils/upgrade/**/package.json : Update package.json dependencies to use '@elizaos/core' version ^1.0.0 and update scripts to use vitest and tsup.
Learnt from: CR
PR: elizaOS/eliza#0
File: packages/cli/src/utils/upgrade/CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:49.972Z
Learning: Applies to packages/cli/src/utils/upgrade/**/*.{ts,tsx} : Convert generateText calls to runtime.useModel with the new message-based API.
Learnt from: CR
PR: elizaOS/eliza#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:32.208Z
Learning: Do not use the `elizaos` CLI within the `eliza` monorepo itself; use `bun` commands for monorepo development
Learnt from: CR
PR: elizaOS/eliza#0
File: packages/cli/src/utils/upgrade/CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:49.972Z
Learning: Applies to packages/cli/src/utils/upgrade/**/*.{ts,tsx} : Update all type references: Account → Entity, userId → entityId, room → world (agent-side abstraction only), IAgentRuntime → AgentRuntime.
Learnt from: CR
PR: elizaOS/eliza#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:32.208Z
Learning: Applies to packages/{cli,client,app,server,api-client,plugin-bootstrap,plugin-sql,plugin-starter,project-starter,project-tee-starter,autodoc,docs,create-eliza}/src/**/*.{ts,tsx} : Use `@elizaos/core` for imports in package code, and `packages/core` for internal references
Learnt from: wtfsayo
PR: elizaOS/eliza#0
File: :0-0
Timestamp: 2025-06-22T17:42:23.153Z
Learning: In the elizaOS/eliza repository, always use bun:test for testing instead of jest or vitest. Import testing utilities from 'bun:test' rather than '@jest/globals' or other testing frameworks.
Learnt from: CR
PR: elizaOS/eliza#0
File: packages/cli/src/utils/upgrade/CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:49.972Z
Learning: Applies to packages/cli/src/utils/upgrade/**/*.{ts,tsx} : Ensure proper plugin structure by exporting a Plugin object with name, version, actions, providers, evaluators, and services.
Learnt from: CR
PR: elizaOS/eliza#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:32.208Z
Learning: NEVER USE `npm` OR `pnpm` for package management or script execution; ALWAYS USE `bun`
Learnt from: wtfsayo
PR: elizaOS/eliza#2389
File: packages/client-direct/src/api.ts:181-191
Timestamp: 2025-01-17T12:46:49.173Z
Learning: When implementing file storage in the character system, ensure the target directory exists using `fs.promises.mkdir` with `recursive: true` option, and use `elizaLogger` for proper error logging instead of console.log.
Learnt from: yungalgo
PR: elizaOS/eliza#4813
File: packages/project-starter/package.json:9-9
Timestamp: 2025-05-28T16:15:33.419Z
Learning: Project starter packages like @elizaos/project-starter are templates that users copy rather than install as dependencies, so minor path inconsistencies in package.json entry points are less critical than for published packages.
Learnt from: CR
PR: elizaOS/eliza#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:32.208Z
Learning: Applies to **/*.test.{ts,tsx} : Use Bun's built-in test runner for all tests
packages/cli/src/commands/create/actions/creators.ts (13)
Learnt from: CR
PR: elizaOS/eliza#0
File: packages/cli/src/utils/upgrade/CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:49.972Z
Learning: Applies to packages/cli/src/utils/upgrade/**/*.{ts,tsx} : Ensure proper plugin structure by exporting a Plugin object with name, version, actions, providers, evaluators, and services.
Learnt from: CR
PR: elizaOS/eliza#0
File: packages/cli/src/utils/upgrade/CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:49.972Z
Learning: Applies to packages/cli/src/utils/upgrade/**/*.{test,spec}.{ts,tsx} : Create comprehensive unit and integration tests: test all actions, providers, evaluators, service initialization and lifecycle, event handling, memory operations, and error handling.
Learnt from: CR
PR: elizaOS/eliza#0
File: packages/cli/src/utils/upgrade/CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:49.972Z
Learning: Applies to packages/cli/src/utils/upgrade/**/*.{ts,tsx} : Convert generateText calls to runtime.useModel with the new message-based API.
Learnt from: CR
PR: elizaOS/eliza#0
File: packages/cli/src/utils/upgrade/CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:49.972Z
Learning: Applies to packages/cli/src/utils/upgrade/**/*.{ts,tsx} : Services must now extend the base Service class from '@elizaos/core' and implement lifecycle methods: initialize, start, and stop.
Learnt from: CR
PR: elizaOS/eliza#0
File: packages/cli/src/utils/upgrade/CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:49.972Z
Learning: Applies to packages/cli/src/utils/upgrade/**/*.{ts,tsx} : All @elizaos imports must be updated to use the new paths (e.g., import { logger } from '@elizaos/core'; instead of import { elizaLogger } from '@elizaos/core';).
Learnt from: CR
PR: elizaOS/eliza#0
File: packages/cli/src/utils/upgrade/CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:49.972Z
Learning: Applies to packages/cli/src/utils/upgrade/**/*.{ts,tsx} : Implement proper event emission and handling using this.runtime.emit and this.runtime.on.
Learnt from: CR
PR: elizaOS/eliza#0
File: packages/cli/src/utils/upgrade/CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:49.972Z
Learning: Applies to packages/cli/src/utils/upgrade/**/*.{ts,tsx} : Update memory operations to use the new API with table names (use runtime.memory.create with entityId, worldId, content, and tableName).
Learnt from: CR
PR: elizaOS/eliza#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:32.208Z
Learning: Applies to packages/cli/src/index.ts : CLI entry point must be in `packages/cli/src/index.ts`
Learnt from: CR
PR: elizaOS/eliza#0
File: .cursorrules:0-0
Timestamp: 2025-06-30T09:27:56.759Z
Learning: Applies to **/*.{ts,tsx} : Comprehensive error handling required
Learnt from: CR
PR: elizaOS/eliza#0
File: CLAUDE.md:0-0
Timestamp: 2025-06-30T09:28:32.208Z
Learning: Applies to **/*.{ts,tsx} : Comprehensive error handling required
Learnt from: wtfsayo
PR: elizaOS/eliza#0
File: :0-0
Timestamp: 2025-01-21T10:42:58.166Z
Learning: New plugins must be imported in both `agent/package.json` (as a dependency) and `agent/src/index.ts` (for initialization) to be properly integrated into the system.
Learnt from: wtfsayo
PR: elizaOS/eliza#2389
File: packages/client-direct/src/api.ts:181-191
Timestamp: 2025-01-17T12:46:49.173Z
Learning: When implementing file storage in the character system, ensure the target directory exists using `fs.promises.mkdir` with `recursive: true` option, and use `elizaLogger` for proper error logging instead of console.log.
Learnt from: yungalgo
PR: elizaOS/eliza#4813
File: packages/project-starter/package.json:9-9
Timestamp: 2025-05-28T16:15:33.419Z
Learning: Project starter packages like @elizaos/project-starter are templates that users copy rather than install as dependencies, so minor path inconsistencies in package.json entry points are less critical than for published packages.
🧬 Code Graph Analysis (2)
packages/cli/src/utils/build-project.ts (1)
packages/cli/src/utils/run-bun.ts (1)
  • runBunCommand (10-44)
packages/cli/tests/commands/create.test.ts (2)
packages/cli/tests/commands/test-utils.ts (1)
  • crossPlatform (503-529)
packages/cli/tests/test-timeouts.ts (1)
  • TEST_TIMEOUTS (12-106)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: databaseIntegrationTests
  • GitHub Check: test (ubuntu-latest)
  • GitHub Check: test (macos-latest)
  • GitHub Check: test (windows-latest)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (3)
packages/cli/src/commands/create/actions/setup.ts (1)

340-351: Good subprocess handling with proper SIGINT support!

The direct use of execa with reject: false and explicit exit code handling is the right approach for graceful interruption support.

packages/cli/src/commands/create/actions/creators.ts (2)

295-301: Smart handling of current directory case!

Good design decision to skip cleanup wrapper for current directory to prevent accidental deletion.


23-33: Add existence check to prevent unnecessary cleanup attempts

The cleanup function should verify the directory exists before attempting removal to avoid errors.

   const cleanup = () => {
-    if (directoryCreated && existsSync(targetDir)) {
+    // Only cleanup if we created it and it still exists
+    if (directoryCreated && existsSync(targetDir)) {
       console.info(colors.red(`\n\nInterrupted! Cleaning up ${displayName}...`));
       try {
         rmSync(targetDir, { recursive: true, force: true });
         console.info('Cleanup completed.');
       } catch (error) {
-        console.error(colors.red('Error during cleanup:'), error);
+        // Only log if directory still exists (could be race condition)
+        if (existsSync(targetDir)) {
+          console.error(colors.red('Error during cleanup:'), error);
+        }
       }
     }
   };
⛔ Skipped due to learnings
Learnt from: simsaidev
PR: elizaOS/eliza#2614
File: packages/client-simsai/src/index.ts:0-0
Timestamp: 2025-01-21T17:38:50.416Z
Learning: Stop methods in clients should include comprehensive error handling with try-catch blocks, proper cleanup (e.g., calling stop on all sub-components), error logging, and success confirmation logs. Example pattern:
```typescript
try {
  await cleanup1();
  await cleanup2();
  log.info("Cleanup successful");
} catch (error) {
  log.error("Cleanup failed:", error);
  throw error;
}
```
Learnt from: wtfsayo
PR: elizaOS/eliza#2389
File: packages/client-direct/src/api.ts:181-191
Timestamp: 2025-01-17T12:46:49.173Z
Learning: When implementing file storage in the character system, ensure the target directory exists using `fs.promises.mkdir` with `recursive: true` option, and use `elizaLogger` for proper error logging instead of console.log.

@yungalgo yungalgo changed the title Fix/cli create cleanup fix: cli create command directory display and cleanup on interruption Jun 30, 2025
@yungalgo yungalgo marked this pull request as ready for review June 30, 2025 15:04
cursor[bot]

This comment was marked as outdated.

@wtfsayo wtfsayo requested a review from Copilot June 30, 2025 15:34
Copy link
Contributor

@Copilot 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

This PR improves the elizaos create command by displaying user-friendly directory names and automatically cleaning up partially created directories when interrupted.

  • Introduces getDisplayDirectory() to simplify prompts by showing only the directory basename.
  • Adds withCleanupOnInterrupt() wrapper to handle SIGINT/SIGTERM and remove incomplete directories.
  • Updates install and build flows to delegate cleanup and adjusts tests to cover interruption scenarios.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/cli/tests/commands/create.test.ts Added a test case to verify directory cleanup on SIGINT interrupt
packages/cli/src/utils/helpers.ts Implemented getDisplayDirectory() helper for prompt messages
packages/cli/src/utils/build-project.ts Updated comments to note cleanup is handled upstream
packages/cli/src/commands/create/actions/setup.ts Switched installDependencies to execa and removed local cleanup
packages/cli/src/commands/create/actions/creators.ts Added withCleanupOnInterrupt and hooked it into all create flows
Comments suppressed due to low confidence (3)

packages/cli/src/utils/helpers.ts:8

  • The doc comment specifically mentions mapping "." to "Desktop", but the implementation returns path.basename(process.cwd()). Update the comment to reflect that it returns the current working directory's base name rather than always "Desktop".
 * converts paths like "." to "Desktop" or "/Users/me/Desktop" to "Desktop"

packages/cli/src/commands/create/actions/creators.ts:301

  • [nitpick] The displayName parameter is passed as projectName, which may not clearly represent the directory being cleaned up. Consider passing a more descriptive label (e.g., the directory basename or displayProjectName) for clearer cleanup messages.
    await withCleanupOnInterrupt(projectTargetDir, projectName, createFn);

packages/cli/tests/commands/create.test.ts:356

  • Using fixed setTimeout delays can lead to flaky tests if the process startup time varies. Consider polling for the directory or listening to process output/events to determine when to send SIGINT.
        await new Promise((resolve) => setTimeout(resolve, 1500));

cursor[bot]

This comment was marked as outdated.

@yungalgo
Copy link
Member Author

yungalgo commented Jul 1, 2025

@wtfsayo fixed the bugbot nitpick

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

yungalgo and others added 3 commits July 1, 2025 14:53
…type-text

fix: (cli) show correct type in create command messages
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@wtfsayo
Copy link
Member

wtfsayo commented Jul 1, 2025

bugbot run

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

✅ BugBot reviewed your changes and found no bugs!


Was this report helpful? Give feedback by reacting with 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants