Skip to content

feat(agent/agentcontainers): auto detect dev containers #18950

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

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

DanielleMaywood
Copy link
Contributor

@DanielleMaywood DanielleMaywood commented Jul 21, 2025

Summary by CodeRabbit

  • New Features

    • Automatic detection of devcontainer projects within agent directories, including support for Git repositories and nested configurations.
    • Added a new Storybook scenario for devcontainers with no container, agent, or sub-agents.
  • Bug Fixes

    • Improved logic for displaying the parent apps section, now only hiding it if a devcontainer is running or starting.
  • UI Improvements

    • Updated devcontainer card to display the config path as a fallback name and adjusted the rebuild button to show "Start" when appropriate.
  • Tests

    • Introduced comprehensive tests for devcontainer discovery using simulated filesystems.

Copy link

coderabbitai bot commented Jul 21, 2025

Important

Review skipped

Draft detected.

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

The changes introduce automatic discovery of devcontainer projects within agent directories, update the API initialization to support this, and expand manifest information handling. Tests are added for the discovery feature. UI adjustments include new Storybook scenarios, conditional button labeling, fallback display logic, debug logging, and refined control of app section visibility based on devcontainer status.

Changes

File(s) Change Summary
agent/agent.go Passes agent directory as a fourth parameter to WithManifestInfo during container API initialization.
agent/agentcontainers/api.go Adds devcontainer discovery on startup, filesystem abstraction, agent directory tracking, and new options.
agent/agentcontainers/api_test.go Adds tests for devcontainer discovery using in-memory filesystem; updates manifest info usage in tests.
site/src/modules/resources/AgentDevcontainerCard.stories.tsx Adds a Storybook story for a devcontainer with no container, agent, or sub-agents.
site/src/modules/resources/AgentDevcontainerCard.tsx Adds debug logging, fallback display logic for names, and conditional button labeling in the UI.
site/src/modules/resources/AgentRow.tsx Refines logic for hiding parent apps section based on devcontainer running/starting status.

Sequence Diagram(s)

sequenceDiagram
    participant Agent as Agent
    participant ContainerAPI as Container API
    participant FS as Filesystem

    Agent->>ContainerAPI: Init(WithManifestInfo(..., agentDirectory))
    ContainerAPI->>FS: On start, discoverDevcontainerProjects()
    FS-->>ContainerAPI: List directories, check for .git and devcontainer configs
    ContainerAPI->>ContainerAPI: Update knownDevcontainers map
Loading

Estimated code review effort

4 (~90 minutes)

Poem

A rabbit hopped through code so neat,
Discovering devcontainers—what a feat!
With stories told and buttons smart,
And parent apps that play their part.
Debug logs here, new tests appear,
This burrow’s grown more clever this year!
🐰💻✨


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

@DanielleMaywood
Copy link
Contributor Author

@coderabbitai review

Copy link

coderabbitai bot commented Jul 21, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link

@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: 3

🧹 Nitpick comments (3)
agent/agentcontainers/api.go (3)

393-398: Consider tracking discovery completion state.

The discovery runs asynchronously without tracking completion. This could result in incomplete devcontainer lists being returned before discovery finishes.

Consider adding a discovery completion channel or atomic boolean to track when initial discovery is complete, similar to how initDone is used.


403-407: Improve error message clarity.

The error message is misleading - it describes what was being checked rather than what failed.

Apply this diff to improve the error message:

-	isGitProject, err := afero.DirExists(api.fs, filepath.Join(api.agentDirectory, "/.git"))
-	if err != nil {
-		return xerrors.Errorf(".git dir exists: %w", err)
-	}
+	isGitProject, err := afero.DirExists(api.fs, filepath.Join(api.agentDirectory, "/.git"))
+	if err != nil {
+		return xerrors.Errorf("check .git directory: %w", err)
+	}

429-432: Improve error message clarity.

Same issue with misleading error message.

Apply this diff:

