summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-15 22:46:07 +0200
committerPaul Buetow <paul@buetow.org>2026-03-15 22:46:07 +0200
commit1352cda0ee2666b6b35d6fe5bacb1060fba662c6 (patch)
tree647d6cb0d94c562761b8ae3c69323a0da35edf08
parentde167eb92c19b49d5a6fc12c4ce3c636eef8b143 (diff)
Manage OpenCode config via Rex
-rw-r--r--README.md1
-rw-r--r--Rexfile76
2 files changed, 77 insertions, 0 deletions
diff --git a/README.md b/README.md
index 3e71559..9b652fb 100644
--- a/README.md
+++ b/README.md
@@ -13,3 +13,4 @@ Prompts are managed from `~/Notes/Prompts` and linked by `home_prompts` into eac
- Codex CLI slash command path: `~/.codex/prompts`
- Shared agent prompt paths: `~/.agents/{commands,skills}`
- Codex CLI runtime config: `~/.codex/config.toml`
+- OpenCode runtime config: `~/.config/opencode/opencode.json` via `rex home`, using `OLLAMA_HOST` from `fish/conf.d/ai.fish` when available
diff --git a/Rexfile b/Rexfile
index b7d08b7..8587a23 100644
--- a/Rexfile
+++ b/Rexfile
@@ -1,5 +1,6 @@
use Rex -feature => [ '1.14', 'exec_autodie' ];
use Rex::Logger;
+use JSON::PP ();
our $HOME = $ENV{HOME};
@@ -38,6 +39,65 @@ sub ensure {
( $dst =~ /\/$/ ? \&ensure_dir : \&ensure_file )->( $src, $dst, $mode );
}
+sub configured_ollama_host {
+ my $ollama_host = $ENV{OLLAMA_HOST};
+
+ if ( !defined $ollama_host || $ollama_host eq q{} ) {
+ my $fish_config = "$DOT/fish/conf.d/ai.fish";
+
+ if ( open my $fh, '<', $fish_config ) {
+ while ( my $line = <$fh> ) {
+ if ( $line =~ /set -gx OLLAMA_HOST\s+(\S+)/ ) {
+ $ollama_host = $1;
+ last;
+ }
+ }
+
+ close $fh;
+ }
+ }
+
+ $ollama_host ||= 'http://hyperstack.wg1:11434';
+ $ollama_host =~ s{/\z}{};
+ $ollama_host =~ s{/v1\z}{};
+
+ return $ollama_host;
+}
+
+sub opencode_config_content {
+ my $base_url = configured_ollama_host() . '/v1';
+
+ return JSON::PP->new->ascii->pretty->canonical->encode(
+ {
+ '$schema' => 'https://opencode.ai/config.json',
+ 'model' => 'ollama/nemotron-3-super:latest',
+ 'provider' => {
+ 'ollama' => {
+ 'models' => {
+ 'gpt-oss:120b' => {
+ 'name' => 'GPT-OSS 120B'
+ },
+ 'gpt-oss:20b' => {
+ 'name' => 'GPT-OSS 20B'
+ },
+ 'nemotron-3-super:latest' => {
+ 'name' => 'Nemotron 3 Super'
+ },
+ 'qwen3-coder:30b' => {
+ 'name' => 'Qwen3 Coder 30B'
+ },
+ },
+ 'name' => 'Ollama',
+ 'npm' => '@ai-sdk/openai-compatible',
+ 'options' => {
+ 'baseURL' => $base_url
+ },
+ },
+ },
+ }
+ );
+}
+
desc 'Install packages on Termux';
task 'pkg_termux', sub {
my @pkgs = qw/
@@ -148,6 +208,22 @@ task 'home_ghostty', sub { ensure "$DOT/ghostty/*" => "$HOME/.config/ghostty/" }
desc 'Install ~/.config/lazygit';
task 'home_lazygit', sub { ensure "$DOT/lazygit/*" => "$HOME/.config/lazygit/" };
+desc 'Install ~/.config/opencode';
+task 'home_opencode', sub {
+ my $opencode_dir = "$HOME/.config/opencode";
+
+ Rex::Logger::info( 'Deploying OpenCode config via ' . configured_ollama_host() );
+
+ file $opencode_dir,
+ ensure => 'directory',
+ mode => '0750';
+
+ file "$opencode_dir/opencode.json",
+ ensure => 'present',
+ content => opencode_config_content(),
+ mode => '0640';
+};
+
desc 'Install prompt links for AI tools';
task 'home_prompts', sub {
if ( -d "$HOME/Notes/Prompts/commands" ) {