Skip to content

feat(domain): add agentrun creation and spec initialization to adopted branches#417

Open
arielshad wants to merge 13 commits intomainfrom
feat/adopted-branch-agent-runs
Open

feat(domain): add agentrun creation and spec initialization to adopted branches#417
arielshad wants to merge 13 commits intomainfrom
feat/adopted-branch-agent-runs

Conversation

@arielshad
Copy link
Contributor

Summary

Adds AgentRun creation and spec directory initialization to AdoptBranchUseCase, enabling adopted features to participate in the full agent execution lifecycle (start, resume, reject iterations).

Fixes: Adopted branches can now be started, resumed after interruption, and process rejection feedback - previously these operations failed with "No agent run found" error.

Changes

Core Implementation

  • AdoptBranchUseCase (packages/core/src/application/use-cases/features/adopt-branch.use-case.ts):
    • Inject IAgentRunRepository and ISpecInitializerService dependencies
    • Create AgentRun record before Feature creation with correct initialization (status=pending, agentType from settings, threadId generated)
    • Initialize spec directory conditionally (only if none exists) to preserve existing spec work
    • Link Feature and AgentRun via feature.agentRunId field
    • Set Feature.lifecycle to Review (if PR exists) or Maintain (if no PR)

Test Coverage

  • Unit tests (tests/unit/use-cases/features/adopt-branch.use-case.test.ts):

    • 36 tests covering AgentRun creation, spec initialization, feature linking, and edge cases
    • Validates existing spec directory preservation
    • Tests settings integration for agent type and model ID
    • Confirms lifecycle determination based on PR status
  • Integration tests (tests/integration/features/adopt-flow.integration.test.ts):

    • 7 tests validating end-to-end adopt → start → resume flow
    • Confirms AgentRun support enables full agent lifecycle for adopted features
    • Tests rejection feedback processing
    • Validates spec directory initialization and reuse

Evidence

The following evidence was captured to prove task completion:

Testing

# Unit tests for AdoptBranchUseCase
pnpm test tests/unit/use-cases/features/adopt-branch.use-case.test.ts

# Integration tests for adopt flow
pnpm test tests/integration/features/adopt-flow.integration.test.ts

# All tests
pnpm test

Related

🤖 Generated with Claude Code

arielshad and others added 13 commits March 17, 2026 18:35
…anch agent runs

- Added 17 functional requirements covering AgentRun creation and linking
- Added 10 non-functional requirements for performance, consistency, and maintainability
- Defined 10 measurable success criteria for feature completion
- Resolved 4 product questions with structured options and AI recommendations:
  1. Adopted features start as Pending (requires explicit start)
  2. AgentRun.prompt uses "(adopted from existing branch)" placeholder
  3. Spec directory is initialized with empty YAMLs for consistency
  4. Agent validation skipped during adoption (deferred to execution time)
- Detailed implementation notes following CreateFeatureUseCase pattern
- Comprehensive TDD testing strategy with unit and integration test plans

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Inject IAgentRunRepository and ISpecInitializerService into
AdoptBranchUseCase constructor following existing tsyringe pattern.
Import required Node.js modules (existsSync, join, randomUUID),
TypeSpec-generated types (AgentRunStatus, SdlcLifecycle), and
getSettings service. Update test mocks to include new repositories.
All dependencies already registered in DI container. Imports prepared
for Phase 2 AgentRun creation logic.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…d branches

Implement phase 2 of feature 071 (adopted-branch-agent-runs):
- Calculate feature number from existing features in repository
- Conditionally initialize spec directory (preserve existing, create if missing)
- Create AgentRun record following CreateFeatureUseCase pattern (lines 156-210)
- Link Feature to AgentRun via agentRunId field
- Persist AgentRun before Feature (respects referential integrity)

Changes:
- AdoptBranchUseCase now creates AgentRun with status=pending, agentType from settings
- Spec directory detection via existsSync - preserves existing work
- AgentRun.prompt set to "(adopted from existing branch)" placeholder
- Feature.specPath and Feature.agentRunId now populated for adopted features
- All 28 unit tests passing, 4354 total tests passing

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…t run support

Add unit and integration tests validating AgentRun creation, spec directory
initialization, and entity linking for adopted branches. Tests cover all
acceptance criteria including field validation, error handling, and
persistence order.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Replace hardcoded Unix paths with path.join() to ensure tests pass on Windows.
Fixes CI failure on windows-latest runner where backslashes are used.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Use path.join() in test mocks to generate platform-specific paths on Windows.
This ensures the mock paths match what the implementation generates with join().

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…iables

Move mockWorktreePath to module level and use consistently across all tests.
This ensures all path assertions work on both Unix and Windows platforms.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@github-actions
Copy link

Dev Release Published

Artifact Version Install
npm 1.130.0-pr417.355b6bd npm install -g @shepai/cli@1.130.0-pr417.355b6bd

Published from commit 4a28b28 | View CI

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