-		isGitProject, err = afero.DirExists(api.fs, filepath.Join(api.agentDirectory, entry.Name(), ".git"))
-		if err != nil {
-			return xerrors.Errorf(".git dir exists: %w", err)
-		}
+		isGitProject, err = afero.DirExists(api.fs, filepath.Join(api.agentDirectory, entry.Name(), ".git"))
+		if err != nil {
+			return xerrors.Errorf("check .git directory in %s: %w", entry.Name(), err)
+		}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4ac6be6 and c3620e2.

📒 Files selected for processing (6)
  • agent/agent.go (1 hunks)
  • agent/agentcontainers/api.go (8 hunks)
  • agent/agentcontainers/api_test.go (4 hunks)
  • site/src/modules/resources/AgentDevcontainerCard.stories.tsx (1 hunks)
  • site/src/modules/resources/AgentDevcontainerCard.tsx (3 hunks)
  • site/src/modules/resources/AgentRow.tsx (1 hunks)
🧰 Additional context used
🧠 Learnings (4)
site/src/modules/resources/AgentRow.tsx (1)

Learnt from: CR
PR: coder/coder#0
File: site/CLAUDE.md:0-0
Timestamp: 2025-07-21T14:33:50.919Z
Learning: Applies to site/src/**/*.tsx : Use functional updates (setX(prev ⇒ …)) whenever next state depends on previous state.

site/src/modules/resources/AgentDevcontainerCard.tsx (4)

Learnt from: CR
PR: coder/coder#0
File: site/CLAUDE.md:0-0
Timestamp: 2025-07-21T14:33:50.919Z
Learning: Applies to site/src/**/*.tsx : Group related Tailwind classes

Learnt from: CR
PR: coder/coder#0
File: site/CLAUDE.md:0-0
Timestamp: 2025-07-21T14:33:50.919Z
Learning: Applies to site/src/**/*.tsx : Responsive design - use Tailwind's responsive prefixes (sm:, md:, lg:, xl:)

Learnt from: CR
PR: coder/coder#0
File: site/CLAUDE.md:0-0
Timestamp: 2025-07-21T14:33:50.919Z
Learning: Applies to site/src/**/*.tsx : Use className with clsx for conditional styling

Learnt from: CR
PR: coder/coder#0
File: site/CLAUDE.md:0-0
Timestamp: 2025-07-21T14:33:50.919Z
Learning: Applies to site/src/**/*.tsx : Use Tailwind classes for all new styling

agent/agentcontainers/api.go (4)

Learnt from: CR
PR: coder/coder#0
File: .cursorrules:0-0
Timestamp: 2025-07-21T14:32:43.035Z
Learning: Applies to **/*.go : Coder emphasizes clear error handling, with specific patterns required: Concise error messages that avoid phrases like "failed to"; Wrapping errors with %w to maintain error chains; Using sentinel errors with the "err" prefix (e.g., errNotFound).

Learnt from: CR
PR: coder/coder#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-21T14:32:56.474Z
Learning: Applies to **/*.go : OAuth2-compliant error responses must use writeOAuth2Error in Go code

Learnt from: CR
PR: coder/coder#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-21T14:32:56.474Z
Learning: Applies to **/*.go : Follow Uber Go Style Guide

Learnt from: CR
PR: coder/coder#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-21T14:32:56.474Z
Learning: Applies to **/*_test.go : Use unique identifiers in concurrent Go tests to prevent race conditions (e.g., fmt.Sprintf with t.Name() and time.Now().UnixNano())

agent/agentcontainers/api_test.go (6)

Learnt from: CR
PR: coder/coder#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-21T14:32:56.474Z
Learning: Applies to **/*_test.go : Never use hardcoded names in concurrent Go tests

Learnt from: CR
PR: coder/coder#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-21T14:32:56.474Z
Learning: Applies to **/*_test.go : Use unique identifiers in concurrent Go tests to prevent race conditions (e.g., fmt.Sprintf with t.Name() and time.Now().UnixNano())

Learnt from: CR
PR: coder/coder#0
File: CLAUDE.md:0-0
Timestamp: 2025-07-21T14:32:56.474Z
Learning: Applies to **/*.go : Follow Uber Go Style Guide

Learnt from: CR
PR: coder/coder#0
File: .cursorrules:0-0
Timestamp: 2025-07-21T14:32:43.034Z
Learning: Applies to coderd/coderd.go : The REST API is defined in coderd/coderd.go and uses Chi for HTTP routing.

Learnt from: CR
PR: coder/coder#0
File: .cursorrules:0-0
Timestamp: 2025-07-21T14:32:43.035Z
Learning: Applies to **/*_test.go : All tests must use t.Parallel() to run concurrently, which improves test suite performance and helps identify race conditions.

