feat: opencode

This commit is contained in:
Anish Lakhwara 2025-12-13 00:40:32 -08:00
parent e5fed2cdaf
commit c23de0c990
No known key found for this signature in database
GPG key ID: 7FC5DF072EF7B716
15 changed files with 430 additions and 13 deletions

View file

@ -75,6 +75,28 @@
"url": "ssh://gitea@git.sealight.xyz/aynish/basant"
}
},
"blueprint": {
"inputs": {
"nixpkgs": [
"llm-agents",
"nixpkgs"
],
"systems": "systems_5"
},
"locked": {
"lastModified": 1763308703,
"narHash": "sha256-O9Y+Wer8wOh+N+4kcCK5p/VLrXyX+ktk0/s3HdZvJzk=",
"owner": "numtide",
"repo": "blueprint",
"rev": "5a9bba070f801d63e2af3c9ef00b86b212429f4f",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "blueprint",
"type": "github"
}
},
"brew-src": {
"flake": false,
"locked": {
@ -433,7 +455,7 @@
},
"flake-utils_5": {
"inputs": {
"systems": "systems_5"
"systems": "systems_6"
},
"locked": {
"lastModified": 1694529238,
@ -708,6 +730,26 @@
"type": "github"
}
},
"llm-agents": {
"inputs": {
"blueprint": "blueprint",
"nixpkgs": "nixpkgs_3",
"treefmt-nix": "treefmt-nix_2"
},
"locked": {
"lastModified": 1765594737,
"narHash": "sha256-9r+CxptJlqTdREkSHA1pxc3oZYnpgYNkAymkQLB0R8w=",
"owner": "numtide",
"repo": "llm-agents.nix",
"rev": "fb30f7dd63c0c7227c4b80a4dbfb6765f4b9a900",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "llm-agents.nix",
"type": "github"
}
},
"lowdown-src": {
"flake": false,
"locked": {
@ -822,7 +864,7 @@
"devshell": "devshell",
"flake-compat": "flake-compat_3",
"nixlib": "nixlib",
"nixpkgs": "nixpkgs_3"
"nixpkgs": "nixpkgs_4"
},
"locked": {
"lastModified": 1683490239,
@ -974,6 +1016,22 @@
}
},
"nixpkgs_3": {
"locked": {
"lastModified": 1765425892,
"narHash": "sha256-jlQpSkg2sK6IJVzTQBDyRxQZgKADC2HKMRfGCSgNMHo=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "5d6bdbddb4695a62f0d00a3620b37a15275a5093",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixpkgs-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_4": {
"locked": {
"lastModified": 1662099760,
"narHash": "sha256-MdZLCTJPeHi/9fg6R9fiunyDwP3XHJqDd51zWWz9px0=",
@ -989,7 +1047,7 @@
"type": "github"
}
},
"nixpkgs_4": {
"nixpkgs_5": {
"locked": {
"lastModified": 1758791193,
"narHash": "sha256-F8WmEwFoHsnix7rt290R0rFXNJiMbClMZyIC/e+HYf0=",
@ -1005,7 +1063,7 @@
"type": "github"
}
},
"nixpkgs_5": {
"nixpkgs_6": {
"locked": {
"lastModified": 1758690382,
"narHash": "sha256-NY3kSorgqE5LMm1LqNwGne3ZLMF2/ILgLpFr1fS4X3o=",
@ -1024,7 +1082,7 @@
"nur": {
"inputs": {
"flake-parts": "flake-parts_2",
"nixpkgs": "nixpkgs_5"
"nixpkgs": "nixpkgs_6"
},
"locked": {
"lastModified": 1759117007,
@ -1106,10 +1164,11 @@
"homebrew-cask": "homebrew-cask",
"homebrew-core": "homebrew-core",
"jovian": "jovian",
"llm-agents": "llm-agents",
"nix-homebrew": "nix-homebrew",
"nix-matrix-appservices": "nix-matrix-appservices",
"nixos-hardware": "nixos-hardware",
"nixpkgs": "nixpkgs_4",
"nixpkgs": "nixpkgs_5",
"nur": "nur",
"poonam": "poonam",
"rust-overlay": "rust-overlay",
@ -1260,6 +1319,21 @@
"type": "github"
}
},
"systems_6": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"tangled": {
"inputs": {
"flake-compat": "flake-compat_4",
@ -1349,6 +1423,27 @@
"type": "github"
}
},
"treefmt-nix_2": {
"inputs": {
"nixpkgs": [
"llm-agents",
"nixpkgs"
]
},
"locked": {
"lastModified": 1762938485,
"narHash": "sha256-AlEObg0syDl+Spi4LsZIBrjw+snSVU4T8MOeuZJUJjM=",
"owner": "numtide",
"repo": "treefmt-nix",
"rev": "5b4ee75aeefd1e2d5a1cc43cf6ba65eba75e83e4",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "treefmt-nix",
"type": "github"
}
},
"unstable": {
"locked": {
"lastModified": 1758690382,

View file

@ -1,6 +1,11 @@
{
description = "Sealight NixOS Config";
nixConfig = {
extra-substituters = [ "https://cache.numtide.com" ];
extra-trusted-public-keys = [ "niks3.numtide.com-1:DTx8wZduET09hRmMtKdQDxNNthLQETkc/yaX7M4qK0g=" ];
};
inputs = {
# Nixpkgs
nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05";
@ -71,6 +76,9 @@
inputs.nixpkgs.follows = "nixpkgs";
};
# LLM Agents
llm-agents.url = "github:numtide/llm-agents.nix";
# Others
nur.url = "github:nix-community/NUR";
rust-overlay = {
@ -95,7 +103,7 @@
outputs = { self, nixpkgs, unstable, nixos-hardware, home-manager, deploy-rs
, agenix, disko, basant, grasp, nix-matrix-appservices, nur, tidalcycles
, rust-overlay, vimwikicli, autohide-tdrop, darwin, nix-homebrew, homebrew-bundle
, homebrew-core, homebrew-cask, jovian, tangled, ... }@inputs:
, homebrew-core, homebrew-cask, jovian, tangled, llm-agents, ... }@inputs:
let
forAllSystems = nixpkgs.lib.genAttrs [
"aarch64-linux"
@ -258,6 +266,7 @@
nix.registry.unstable.flake = unstable;
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.extraSpecialArgs = { inherit inputs; };
home-manager.users.anish = import ./home/gui;
}
];
@ -320,6 +329,7 @@
nix.registry.nixpkgs.flake = nixpkgs;
home-manager.useGlobalPkgs = true;
home-manager.useUserPackages = true;
home-manager.extraSpecialArgs = { inherit inputs; };
home-manager.users.anish = import ./home/dev;
}
];
@ -362,6 +372,7 @@
users.anishlakhwara = import ./home/darwin;
useGlobalPkgs = true;
useUserPackages = true;
extraSpecialArgs = { inherit inputs; };
};
}
];

View file

@ -1,4 +1,4 @@
{ self, pkgs, ... }:
{ self, pkgs, inputs, ... }:
{
imports = [
../profiles/nvim
@ -8,6 +8,7 @@
../profiles/task
../profiles/kitty
../profiles/tmux
../profiles/opencode
# ../profiles/firefox
];

View file

@ -1,5 +1,5 @@
{ self, pkgs, ... }: {
{ self, pkgs, inputs, ... }: {
imports =
[ ../profiles/cli ../profiles/nvim ../profiles/direnv ../profiles/git ];
[ ../profiles/cli ../profiles/nvim ../profiles/direnv ../profiles/git ../profiles/opencode ];
home.stateVersion = "22.05";
}

View file

@ -1,4 +1,4 @@
{ pkgs, ... }:
{ pkgs, inputs, ... }:
{
imports = [
../core
@ -10,6 +10,7 @@
../profiles/sync/kitaab
../profiles/ssh
../profiles/task
../profiles/opencode
];
# GPG configuration for user session

View file

@ -0,0 +1,141 @@
---
description: A specialized codebase understanding agent that helps answer questions about large, complex codebases across GitHub repositories. Use this for exploring multi-repository architectures, understanding code patterns, finding implementations, and analyzing commit history.
mode: subagent
model: anthropic/claude-haiku-4-5
temperature: 0.1
tools:
"*": false
github_*: true
---
You are the Librarian, a specialized codebase understanding agent that helps users answer questions about large, complex codebases across repositories.
Your role is to provide thorough, comprehensive analysis and explanations of code architecture, functionality, and patterns across multiple repositories.
You are running inside an AI coding system in which you act as a subagent that's used when the main agent needs deep, multi-repository codebase understanding and analysis.
## Key Responsibilities
- Explore repositories to answer questions
- Understand and explain architectural patterns and relationships across repositories
- Find specific implementations and trace code flow across codebases
- Explain how features work end-to-end across multiple repositories
- Understand code evolution through commit history
- Create visual diagrams when helpful for understanding complex systems
## Guidelines
- Use available GitHub MCP tools extensively to explore repositories
- Execute tools in parallel when possible for efficiency
- Read files thoroughly to understand implementation details
- Search for patterns and related code across multiple repositories
- Use commit listing to understand how code evolved over time
- Focus on thorough understanding and comprehensive explanation across repositories
- Create mermaid diagrams to visualize complex relationships or flows
## Available Tools (GitHub MCP)
You have access to the following GitHub MCP tools:
### Reading & Exploring
- `github_get_file_contents`: Read file or directory contents from a repository
- For directories, the path must end with `/`
- Parameters: `owner`, `repo`, `path`, `ref` (optional branch/tag)
- `github_get_repository_tree`: List all files in a repository with optional path filtering
- Use `recursive: true` to get all files
- Use `path_filter` to filter by path prefix
- Parameters: `owner`, `repo`, `recursive`, `path_filter`, `tree_sha`
- `github_list_branches`: List branches in a repository
- `github_list_tags`: List tags in a repository
### Searching
- `github_search_code`: Search for code patterns across repositories
- Use GitHub's search syntax: `pattern repo:owner/repo language:typescript path:src/`
- Combine with AND, OR, NOT operators
- Parameters: `query`, `perPage`, `page`
- `github_search_repositories`: Find repositories by name, org, language, etc.
- Use query syntax: `name org:orgname language:typescript`
- Parameters: `query`, `perPage`, `page`
### Commit History
- `github_list_commits`: View commit history for a repository
- Parameters: `owner`, `repo`, `sha` (branch/tag), `author`, `perPage`, `page`
- `github_get_commit`: Get detailed commit information including diffs
- Set `include_diff: true` for file changes
- Parameters: `owner`, `repo`, `sha`, `include_diff`
## Tool Usage Guidelines
You should use all available tools to thoroughly explore the codebase before answering.
Use tools in parallel whenever possible for efficiency.
When searching code, use GitHub's search syntax:
- `"pattern repo:owner/repo"` to search a specific repo
- `"pattern language:typescript"` to filter by language
- `"pattern path:src/"` to filter by directory
- Combine with AND, OR, NOT operators (max 5 operators)
When exploring file structure:
- Use `github_get_repository_tree` with `recursive: true` to see all files
- Use `github_get_file_contents` with a path ending in `/` to list directory contents
- Read key files like README.md, package.json, or main entry points first
## Communication
You must use Markdown for formatting your responses.
IMPORTANT: When including code blocks, you MUST ALWAYS specify the language for syntax highlighting. Always add the language identifier after the opening backticks.
NEVER refer to tools by their names. Example: NEVER say "I can use the github_get_file_contents tool", instead say "I'm going to read the file"
### Direct & Detailed Communication
You should only address the user's specific query or task at hand. Do not investigate or provide information beyond what is necessary to answer the question.
You must avoid tangential information unless absolutely critical for completing the request. Avoid long introductions, explanations, and summaries. Avoid unnecessary preamble or postamble, unless the user asks you to.
Answer the user's question directly, without elaboration, explanation, or details. You MUST avoid text before/after your response, such as "The answer is <answer>.", "Here is the content of the file..." or "Based on the information provided, the answer is..." or "Here is what I will do next...".
You're optimized for thorough understanding and explanation, suitable for documentation and sharing.
You should be comprehensive but focused, providing clear analysis that helps users understand complex codebases.
IMPORTANT: Only your last message is returned to the main agent and displayed to the user. Your last message should be comprehensive and include all important findings from your exploration.
## Linking
To make it easy for the user to look into code you are referring to, you always link to the source with markdown links.
For files or directories, the URL should look like:
`https://github.com/<org>/<repository>/blob/<revision>/<filepath>#L<range>`
Where:
- `<org>` is the organization or user
- `<repository>` is the repository name
- `<revision>` is the branch or commit SHA (use `main` or `master` if not specified)
- `<filepath>` is the absolute path to the file
- `<range>` is an optional fragment with the line range (e.g., `L32-L42`)
Example: `https://github.com/foo_org/bar_repo/blob/develop/src/test.py#L32-L42`
Prefer "fluent" linking style. That is, don't show the user the actual URL, but instead use it to add links to relevant parts (file names, directory names, or repository names) of your response.
Whenever you mention a file, directory or repository by name, you MUST link to it in this way. ONLY link if the mention is by name.
## Examples
When asked "How does authentication work in the Kubernetes codebase?":
1. Search for authentication-related code
2. Read key files to understand the implementation
3. Trace the code flow
4. Provide a comprehensive explanation with links to source files
When asked "Find how database migrations are handled in Rails":
1. Search the Rails repository for migration-related code
2. Explore the directory structure
3. Read migration runner and generator files
4. Explain the migration system with code references

View file

@ -0,0 +1,52 @@
{ pkgs, lib, inputs, ... }:
let
# Paths to agenix-decrypted secrets (same on Darwin and NixOS)
githubToken = "/run/agenix/github-token";
anthropicToken = "/run/agenix/anthropicToken";
# github-mcp-server binary path from nixpkgs
githubMcpServer = "${pkgs.github-mcp-server}/bin/github-mcp-server";
in
{
home.packages = [
pkgs.github-mcp-server
inputs.llm-agents.packages.${pkgs.system}.opencode
inputs.llm-agents.packages.${pkgs.system}.beads
];
# OpenCode configuration directory
xdg.configFile = {
"opencode/opencode.json".text = builtins.toJSON {
"$schema" = "https://opencode.ai/config.json";
theme = "ayu-mirage";
autoupdate = false;
permission = {
external_directory = "allow";
};
provider = {
anthropic = {
options = {
apiKey = "{file:${anthropicToken}}";
};
};
};
mcp = {
github = {
type = "local";
command = [ githubMcpServer "stdio" ];
environment = {
GITHUB_PERSONAL_ACCESS_TOKEN = "{file:${githubToken}}";
};
};
};
agent = {
build.tools."github_*" = false;
plan.tools."github_*" = false;
};
};
"opencode/themes/ayu-mirage.json".source = ./themes/ayu-mirage.json;
"opencode/agent/librarian.md".source = ./agent/librarian.md;
};
}

View file

@ -0,0 +1,80 @@
{
"$schema": "https://opencode.ai/theme.json",
"defs": {
"darkBg": "#1f2430",
"darkBgAlt": "#242936",
"darkLine": "#171b24",
"darkPanel": "#1c212b",
"darkFg": "#cccac2",
"darkFgMuted": "#707a8c",
"darkGutter": "#8a919966",
"darkTag": "#5ccfe6",
"darkFunc": "#ffd173",
"darkEntity": "#73d0ff",
"darkString": "#d5ff80",
"darkRegexp": "#95e6cb",
"darkMarkup": "#f28779",
"darkKeyword": "#ffad66",
"darkSpecial": "#ffdfb3",
"darkComment": "#b8cfe680",
"darkConstant": "#dfbfffb3",
"darkOperator": "#f29e7480",
"darkAdded": "#87d96cb3",
"darkRemoved": "#f27983b3",
"darkAccent": "#ffcc66b3",
"darkError": "#ff6666",
"darkIndentActive": "#8a919959"
},
"theme": {
"primary": "darkEntity",
"secondary": "darkConstant",
"accent": "darkAccent",
"error": "darkError",
"warning": "darkSpecial",
"success": "darkAdded",
"info": "darkTag",
"text": "darkFg",
"textMuted": "darkFgMuted",
"background": "darkBg",
"backgroundPanel": "darkPanel",
"backgroundElement": "darkBgAlt",
"border": "darkGutter",
"borderActive": "darkIndentActive",
"borderSubtle": "darkLine",
"diffAdded": "darkAdded",
"diffRemoved": "darkRemoved",
"diffContext": "darkComment",
"diffHunkHeader": "darkComment",
"diffHighlightAdded": "darkString",
"diffHighlightRemoved": "darkMarkup",
"diffAddedBg": "#20303b",
"diffRemovedBg": "#37222c",
"diffContextBg": "darkPanel",
"diffLineNumber": "darkGutter",
"diffAddedLineNumberBg": "#1b2b34",
"diffRemovedLineNumberBg": "#2d1f26",
"markdownText": "darkFg",
"markdownHeading": "darkConstant",
"markdownLink": "darkEntity",
"markdownLinkText": "darkTag",
"markdownCode": "darkString",
"markdownBlockQuote": "darkSpecial",
"markdownEmph": "darkSpecial",
"markdownStrong": "darkFunc",
"markdownHorizontalRule": "darkFgMuted",
"markdownListItem": "darkEntity",
"markdownListEnumeration": "darkTag",
"markdownImage": "darkEntity",
"markdownImageText": "darkTag",
"markdownCodeBlock": "darkFg",
"syntaxComment": "darkComment",
"syntaxKeyword": "darkKeyword",
"syntaxFunction": "darkFunc",
"syntaxVariable": "darkEntity",
"syntaxString": "darkString",
"syntaxNumber": "darkConstant",
"syntaxType": "darkSpecial",
"syntaxOperator": "darkOperator",
"syntaxPunctuation": "darkFg"
}
}

View file

@ -91,7 +91,16 @@
# Enable the OpenSSH daemon.
services.openssh.enable = true;
networking.firewall.allowedTCPPorts = [ 22 ];
networking.firewall.allowedTCPPorts = [
22 # SSH
5003 # opencode-manager backend
5173 # opencode-manager frontend
5551 # opencode server
];
networking.firewall.allowedTCPPortRanges = [{
from = 7000;
to = 9000;
}]; # opencode-manager: ports for testing user changes
programs.gnupg.agent.enable = true;
programs.gnupg.agent.pinentryPackage = pkgs.pinentry-curses;

View file

@ -66,6 +66,10 @@
age.secrets.box-wg.file = "${self}/secrets/box-wg.age";
age.secrets.box-wg.owner = "anish";
age.secrets.borg-key.file = "${self}/secrets/borg-key.age";
age.secrets.github-token.file = "${self}/secrets/github-token.age";
age.secrets.github-token.owner = "anish";
age.secrets.anthropicToken.file = "${self}/secrets/anthropicToken.age";
age.secrets.anthropicToken.owner = "anish";
mossnet.wg = {
enable = true;
ips = [ "10.0.69.4/24" ];

View file

@ -85,6 +85,10 @@
age.secrets.curve-wg.file = "${self}/secrets/curve-wg.age";
age.secrets.curve-wg.owner = "anish";
age.secrets.github-token.file = "${self}/secrets/github-token.age";
age.secrets.github-token.owner = "anish";
age.secrets.anthropicToken.file = "${self}/secrets/anthropicToken.age";
age.secrets.anthropicToken.owner = "anish";
mossnet.wg = {
enable = true;
ips = [ "10.0.69.2/24" ];

View file

@ -1,4 +1,4 @@
{ self, pkgs, config, ... }:
{ self, pkgs, config, inputs, ... }:
{
imports = [
@ -22,6 +22,10 @@
age.identityPaths = [ "/Users/anishlakhwara/.ssh/id_ed25519" ];
age.secrets.work-wg.file = "${self}/secrets/work-wg.age";
age.secrets.work-wg.owner = "anishlakhwara";
age.secrets.github-token.file = "${self}/secrets/github-token.age";
age.secrets.github-token.owner = "anishlakhwara";
age.secrets.anthropicToken.file = "${self}/secrets/anthropicToken.age";
age.secrets.anthropicToken.owner = "anishlakhwara";
networking.wg-quick.interfaces = {
wg0 = {
address = [ "10.0.69.7/24" ];

View file

@ -0,0 +1,13 @@
age-encryption.org/v1
-> ssh-ed25519 thu/uw QLaolmSxc9Ttj1oeUpXOXXFWl8tujPNHPWndONc5tj4
XkyS+bH2PkbDzgnGot5os/PNW8vc2To3XkURqizAbnE
-> ssh-ed25519 AiezdQ D+YMTZ3+ugspxhXe+wUMD4NnZcFdPBbB6vZNzDJ0tiU
V562Gi4OeTgX2Qs5gnzb75e+YzgWarimh5Jy9aNIXFU
-> ssh-ed25519 H6uv4Q Z8pKwmLJcZCa/+5BrfOU5Av1KxgykAtI51mvr7AonWI
35sCIDjumH3hWjk72ezEZbzw7KPMEe7UKko52q3InN0
-> ssh-ed25519 K2vF/Q +i4DZxik5VBvvF0eH3rN1fuPbpbaWMOvQqN32lZEcD8
msEHIWIJwHk54jTifMRZcQXSBMLv8ROIMpOglWEyQaA
--- jkVE6fH3DN5pOY7lAp7hj2EnNvd7VZT8nObC9RrVo7E
ë¡©/¢
êŒ}ÚøÚºÙ)ñºôÈ!˜½ wžzµ:L³tш¬iÅm8>NœL ì<>³,® M2Rƒ0wþÀá^©_{ž«Æ2)Ÿk@4õk-F¬šX<C5A1>ÜRÑ/<2F>Ø=^Ñm*ðOüÆÆ°£ÅzIœONãº6r‡ŸQ„
Wõa¿±yoƒ-

BIN
secrets/github-token.age Normal file

Binary file not shown.

View file

@ -37,4 +37,6 @@ in
"wallabag-secret.age".publicKeys = [ mossnet ];
"work-wg.age".publicKeys = [ work user system ];
"github-token.age".publicKeys = [ work user system mossnet ];
"anthropicToken.age".publicKeys = [ work user system mossnet ];
}