Skip to content

feat(pkgdef): add package definition library - #3001

Open
mikeland73 wants to merge 1 commit into
mikeland73/pkgdef-specfrom
mikeland73/pkgdef-lib
Open

mikeland73 wants to merge 1 commit into
mikeland73/pkgdef-specfrom
mikeland73/pkgdef-lib

Conversation

@mikeland73

Copy link
Copy Markdown
Collaborator

Summary

Second PR of the package definitions stack (spec: specs/package-definitions.md, added in the previous PR). Adds internal/pkgdef, a leaf package with no dependency on devpkg, lock or plugin:

  • Parse/Validate for *.pkg.json (hujson), with every error reported at once.
  • ParseRef for pkg:<ref>@<version> (version split at the last @).
  • Client.Load for path, https:// and file:// refs. Remote definitions are cached by content hash and can be pinned to a hash from the lockfile (ErrDefinitionChanged when the server now serves something else).
  • Version sources: static, http_json (jq via gojq), github_releases (drafts and pre-releases skipped, token only ever sent to the GitHub API host).
  • Client.Resolve/Lock: resolve latest, a prefix or an exact version, then render the artifact URL and fetch its sha256 (http_json or sha256_url, which handles bare digests and SHASUMS-style lists) for every supported system.
  • Client.Install: idempotent install into $XDG_CACHE_HOME/devbox/pkgs/<name>/<version>/<system>, serialized across processes with a file lock, verified against the lockfile digest, extracted with path and symlink sanitization (tar.{gz,xz,bz2,zst} and zip via mholt/archives, which the repo already uses), post_install hooks with their output kept for error messages.
  • manager and script strategies return ErrNotImplemented for now, as the spec marks them planned.

New direct dependency: github.com/itchyny/gojq (vendor-hash refreshed).

Test plan

  • go test ./internal/pkgdef/ (unit tests against an httptest "vendor": resolve, lock, archive and binary installs, concurrent installs, checksum mismatch, trust on first use, GitHub releases, remote pinning, extraction safety)
  • golangci-lint and gofumpt clean

🤖 Generated with Claude Code

Add internal/pkgdef, the library behind package definitions (see
specs/package-definitions.md): parsing and validation of *.pkg.json
files, pkg:<ref>@<version> reference parsing, loading local and remote
definitions (remote ones cached and pinned by content hash), version
resolution from static lists, JSON indexes (via gojq) and GitHub
releases, per-system artifact locking with checksums, and idempotent
installs into $XDG_CACHE_HOME/devbox/pkgs/<name>/<version>/<system>.

The package is a leaf with no dependency on devpkg, lock or plugin so
the wiring in a follow-up PR can build on it. The manager and script
strategies defined by the spec return ErrNotImplemented for now.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@mikeland73
mikeland73 requested a review from savil October 22, 2026 21:33
@mikeland73
mikeland73 added this pull request to stack #3003 October 22, 2026 21:35

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant