# https://github.com/bootc-dev/bootc/issues/1640
%if 0%{?fedora} || 0%{?rhel} >= 10 || 0%{?rust_minor} >= 89
%global new_cargo_macros 1
%else
%global new_cargo_macros 0
%endif
# RPM Specific
%define python_package_src command_line_assistant
%define binary_name c
%define symlink_binary_name cla
%define daemon_binary_name clad
%define selinux_policyver 41.27-1
%define selinuxtype targeted
%define modulename %{daemon_binary_name}
Name: command-line-assistant
# Replaced by cargo xtask spec
Version: 202510151807.g6c5ef87980
Release: 1%{?dist}
Summary: A simple wrapper to interact with RAG
License: Apache-2.0
URL: https://github.com/rhel-lightspeed/command-line-assistant
Source0: command-line-assistant-202510151807.g6c5ef87980.tar.zstd
Source1: command-line-assistant-202510151807.g6c5ef87980-vendor.tar.zstd
%if 0%{?rhel}
BuildRequires: rust-toolset
%else
BuildRequires: cargo-rpm-macros >= 25
%endif
BuildRequires: systemd
BuildRequires: systemd-units
BuildRequires: openssl-devel
# Build dependencies for SELinux policy
BuildRequires: selinux-policy-devel
Requires: systemd
# Add selinux subpackage as dependency
Requires: %{name}-selinux
%description
A simple wrapper to interact with RAG
%package selinux
Summary: CLAD SELinux policy
BuildArch: noarch
Requires: selinux-policy-%{selinuxtype}
Requires(post): selinux-policy-%{selinuxtype}
%description selinux
This package installs and sets up the SELinux policy security module for clad.
%prep
%autosetup -a1 -n %{name}-%{version}
# Default -v vendor config doesn't support non-crates.io deps (i.e. git)
cp .cargo/vendor-config.toml .
%cargo_prep -N
cat vendor-config.toml >> .cargo/config.toml
rm vendor-config.toml
%build
# Build the main bootc binary
%cargo_build
%cargo_vendor_manifest
# https://pagure.io/fedora-rust/rust-packaging/issue/33
sed -i -e '/https:\/\//d' cargo-vendor.txt
%cargo_license_summary
%{cargo_license} > LICENSE.dependencies
# Build selinux policy file
pushd data/release/selinux
%{__make} %{modulename}.pp.bz2
popd
%install
# Install binaries
install -D -m 0755 target/release/clad %{buildroot}%{_bindir}/clad
install -D -m 0755 target/release/c %{buildroot}%{_bindir}/c
# Create needed directories in buildroot
%{__install} -d -m 0755 %{buildroot}/%{_sysconfdir}/xdg/%{name}
%{__install} -d -m 0755 %{buildroot}/%{_sysconfdir}/systemd/system/clad.service.d
%{__install} -d -m 0755 %{buildroot}/%{_sharedstatedir}/%{name}
%{__install} -d %{buildroot}/%{_mandir}/man1
%{__install} -d %{buildroot}/%{_mandir}/man8
%{__install} -d %{buildroot}/%{_datadir}/selinux/packages/%{selinuxtype}
# Symlink `c` to `cla`
ln -sr %{buildroot}/%{_bindir}/%{binary_name} %{buildroot}/%{_bindir}/%{symlink_binary_name}
# ln -sr %{buildroot}%{_mandir}/man1/%{binary_name}.1 %{buildroot}%{_mandir}/man1/%{symlink_binary_name}.1
# System units & tmpfiles.d config
%{__install} -D -m 0644 data/release/systemd/%{daemon_binary_name}.service %{buildroot}/%{_unitdir}/%{daemon_binary_name}.service
%{__install} -D -m 0644 data/release/systemd/%{daemon_binary_name}.tmpfiles.conf %{buildroot}/%{_tmpfilesdir}/%{daemon_binary_name}.conf
# Config file
%{__install} -D -m 0600 data/release/xdg/config.toml %{buildroot}/%{_sysconfdir}/xdg/%{name}/config.toml
# Manpages
# %{__install} -D -m 0644 data/release/man/%{binary_name}.1 %{buildroot}/%{_mandir}/man1/%{binary_name}.1
# %{__install} -D -m 0644 data/release/man/%{daemon_binary_name}.8 %{buildroot}/%{_mandir}/man8/%{daemon_binary_name}.8
# selinux
%{__install} -m 0644 data/release/selinux/%{modulename}.pp.bz2 %{buildroot}%{_datadir}/selinux/packages/%{selinuxtype}/%{modulename}.pp.bz2
%preun
%systemd_preun %{daemon_binary_name}.service
%pre selinux
%selinux_relabel_pre -s %{selinuxtype}
%post
%systemd_post %{daemon_binary_name}.service
%post selinux
%selinux_modules_install -s %{selinuxtype} %{_datadir}/selinux/packages/%{selinuxtype}/%{modulename}.pp.bz2
%postun
%systemd_postun_with_restart %{daemon_binary_name}.service
%postun selinux
if [ $1 -eq 0 ]; then
%selinux_modules_uninstall -s %{selinuxtype} %{modulename}
fi
%posttrans selinux
%selinux_relabel_post -s %{selinuxtype}
%files
%doc README.md
%license LICENSE
%license LICENSE.dependencies
%license cargo-vendor.txt
# Binaries
%{_bindir}/%{binary_name}
%{_bindir}/%{symlink_binary_name}
%{_bindir}/%{daemon_binary_name}
# System units
%{_unitdir}/%{daemon_binary_name}.service
%{_tmpfilesdir}/%{daemon_binary_name}.conf
# # Manpages
# %{_mandir}/man1/%{binary_name}.1.gz
# %{_mandir}/man1/%{symlink_binary_name}.1.gz
# %{_mandir}/man8/%{daemon_binary_name}.8.gz
# Needed directories
%dir %attr(0700, root, root) %{_sharedstatedir}/%{name}
%dir %attr(0700, root, root) %{_sysconfdir}/xdg/%{name}
%dir %attr(0700, root, root) %{_sysconfdir}/systemd/system/clad.service.d
# Config file
%config(noreplace) %attr(0600, root, root) %{_sysconfdir}/xdg/%{name}/config.toml
%files selinux
%attr(0600,root,root) %{_datadir}/selinux/packages/%{selinuxtype}/%{modulename}.pp.bz2
%ghost %verify(not md5 size mode mtime) %{_sharedstatedir}/selinux/%{selinuxtype}/active/modules/200/%{modulename}
%changelog
* Mon Aug 18 2025 Link Dupont - 0.4.2
- Migrate from poetry to uv
- Fix typo in warning message for total input size
- Catch OSError being thrown by submit method (RHEL-102629)
* Thu Jul 10 2025 Link Dupont - 0.4.1
- Add horizontal lines back
- Limit permission for history database to own user
- Fix interactive mode regression
- Fix legal message regression found in 0.4
- Print help message in case of command has no arguments (RHEL-93272)
- Fix CommandContext to get user ID correctly by changing from os.getegid() to os.geteuid()
- Allow to pass terminal output without question or stdin
- Add missing line for %files in rpmbuild
- Add horizontal line after spinner message
- Fix terminal width handling in TextWrapDecorator (RHEL-95741)
- Fix regression for c history
* Tue May 27 2025 Rodolfo Olivieri 0.4.0
- Refactor error codes
- Add support for plain, simple output
- Add tmpfs SELinux domain
- Add check in clear(-all) to check if there is any chat to clean
- Update colors in MarkdownRenderer to make the text more visible
- Apply fixes to commands description and manpage in general
- Fix legal message not showing up on each session
- Prevent --with-output without terminal capture
- Fix chat description and name defaults
- Default to --all in history command
- Fix unprocessable entity request for inference
- Warn if .bashrc.d missing
- Honor the http_proxy environment variables
* Tue Mar 18 2025 Rodolfo Olivieri 0.3.1
- Add exception handling for RuntimeError
- Disallow empty query arguments for query_string and stdin
- Simpify cert loading
- Fix dbus permissions for clad
- Prevent one character input from query_string and stdin
- Improve CLAD systemd unit security
- Add explanation for --description in chat command
- Add a --from-chat switch to history to filter out conversation
- Specify pymysql in the mysql connection string
- Fix incorrect key on database schema
- Add cla binary and a symlink for c
- Fix inconsistency in reading the terminal output
- Fix typos in legal and feedback message
* Mon Mar 03 2025 Rodolfo Olivieri 0.3.0
- Update markdown text from "Suggestion" to "Snippet"
- Add small feedback command
- Fix created_at dates for history and chat
- Rework to start sending context alongside question
- Add proxy setting for config.toml
- Rename all instances of public "query" to "chat"
- Add Chat sessions
- Add simple and interactive chat session
- Minor improvements to spinner
- Disable default audit loggers
- Rework audit logging system
- Add a new shell command to handle integrations
- Fix typoos for CLAD man page documentation
- Increase systemd timeout seconds
- Fix logging and audit
- Capture terminal output
- Remove unused output config and code handler
- Reverse order of the terminal output reader
- Rename interactive bash function
- Fix typing_extension and name change for chat command
- Add raw mode for queries
- Add error handling for history command
- Fix selinux policy configs
- Fix files and folders permissions when installing the RPM
- Add ability to load credentials from systemd
- Remove default value for with-output
- Improve error message for missing history
- Fix none values in stdin and query_string
- Fix typo in interactive session message
- Change permissions for xdg and lib folder for cla
- Fix search ordering in last output function
- Add KeyboardInterrupt exception catch to top-level call
- Limit down the size of message that will be sent to the backend
- Add message when the history is not enabled in the config file
- Add markdown renderer for chat and history
- Update links to use RHEL bug tracker
- Fix terminal line wrapping when in terminal capture mode
- Add null-character as prefix in logs to make parsing easier
- Update markdown text from "Suggestion" to "Snippet"
- Fixed created_at dates for chat and history
- Introduce a simple feedback mechanis,
* Mon Jan 27 2025 Rodolfo Olivieri 0.2.2
- Add noreplace to config file in specfile
* Wed Jan 22 2025 Rodolfo Olivieri 0.2.1
- Change import location for SQLAlchemy
* Tue Jan 21 2025 Rodolfo Olivieri 0.2.0
- Add String size limit to SQLAlchemy models
- Add workaround for SQLite UUID types
- Update packaging to include selinux custom policy
- Fix returncode when running commands
- Refactor the CLI to be separate commands
- Add an experimental rendering module for client
- Add Command Line Assistant Daemon
- Update specfile to include config from release dir
- Split the query and history dbus implementations
- Switch to system bus instead of session bus
- Add schema for input/output queries and history
- The connect_signals was triggered the API request twice
- Add local history management and improve the command
- Query against rlsrag
- Improve error handling
- Update systemd units to be socket activated
- Add 100% docstring coverage
- Fix query read from stdin
- Remove colorama dep
- Apply NO_COLOR to colored output
- Generate manpages for CLA and CLAD
- Prevent binary stdin
- Add audit logging capability to CLAD
- Add exception handling for SSL certificates
- Normalize the folder name to command-line-assistant
- Small code refactor for outputting text
- Update legal message
- Remove record command
- Fix config.toml for release and devel
- Add audit logging to stdout
- Add filter history option
- Implement a basic user session management
- Add input field for query by
- Migrate JSON history cache to database solution
- Fix ordering from history results
- Add user_id to history tables.
- Update manpages for RH1
* Mon Nov 25 2024 Rodolfo Olivieri 0.1.0
- Initial release of Command Line Assistant
- Rework config file handler and history
- Remove leftover yaml import from utils
- Fix config and history wrong paths
- Add option to disable SSL verification on backend
- Drop builds for EPEL 8
- Remove leftover yaml config file
- Refactor to use dataclasses instead of namedtuple
- Improve logging
- Transform dict to schema config
- Append stdin to the user query
- Convert the config class to be a dataclass
- Remove use of slots in dataclasses