OS Detector¶
os_detector
¶
OS detection for the Linux AI NPU Assistant.
Detects the running Linux distribution and environment so the AI assistant
can generate distro-accurate commands (e.g. apt on Ubuntu/Debian,
dnf on Fedora, pacman on Arch, etc.).
Detection sources (in priority order)¶
/etc/os-release— machine-readable, present on all modern distros.platform.freedesktop_os_release()— Python 3.10+ stdlib wrapper for the same file (used when available)./etc/lsb-release,/etc/redhat-release,/etc/arch-release,/etc/alpine-release— legacy fallbacks for older systems.
All detection is read-only, uses no network, and runs in < 5 ms. Results are cached after the first call so repeated access is free.
OSInfo
dataclass
¶
OSInfo(id='', name='', pretty_name='', version='', codename='', id_like='', package_manager='', install_command='', architecture='', kernel='', init_system='', desktop='', hostname='', extra=dict())
Detected operating-system information.
All fields are strings so they can be safely embedded in prompts. Unknown values are represented as empty strings.
id
class-attribute
instance-attribute
¶
Machine-readable distro ID, e.g. ubuntu, fedora, arch.
name
class-attribute
instance-attribute
¶
Human-friendly distro name, e.g. Ubuntu, Fedora Linux.
pretty_name
class-attribute
instance-attribute
¶
Full name + version, e.g. Ubuntu 24.04.4 LTS (Noble Numbat).
codename
class-attribute
instance-attribute
¶
Release codename, e.g. noble, bookworm (empty if not set).
id_like
class-attribute
instance-attribute
¶
Space-separated parent distro IDs, e.g. debian or rhel fedora.
package_manager
class-attribute
instance-attribute
¶
Primary package manager: apt, dnf, pacman, etc.
install_command
class-attribute
instance-attribute
¶
Template install command, e.g. sudo apt install {package}.
architecture
class-attribute
instance-attribute
¶
CPU architecture, e.g. x86_64, aarch64.
kernel
class-attribute
instance-attribute
¶
Kernel version string, e.g. 6.8.0-57-generic.
init_system
class-attribute
instance-attribute
¶
Init system: systemd, openrc, runit, sysv, or unknown.
desktop
class-attribute
instance-attribute
¶
Current desktop environment or none (headless).
extra
class-attribute
instance-attribute
¶
Any additional keys from /etc/os-release not captured above.
to_system_prompt_block
¶
Return a concise block suitable for injection into the system prompt.
The block tells the AI exactly which distro, version, and package manager are active so every command suggestion is accurate.
Source code in src/os_detector.py
detect
cached
¶
Detect the current OS and return an :class:OSInfo instance.
Results are cached after the first call (lru_cache) so subsequent
accesses are free. Call :func:detect.cache_clear in tests to reset.