-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathopencode.nix
More file actions
163 lines (158 loc) · 4.69 KB
/
Copy pathopencode.nix
File metadata and controls
163 lines (158 loc) · 4.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
{ inputs, pkgs, ... }:
let
llm = inputs.llm-agents.packages.${pkgs.system};
opencode-wrapped = pkgs.symlinkJoin {
name = "opencode-wrapped";
paths = [ llm.opencode ];
buildInputs = [ pkgs.makeWrapper ];
postBuild = ''
wrapProgram $out/bin/opencode --set OPENCODE_ENABLE_EXA 1
'';
};
in
{
home.packages = [
opencode-wrapped
llm.rtk
pkgs.libnotify
];
xdg.configFile = {
"opencode/opencode.json" = {
force = true;
text = builtins.toJSON {
"$schema" = "https://opencode.ai/config.json";
autoshare = false;
theme = "system";
plugin = [
"@mohak34/opencode-notifier@latest"
"${inputs.ponytail}/.opencode/plugins/ponytail.mjs"
];
command = {
last30days = {
description = "Research any topic across Reddit, X, YouTube, TikTok, HN, Polymarket, GitHub, and the web";
template = "Run the last30days skill to research this topic across all available sources: {{input}}";
};
};
};
};
"opencode/opencode-notifier.json" = {
force = true;
text = builtins.toJSON {
sound = false;
notification = true;
bell = false;
timeout = 5;
showProjectName = true;
showSessionTitle = false;
showIcon = true;
suppressWhenFocused = true;
enableOnDesktop = false;
linux = {
grouping = true;
};
minDuration = 0;
events = {
permission = {
sound = false;
notification = true;
command = false;
bell = false;
};
complete = {
sound = false;
notification = true;
command = false;
bell = false;
};
subagent_complete = {
sound = false;
notification = false;
command = false;
bell = false;
};
error = {
sound = false;
notification = true;
command = false;
bell = false;
};
question = {
sound = false;
notification = true;
command = false;
bell = false;
};
user_cancelled = {
sound = false;
notification = false;
command = false;
bell = false;
};
plan_exit = {
sound = false;
notification = true;
command = false;
bell = false;
};
session_started = {
sound = false;
notification = false;
command = false;
bell = false;
};
user_message = {
sound = false;
notification = false;
command = false;
bell = false;
};
client_connected = {
sound = false;
notification = false;
command = false;
bell = false;
};
};
};
};
"opencode/plugins/rtk.ts" = {
force = true;
text = ''
import type { Plugin } from "@opencode-ai/plugin"
// RTK OpenCode plugin — rewrites commands to use rtk for token savings.
// Requires: rtk >= 0.23.0 in PATH.
//
// This is a thin delegating plugin: all rewrite logic lives in `rtk rewrite`,
// which is the single source of truth (src/discover/registry.rs).
// To add or change rewrite rules, edit the Rust registry — not this file.
export const RtkOpenCodePlugin: Plugin = async ({ $ }) => {
try {
await $`which rtk`.quiet()
} catch {
console.warn("[rtk] rtk binary not found in PATH — plugin disabled")
return {}
}
return {
"tool.execute.before": async (input, output) => {
const tool = String(input?.tool ?? "").toLowerCase()
if (tool !== "bash" && tool !== "shell") return
const args = output?.args
if (!args || typeof args !== "object") return
const command = (args as Record<string, unknown>).command
if (typeof command !== "string" || !command) return
try {
const result = await $`rtk rewrite ''${command}`.quiet().nothrow()
const rewritten = String(result.stdout).trim()
if (rewritten && rewritten !== command) {
;(args as Record<string, unknown>).command = rewritten
}
} catch {
// rtk rewrite failed — pass through unchanged
}
},
}
}
'';
};
};
}