feat(coding): add ai-memory client module, drop Pi and babysitter

coding.aiMemory wires Claude Code and OpenCode2 to the central ai-memory
server: Nix owns the client config (server URL + bearer token file), the
OpenCode MCP entry, and the scope markers (home workspace plus one marker
per workspaceDirs entry); activation runs ai-memory's own installers for
hooks, the Claude MCP bridge and the skills. The token never lands in a
generated file: hooks and the bridge read [auth].bearer_token_file, the
OpenCode plugin reads the data-dir auth-token symlink.

Pi (and its babysitter profile) are no longer used; LifeOS is being
removed from the hosts as well.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
m3tam3reandClaude Fable 5.1 committed 2026-10-25 12:47:09 +01:00
1 parent d608fb29b1
commit c3b51b3546
6 files changed
+464 -389

No files matched your search

+3 -8
View File
@@ -1,4 +1,4 @@
# AI agent system — OpenCode, Pi, and MCP server configuration.
# AI agent system — OpenCode, Claude Code, ai-memory and MCP server configuration.
# Relies on coding.agents options provided by home/common/default.nix
# (m3taHomeInputs.m3ta-nixpkgs.homeManagerModules.default).
{
@@ -17,15 +17,12 @@
};
imports = [
# Babysitter agent and OpenCode/Pi tool configurations
./babysitter.nix
# ai-memory client, skill mirror and OpenCode config
./ai-memory.nix
./claude-skills.nix
./opencode.nix
./pi.nix
];
coding.agents.babysitter.enable = true;
programs.mcp = {
enable = true;
servers = {
@@ -73,14 +70,12 @@
agenix-cli
agent-lib
llm-agents.agent-browser
llm-agents.ai-memory
llm-agents.beads
llm-agents.claude-code
llm-agents.claude-desktop
crunch
docker-sbx
llm-agents.herdr
llm-agents.pi
(llm-agents.qmd.override {
vulkanSupport = videoDrivers == ["amdgpu"];
cudaSupport = videoDrivers == ["nvidia"];
+142
View File
@@ -0,0 +1,142 @@
# ai-memory client (https://aimemory.sh) — shared agent memory.
#
# The server runs on m3-hermes (nixos-config) and is reached at
# memory.m3ta.dev; no server runs on clients. Hybrid setup:
# - Nix owns the package, the client config (server URL + bearer token
# file), the OpenCode MCP entry (via programs.mcp, since opencode.json
# is a home-manager symlink) and the scope markers (~/.ai-memory.toml
# plus one marker per workspace directory).
# - Activation runs ai-memory's own installers for the lifecycle hooks,
# the session-aware Claude Code MCP entry and the skills, so generated
# files always match the installed ai-memory version.
#
# The bearer token (an `aim_` API key, one per host) is an agenix secret the
# host repo provides at `tokenFile`. It is never copied into a generated
# file: hooks and the MCP bridge read `[auth].bearer_token_file` from the
# client config, and the OpenCode plugin reads `<data_dir>/auth-token`,
# which activation symlinks to the secret. Without the token activation
# skips the installers instead of writing hooks that cannot authenticate.
{
config,
lib,
pkgs,
...
}:
with lib; let
cfg = config.coding.aiMemory;
package = pkgs.llm-agents.ai-memory;
exe = "${package}/bin/ai-memory";
dataDir = "${config.home.homeDirectory}/.local/share/ai-memory";
tomlList = xs: "[${concatMapStringsSep ", " (x: ''"${x}"'') xs}]";
# Markers are not merged with their ancestors, so every marker repeats
# the capture exclusions.
marker = workspace: ''
workspace = "${workspace}"
[capture]
ignore_paths = ${tomlList cfg.ignorePaths}
'';
in {
options.coding.aiMemory = {
enable = mkEnableOption "the ai-memory client (hooks, MCP and skills for coding agents)";
serverUrl = mkOption {
type = types.str;
default = "https://memory.m3ta.dev";
description = "Base URL of the ai-memory server; MCP is served at <serverUrl>/mcp.";
};
tokenFile = mkOption {
type = types.str;
default = "/run/agenix/ai-memory-token";
description = "File holding this host's `aim_` API key, readable by the user.";
};
agents = mkOption {
type = types.listOf (types.enum ["claude-code" "opencode2"]);
default = ["claude-code" "opencode2"];
description = "Agents whose lifecycle hooks are installed.";
};
workspace = mkOption {
type = types.str;
default = "private";
description = ''
ai-memory workspace for every directory below $HOME that has no
marker of its own (and no entry in `workspaceDirs`). Projects are
still derived per repository (git remote), only the workspace is
fixed here. Work hosts set this to the work workspace.
'';
};
workspaceDirs = mkOption {
type = types.attrsOf types.str;
default = {};
example = {"p/AZ" = "az";};
description = ''
Home-relative directories whose subtree belongs to another
workspace. Each gets its own `.ai-memory.toml` marker.
'';
};
ignorePaths = mkOption {
type = types.listOf types.str;
default = ["/run/agenix/**" "~/.config/sops/**" "~/.ssh/**" "**/.env*"];
description = "Paths kept out of capture via the markers' [capture] ignore_paths.";
};
};
config = mkIf cfg.enable {
# The llm-agents build wraps the binary with git on PATH (hooks need it).
home.packages = [package];
home.sessionVariables.AI_MEMORY_SERVER_URL = cfg.serverUrl;
# OpenCode2 picks this up via programs.opencode.enableMcpIntegration.
programs.mcp.servers.ai-memory = {
command = exe;
args = ["mcp-bridge" "--no-session-id" "--server-url" "${cfg.serverUrl}/mcp"];
};
home.file =
{
# Client config: `ai-memory hook`, `mcp-bridge` and the installers
# read server_url and the token from here, so no generated file
# carries the token.
".local/share/ai-memory/config.toml".text = ''
server_url = "${cfg.serverUrl}"
[auth]
bearer_token_file = "${cfg.tokenFile}"
'';
# Scope marker: $HOME governs everything without a closer marker.
".ai-memory.toml".text = marker cfg.workspace;
}
# One marker per directory that belongs to another workspace.
// mapAttrs' (dir: ws: nameValuePair "${dir}/.ai-memory.toml" {text = marker ws;}) cfg.workspaceDirs;
home.activation.aiMemoryInstall = lib.hm.dag.entryAfter ["writeBoundary" "claudeSkillsSync"] ''
if [ ! -r ${escapeShellArg cfg.tokenFile} ]; then
echo "ai-memory: token file ${cfg.tokenFile} missing, skipping" >&2
else
# The OpenCode plugin reads <data_dir>/auth-token; point it at the secret.
run mkdir -p ${escapeShellArg dataDir}
run ln -sfn ${escapeShellArg cfg.tokenFile} ${escapeShellArg "${dataDir}/auth-token"}
${concatMapStringsSep "\n" (agent: ''
run ${exe} install-hooks --agent ${agent} --apply --server-url ${escapeShellArg cfg.serverUrl}
'')
cfg.agents}
${optionalString (elem "claude-code" cfg.agents) ''
export PATH="${pkgs.llm-agents.claude-code}/bin:$PATH"
run claude mcp remove ai-memory -s user >/dev/null 2>&1 || true
run ${exe} install-mcp --client claude-code --apply \
--server-url ${escapeShellArg "${cfg.serverUrl}/mcp"}
''}
# Into ~/.agents/skills; claude-skills-sync mirrors them to Claude.
run ${exe} install-skills --scope global --agent agents
fi
'';
};
}
+61
View File
@@ -0,0 +1,61 @@
#!/usr/bin/env bash
# Eval checks for coding.aiMemory against m3-kratos in nixos-config, using
# this checkout of m3ta-home. Usage: ai-memory.test.sh [path/to/nixos-config]
set -euo pipefail
home_repo="$(cd "$(dirname "$0")/../../../.." && pwd)"
nixos_repo="${1:-$home_repo/../nixos-config}"
hm="#nixosConfigurations.m3-kratos.config.home-manager.users.m3tam3re"
fail=0
ev() { # attr [extra nix eval args...]
local attr="$1"; shift
nix eval --raw --override-input m3ta-home "path:$home_repo" "$nixos_repo$hm.$attr" "$@" 2>/dev/null
}
check() { # name, haystack, needle
if [[ "$2" == *"$3"* ]]; then echo "ok $1"; else echo "FAIL $1: missing '$3'"; fail=1; fi
}
refute() { # name, haystack, needle
if [[ "$2" == *"$3"* ]]; then echo "FAIL $1: found '$3'"; fail=1; else echo "ok $1"; fi
}
check "server url" "$(ev home.sessionVariables.AI_MEMORY_SERVER_URL)" "https://memory.m3ta.dev"
conf="$(ev 'home.file.".local/share/ai-memory/config.toml".text')"
check "client config server_url" "$conf" 'server_url = "https://memory.m3ta.dev"'
check "client config token file" "$conf" 'bearer_token_file = "/run/agenix/ai-memory-token"'
mcp="$(ev programs.mcp.servers.ai-memory.args --apply 'builtins.concatStringsSep " "')"
check "mcp bridge" "$mcp" "mcp-bridge --no-session-id --server-url https://memory.m3ta.dev/mcp"
refute "mcp carries no token" "$mcp" "ai-memory-token"
opencode="$(cat "$(nix build --no-link --print-out-paths --override-input m3ta-home "path:$home_repo" \
"$nixos_repo$hm.xdg.configFile.\"opencode/opencode.json\".source" 2>/dev/null)")"
check "opencode gets mcp" "$opencode" "mcp-bridge"
marker="$(ev 'home.file.".ai-memory.toml".text')"
check "home marker workspace" "$marker" 'workspace = "private"'
check "marker section" "$marker" "[capture]"
for p in "/run/agenix/**" "~/.config/sops/**" "~/.ssh/**" "**/.env*"; do
check "marker $p" "$marker" "\"$p\""
done
az="$(ev 'home.file."p/AZ/.ai-memory.toml".text' 2>/dev/null || true)"
check "AZ marker workspace" "$az" 'workspace = "az"'
check "AZ marker repeats capture" "$az" "[capture]"
act="$(ev home.activation.aiMemoryInstall.data)"
check "hooks claude-code" "$act" "install-hooks --agent claude-code --apply"
check "hooks opencode2" "$act" "install-hooks --agent opencode2 --apply"
check "auth-token symlink" "$act" "ln -sfn /run/agenix/ai-memory-token "
refute "no token on command lines" "$act" "--auth-token"
refute "activation must not write opencode.json (home-manager symlink)" "$act" "install-mcp --client opencode"
# Missing token file: skip with a warning, exit 0, never call ai-memory.
script="$(printf '%s\n' "$act" | sed 's|/run/agenix/ai-memory-token|/nonexistent/ai-memory-token|g')"
out="$(run() { echo "CALLED $*"; }; eval "$script" 2>&1)"
check "skip warning" "$out" "token file /nonexistent/ai-memory-token missing, skipping"
refute "no installer without token" "$out" "CALLED"
exit "$fail"
-142
View File
@@ -1,142 +0,0 @@
# Babysitter user profile for Pi/agent workflows.
{
config,
lib,
...
}: let
cfg = config.coding.agents.babysitter;
defaultTimestamp = "2026-05-29T00:00:00.000Z";
defaultUserProfile = {
name = config.home.username;
specialties = [
{
domain = "declarative-system-configuration";
subdomains = ["nix" "home-manager" "agents"];
}
];
expertiseLevels = {};
goals = [
{
id = "goal-agents-declarative-profile";
description = "Keep Babysitter user preferences declarative and reproducible across systems.";
category = "agents";
priority = "medium";
status = "active";
}
];
preferences = {
verbosity = "concise";
autonomyLevel = "semi-autonomous";
riskTolerance = "conservative";
};
toolPreferences = {
packageManagers = ["nix"];
languages = ["nix"];
operatingSystem = "nixos";
};
breakpointTolerance = {
global = "moderate";
skipBreakpointsForKnownPatterns = false;
alwaysBreakOn = ["destructive-operations" "secrets" "external-publication"];
};
communicationStyle = {
tone = "technical";
language = "en";
useEmojis = false;
explanationDepth = "brief";
preferredResponseFormat = "markdown";
};
experience = {};
installedPlugins = ["babysitter-pi"];
installedSkills = ["babysit" "call" "plan" "resume" "doctor" "yolo"];
installedAgents = [];
createdAt = defaultTimestamp;
updatedAt = defaultTimestamp;
version = 1;
};
effectiveProfile = lib.recursiveUpdate cfg.profile cfg.profileOverrides;
profileJsonTarget = "${cfg.profileDirectory}/user-profile.json";
profileMarkdownTarget = "${cfg.profileDirectory}/user-profile.md";
profilePreferences = effectiveProfile.preferences or {};
profileBreakpointTolerance = effectiveProfile.breakpointTolerance or {};
listMarkdown = values:
lib.concatMapStringsSep "\n" (value: "- ${toString value}") values;
specialtyDomains = map (specialty: specialty.domain or "unspecified") (effectiveProfile.specialties or []);
profileMarkdown = ''
# Babysitter User Profile
This file is generated by Home Manager from `coding.agents.babysitter`.
- Name: ${effectiveProfile.name or "unspecified"}
- Breakpoint tolerance: ${profileBreakpointTolerance.global or "unspecified"}
- Autonomy level: ${profilePreferences.autonomyLevel or "unspecified"}
- Risk tolerance: ${profilePreferences.riskTolerance or "unspecified"}
## Specialties
${listMarkdown specialtyDomains}
## Installed Babysitter Pi Skills
${listMarkdown (effectiveProfile.installedSkills or [])}
'';
in {
options.coding.agents.babysitter = {
enable = lib.mkEnableOption "Babysitter user profile for Pi/agent workflows";
profileDirectory = lib.mkOption {
type = lib.types.str;
default = ".a5c";
description = ''
Home-relative directory where Babysitter reads the user profile.
Babysitter Pi documents the user profile at ~/.a5c/user-profile.json.
'';
};
profile = lib.mkOption {
type = lib.types.attrsOf lib.types.anything;
default = defaultUserProfile;
description = "Complete non-secret Babysitter user profile JSON.";
};
profileOverrides = lib.mkOption {
type = lib.types.attrsOf lib.types.anything;
default = {};
description = ''
Recursive overrides merged into the default Babysitter user profile.
Keep this non-secret; the result is written into the Nix store.
'';
};
};
config = lib.mkIf cfg.enable {
assertions = [
{
assertion = cfg.profileDirectory != "" && !lib.hasPrefix "/" cfg.profileDirectory;
message = "coding.agents.babysitter.profileDirectory must be a non-empty home-relative path.";
}
{
assertion = effectiveProfile ? name && builtins.isString effectiveProfile.name;
message = "coding.agents.babysitter profile must include a string name.";
}
{
assertion = effectiveProfile ? specialties && builtins.isList effectiveProfile.specialties;
message = "coding.agents.babysitter profile must include a specialties list.";
}
{
assertion = effectiveProfile ? breakpointTolerance && effectiveProfile.breakpointTolerance ? global;
message = "coding.agents.babysitter profile must include breakpointTolerance.global.";
}
];
home.file = {
"${profileJsonTarget}".text = builtins.toJSON effectiveProfile + "\n";
"${profileMarkdownTarget}".text = profileMarkdown;
};
};
}
-239
View File
@@ -1,239 +0,0 @@
{...}: {
coding.agents.pi = {
enable = true;
settings = {
packages = [
"npm:@dreadedzombie/pi-init"
"git:github.com/a5c-ai/babysitter-pi"
"npm:@plannotator/pi-extension"
"npm:pi-agent-browser-native"
"npm:pi-beads-extension"
"npm:pi-lens"
"npm:pi-markdown-preview"
"npm:pi-mcp-adapter"
"npm:pi-powerline-footer"
"npm:pi-prompt-template-model"
"npm:pi-subagents"
"npm:pi-tool-display"
"npm:pi-web-access"
];
defaultProvider = "openai-codex";
defaultModel = "gpt-5.5";
defaultThinkingLevel = "high";
};
# pi-guardrails: strict security config
# NOTE: Path access checks are lexical (not symlink-safe).
# NOTE: Local project .pi/extensions/guardrails.json can override same rule IDs.
# For immutable global policies, consider a wrapper or upstream patch.
guardrails = {
enable = false;
config = {
enabled = true;
applyBuiltinDefaults = true;
onboarding = {
completed = true;
};
features = {
policies = true;
permissionGate = true;
pathAccess = true;
};
pathAccess = {
mode = "ask";
allowedPaths = [
"/nix/store/"
"/tmp/"
];
};
policies = {
rules = [
# ── SSH keys ───────────────────────────────────────────
{
id = "home-ssh";
enabled = true;
protection = "noAccess";
onlyIfExists = false;
patterns = [
{pattern = "~/.ssh/**";}
{pattern = "~/.ssh/*_rsa";}
{pattern = "~/.ssh/*_ed25519";}
{pattern = "~/.ssh/*.pem";}
];
allowedPatterns = [
{pattern = "~/.ssh/*.pub";}
];
}
# ── GPG keys ─────────────────────────────────────────
{
id = "home-gpg";
enabled = true;
protection = "noAccess";
onlyIfExists = false;
patterns = [
{pattern = "~/.gnupg/**";}
{pattern = "~/*.gpg";}
{pattern = "~/.gpg-agent.conf";}
];
}
# ── AWS credentials ────────────────────────────────────
{
id = "home-aws";
enabled = true;
protection = "noAccess";
onlyIfExists = false;
patterns = [
{pattern = "~/.aws/**";}
{pattern = "~/.aws/credentials";}
{pattern = "~/.aws/config";}
];
}
# ── Kubernetes configs ────────────────────────────────
{
id = "home-kube";
enabled = true;
protection = "noAccess";
onlyIfExists = false;
patterns = [
{pattern = "~/.kube/**";}
{pattern = "*kubeconfig*";}
];
}
# ── Cloud CLI configs ────────────────────────────────
{
id = "home-config";
enabled = true;
protection = "noAccess";
onlyIfExists = false;
patterns = [
{pattern = "~/.config/gh/**";}
{pattern = "~/.config/gcloud/**";}
{pattern = "~/.config/op/**";}
{pattern = "~/.config/sops/**";}
];
}
# ── agenix secrets ───────────────────────────────────
{
id = "agenix-secrets";
enabled = true;
protection = "noAccess";
onlyIfExists = false;
patterns = [
{pattern = "/run/agenix/**";}
];
}
# ── Pi auth and sessions ────────────────────────────
{
id = "pi-auth-sessions";
enabled = true;
protection = "noAccess";
onlyIfExists = false;
patterns = [
{pattern = "~/.pi/agent/auth.json";}
{pattern = "~/.pi/agent/sessions/**";}
];
}
# ── Environment files ─────────────────────────────────
{
id = "secret-files";
enabled = true;
protection = "noAccess";
onlyIfExists = true;
patterns = [
{pattern = ".env";}
{pattern = ".env.*";}
{pattern = ".dev.vars";}
];
allowedPatterns = [
{pattern = "*.example.env";}
{pattern = "*.sample.env";}
{pattern = "*.test.env";}
{pattern = ".env.example";}
{pattern = ".env.sample";}
{pattern = ".env.test";}
];
}
# ── Private keys and certificates ───────────────────
{
id = "private-keys";
enabled = true;
protection = "noAccess";
onlyIfExists = false;
patterns = [
{pattern = "*.pem";}
{pattern = "*.key";}
{pattern = "*.p12";}
{pattern = "*.pfx";}
{pattern = "*id_rsa*";}
{pattern = "*id_ed25519*";}
{pattern = "*id_ecdsa*";}
];
allowedPatterns = [
{pattern = "*.pub";}
{pattern = "*.csr";}
];
}
];
};
permissionGate = {
explainCommands = false;
# Auto-deny patterns: env leakage and credential dumping
autoDenyPatterns = [
{
pattern = "\\benv\\b";
regex = true;
description = "env command (may dump environment)";
}
{
pattern = "\\bprintenv\\b";
regex = true;
description = "printenv command (dumps environment variables)";
}
{
pattern = "/proc/[0-9]+/environ";
regex = true;
description = "reading process environment files";
}
{
pattern = "gpg\\s+--export-secret-keys";
regex = true;
description = "GPG secret key export";
}
{
pattern = "gpg\\s+--export-secret-subkeys";
regex = true;
description = "GPG secret subkey export";
}
{
pattern = "ssh-add\\s+-D";
regex = true;
description = "delete all SSH identities";
}
{
pattern = "\\b(op|pass)\\s+(read|show|get)";
regex = true;
description = "password manager read operations";
}
];
};
};
};
# MCP servers auto-inherited from programs.mcp in default.nix
};
}