opencode-peak-badge 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +169 -326
- package/dist/core.d.ts +25 -8
- package/dist/gui-experimental.cjs +2 -0
- package/dist/rpc.d.ts +298 -0
- package/dist/server.d.ts +3 -0
- package/dist/server.js +152 -0
- package/dist/server.js.map +13 -0
- package/dist/settings-client.d.ts +29 -0
- package/dist/settings.d.ts +65 -0
- package/dist/tui-settings.d.ts +15 -0
- package/dist/tui.d.ts +2 -1
- package/dist/tui.js +804 -68
- package/dist/tui.js.map +9 -5
- package/package.json +29 -18
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("solid-js/web"),w=require("@opencode/plugin/gui"),p=require("solid-js"),me=require("@opencode/plugin/rpc"),ee=[["01:00","04:00"],["06:00","10:00"]],te=["re:^opencode-go/deepseek","re:^opencode/deepseek","re:^deepseek/deepseek"];function $(e,t=new Date){if(e){const n=new Date(e);if(!Number.isNaN(n.getTime()))return n}return t}function D(e){const t=/^(\d{1,2}):(\d{2})$/.exec(e.trim());if(!t)return;const n=Number(t[1]),r=Number(t[2]);if(!(n>23||r>59))return n*60+r}function we(e){const t=D(e[0]),n=D(e[1]);if(!(t===void 0||n===void 0))return{start:t,end:n}}function x(e){const t=[];for(const n of e){const r=we(n);r&&t.push(r)}return t}function he(e,t){return t.end<=t.start?e>=t.start||e<t.end:e>=t.start&&e<t.end}function ye(e,t,n=!0){if(n){const s=e.getUTCDay();if(s===0||s===6)return!1}const r=e.getUTCHours()*60+e.getUTCMinutes();return t.some(s=>he(r,s))}function j(e,t){return`${e}/${t}`.trim().toLowerCase()}function V(e,t,n,r){return{id:e,windows:t.windows?.length?x(t.windows):n,weekdaysOnly:t.weekdaysOnly??r}}function ne(e={}){const t=x(e.windows??ee),n=e.weekdaysOnly??!0,r=e.models??te,s=new Map,l=[];for(const f of r)if(typeof f=="string"){const g=f.trim();if(!g)continue;if(g.toLowerCase().startsWith("re:")){const d=g.slice(3);if(!d.trim())continue;const a=J(d);if(!a)continue;l.push({id:d,regex:a,windows:t,weekdaysOnly:n})}else{const d=g.toLowerCase();s.set(d,V(d,{},t,n))}}else if("pattern"in f){const g=f.pattern;if(!g.trim())continue;const d=J(g);if(!d)continue;l.push({id:g,regex:d,windows:f.windows?.length?x(f.windows):t,weekdaysOnly:f.weekdaysOnly??n})}else{const g=f.id.trim().toLowerCase();if(!g)continue;s.set(g,V(g,f,t,n))}return{exact:s,patterns:l,fallback:{id:"",windows:t,weekdaysOnly:n}}}function be(e){const t=ne({models:[e]});return t.exact.size>0||t.patterns.length>0}function ke(e){let t=0,n=!1;for(let r=0;r<e.length;r++){const s=e[r];if(s==="\\"){r++;continue}if(s==="["){n=!0;continue}if(s==="]"){n=!1;continue}if(!n){if(s==="(")t++;else if(s===")")t=Math.max(0,t-1);else if(t>0&&"+*}".includes(s))return!1}}return!0}function J(e){try{return ke(e)?new RegExp(e,"i"):void 0}catch{return}}function q(e,t){const n=e.exact.get(t);if(n)return n;for(const r of e.patterns)if(r.regex.test(t))return r}function G(e,t,n){if(!t)return;const r=ye(e,t.windows,t.weekdaysOnly);return{label:r?n.peak:n.offPeak,peak:r}}function ve(e){let t;for(const n of e)if(n){if(!t){t=n;continue}n.peak&&!t.peak&&(t=n)}return t}function Z(e){const t=[];if(e.main){const n=q(e.rules,j(e.main.providerID,e.main.id))??(e.alwaysShow?e.rules.fallback:void 0),r=G(e.now,n,e.labels);r&&t.push(r)}for(const n of e.subagents){const r=G(e.now,q(e.rules,j(n.providerID,n.id)),e.labels);r&&t.push(r)}return ve(t)}function Se(e){const t=[],n=new Set,r=[...e.family(e.sessionID)];for(;r.length>0;){const s=r.pop();if(!(!s||n.has(s))){if(n.add(s),e.status(s)==="running"){const l=e.model(s);l&&t.push(l)}for(const l of e.family(s))n.has(l)||r.push(l)}}return t}const Ce={type:"object",properties:{models:{type:"array",items:{type:"string"}},windows:{type:"array",items:{type:"array",items:{type:"string"},minItems:2,maxItems:2}},weekdaysOnly:{type:"boolean"},pollSeconds:{type:"string"},labelPeak:{type:"string"},labelOffPeak:{type:"string"},subagents:{type:"boolean"},alwaysShow:{type:"boolean"},debug:{type:"boolean"},fakeTime:{type:"string"}},additionalProperties:!1},P={type:"object",properties:{settings:Ce},required:["settings"],additionalProperties:!1},Q={type:"object",additionalProperties:!1},Pe=me.Rpc.define({id:"peak-badge.settings",methods:{get:{input:Q,output:P},set:{input:P,output:P},reset:{input:Q,output:P}},events:{updated:{schema:P}}}),ie=10,E={models:Re(te),windows:ee.map(([e,t])=>[e,t]),weekdaysOnly:!0,pollSeconds:String(ie),labelPeak:"[PEAK]",labelOffPeak:"[OFF-PEAK]",subagents:!0,alwaysShow:!1,debug:!1,fakeTime:""};function Oe(){return{...E,models:[...E.models],windows:E.windows.map(([e,t])=>[e,t])}}function L(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Te(e){return Array.isArray(e)&&e.length===2&&typeof e[0]=="string"&&typeof e[1]=="string"}function re(e){return Array.isArray(e)&&e.every(Te)}function C(e){const t=Oe();return L(e)&&(Array.isArray(e.models)&&e.models.every(n=>typeof n=="string")&&(t.models=[...e.models]),re(e.windows)&&(t.windows=e.windows.map(([n,r])=>[n,r])),typeof e.weekdaysOnly=="boolean"&&(t.weekdaysOnly=e.weekdaysOnly),typeof e.pollSeconds=="string"&&(t.pollSeconds=e.pollSeconds),typeof e.labelPeak=="string"&&(t.labelPeak=e.labelPeak),typeof e.labelOffPeak=="string"&&(t.labelOffPeak=e.labelOffPeak),typeof e.subagents=="boolean"&&(t.subagents=e.subagents),typeof e.alwaysShow=="boolean"&&(t.alwaysShow=e.alwaysShow),typeof e.debug=="boolean"&&(t.debug=e.debug),typeof e.fakeTime=="string"&&(t.fakeTime=e.fakeTime)),t}function O(e){return C(L(e)?e.settings:void 0)}function Ie(e){const t=Number(e.pollSeconds);return{rules:ne({models:Me(e.models),windows:e.windows,weekdaysOnly:e.weekdaysOnly}),labels:{peak:e.labelPeak,offPeak:e.labelOffPeak},pollSeconds:Number.isFinite(t)&&t>=1?t:ie,subagents:e.subagents,alwaysShow:e.alwaysShow,debug:e.debug,fakeTime:e.fakeTime.trim()||void 0}}function Re(e){return e.map(t=>typeof t=="string"?t:JSON.stringify(t))}function oe(e){const t=e.trim();if(!t)return;if(!t.startsWith("{")&&!t.startsWith("["))return t;let n;try{n=JSON.parse(t)}catch{return}if(!L(n))return;const r=typeof n.pattern=="string"&&n.pattern.trim()?n.pattern.trim():void 0,s=typeof n.id=="string"&&n.id.trim()?n.id.trim():void 0;if(!r&&!s)return;let l;if(n.windows!==void 0){if(!re(n.windows))return;l=n.windows.map(([d,a])=>[d,a])}if(n.weekdaysOnly!==void 0&&typeof n.weekdaysOnly!="boolean")return;const f=typeof n.weekdaysOnly=="boolean"?n.weekdaysOnly:void 0;return r?{pattern:r,...l!==void 0?{windows:l}:{},...f!==void 0?{weekdaysOnly:f}:{}}:{id:s,...l!==void 0?{windows:l}:{},...f!==void 0?{weekdaysOnly:f}:{}}}function Me(e){const t=[];for(const n of e){const r=oe(n);r!==void 0&&t.push(r)}return t}function I(e){return D(e)!==void 0}function _e(e){return I(e[0])&&I(e[1])}function $e(e){const t=oe(e);return!(t===void 0||!be(t)||typeof t=="object"&&t.windows&&!t.windows.every(_e))}function Ee(e){const t=Number(e);return e.trim()!==""&&Number.isFinite(t)&&t>=1}function Ae(e){return e.trim()?!Number.isNaN(new Date(e).getTime()):!0}function T(e){return e instanceof Error?e.message:String(e)}function De(e){let t,n=!1;function r(){const d=e.client();if(typeof d.rpc=="function")return d.rpc(Pe)}async function s(d=!1){const a=r();if(a)try{const u=O(await a.get({}));if(n||!d&&e.canApply&&!e.canApply(u))return;e.set(u)}catch(u){n||e.onLoadError?.(T(u))}}function l(){n=!1,t?.(),t=void 0;const d=r();if(d)try{t=d.events.on("updated",a=>{if(n)return;const u=O(a.data);if(e.acceptEvent){if(!e.acceptEvent(u))return}else if(e.canApply&&!e.canApply(u))return;n||e.set(u)})}catch(a){e.onLoadError?.(T(a))}s()}async function f(d){const a=C(d);e.set(a);const u=r();if(u)try{const h=O(await u.set({settings:a}));n||e.set(h)}catch(h){if(n)return;e.onSaveError?.(T(h)),await s(!0)}}async function g(){const d=r();if(!d){e.set(C(void 0));return}try{const a=O(await d.reset({}));n||e.set(a)}catch(a){if(n)return;e.onSaveError?.(T(a)),await s(!0)}}return{connect:l,refresh:s,save:f,reset:g,stop:()=>{n=!0,t?.(),t=void 0}}}var xe=i.template("<div style=display:grid;gap:8px;width:360px;max-width:100%><div>"),Le=i.template("<div style=display:flex;gap:6px;align-items:center><div style=width:88px></div><span>to</span><div style=width:88px>"),We=i.template("<div style=display:grid;gap:8px;width:400px;max-width:100%><div>"),Be=i.template('<div style=display:flex;gap:6px;align-items:center><div style="flex:1 1 auto;min-width:160px;max-width:360px">'),X=i.template("<div style=width:200px>"),Ne=i.template("<div style=width:100px>"),Fe=i.template("<div style=width:280px;max-width:100%>");function Ue(e){const t=w.usePlugin().ui;function n(a){const u={...e.settings()};a(u),e.save(u)}function r(a,u,h){n(y=>{y.windows=y.windows.map((b,R)=>R!==a?b:u===0?[h,b[1]]:[b[0],h])})}function s(){n(a=>{const u=["",""];a.windows=[...a.windows,u]})}function l(a){n(u=>{u.windows=u.windows.filter((h,y)=>y!==a)})}function f(a,u){n(h=>{h.models=h.models.map((y,b)=>b===a?u:y)})}function g(){n(a=>{a.models=[...a.models,""]})}function d(a){n(u=>{u.models=u.models.filter((h,y)=>y!==a)})}return i.createComponent(t.SettingsLayout,{title:"Peak Badge",description:"Shared with the TUI. Settings are stored on this server and apply live.",get children(){return[i.createComponent(He,{get error(){return e.error},get refresh(){return e.refresh}}),i.createComponent(ze,{get settings(){return e.settings},update:n,patchWindow:r,addWindow:s,removeWindow:l}),i.createComponent(Ke,{get settings(){return e.settings},update:n,patchModel:f,addModel:g,removeModel:d}),i.createComponent(je,{get settings(){return e.settings},update:n}),i.createComponent(Ve,{get settings(){return e.settings},update:n}),i.createComponent(Je,{get settings(){return e.settings},update:n}),i.createComponent(qe,{get reset(){return e.reset}})]}})}function He(e){const t=w.usePlugin().ui;return i.createComponent(p.Show,{get when(){return e.error()},children:n=>i.createComponent(t.SettingsSection,{title:"Connection",get children(){return i.createComponent(t.SettingsRow,{title:"Shared settings unavailable",get description(){return n()},get children(){return i.createComponent(t.Button,{size:"small",get onClick(){return e.refresh},children:"Retry"})}})}})})}function ze(e){const t=w.usePlugin().ui;return i.createComponent(t.SettingsSection,{title:"Peak hours",get children(){return[i.createComponent(t.SettingsRow,{id:"peak-badge-windows",title:"Peak windows (UTC)",description:"Half-open; an end at or before the start wraps midnight. An empty list means no peak hours.",get children(){var n=xe(),r=n.firstChild;return i.insert(n,i.createComponent(p.Index,{get each(){return e.settings().windows},children:(s,l)=>(()=>{var f=Le(),g=f.firstChild,d=g.nextSibling,a=d.nextSibling;return i.insert(g,i.createComponent(t.TextInput,{label:`Window ${l+1} start`,get value(){return s()[0]},get invalid(){return!I(s()[0])},onInput:u=>e.patchWindow(l,0,u)})),i.insert(a,i.createComponent(t.TextInput,{label:`Window ${l+1} end`,get value(){return s()[1]},get invalid(){return!I(s()[1])},onInput:u=>e.patchWindow(l,1,u)})),i.insert(f,i.createComponent(t.IconButton,{icon:"trash",label:`Remove window ${l+1}`,onClick:()=>e.removeWindow(l)}),null),f})()}),r),i.insert(r,i.createComponent(t.Button,{size:"small",icon:"plus",get onClick(){return e.addWindow},children:"Add window"})),n}}),i.createComponent(t.SettingsRow,{id:"peak-badge-weekdays",title:"Weekdays only",description:"Weekends are always off-peak.",get children(){return i.createComponent(t.Switch,{label:"Weekdays only",hideLabel:!0,get checked(){return e.settings().weekdaysOnly},onChange:n=>e.update(r=>{r.weekdaysOnly=n})})}})]}})}function Ke(e){const t=w.usePlugin().ui;return i.createComponent(t.SettingsSection,{title:"Models",get children(){return[i.createComponent(t.SettingsRow,{id:"peak-badge-models",title:"Models",description:"One per row: provider/model, re:pattern, or a JSON object with id/pattern and optional windows/weekdaysOnly. Replaces the default list.",get children(){var n=We(),r=n.firstChild;return i.insert(n,i.createComponent(p.Index,{get each(){return e.settings().models},children:(s,l)=>(()=>{var f=Be(),g=f.firstChild;return i.insert(g,i.createComponent(t.TextInput,{label:`Model ${l+1}`,get value(){return s()},get invalid(){return!$e(s())},placeholder:"provider/model or re:pattern",onInput:d=>e.patchModel(l,d)})),i.insert(f,i.createComponent(t.IconButton,{icon:"trash",label:`Remove model ${l+1}`,onClick:()=>e.removeModel(l)}),null),f})()}),r),i.insert(r,i.createComponent(t.Button,{size:"small",icon:"plus",get onClick(){return e.addModel},children:"Add model"})),n}}),i.createComponent(t.SettingsRow,{id:"peak-badge-subagents",title:"Include subagents",description:"Running subagent sessions can make the parent badge peak.",get children(){return i.createComponent(t.Switch,{label:"Include subagents",hideLabel:!0,get checked(){return e.settings().subagents},onChange:n=>e.update(r=>{r.subagents=n})})}}),i.createComponent(t.SettingsRow,{id:"peak-badge-always-show",title:"Show unmatched models",description:"Show the main model even when it does not match a tracked model, using the top-level windows.",get children(){return i.createComponent(t.Switch,{label:"Show unmatched models",hideLabel:!0,get checked(){return e.settings().alwaysShow},onChange:n=>e.update(r=>{r.alwaysShow=n})})}})]}})}function je(e){const t=w.usePlugin().ui;return i.createComponent(t.SettingsSection,{title:"Badge",get children(){return[i.createComponent(t.SettingsRow,{id:"peak-badge-label-peak",title:"Peak label",description:"Text shown when the model is in peak hours.",get children(){var n=X();return i.insert(n,i.createComponent(t.TextInput,{label:"Peak label",get value(){return e.settings().labelPeak},onInput:r=>e.update(s=>{s.labelPeak=r})})),n}}),i.createComponent(t.SettingsRow,{id:"peak-badge-label-off",title:"Off-peak label",description:"Text shown when the model is outside peak hours.",get children(){var n=X();return i.insert(n,i.createComponent(t.TextInput,{label:"Off-peak label",get value(){return e.settings().labelOffPeak},onInput:r=>e.update(s=>{s.labelOffPeak=r})})),n}}),i.createComponent(t.SettingsRow,{id:"peak-badge-debug",title:"Debug",description:"Append provider/model to the badge.",get children(){return i.createComponent(t.Switch,{label:"Debug",hideLabel:!0,get checked(){return e.settings().debug},onChange:n=>e.update(r=>{r.debug=n})})}})]}})}function Ve(e){const t=w.usePlugin().ui;return i.createComponent(t.SettingsSection,{title:"Refresh",get children(){return i.createComponent(t.SettingsRow,{id:"peak-badge-poll",title:"Poll seconds",description:"Seconds between recomputations; at least 1. Invalid values fall back to 10.",get children(){var n=Ne();return i.insert(n,i.createComponent(t.TextInput,{label:"Poll seconds",get value(){return e.settings().pollSeconds},get invalid(){return!Ee(e.settings().pollSeconds)},onInput:r=>e.update(s=>{s.pollSeconds=r})})),n}})}})}function Je(e){const t=w.usePlugin().ui;return i.createComponent(t.SettingsSection,{title:"Advanced",get children(){return i.createComponent(t.SettingsRow,{id:"peak-badge-fake-time",title:"Fake time",description:"Fixed ISO timestamp for testing. Empty uses the real clock.",get children(){var n=Fe();return i.insert(n,i.createComponent(t.TextInput,{label:"Fake time",get value(){return e.settings().fakeTime},get invalid(){return!Ae(e.settings().fakeTime)},placeholder:"2026-09-07T08:30:00Z",onInput:r=>e.update(s=>{s.fakeTime=r})})),n}})}})}function qe(e){const t=w.usePlugin().ui;return i.createComponent(t.SettingsSection,{title:"Reset",get children(){return i.createComponent(t.SettingsRow,{id:"peak-badge-reset",title:"Reset to defaults",description:"Restore the built-in peak windows, models, labels and flags for both the TUI and Desktop.",get children(){return i.createComponent(t.Button,{size:"small",get onClick(){return e.reset},children:"Reset"})}})}})}var Y=i.template("<span>");const Ge={display:"inline-flex","align-items":"center",gap:"4px","font-size":"11px","font-weight":"600","letter-spacing":"0.02em","white-space":"nowrap"},Ze="var(--v2-orange-1000, #954c27)",Qe="var(--v2-orange-600, #ff8648)";function Xe(e){return e==="dark"?Qe:Ze}function A(e){return e?.providerID&&e.id?{providerID:e.providerID,id:e.id}:void 0}function Ye(e){return e?{providerID:e.providerID,id:e.modelID}:void 0}const et=200,tt=w.Plugin.define({setup(e){const[t,n]=p.createSignal(C(void 0)),[r,s]=p.createSignal(),l=p.createMemo(()=>Ie(t())),f=p.createMemo(()=>l().pollSeconds),g=p.createMemo(()=>l().fakeTime);let d,a=0,u=Promise.resolve(),h=!1,y=!1;const b=De({client:()=>e.client,set:o=>{n(o),s(void 0)},canApply:()=>d===void 0&&a===0,acceptEvent:o=>JSON.stringify(o)===JSON.stringify(t())?!1:d!==void 0||a>0?(y=!0,!1):!0,onLoadError:o=>s(o),onSaveError:o=>{s(o),e.toast.show({title:"Peak Badge settings",description:"Could not save the shared settings. Showing the server's values.",variant:"error"})}});b.connect();function R(o){const c=C(o);n(c),clearTimeout(d),d=setTimeout(()=>{d=void 0,a+=1,u=u.then(()=>b.save(c)).finally(()=>{a-=1,a===0&&d===void 0&&y&&(y=!1,b.refresh())})},et)}function se(){h||(clearTimeout(d),d=void 0,h=!0,n(C(void 0)),u=u.then(()=>b.reset()).finally(()=>{h=!1,a===0&&d===void 0&&y&&(y=!1,b.refresh())}))}const[W,B]=p.createSignal($(g()).getTime()),[ae,de]=p.createSignal(void 0),M=new Set;function N(o,c,m){M.has(c)||(M.add(c),o.sync(m).catch(()=>M.delete(c)))}function F(o){const c=l().debug&&o.model?`${o.model.providerID}/${o.model.id}`:"";return[o.state?.label??"",c].filter(Boolean).join(" ")}function U(o){return o?.peak?Xe(e.appearance.mode()):void 0}function le(o){const c=o.active===!1?void 0:Ye(o.screen.composer.model());if(c)return c;const m=o.session.server.data.session,k=A(m.get(o.session.id)?.model);return k||N(m,o.session.key,o.session.id),k}function ce(o,c){const m=o.session.server.data.session,k=A(m.get(c)?.model);return k||N(m,`${o.session.server.id}
|
|
2
|
+
${c}`,c),k}function ue(o){const c=l(),m=le(o),k=c.subagents?Se({sessionID:o.session.id,family:S=>o.session.server.data.session.family(S),status:S=>o.session.server.data.session.status(S),model:S=>ce(o,S)}):[];return{state:Z({now:new Date(W()),rules:c.rules,labels:c.labels,main:m,subagents:k,alwaysShow:c.alwaysShow}),model:m}}function fe(o){const c=p.createMemo(()=>ue(o.input));return i.createComponent(p.Show,{get when(){return F(c())},children:m=>(()=>{var k=Y();return i.insert(k,i.createComponent(p.Show,{get when(){return c().state},children:v=>i.createComponent(p.Show,{get when(){return v().peak},get fallback(){return i.createComponent(e.ui.Icon,{name:"circle-check",size:"small"})},get children(){return i.createComponent(e.ui.Icon,{name:"warning",size:"small"})}})}),null),i.insert(k,i.createComponent(p.Show,{get when(){return!o.input.compact},get children(){return m()}}),null),i.effect(v=>{var S={...Ge,color:U(c().state)},z=m(),K=o.input.compact?m():void 0;return v.e=i.style(k,S,v.e),z!==v.t&&i.setAttribute(k,"title",v.t=z),K!==v.a&&i.setAttribute(k,"aria-label",v.a=K),v},{e:void 0,t:void 0,a:void 0}),k})()})}const H=p.createMemo(()=>{const o=l(),c=ae();return{state:Z({now:new Date(W()),rules:o.rules,labels:o.labels,main:c,subagents:[],alwaysShow:o.alwaysShow}),model:c}});function ge(){return i.createComponent(p.Show,{get when(){return F(H())},children:o=>(()=>{var c=Y();return i.insert(c,o),i.effect(m=>i.setStyleProperty(c,"color",U(H().state))),c})()})}async function _(){try{const o=await e.client.model.default();de(A(o.data))}catch{}}_();function pe(){try{for(const o of e.servers.list()){const c=e.servers.get(o);if(c?.builtin)return c.data}}catch{}}return w.createKeyed(()=>pe(),o=>{p.onCleanup(o.on("model.updated",()=>{_()})),p.onCleanup(o.on("server.connected",()=>b.connect()))}),w.createKeyed(()=>f(),o=>{const c=setInterval(()=>{B($(g()).getTime()),e.sessions.current()||_()},o*1e3);p.onCleanup(()=>clearInterval(c))}),w.createKeyed(()=>g(),o=>B($(o).getTime())),e.add(w.SettingsPage,{id:"peak-badge",icon:"sliders",get title(){return"Peak Badge"},get entries(){return[{id:"peak-badge",title:"Peak Badge",description:"Peak hours, models and badge settings",keywords:"peak off-peak deepseek"},{id:"peak-badge-windows",title:"Peak windows",description:"UTC windows when the badge is peak"},{id:"peak-badge-weekdays",title:"Weekdays only",description:"Weekends are off-peak"},{id:"peak-badge-models",title:"Models",description:"Tracked model ids and patterns"},{id:"peak-badge-subagents",title:"Include subagents",description:"Running subagents can make the parent peak"},{id:"peak-badge-always-show",title:"Show unmatched models",description:"Badge the main model without a matching rule"},{id:"peak-badge-label-peak",title:"Peak label",description:"Text shown when peak"},{id:"peak-badge-label-off",title:"Off-peak label",description:"Text shown when off-peak"},{id:"peak-badge-debug",title:"Debug",description:"Append provider/model to the badge"},{id:"peak-badge-poll",title:"Poll seconds",description:"Badge recompute interval"},{id:"peak-badge-fake-time",title:"Fake time",description:"Fixed time for testing"},{id:"peak-badge-reset",title:"Reset to defaults",description:"Restore the built-in settings"}]},render:()=>i.createComponent(Ue,{settings:t,save:R,reset:se,refresh:()=>{b.refresh(!0)},error:r})}),e.add(w.Command,()=>({id:"settings",title:"Peak Badge settings",description:"Peak windows, models, labels and refresh",group:"Peak Badge",run:()=>e.layout.settings("peak-badge")})),e.add(w.Slot,{at:"session.header",order:100,render:o=>i.createComponent(fe,{input:o})}),e.add(w.Slot,{at:"window.bottom",order:10,render:()=>i.createComponent(p.Show,{get when(){return!e.sessions.current()},get children(){return i.createComponent(ge,{})}})}),()=>{b.stop(),clearTimeout(d)}}});exports.default=tt;
|
package/dist/rpc.d.ts
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shared settings RPC. `get` returns the defaults when nothing is stored;
|
|
3
|
+
* `set` replaces the full object; `reset` removes the stored value. `updated`
|
|
4
|
+
* reaches every open TUI and desktop window so both badges follow the change.
|
|
5
|
+
*/
|
|
6
|
+
export declare const PeakBadgeSettingsRpc: {
|
|
7
|
+
readonly id: "peak-badge.settings";
|
|
8
|
+
readonly methods: {
|
|
9
|
+
readonly get: {
|
|
10
|
+
readonly input: {
|
|
11
|
+
readonly type: "object";
|
|
12
|
+
readonly additionalProperties: false;
|
|
13
|
+
};
|
|
14
|
+
readonly output: {
|
|
15
|
+
readonly type: "object";
|
|
16
|
+
readonly properties: {
|
|
17
|
+
readonly settings: {
|
|
18
|
+
readonly type: "object";
|
|
19
|
+
readonly properties: {
|
|
20
|
+
readonly models: {
|
|
21
|
+
readonly type: "array";
|
|
22
|
+
readonly items: {
|
|
23
|
+
readonly type: "string";
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
readonly windows: {
|
|
27
|
+
readonly type: "array";
|
|
28
|
+
readonly items: {
|
|
29
|
+
readonly type: "array";
|
|
30
|
+
readonly items: {
|
|
31
|
+
readonly type: "string";
|
|
32
|
+
};
|
|
33
|
+
readonly minItems: 2;
|
|
34
|
+
readonly maxItems: 2;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
readonly weekdaysOnly: {
|
|
38
|
+
readonly type: "boolean";
|
|
39
|
+
};
|
|
40
|
+
readonly pollSeconds: {
|
|
41
|
+
readonly type: "string";
|
|
42
|
+
};
|
|
43
|
+
readonly labelPeak: {
|
|
44
|
+
readonly type: "string";
|
|
45
|
+
};
|
|
46
|
+
readonly labelOffPeak: {
|
|
47
|
+
readonly type: "string";
|
|
48
|
+
};
|
|
49
|
+
readonly subagents: {
|
|
50
|
+
readonly type: "boolean";
|
|
51
|
+
};
|
|
52
|
+
readonly alwaysShow: {
|
|
53
|
+
readonly type: "boolean";
|
|
54
|
+
};
|
|
55
|
+
readonly debug: {
|
|
56
|
+
readonly type: "boolean";
|
|
57
|
+
};
|
|
58
|
+
readonly fakeTime: {
|
|
59
|
+
readonly type: "string";
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
readonly additionalProperties: false;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
readonly required: readonly ["settings"];
|
|
66
|
+
readonly additionalProperties: false;
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
readonly set: {
|
|
70
|
+
readonly input: {
|
|
71
|
+
readonly type: "object";
|
|
72
|
+
readonly properties: {
|
|
73
|
+
readonly settings: {
|
|
74
|
+
readonly type: "object";
|
|
75
|
+
readonly properties: {
|
|
76
|
+
readonly models: {
|
|
77
|
+
readonly type: "array";
|
|
78
|
+
readonly items: {
|
|
79
|
+
readonly type: "string";
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
readonly windows: {
|
|
83
|
+
readonly type: "array";
|
|
84
|
+
readonly items: {
|
|
85
|
+
readonly type: "array";
|
|
86
|
+
readonly items: {
|
|
87
|
+
readonly type: "string";
|
|
88
|
+
};
|
|
89
|
+
readonly minItems: 2;
|
|
90
|
+
readonly maxItems: 2;
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
readonly weekdaysOnly: {
|
|
94
|
+
readonly type: "boolean";
|
|
95
|
+
};
|
|
96
|
+
readonly pollSeconds: {
|
|
97
|
+
readonly type: "string";
|
|
98
|
+
};
|
|
99
|
+
readonly labelPeak: {
|
|
100
|
+
readonly type: "string";
|
|
101
|
+
};
|
|
102
|
+
readonly labelOffPeak: {
|
|
103
|
+
readonly type: "string";
|
|
104
|
+
};
|
|
105
|
+
readonly subagents: {
|
|
106
|
+
readonly type: "boolean";
|
|
107
|
+
};
|
|
108
|
+
readonly alwaysShow: {
|
|
109
|
+
readonly type: "boolean";
|
|
110
|
+
};
|
|
111
|
+
readonly debug: {
|
|
112
|
+
readonly type: "boolean";
|
|
113
|
+
};
|
|
114
|
+
readonly fakeTime: {
|
|
115
|
+
readonly type: "string";
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
readonly additionalProperties: false;
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
readonly required: readonly ["settings"];
|
|
122
|
+
readonly additionalProperties: false;
|
|
123
|
+
};
|
|
124
|
+
readonly output: {
|
|
125
|
+
readonly type: "object";
|
|
126
|
+
readonly properties: {
|
|
127
|
+
readonly settings: {
|
|
128
|
+
readonly type: "object";
|
|
129
|
+
readonly properties: {
|
|
130
|
+
readonly models: {
|
|
131
|
+
readonly type: "array";
|
|
132
|
+
readonly items: {
|
|
133
|
+
readonly type: "string";
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
readonly windows: {
|
|
137
|
+
readonly type: "array";
|
|
138
|
+
readonly items: {
|
|
139
|
+
readonly type: "array";
|
|
140
|
+
readonly items: {
|
|
141
|
+
readonly type: "string";
|
|
142
|
+
};
|
|
143
|
+
readonly minItems: 2;
|
|
144
|
+
readonly maxItems: 2;
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
readonly weekdaysOnly: {
|
|
148
|
+
readonly type: "boolean";
|
|
149
|
+
};
|
|
150
|
+
readonly pollSeconds: {
|
|
151
|
+
readonly type: "string";
|
|
152
|
+
};
|
|
153
|
+
readonly labelPeak: {
|
|
154
|
+
readonly type: "string";
|
|
155
|
+
};
|
|
156
|
+
readonly labelOffPeak: {
|
|
157
|
+
readonly type: "string";
|
|
158
|
+
};
|
|
159
|
+
readonly subagents: {
|
|
160
|
+
readonly type: "boolean";
|
|
161
|
+
};
|
|
162
|
+
readonly alwaysShow: {
|
|
163
|
+
readonly type: "boolean";
|
|
164
|
+
};
|
|
165
|
+
readonly debug: {
|
|
166
|
+
readonly type: "boolean";
|
|
167
|
+
};
|
|
168
|
+
readonly fakeTime: {
|
|
169
|
+
readonly type: "string";
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
readonly additionalProperties: false;
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
readonly required: readonly ["settings"];
|
|
176
|
+
readonly additionalProperties: false;
|
|
177
|
+
};
|
|
178
|
+
};
|
|
179
|
+
readonly reset: {
|
|
180
|
+
readonly input: {
|
|
181
|
+
readonly type: "object";
|
|
182
|
+
readonly additionalProperties: false;
|
|
183
|
+
};
|
|
184
|
+
readonly output: {
|
|
185
|
+
readonly type: "object";
|
|
186
|
+
readonly properties: {
|
|
187
|
+
readonly settings: {
|
|
188
|
+
readonly type: "object";
|
|
189
|
+
readonly properties: {
|
|
190
|
+
readonly models: {
|
|
191
|
+
readonly type: "array";
|
|
192
|
+
readonly items: {
|
|
193
|
+
readonly type: "string";
|
|
194
|
+
};
|
|
195
|
+
};
|
|
196
|
+
readonly windows: {
|
|
197
|
+
readonly type: "array";
|
|
198
|
+
readonly items: {
|
|
199
|
+
readonly type: "array";
|
|
200
|
+
readonly items: {
|
|
201
|
+
readonly type: "string";
|
|
202
|
+
};
|
|
203
|
+
readonly minItems: 2;
|
|
204
|
+
readonly maxItems: 2;
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
readonly weekdaysOnly: {
|
|
208
|
+
readonly type: "boolean";
|
|
209
|
+
};
|
|
210
|
+
readonly pollSeconds: {
|
|
211
|
+
readonly type: "string";
|
|
212
|
+
};
|
|
213
|
+
readonly labelPeak: {
|
|
214
|
+
readonly type: "string";
|
|
215
|
+
};
|
|
216
|
+
readonly labelOffPeak: {
|
|
217
|
+
readonly type: "string";
|
|
218
|
+
};
|
|
219
|
+
readonly subagents: {
|
|
220
|
+
readonly type: "boolean";
|
|
221
|
+
};
|
|
222
|
+
readonly alwaysShow: {
|
|
223
|
+
readonly type: "boolean";
|
|
224
|
+
};
|
|
225
|
+
readonly debug: {
|
|
226
|
+
readonly type: "boolean";
|
|
227
|
+
};
|
|
228
|
+
readonly fakeTime: {
|
|
229
|
+
readonly type: "string";
|
|
230
|
+
};
|
|
231
|
+
};
|
|
232
|
+
readonly additionalProperties: false;
|
|
233
|
+
};
|
|
234
|
+
};
|
|
235
|
+
readonly required: readonly ["settings"];
|
|
236
|
+
readonly additionalProperties: false;
|
|
237
|
+
};
|
|
238
|
+
};
|
|
239
|
+
};
|
|
240
|
+
readonly events: {
|
|
241
|
+
readonly updated: {
|
|
242
|
+
readonly schema: {
|
|
243
|
+
readonly type: "object";
|
|
244
|
+
readonly properties: {
|
|
245
|
+
readonly settings: {
|
|
246
|
+
readonly type: "object";
|
|
247
|
+
readonly properties: {
|
|
248
|
+
readonly models: {
|
|
249
|
+
readonly type: "array";
|
|
250
|
+
readonly items: {
|
|
251
|
+
readonly type: "string";
|
|
252
|
+
};
|
|
253
|
+
};
|
|
254
|
+
readonly windows: {
|
|
255
|
+
readonly type: "array";
|
|
256
|
+
readonly items: {
|
|
257
|
+
readonly type: "array";
|
|
258
|
+
readonly items: {
|
|
259
|
+
readonly type: "string";
|
|
260
|
+
};
|
|
261
|
+
readonly minItems: 2;
|
|
262
|
+
readonly maxItems: 2;
|
|
263
|
+
};
|
|
264
|
+
};
|
|
265
|
+
readonly weekdaysOnly: {
|
|
266
|
+
readonly type: "boolean";
|
|
267
|
+
};
|
|
268
|
+
readonly pollSeconds: {
|
|
269
|
+
readonly type: "string";
|
|
270
|
+
};
|
|
271
|
+
readonly labelPeak: {
|
|
272
|
+
readonly type: "string";
|
|
273
|
+
};
|
|
274
|
+
readonly labelOffPeak: {
|
|
275
|
+
readonly type: "string";
|
|
276
|
+
};
|
|
277
|
+
readonly subagents: {
|
|
278
|
+
readonly type: "boolean";
|
|
279
|
+
};
|
|
280
|
+
readonly alwaysShow: {
|
|
281
|
+
readonly type: "boolean";
|
|
282
|
+
};
|
|
283
|
+
readonly debug: {
|
|
284
|
+
readonly type: "boolean";
|
|
285
|
+
};
|
|
286
|
+
readonly fakeTime: {
|
|
287
|
+
readonly type: "string";
|
|
288
|
+
};
|
|
289
|
+
};
|
|
290
|
+
readonly additionalProperties: false;
|
|
291
|
+
};
|
|
292
|
+
};
|
|
293
|
+
readonly required: readonly ["settings"];
|
|
294
|
+
readonly additionalProperties: false;
|
|
295
|
+
};
|
|
296
|
+
};
|
|
297
|
+
};
|
|
298
|
+
};
|
package/dist/server.d.ts
ADDED
package/dist/server.js
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// src/server.ts
|
|
2
|
+
import { Plugin } from "@opencode/plugin";
|
|
3
|
+
|
|
4
|
+
// src/rpc.ts
|
|
5
|
+
import { Rpc } from "@opencode/plugin/rpc";
|
|
6
|
+
var Settings = {
|
|
7
|
+
type: "object",
|
|
8
|
+
properties: {
|
|
9
|
+
models: { type: "array", items: { type: "string" } },
|
|
10
|
+
windows: {
|
|
11
|
+
type: "array",
|
|
12
|
+
items: {
|
|
13
|
+
type: "array",
|
|
14
|
+
items: { type: "string" },
|
|
15
|
+
minItems: 2,
|
|
16
|
+
maxItems: 2
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
weekdaysOnly: { type: "boolean" },
|
|
20
|
+
pollSeconds: { type: "string" },
|
|
21
|
+
labelPeak: { type: "string" },
|
|
22
|
+
labelOffPeak: { type: "string" },
|
|
23
|
+
subagents: { type: "boolean" },
|
|
24
|
+
alwaysShow: { type: "boolean" },
|
|
25
|
+
debug: { type: "boolean" },
|
|
26
|
+
fakeTime: { type: "string" }
|
|
27
|
+
},
|
|
28
|
+
additionalProperties: false
|
|
29
|
+
};
|
|
30
|
+
var Envelope = {
|
|
31
|
+
type: "object",
|
|
32
|
+
properties: { settings: Settings },
|
|
33
|
+
required: ["settings"],
|
|
34
|
+
additionalProperties: false
|
|
35
|
+
};
|
|
36
|
+
var Empty = { type: "object", additionalProperties: false };
|
|
37
|
+
var PeakBadgeSettingsRpc = Rpc.define({
|
|
38
|
+
id: "peak-badge.settings",
|
|
39
|
+
methods: {
|
|
40
|
+
get: { input: Empty, output: Envelope },
|
|
41
|
+
set: { input: Envelope, output: Envelope },
|
|
42
|
+
reset: { input: Empty, output: Envelope }
|
|
43
|
+
},
|
|
44
|
+
events: {
|
|
45
|
+
updated: { schema: Envelope }
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// src/core.ts
|
|
50
|
+
var DEFAULT_WINDOWS = [
|
|
51
|
+
["01:00", "04:00"],
|
|
52
|
+
["06:00", "10:00"]
|
|
53
|
+
];
|
|
54
|
+
var DEFAULT_MODELS = [
|
|
55
|
+
"re:^opencode-go/deepseek",
|
|
56
|
+
"re:^opencode/deepseek",
|
|
57
|
+
"re:^deepseek/deepseek"
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
// src/settings.ts
|
|
61
|
+
var DEFAULT_POLL_SECONDS = 10;
|
|
62
|
+
var DEFAULT_SETTINGS = {
|
|
63
|
+
models: modelLines(DEFAULT_MODELS),
|
|
64
|
+
windows: DEFAULT_WINDOWS.map(([start, end]) => [start, end]),
|
|
65
|
+
weekdaysOnly: true,
|
|
66
|
+
pollSeconds: String(DEFAULT_POLL_SECONDS),
|
|
67
|
+
labelPeak: "[PEAK]",
|
|
68
|
+
labelOffPeak: "[OFF-PEAK]",
|
|
69
|
+
subagents: true,
|
|
70
|
+
alwaysShow: false,
|
|
71
|
+
debug: false,
|
|
72
|
+
fakeTime: ""
|
|
73
|
+
};
|
|
74
|
+
function defaultSettings() {
|
|
75
|
+
return {
|
|
76
|
+
...DEFAULT_SETTINGS,
|
|
77
|
+
models: [...DEFAULT_SETTINGS.models],
|
|
78
|
+
windows: DEFAULT_SETTINGS.windows.map(([start, end]) => [start, end])
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function isRecord(value) {
|
|
82
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
83
|
+
}
|
|
84
|
+
function isWindowSpec(value) {
|
|
85
|
+
return Array.isArray(value) && value.length === 2 && typeof value[0] === "string" && typeof value[1] === "string";
|
|
86
|
+
}
|
|
87
|
+
function isWindowList(value) {
|
|
88
|
+
return Array.isArray(value) && value.every(isWindowSpec);
|
|
89
|
+
}
|
|
90
|
+
function sanitizeSettings(value) {
|
|
91
|
+
const next = defaultSettings();
|
|
92
|
+
if (!isRecord(value))
|
|
93
|
+
return next;
|
|
94
|
+
if (Array.isArray(value.models) && value.models.every((entry) => typeof entry === "string")) {
|
|
95
|
+
next.models = [...value.models];
|
|
96
|
+
}
|
|
97
|
+
if (isWindowList(value.windows)) {
|
|
98
|
+
next.windows = value.windows.map(([start, end]) => [start, end]);
|
|
99
|
+
}
|
|
100
|
+
if (typeof value.weekdaysOnly === "boolean")
|
|
101
|
+
next.weekdaysOnly = value.weekdaysOnly;
|
|
102
|
+
if (typeof value.pollSeconds === "string")
|
|
103
|
+
next.pollSeconds = value.pollSeconds;
|
|
104
|
+
if (typeof value.labelPeak === "string")
|
|
105
|
+
next.labelPeak = value.labelPeak;
|
|
106
|
+
if (typeof value.labelOffPeak === "string")
|
|
107
|
+
next.labelOffPeak = value.labelOffPeak;
|
|
108
|
+
if (typeof value.subagents === "boolean")
|
|
109
|
+
next.subagents = value.subagents;
|
|
110
|
+
if (typeof value.alwaysShow === "boolean")
|
|
111
|
+
next.alwaysShow = value.alwaysShow;
|
|
112
|
+
if (typeof value.debug === "boolean")
|
|
113
|
+
next.debug = value.debug;
|
|
114
|
+
if (typeof value.fakeTime === "string")
|
|
115
|
+
next.fakeTime = value.fakeTime;
|
|
116
|
+
return next;
|
|
117
|
+
}
|
|
118
|
+
function settingsFromEnvelope(value) {
|
|
119
|
+
return sanitizeSettings(isRecord(value) ? value.settings : undefined);
|
|
120
|
+
}
|
|
121
|
+
function modelLines(entries) {
|
|
122
|
+
return entries.map((entry) => typeof entry === "string" ? entry : JSON.stringify(entry));
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// src/server.ts
|
|
126
|
+
var server_default = Plugin.define({
|
|
127
|
+
id: "peak-badge",
|
|
128
|
+
async setup(ctx) {
|
|
129
|
+
let notify;
|
|
130
|
+
const registration = await ctx.rpc.register(PeakBadgeSettingsRpc, {
|
|
131
|
+
get: async () => ({ settings: sanitizeSettings(await ctx.storage.get("settings")) }),
|
|
132
|
+
set: async (input) => {
|
|
133
|
+
const settings = sanitizeSettings(settingsFromEnvelope(input));
|
|
134
|
+
await ctx.storage.set("settings", settings);
|
|
135
|
+
await notify?.(settings);
|
|
136
|
+
return { settings };
|
|
137
|
+
},
|
|
138
|
+
reset: async () => {
|
|
139
|
+
await ctx.storage.remove("settings");
|
|
140
|
+
const settings = sanitizeSettings(undefined);
|
|
141
|
+
await notify?.(settings);
|
|
142
|
+
return { settings };
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
notify = (settings) => registration.events.emit("updated", { settings });
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
export {
|
|
149
|
+
server_default as default
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
//# debugId=42D98E84CA3C7A8164756E2164756E21
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/server.ts", "../src/rpc.ts", "../src/core.ts", "../src/settings.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import { Plugin } from \"@opencode/plugin\"\nimport { PeakBadgeSettingsRpc } from \"./rpc\"\nimport { sanitizeSettings, settingsFromEnvelope, type PeakBadgeSettings } from \"./settings\"\n\n// The server stores the single shared settings object and exposes it over RPC.\n// Keeping it here, in the server's plugin storage, lets the TUI and every\n// desktop window read and write the same value and receive live updates.\nexport default Plugin.define({\n id: \"peak-badge\",\n async setup(ctx) {\n // The registration is needed to emit, but the handlers are built before it\n // exists. Calls cannot arrive until register resolves, so a late binding is\n // safe and avoids returning the settings without notifying other clients.\n let notify: ((settings: PeakBadgeSettings) => Promise<void>) | undefined\n\n const registration = await ctx.rpc.register(PeakBadgeSettingsRpc, {\n get: async () => ({ settings: sanitizeSettings(await ctx.storage.get(\"settings\")) }),\n set: async (input) => {\n const settings = sanitizeSettings(settingsFromEnvelope(input))\n await ctx.storage.set(\"settings\", settings)\n await notify?.(settings)\n return { settings }\n },\n reset: async () => {\n await ctx.storage.remove(\"settings\")\n const settings = sanitizeSettings(undefined)\n await notify?.(settings)\n return { settings }\n },\n })\n\n notify = (settings) => registration.events.emit(\"updated\", { settings })\n },\n})\n",
|
|
6
|
+
"import { Rpc } from \"@opencode/plugin/rpc\"\n\n// JSON Schema keeps the RPC definition dependency-free and portable: both the\n// server and the clients use the same object, and the host validates every\n// call and event. Unknown fields are rejected so a typo cannot silently store\n// a setting the plugin does not understand.\nconst Settings = {\n type: \"object\",\n properties: {\n models: { type: \"array\", items: { type: \"string\" } },\n windows: {\n type: \"array\",\n items: {\n type: \"array\",\n items: { type: \"string\" },\n minItems: 2,\n maxItems: 2,\n },\n },\n weekdaysOnly: { type: \"boolean\" },\n pollSeconds: { type: \"string\" },\n labelPeak: { type: \"string\" },\n labelOffPeak: { type: \"string\" },\n subagents: { type: \"boolean\" },\n alwaysShow: { type: \"boolean\" },\n debug: { type: \"boolean\" },\n fakeTime: { type: \"string\" },\n },\n additionalProperties: false,\n} as const\n\nconst Envelope = {\n type: \"object\",\n properties: { settings: Settings },\n required: [\"settings\"],\n additionalProperties: false,\n} as const\n\nconst Empty = { type: \"object\", additionalProperties: false } as const\n\n/**\n * The shared settings RPC. `get` returns the defaults when nothing is stored;\n * `set` replaces the full object; `reset` removes the stored value. `updated`\n * reaches every open TUI and desktop window so both badges follow the change.\n */\nexport const PeakBadgeSettingsRpc = Rpc.define({\n id: \"peak-badge.settings\",\n methods: {\n get: { input: Empty, output: Envelope },\n set: { input: Envelope, output: Envelope },\n reset: { input: Empty, output: Envelope },\n },\n events: {\n updated: { schema: Envelope },\n },\n})\n",
|
|
7
|
+
"export type WindowSpec = readonly [start: string, end: string]\n\nexport type MinuteWindow = { start: number; end: number }\n\nexport type ModelEntryObject =\n | { id: string; windows?: WindowSpec[]; weekdaysOnly?: boolean }\n | { pattern: string; windows?: WindowSpec[]; weekdaysOnly?: boolean }\n\nexport type ModelEntrySpec = string | ModelEntryObject\n\nexport type RuleOptions = {\n models?: ModelEntrySpec[]\n windows?: WindowSpec[]\n weekdaysOnly?: boolean\n}\n\nexport type ResolvedModelRule = {\n id: string\n windows: MinuteWindow[]\n weekdaysOnly: boolean\n regex?: RegExp\n}\n\nexport type RuleSet = {\n exact: Map<string, ResolvedModelRule>\n patterns: ResolvedModelRule[]\n fallback: ResolvedModelRule\n}\n\nexport type BadgeState = { label: string; peak: boolean }\n\nexport type ModelRef = { providerID: string; id: string }\n\nexport const DEFAULT_WINDOWS: WindowSpec[] = [\n [\"01:00\", \"04:00\"],\n [\"06:00\", \"10:00\"],\n]\n\nexport const DEFAULT_MODELS: ModelEntrySpec[] = [\n \"re:^opencode-go/deepseek\",\n \"re:^opencode/deepseek\",\n \"re:^deepseek/deepseek\",\n]\n\n// Resolves the clock used by the badge. `fakeTime` comes from the shared\n// settings; the TUI also passes its test-only environment variable.\nexport function currentNow(fakeTime?: string, realNow: Date = new Date()): Date {\n if (fakeTime) {\n const parsed = new Date(fakeTime)\n if (!Number.isNaN(parsed.getTime())) return parsed\n }\n return realNow\n}\n\nexport function parseHHMM(value: string): number | undefined {\n const match = /^(\\d{1,2}):(\\d{2})$/.exec(value.trim())\n if (!match) return undefined\n const hours = Number(match[1])\n const minutes = Number(match[2])\n if (hours > 23 || minutes > 59) return undefined\n return hours * 60 + minutes\n}\n\nexport function parseWindow(spec: WindowSpec): MinuteWindow | undefined {\n const start = parseHHMM(spec[0])\n const end = parseHHMM(spec[1])\n if (start === undefined || end === undefined) return undefined\n return { start, end }\n}\n\nexport function parseWindows(specs: readonly WindowSpec[]): MinuteWindow[] {\n const windows: MinuteWindow[] = []\n for (const spec of specs) {\n const window = parseWindow(spec)\n if (window) windows.push(window)\n }\n return windows\n}\n\nexport function inWindow(minutes: number, window: MinuteWindow): boolean {\n if (window.end <= window.start) return minutes >= window.start || minutes < window.end\n return minutes >= window.start && minutes < window.end\n}\n\nexport function isPeakUtc(now: Date, windows: readonly MinuteWindow[], weekdaysOnly = true): boolean {\n if (weekdaysOnly) {\n const day = now.getUTCDay()\n if (day === 0 || day === 6) return false\n }\n const minutes = now.getUTCHours() * 60 + now.getUTCMinutes()\n return windows.some((window) => inWindow(minutes, window))\n}\n\nexport function modelKey(providerID: string, modelID: string): string {\n return `${providerID}/${modelID}`.trim().toLowerCase()\n}\n\nfunction buildRule(\n id: string,\n spec: { windows?: WindowSpec[]; weekdaysOnly?: boolean },\n defaultWindows: MinuteWindow[],\n defaultWeekdays: boolean,\n): ResolvedModelRule {\n return {\n id,\n windows: spec.windows?.length ? parseWindows(spec.windows) : defaultWindows,\n weekdaysOnly: spec.weekdaysOnly ?? defaultWeekdays,\n }\n}\n\nexport function resolveRules(options: RuleOptions = {}): RuleSet {\n const defaultWindows = parseWindows(options.windows ?? DEFAULT_WINDOWS)\n const defaultWeekdays = options.weekdaysOnly ?? true\n const entries = options.models ?? DEFAULT_MODELS\n const exact = new Map<string, ResolvedModelRule>()\n const patterns: ResolvedModelRule[] = []\n for (const entry of entries) {\n if (typeof entry === \"string\") {\n const trimmed = entry.trim()\n if (!trimmed) continue\n if (trimmed.toLowerCase().startsWith(\"re:\")) {\n const source = trimmed.slice(3)\n if (!source.trim()) continue\n const regex = compileRegex(source)\n if (!regex) continue\n patterns.push({ id: source, regex, windows: defaultWindows, weekdaysOnly: defaultWeekdays })\n } else {\n const id = trimmed.toLowerCase()\n exact.set(id, buildRule(id, {}, defaultWindows, defaultWeekdays))\n }\n } else if (\"pattern\" in entry) {\n const source = entry.pattern\n if (!source.trim()) continue\n const regex = compileRegex(source)\n if (!regex) continue\n patterns.push({\n id: source,\n regex,\n windows: entry.windows?.length ? parseWindows(entry.windows) : defaultWindows,\n weekdaysOnly: entry.weekdaysOnly ?? defaultWeekdays,\n })\n } else {\n const id = entry.id.trim().toLowerCase()\n if (!id) continue\n exact.set(id, buildRule(id, entry, defaultWindows, defaultWeekdays))\n }\n }\n return {\n exact,\n patterns,\n fallback: { id: \"\", windows: defaultWindows, weekdaysOnly: defaultWeekdays },\n }\n}\n\n// Whether one configured model entry is usable. Shared by the settings editors\n// so a typo in an exact id or an unsafe regex is reported instead of silently\n// matching nothing.\nexport function isValidModelEntry(entry: ModelEntrySpec): boolean {\n const rules = resolveRules({ models: [entry] })\n return rules.exact.size > 0 || rules.patterns.length > 0\n}\n\nfunction isSafeRegex(source: string): boolean {\n let depth = 0\n let inClass = false\n for (let i = 0; i < source.length; i++) {\n const ch = source[i]!\n if (ch === \"\\\\\") {\n i++\n continue\n }\n if (ch === \"[\") {\n inClass = true\n continue\n }\n if (ch === \"]\") {\n inClass = false\n continue\n }\n if (inClass) continue\n if (ch === \"(\") depth++\n else if (ch === \")\") depth = Math.max(0, depth - 1)\n else if (depth > 0 && \"+*}\".includes(ch)) return false\n }\n return true\n}\n\nfunction compileRegex(source: string): RegExp | undefined {\n try {\n if (!isSafeRegex(source)) return undefined\n return new RegExp(source, \"i\")\n } catch {\n // An invalid regex is ignored; resolveRules skips this entry.\n return undefined\n }\n}\n\nexport function matchRule(rules: RuleSet, key: string): ResolvedModelRule | undefined {\n const exact = rules.exact.get(key)\n if (exact) return exact\n for (const rule of rules.patterns) {\n if (rule.regex!.test(key)) return rule\n }\n return undefined\n}\n\nexport function badgeFor(\n now: Date,\n rule: ResolvedModelRule | undefined,\n labels: { peak: string; offPeak: string },\n): BadgeState | undefined {\n if (!rule) return undefined\n const peak = isPeakUtc(now, rule.windows, rule.weekdaysOnly)\n return { label: peak ? labels.peak : labels.offPeak, peak }\n}\n\nexport function mergeBadges(states: Array<BadgeState | undefined>): BadgeState | undefined {\n let result: BadgeState | undefined\n for (const state of states) {\n if (!state) continue\n if (!result) {\n result = state\n continue\n }\n if (state.peak && !result.peak) result = state\n }\n return result\n}\n\n// Shared by the TUI and desktop adapters: the main model follows `alwaysShow`;\n// a running subagent only contributes when it matches a configured rule.\nexport function badgeForModels(input: {\n now: Date\n rules: RuleSet\n labels: { peak: string; offPeak: string }\n main: ModelRef | undefined\n subagents: readonly ModelRef[]\n alwaysShow: boolean\n}): BadgeState | undefined {\n const states: BadgeState[] = []\n if (input.main) {\n const rule =\n matchRule(input.rules, modelKey(input.main.providerID, input.main.id)) ??\n (input.alwaysShow ? input.rules.fallback : undefined)\n const state = badgeFor(input.now, rule, input.labels)\n if (state) states.push(state)\n }\n for (const child of input.subagents) {\n const state = badgeFor(input.now, matchRule(input.rules, modelKey(child.providerID, child.id)), input.labels)\n if (state) states.push(state)\n }\n return mergeBadges(states)\n}\n\n// Walks the descendant tree of a session and returns the models of the\n// running subagents. The model callback lets each adapter decide how to read\n// (and cache) a child's model.\nexport function runningSubagentRefs(input: {\n sessionID: string\n family: (sessionID: string) => readonly string[]\n status: (sessionID: string) => \"idle\" | \"running\"\n model: (sessionID: string) => ModelRef | undefined\n}): ModelRef[] {\n const refs: ModelRef[] = []\n const seen = new Set<string>()\n const stack: string[] = [...input.family(input.sessionID)]\n while (stack.length > 0) {\n const id = stack.pop()\n if (!id || seen.has(id)) continue\n seen.add(id)\n if (input.status(id) === \"running\") {\n const model = input.model(id)\n if (model) refs.push(model)\n }\n // `family` may return every descendant already; recursing keeps nested\n // subagents covered if it only returns direct children. `seen` caps it.\n for (const nested of input.family(id)) {\n if (!seen.has(nested)) stack.push(nested)\n }\n }\n return refs\n}\n",
|
|
8
|
+
"import {\n DEFAULT_MODELS,\n DEFAULT_WINDOWS,\n isValidModelEntry,\n parseHHMM,\n resolveRules,\n type ModelEntryObject,\n type ModelEntrySpec,\n type RuleSet,\n type WindowSpec,\n} from \"./core\"\n\n/**\n * The settings shared by the TUI and the desktop app. `models` keeps one raw\n * line per entry so the editors can round-trip exact ids, regexes and JSON\n * objects without a second shape. `pollSeconds` and `fakeTime` stay raw for the\n * same reason; resolveSettings normalizes them for the badge.\n */\nexport type PeakBadgeSettings = {\n models: string[]\n windows: WindowSpec[]\n weekdaysOnly: boolean\n pollSeconds: string\n labelPeak: string\n labelOffPeak: string\n subagents: boolean\n alwaysShow: boolean\n debug: boolean\n fakeTime: string\n}\n\n/** The normalized values a badge needs, derived from PeakBadgeSettings. */\nexport type ResolvedSettings = {\n rules: RuleSet\n labels: { peak: string; offPeak: string }\n pollSeconds: number\n subagents: boolean\n alwaysShow: boolean\n debug: boolean\n fakeTime: string | undefined\n}\n\nexport const DEFAULT_POLL_SECONDS = 10\n\nexport const DEFAULT_SETTINGS: PeakBadgeSettings = {\n models: modelLines(DEFAULT_MODELS),\n windows: DEFAULT_WINDOWS.map(([start, end]): WindowSpec => [start, end]),\n weekdaysOnly: true,\n pollSeconds: String(DEFAULT_POLL_SECONDS),\n labelPeak: \"[PEAK]\",\n labelOffPeak: \"[OFF-PEAK]\",\n subagents: true,\n alwaysShow: false,\n debug: false,\n fakeTime: \"\",\n}\n\n/** A fresh copy of the built-in settings, safe for an editor to mutate. */\nexport function defaultSettings(): PeakBadgeSettings {\n return {\n ...DEFAULT_SETTINGS,\n models: [...DEFAULT_SETTINGS.models],\n windows: DEFAULT_SETTINGS.windows.map(([start, end]): WindowSpec => [start, end]),\n }\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value)\n}\n\nfunction isWindowSpec(value: unknown): value is WindowSpec {\n return (\n Array.isArray(value) &&\n value.length === 2 &&\n typeof value[0] === \"string\" &&\n typeof value[1] === \"string\"\n )\n}\n\nfunction isWindowList(value: unknown): value is WindowSpec[] {\n return Array.isArray(value) && value.every(isWindowSpec)\n}/**\n * Fills missing or invalid fields with defaults. Used by the server when it\n * reads storage and by both clients when they receive an RPC payload, so a\n * partial or older value can never break a badge.\n */\nexport function sanitizeSettings(value: unknown): PeakBadgeSettings {\n const next = defaultSettings()\n if (!isRecord(value)) return next\n\n if (Array.isArray(value.models) && value.models.every((entry) => typeof entry === \"string\")) {\n next.models = [...value.models]\n }\n if (isWindowList(value.windows)) {\n next.windows = value.windows.map(([start, end]): WindowSpec => [start, end])\n }\n if (typeof value.weekdaysOnly === \"boolean\") next.weekdaysOnly = value.weekdaysOnly\n if (typeof value.pollSeconds === \"string\") next.pollSeconds = value.pollSeconds\n if (typeof value.labelPeak === \"string\") next.labelPeak = value.labelPeak\n if (typeof value.labelOffPeak === \"string\") next.labelOffPeak = value.labelOffPeak\n if (typeof value.subagents === \"boolean\") next.subagents = value.subagents\n if (typeof value.alwaysShow === \"boolean\") next.alwaysShow = value.alwaysShow\n if (typeof value.debug === \"boolean\") next.debug = value.debug\n if (typeof value.fakeTime === \"string\") next.fakeTime = value.fakeTime\n\n return next\n}\n\n/** Reads the `{ settings }` envelope used by the RPC methods and event. */\nexport function settingsFromEnvelope(value: unknown): PeakBadgeSettings {\n return sanitizeSettings(isRecord(value) ? value.settings : undefined)\n}\n\n/** Normalizes stored settings for both badge adapters. */\nexport function resolveSettings(settings: PeakBadgeSettings): ResolvedSettings {\n const poll = Number(settings.pollSeconds)\n return {\n rules: resolveRules({\n models: parseModelLines(settings.models),\n windows: settings.windows,\n weekdaysOnly: settings.weekdaysOnly,\n }),\n labels: { peak: settings.labelPeak, offPeak: settings.labelOffPeak },\n pollSeconds: Number.isFinite(poll) && poll >= 1 ? poll : DEFAULT_POLL_SECONDS,\n subagents: settings.subagents,\n alwaysShow: settings.alwaysShow,\n debug: settings.debug,\n fakeTime: settings.fakeTime.trim() || undefined,\n }\n}\n\n/** Serializes model entries into one editable line each. */\nexport function modelLines(entries: readonly ModelEntrySpec[]): string[] {\n return entries.map((entry) => (typeof entry === \"string\" ? entry : JSON.stringify(entry)))\n}\n\n/**\n * Parses one editable model line. Strings are exact ids or `re:` patterns;\n * lines starting with `{` are JSON objects with `id` or `pattern`, plus\n * optional `windows` and `weekdaysOnly`. Invalid JSON, a JSON array, or an\n * object without a usable id/pattern yields undefined.\n */\nexport function parseModelLine(line: string): ModelEntrySpec | undefined {\n const text = line.trim()\n if (!text) return undefined\n if (!text.startsWith(\"{\") && !text.startsWith(\"[\")) return text\n\n let value: unknown\n try {\n value = JSON.parse(text)\n } catch {\n // A line that starts like JSON but does not parse is an invalid entry.\n return undefined\n }\n if (!isRecord(value)) return undefined\n\n const pattern = typeof value.pattern === \"string\" && value.pattern.trim() ? value.pattern.trim() : undefined\n const id = typeof value.id === \"string\" && value.id.trim() ? value.id.trim() : undefined\n if (!pattern && !id) return undefined\n\n let windows: WindowSpec[] | undefined\n if (value.windows !== undefined) {\n if (!isWindowList(value.windows)) return undefined\n windows = value.windows.map(([start, end]): WindowSpec => [start, end])\n }\n if (value.weekdaysOnly !== undefined && typeof value.weekdaysOnly !== \"boolean\") return undefined\n const weekdaysOnly = typeof value.weekdaysOnly === \"boolean\" ? value.weekdaysOnly : undefined\n\n const entry: ModelEntryObject = pattern\n ? {\n pattern,\n ...(windows !== undefined ? { windows } : {}),\n ...(weekdaysOnly !== undefined ? { weekdaysOnly } : {}),\n }\n : {\n id: id!,\n ...(windows !== undefined ? { windows } : {}),\n ...(weekdaysOnly !== undefined ? { weekdaysOnly } : {}),\n }\n return entry\n}\n\n/** Parses the editable lines, dropping entries that are not valid shapes. */\nexport function parseModelLines(lines: readonly string[]): ModelEntrySpec[] {\n const entries: ModelEntrySpec[] = []\n for (const line of lines) {\n const entry = parseModelLine(line)\n if (entry !== undefined) entries.push(entry)\n }\n return entries\n}\n\nexport function isHHMM(value: string): boolean {\n return parseHHMM(value) !== undefined\n}\n\nexport function isWindowValid(window: WindowSpec): boolean {\n return isHHMM(window[0]) && isHHMM(window[1])\n}\n\n/**\n * A model line is valid when its shape parses, its regex/id is usable, and any\n * per-entry windows use HH:MM. Exact ids are accepted as-is; a regex with a\n * typo is reported so the badge does not silently stop matching.\n */\nexport function isValidModelLine(line: string): boolean {\n const entry = parseModelLine(line)\n if (entry === undefined || !isValidModelEntry(entry)) return false\n if (typeof entry === \"object\" && entry.windows && !entry.windows.every(isWindowValid)) return false\n return true\n}\n\nexport function isValidPollSeconds(raw: string): boolean {\n const value = Number(raw)\n return raw.trim() !== \"\" && Number.isFinite(value) && value >= 1\n}\n\nexport function isValidFakeTime(raw: string): boolean {\n if (!raw.trim()) return true\n return !Number.isNaN(new Date(raw).getTime())\n}\n\nexport function formatWindows(windows: readonly WindowSpec[]): string {\n if (windows.length === 0) return \"none\"\n return windows.map(([start, end]) => `${start} - ${end}`).join(\", \")\n}\n\nexport function formatModels(models: readonly string[]): string {\n if (models.length === 0) return \"none\"\n const shown = models.slice(0, 2).join(\", \")\n return models.length > 2 ? `${shown}, ...` : shown\n}\n\nexport function onOff(value: boolean): string {\n return value ? \"on\" : \"off\"\n}\n"
|
|
9
|
+
],
|
|
10
|
+
"mappings": "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",
|
|
11
|
+
"debugId": "42D98E84CA3C7A8164756E2164756E21",
|
|
12
|
+
"names": []
|
|
13
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { OpenCodeClient } from "@opencode/client";
|
|
2
|
+
import { type PeakBadgeSettings } from "./settings";
|
|
3
|
+
/**
|
|
4
|
+
* The shared settings RPC plumbing both badge adapters need: connect to the
|
|
5
|
+
* event stream, refresh on demand, save a full object, and reset to defaults.
|
|
6
|
+
* The TUI and the desktop differ only in when they call these methods and how
|
|
7
|
+
* they surface errors.
|
|
8
|
+
*/
|
|
9
|
+
export type SettingsSync = {
|
|
10
|
+
connect(): void;
|
|
11
|
+
refresh(force?: boolean): Promise<void>;
|
|
12
|
+
save(next: PeakBadgeSettings): Promise<void>;
|
|
13
|
+
reset(): Promise<void>;
|
|
14
|
+
stop(): void;
|
|
15
|
+
};
|
|
16
|
+
export type SettingsSyncOptions = {
|
|
17
|
+
/** Read the client where it is used: it changes after a server restart. */
|
|
18
|
+
readonly client: () => OpenCodeClient;
|
|
19
|
+
readonly set: (next: PeakBadgeSettings) => void;
|
|
20
|
+
/** Skip an incoming value while the caller has a local edit pending. */
|
|
21
|
+
readonly canApply?: (next: PeakBadgeSettings) => boolean;
|
|
22
|
+
/** Replace the default event acceptance check. Return false to ignore. */
|
|
23
|
+
readonly acceptEvent?: (next: PeakBadgeSettings) => boolean;
|
|
24
|
+
/** Load failures: fetch or event subscription. */
|
|
25
|
+
readonly onLoadError?: (message: string) => void;
|
|
26
|
+
/** Save and reset failures. */
|
|
27
|
+
readonly onSaveError?: (message: string) => void;
|
|
28
|
+
};
|
|
29
|
+
export declare function createSettingsSync(options: SettingsSyncOptions): SettingsSync;
|