Learnt from: CR
PR: coder/coder#0
File: .cursorrules:0-0
Timestamp: 2025-07-21T14:32:43.035Z
Learning: Applies to **/*_test.go : All tests should run in parallel using t.Parallel() to ensure efficient testing and expose potential race conditions.

🪛 GitHub Check: lint
agent/agentcontainers/api.go

[failure] 270-270:
import-shadowing: The name 'fs' shadows an import name (revive)


[failure] 452-452:
unused-parameter: parameter 'info' seems to be unused, consider removing or renaming it as _ (revive)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: test-e2e
  • GitHub Check: chromatic
  • GitHub Check: test-go-pg (windows-2022)
  • GitHub Check: test-go-pg (macos-latest)
  • GitHub Check: test-go-race-pg
  • GitHub Check: test-go-pg-17
  • GitHub Check: test-go-pg (ubuntu-latest)
  • GitHub Check: gen
🔇 Additional comments (11)
site/src/modules/resources/AgentDevcontainerCard.stories.tsx (1)

94-103: LGTM! Good addition for edge case testing.

The new Storybook story appropriately tests the UI behavior when both container and agent are undefined, which is valuable for comprehensive component testing.

site/src/modules/resources/AgentDevcontainerCard.tsx (2)

223-224: Good fallback logic for devcontainer display name.

The updated logic properly falls back to config_path when both subAgent?.name and devcontainer.name are unavailable, providing better UX for auto-detected devcontainers.


259-259: Excellent conditional button labeling.

The conditional button text ("Start" vs "Rebuild") based on container presence provides clear user intent and aligns well with the devcontainer lifecycle.

agent/agent.go (1)

1171-1171: Appropriate extension of manifest information.

Adding manifest.Directory to the WithManifestInfo call properly supports the devcontainer auto-detection feature by providing the necessary filesystem context for discovery.

site/src/modules/resources/AgentRow.tsx (1)

140-151: Excellent refinement of app visibility logic.

The updated condition properly narrows when to hide parent apps - only when devcontainers are actively "running" or "starting". This provides better UX by showing parent apps when all devcontainers are stopped, while still reducing clutter when devcontainers are active. The inline comments clearly explain the reasoning.

agent/agentcontainers/api_test.go (3)

23-23: LGTM: Appropriate import for filesystem testing

The afero package import is necessary for the new TestDevcontainerDiscovery test function which uses in-memory filesystem operations.


1682-1682: LGTM: Consistent updates to WithManifestInfo calls

All three calls to WithManifestInfo have been correctly updated with the new agent directory parameter ("/parent-agent"), aligning with the updated function signature.

Also applies to: 1666-1666, 3367-3367


3194-3423: Well-structured test for devcontainer discovery functionality

The test comprehensively validates the automatic devcontainer discovery feature with:

  • Table-driven test cases covering various directory structures
  • Proper use of t.Parallel() as per codebase conventions
  • In-memory filesystem for isolated testing
  • Deterministic result sorting for reliable assertions
  • Appropriate use of Eventually pattern for async operations

The test effectively exercises the new discovery logic that scans agent directories for Git repositories containing devcontainer configurations.

agent/agentcontainers/api.go (3)

346-348: LGTM!

Good defensive initialization ensuring the filesystem is always set.


462-478: No issues found with handling incomplete devcontainer entries in the update loop.

The processUpdatedContainersLocked method explicitly resets and then populates each devcontainer’s Name and Status—defaulting to “Stopped” (or “Running” when appropriate) and generating a valid name based on the workspace folder or container friendly name when a container appears. This ensures there’s no race on uninitialized entries.


199-206: All WithManifestInfo Callers Updated

All usages of WithManifestInfo in agent/agent.go and agent/agentcontainers/api_test.go include the new agentDirectory argument. No further changes are required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant