-
-
Notifications
You must be signed in to change notification settings - Fork 0
Update Remove and GC
Numan provides a robust set of lifecycle management commands—update, remove, and gc—designed to maintain the health and currency of installed Nushell packages. These commands operate under strict architectural invariants, ensuring that mutations to the system state are journaled, atomic, and safe. While installation is inert, these commands manage the transition of packages through their lifecycle stages, from upgrading to new registry versions to the final pruning of orphaned artifacts.
These lifecycle operations are part of "Phase 5" of the Numan roadmap, introducing Lockfile v2 and a pending-lifecycle.json journal to handle crash recovery during complex mutations.
All lifecycle commands that modify the Numan root (including update, remove, and gc) must follow the project's mutation serialization rules. This involves acquiring an advisory filesystem lock to prevent concurrent destructive operations and utilizing a journal for crash recovery.
To prevent race conditions, Numan uses acquire_mutation_lock(root). This returns an RAII guard; if a second process attempts to acquire the lock on the same root, it fails immediately.
Mutations are tracked via the pending-lifecycle.json journal. This allows Numan to reconcile the state if a process is interrupted. The journal tracks operations through stages such as Prepared, PayloadsStaged, PayloadsPromoted, and SelectionCommitted.
flowchart TD
Start[Command Invoked] --> Lock[Acquire Mutation Lock]
Lock --> Snapshot[Create Lockfile Snapshot]
Snapshot --> Journal[Write Pending Lifecycle Journal]
Journal --> Execute[Execute Mutation]
Execute --> Commit[Update Lockfile & State]
Commit --> Cleanup[Clear Journal & Release Lock]
The diagram shows the standard sequence for any command modifying the Numan state.
The update command allows users to detect and apply registry version upgrades for installed packages. It distinguishes between checking for updates and applying them.
-
Check Mode (
--check): Numan queries the synced registry indexes to find newer versions that satisfy the package'snu_versionconstraints. - Application: If updates are found and the user applies them, Numan performs a standard install transaction for the new version.
- Immutable Payloads: Because Numan uses content-addressed, versioned paths, the update process does not overwrite the old version in place. Instead, it installs the new version to a new directory, updating the lockfile to point to the new revision.
The remove command excises a package from the Numan system. By default, it removes the entry from the lockfile and marks the payload for eventual garbage collection.
- Active Packages: Numan typically prevents the removal of packages that are currently active in Nushell (plugins registered or modules in the autoload file).
-
Force Removal: The
--forceflag allows the removal of a package even if it is currently active. -
Payload Deletion: While the lockfile entry is removed immediately, the physical payload directory is often left for the
gccommand to clean up, unless the lifecycle journal specifically handles the deletion.
Garbage collection is the process of deleting orphaned payload directories—those that are no longer referenced by any entry in the current lockfile or any valid activation snapshot.
Numan's gc command treats the following as "live roots":
- Every package version entry in the current
lockfile. - Every payload referenced in an immutable activation snapshot.
Any directory under <root>/packages/ that does not correspond to a live root is considered orphaned and is eligible for deletion.
| Flag | Description | Safety Level |
|---|---|---|
--dry-run |
Previews which orphaned payload directories would be deleted without performing the actual deletion. | High |
| (default) | Deletes all unreferenced payloads and can optionally prune old snapshot directories. | Moderate |
graph TD
Identify[Scan /packages/ directory] --> Filter[Compare against Lockfile & Snapshots]
Filter --> Orphans[Identify Unreferenced Dirs]
Orphans --> DryRun{Dry Run?}
DryRun -- Yes --> Report[Print paths to be deleted]
DryRun -- No --> Delete[Delete orphaned directories]
The GC process ensures that immutable payloads are only removed when they are no longer required for potential rollbacks or current usage.
| Command | Action | Key Configuration/Flags |
|---|---|---|
numan update |
Upgrades installed packages |
--check (report only), -v (verbose) |
numan remove |
Removes package from lockfile |
--force (remove despite active status) |
numan gc |
Deletes orphaned directories |
--dry-run (preview only) |
The Update, Remove, and GC suite provides a complete management lifecycle that prioritizes system stability. By utilizing immutable payloads and a centralized lockfile as the ground truth, Numan ensures that even failed updates or accidental removals can be managed through snapshots or journaled recovery, while the GC command keeps the filesystem clean of obsolete artifacts.
Numan wiki for tonythethompson/numan · v0.1.4 · MIT