dotfiles bugabingas dorkfiles
owned by bugabinga
README Source History Refs Compare Notes Search Review guide config: add kimi coding model
b924295a3e2c1562026b65e87577ce04bce9422b
Oliver Jan Krylow <oliver@bugabinga.net > · 20 May 2026
unsigned
Browse files Compare with HEAD
Changed files (10) nushell/gen-secrets.nu Modified 34 34 secret MINIMAX_WORK_API_KEY
35 35 secret ZAI_WORK_API_KEY
nushell/modules/kimi.nu Added new file mode 100644 6 + print
"Kimi Code / Moonshot AI integration" 7 + print
" kimi usage — check subscription quota" 8 + print
" kimi chat <message> — send a chat completion" 9 + print
" kimi models — list available models" 11 + print
"Run a subcommand with --help for details." 17 + export def usage [] {
18 + let token = get-token
21 + Authorization: $
'Bearer ($token)' 22 + Accept:
"application/json" 26 + http get --headers
$hs $
"($base)/usages" 29 + msg:
"Failed to fetch usage" 30 + label: { text:
"Check KIMI_API_KEY and network connection" }
41 + print $
"($c)KIMI CODE USAGE($e)" 45 + let usage =
$res | get --optional usage | default {}
46 + let limit =
$usage | get --optional limit | default
"0" 47 + let used =
$usage | get --optional used | default
"0" 48 + let remain =
$usage | get --optional remaining | default
"0" 49 + let reset =
$usage | get --optional resetTime | default
"" 51 + if (
$limit | into int) >
0 {
52 + let pct = (
$remain | into int) *
100 // (
$limit | into int)
54 + let color =
if $pct <=
10 {
$r }
else if $pct <=
30 {
$y }
else {
$g }
55 + let reset_hint =
if $reset !=
"" { $
" ($d)resets ($reset)($e)" }
else {
"" }
56 + print $
" ($c)Weekly Quota($e)" 57 + print $
" ($bar) ($color)($remain)/($limit) ($pct)% left($e)($reset_hint)" 62 + let total_quota =
$res | get --optional totalQuota | default {}
63 + let tq_limit =
$total_quota | get --optional limit | default
"0" 64 + let tq_remain =
$total_quota | get --optional remaining | default
"0" 65 + if (
$tq_limit | into int) >
0 {
66 + print $
" ($c)Total Quota($e) ($tq_remain)/($tq_limit) remaining" 71 + let limits =
$res | get --optional limits | default []
72 + if (
$limits | length) >
0 {
73 + print $
" ($c)Rate Limits($e)" 74 + for item
in $limits {
75 + let window =
$item | get --optional window | default {}
76 + let detail =
$item | get --optional detail | default {}
77 + let w_dur =
$window | get --optional duration | default
0 78 + let w_unit =
$window | get --optional timeUnit | default
"" 79 + let d_limit =
$detail | get --optional limit | default
"0" 80 + let d_used =
$detail | get --optional used | default
"0" 81 + let d_remain =
$detail | get --optional remaining | default
"0" 83 + let label =
if (
$w_unit | str contains
"MINUTE" ) and
$w_dur >=
60 and (
$w_dur mod
60 ) ==
0 {
84 + $
"($w_dur / 60)h limit" 85 + }
else if (
$w_unit | str contains
"MINUTE" ) {
87 + }
else if (
$w_unit | str contains
"HOUR" ) {
89 + }
else if (
$w_unit | str contains
"DAY" ) {
95 + let pct =
if (
$d_limit | into int) >
0 {
96 + (
$d_remain | into int) *
100 // (
$d_limit | into int)
99 + print $
" ($label) ($bar) ($d_remain)/($d_limit)" 105 + let parallel =
$res | get --optional parallel | default {}
106 + let p_limit =
$parallel | get --optional limit | default
"0" 107 + if (
$p_limit | into int) >
0 {
108 + print $
" ($c)Concurrency($e) max ($p_limit) parallel requests" 113 + def bar [pct: int] {
114 + let n = (
$pct /
10 | math round | into int)
115 + let n =
if $n >
10 {
10 }
else if $n <
0 {
0 }
else {
$n }
121 + let color =
if $pct <
50 {
$g }
else if $pct <
80 {
$y }
else {
$r }
122 + let filled =
1 ..
$n |
each { $
"($g)▓" } | str join
123 + let empty =
1 ..(
10 -
$n ) |
each { $
"($d)░" } | str join
124 + $
"($filled)($empty)($e)" 130 + let token =
$env | get --optional KIMI_API_KEY
131 + if (
$token | is-empty) {
133 + msg:
"KIMI_API_KEY is not set" 134 + label: { text:
"Set KIMI_API_KEY in secrets.nuon" }
141 + $env | get --optional KIMI_API_BASE | default
"https://api.kimi.com/coding/v1" 146 + Authorization: $
'Bearer (get-token)' 147 + Content-Type:
"application/json" 148 + Accept:
"application/json" 161 + --system (-s): string =
"" 163 + if (
$message | str trim | is-empty) {
165 + msg:
"Message cannot be empty" 166 + label: { text:
"Provide a non-empty message" }
170 + let base = get-base
174 + if (
$system | str trim | is-not-empty) {
175 + $messages =
$messages | append { role:
"system" , content:
$system }
177 + $messages =
$messages | append { role:
"user" , content:
$message }
180 + model:
"kimi-for-coding" 181 + messages:
$messages 185 + http post --headers
$hs $
"($base)/chat/completions" (
$payload | to json)
187 + let raw =
$e.raw | default
"" 188 + if (
$raw | str contains
"401" ) {
190 + msg:
"Authentication failed (401)" 191 + label: { text:
"Check KIMI_API_KEY is correct and active" }
193 + }
else if (
$raw | str contains
"403" ) {
195 + msg:
"Access forbidden (403)" 196 + label: { text:
"Kimi Code API key may be restricted. Ensure subscription includes API access and key is active at https://www.kimi.com/code/console" }
198 + }
else if (
$raw | str contains
"429" ) {
200 + msg:
"Rate limited (429)" 201 + label: { text:
"Too many requests — wait and retry" }
205 + msg:
"Chat request failed" 206 + label: { text: (
$e.msg | default
"Check network and API base URL" ) }
210 + let choice =
$resp | get --optional choices | default [] | get
0 | default {}
211 + let content =
$choice | get --optional message.content | default
"" 212 + let finish =
$choice | get --optional finish_reason | default
"" 216 + if $finish !=
"stop" and (
$finish | is-not-empty) {
217 + print $
"(ansi d)[finish_reason: ($finish)](ansi rst)" 224 + export def models [] {
225 + let base = get-base
229 + http get --headers
$hs $
"($base)/models" 232 + msg:
"Failed to list models" 233 + label: { text:
"Check KIMI_API_KEY and KIMI_API_BASE" }
237 + $res.data |
each { |m|
240 + display_name: (
$m | get --optional display_name | default
"" )
241 + context: (
$m | get --optional context_length | default
0 )
pi/agent/extensions/free/index.ts Deleted deleted file mode 100644 18 - import type { ExtensionAPI, ProviderModelConfig }
from "@mariozechner/pi-coding-agent" ;
24 - const ZEN_BASE_URL
= "https://opencode.ai/zen" ;
27 - const ZEN_AM_MODELS
= [
"big-pickle" ,
"minimax-m2.5-free" ];
30 - const ZEN_OC_MODELS
= [
"hy3-preview-free" ,
"ling-2.6-flash-free" ,
"nemotron-3-super-free" ];
33 - const ZEN_SPECS
: Record <
string , { contextWindow
: number ; maxTokens
: number ; reasoning
: boolean }>
= {
34 - "big-pickle" : { contextWindow:
200_000 , maxTokens:
128_000 , reasoning:
true },
35 - "minimax-m2.5-free" : { contextWindow:
128_000 , maxTokens:
32_000 , reasoning:
false },
36 - "hy3-preview-free" : { contextWindow:
262_144 , maxTokens:
262_144 , reasoning:
false },
37 - "ling-2.6-flash-free" : { contextWindow:
262_144 , maxTokens:
32_000 , reasoning:
false },
38 - "nemotron-3-super-free" : { contextWindow:
262_144 , maxTokens:
262_144 , reasoning:
false },
41 - function zenSpec (id
: string ) {
42 - return ZEN_SPECS[id]
?? { contextWindow:
128_000 , maxTokens:
32_000 , reasoning:
false };
45 - function zenModel (id
: string , api
: "anthropic-messages" | "openai-completions" )
: ProviderModelConfig {
46 - const s
= zenSpec (id);
47 - const name
= id.
replace (
/-/ g ,
" " ).
replace (
/ \b \w/ g , (c)
=> c.
toUpperCase ());
51 - reasoning: s.reasoning,
52 - input: [
"text" ]
as (
"text" | "image" )[],
53 - cost: { input:
0 , output:
0 , cacheRead:
0 , cacheWrite:
0 },
54 - contextWindow: s.contextWindow,
55 - maxTokens: s.maxTokens,
57 - if (api
=== "openai-completions" ) {
60 - api:
"openai-completions" as const ,
62 - maxTokensField:
"max_tokens" ,
63 - supportsStore:
false ,
64 - supportsDeveloperRole:
false ,
65 - supportsReasoningEffort:
false ,
66 - requiresThinkingAsText:
false ,
70 - return {
... base, api:
"anthropic-messages" as const };
73 - interface ZenModel { id
: string ; }
74 - interface ZenModelsResponse { data
: ZenModel []; }
76 - async function fetchZenModels (signal
?: AbortSignal ) {
77 - const res
= await fetch (
"https://opencode.ai/zen/v1/models" , { signal });
78 - if (
! res.ok)
throw new Error (
`Zen returned ${res. status }` );
79 - const data
= (
await res.
json ())
as ZenModelsResponse ;
80 - const ids
= data.
data .
map ((m)
=> m.
id );
82 - am: ZEN_AM_MODELS.
filter ((id)
=> ids.
includes (id)).
map ((id)
=> zenModel (id,
"anthropic-messages" )),
83 - oc: ZEN_OC_MODELS.
filter ((id)
=> ids.
includes (id)).
map ((id)
=> zenModel (id,
"openai-completions" )),
91 - interface KiloModelSpec {
94 - contextWindow
: number ;
96 - input
: (
"text" | "image" )[];
99 - const KILO_MODELS
: KiloModelSpec []
= [
100 - { id:
"inclusionai/ling-2.6-1t:free" , name:
"Ling 2.6 1t" , contextWindow:
262_144 , maxTokens:
32_768 , input: [
"text" ] },
101 - { id:
"inclusionai/ling-2.6-flash:free" , name:
"Ling 2.6 Flash" , contextWindow:
262_144 , maxTokens:
32_768 , input: [
"text" ] },
102 - { id:
"nvidia/nemotron-3-super-120b-a12b:free" , name:
"Nemotron 3 Super" , contextWindow:
262_144 , maxTokens:
262_144 , input: [
"text" ] },
103 - { id:
"tencent/hy3-preview:free" , name:
"Hy3 Preview" , contextWindow:
262_144 , maxTokens:
262_144 , input: [
"text" ] },
104 - { id:
"kilo-auto/free" , name:
"Kilo Auto" , contextWindow:
256_000 , maxTokens:
10_000 , input: [
"text" ] },
105 - { id:
"openrouter/free" , name:
"OpenRouter Free" , contextWindow:
200_000 , maxTokens:
32_768 , input: [
"text" ] },
106 - { id:
"baidu/qianfan-ocr-fast:free" , name:
"Qianfan OCR Fast" , contextWindow:
65_536 , maxTokens:
28_672 , input: [
"text" ,
"image" ] },
109 - function kiloModels ()
: ProviderModelConfig [] {
110 - return KILO_MODELS.
map ((m)
=> ({
115 - cost: { input:
0 , output:
0 , cacheRead:
0 , cacheWrite:
0 },
116 - contextWindow: m.contextWindow,
117 - maxTokens: m.maxTokens,
119 - maxTokensField:
"max_tokens" ,
120 - supportsStore:
false ,
121 - supportsDeveloperRole:
false ,
122 - supportsReasoningEffort:
false ,
123 - requiresThinkingAsText:
false ,
129 - let liveKiloModels
: ProviderModelConfig []
| null = null ;
131 - interface KiloGatewayModel {
133 - pricing
?: { prompt
?: string ; completion
?: string };
134 - context_length
?: number ;
135 - top_provider
?: { max_completion_tokens
?: number };
136 - architecture
?: { input_modalities
?: string []; output_modalities
?: string [] };
138 - interface KiloGatewayResponse { data
?: KiloGatewayModel []; }
140 - async function fetchKiloModels (signal
?: AbortSignal )
: Promise <
ProviderModelConfig []> {
141 - const res
= await fetch (
"https://api.kilo.ai/api/gateway/models" , { signal });
142 - if (
! res.ok)
throw new Error (
`Kilo returned ${res. status }` );
143 - const data
= (
await res.
json ())
as KiloGatewayResponse ;
145 - return (data.
data ?? [])
146 - .
filter ((m)
=> m.pricing?.
prompt === "0" && m.pricing?.completion
=== "0" )
147 - .
filter ((m)
=> ! m.architecture?.output_modalities?.
includes (
"audio" ))
149 - const ctx
= m.context_length
?? 128_000 ;
150 - const maxTok
= m.top_provider?.max_completion_tokens
?? 32_768 ;
151 - const hasImage
= m.architecture?.input_modalities?.
includes (
"image" )
?? false ;
152 - const name
= (m.
id .
includes (
"/" )
? m.
id .
split (
"/" )[
1 ]
: m.
id )
153 - .
replace (
/:free $ / ,
"" ).
replace (
/-/ g ,
" " )
154 - .
replace (
/ \b \w/ g , (c
: string )
=> c.
toUpperCase ());
159 - input: hasImage
? ([
"text" ,
"image" ]
as const )
: ([
"text" ]
as const ),
160 - cost: { input:
0 , output:
0 , cacheRead:
0 , cacheWrite:
0 },
161 - contextWindow: ctx,
164 - maxTokensField:
"max_tokens" ,
165 - supportsStore:
false ,
166 - supportsDeveloperRole:
false ,
167 - supportsReasoningEffort:
false ,
168 - requiresThinkingAsText:
false ,
176 - function registerKilo (pi
: ExtensionAPI , models
: ProviderModelConfig []) {
177 - pi.
registerProvider (
"free" , {
178 - baseUrl:
"https://api.kilo.ai/api/gateway/v1" ,
181 - api:
"openai-completions" ,
186 - function registerZenAm (pi
: ExtensionAPI , models
: ProviderModelConfig []) {
187 - pi.
registerProvider (
"zen" , {
188 - baseUrl: ZEN_BASE_URL,
191 - api:
"anthropic-messages" ,
196 - function registerZenOc (pi
: ExtensionAPI , models
: ProviderModelConfig []) {
197 - pi.
registerProvider (
"zen-free" , {
198 - baseUrl:
`${ZEN_BASE_URL}/v1` ,
201 - api:
"openai-completions" ,
208 - export default async function freeExtension (pi
: ExtensionAPI ) {
210 - let zenAm
: ProviderModelConfig []
= [];
211 - let zenOc
: ProviderModelConfig []
= [];
213 - const result
= await fetchZenModels ();
217 - console .
warn (
"[free] Zen fetch failed:" , err);
221 - let kilo
= liveKiloModels
?? kiloModels ();
223 - if (kilo.
length === 0 && zenAm.
length === 0 && zenOc.
length === 0 ) {
224 - console .
error (
"[free] No free models available. Check network." );
228 - if (kilo.
length > 0 )
registerKilo (pi, kilo);
229 - if (zenAm.
length > 0 )
registerZenAm (pi, zenAm);
230 - if (zenOc.
length > 0 )
registerZenOc (pi, zenOc);
233 - pi.
on (
"session_start" , (_event, ctx)
=> {
234 - const parts
: string []
= [];
235 - if (kilo.
length > 0 ) parts.
push (
`${kilo. length } Kilo` );
236 - if (zenAm.
length + zenOc.
length > 0 ) parts.
push (
`${zenAm. length + zenOc. length } Zen` );
237 - if (parts.
length > 0 ) {
238 - ctx.ui.
notify (
`free: ${parts. join (" + ")}. /free-refresh to update.` ,
"info" );
243 - pi.
registerCommand (
"free-refresh" , {
244 - description:
"Re-fetch free models from Kilo's gateway and Zen's model list." ,
245 - async handler (_args, ctx) {
247 - const [kiloResult, zenResult]
= await Promise .
allSettled ([
248 - fetchKiloModels (ctx.signal),
249 - fetchZenModels (ctx.signal),
252 - if (kiloResult.
status === "fulfilled" && kiloResult.
value .
length > 0 ) {
253 - registerKilo (pi, kiloResult.
value );
254 - liveKiloModels
= kiloResult.
value ;
255 - kilo
= kiloResult.
value ;
257 - if (zenResult.
status === "fulfilled" ) {
258 - if (zenResult.
value .am.
length > 0 )
registerZenAm (pi, zenResult.
value .am);
259 - if (zenResult.
value .oc.
length > 0 )
registerZenOc (pi, zenResult.
value .oc);
260 - zenAm
= zenResult.
value .am;
261 - zenOc
= zenResult.
value .oc;
264 - const k
= kiloResult.
status === "fulfilled" ? kiloResult.
value .
length : "?" ;
265 - const z
= (zenResult.
status === "fulfilled" ? zenResult.
value .am.
length + zenResult.
value .oc.
length : "?" );
266 - const failed
: string []
= [];
267 - if (kiloResult.
status === "rejected" ) failed.
push (
"Kilo" );
268 - if (zenResult.
status === "rejected" ) failed.
push (
"Zen" );
269 - const note
= failed.
length ? ` (${failed. join (", ")} failed)` : "" ;
270 - ctx.ui.
notify (
`free: ${k} Kilo + ${z} Zen model(s)${note}.` ,
"info" );
272 - ctx.ui.
notify (
`free refresh failed: ${(err as Error ).message}` ,
"error" );
pi/agent/extensions/free/package.json Deleted deleted file mode 100644 2 - "name" :
"@bugabinga/pi-ext-free" ,
7 - "peerDependencies" : {
8 - "@mariozechner/pi-coding-agent" :
"*" pi/agent/extensions/quota/index.ts Modified 8 8 import { readFileSync }
from "node:fs" ;
9 9 import { homedir }
from "node:os" ;
10 10 import { join }
from "node:path" ;
11 - import type { ExtensionAPI, ExtensionContext }
from "@mariozechner/pi-coding-agent" ;
11 + import type { ExtensionAPI, ExtensionContext }
from "@earendil-works/pi-coding-agent" ;
38 + interface KimiUsage {
45 + interface KimiLimit {
46 + window
?: { duration
?: number ; timeUnit
?: string };
50 + interface KimiResponse {
52 + limits
?: KimiLimit [];
53 + totalQuota
?: { limit
: string ; remaining
: string };
126 + async function fetchKimi (key
: string ) {
127 + const r
= await fetch (
"https://api.kimi.com/coding/v1/usages" , {
128 + headers: { Authorization:
`Bearer ${key}` , Accept:
"application/json" },
129 + signal: AbortSignal.
timeout (
10_000 ),
131 + if (
! r.ok)
throw new Error (
`${r. status }` );
132 + return r.
json ()
as Promise <
KimiResponse >;
110 137 function parseDateish (value
: unknown )
: number {
209 + function parseKimi (data
: KimiResponse )
: ProviderUsage {
210 + const usage
= data?.usage;
211 + const uLimit
= Number (usage?.limit
?? 0 );
212 + const uUsed
= Number (usage?.used
?? 0 );
213 + const uReset
= usage?.resetTime
? new Date (usage.resetTime).
getTime ()
: undefined ;
216 + const limits
= data?.limits
?? [];
217 + const firstLimit
= limits[
0 ]?.detail;
218 + const wLimit
= Number (firstLimit?.limit
?? 0 );
219 + const wUsed
= Number (firstLimit?.used
?? 0 );
220 + const wReset
= firstLimit?.resetTime
? new Date (firstLimit.resetTime).
getTime ()
: undefined ;
224 + fiveH: { used: wUsed, total: wLimit, remaining: wLimit
- wUsed, resetAt: wReset },
225 + weekly: { used: uUsed, total: uLimit, remaining: uLimit
- uUsed, resetAt: uReset },
184 231 function bar (pct
: number , w
= 15 )
: string {
213 260 "openai-codex" :
"OpenAI Codex" ,
214 261 minimax :
"MiniMax" ,
263 + "kimi-coding" :
"Kimi" ,
218 266 function emptyProvider (name
: string )
: ProviderUsage {
265 313 catch { results.
push (
emptyProvider (
"Zai" )); }
317 + const kimiKey
= await ctx.modelRegistry.
getApiKeyForProvider (
"kimi-coding" );
319 + try { results.
push (
parseKimi (
await fetchKimi (kimiKey))); }
320 + catch { results.
push (
emptyProvider (
"Kimi" )); }
268 323 providers
= results;
269 324 fetchedAt
= Date .
now ();
pi/agent/extensions/quota/package.json Modified 7 7 "peerDependencies" : {
8 - "@mariozechner/pi-coding-agent" :
"*" 8 + "@earendil-works/pi-coding-agent" :
"*" pi/agent/models.json Modified 4 - "baseUrl" :
"https://api.minimax.io/anthropic" ,
5 - "api" :
"anthropic-messages" ,
8 - "id" :
"MiniMax-M2.5-highspeed" ,
9 - "name" :
"MiniMax-M2.5-highspeed" ,
14 - "contextWindow" :
204800 ,
4 + "baseUrl" :
"https://api.minimax.io/anthropic" ,
5 + "api" :
"anthropic-messages" ,
8 + "id" :
"MiniMax-M2.5-highspeed" ,
9 + "name" :
"MiniMax-M2.5-highspeed" ,
14 + "contextWindow" :
204800 ,
pi/agent/prompts/brainstorm.md Modified 12 12 1. **Read Context** - Load AGENTS.md and explore code base
13 13 2. **Diverge** - Generate many ideas wildly
14 - 3. **Challenge** - Consult with the devil to find flaws
14 + 3. **Challenge** - Consult subagent (pi --print) to find flaws
15 15 4. **Defend** - Strengthen surviving ideas
16 16 5. **Converge** - Pick best recommendations
pi/agent/settings.json Modified 9 9 "openai-codex/gpt-5.5" ,
10 - "free/inclusionai/ling-2.6-1t:free" ,
11 - "free/tencent/hy3-preview:free" 10 + "kimi-coding/kimi-for-coding" 13 12 "defaultProvider" :
"openai-codex" ,
14 13 "defaultModel" :
"gpt-5.5" ,
42 49 "git:github.com/pasky/chrome-cdp-skill" 45 - "cooldownMs" :
300000 ,
49 - "MINIMAX_WORK_API_KEY" 60 52 "model" :
"minimax/MiniMax-M2.5-highspeed"