LLMs

Chat agents for when I am lazy.

Previous post: NuShell.

Claude Code

Link: Claude-code

A chat agent that has access to your filesystem and system commands. It sends all your local data (file contents, command output) to remote Anthropic servers, so be careful.

Custom Nix agent module

I share my user prompt between different agents such a VS Code’s chat extension, using a Nix module that takes files like this as input:

Show my user prompt for all my development tasks in Nix
# AI Agent Instructions Data
# Base instructions and language-specific instructions for AI coding assistants
{
  # Base instructions for all AI agents (in order of importance)
  baseInstructions = [
    "Don't be sycophantic and tell how good my ideas are. I may have flawed ideas."
    "I am not interested in refactoring or summary documents."
    "When writing in an interactive Nu shell, you should use Nushell syntax for commands."
    "Use a functional and declarative programming approach"
    "Never comment-out or adjust tests while fixing bugs. Instead, double-check the test expectations and fix the library implementation."
    "Don't use emojis or emoticons in comments or output"
    "Ask concise follow-up questions to figure out what I want"
    "When a command is missing, you can use `nix-shell -p [command-nix-package] --run 'command'` for running the missing command."
    "Only add comments when the variable or function naming is not self-explanatory."
    "Always try to run linters with JSON output turned first to save tokens."
    "Consider replacing comments by better variable or function names."
    "Request examples when requirements are ambiguous"
    "Suggest testing approaches for generated code"
    "Prevent security problems in already written and new code"
    "Enable logging or tracing to debug difficult failing tests"
    "You should never capture or redirect stdout or stderr output unless necessary."
    "Modify documents in-place and do not create new version with suffixes in the filename."
    "Use sub-agents to complete tasks to require changes to unrelated files."
    "Use custom composite `ast-grep` rules to make bulk code changes in large code bases to save time."
    "When you are done with all tasks, search the codebase for todo (case-insensitive) comments to gather new tasks and start right away executing them."
    "Remove dead / unused code and inline simple functions that are just used once."
  ];

# Language-specific instructions

  languages = {
    lean = {
      enable = false;
      extensions = [ "lean" ];
      instructions = [
        "Use `lean-lsp-mcp` MCP server for goals/diagnostics when available"
        "Replace `sorry` step-by-step in tests"
        "Try `exact?` and then `apply?` before searching elsewhere"
        "Use `lake build` and avoid `lake clean`"
        "Keep functions computable when possible"
        "Use problem decomposition for complex proofs"
        "Leverage existing mathlib theorems before creating new ones"
        "Provide counterexamples when proofs fail"
      ];
    };

    nix = {
      enable = true;
      extensions = [ "nix" ];
      instructions = [
        "When running as root, call `nixos-rebuild test` and skip the dry-run step."
        "When running as a normal non-root user, use `nixos-rebuild dry-run` to validate the nix configuration of the current host without building it."
        "Never run any `find` command on the `/nix/store` folder based on filename, because absolute store paths slow to traverse and unpredictable."
        "Don't create new script/ directories, just embed script files directly in the parent directory."
        "Check for nix configuration evaluation performance regressions when making changes to the nix import structure."
        "Use separate files for shell scripts, never inline them in nix files (unless it is a one-liner)."
        "Prefer Nushell as the primary flavor for writing new shell scripting"
        "Never use nix built-in string replacement or substitution with `@` placeholders on external included files but implement command-line argument passing."
        "Declare runtime dependencies for scripts in the related Nix systemd service definition and its path option. Don't add them globally."
      ];
    };

    sh = {
      enable = true;
      extensions = [
        "sh"
        "bash"
      ];
      instructions = [
        "Do not create functions in scripts that are just one line (excluding comments)."
        "Lint bash script files with ShellCheck linter and fix issues."
        "When printing errors, consider writing to either stdout or stderr."
        "Prefix shell script output with journald priority levels as <level>."
        "Consider using Nushell for new scripts instead of bash."
      ];
    };

    typ = {
      enable = true;
      extensions = [ "typ" ];
      instructions = [
        "To debug a long Typst document, make a minimal example that reproduces the problem."
        "Extract a small amount of images of pages from the PDF output and analyze them."
        "Modify the template instead of the user content when fixing layout issues."
        "Create reusable, general layout functions for repeated patterns."
        "Do not duplicate functionality, but improve generalisability for existing functions."
        "Search online first whether someone else created a library for a common layout problem."
      ];
    };

    nu = {
      enable = true;
      extensions = [ "nu" ];
      instructions = [
        "Leverage Nushell's structured data capabilities for data manipulation."
        "Utilize built-in Nushell commands for common tasks instead of external utilities."
        "When writing scripts, prefer pipelines and data transformations over imperative loops."
      ];
    };

    py = {
      enable = false;
      extensions = [ "py" ];
      instructions = [
        "Use type hints"
        "Use structured error handling with specific exception types"
        "Validate inputs and provide clear error messages"
      ];
    };

    rs = {
      enable = true;
      extensions = [ "rs" ];
      instructions = [
        "Never use the `anyhow` dependency."
        "Never use the `String` type for building error types or enum variants."

        "Only make code `pub` or `pub(crate)` when necessary."
        "Use `Result` and `Option` consistently instead of panicking."
        "Use the `clippy` linter to improve code quality."
        "Write new tests for public API inside the tests/ folder"
        "Write new unit tests for private API inside the relevant src file"
        "Use extension traits to group together related methods that are always called on the same (first) argument type."
        "Fix a large portion of clippy problems automatically with `cargo clippy --all-targets --fix --allow-dirty`."
        "Instead of adding comments that become stale, add logging with the external `log` crate and its macros."
      ];
    };

    md = {
      enable = true;
      extensions = [
        "md"
        "markdown"
      ];
      instructions = [
        "Do not use deeply nested sub-sections or sub-headings."
        "The ratio of semantic content to layout should be high."
        "Use YAML front matter for metadata when appropriate"
        "Only write markdown that adds value beyond improving existing code naming and structure."
      ];
    };
  };
}