Skip to content

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

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

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

Conversation

@arielshad
Copy link
Copy Markdown
Contributor

@arielshad arielshad commented Mar 17, 2026

Summary

  • Adds AgentRun record creation to AdoptBranchUseCase, enabling adopted branches to start, resume, and process rejection feedback
  • Initializes spec directory with empty YAMLs for adopted features (preserves existing specs if present)
  • Links Feature entity to AgentRun via agentRunId and sets specPath correctly

What Changed

Core Implementation (adopt-branch.use-case.ts):

  • Injects IAgentRunRepository and ISpecInitializerService dependencies
  • Creates AgentRun with status=pending, prompt="(adopted from existing branch)", agent type from settings
  • Conditional spec directory initialization: detects existing specs, only creates new ones if needed
  • Correct persistence order: AgentRun created before Feature (referential integrity)
  • Platform-aware paths throughout

Tests:

  • 36 unit tests covering AgentRun creation, spec directory initialization, feature linking, error handling
  • 7 integration tests validating the full adopt → start → resume flow

Evidence

Screenshots (SVG)

Evidence Description
app-adopt-branch-cli-output.svg CLI output showing shep feat adopt creating a feature with AgentRun
app-adopt-spec-directory-init.svg Spec directory initialization with sequential numbering
app-adopt-agentrun-db-proof.svg Database query proving AgentRun ↔ Feature linkage (before vs after)

Video (Terminal Recording)

Evidence Description
app-adopt-branch-full-flow.cast Full terminal recording (asciinema format) of the adopt flow: repo setup → adopt → DB verification → spec directory → feat ls

Test Output

Evidence Description
adopt-branch-unit-tests.txt 36 unit tests passing
adopt-integration-tests.txt 7 integration tests passing
app-adopt-branch-e2e-verification.txt End-to-end manual verification with database queries
implementation-summary.txt Implementation summary with all success criteria

Test plan

  • All 36 unit tests pass (pnpm test:unit)
  • All 7 integration tests pass (pnpm test:int)
  • Build succeeds (pnpm build)
  • Lint passes (pnpm lint:fix)
  • CLI demonstration: shep feat adopt creates Feature + AgentRun
  • Database verification: agent_runs table populated with correct fields
  • Spec directory initialized with empty YAMLs on adoption
  • Existing spec directories preserved when adopting branches with specs

🤖 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
Copy Markdown
Contributor

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

…runs

Evidence includes SVG screenshots of CLI output, database proof of
AgentRun linkage, spec directory initialization, and an asciinema
terminal recording of the full adopt flow.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

Dev Release Published

Artifact Version Install
npm 1.136.0-pr417.01aebe9 npm install -g @shepai/cli@1.136.0-pr417.01aebe9

Published from commit 82a4c11 | 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