Skip to content

Refactor CLI analyze to use pkg/prism (Phase 2)#5

Merged
hidetzu merged 1 commit into
mainfrom
feature/cli-uses-pkg-prism
Apr 11, 2026
Merged

Refactor CLI analyze to use pkg/prism (Phase 2)#5
hidetzu merged 1 commit into
mainfrom
feature/cli-uses-pkg-prism

Conversation

@hidetzu
Copy link
Copy Markdown
Owner

@hidetzu hidetzu commented Apr 11, 2026

Summary

CLI analyze now calls pkg/prism.Analyze() internally. The CLI JSON output is byte-identical to pkg/prism.Result, verified by golden tests. This completes Phase 2 of ADR-0002 and ensures CLI/library symmetry.

Breaking changes (CLI JSON output, v0.2 → v0.3)

Field v0.2.x v0.3.0
`provider` top-level `pull_request.provider`
`pull_request.description` included removed (use `prism fetch`)
`pull_request.url` not present added
`changed_files[].patch` included excluded by default
Empty fields always present omitted (`omitempty`)

These changes match the spec defined in ADR-0002 and are documented in `docs/json-schema.md`.

What's in

Code

  • Delete: `internal/usecase/analyze.go` and tests (replaced by `pkg/prism.Analyze` + formatter)
  • Delete: `internal/formatter/types.go` (formatter now uses `prism.Result` directly)
  • Rewrite: `internal/formatter/{json,markdown,text}.go` to accept `prism.Result`
  • Update: `cmd/prism/main.go runAnalyze` to call `pkg/prism.Analyze` and route through formatter
  • Update: `cmd/prism` exit-code mapping to also recognize `prism.Err*` sentinels
  • Add: `provider.NewRegistryWithGitHubBaseURL` test seam (used by pkg/prism integration tests)
  • Add: `pkg/prism/integration_test.go` with 5 happy-path tests using a mock GitHub server
  • Update: golden test fixture to new JSON shape

Docs

  • `README.md`: JSON/Markdown examples updated, Roadmap reorganized (v0.3.0 = library API, v0.4.0 = policy files, v0.5.0+ = SARIF/IDE)
  • `docs/adr/0002-public-api-boundary.md`: Phase 2 completion noted, differences-from-CLI section updated
  • `docs/json-schema.md`: new schema + breaking-change section
  • `docs/architecture.md`: cmd/prism, formatter, usecase descriptions updated

Deferred to a future PR

  • `prompt` and `fetch` commands still go through `internal/usecase` because `pkg/prism.Prompt` returns a plain string and does not yet cover `--format json|markdown` or `--template`. Extending `pkg/prism` with a structured prompt API would unlock the full unification.

Test plan

  • `make test` (with `-race`) — all packages pass
  • `make lint` — 0 issues
  • `make vet` — clean
  • Golden test verifies CLI JSON ≡ `pkg/prism.Result` JSON
  • New integration tests cover Analyze happy path, IncludePatches, explicit provider, upstream failure, Prompt happy path

The CLI analyze command now calls pkg/prism.Analyze() internally and
delegates output formatting to internal/formatter, which has been
rewritten to take prism.Result as input. CLI JSON output is now
byte-identical to pkg/prism.Result, verified by golden tests.

Breaking changes to CLI JSON output (v0.2 → v0.3):
- provider moved from top-level to pull_request.provider
- pull_request.description removed (use prism fetch for raw description)
- pull_request.url added (canonical PR URL)
- changed_files[].patch excluded by default (library has IncludePatches opt-in)
- Empty/zero fields now omitted (omitempty semantics)

Implementation:
- Delete internal/usecase/analyze.go (replaced by pkg/prism.Analyze + formatter)
- Rewrite internal/formatter to take prism.Result instead of domain types
- Update golden test fixture to new shape
- Add test seam: provider.NewRegistryWithGitHubBaseURL for redirecting
  the github provider to a local httptest server
- Add pkg/prism/integration_test.go with happy-path tests using mock
  GitHub server (Analyze, Prompt, IncludePatches, upstream failure)
- CLI version bumped to 0.3.0-dev

prompt and fetch commands still go through internal/usecase pending
extension of pkg/prism.Prompt to cover --format and --template options.

Documentation updates:
- README.md: JSON/Markdown examples updated, Roadmap reorganized
  (v0.3.0 = library API, v0.4.0 = policy files)
- docs/adr/0002: Phase 2 completion noted
- docs/json-schema.md: new shape, breaking changes section
- docs/architecture.md: cmd/prism, formatter, usecase descriptions updated
@hidetzu hidetzu merged commit 1ab476c into main Apr 11, 2026
2 checks passed
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