Skip to content

Add pkg/prism public API (ADR-0002)#4

Merged
hidetzu merged 1 commit into
mainfrom
feature/public-api-boundary
Apr 11, 2026
Merged

Add pkg/prism public API (ADR-0002)#4
hidetzu merged 1 commit into
mainfrom
feature/public-api-boundary

Conversation

@hidetzu
Copy link
Copy Markdown
Owner

@hidetzu hidetzu commented Apr 11, 2026

Summary

Introduce the pkg/prism package as the stable public API for embedding prism as a library. This unblocks the planned prism-api (HTTP service on Fly.io) and enables editor plugins, CI integrations, and other library consumers.

What's in

Code

  • pkg/prism/prism.goAnalyze, Prompt, AnalyzeOptions, Result, PRInfo, AnalysisResult, ChangedFile, sentinel errors
  • pkg/prism/prism_test.go — validation & error categorization (7 tests)
  • pkg/prism/internal_test.gobuildResult & buildPRURL unit tests (11 tests)

Docs

  • docs/adr/0002-public-api-boundary.md — Accepted ADR covering rationale, what is and is not exposed, differences from CLI JSON, compatibility guarantees, and implementation plan
  • README.md — new Library Usage section with Analyze/Prompt examples
  • docs/architecture.mdpkg/prism added to Package Responsibilities
  • docs/json-schema.md — note that pkg/prism.Result differs from CLI JSON
  • docs/versioning.md — covers both CLI JSON and pkg/prism API stability

Design decisions

  • Single high-level facade: only Analyze and Prompt are exposed. Internals (internal/domain, internal/provider, etc.) remain private.
  • Additive-only options: new fields can be added to AnalyzeOptions and Result without breaking consumers.
  • Four sentinel errors for HTTP status mapping: ErrInvalidInput, ErrUnsupportedProvider, ErrAuthRequired, ErrUpstreamFailure.
  • Patches opt-in via AnalyzeOptions.IncludePatches to keep responses lightweight.
  • pkg/prism.Result differs from CLI JSON (provider position, URL inclusion, description exclusion). Phase 2 will unify them via CLI refactor.

Phase 2 (deferred)

  • Refactor cmd/prism to use pkg/prism internally
  • Verify CLI JSON equals pkg/prism.Result JSON via golden tests
  • Create prism-api repository

Test plan

  • make test (with -race) — all 18 pkg/prism tests pass
  • make lint — 0 issues
  • make vet — clean
  • No regression in existing packages

Introduce the pkg/prism package as the stable public API for embedding
prism as a library. Enables prism-api, editor plugins, and CI integrations
to use prism without depending on internal packages.

- Add pkg/prism/prism.go with Analyze, Prompt, AnalyzeOptions, Result,
  PRInfo, AnalysisResult, ChangedFile, and sentinel errors
- Add pkg/prism tests covering validation, error categorization,
  buildResult conversion, and buildPRURL construction (18 tests)
- Add ADR-0002 documenting the public API boundary, what is and is not
  exposed, compatibility guarantees, and differences from CLI JSON
- Update README with Library Usage section and code examples
- Update architecture.md to include pkg/prism responsibilities
- Update json-schema.md noting pkg/prism.Result differs from CLI JSON
- Update versioning.md covering both CLI JSON and pkg/prism API stability

The CLI refactor to use pkg/prism internally is deferred to Phase 2.
@hidetzu hidetzu merged commit 0eddc32 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