Files
nixos-configs/hosts/pinwheel/modules/ai/default.nix
T

98 lines
2.7 KiB
Nix

{
inputs,
pkgs,
lib,
config,
...
}:
let
enabled = config.mod.ai.enable;
# Shared statusline: show the logged-in account email.
statusLine = {
type = "command";
command = "jq -r '.oauthAccount.emailAddress' \"$CLAUDE_CONFIG_DIR/.claude.json\"";
};
# PostToolUse hook: echoes a JSON payload that injects a comment-policy
# reminder as additional context after every Write/Edit.
commentPolicyPayload = builtins.toJSON {
suppressOutput = true;
hookSpecificOutput = {
hookEventName = "PostToolUse";
additionalContext = "Comment policy: default to ZERO code comments. Review what you just wrote and delete any comment that narrates the change, restates the code, states the obvious, is tangential, or explains design/why rationale -- put that reasoning in your chat reply instead, never in the code. Never use em dashes or en dashes anywhere in file content; use a plain ASCII hyphen or reword.";
};
};
settings = builtins.toJSON {
inherit statusLine;
theme = "dark";
editorMode = "vim";
cleanupPeriodDays = 3650;
attribution = {
commit = "";
pr = "";
};
hooks = {
PostToolUse = [
{
matcher = "Write|Edit";
hooks = [
{
type = "command";
command = "echo ${lib.escapeShellArg commentPolicyPayload}";
}
];
}
];
};
};
settingsFile = pkgs.writeText "claude-settings.json" settings;
in
{
options = {
mod.ai = {
enable = lib.mkEnableOption "enable ai module";
};
};
config = lib.mkMerge [
{ home-manager.sharedModules = [ inputs.ct.homeManagerModules.default ]; }
(lib.mkIf enabled {
home-manager.users.alex = {
home.packages = [ pkgs.claude-code ];
programs.zsh.shellAliases = {
claude = "pclaude";
wclaude = "CLAUDE_CONFIG_DIR=$HOME/.claude-work command claude";
pclaude = "CLAUDE_CONFIG_DIR=$HOME/.claude-personal command claude";
};
home.activation.claudeSettings = {
after = [ "linkGeneration" ];
before = [ ];
data = ''
for f in "$HOME"/.claude-{work,personal}/settings.json; do
current="$(cat "$f" 2>/dev/null || echo '{}')"
run mkdir -p "$(dirname "$f")"
run rm -f "$f"
echo "$current" | ${pkgs.jq}/bin/jq -s '.[0] * .[1]' ${settingsFile} - | run tee "$f" > /dev/null
done
'';
};
programs.ct = {
enable = true;
web.enable = true;
settings.profiles = {
work.configDir = "/home/alex/.claude-work";
personal.configDir = "/home/alex/.claude-personal";
};
};
};
})
];
}