Skip to content

Add build steps and a runtime context for plugins - #5

Open
rawnly wants to merge 3 commits into
mainfrom
feat/build-hook-and-plugin-context
Open

rawnly wants to merge 3 commits into
mainfrom
feat/build-hook-and-plugin-context

Conversation

@rawnly

@rawnly rawnly commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Amber can't replace the install scripts that Rex plugins ship today (rex-durable is the one that got me looking). Two things are missing: a way to run something after checkout, and a way for setup to find out where the plugin lives, so nothing has to be baked in at install time. This adds both, modeled on lazy.nvim's build.

build

A plugin spec can take build as a shell command, a function, or a list of those. Install, update and restore run it when the locked commit isn't the one recorded as built. amber_build forces it, and amber_status shows whether it's current. built lives next to commit in the lockfile, so the format stays at 1.

A few decisions worth a look:

  • Builds only ever target the locked commit. If HEAD has drifted, it refuses and points at amber_restore.
  • The checkout is recorded under the lockfile guard, then the build runs with the guard released, then a second write records built if the entry still points at that commit. This way a slow or killed build can't leave .lock behind.
  • A failed build keeps the checkout in the lockfile and fails the action; amber_build retries it.
  • An installed plugin with a build step isn't set up until its build has run. That means adding build to an existing plugin needs one amber_build and a reload. If the lockfile can't be read, nothing is held back.
  • Steps share the 23 s action budget, so they have to be short.
  • Build output inside the checkout has to be gitignored or written to data_dir, since restore and update refuse dirty checkouts.
  • build is rejected together with path.

setup(opts, ctx)

ctx has name, dir, module_dir, commit (the locked one) and data_dir (under $XDG_STATE_HOME/rex/amber; Amber names it but doesn't create it). Plugins that ignore the second argument don't notice.

Not here

No service management and no launchd/systemd units. For a background watcher the README says to start it from setup. There's also no rex_bin in ctx, because I don't know a reliable way to find the server binary, and no uninstall or amber_clean.

Testing

CI is green. Locally I only had texlua (Lua 5.3) with a small package.loaders shim, so the suite ran there and formatting was done by hand. I haven't tried it against a real Rex: rex config check, rex.exec with sh -c and env, and the detached-process notes in the README are all unchecked.

https://claude.ai/code/session_01HYR5Nyv85TQGevuubCSZYd


Generated by Claude Code

Plugins that need work after checkout, or that must resolve paths at
runtime, had to ship their own installer. Add the lazy.nvim-style pieces
Amber was missing:

- build option (command, function, or list) run after install, update, or
  restore when the checkout commit differs from the lockfile's built commit
- amber_build action to force a build, and a built state in amber_status
- lockfile entries may carry a built commit; a failed build still records
  the checkout and can be retried
- setup is held back (status unbuilt) until the build has run for the
  locked commit
- setup(opts, ctx) with name, dir, module_dir, commit, and data_dir
- docs on starting background processes from the plugin; Amber still has
  no service management

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HYR5Nyv85TQGevuubCSZYd
Split an unbalanced assignment in amber.lua and annotate the test stubs
that replace rex.json.decode, which the types check reported.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HYR5Nyv85TQGevuubCSZYd
@rawnly rawnly added the enhancement New feature or request label Nov 14, 2026
- Split manage into three phases: record the checkout under the lockfile
  guard, run the build with the guard released, then record `built` only if
  the lock entry still points at the built commit.
- Build the locked commit only; refuse a drifted checkout and point to
  amber_restore instead of recording a build for an unlocked HEAD.
- amber_build fails without a lock entry instead of reporting "built".
- exec merges opts.env over the AMBER_PLUGIN_* variables; add
  AMBER_PLUGIN_MODULE_DIR and AMBER_PLUGIN_DATA_DIR, and point
  AMBER_PLUGIN_DIR at the checkout.
- Expose data_dir to build steps and document that build output must be
  gitignored or kept in data_dir, since restore and update refuse dirty
  checkouts. Note the shared budget in bulk actions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HYR5NzbCKe2x4vjWBiynJt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants