Skip to content

Solution for long term memory for agent coding CLIs and to facilitate handoff between different agent vendors

Rust

feat(release): add native Arch packaging

AkitaOnRails6fde3570265b
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 5b3ca53a..bbf8ccf6 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -59,6 +59,13 @@ jobs:
- uses: Swatinem/rust-cache@v2
- run: cargo build --release --bin ai-memory
+ native-packaging:
+ name: native packaging assets
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+ - run: scripts/check-native-packaging.sh
+
# End-to-end docker smoke: builds the published image and confirms
# the binary inside runs. Catches Dockerfile drift (missing COPY,
# bad ENTRYPOINT) before it lands in production.
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 7f9de8f3..d7784f25 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -1,16 +1,18 @@
name: release
-# Triggered when a version tag is pushed, e.g. git push origin v0.2.0.
-# Builds the Docker image and pushes it to Docker Hub with both the
-# version tag and `latest`.
+# Triggered when a version tag is pushed, e.g. git push origin v0.3.0.
+# Builds the native Linux release tarball, creates the GitHub Release,
+# and pushes the Docker image to Docker Hub with both the version tag
+# and `latest` when Docker Hub credentials are configured.
#
-# Required secrets (set in repo Settings → Secrets and variables → Actions):
+# Optional publish secrets (set in repo Settings → Secrets and variables → Actions):
# DOCKERHUB_USERNAME — Docker Hub account name
# DOCKERHUB_TOKEN — Docker Hub access token (read/write)
+# AUR_SSH_PRIVATE_KEY — private key for an AUR account with maintainer access
#
-# The CI workflow already validates the binary (fmt / clippy / test).
-# This workflow assumes CI passed on the same commit; it only builds
-# and pushes the image.
+# The CI workflow already validates the binary and package assets
+# (fmt / clippy / test / native-packaging). This workflow assumes CI
+# passed on the same commit and only performs release publication.
on:
push:
@@ -20,30 +22,121 @@ on:
env:
CARGO_TERM_COLOR: always
+permissions:
+ contents: write
+ packages: write
+
jobs:
+ validate-version:
+ name: validate release version
+ runs-on: ubuntu-latest
+ outputs:
+ version: ${{ steps.version.outputs.version }}
+ steps:
+ - uses: actions/checkout@v4
+
+ - id: version
+ run: |
+ set -euo pipefail
+ tag_version="${GITHUB_REF_NAME#v}"
+ manifest_version="$(awk -F ' *= *' '
+ /^\[workspace.package\]$/ { in_workspace_package = 1; next }
+ /^\[/ { in_workspace_package = 0 }
+ in_workspace_package && $1 == "version" {
+ gsub(/"/, "", $2);
+ print $2;
+ exit;
+ }
+ ' Cargo.toml)"
+ if [ -z "$manifest_version" ]; then
+ echo "could not read [workspace.package].version from Cargo.toml" >&2
+ exit 1
+ fi
+ if [ "$tag_version" != "$manifest_version" ]; then
+ echo "tag version v${tag_version} does not match Cargo.toml version ${manifest_version}" >&2
+ exit 1
+ fi
+ echo "version=${tag_version}" >> "$GITHUB_OUTPUT"
+
+ binary:
+ name: linux x86_64 binary
+ needs: validate-version
+ runs-on: ubuntu-22.04
+ steps:
+ - uses: actions/checkout@v4
+
+ - uses: dtolnay/[email protected]
+
+ - uses: Swatinem/rust-cache@v2
+
+ - name: Build release binary
+ env:
+ TAILWIND_SKIP: "1"
+ run: cargo build --release -p ai-memory-cli
+
+ - name: Create release tarball
+ run: |
+ artifact="ai-memory-linux-x86_64"
+ mkdir -p "dist/$artifact"
+ cp target/release/ai-memory "dist/$artifact/ai-memory"
+ cp -a hooks "dist/$artifact/hooks"
+ mkdir -p "dist/$artifact/packaging"
+ cp -a packaging/systemd "dist/$artifact/packaging/systemd"
+ cp -a packaging/sysusers "dist/$artifact/packaging/sysusers"
+ cp -a packaging/tmpfiles "dist/$artifact/packaging/tmpfiles"
+ cp -a packaging/env "dist/$artifact/packaging/env"
+ mkdir -p "dist/$artifact/crates/ai-memory-cli/templates"
+ cp crates/ai-memory-cli/templates/config.default.toml \
+ "dist/$artifact/crates/ai-memory-cli/templates/config.default.toml"
+ mkdir -p "dist/$artifact/docs"
+ cp README.md LICENSE "dist/$artifact/"
+ cp docs/install.md "dist/$artifact/docs/install.md"
+ tar -C "dist/$artifact" -czf "$artifact.tar.gz" .
+ sha256sum "$artifact.tar.gz" > "$artifact.tar.gz.sha256"
+
+ - uses: actions/upload-artifact@v4
+ with:
+ name: ai-memory-linux-x86_64
+ path: |
+ ai-memory-linux-x86_64.tar.gz
+ ai-memory-linux-x86_64.tar.gz.sha256
+
# Gate the publish on the Docker Hub secrets actually being present, so a
# fresh clone (or a fork) doesn't get a red failing run on every tag. The
# docker job activates automatically once DOCKERHUB_USERNAME + _TOKEN are
- # set in repo Settings → Secrets and variables → Actions.
+ # set in repo Settings → Secrets and variables → Actions. Same idea for AUR:
+ # publishing activates only when AUR_SSH_PRIVATE_KEY is configured.
check-secrets:
name: check publish credentials
runs-on: ubuntu-latest
outputs:
- enabled: ${{ steps.check.outputs.enabled }}
+ docker_enabled: ${{ steps.check.outputs.docker_enabled }}
+ aur_enabled: ${{ steps.check.outputs.aur_enabled }}
steps:
- id: check
+ env:
+ DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
+ DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
+ AUR_SSH_PRIVATE_KEY: ${{ secrets.AUR_SSH_PRIVATE_KEY }}
run: |
- if [ -n "${{ secrets.DOCKERHUB_TOKEN }}" ] && [ -n "${{ secrets.DOCKERHUB_USERNAME }}" ]; then
- echo "enabled=true" >> "$GITHUB_OUTPUT"
+ if [ -n "$DOCKERHUB_TOKEN" ] && [ -n "$DOCKERHUB_USERNAME" ]; then
+ echo "docker_enabled=true" >> "$GITHUB_OUTPUT"
else
- echo "enabled=false" >> "$GITHUB_OUTPUT"
+ echo "docker_enabled=false" >> "$GITHUB_OUTPUT"
echo "::warning::DOCKERHUB_USERNAME / DOCKERHUB_TOKEN not set — skipping image publish. Add them in repo Settings → Secrets and variables → Actions to enable tag-triggered publishing."
fi
+ if [ -n "$AUR_SSH_PRIVATE_KEY" ]; then
+ echo "aur_enabled=true" >> "$GITHUB_OUTPUT"
+ else
+ echo "aur_enabled=false" >> "$GITHUB_OUTPUT"
+ echo "::warning::AUR_SSH_PRIVATE_KEY not set — skipping AUR publish."
+ fi
+
docker:
name: docker build + push
- needs: check-secrets
- if: needs.check-secrets.outputs.enabled == 'true'
+ needs: [check-secrets, validate-version]
+ if: needs.check-secrets.outputs.docker_enabled == 'true'
runs-on: ubuntu-latest
permissions:
contents: read
@@ -59,11 +152,6 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- # Extract the version from the tag (strips the leading "v").
- - name: Extract version
- id: version
- run: echo "VERSION=${GITHUB_REF_NAME#v}" >> "$GITHUB_OUTPUT"
-
- name: Build and push
uses: docker/build-push-action@v6
with:
@@ -72,13 +160,152 @@ jobs:
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/ai-memory:latest
- ${{ secrets.DOCKERHUB_USERNAME }}/ai-memory:${{ steps.version.outputs.VERSION }}
+ ${{ secrets.DOCKERHUB_USERNAME }}/ai-memory:${{ needs.validate-version.outputs.version }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Smoke test the published image
run: |
- docker pull "${{ secrets.DOCKERHUB_USERNAME }}/ai-memory:${{ steps.version.outputs.VERSION }}"
+ docker pull "${{ secrets.DOCKERHUB_USERNAME }}/ai-memory:${{ needs.validate-version.outputs.version }}"
docker run --rm \
- "${{ secrets.DOCKERHUB_USERNAME }}/ai-memory:${{ steps.version.outputs.VERSION }}" \
+ "${{ secrets.DOCKERHUB_USERNAME }}/ai-memory:${{ needs.validate-version.outputs.version }}" \
--version
+
+ github-release:
+ name: github release
+ needs: [binary, validate-version]
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/download-artifact@v4
+ with:
+ path: artifacts
+ merge-multiple: true
+
+ - name: Generate release body
+ run: |
+ echo "## Checksums (SHA256)" > body.md
+ echo '```' >> body.md
+ cat artifacts/*.sha256 >> body.md
+ echo '```' >> body.md
+ echo "" >> body.md
+ echo "## Install" >> body.md
+ echo '```bash' >> body.md
+ echo "# Arch Linux (AUR)" >> body.md
+ echo "yay -S ai-memory-bin # prebuilt Linux x86_64 binary" >> body.md
+ echo "yay -S ai-memory # builds from source" >> body.md
+ echo "" >> body.md
+ echo "# Docker" >> body.md
+ echo "docker pull akitaonrails/ai-memory:${{ needs.validate-version.outputs.version }}" >> body.md
+ echo "" >> body.md
+ echo "# From source" >> body.md
+ echo "cargo install --git https://github.com/akitaonrails/ai-memory --tag ${GITHUB_REF_NAME}" >> body.md
+ echo '```' >> body.md
+
+ - name: Create GitHub Release
+ env:
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ run: |
+ gh release create "$GITHUB_REF_NAME" artifacts/* \
+ --repo "$GITHUB_REPOSITORY" \
+ --title "$GITHUB_REF_NAME" \
+ --notes-file body.md \
+ --latest
+
+ aur:
+ name: aur publish
+ needs: [check-secrets, github-release, validate-version]
+ if: needs.check-secrets.outputs.aur_enabled == 'true'
+ runs-on: ubuntu-latest
+ container: archlinux:latest
+ steps:
+ - uses: actions/checkout@v4
+
+ - uses: actions/download-artifact@v4
+ with:
+ name: ai-memory-linux-x86_64
+ path: artifacts
+
+ - name: Install AUR publish tools
+ run: pacman -Syu --noconfirm --needed base-devel curl git openssh
+
+ - name: Publish ai-memory AUR packages
+ env:
+ AUR_SSH_PRIVATE_KEY: ${{ secrets.AUR_SSH_PRIVATE_KEY }}
+ VERSION: ${{ needs.validate-version.outputs.version }}
+ run: |
+ set -euo pipefail
+
+ version="$VERSION"
+ source_sha="$(curl -fsSL "https://github.com/akitaonrails/ai-memory/archive/refs/tags/v${version}.tar.gz" | sha256sum | awk '{print $1}')"
+ bin_sha="$(sha256sum artifacts/ai-memory-linux-x86_64.tar.gz | awk '{print $1}')"
+
+ useradd -m aurbuild
+ chown -R aurbuild:aurbuild "$GITHUB_WORKSPACE"
+ install -d -m 0700 -o aurbuild -g aurbuild /home/aurbuild/.ssh
+ printf '%s\n' "$AUR_SSH_PRIVATE_KEY" > /home/aurbuild/.ssh/aur
+ chmod 0600 /home/aurbuild/.ssh/aur
+ chown aurbuild:aurbuild /home/aurbuild/.ssh/aur
+ ssh-keyscan aur.archlinux.org > /home/aurbuild/.ssh/known_hosts
+ chown aurbuild:aurbuild /home/aurbuild/.ssh/known_hosts
+ cat >/home/aurbuild/.ssh/config <<'EOF'
+ Host aur.archlinux.org
+ HostName aur.archlinux.org
+ User aur
+ IdentityFile ~/.ssh/aur
+ IdentitiesOnly yes
+ EOF
+ chown aurbuild:aurbuild /home/aurbuild/.ssh/config
+ chmod 0600 /home/aurbuild/.ssh/config
+
+ runuser -u aurbuild -- bash -s -- "$version" "$source_sha" "$bin_sha" "$GITHUB_WORKSPACE" <<'EOF'
+ set -euo pipefail
+
+ version="$1"
+ source_sha="$2"
+ bin_sha="$3"
+ workspace="$4"
+ workdir="/tmp/ai-memory-aur-publish"
+
+ git config --global user.name "ai-memory release bot"
+ git config --global user.email "[email protected]"
+
+ rm -rf "$workdir"
+ mkdir -p "$workdir/generated"
+
+ source_pkgbuild="$workdir/generated/PKGBUILD.source"
+ bin_pkgbuild="$workdir/generated/PKGBUILD.bin"
+ cp "$workspace/packaging/aur/PKGBUILD" "$source_pkgbuild"
+ cp "$workspace/packaging/aur/PKGBUILD-bin" "$bin_pkgbuild"
+
+ sed -i \
+ -e "s/^pkgver=.*/pkgver=${version}/" \
+ -e "s/^pkgrel=.*/pkgrel=1/" \
+ -e "s/^sha256sums=('.*')/sha256sums=('${source_sha}')/" \
+ "$source_pkgbuild"
+ sed -i \
+ -e "s/^pkgver=.*/pkgver=${version}/" \
+ -e "s/^pkgrel=.*/pkgrel=1/" \
+ -e "s/^sha256sums_x86_64=('.*')/sha256sums_x86_64=('${bin_sha}')/" \
+ "$bin_pkgbuild"
+
+ publish_pkg() {
+ pkgbase="$1"
+ pkgbuild="$2"
+ repo="$workdir/$pkgbase"
+
+ git clone "ssh://[email protected]/${pkgbase}.git" "$repo"
+ cp "$pkgbuild" "$repo/PKGBUILD"
+ cp "$workspace/packaging/aur/ai-memory.install" "$repo/ai-memory.install"
+ (cd "$repo" && makepkg --printsrcinfo > .SRCINFO)
+ (cd "$repo" && git add PKGBUILD .SRCINFO ai-memory.install)
+ if (cd "$repo" && git diff --cached --quiet); then
+ echo "${pkgbase}: no AUR changes to publish"
+ return 0
+ fi
+ (cd "$repo" && git commit -m "Update to ${version}")
+ (cd "$repo" && git push)
+ }
+
+ publish_pkg ai-memory "$source_pkgbuild"
+ publish_pkg ai-memory-bin "$bin_pkgbuild"
+ EOF
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 35f0bdcb..7ea659a1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,7 +6,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased]
+
+## [0.3.0] - 2026-05-27
### Added
+- Arch Linux native packaging assets: source and prebuilt AUR package
+ definitions, system/user systemd units, sysusers/tmpfiles entries, native
+ config/env templates, CI-safe alternate-root packaging checks, and a manual
+ disposable-distrobox integration harness for validating real service startup
+ before publishing.
+- Tag-triggered release automation now validates that `vX.Y.Z` matches
+ `Cargo.toml`, publishes a native Linux release tarball, keeps Docker image
+ publishing behind Docker Hub secrets, and optionally publishes both AUR
+ package bases when `AUR_SSH_PRIVATE_KEY` is configured.
- `memory_write_page` MCP tool for explicit durable annotations, so agents can
write permanent wiki knowledge without abusing single-use handoffs.
- `openai-oauth` LLM provider for ChatGPT/Codex accounts, including
@@ -272,7 +283,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Consolidator used server startup default project instead of the
session's actual project.
-[Unreleased]: https://github.com/akitaonrails/ai-memory/compare/v0.2.0...HEAD
+[Unreleased]: https://github.com/akitaonrails/ai-memory/compare/v0.3.0...HEAD
+[0.3.0]: https://github.com/akitaonrails/ai-memory/releases/tag/v0.3.0
[0.2.0]: https://github.com/akitaonrails/ai-memory/releases/tag/v0.2.0
[0.1.3]: https://github.com/akitaonrails/ai-memory/releases/tag/v0.1.3
[0.1.2]: https://github.com/akitaonrails/ai-memory/releases/tag/v0.1.2
diff --git a/Cargo.lock b/Cargo.lock
index c25fadae..c8d4569a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -31,7 +31,7 @@ dependencies = [
[[package]]
name = "ai-memory-cli"
-version = "0.2.0"
+version = "0.3.0"
dependencies = [
"ai-memory-consolidate",
"ai-memory-core",
@@ -70,7 +70,7 @@ dependencies = [
[[package]]
name = "ai-memory-consolidate"
-version = "0.2.0"
+version = "0.3.0"
dependencies = [
"ai-memory-core",
"ai-memory-llm",
@@ -91,7 +91,7 @@ dependencies = [
[[package]]
name = "ai-memory-core"
-version = "0.2.0"
+version = "0.3.0"
dependencies = [
"jiff",
"regex",
@@ -105,7 +105,7 @@ dependencies = [
[[package]]
name = "ai-memory-eval"
-version = "0.2.0"
+version = "0.3.0"
dependencies = [
"ai-memory-consolidate",
"ai-memory-core",
@@ -124,7 +124,7 @@ dependencies = [
[[package]]
name = "ai-memory-hooks"
-version = "0.2.0"
+version = "0.3.0"
dependencies = [
"ai-memory-consolidate",
"ai-memory-core",
@@ -146,7 +146,7 @@ dependencies = [
[[package]]
name = "ai-memory-llm"
-version = "0.2.0"
+version = "0.3.0"
dependencies = [
"ai-memory-core",
"anyhow",
@@ -167,7 +167,7 @@ dependencies = [
[[package]]
name = "ai-memory-mcp"
-version = "0.2.0"
+version = "0.3.0"
dependencies = [
"ai-memory-consolidate",
"ai-memory-core",
@@ -193,7 +193,7 @@ dependencies = [
[[package]]
name = "ai-memory-store"
-version = "0.2.0"
+version = "0.3.0"
dependencies = [
"ai-memory-core",
"anyhow",
@@ -213,7 +213,7 @@ dependencies = [
[[package]]
name = "ai-memory-web"
-version = "0.2.0"
+version = "0.3.0"
dependencies = [
"ai-memory-core",
"ai-memory-store",
@@ -236,7 +236,7 @@ dependencies = [
[[package]]
name = "ai-memory-wiki"
-version = "0.2.0"
+version = "0.3.0"
dependencies = [
"ai-memory-core",
"ai-memory-llm",
diff --git a/Cargo.toml b/Cargo.toml
index 62d36aaa..7e926f0f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -16,7 +16,7 @@ members = [
]
[workspace.package]
-version = "0.2.0"
+version = "0.3.0"
edition = "2024"
rust-version = "1.95"
license = "MIT"
@@ -25,14 +25,14 @@ authors = ["Fabio Akita <[email protected]>"]
[workspace.dependencies]
# Inter-crate dependencies.
-ai-memory-core = { path = "crates/ai-memory-core", version = "0.2.0" }
-ai-memory-store = { path = "crates/ai-memory-store", version = "0.2.0" }
-ai-memory-wiki = { path = "crates/ai-memory-wiki", version = "0.2.0" }
-ai-memory-mcp = { path = "crates/ai-memory-mcp", version = "0.2.0" }
-ai-memory-hooks = { path = "crates/ai-memory-hooks", version = "0.2.0" }
-ai-memory-llm = { path = "crates/ai-memory-llm", version = "0.2.0" }
-ai-memory-consolidate = { path = "crates/ai-memory-consolidate", version = "0.2.0" }
-ai-memory-web = { path = "crates/ai-memory-web", version = "0.2.0" }
+ai-memory-core = { path = "crates/ai-memory-core", version = "0.3.0" }
+ai-memory-store = { path = "crates/ai-memory-store", version = "0.3.0" }
+ai-memory-wiki = { path = "crates/ai-memory-wiki", version = "0.3.0" }
+ai-memory-mcp = { path = "crates/ai-memory-mcp", version = "0.3.0" }
+ai-memory-hooks = { path = "crates/ai-memory-hooks", version = "0.3.0" }
+ai-memory-llm = { path = "crates/ai-memory-llm", version = "0.3.0" }
+ai-memory-consolidate = { path = "crates/ai-memory-consolidate", version = "0.3.0" }
+ai-memory-web = { path = "crates/ai-memory-web", version = "0.3.0" }
# (Workspace shared deps follow below)
diff --git a/README.md b/README.md
index f5da14de..3d17acab 100644
--- a/README.md
+++ b/README.md
@@ -18,7 +18,7 @@
| Area | Status | Notes |
|---|---|---|
-| Linux | Supported | Primary Docker/server target and CI platform. |
+| Linux | Supported | Primary Docker/server target and CI platform. Native Arch/AUR packages include system and user systemd units. |
| macOS | Supported | Workspace tests run in CI; native source builds are supported. |
| Windows via WSL2 | Supported | Use the Linux install path inside WSL2 when the agent runs there. |
| Native Windows | Experimental | PowerShell wrapper and `.ps1` hooks are available; real agent harness feedback still needed. See [`docs/windows.md`](docs/windows.md). |
@@ -117,6 +117,34 @@ priors are at the [bottom](#influences-and-prior-art).
## Quick start
+### Arch Linux (AUR)
+
+For native Arch installs, use the AUR packages. They install
+`/usr/bin/ai-memory`, packaged hook sources, and both system-level and
+user-level systemd units.
+
+```bash
+yay -S ai-memory-bin # prebuilt Linux x86_64 binary
+yay -S ai-memory # builds from source
+```
+
+Single-user workstation:
+
+```bash
+mkdir -p ~/.config/ai-memory ~/.local/share/ai-memory
+ai-memory --data-dir ~/.local/share/ai-memory \
+ --config ~/.config/ai-memory/config.toml init
+systemctl --user enable --now ai-memory.service
+ai-memory install-mcp --client claude-code --apply
+ai-memory install-hooks --agent claude-code --apply
+```
+
+System service installs use `/var/lib/ai-memory` and `/etc/ai-memory/` via the
+packaged unit. Full user-service, system-service, auth, and provider setup is in
+[`docs/install.md#arch-linux-native-packages-aur`](docs/install.md#arch-linux-native-packages-aur).
+
+### Docker
+
You need: Docker + an agent CLI (Claude Code, Codex, OpenCode, OMP, Cursor,
Antigravity CLI, or anything else that speaks MCP).
diff --git a/crates/ai-memory-cli/src/commands/init.rs b/crates/ai-memory-cli/src/commands/init.rs
index 097a38cd..6c9e5b98 100644
--- a/crates/ai-memory-cli/src/commands/init.rs
+++ b/crates/ai-memory-cli/src/commands/init.rs
@@ -2,6 +2,7 @@
use std::fs;
use std::io::Write;
+use std::path::{Path, PathBuf};
use anyhow::{Context, Result};
@@ -15,12 +16,15 @@ const SUBDIRS: &[&str] = &["wiki", "raw", "db", "models"];
/// Run the `init` subcommand.
///
/// Creates `<data_dir>/{wiki,raw,db,models}` (idempotent) and writes a default
-/// `config.toml` unless one already exists (use `--force` to overwrite).
+/// config file unless one already exists (use `--force` to overwrite). With no
+/// explicit `--config`, the config remains at `<data_dir>/config.toml`; packaged
+/// systemd units can pass `--config /etc/ai-memory/config.toml` or
+/// `--config ~/.config/ai-memory/config.toml` without changing the data root.
///
/// # Errors
/// Returns an error if directories cannot be created or the config file
/// cannot be written.
-pub fn run(config: &Config, args: InitArgs) -> Result<()> {
+pub fn run(config: &Config, args: InitArgs, config_path: Option<&Path>) -> Result<()> {
let root = &config.data_dir;
fs::create_dir_all(root).with_context(|| format!("creating data root {}", root.display()))?;
@@ -30,13 +34,17 @@ pub fn run(config: &Config, args: InitArgs) -> Result<()> {
tracing::info!(path = %path.display(), "ensured directory");
}
- let cfg_path = root.join("config.toml");
+ let cfg_path = init_config_path(root, config_path);
if cfg_path.exists() && !args.force {
tracing::info!(
path = %cfg_path.display(),
"config already exists; leaving untouched (pass --force to overwrite)",
);
} else {
+ if let Some(parent) = cfg_path.parent() {
+ fs::create_dir_all(parent)
+ .with_context(|| format!("creating config dir {}", parent.display()))?;
+ }
let mut f = fs::File::create(&cfg_path)
.with_context(|| format!("creating {}", cfg_path.display()))?;
f.write_all(DEFAULT_CONFIG_TOML.as_bytes())
@@ -48,6 +56,12 @@ pub fn run(config: &Config, args: InitArgs) -> Result<()> {
Ok(())
}
+fn init_config_path(data_dir: &Path, explicit: Option<&Path>) -> PathBuf {
+ explicit
+ .map(PathBuf::from)
+ .unwrap_or_else(|| data_dir.join("config.toml"))
+}
+
#[cfg(test)]
mod tests {
use super::*;
@@ -64,7 +78,7 @@ mod tests {
fn init_creates_subdirs_and_config() {
let tmp = TempDir::new().unwrap();
let config = cfg_in(tmp.path());
- run(&config, InitArgs { force: false }).unwrap();
+ run(&config, InitArgs { force: false }, None).unwrap();
for sub in SUBDIRS {
assert!(tmp.path().join(sub).is_dir(), "missing {sub}");
}
@@ -75,18 +89,42 @@ mod tests {
fn init_is_idempotent() {
let tmp = TempDir::new().unwrap();
let config = cfg_in(tmp.path());
- run(&config, InitArgs { force: false }).unwrap();
+ run(&config, InitArgs { force: false }, None).unwrap();
// Touch the config to detect a clobber.
let stamp = std::fs::metadata(tmp.path().join("config.toml"))
.unwrap()
.modified()
.unwrap();
std::thread::sleep(std::time::Duration::from_millis(20));
- run(&config, InitArgs { force: false }).unwrap();
+ run(&config, InitArgs { force: false }, None).unwrap();
let stamp2 = std::fs::metadata(tmp.path().join("config.toml"))
.unwrap()
.modified()
.unwrap();
assert_eq!(stamp, stamp2, "second init clobbered the config");
}
+
+ #[test]
+ fn init_honors_explicit_config_path_outside_data_dir() {
+ let tmp = TempDir::new().unwrap();
+ let data_dir = tmp.path().join("data");
+ let config_dir = tmp.path().join("config").join("ai-memory");
+ let config_path = config_dir.join("config.toml");
+ let config = cfg_in(&data_dir);
+
+ run(
+ &config,
+ InitArgs { force: false },
+ Some(config_path.as_path()),
+ )
+ .unwrap();
+
+ assert!(data_dir.join("wiki").is_dir());
+ assert!(data_dir.join("raw").is_dir());
+ assert!(config_path.is_file());
+ assert!(
+ !data_dir.join("config.toml").exists(),
+ "explicit --config must not also write data-dir config"
+ );
+ }
}
diff --git a/crates/ai-memory-cli/src/commands/install_hooks.rs b/crates/ai-memory-cli/src/commands/install_hooks.rs
index 39bb87c3..8ef73225 100644
--- a/crates/ai-memory-cli/src/commands/install_hooks.rs
+++ b/crates/ai-memory-cli/src/commands/install_hooks.rs
@@ -1432,18 +1432,7 @@ fn resolve_hooks_dir(explicit: Option<&Path>, agent: AgentChoice) -> Result<Path
}
// Probe candidates in order. The first dir that exists wins.
- let candidates: [PathBuf; 3] = [
- // Cargo-run from the repo.
- repo_root_guess()
- .map(|r| r.join("hooks").join(sub))
- .unwrap_or_default(),
- // Docker image lays them out under /usr/local/share/ai-memory/.
- PathBuf::from(format!("/usr/local/share/ai-memory/hooks/{sub}")),
- // Local install honourable mention.
- dirs::data_local_dir()
- .map(|d| d.join("ai-memory/hooks").join(sub))
- .unwrap_or_default(),
- ];
+ let candidates = hook_source_candidates(sub, repo_root_guess(), dirs::data_local_dir());
for path in &candidates {
if !path.as_os_str().is_empty() && path.is_dir() {
return Ok(path.clone());
@@ -1452,6 +1441,29 @@ fn resolve_hooks_dir(explicit: Option<&Path>, agent: AgentChoice) -> Result<Path
anyhow::bail!("could not locate hooks directory. Tried: {:?}", candidates,);
}
+fn hook_source_candidates(
+ sub: &str,
+ repo_root: Option<PathBuf>,
+ data_local_dir: Option<PathBuf>,
+) -> Vec<PathBuf> {
+ let mut candidates = Vec::with_capacity(4);
+ // Cargo-run from the repo.
+ if let Some(root) = repo_root {
+ candidates.push(root.join("hooks").join(sub));
+ }
+ // Docker image lays them out under /usr/local/share/ai-memory/.
+ candidates.push(PathBuf::from(format!(
+ "/usr/local/share/ai-memory/hooks/{sub}"
+ )));
+ // Native Linux packages install hook sources under /usr/share.
+ candidates.push(PathBuf::from(format!("/usr/share/ai-memory/hooks/{sub}")));
+ // Local install honourable mention.
+ if let Some(dir) = data_local_dir {
+ candidates.push(dir.join("ai-memory/hooks").join(sub));
+ }
+ candidates
+}
+
fn repo_root_guess() -> Option<PathBuf> {
// When the binary lives under target/{debug,release}/<name>, the
// workspace root is two parents up.
@@ -1782,6 +1794,29 @@ Authorization = "Bearer secret-token"
assert!(!staged.join("_lib.sh").exists());
}
+ #[test]
+ fn hook_source_candidates_include_native_package_dir() {
+ let candidates = hook_source_candidates(
+ "claude-code",
+ Some(PathBuf::from("/repo")),
+ Some(PathBuf::from("/home/alice/.local/share")),
+ );
+
+ assert_eq!(candidates[0], PathBuf::from("/repo/hooks/claude-code"));
+ assert_eq!(
+ candidates[1],
+ PathBuf::from("/usr/local/share/ai-memory/hooks/claude-code")
+ );
+ assert_eq!(
+ candidates[2],
+ PathBuf::from("/usr/share/ai-memory/hooks/claude-code")
+ );
+ assert_eq!(
+ candidates[3],
+ PathBuf::from("/home/alice/.local/share/ai-memory/hooks/claude-code")
+ );
+ }
+
// ----------------------------------------------------------------
// OpenCode tests
// ----------------------------------------------------------------
diff --git a/crates/ai-memory-cli/src/commands/setup_agent.rs b/crates/ai-memory-cli/src/commands/setup_agent.rs
index 4f184b74..1206e156 100644
--- a/crates/ai-memory-cli/src/commands/setup_agent.rs
+++ b/crates/ai-memory-cli/src/commands/setup_agent.rs
@@ -270,6 +270,8 @@ fn resolve_source(explicit: Option<&Path>, sub: &str) -> Result<PathBuf> {
let mut v = vec![
// Docker image lays them out under /usr/local/share/.
PathBuf::from(format!("/usr/local/share/ai-memory/hooks/{sub}")),
+ // Native Linux packages install hook sources under /usr/share.
+ PathBuf::from(format!("/usr/share/ai-memory/hooks/{sub}")),
];
// Repo-local fallback for `cargo run setup-agent` during dev.
if let Some(p) = std::env::current_exe()
diff --git a/crates/ai-memory-cli/src/main.rs b/crates/ai-memory-cli/src/main.rs
index bce9fea7..76a8f1c8 100644
--- a/crates/ai-memory-cli/src/main.rs
+++ b/crates/ai-memory-cli/src/main.rs
@@ -27,6 +27,7 @@ use config::Config;
#[tokio::main]
async fn main() -> Result<()> {
let cli = Cli::parse();
+ let config_path = cli.config.clone();
let config = Arc::new(Config::load(cli.config.as_deref(), cli.data_dir.clone())?);
let _logging_guard = logging::init(&config)?;
@@ -39,7 +40,7 @@ async fn main() -> Result<()> {
);
match cli.command {
- Command::Init(args) => commands::init::run(&config, args),
+ Command::Init(args) => commands::init::run(&config, args, config_path.as_deref()),
Command::Status(args) => commands::status::run(&config, args).await,
Command::Search(args) => commands::search::run(&config, args).await,
Command::WritePage(args) => commands::write_page::run(&config, args).await,
diff --git a/crates/ai-memory-cli/tests/packaging.rs b/crates/ai-memory-cli/tests/packaging.rs
new file mode 100644
index 00000000..3ccf7007
--- /dev/null
+++ b/crates/ai-memory-cli/tests/packaging.rs
@@ -0,0 +1,69 @@
+//! Packaging asset regression tests.
+
+use std::path::{Path, PathBuf};
+
+fn repo_root() -> PathBuf {
+ Path::new(env!("CARGO_MANIFEST_DIR"))
+ .parent()
+ .and_then(Path::parent)
+ .expect("crate should live under crates/ai-memory-cli")
+ .to_path_buf()
+}
+
+fn read_repo(path: &str) -> String {
+ let path = repo_root().join(path);
+ std::fs::read_to_string(&path)
+ .unwrap_or_else(|e| panic!("failed to read {}: {e}", path.display()))
+}
+
+#[test]
+fn systemd_units_use_explicit_native_paths() {
+ let system = read_repo("packaging/systemd/ai-memory.service");
+ assert!(system.contains("--data-dir /var/lib/ai-memory"));
+ assert!(system.contains("--config /etc/ai-memory/config.toml"));
+ assert!(system.contains("EnvironmentFile=-/etc/ai-memory/env"));
+ assert!(system.contains("StateDirectory=ai-memory"));
+ assert!(system.contains("ReadWritePaths=/var/lib/ai-memory"));
+ assert!(!system.contains("/var/local"));
+
+ let user = read_repo("packaging/systemd/ai-memory-user.service");
+ assert!(user.contains("--data-dir %h/.local/share/ai-memory"));
+ assert!(user.contains("--config %h/.config/ai-memory/config.toml"));
+ assert!(user.contains("EnvironmentFile=-%h/.config/ai-memory/env"));
+ assert!(!user.contains("/var/lib/ai-memory"));
+}
+
+#[test]
+fn aur_packages_install_all_native_assets() {
+ for path in ["packaging/aur/PKGBUILD", "packaging/aur/PKGBUILD-bin"] {
+ let pkgbuild = read_repo(path);
+ assert!(pkgbuild.contains("/usr/bin/ai-memory"), "{path}");
+ assert!(pkgbuild.contains("/usr/share/ai-memory"), "{path}");
+ assert!(
+ pkgbuild.contains("/usr/lib/systemd/system/ai-memory.service"),
+ "{path}"
+ );
+ assert!(
+ pkgbuild.contains("/usr/lib/systemd/user/ai-memory.service"),
+ "{path}"
+ );
+ assert!(
+ pkgbuild.contains("/usr/lib/sysusers.d/ai-memory.conf"),
+ "{path}"
+ );
+ assert!(
+ pkgbuild.contains("/usr/lib/tmpfiles.d/ai-memory.conf"),
+ "{path}"
+ );
+ assert!(pkgbuild.contains("etc/ai-memory/config.toml"), "{path}");
+ assert!(pkgbuild.contains("etc/ai-memory/env"), "{path}");
+ assert!(
+ pkgbuild.contains("install -Dm0640 packaging/env/ai-memory.env"),
+ "{path}"
+ );
+ }
+
+ let install = read_repo("packaging/aur/ai-memory.install");
+ assert!(install.contains("sudo -u ai-memory ai-memory --data-dir /var/lib/ai-memory"));
+ assert!(!install.contains("sudo ai-memory --data-dir /var/lib/ai-memory"));
+}
diff --git a/docs/deploy.md b/docs/deploy.md
index 5b75dabb..30c02bdf 100644
--- a/docs/deploy.md
+++ b/docs/deploy.md
@@ -6,6 +6,13 @@ reachable on your LAN at `http://<host>:49374/mcp`, configured with
your LLM/embedding API keys, with backups handled by whatever you
already use for `/var/opt/docker/...`.
+If you want a native Linux service instead of Docker, use the Arch/AUR
+systemd path in [`docs/install.md`](install.md#arch-linux-native-packages-aur).
+That install mode uses `/var/lib/ai-memory` plus `/etc/ai-memory/` for the
+system service, or XDG user paths for the user service. The Docker deployment
+below remains `/data` inside the container and `/var/opt/docker/...` on the
+host.
+
## What gets committed vs. what stays local
The repo ships **templates only**. The real files with your homelab
diff --git a/docs/install.md b/docs/install.md
index 386f00f0..0bfba7e6 100644
--- a/docs/install.md
+++ b/docs/install.md
@@ -6,6 +6,8 @@ path (docker + Claude Code). This page covers everything else:
- [Server on a different machine](#server-on-a-different-machine)
(homelab, LAN box, remote server)
- [Configuring the CLI URL and auth](#configuring-the-cli-url-and-auth)
+- [Arch Linux native packages (AUR)](#arch-linux-native-packages-aur)
+ (systemd system service or user service)
- [Configuring other agent CLIs](#configuring-other-agent-clis)
(Codex, OpenCode, OMP, Cursor, Claude Desktop, Gemini CLI, Antigravity CLI, OpenClaw)
- [Installing hooks without docker](#installing-hooks-without-docker)
@@ -103,6 +105,284 @@ they either create local files or start the server itself.
---
+## Arch Linux native packages (AUR)
+
+Use the native packages when you want `/usr/bin/ai-memory` plus systemd units
+instead of the Docker wrapper. The package installs the binary and hook sources
+once; each user still stages their agent hook scripts into their own home dir
+with `install-hooks --apply`.
+
+### Package choice
+
+```bash
+yay -S ai-memory-bin # prebuilt Linux x86_64 binary, fastest install
+yay -S ai-memory # builds from source, works on x86_64 and aarch64
+```
+
+Both packages install the same runtime layout:
+
+| Path | Purpose |
+|---|---|
+| `/usr/bin/ai-memory` | Native CLI/server binary. |
+| `/usr/share/ai-memory/hooks/` | Packaged hook source bundle used by `install-hooks`. |
+| `/usr/lib/systemd/system/ai-memory.service` | System-wide service unit. |
+| `/usr/lib/systemd/user/ai-memory.service` | Per-user service unit. |
+| `/usr/lib/sysusers.d/ai-memory.conf` | Creates the `ai-memory` system user. |
+| `/usr/lib/tmpfiles.d/ai-memory.conf` | Creates `/var/lib/ai-memory` for the system service. |
+| `/etc/ai-memory/config.toml` | System-service config file, tracked as a pacman backup file. |
+| `/etc/ai-memory/env` | System-service environment/secrets file, tracked as a pacman backup file. |
+
+The binary itself does not guess between system and user mode. The unit file
+chooses explicitly:
+
+| Mode | Data dir | Config | Env/secrets | Requires sudo? |
+|---|---|---|---|---|
+| User service | `~/.local/share/ai-memory` | `~/.config/ai-memory/config.toml` | `~/.config/ai-memory/env` | No |
+| System service | `/var/lib/ai-memory` | `/etc/ai-memory/config.toml` | `/etc/ai-memory/env` | Yes |
+
+Do not run both services on the same bind address. They can coexist on disk, but
+only one can listen on `127.0.0.1:49374` unless you change `bind` in one config.
+
+### User-level service
+
+Use this on a single-user workstation. It needs no sudo after package install and
+keeps all state in your home directory.
+
+```bash
+mkdir -p ~/.config/ai-memory ~/.local/share/ai-memory
+ai-memory \
+ --data-dir ~/.local/share/ai-memory \
+ --config ~/.config/ai-memory/config.toml \
+ init
+```
+
+Edit provider/auth settings if you want LLM consolidation or bearer auth:
+
+```bash
+$EDITOR ~/.config/ai-memory/config.toml
+$EDITOR ~/.config/ai-memory/env
+```
+
+For a loopback-only local service, bearer auth is optional. If you want one:
+
+```bash
+TOKEN=$(ai-memory generate-auth-token)
+printf 'AI_MEMORY_AUTH_TOKEN=%s\n' "$TOKEN" >> ~/.config/ai-memory/env
+```
+
+Start and inspect the service:
+
+```bash
+systemctl --user daemon-reload
+systemctl --user enable --now ai-memory.service
+systemctl --user status ai-memory.service
+journalctl --user -u ai-memory.service -f
+```
+
+If the service should keep running after you log out:
+
+```bash
+loginctl enable-linger "$USER"
+```
+
+Verify the HTTP server:
+
+```bash
+curl http://127.0.0.1:49374/mcp
+# Expect a JSON-RPC error, which means the server is reachable.
+```
+
+### System-level service
+
+Use this for a shared workstation, LAN box, or homelab-style host where the
+server should run independently of any logged-in user.
+
+Make sure the package-created user and state directory exist, then initialize
+the data layout as that service user:
+
+```bash
+sudo systemd-sysusers /usr/lib/sysusers.d/ai-memory.conf
+sudo systemd-tmpfiles --create /usr/lib/tmpfiles.d/ai-memory.conf
+sudo -u ai-memory ai-memory \
+ --data-dir /var/lib/ai-memory \
+ --config /etc/ai-memory/config.toml \
+ init
+```
+
+Edit system config and secrets:
+
+```bash
+sudoedit /etc/ai-memory/config.toml
+sudoedit /etc/ai-memory/env
+```
+
+The package installs `/etc/ai-memory/env` as root-readable only because it may
+hold API keys. Keep that file out of backups or logs that other users can read.
+
+For LAN exposure, set a non-loopback bind and allowed hosts in
+`/etc/ai-memory/config.toml`, and set a bearer token in `/etc/ai-memory/env`:
+
+```toml
+bind = "0.0.0.0:49374"
+allowed_hosts = ["homelab", "192.168.0.90", "localhost", "127.0.0.1"]
+```
+
+```bash
+TOKEN=$(ai-memory generate-auth-token)
+printf 'AI_MEMORY_AUTH_TOKEN=%s\n' "$TOKEN" | sudo tee -a /etc/ai-memory/env
+```
+
+Start and inspect the service:
+
+```bash
+sudo systemctl daemon-reload
+sudo systemctl enable --now ai-memory.service
+sudo systemctl status ai-memory.service
+journalctl -u ai-memory.service -f
+```
+
+Verify from the host:
+
+```bash
+curl -sI http://127.0.0.1:49374/handoff
+# 401 Unauthorized when AI_MEMORY_AUTH_TOKEN is set.
+```
+
+### LLM provider login with native services
+
+API-key providers go in the relevant env file:
+
+```bash
+# User service
+printf 'AI_MEMORY_LLM_PROVIDER=anthropic\nANTHROPIC_API_KEY=sk-ant-...\n' >> ~/.config/ai-memory/env
+systemctl --user restart ai-memory.service
+
+# System service
+sudoedit /etc/ai-memory/env
+sudo systemctl restart ai-memory.service
+```
+
+OAuth-style providers write tokens into the selected data dir. Run the login
+with the same `--data-dir` and `--config` pair as the service:
+
+```bash
+# User service
+ai-memory \
+ --data-dir ~/.local/share/ai-memory \
+ --config ~/.config/ai-memory/config.toml \
+ auth login openai-oauth
+
+# System service
+sudo -u ai-memory ai-memory \
+ --data-dir /var/lib/ai-memory \
+ --config /etc/ai-memory/config.toml \
+ auth login openai-oauth
+```
+
+Use `auth login copilot` the same way for GitHub Copilot. Restart the service
+after changing provider settings:
+
+```bash
+systemctl --user restart ai-memory.service # user mode
+sudo systemctl restart ai-memory.service # system mode
+```
+
+### Wire agent CLIs after native install
+
+For a local loopback server with no bearer token:
+
+```bash
+ai-memory install-mcp --client claude-code --apply
+ai-memory install-hooks --agent claude-code --apply
+```
+
+For a bearer-protected local or LAN server, export the endpoint first. The MCP
+URL includes `/mcp`; the hook URL is the bare origin.
+
+```bash
+export AI_MEMORY_SERVER_URL="http://127.0.0.1:49374"
+export AI_MEMORY_AUTH_TOKEN="$TOKEN"
+
+ai-memory install-mcp --client claude-code --apply
+ai-memory install-hooks --agent claude-code --apply
+```
+
+`install-hooks` finds packaged hook sources under `/usr/share/ai-memory/hooks`,
+then stages runnable copies under `~/.local/share/ai-memory/hooks/<agent>/` so
+the agent can execute files owned by your user. Re-run `install-hooks --apply`
+after package upgrades to refresh those staged copies.
+
+### Native service operations
+
+```bash
+# User service
+systemctl --user restart ai-memory.service
+systemctl --user stop ai-memory.service
+journalctl --user -u ai-memory.service -n 100
+
+# System service
+sudo systemctl restart ai-memory.service
+sudo systemctl stop ai-memory.service
+journalctl -u ai-memory.service -n 100
+```
+
+Backups still use the same CLI, just point it at the service data dir:
+
+```bash
+# User service
+ai-memory --data-dir ~/.local/share/ai-memory backup --to ~/ai-memory-backup.tar.gz
+
+# System service
+sudo -u ai-memory ai-memory --data-dir /var/lib/ai-memory backup --to /var/lib/ai-memory/backup.tar.gz
+```
+
+Package removal does not delete data. Stop the service and remove state only
+when you intentionally want to erase memory:
+
+```bash
+systemctl --user disable --now ai-memory.service
+sudo systemctl disable --now ai-memory.service
+
+# Optional destructive cleanup:
+rm -rf ~/.local/share/ai-memory ~/.config/ai-memory
+sudo rm -rf /var/lib/ai-memory /etc/ai-memory
+```
+
+### Maintainer integration test
+
+The normal CI runs `scripts/check-native-packaging.sh`, a host-safe regression
+check that uses a temporary alternate root for `systemd-analyze`,
+`systemd-sysusers`, and `systemd-tmpfiles`. It verifies unit syntax, expected
+paths, sysusers output, tmpfiles rules, env-file mode, and AUR shell syntax
+without writing to host `/usr`, `/etc`, `/var`, or touching real services.
+
+The repo also includes a manual Arch integration harness that is intentionally
+kept out of routine CI because it creates a disposable distrobox, installs
+packages, starts real systemd services, and can take several minutes:
+
+```bash
+scripts/test-native-arch-systemd-distrobox.sh
+```
+
+It verifies the AUR metadata shape, builds the current working tree, installs
+the native layout into the disposable Arch container, starts the system service
+with `systemctl`, starts the user-profile command under transient systemd
+supervision, and checks that packaged hook sources under
+`/usr/share/ai-memory/hooks` can be staged by `install-hooks`.
+
+The destructive part of that script refuses to run unless it detects a
+container/distrobox environment.
+
+Useful knobs:
+
+```bash
+AI_MEMORY_NATIVE_TEST_BOX=ai-memory-native-test scripts/test-native-arch-systemd-distrobox.sh
+AI_MEMORY_NATIVE_TEST_KEEP_BOX=1 scripts/test-native-arch-systemd-distrobox.sh
+AI_MEMORY_NATIVE_TEST_IMAGE=quay.io/toolbx/arch-toolbox:latest scripts/test-native-arch-systemd-distrobox.sh
+```
+
+---
+
## Configuring other agent CLIs
> `install-mcp --server-url` takes the MCP endpoint **including** `/mcp`
diff --git a/packaging/aur/PKGBUILD b/packaging/aur/PKGBUILD
new file mode 100644
index 00000000..96de92a2
--- /dev/null
+++ b/packaging/aur/PKGBUILD
@@ -0,0 +1,63 @@
+# Maintainer: AkitaOnRails <[email protected]>
+
+pkgname=ai-memory
+pkgver=0.3.0
+pkgrel=1
+pkgdesc="Local-first long-term memory MCP server for AI coding agents"
+arch=('x86_64' 'aarch64')
+url="https://github.com/akitaonrails/ai-memory"
+license=('MIT')
+depends=('ca-certificates' 'gcc-libs' 'glibc')
+makedepends=('cargo')
+optdepends=(
+ 'systemd: run ai-memory as a system or user service'
+)
+backup=('etc/ai-memory/config.toml' 'etc/ai-memory/env')
+install=ai-memory.install
+options=('!debug')
+conflicts=('ai-memory-bin')
+source=("$pkgname-$pkgver.tar.gz::$url/archive/refs/tags/v$pkgver.tar.gz")
+sha256sums=('SKIP')
+
+prepare() {
+ cd "$pkgname-$pkgver"
+ export RUSTUP_TOOLCHAIN=1.95
+ cargo fetch --locked --target "$(rustc -vV | sed -n 's/host: //p')"
+}
+
+build() {
+ cd "$pkgname-$pkgver"
+ export RUSTUP_TOOLCHAIN=1.95
+ export CARGO_TARGET_DIR=target
+ export TAILWIND_SKIP=1
+ cargo build --frozen --release -p ai-memory-cli
+}
+
+check() {
+ cd "$pkgname-$pkgver"
+ export RUSTUP_TOOLCHAIN=1.95
+ export CARGO_TARGET_DIR=target
+ export TAILWIND_SKIP=1
+ export HOME="$srcdir/test-home"
+ mkdir -p "$HOME"
+ cargo test --frozen --release -p ai-memory-cli --bin ai-memory
+}
+
+package() {
+ cd "$pkgname-$pkgver"
+
+ install -Dm0755 target/release/ai-memory "$pkgdir/usr/bin/ai-memory"
+ install -Dm0644 README.md "$pkgdir/usr/share/doc/$pkgname/README.md"
+ install -Dm0644 docs/install.md "$pkgdir/usr/share/doc/$pkgname/install.md"
+ install -Dm0644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
+
+ install -dm0755 "$pkgdir/usr/share/ai-memory"
+ cp -a hooks "$pkgdir/usr/share/ai-memory/"
+
+ install -Dm0644 crates/ai-memory-cli/templates/config.default.toml "$pkgdir/etc/ai-memory/config.toml"
+ install -Dm0640 packaging/env/ai-memory.env "$pkgdir/etc/ai-memory/env"
+ install -Dm0644 packaging/systemd/ai-memory.service "$pkgdir/usr/lib/systemd/system/ai-memory.service"
+ install -Dm0644 packaging/systemd/ai-memory-user.service "$pkgdir/usr/lib/systemd/user/ai-memory.service"
+ install -Dm0644 packaging/sysusers/ai-memory.conf "$pkgdir/usr/lib/sysusers.d/ai-memory.conf"
+ install -Dm0644 packaging/tmpfiles/ai-memory.conf "$pkgdir/usr/lib/tmpfiles.d/ai-memory.conf"
+}
diff --git a/packaging/aur/PKGBUILD-bin b/packaging/aur/PKGBUILD-bin
new file mode 100644
index 00000000..bb167050
--- /dev/null
+++ b/packaging/aur/PKGBUILD-bin
@@ -0,0 +1,39 @@
+# Maintainer: AkitaOnRails <[email protected]>
+
+pkgname=ai-memory-bin
+_pkgname=ai-memory
+pkgver=0.3.0
+pkgrel=1
+pkgdesc="Local-first long-term memory MCP server for AI coding agents (prebuilt binary)"
+arch=('x86_64')
+url="https://github.com/akitaonrails/ai-memory"
+license=('MIT')
+depends=('ca-certificates' 'gcc-libs' 'glibc')
+optdepends=(
+ 'systemd: run ai-memory as a system or user service'
+)
+provides=("$_pkgname=$pkgver")
+conflicts=("$_pkgname" "$_pkgname-debug")
+backup=('etc/ai-memory/config.toml' 'etc/ai-memory/env')
+install=ai-memory.install
+options=('!strip' '!debug')
+
+source_x86_64=("$_pkgname-$pkgver-x86_64.tar.gz::$url/releases/download/v$pkgver/$_pkgname-linux-x86_64.tar.gz")
+sha256sums_x86_64=('SKIP')
+
+package() {
+ install -Dm0755 ai-memory "$pkgdir/usr/bin/ai-memory"
+ install -Dm0644 README.md "$pkgdir/usr/share/doc/$_pkgname/README.md"
+ install -Dm0644 docs/install.md "$pkgdir/usr/share/doc/$_pkgname/install.md"
+ install -Dm0644 LICENSE "$pkgdir/usr/share/licenses/$_pkgname/LICENSE"
+
+ install -dm0755 "$pkgdir/usr/share/ai-memory"
+ cp -a hooks "$pkgdir/usr/share/ai-memory/"
+
+ install -Dm0644 crates/ai-memory-cli/templates/config.default.toml "$pkgdir/etc/ai-memory/config.toml"
+ install -Dm0640 packaging/env/ai-memory.env "$pkgdir/etc/ai-memory/env"
+ install -Dm0644 packaging/systemd/ai-memory.service "$pkgdir/usr/lib/systemd/system/ai-memory.service"
+ install -Dm0644 packaging/systemd/ai-memory-user.service "$pkgdir/usr/lib/systemd/user/ai-memory.service"
+ install -Dm0644 packaging/sysusers/ai-memory.conf "$pkgdir/usr/lib/sysusers.d/ai-memory.conf"
+ install -Dm0644 packaging/tmpfiles/ai-memory.conf "$pkgdir/usr/lib/tmpfiles.d/ai-memory.conf"
+}
diff --git a/packaging/aur/README.md b/packaging/aur/README.md
new file mode 100644
index 00000000..f30595ad
--- /dev/null
+++ b/packaging/aur/README.md
@@ -0,0 +1,84 @@
+# AUR Packaging
+
+This directory contains the package definitions for two Arch User Repository
+packages:
+
+- `ai-memory-bin`: installs the prebuilt Linux x86_64 binary and bundled files
+ from GitHub Releases.
+- `ai-memory`: builds from the GitHub source tag with the local Rust toolchain.
+
+The files here are the source of truth for the AUR repos, but AUR still requires
+each package to be pushed to its own Git repository with a generated `.SRCINFO`.
+
+## User Install
+
+Use an AUR helper:
+
+```bash
+yay -S ai-memory-bin # prebuilt binary, fastest on x86_64
+yay -S ai-memory # builds from source, supports x86_64/aarch64
+```
+
+Then follow the native Linux service instructions in `docs/install.md`.
+
+## Local Integration Test
+
+Before publishing package updates, run the manual distrobox harness from the
+repository root:
+
+```bash
+scripts/test-native-arch-systemd-distrobox.sh
+```
+
+It creates a disposable Arch distrobox, builds the current working tree,
+installs the native filesystem layout, verifies the AUR metadata shape, starts
+the packaged system service with real `systemctl`, smoke-tests the user profile
+runner under transient systemd supervision, and confirms packaged hook sources
+stage correctly.
+
+Routine CI runs `scripts/check-native-packaging.sh` for non-destructive coverage
+against a temporary alternate root. The distrobox script is the final real
+service-start smoke before publishing.
+
+## Maintainer Release Checklist
+
+The GitHub release workflow publishes these AUR repos automatically on `v*.*.*`
+tags when `AUR_SSH_PRIVATE_KEY` is configured. It validates that the tag version
+matches `Cargo.toml`, computes fresh checksums, generates `.SRCINFO`, and pushes
+both `ai-memory` and `ai-memory-bin`.
+
+For every new upstream release:
+
+1. Bump `[workspace.package].version` in `Cargo.toml` and all workspace crate
+ dependency versions as usual.
+2. Run the local gate, including `scripts/check-native-packaging.sh` and the
+ disposable distrobox integration test.
+3. Push a matching version tag, for example `v0.3.0`.
+4. Confirm the `release` workflow created the GitHub release, pushed Docker if
+ Docker Hub secrets are configured, and pushed AUR if `AUR_SSH_PRIVATE_KEY` is
+ configured.
+
+Manual fallback if the AUR job is disabled or needs repair:
+
+1. Update `pkgver` in both `PKGBUILD` files and reset `pkgrel=1`.
+2. Update source checksums. Replace any temporary `SKIP` values before pushing
+ to AUR.
+3. Validate both package variants with `makepkg --verifysource` and `makepkg -Ccf`.
+4. Generate `.SRCINFO` in each AUR checkout with `makepkg --printsrcinfo > .SRCINFO`.
+5. Commit and push to the separate AUR repos: `ai-memory` and `ai-memory-bin`.
+
+Checksum helpers for version `X.Y.Z`:
+
+```bash
+version=X.Y.Z
+
+# Source package tarball
+curl -fsSL "https://github.com/akitaonrails/ai-memory/archive/refs/tags/v${version}.tar.gz" | sha256sum
+
+# Binary package release artifact
+curl -fsSL "https://github.com/akitaonrails/ai-memory/releases/download/v${version}/ai-memory-linux-x86_64.tar.gz.sha256"
+```
+
+`ai-memory-bin` is currently `x86_64` only because the release workflow publishes
+a Linux x86_64 binary. The source package includes `aarch64` because it compiles
+locally on Arch Linux ARM.
diff --git a/packaging/aur/ai-memory.install b/packaging/aur/ai-memory.install
new file mode 100644
index 00000000..02217d4d
--- /dev/null
+++ b/packaging/aur/ai-memory.install
@@ -0,0 +1,27 @@
+post_install() {
+ cat <<'EOF'
+ai-memory is installed.
+
+User service:
+ ai-memory --data-dir "$HOME/.local/share/ai-memory" --config "$HOME/.config/ai-memory/config.toml" init
+ systemctl --user enable --now ai-memory.service
+
+System service:
+ sudo systemd-sysusers /usr/lib/sysusers.d/ai-memory.conf
+ sudo systemd-tmpfiles --create /usr/lib/tmpfiles.d/ai-memory.conf
+ sudo -u ai-memory ai-memory --data-dir /var/lib/ai-memory --config /etc/ai-memory/config.toml init
+ sudo systemctl enable --now ai-memory.service
+
+Configure LLM/API keys in ~/.config/ai-memory/env for the user service, or
+/etc/ai-memory/env for the system service. See docs/install.md for details.
+EOF
+}
+
+post_upgrade() {
+ cat <<'EOF'
+ai-memory was upgraded.
+
+If you use lifecycle hooks, refresh staged hook scripts for each agent:
+ ai-memory install-hooks --agent claude-code --apply
+EOF
+}
diff --git a/packaging/env/ai-memory.env b/packaging/env/ai-memory.env
new file mode 100644
index 00000000..1944e8b5
--- /dev/null
+++ b/packaging/env/ai-memory.env
@@ -0,0 +1,12 @@
+# Environment file read by the system ai-memory.service.
+#
+# Keep one KEY=value assignment per line. Do not quote values unless the value
+# itself contains quotes; systemd EnvironmentFile is not a shell script.
+#
+# Common choices:
+# AI_MEMORY_AUTH_TOKEN=<generated with: ai-memory generate-auth-token>
+# AI_MEMORY_ALLOWED_HOSTS=localhost,127.0.0.1,::1
+# AI_MEMORY_LLM_PROVIDER=anthropic
+# ANTHROPIC_API_KEY=sk-ant-...
+# AI_MEMORY_EMBEDDING_PROVIDER=openai
+# OPENAI_API_KEY=sk-...
diff --git a/packaging/systemd/ai-memory-user.service b/packaging/systemd/ai-memory-user.service
new file mode 100644
index 00000000..d70e5947
--- /dev/null
+++ b/packaging/systemd/ai-memory-user.service
@@ -0,0 +1,15 @@
+[Unit]
+Description=ai-memory MCP server (user service)
+Documentation=https://github.com/akitaonrails/ai-memory
+
+[Service]
+Type=simple
+EnvironmentFile=-%h/.config/ai-memory/env
+ExecStart=/usr/bin/ai-memory --data-dir %h/.local/share/ai-memory --config %h/.config/ai-memory/config.toml serve --transport http --enable-web
+Restart=on-failure
+RestartSec=5s
+NoNewPrivileges=true
+PrivateTmp=true
+
+[Install]
+WantedBy=default.target
diff --git a/packaging/systemd/ai-memory.service b/packaging/systemd/ai-memory.service
new file mode 100644
index 00000000..47badbd6
--- /dev/null
+++ b/packaging/systemd/ai-memory.service
@@ -0,0 +1,24 @@
+[Unit]
+Description=ai-memory MCP server
+Documentation=https://github.com/akitaonrails/ai-memory
+After=network-online.target
+Wants=network-online.target
+
+[Service]
+Type=simple
+User=ai-memory
+Group=ai-memory
+EnvironmentFile=-/etc/ai-memory/env
+ExecStart=/usr/bin/ai-memory --data-dir /var/lib/ai-memory --config /etc/ai-memory/config.toml serve --transport http --enable-web
+Restart=on-failure
+RestartSec=5s
+StateDirectory=ai-memory
+StateDirectoryMode=0750
+NoNewPrivileges=true
+PrivateTmp=true
+ProtectHome=true
+ProtectSystem=strict
+ReadWritePaths=/var/lib/ai-memory
+
+[Install]
+WantedBy=multi-user.target
diff --git a/packaging/sysusers/ai-memory.conf b/packaging/sysusers/ai-memory.conf
new file mode 100644
index 00000000..1702a974
--- /dev/null
+++ b/packaging/sysusers/ai-memory.conf
@@ -0,0 +1 @@
+u ai-memory - "ai-memory service user" /var/lib/ai-memory /usr/bin/nologin
diff --git a/packaging/tmpfiles/ai-memory.conf b/packaging/tmpfiles/ai-memory.conf
new file mode 100644
index 00000000..30ace07a
--- /dev/null
+++ b/packaging/tmpfiles/ai-memory.conf
@@ -0,0 +1 @@
+d /var/lib/ai-memory 0750 ai-memory ai-memory -
diff --git a/scripts/check-native-packaging.sh b/scripts/check-native-packaging.sh
new file mode 100755
index 00000000..dd2c967b
--- /dev/null
+++ b/scripts/check-native-packaging.sh
@@ -0,0 +1,159 @@
+#!/usr/bin/env bash
+# CI-safe checks for the native Linux package assets.
+#
+# This script must not mutate host-level /usr, /etc, /var, users, groups, or
+# services. It validates systemd/sysusers/tmpfiles behavior against a temporary
+# alternate root and removes that root on exit.
+
+set -euo pipefail
+
+TMP_ROOT=""
+
+log() {
+ printf '==> %s\n' "$*"
+}
+
+fail() {
+ printf 'error: %s\n' "$*" >&2
+ exit 1
+}
+
+repo_root() {
+ local script_dir
+ script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+ cd "${script_dir}/.." && pwd
+}
+
+require_tool() {
+ command -v "$1" >/dev/null 2>&1 || fail "$1 is required"
+}
+
+copy_system_unit_dependency() {
+ local unit="$1"
+ local dest="$2/usr/lib/systemd/system/$unit"
+ local source_dir
+ for source_dir in /usr/lib/systemd/system /lib/systemd/system; do
+ if [ -f "${source_dir}/${unit}" ]; then
+ cp "${source_dir}/${unit}" "${dest}"
+ return 0
+ fi
+ done
+}
+
+assert_contains() {
+ local file="$1"
+ local needle="$2"
+ if ! grep -Fq -- "$needle" "$file"; then
+ fail "${file} does not contain expected text: ${needle}"
+ fi
+}
+
+main() {
+ require_tool systemd-analyze
+ require_tool systemd-sysusers
+ require_tool systemd-tmpfiles
+
+ local repo tmpfiles_output
+ repo="$(repo_root)"
+ cd "${repo}"
+
+ log "Checking shell packaging syntax"
+ bash -n packaging/aur/PKGBUILD
+ bash -n packaging/aur/PKGBUILD-bin
+ bash -n packaging/aur/ai-memory.install
+ bash -n scripts/test-native-arch-systemd-distrobox.sh
+
+ if command -v makepkg >/dev/null 2>&1 && [ "$(id -u)" != "0" ]; then
+ log "Checking AUR .SRCINFO generation"
+ (cd packaging/aur && makepkg --printsrcinfo -p PKGBUILD) >/dev/null
+ (cd packaging/aur && makepkg --printsrcinfo -p PKGBUILD-bin) >/dev/null
+ else
+ log "Skipping makepkg .SRCINFO check (makepkg unavailable or running as root)"
+ fi
+
+ TMP_ROOT="$(mktemp -d /tmp/ai-memory-native-root.XXXXXX)"
+ cleanup() {
+ if [ -n "${TMP_ROOT}" ]; then
+ rm -rf "${TMP_ROOT}"
+ fi
+ }
+ trap cleanup EXIT
+
+ log "Creating temporary alternate root"
+ mkdir -p \
+ "${TMP_ROOT}/etc" \
+ "${TMP_ROOT}/etc/ai-memory" \
+ "${TMP_ROOT}/usr/bin" \
+ "${TMP_ROOT}/usr/lib/systemd/system" \
+ "${TMP_ROOT}/usr/lib/systemd/user" \
+ "${TMP_ROOT}/usr/lib/sysusers.d" \
+ "${TMP_ROOT}/usr/lib/tmpfiles.d" \
+ "${TMP_ROOT}/var/lib"
+ : >"${TMP_ROOT}/etc/passwd"
+ : >"${TMP_ROOT}/etc/group"
+ : >"${TMP_ROOT}/usr/bin/ai-memory"
+ chmod 0755 "${TMP_ROOT}/usr/bin/ai-memory"
+
+ cp crates/ai-memory-cli/templates/config.default.toml "${TMP_ROOT}/etc/ai-memory/config.toml"
+ cp packaging/env/ai-memory.env "${TMP_ROOT}/etc/ai-memory/env"
+ chmod 0640 "${TMP_ROOT}/etc/ai-memory/env"
+ cp packaging/systemd/ai-memory.service "${TMP_ROOT}/usr/lib/systemd/system/ai-memory.service"
+ cp packaging/systemd/ai-memory-user.service "${TMP_ROOT}/usr/lib/systemd/user/ai-memory.service"
+ cp packaging/sysusers/ai-memory.conf "${TMP_ROOT}/usr/lib/sysusers.d/ai-memory.conf"
+ cp packaging/tmpfiles/ai-memory.conf "${TMP_ROOT}/usr/lib/tmpfiles.d/ai-memory.conf"
+
+ for unit in \
+ sysinit.target \
+ basic.target \
+ multi-user.target \
+ network-online.target \
+ sockets.target \
+ timers.target \
+ paths.target \
+ slices.target \
+ shutdown.target \
+ remote-fs.target \
+ local-fs.target \
+ swap.target; do
+ copy_system_unit_dependency "$unit" "$TMP_ROOT" || true
+ done
+
+ log "Checking sysusers in alternate root"
+ systemd-sysusers --root="${TMP_ROOT}" "${TMP_ROOT}/usr/lib/sysusers.d/ai-memory.conf" >/dev/null
+ assert_contains "${TMP_ROOT}/etc/passwd" "ai-memory service user:/var/lib/ai-memory:/usr/bin/nologin"
+ assert_contains "${TMP_ROOT}/etc/group" "ai-memory"
+
+ log "Checking tmpfiles in dry-run alternate root"
+ tmpfiles_output="$(systemd-tmpfiles --root="${TMP_ROOT}" --create --dry-run "${TMP_ROOT}/usr/lib/tmpfiles.d/ai-memory.conf" 2>&1)"
+ case "${tmpfiles_output}" in
+ *"/var/lib/ai-memory"*) ;;
+ *) fail "tmpfiles dry-run did not plan /var/lib/ai-memory: ${tmpfiles_output}" ;;
+ esac
+ assert_contains packaging/tmpfiles/ai-memory.conf "d /var/lib/ai-memory 0750 ai-memory ai-memory -"
+
+ log "Checking systemd units in alternate root"
+ systemd-analyze --root="${TMP_ROOT}" verify ai-memory.service
+
+ # systemd-analyze cannot combine --user and --root on some distro versions.
+ # Copy the user unit into the system search path under a temporary name to
+ # still parse and validate the Service/Install directives with the same fake
+ # /usr/bin/ai-memory executable.
+ cp packaging/systemd/ai-memory-user.service \
+ "${TMP_ROOT}/usr/lib/systemd/system/ai-memory-user-parse-test.service"
+ systemd-analyze --root="${TMP_ROOT}" verify ai-memory-user-parse-test.service
+
+ log "Checking expected native paths and modes"
+ assert_contains packaging/systemd/ai-memory.service "--data-dir /var/lib/ai-memory"
+ assert_contains packaging/systemd/ai-memory.service "--config /etc/ai-memory/config.toml"
+ assert_contains packaging/systemd/ai-memory.service "EnvironmentFile=-/etc/ai-memory/env"
+ assert_contains packaging/systemd/ai-memory.service "StateDirectory=ai-memory"
+ assert_contains packaging/systemd/ai-memory.service "ReadWritePaths=/var/lib/ai-memory"
+ assert_contains packaging/systemd/ai-memory-user.service "--data-dir %h/.local/share/ai-memory"
+ assert_contains packaging/systemd/ai-memory-user.service "--config %h/.config/ai-memory/config.toml"
+ assert_contains packaging/systemd/ai-memory-user.service "EnvironmentFile=-%h/.config/ai-memory/env"
+ test "$(stat -c '%a' "${TMP_ROOT}/etc/ai-memory/env")" = "640"
+
+ log "Native packaging checks passed without touching host service paths"
+}
+
+main "$@"
diff --git a/scripts/test-native-arch-systemd-distrobox.sh b/scripts/test-native-arch-systemd-distrobox.sh
new file mode 100755
index 00000000..40811e15
--- /dev/null
+++ b/scripts/test-native-arch-systemd-distrobox.sh
@@ -0,0 +1,199 @@
+#!/usr/bin/env bash
+# Manual native Linux integration test for the Arch/AUR install path.
+#
+# This is intentionally not part of CI. It creates a disposable Arch distrobox,
+# installs the current working tree into native filesystem locations, then tests
+# the packaged systemd assets against a real system manager where distrobox
+# supports `--init`.
+
+set -euo pipefail
+
+BOX_NAME="${AI_MEMORY_NATIVE_TEST_BOX:-ai-memory-native-systemd-test}"
+IMAGE="${AI_MEMORY_NATIVE_TEST_IMAGE:-docker.io/library/archlinux:latest}"
+KEEP_BOX="${AI_MEMORY_NATIVE_TEST_KEEP_BOX:-0}"
+HOST_TEST_HOME=""
+
+log() {
+ printf '\n==> %s\n' "$*"
+}
+
+fail() {
+ printf 'error: %s\n' "$*" >&2
+ exit 1
+}
+
+assert_inside_container() {
+ if [ -f /.dockerenv ] || [ -f /run/.containerenv ] || [ -n "${container:-}" ]; then
+ return 0
+ fi
+ if command -v systemd-detect-virt >/dev/null 2>&1 \
+ && systemd-detect-virt --container --quiet; then
+ return 0
+ fi
+ fail "refusing to run destructive native install test outside a container/distrobox"
+}
+
+repo_root() {
+ local script_dir
+ script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+ cd "${script_dir}/.." && pwd
+}
+
+wait_for_http() {
+ local url="$1"
+ local unit="$2"
+ for _ in $(seq 1 80); do
+ if curl -fsS "${url}" >/dev/null 2>&1; then
+ return 0
+ fi
+ sleep 0.25
+ done
+ journalctl -u "${unit}" --no-pager -n 120 >&2 || true
+ fail "timed out waiting for ${url}"
+}
+
+run_inside() {
+ assert_inside_container
+
+ cd /work/ai-memory
+
+ log "Installing Arch build/runtime dependencies"
+ sudo pacman -Syu --noconfirm --needed \
+ base-devel \
+ ca-certificates \
+ curl \
+ git \
+ pkgconf \
+ rustup \
+ systemd
+
+ log "Installing Rust 1.95 toolchain"
+ rustup toolchain install 1.95 --profile minimal --component rustfmt --component clippy
+ rustup default 1.95
+
+ log "Checking package metadata syntax"
+ bash -n packaging/aur/PKGBUILD
+ bash -n packaging/aur/PKGBUILD-bin
+ (cd packaging/aur && makepkg --printsrcinfo -p PKGBUILD) >/tmp/ai-memory.PKGBUILD.SRCINFO
+ (cd packaging/aur && makepkg --printsrcinfo -p PKGBUILD-bin) >/tmp/ai-memory-bin.PKGBUILD.SRCINFO
+
+ log "Building ai-memory release binary from current working tree"
+ export TAILWIND_SKIP=1
+ cargo build --release -p ai-memory-cli
+
+ log "Installing native package layout into the disposable distrobox"
+ sudo install -Dm0755 target/release/ai-memory /usr/bin/ai-memory
+ sudo rm -rf /usr/share/ai-memory/hooks
+ sudo install -dm0755 /usr/share/ai-memory
+ sudo cp -a hooks /usr/share/ai-memory/
+ sudo install -Dm0644 crates/ai-memory-cli/templates/config.default.toml /etc/ai-memory/config.toml
+ sudo install -Dm0640 packaging/env/ai-memory.env /etc/ai-memory/env
+ sudo install -Dm0644 packaging/systemd/ai-memory.service /usr/lib/systemd/system/ai-memory.service
+ sudo install -Dm0644 packaging/systemd/ai-memory-user.service /usr/lib/systemd/user/ai-memory.service
+ sudo install -Dm0644 packaging/sysusers/ai-memory.conf /usr/lib/sysusers.d/ai-memory.conf
+ sudo install -Dm0644 packaging/tmpfiles/ai-memory.conf /usr/lib/tmpfiles.d/ai-memory.conf
+
+ log "Verifying systemd unit files"
+ systemd-analyze verify /usr/lib/systemd/system/ai-memory.service
+ systemd-analyze --user verify /usr/lib/systemd/user/ai-memory.service
+
+ log "Creating system service user and state directory"
+ sudo systemd-sysusers /usr/lib/sysusers.d/ai-memory.conf
+ sudo systemd-tmpfiles --create /usr/lib/tmpfiles.d/ai-memory.conf
+ test -d /var/lib/ai-memory
+ test "$(stat -c '%U:%G' /var/lib/ai-memory)" = "ai-memory:ai-memory"
+
+ log "Initializing system-service data with explicit /var + /etc paths"
+ sudo -u ai-memory /usr/bin/ai-memory \
+ --data-dir /var/lib/ai-memory \
+ --config /etc/ai-memory/config.toml \
+ init
+ sudo test -d /var/lib/ai-memory/wiki
+ sudo test -d /var/lib/ai-memory/db
+
+ if ! systemctl list-units --type=service --no-pager >/dev/null 2>&1; then
+ fail "systemd is not reachable inside this distrobox. Recreate with distrobox --init, or use a provider that supports systemd containers."
+ fi
+
+ log "Starting packaged system service with real systemctl"
+ sudo systemctl daemon-reload
+ sudo systemctl restart ai-memory.service
+ wait_for_http http://127.0.0.1:49374/web ai-memory.service
+ sudo -u ai-memory /usr/bin/ai-memory \
+ --data-dir /var/lib/ai-memory \
+ --config /etc/ai-memory/config.toml \
+ status --json >/tmp/ai-memory-system-status.json
+ sudo systemctl stop ai-memory.service
+
+ log "Initializing user profile paths"
+ mkdir -p "${HOME}/.config/ai-memory" "${HOME}/.local/share/ai-memory"
+ /usr/bin/ai-memory \
+ --data-dir "${HOME}/.local/share/ai-memory" \
+ --config "${HOME}/.config/ai-memory/config.toml" \
+ init
+ sed -i 's/127\.0\.0\.1:49374/127.0.0.1:49375/' "${HOME}/.config/ai-memory/config.toml"
+
+ log "Starting user-profile command under transient systemd supervision"
+ sudo systemd-run \
+ --unit ai-memory-user-profile-smoke \
+ --collect \
+ --uid "$(id -u)" \
+ --gid "$(id -g)" \
+ --setenv "HOME=${HOME}" \
+ /usr/bin/ai-memory \
+ --data-dir "${HOME}/.local/share/ai-memory" \
+ --config "${HOME}/.config/ai-memory/config.toml" \
+ serve --transport http --enable-web
+ wait_for_http http://127.0.0.1:49375/web ai-memory-user-profile-smoke.service
+ sudo systemctl stop ai-memory-user-profile-smoke.service
+
+ log "Verifying packaged hook source lookup and agent config writes"
+ /usr/bin/ai-memory install-mcp --client claude-code --apply --server-url http://127.0.0.1:49375/mcp
+ /usr/bin/ai-memory install-hooks --agent claude-code --apply --server-url http://127.0.0.1:49375
+ test -x "${HOME}/.local/share/ai-memory/hooks/claude-code/session-start.sh"
+ test -f "${HOME}/.claude.json"
+
+ log "Native Arch systemd integration passed"
+}
+
+main() {
+ if [ "${AI_MEMORY_NATIVE_TEST_INNER:-0}" = "1" ]; then
+ run_inside
+ return
+ fi
+
+ command -v distrobox >/dev/null 2>&1 || fail "distrobox is required"
+
+ local repo
+ repo="$(repo_root)"
+ HOST_TEST_HOME="$(mktemp -d /tmp/ai-memory-native-home.XXXXXX)"
+
+ cleanup() {
+ if [ "${KEEP_BOX}" != "1" ]; then
+ distrobox rm --force "${BOX_NAME}" >/dev/null 2>&1 || true
+ if [ -n "${HOST_TEST_HOME}" ]; then
+ rm -rf "${HOST_TEST_HOME}"
+ fi
+ else
+ printf 'keeping distrobox %s and home %s\n' "${BOX_NAME}" "${HOST_TEST_HOME}" >&2
+ fi
+ }
+ trap cleanup EXIT
+
+ log "Creating disposable Arch distrobox ${BOX_NAME}"
+ distrobox rm --force "${BOX_NAME}" >/dev/null 2>&1 || true
+ distrobox create \
+ --yes \
+ --name "${BOX_NAME}" \
+ --image "${IMAGE}" \
+ --init \
+ --home "${HOST_TEST_HOME}" \
+ --volume "${repo}:/work/ai-memory:rw"
+
+ log "Running native integration inside ${BOX_NAME}"
+ distrobox enter "${BOX_NAME}" -- \
+ env AI_MEMORY_NATIVE_TEST_INNER=1 \
+ bash /work/ai-memory/scripts/test-native-arch-systemd-distrobox.sh
+}
+
+main "$@"