Skip to content

Migrate deprecated nested shell object to top-level fields#2841

Open
mikeland73 wants to merge 1 commit into
mainfrom
claude/admiring-dirac-eyYb0
Open

Migrate deprecated nested shell object to top-level fields#2841
mikeland73 wants to merge 1 commit into
mainfrom
claude/admiring-dirac-eyYb0

Conversation

@mikeland73
Copy link
Copy Markdown
Collaborator

Summary

This PR adds support for migrating the deprecated nested shell object in devbox.json to modern top-level init_hook and scripts fields. The changes include:

  • New top-level fields: Added init_hook and scripts as first-class fields in the config schema, replacing the nested shell.init_hook and shell.scripts structure
  • Backward compatibility: The nested shell object remains readable for existing configs; accessors fall back to deprecated fields when top-level fields are absent
  • Migration tooling: Implemented MigrateShell() method that moves nested shell fields to the top level while preserving comments and formatting
  • New CLI command: Added devbox config fmt command to automatically migrate configs and reformat them to canonical layout
  • Deprecation warnings: Users are warned when opening a config with the deprecated shell field, directing them to run devbox config fmt
  • Schema updates: Updated JSON schema to mark the nested shell object as deprecated and document the new top-level fields

How was it tested?

  • Added comprehensive unit tests in shell_migration_test.go covering:
    • Backward compatibility with deprecated nested shell fields
    • Reading modern top-level fields
    • Migration preserving data and comments
    • Round-trip serialization/deserialization
    • No-op behavior when shell object is absent
  • Added integration test in testscripts/config/fmt.test.txt verifying the devbox config fmt command migrates configs correctly and is idempotent
  • Updated default config generation to use top-level fields instead of nested shell object

Community Contribution License

All community contributions in this pull request are licensed to the project
maintainers under the terms of the
Apache 2 License.

By creating this pull request, I represent that I have the right to license the
contributions to the project maintainers under the Apache 2 License as stated in
the
Community Contribution License.

https://claude.ai/code/session_017QEtLcEdV7hPXvH7XYkyai

Move init_hook and scripts to the top level of devbox.json. The nested
"shell" object is still accepted for backward compatibility, but is now
deprecated and emits a warning on load.

- Add top-level init_hook and scripts fields to ConfigFile. Accessors
  (InitHook, Scripts) read the top-level fields first and fall back to
  the deprecated shell.* fields.
- Warn when a config still nests init_hook/scripts under "shell".
- Add `devbox config fmt` to format and modernize devbox.json. It
  migrates the deprecated "shell" object to top-level fields via the
  hujson AST, preserving comments and formatting.
- Update DefaultConfig (devbox init) and the JSON schema to use the new
  top-level layout; mark "shell" as deprecated in the schema.
- Add unit tests for backward compat / migration and an integration
  testscript for `devbox config fmt`.

https://claude.ai/code/session_017QEtLcEdV7hPXvH7XYkyai
Copilot AI review requested due to automatic review settings May 31, 2026 18:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates devbox.json shell configuration toward top-level init_hook and scripts fields while keeping legacy shell configs readable.

Changes:

  • Adds top-level config fields and backward-compatible accessors for legacy shell.init_hook / shell.scripts.
  • Implements shell-field migration and a new devbox config fmt command.
  • Updates schema, defaults, warning behavior, and tests for the new layout.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
internal/devconfig/configfile/file.go Adds top-level fields, deprecation detection, and migration entry point.
internal/devconfig/configfile/scripts.go Reads scripts from both legacy and top-level locations.
internal/devconfig/configfile/ast.go Adds AST migration from nested shell to top-level fields.
internal/devconfig/config.go Updates generated default config layout.
internal/devbox/devbox.go Emits deprecation warning for legacy shell configs.
internal/boxcli/config_fmt.go Adds devbox config fmt command.
internal/boxcli/root.go Registers the new config command group.
.schema/devbox.schema.json Documents top-level fields and deprecates nested shell.
internal/devconfig/configfile/shell_migration_test.go, testscripts/config/fmt.test.txt Adds unit and integration coverage for migration behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +493 to +495
// Don't clobber a field that already exists at the top level.
if c.memberIndex(rootObj, key) != -1 {
continue
Comment on lines +497 to +502
member := shellObj.Members[srcIdx]
// Ensure the migrated field starts on its own line.
if !slices.Contains(member.Name.BeforeExtra, '\n') {
member.Name.BeforeExtra = append([]byte{'\n'}, member.Name.BeforeExtra...)
}
rootObj.Members = append(rootObj.Members, member)
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.

3 participants