Skip to content

feat(cli): add shep doctor command for self-diagnosis and auto-fix#438

Open
arielshad wants to merge 17 commits intomainfrom
feat/shep-doctor
Open

feat(cli): add shep doctor command for self-diagnosis and auto-fix#438
arielshad wants to merge 17 commits intomainfrom
feat/shep-doctor

Conversation

@arielshad
Copy link
Contributor

Summary

  • Add shep doctor top-level CLI command that lets users report operational failures, auto-creates GitHub issues on shep-ai/cli, optionally invokes an AI agent to attempt a fix, and opens a PR with the proposed fix
  • Supports both maintainers (direct push to shep-ai/cli) and external contributors (auto-fork + cross-fork PR) via push access auto-detection
  • Collects diagnostic context (recent failed agent runs, CLI version, system info) to produce structured bug reports

Changes

Domain Layer (TypeSpec)

  • New DoctorDiagnosticReport, FailedRunSummary, and SystemInfo value objects in TypeSpec
  • Extended WorkflowConfig with doctorMaxFixAttempts setting

Application Layer

  • New DoctorDiagnoseUseCase orchestrating the full diagnose → issue → clone/fork → agent fix → PR flow
  • New service interfaces: IGitHubIssueCreatorService (issue creation), IGitHubPermissionService (push access check), IDoctorRepositoryService (clone/fork management)

Infrastructure Layer

  • GitHubIssueCreatorService — wraps gh issue create with error mapping (not found, auth, network)
  • GitHubPermissionService — checks push access via gh api repos/.../permissions
  • DoctorRepositoryService — handles clone, fork, branch creation, and cleanup

Presentation Layer

  • doctor.command.ts — Commander.js command with [description] positional arg, --fix/--no-fix/--workdir options
  • Interactive prompt fallback when no description argument provided
  • Progress spinners and result display (issue URL, PR URL)

DI Container

  • All new services and use case registered in container.ts

Test Coverage

  • 11 unit tests for GitHubIssueCreatorService (success paths, error mapping, cause preservation)
  • 24 unit tests for DoctorDiagnoseUseCase (diagnostic collection, issue creation, maintainer/contributor flows, agent invocation, graceful degradation, temp dir cleanup)
  • 28 unit tests for doctor CLI command (structure, prerequisites, description collection, fix gate flags, workdir, result display, error handling)
  • 19 integration tests for doctor workflow (end-to-end maintainer flow, contributor flow, issue-only flow, failure graceful degradation, service ordering)

Total: 82 new tests, all passing

Test plan

  • pnpm build compiles without errors
  • pnpm validate (lint + format + typecheck + tsp) passes
  • pnpm test:unit — all 4619 tests pass (336 test files)
  • CI pipeline passes all checks

Evidence

Area Evidence
TypeSpec types DoctorDiagnosticReport, FailedRunSummary, SystemInfo value objects generated correctly
CLI registration shep doctor registered as top-level command, --help shows all options
Unit tests 82/82 passing across service, use case, and command layers
Integration tests 19/19 passing covering both maintainer and contributor flows
Build Clean compilation with no errors

Spec: specs/073-shep-doctor/

🤖 Generated with Claude Code

arielshad and others added 16 commits March 20, 2026 22:37
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…utor flows

Address user feedback: shep doctor now supports both shep maintainers (who
push directly to shep-ai/cli without forking) and external contributors
(who fork first). Uses gh api permission check to auto-detect push access
and select the appropriate flow automatically.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…p doctor

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…octor

15 tasks across 6 phases: TypeSpec domain models, service interface
ports, infrastructure implementations, use case orchestration, CLI
command with DI wiring, and integration testing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…fig extension

Add DoctorDiagnosticReport TypeSpec value object with FailedRunSummary
and SystemInfo sub-models for structured diagnostic data collection.
Extend WorkflowConfig with optional doctorMaxFixAttempts field (default 1)
to control fix retry behavior in the shep doctor workflow.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add IGitHubIssueService interface with createIssue method, error types,
and result DTO. Extend IGitHubRepositoryService with checkPushAccess
and forkRepository methods for maintainer vs contributor flow detection.
Extend IGitPrService with createPrFromArgs for programmatic cross-fork
PR creation. Includes implementations and comprehensive interface tests.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Implement GitHubIssueCreatorService wrapping gh issue create with
typed error handling (GH_NOT_FOUND, AUTH_FAILURE, NETWORK_ERROR,
CREATE_FAILED). Register IGitHubIssueService in DI container.
Add comprehensive unit tests covering success and error paths.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add tests for checkPushAccess (true/false/error fallback paths),
forkRepository (new fork, existing fork, error handling), and
createPrFromArgs (same-repo, cross-fork with --repo flag, error
handling). All three methods were implemented in phase 2 and now
have comprehensive test coverage.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… and fix workflow

Implement DoctorDiagnoseUseCase orchestrating the full shep doctor workflow:
- Collect diagnostics (failed agent runs, CLI version, system info)
- Create structured GitHub issue on shep-ai/cli
- Auto-detect push access for maintainer vs contributor flow
- Clone/fork repo, invoke AI agent, commit and create PR
- Graceful degradation on failures, temp directory cleanup

24 unit tests covering both flows, edge cases, and NFR compliance.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add top-level `shep doctor` CLI command that diagnoses shep failures,
creates GitHub issues, and optionally attempts automated fixes.
Register DoctorDiagnoseUseCase in DI container and wire command into
the CLI program.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Clean ANSI codes from evidence files and add complete headers with
test suite names, file paths, dates, and structured pass/fail markers.
All 8 evidence files updated with fresh test runs confirming:
- 11/11 github-issue-creator service tests passing
- 24/24 doctor use case unit tests passing
- 28/28 doctor command unit tests passing
- 19/19 doctor integration tests passing
- TypeSpec types verified in generated output
- CLI help and command registration confirmed
- Build succeeds with no errors

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

Dev Release Published

Artifact Version Install
npm 1.135.2-pr438.e15badd npm install -g @shepai/cli@1.135.2-pr438.e15badd

Published from commit c2a610e | View CI

TypeSpec compiler v0.60.1 now emits double-quoted strings in enum
values. Regenerated output.ts to match current compiler output and
prevent freshness check failures.

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

Dev Release Published

Artifact Version Install
npm 1.135.2-pr438.f43bc1e npm install -g @shepai/cli@1.135.2-pr438.f43bc1e

Published from commit 1ac4c2e | 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