Add OpenSpec for declpac CLI tool

- OpenSpec for declarative pacman package management
- stdin and --state file inputs with merging
- Full system upgrades, transitive deps, orphan cleanup
- AUR support with pacman/makepkg fallback
- Machine-readable output for scripting
This commit is contained in:
AI Bot
2026-04-13 15:42:35 +02:00
committed by Riyyi
parent cb3936c42a
commit 6699c62d9e
14 changed files with 443 additions and 1 deletions
@@ -0,0 +1,23 @@
## ADDED Requirements
### Requirement: Can handle AUR packages with pacman fallback
The system SHALL attempt to install AUR packages by first trying pacman
repositories, then falling back to AUR when pacman fails, and finally reporting
errors for packages still missing.
#### Scenario: Install from pacman first
- **WHEN** package is in pacman repositories
- **THEN** system shall install via pacman
#### Scenario: Fall back to AUR
- **WHEN** package is not in pacman repositories but is in AUR
- **THEN** system shall attempt installation via makepkg (direct AUR build)
#### Scenario: Report error for missing packages
- **WHEN** package is not in pacman repositories or AUR
- **THEN** system shall report error and print to stderr
#### Scenario: Continue for remaining packages
- **WHEN** some packages are installed and some fail
- **THEN** system shall continue installation process for successful packages
@@ -0,0 +1,24 @@
## ADDED Requirements
### Requirement: Can merge multiple input sources
The system SHALL combine package lists from all inputs using an additive
strategy without conflict resolution.
#### Scenario: Additive merging of all inputs
- **WHEN** stdin and multiple state files provide package lists
- **THEN** system shall include all packages from all inputs in the final state
#### Scenario: Input priority is last-writer-wins per file
- **WHEN** multiple state files contain the same package name
- **THEN** the package from the last provided file in command-line order takes
precedence
#### Scenario: Missing packages from stdin are added
- **WHEN** stdin contains packages not in state files
- **THEN** those packages shall be added to the final state
#### Scenario: Duplicate packages accumulate
- **WHEN** the same package appears in multiple inputs
- **THEN** it shall be included multiple times in the final state (pacman
handles duplicates)
@@ -0,0 +1,21 @@
## ADDED Requirements
### Requirement: Can generate machine-readable output
The system SHALL produce output suitable for automated scripting.
#### Scenario: Install/remove count output
- **WHEN** sync completes successfully
- **THEN** system shall output: "<installed_count> package(s) installed, <removed_count> package(s) removed"
#### Scenario: Empty output format
- **WHEN** no packages to sync
- **THEN** system shall output nothing (or indicate no changes)
#### Scenario: Error details in output
- **WHEN** pacman operation fails
- **THEN** system shall include error details in output (package names, pacman error messages)
#### Scenario: Exit code for scripting
- **WHEN** sync completes
- **THEN** system shall return exit code 0 for success, non-zero for errors
@@ -0,0 +1,29 @@
## ADDED Requirements
### Requirement: Can mark non-state packages as non-explicit
The system SHALL mark all packages not declared in the state as non-explicit
(dependencies) before syncing, so they can be safely removed later.
#### Scenario: Mark packages as non-explicit
- **WHEN** packages are declared in state
- **THEN** system shall mark those packages as explicitly installed via pacman -D --explicit
- **AND** mark all other installed packages as non-explicit
### Requirement: Can clean up orphaned packages
After syncing, the system SHALL remove packages that are no longer required
(as dependencies of removed packages).
#### Scenario: Orphan cleanup after sync
- **WHEN** sync operation completes successfully
- **THEN** system shall run pacman -Rsu to remove unneeded dependencies
- **AND** report the number of packages removed
#### Scenario: Orphan cleanup respects explicitly installed
- **WHEN** a package not in state is marked as explicitly installed by user
- **THEN** system shall NOT remove it during orphan cleanup
#### Scenario: No orphans to clean
- **WHEN** there are no orphaned packages to remove
- **THEN** system shall report "No packages to remove" in output
@@ -0,0 +1,25 @@
## ADDED Requirements
### Requirement: Can sync system with declared package state
The system SHALL execute pacman operations to install and upgrade all declared packages.
#### Scenario: Full system upgrade with all packages
- **WHEN** system has declared package list
- **THEN** system shall run pacman -Syu with all declared package names
#### Scenario: No partial upgrades
- **WHEN** running pacman commands
- **THEN** system shall use -Syu flag (full system upgrade) ensuring all packages are latest
#### Scenario: Package availability check
- **WHEN** a package from input is not in pacman repositories
- **THEN** system shall report the error and include package name
#### Scenario: Pacman execution capture
- **WHEN** pacman commands execute
- **THEN** system shall capture both stdout and stderr for error reporting
#### Scenario: Exit code propagation
- **WHEN** pacman commands execute
- **THEN** system shall exit with code equal to pacman's exit code for success/failure detection
@@ -0,0 +1,21 @@
## ADDED Requirements
### Requirement: Can load package states from state files
The system SHALL load package lists from state files specified via --state flag.
#### Scenario: Single state file loading
- **WHEN** a state file is provided via --state flag
- **THEN** system shall read package names from the file content
#### Scenario: Multiple state file loading
- **WHEN** multiple --state flags are provided
- **THEN** system shall load package names from each file
#### Scenario: State file format is text list
- **WHEN** loading from state files
- **THEN** system shall parse whitespace-delimited package names
#### Scenario: File path validation
- **WHEN** a state file path points to a non-existent file
- **THEN** system shall report a file read error
@@ -0,0 +1,17 @@
## ADDED Requirements
### Requirement: Can detect empty state input
The system SHALL detect when no packages are provided in any input source.
#### Scenario: Empty state warning
- **WHEN** no package names are found in stdin or state files
- **THEN** system shall print a warning to stderr
#### Scenario: Empty state warning message
- **WHEN** warning is printed for empty state
- **THEN** message shall say: "Called without state, aborting.."
#### Scenario: Abort on empty state
- **WHEN** empty state is detected
- **THEN** system shall exit with code 1 (error: no packages to sync)
@@ -0,0 +1,17 @@
## ADDED Requirements
### Requirement: Can read package lists from stdin
The system SHALL accept package names from standard input, where each line represents a package name.
#### Scenario: Packages from stdin are read correctly
- **WHEN** package names are passed via stdin separated by whitespace, tabs, or newlines
- **THEN** system shall parse each unique package name from the input stream
#### Scenario: Empty stdin input is handled
- **WHEN** stdin contains no package names
- **THEN** system shall skip stdin input processing
#### Scenario: Whitespace normalization
- **WHEN** packages are separated by multiple spaces, tabs, or newlines
- **THEN** each package name shall have leading/trailing whitespace trimmed
@@ -0,0 +1,23 @@
## ADDED Requirements
### Requirement: Can resolve transitive dependencies automatically
The system SHALL automatically determine and install all transitive dependencies
for declared packages, so users only need to specify direct packages.
#### Scenario: Transitive dependencies are resolved
- **WHEN** a package with dependencies is declared in state
- **THEN** system shall identify all transitive dependencies via pacman
- **AND** include them in the installation operation
#### Scenario: Dependency resolution includes AUR dependencies
- **WHEN** a package's transitive dependencies include AUR packages
- **THEN** system shall resolve those AUR dependencies via makepkg
#### Scenario: Shared dependencies are deduplicated
- **WHEN** multiple declared packages share dependencies
- **THEN** system shall install each shared dependency only once
#### Scenario: Missing dependency handling
- **WHEN** a declared package has a dependency not available in pacman or AUR
- **THEN** system shall report error for the missing dependency