chore: update flake, agents lib, and clean up tracked dotfiles
Some checks failed
Update Nix Packages with nix-update / nix-update (push) Failing after 3m59s
Some checks failed
Update Nix Packages with nix-update / nix-update (push) Failing after 3m59s
- Remove .pi* and .td-root files from git index (now in .gitignore) - Update flake.lock and flake.nix - Add shells/coding.nix, remove shells/opencode.nix - Update lib/agents.nix, lib/coding-rules.nix - Update modules/home-manager/coding/agents/pi.nix - Update tests for agents and coding-rules - Update .gitignore
This commit is contained in:
@@ -223,7 +223,10 @@
|
||||
canonical,
|
||||
modelOverrides ? {},
|
||||
primaryAgent ? null,
|
||||
codingRules ? null,
|
||||
}: let
|
||||
# Import coding-rules lib for concatRulesMd when codingRules is provided
|
||||
codingRulesLib = (import ./coding-rules.nix {inherit lib;});
|
||||
# Find the primary agent (there should be exactly one).
|
||||
primaryAgents = lib.filterAttrs (_: a: a.mode == "primary") canonical;
|
||||
primaryNames = lib.attrNames primaryAgents;
|
||||
@@ -306,6 +309,17 @@
|
||||
"- **" + dn + "**: " + agent.description;
|
||||
in
|
||||
lib.mapAttrsToList mkEntry subagents;
|
||||
# ── Coding rules section (optional) ────────────────────────
|
||||
# When codingRules is provided, append selected rules to AGENTS.md.
|
||||
# codingRules attrset: { agents, languages, concerns, frameworks }
|
||||
codingRulesSection =
|
||||
if codingRules != null
|
||||
then let
|
||||
section = codingRulesLib.mkRulesMdSection codingRules;
|
||||
in
|
||||
if section != "" then "\n" + section else ""
|
||||
else "";
|
||||
|
||||
agentsMd =
|
||||
"# Agent Instructions\n"
|
||||
+ "\n"
|
||||
@@ -320,7 +334,8 @@
|
||||
if subagents == {}
|
||||
then ""
|
||||
else "## Available Specialists\n\n" + lib.concatStringsSep "\n" specialistEntries + "\n"
|
||||
);
|
||||
)
|
||||
+ codingRulesSection;
|
||||
|
||||
agentsMdFile = pkgs.writeText "AGENTS.md" agentsMd;
|
||||
systemMdFile = pkgs.writeText "SYSTEM.md" primary.systemPrompt;
|
||||
@@ -346,6 +361,7 @@
|
||||
agentsInput,
|
||||
tool,
|
||||
modelOverrides ? {},
|
||||
codingRules ? null,
|
||||
}: let
|
||||
canonical = agentsInput.lib.loadAgents;
|
||||
in
|
||||
@@ -362,7 +378,7 @@
|
||||
else if tool == "pi"
|
||||
then
|
||||
agentsLib.renderForPi {
|
||||
inherit pkgs canonical modelOverrides;
|
||||
inherit pkgs canonical modelOverrides codingRules;
|
||||
}
|
||||
else throw "lib.agents.renderForTool: unknown tool '${tool}'. Must be opencode, claude-code, or pi.";
|
||||
|
||||
@@ -386,9 +402,10 @@
|
||||
agentsInput,
|
||||
tool,
|
||||
modelOverrides ? {},
|
||||
codingRules ? null,
|
||||
}: let
|
||||
rendered = agentsLib.renderForTool {
|
||||
inherit pkgs agentsInput tool modelOverrides;
|
||||
inherit pkgs agentsInput tool modelOverrides codingRules;
|
||||
};
|
||||
in
|
||||
if tool == "opencode"
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
# The shellHook creates:
|
||||
# - A `.opencode-rules/` symlink pointing to the AGENTS repository rules directory
|
||||
# - A `coding-rules.json` file with a $schema reference and instructions list
|
||||
# - (Optional) Appends coding rules to `AGENTS.md` for Pi agent discovery
|
||||
#
|
||||
# The instructions list contains paths relative to the project root, all prefixed
|
||||
# with `.opencode-rules/`, making them portable across different project locations.
|
||||
@@ -43,6 +44,9 @@
|
||||
# (e.g., [ "react" "fastapi" "django" ])
|
||||
# extraInstructions: Optional list of additional instruction paths
|
||||
# (for custom rules outside standard locations)
|
||||
# forPi: Whether to also append rules to AGENTS.md for Pi agent (default: true)
|
||||
# Pi discovers AGENTS.md files by walking parent dirs + cwd and concatenates them.
|
||||
# When enabled, a delimited block is appended to (or created in) AGENTS.md.
|
||||
#
|
||||
# Returns:
|
||||
# An attribute set containing:
|
||||
@@ -83,6 +87,7 @@
|
||||
frameworks ? [],
|
||||
extraInstructions ? [],
|
||||
rulesDir ? ".opencode-rules",
|
||||
forPi ? false,
|
||||
}: let
|
||||
# Build instructions list by mapping concerns, languages, frameworks to their file paths
|
||||
# All paths are relative to project root via the rulesDir symlink
|
||||
@@ -97,11 +102,46 @@
|
||||
"$schema" = "https://opencode.ai/config.json";
|
||||
inherit instructions;
|
||||
};
|
||||
|
||||
# Pi rules content (concatenated markdown) — only computed when forPi is true
|
||||
piRulesSection =
|
||||
if forPi
|
||||
then mkRulesMdSection {inherit agents languages concerns frameworks;}
|
||||
else "";
|
||||
|
||||
# Bash snippet to append rules to AGENTS.md for Pi discovery.
|
||||
# Uses HTML comment markers for idempotent updates:
|
||||
# - Removes any existing CODING-RULES block
|
||||
# - Appends the new block
|
||||
# - Creates AGENTS.md if it doesn't exist
|
||||
# Note: Uses plain if-then-else instead of lib.optionalString to avoid
|
||||
# forcing the `lib` argument (which may come from import <nixpkgs/lib>)
|
||||
# when forPi is false.
|
||||
piShellHook =
|
||||
if forPi && piRulesSection != ""
|
||||
then ''
|
||||
# Pi agent: append coding rules to AGENTS.md
|
||||
if [ -f AGENTS.md ]; then
|
||||
# Remove existing coding-rules block (if any)
|
||||
sed -i '/<!-- CODING-RULES:START -->/,/<!-- CODING-RULES:END -->/d' AGENTS.md
|
||||
# Append new coding-rules block
|
||||
cat >> AGENTS.md <<'PIRULES_EOF'
|
||||
${piRulesSection}
|
||||
PIRULES_EOF
|
||||
else
|
||||
# Create AGENTS.md with just the coding rules
|
||||
cat > AGENTS.md <<'PIRULES_EOF'
|
||||
${piRulesSection}
|
||||
PIRULES_EOF
|
||||
fi
|
||||
''
|
||||
else "";
|
||||
in {
|
||||
inherit instructions;
|
||||
|
||||
# Shell hook to set up rules in the project
|
||||
# Creates a symlink to the AGENTS rules directory and generates coding-rules.json
|
||||
# Optionally appends rules to AGENTS.md for Pi agent discovery
|
||||
shellHook = ''
|
||||
# Create/update symlink to AGENTS rules directory
|
||||
ln -sfn ${agents}/rules ${rulesDir}
|
||||
@@ -110,8 +150,73 @@
|
||||
cat > coding-rules.json <<'RULES_EOF'
|
||||
${builtins.toJSON rulesConfig}
|
||||
RULES_EOF
|
||||
|
||||
${piShellHook}
|
||||
'';
|
||||
};
|
||||
# Concatenate selected rule files from the AGENTS repository into a single
|
||||
# markdown string. Used by Pi (append to AGENTS.md) and could be used by
|
||||
# other tools that don't support an instructions list.
|
||||
#
|
||||
# Args:
|
||||
# agents: Path to the AGENTS repository (non-flake input)
|
||||
# languages: Optional list of language-specific rules to include
|
||||
# concerns: Optional list of concern rules to include
|
||||
# Default: [ "coding-style" "naming" "documentation" "testing" "git-workflow" "project-structure" ]
|
||||
# frameworks: Optional list of framework-specific rules to include
|
||||
#
|
||||
# Returns: A single concatenated markdown string with all selected rules.
|
||||
#
|
||||
# Example:
|
||||
# concatRulesMd {
|
||||
# agents = inputs.agents;
|
||||
# languages = [ "python" ];
|
||||
# concerns = [ "coding-style" ];
|
||||
# }
|
||||
# # Returns: "\n# Coding Style\n\n...python rules...\n"
|
||||
concatRulesMd = {
|
||||
agents,
|
||||
languages ? [],
|
||||
concerns ? [
|
||||
"coding-style"
|
||||
"naming"
|
||||
"documentation"
|
||||
"testing"
|
||||
"git-workflow"
|
||||
"project-structure"
|
||||
],
|
||||
frameworks ? [],
|
||||
}: let
|
||||
rulePaths =
|
||||
(map (c: {kind = "concerns"; name = c;}) concerns)
|
||||
++ (map (l: {kind = "languages"; name = l;}) languages)
|
||||
++ (map (f: {kind = "frameworks"; name = f;}) frameworks);
|
||||
|
||||
readRule = rule: builtins.readFile "${agents}/rules/${rule.kind}/${rule.name}.md";
|
||||
ruleContents = map readRule rulePaths;
|
||||
in
|
||||
lib.concatStringsSep "\n\n" ruleContents;
|
||||
|
||||
# Build a coding rules section suitable for appending to AGENTS.md.
|
||||
# Wraps concatRulesMd output with a header and HTML comment markers
|
||||
# for idempotent updates in project-level shellHooks.
|
||||
#
|
||||
# Args: Same as concatRulesMd
|
||||
#
|
||||
# Returns: A markdown string with start/end markers and a header.
|
||||
mkRulesMdSection = args: let
|
||||
content = concatRulesMd args;
|
||||
in
|
||||
if builtins.stringLength content == 0
|
||||
then ""
|
||||
else ''
|
||||
<!-- CODING-RULES:START -->
|
||||
# Coding Rules
|
||||
|
||||
${content}
|
||||
<!-- CODING-RULES:END -->
|
||||
'';
|
||||
|
||||
in {
|
||||
inherit mkCodingRules;
|
||||
inherit mkCodingRules concatRulesMd mkRulesMdSection;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user