opencode-codex-memory 0.10.2 → 0.11.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 +5 -4
- package/dist/gui-experimental.cjs +1 -0
- package/dist/src/index.d.ts +3 -144
- package/dist/src/v2/gui.d.ts +4 -0
- package/dist/src/v2/model-readiness.js +6 -0
- package/dist/src/v2/panel-status.d.ts +22 -0
- package/dist/src/v2/panel-status.js +203 -0
- package/dist/src/v2/status-rpc.d.ts +1 -1
- package/dist/src/v2/status-rpc.js +1 -1
- package/dist/src/v2/tools.d.ts +5 -5
- package/dist/src/v2/tools.js +5 -5
- package/dist/src/v2/tui.js +140 -167
- package/dist/tools/control.d.ts +4 -33
- package/dist/tools/memory.d.ts +5 -70
- package/dist/tools/memory.js +1 -0
- package/package.json +18 -16
package/README.md
CHANGED
|
@@ -34,7 +34,7 @@ to your existing global `~/.config/opencode/opencode.jsonc` or `opencode.json`
|
|
|
34
34
|
```jsonc
|
|
35
35
|
{
|
|
36
36
|
"$schema": "https://opencode.ai/config.json",
|
|
37
|
-
"plugins": [{ "package": "opencode-codex-memory@0.
|
|
37
|
+
"plugins": [{ "package": "opencode-codex-memory@0.11.0" }],
|
|
38
38
|
}
|
|
39
39
|
```
|
|
40
40
|
|
|
@@ -43,7 +43,7 @@ to your existing global `~/.config/opencode/opencode.jsonc` or `opencode.json`
|
|
|
43
43
|
```json
|
|
44
44
|
{
|
|
45
45
|
"$schema": "https://opencode.ai/config.json",
|
|
46
|
-
"plugin": ["opencode-codex-memory@0.
|
|
46
|
+
"plugin": ["opencode-codex-memory@0.11.0"]
|
|
47
47
|
}
|
|
48
48
|
```
|
|
49
49
|
|
|
@@ -63,8 +63,9 @@ On OpenCode 1.x, restart OpenCode. If an IDE or another app manages your
|
|
|
63
63
|
OpenCode server, restart that server too.
|
|
64
64
|
|
|
65
65
|
Start a conversation and ask **“Check my memory status.”** The agent can run
|
|
66
|
-
`memory_inspect` to show progress and any warnings.
|
|
67
|
-
|
|
66
|
+
`memory_inspect` to show progress and any warnings.
|
|
67
|
+
[**`/memory-inspect`**](./docs/usage.md#memory-panel) opens the Memory panel in
|
|
68
|
+
the OpenCode 2 terminal UI and in OpenCode Desktop 2.4.2 or later.
|
|
68
69
|
|
|
69
70
|
## Try it
|
|
70
71
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("solid-js/web"),$=require("@opencode/plugin/gui"),u=require("solid-js"),T=["idle","extracting","consolidating","retrying","error","read_only","disabled","stopping"],E={type:"object",properties:{sessionTokens:{type:"number"},sessionRequests:{type:"number"},totalTokens:{type:"number"},totalRequests:{type:"number"}},required:["sessionTokens","sessionRequests","totalTokens","totalRequests"],additionalProperties:!1},P={id:"opencode-codex-memory",methods:{status:{input:{type:"object",properties:{sessionID:{type:"string"},minConsolidatedThreads:{type:"integer",minimum:1,maximum:4096}},additionalProperties:!1},output:{type:"object",properties:{activity:{type:"string",enum:[...T]},version:{type:"string",enum:["v1","v2"]},sessionVersion:{type:"string",enum:["v1","v2"]},dualWrite:{type:"boolean"},v2ConsolidatedThreads:{type:"integer",minimum:0},v2Ready:{type:"boolean"},v2NotReadyReason:{type:["string","null"]},v2SummaryBytes:{type:["integer","null"],minimum:0},v2InjectedSummaryBytes:{type:["integer","null"],minimum:0,maximum:9999},minConsolidatedThreads:{type:"integer",minimum:1,maximum:4096},useMemories:{type:"boolean"},pipelines:{type:"array",items:{type:"object",properties:{version:{type:"string",enum:["v1","v2"]},stage1Count:{type:"integer",minimum:0},extracting:{type:"integer",minimum:0},phase2Status:{type:["string","null"]},lastError:{type:["string","null"]},phase2CooldownUntil:{type:["number","null"]},phase1RetryAt:{type:["number","null"]},phase2RetryAt:{type:["number","null"]}},required:["version","stage1Count","extracting","phase2Status","lastError"],additionalProperties:!1}},generateMemories:{type:"boolean"},extractModel:{type:["string","null"]},consolidationModel:{type:["string","null"]},codexImport:{type:"boolean"},lastSuccessAt:{type:["number","null"]},retryAt:{type:["number","null"]},warnings:{type:"array",items:{type:"string"}},sessionMode:{type:["string","null"],enum:["enabled","disabled","polluted",null]},memoryRoot:{type:"string"},injected:E},required:["activity","version","sessionVersion","dualWrite","v2ConsolidatedThreads","v2Ready","minConsolidatedThreads","pipelines","useMemories","generateMemories","extractModel","consolidationModel","codexImport","lastSuccessAt","retryAt","warnings","sessionMode","memoryRoot","injected"],additionalProperties:!1}},setOption:{input:{type:"object",properties:{key:{type:"string",enum:["use_memories","generate_memories"]},value:{type:"boolean"}},required:["key","value"],additionalProperties:!1},output:{type:"object",properties:{ok:{type:"boolean"}},required:["ok"],additionalProperties:!1}},setSessionMode:{input:{type:"object",properties:{sessionID:{type:"string"},mode:{type:"string",enum:["enabled","disabled"]}},required:["sessionID","mode"],additionalProperties:!1},output:{type:"object",properties:{ok:{type:"boolean"}},required:["ok"],additionalProperties:!1}},consolidateNow:{input:{type:"object",properties:{},additionalProperties:!1},output:{type:"object",properties:{status:{type:"string"}},required:["status"],additionalProperties:!1}},resetMemory:{input:{type:"object",properties:{confirm:{type:"boolean"}},required:["confirm"],additionalProperties:!1},output:{type:"object",properties:{ok:{type:"boolean"},message:{type:"string"}},required:["ok","message"],additionalProperties:!1}}},events:{changed:{schema:{type:"object",properties:{},additionalProperties:!1}}}};function R(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function B(e){if(!R(e)||typeof e.activity!="string"||!T.includes(e.activity))return!1;for(const t of["useMemories","generateMemories","codexImport","dualWrite","v2Ready"])if(typeof e[t]!="boolean")return!1;for(const t of["version","sessionVersion"])if(e[t]!=="v1"&&e[t]!=="v2")return!1;if(!Number.isInteger(e.v2ConsolidatedThreads)||e.v2ConsolidatedThreads<0||e.v2NotReadyReason!==void 0&&e.v2NotReadyReason!==null&&typeof e.v2NotReadyReason!="string")return!1;for(const t of["v2SummaryBytes","v2InjectedSummaryBytes"])if(e[t]!==void 0&&e[t]!==null&&(!Number.isInteger(e[t])||e[t]<0))return!1;if(typeof e.v2InjectedSummaryBytes=="number"&&e.v2InjectedSummaryBytes>9999||!Number.isInteger(e.minConsolidatedThreads)||e.minConsolidatedThreads<1||e.minConsolidatedThreads>4096||!Array.isArray(e.pipelines)||!e.pipelines.every(t=>R(t)&&(t.version==="v1"||t.version==="v2")&&Number.isInteger(t.stage1Count)&&t.stage1Count>=0&&Number.isInteger(t.extracting)&&t.extracting>=0&&(t.phase2Status===null||typeof t.phase2Status=="string")&&(t.lastError===null||typeof t.lastError=="string")&&["phase2CooldownUntil","phase1RetryAt","phase2RetryAt"].every(s=>t[s]===void 0||t[s]===null||typeof t[s]=="number"&&Number.isFinite(t[s]))))return!1;for(const t of["extractModel","consolidationModel","lastSuccessAt","retryAt"]){const s=e[t];if(s!==null&&typeof s!=(t==="extractModel"||t==="consolidationModel"?"string":"number"))return!1}if(!Array.isArray(e.warnings)||!e.warnings.every(t=>typeof t=="string")||e.sessionMode!==null&&e.sessionMode!=="enabled"&&e.sessionMode!=="disabled"&&e.sessionMode!=="polluted"||typeof e.memoryRoot!="string")return!1;const n=e.injected;if(!R(n))return!1;for(const t of["sessionTokens","sessionRequests","totalTokens","totalRequests"])if(typeof n[t]!="number")return!1;return!0}const j={idle:"Idle",extracting:"Extracting",consolidating:"Consolidating",retrying:"Waiting to retry",error:"Needs attention",read_only:"Read only",disabled:"Disabled",stopping:"Stopping"};function L(e,n){const[t,s]=u.createSignal(null),[l,m]=u.createSignal(!1),[v,y]=u.createSignal(!1),[o,d]=u.createSignal(Date.now()),c=new AbortController;let g=0;const f=async()=>{const C=++g;y(!0);try{const h=await e(AbortSignal.any([c.signal,AbortSignal.timeout(5e3)]));if(c.signal.aborted||C!==g)return;if(!B(h))throw new Error("invalid memory status payload");s(h),d(Date.now()),m(!1)}catch{!c.signal.aborted&&C===g&&m(!0)}finally{!c.signal.aborted&&C===g&&y(!1)}},b=n(()=>{f()}),w=setInterval(()=>{f()},3e4);return u.onCleanup(()=>{c.abort(),clearInterval(w),b()}),f(),{status:t,unavailable:l,refreshing:v,updatedAt:o,refresh:f,signal:c.signal}}function U(e){return e.activity==="consolidating"||e.activity==="extracting"||e.pipelines.some(n=>n.extracting>0||n.phase2Status==="running")}function O(e,n){const t=Math.max(0,Math.floor((n-e)/6e4));return t===0?"just now":t<60?`${t}m ago`:t<1440?`${Math.floor(t/60)}h ago`:`${Math.floor(t/1440)}d ago`}function k(e,n){if(e==null)return"—";const t=Math.max(0,Math.ceil((e-n)/6e4));return t<1?"in <1m":t<60?`in ${t}m`:t<1440?`in ${Math.floor(t/60)}h ${t%60}m`:`in ${Math.floor(t/1440)}d`}function _(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:String(e)}function D(e,n){return e.pipelines.flatMap(t=>{const s=t.version.toUpperCase(),l=!e.generateMemories||!e.dualWrite&&t.version!==e.version,m=t.phase1RetryAt!=null&&t.phase1RetryAt>n,v=t.phase2RetryAt!=null&&t.phase2RetryAt>n,y=t.phase2CooldownUntil!=null&&t.phase2CooldownUntil>n,o=t.phase2Status==="pending"?"Queued":t.phase2Status==="failed"?"Retry due":"Idle";return[{label:`${s} recaps`,value:`${t.stage1Count} stored`,tone:"muted"},{label:`${s} extraction`,value:t.extracting?`Running (${t.extracting})`:l?"Paused":m?`Retry ${k(t.phase1RetryAt,n)}`:"Idle",tone:m&&!l?"warn":"muted"},{label:`${s} consolidation`,value:t.phase2Status==="running"?"Running":l?"Paused":v?`Retry ${k(t.phase2RetryAt,n)}`:y?`${o} · cooldown ends ${k(t.phase2CooldownUntil,n)}`:t.phase2Status==="pending"?"Queued · next activity":o,tone:t.lastError?"warn":"muted"},...t.lastError?[{label:`${s} last error`,value:t.lastError,tone:"warn"}]:[]]})}function z(e,n,{includeReadinessDiagnostic:t=!0}={}){return[{label:"Activity",value:j[e.activity]},{label:"Memory version",value:`${e.sessionVersion} (default ${e.version})`},{label:"Learning pipelines",value:e.dualWrite?"v1 + v2":e.version},{label:"V2 readiness",value:`${e.v2Ready?"Ready":"Not ready"} · ${e.v2ConsolidatedThreads}/${e.minConsolidatedThreads} sessions`,tone:e.v2Ready?"ok":"muted"},...t&&e.v2NotReadyReason?[{label:"V2 not ready",value:e.v2NotReadyReason,tone:"muted"}]:[],...e.v2SummaryBytes!==void 0?[{label:"V2 summary",value:e.v2SummaryBytes===null?"Unreadable":e.v2InjectedSummaryBytes!=null?`${e.v2SummaryBytes} bytes on disk · ${e.v2InjectedSummaryBytes} injected${e.v2SummaryBytes>=1e4?" (capped)":""}`:`${e.v2SummaryBytes} UTF-8 bytes`,tone:"muted"}]:[],...D(e,n),{label:"Use memories",value:e.useMemories?"On":"Off",tone:e.useMemories?"ok":"muted"},{label:"Learn from sessions",value:e.generateMemories?"On":"Off",tone:e.generateMemories?"ok":"muted"},...e.sessionMode?[{label:"This session",value:e.sessionMode==="enabled"?e.generateMemories?"Eligible for learning":"Eligible (learning paused)":e.sessionMode==="disabled"?"Not learning":"Excluded (external context)",tone:e.sessionMode==="enabled"&&e.generateMemories?"ok":"muted"}]:[],{label:"Last consolidated",value:e.lastSuccessAt==null?"Never":O(e.lastSuccessAt,n)},...e.retryAt==null?[]:[{label:"Next retry",value:k(e.retryAt,n),tone:"warn"}]]}function V(e,n){const t=e.injected,s=t.sessionRequests>0?Math.round(t.sessionTokens/t.sessionRequests):t.totalRequests>0?Math.round(t.totalTokens/t.totalRequests):0;return[{label:"Block size",value:s?`~${_(s)} tokens / request`:"—"},...n?[{label:"This session",value:`~${_(t.sessionTokens)} tokens · ${t.sessionRequests} req`}]:[],{label:"Since start",value:`~${_(t.totalTokens)} tokens · ${t.totalRequests} req`}]}function W(e){return[{label:"Extraction",value:e.extractModel??"Host default"},{label:"Consolidation",value:e.consolidationModel??"Host default"},{label:"Codex import",value:e.codexImport?"On":"Off",tone:e.codexImport?"ok":"muted"},{label:"Location",value:e.memoryRoot}]}const F=".oc-memory-panel{display:flex;flex-direction:column;block-size:100%;min-block-size:0;color:var(--v2-text-text-base);font-size:13px;line-height:1.45}.oc-memory-panel[data-global]{max-block-size:70dvh}.oc-memory-toolbar{display:flex;flex:none;align-items:center;justify-content:space-between;padding:4px 12px 4px 16px;border-block-end:1px solid var(--v2-border-border-weak);font-weight:500}.oc-memory-body{overflow-y:auto;padding:12px 16px 16px}.oc-memory-body>*+*{margin-block-start:16px}.oc-memory-panel h3,.oc-memory-panel h4{margin-block-end:6px;font-size:inherit;font-weight:600}.oc-memory-panel h4{margin-block-start:10px}.oc-memory-panel p,.oc-memory-panel dt{color:var(--v2-text-text-muted);overflow-wrap:anywhere}.oc-memory-notice{padding:8px;color:var(--v2-text-text-muted)}.oc-memory-control,.oc-memory-values>div{display:flex;align-items:baseline;justify-content:space-between;gap:10px;padding-block:7px;border-block-end:1px solid var(--v2-border-border-weak)}.oc-memory-control{align-items:center;flex-wrap:wrap}.oc-memory-control>:first-child{flex:1 1 9rem}.oc-memory-control>:last-child{flex-shrink:0}.oc-memory-control strong{font-weight:500}.oc-memory-values dd{max-inline-size:60%;margin:0;text-align:end;overflow-wrap:anywhere;-webkit-user-select:text;user-select:text}.oc-memory-values [data-tone=muted]{color:var(--v2-text-text-muted)}.oc-memory-values [data-tone=ok]{color:var(--v2-text-text-feedback-success)}.oc-memory-values [data-tone=warn],.oc-memory-warnings{color:var(--v2-text-text-feedback-warning);overflow-wrap:anywhere}.oc-memory-panel summary{cursor:pointer;font-weight:600}.oc-memory-readiness{margin-block-start:10px}.oc-memory-readiness p{margin-block-start:6px;-webkit-user-select:text;user-select:text}";var H=r.template("<dl class=oc-memory-values>"),G=r.template("<div><dt></dt><dd>"),J=r.template("<div class=oc-memory-control><div><strong></strong><p>"),K=r.template("<p class=oc-memory-notice>Refresh to reconnect."),Q=r.template("<div class=oc-memory-panel><header class=oc-memory-toolbar><div role=status></div></header><div class=oc-memory-body>"),Y=r.template('<section aria-label="Memory controls"><h3>Controls</h3><p>Memory is shared across projects. Global switches last until the server restarts.'),X=r.template("<h4>Attention"),Z=r.template("<ul class=oc-memory-warnings>"),ee=r.template('<section aria-label="Memory status"><h3>Status'),te=r.template("<details><summary>Context usage</summary><p>Token counts are estimates; prompt-cache savings depend on the provider."),re=r.template("<details><summary>Setup"),ne=r.template('<section aria-label="Reset memory">'),oe=r.template("<details class=oc-memory-readiness><summary>V2 readiness details</summary><p>"),se=r.template("<li>"),ie=r.template("<p class=oc-memory-notice>Loading memory…");function I(e,n){const t=e.rpc(P);return{rpc:t,...L(s=>t.status(n?{sessionID:n}:{},{signal:s}),s=>t.events.on("changed",s))}}function A(e){return(()=>{var n=H();return r.insert(n,r.createComponent(u.For,{get each(){return e.rows},children:t=>(()=>{var s=G(),l=s.firstChild,m=l.nextSibling;return r.insert(l,()=>t.label),r.insert(m,()=>t.value),r.effect(()=>r.setAttribute(m,"data-tone",t.tone)),s})()})),n})()}function x(e){return(()=>{var n=J(),t=n.firstChild,s=t.firstChild,l=s.nextSibling;return r.insert(s,()=>e.title),r.insert(l,()=>e.description),r.insert(n,()=>e.children,null),n})()}function q(e){const{ctx:n,watch:t,sessionID:s}=e,l=n.ui,m=u.getOwner(),v=new AbortController,y=AbortSignal.any([v.signal,t.signal]);u.onCleanup(()=>v.abort());const[o,d]=u.createSignal(null),c=()=>t.unavailable()||o()!==null,g=()=>{const b=t.status();return!!b&&U(b)};async function f(b,w,C){if(!(y.aborted||c()||!t.status())){d(b);try{if(b==="resetMemory"){if(!await u.runWithOwner(m,()=>n.dialogs.confirm({title:"Reset memory?",description:"This permanently erases all learned memories and notes across projects and memory versions. Session learning preferences are kept.",confirm:"Reset memory",danger:!0}))||y.aborted||t.unavailable()||g())return;w={confirm:!0}}const h=await t.rpc[b](w,{signal:AbortSignal.any([y,AbortSignal.timeout(5e3)])});if(y.aborted)return;if(b==="consolidateNow"?h?.status!=="started":h?.ok!==!0)throw new Error(h?.message??"The server did not apply the request.");n.toast.show({title:C,variant:"success"}),await t.refresh()}catch(h){if(y.aborted)return;n.toast.show({title:"Memory change failed",description:h instanceof Error?h.message:String(h),variant:"error"}),await t.refresh()}finally{y.aborted||d(null)}}}return(()=>{var b=Q(),w=b.firstChild,C=w.firstChild,h=w.nextSibling;return r.setAttribute(b,"data-global",s===void 0?"":void 0),r.insert(C,(()=>{var a=r.memo(()=>!!t.unavailable());return()=>a()?"Memory unavailable":r.memo(()=>!!t.status())()?j[t.status().activity]:"Loading memory status…"})()),r.insert(w,r.createComponent(l.IconButton,{icon:"outline-rotate-clockwise",label:"Refresh memory status",get busy(){return t.refreshing()},onClick:()=>{t.refresh()}}),null),r.insert(h,r.createComponent(u.Show,{get when(){return t.unavailable()},get children(){var a=K(),i=a.firstChild;return r.insert(a,()=>t.status()?"Showing last known status. ":"",i),a}}),null),r.insert(h,r.createComponent(u.Show,{get when(){return t.status()},children:a=>[(()=>{var i=Y(),M=i.firstChild;return M.nextSibling,r.insert(i,r.createComponent(x,{title:"Use memories",description:"Use the summary and memory lookup tools in conversations.",get children(){return r.createComponent(l.Switch,{hideLabel:!0,label:"Use memories",get checked(){return a().useMemories},get disabled(){return c()},onChange:p=>{f("setOption",{key:"use_memories",value:p},p?"Memory recall turned on.":"Memory recall turned off.")}})}}),null),r.insert(i,r.createComponent(x,{title:"Learn from sessions",description:"Learn from eligible idle conversations.",get children(){return r.createComponent(l.Switch,{hideLabel:!0,label:"Learn from sessions",get checked(){return a().generateMemories},get disabled(){return c()},onChange:p=>{f("setOption",{key:"generate_memories",value:p},p?"Learning resumed.":"Learning paused.")}})}}),null),r.insert(i,r.createComponent(u.Show,{when:s,get children(){return r.createComponent(x,{title:"Learn from this session",get description(){return a().sessionMode==="polluted"?"Excluded after external context. Turning this on allows future learning.":"Saved across restarts; applies when global learning is on."},get children(){return r.createComponent(l.Switch,{hideLabel:!0,label:"Learn from this session",get checked(){return r.memo(()=>a().sessionMode!=="disabled")()&&a().sessionMode!=="polluted"},get disabled(){return c()},onChange:p=>{f("setSessionMode",{sessionID:s,mode:p?"enabled":"disabled"},p?"This session is eligible for learning.":"This session is excluded from learning.")}})}})}}),null),r.insert(i,r.createComponent(x,{title:"Consolidate now",get description(){return r.memo(()=>!!g())()?"Memory work is running. See Status for progress.":a().generateMemories?"Process eligible sessions without waiting for the consolidation cooldown.":"Turn on Learn from sessions first."},get children(){return r.createComponent(l.Button,{size:"small",get disabled(){return c()||g()||!a().generateMemories||a().activity==="stopping"},get busy(){return o()==="consolidateNow"},onClick:()=>{f("consolidateNow",{},"Background run requested.")},children:"Consolidate now"})}}),null),i})(),(()=>{var i=ee();return i.firstChild,r.insert(i,r.createComponent(A,{get rows(){return z(a(),t.updatedAt(),{includeReadinessDiagnostic:!1})}}),null),r.insert(i,r.createComponent(u.Show,{get when(){return a().v2NotReadyReason},children:M=>(()=>{var p=oe(),S=p.firstChild,N=S.nextSibling;return r.insert(N,M),p})()}),null),r.insert(i,r.createComponent(u.Show,{get when(){return a().warnings.length>0},get children(){return[X(),(()=>{var M=Z();return r.insert(M,r.createComponent(u.For,{get each(){return a().warnings},children:p=>(()=>{var S=se();return r.insert(S,p),S})()})),M})()]}}),null),i})(),(()=>{var i=te(),M=i.firstChild,p=M.nextSibling;return r.insert(i,r.createComponent(A,{get rows(){return V(a(),s)}}),p),i})(),(()=>{var i=re();return i.firstChild,r.insert(i,r.createComponent(A,{get rows(){return W(a())}}),null),i})(),(()=>{var i=ne();return r.insert(i,r.createComponent(x,{title:"Reset memory",get description(){return g()?"Wait for the current memory work to finish.":"Erase learned memories and notes."},get children(){return r.createComponent(l.Button,{size:"small",variant:"danger",get disabled(){return c()||g()||a().activity==="stopping"},get busy(){return o()==="resetMemory"},onClick:()=>{f("resetMemory",{},"Memory reset complete.")},children:"Reset memory"})}})),i})()]}),null),b})()}function ae(e){return r.createComponent(u.Show,{keyed:!0,get when(){return e.ctx.client},children:n=>r.createComponent(q,{get ctx(){return e.ctx},get watch(){return I(n)}})})}const le=$.Plugin.define({setup(e){const n={id:"memory",title:"Memory",closable:"compact"},t=`${e.id}:${n.id}`,[s,l]=u.createSignal(),m=o=>o?.server.builtin&&!o.pending;$.createKeyed(()=>{const o=e.sessions.current();return o&&m(o)?{session:o,client:e.client}:void 0},({session:o,client:d})=>{l({session:o,watch:I(d,o.id)}),u.onCleanup(()=>l(void 0))},{equals:(o,d)=>o.session===d.session&&o.client===d.client});const v=o=>{const d=s();if(d?.session.key===o.key&&d.session.directory===o.directory)return d.watch},y=()=>{const o=e.sessions.current();if(o){m(o)&&e.layout.open(t,o);return}e.dialogs.open(()=>r.createComponent(e.ui.Dialog,{title:"Memory",get children(){return r.createComponent(ae,{ctx:e})}}))};e.add($.Style,F),e.add($.Command,()=>({id:"status",title:"Inspect memory",description:"Memory status and controls",group:"Memory",slash:{name:"memory-inspect"},enabled:!e.sessions.current()||m(e.sessions.current()),run:y})),e.add($.Panel,{id:n.id,region:"side",width:408,get mobile(){if(m(e.sessions.current()))return{title:n.title,order:45,kind:"menu",icon:"brain"}},list:({session:o,open:d})=>m(o)&&d.includes(n.id)?[n]:[],render:o=>r.createComponent(u.Show,{keyed:!0,get when(){return v(o.session)},get fallback(){return ie()},children:d=>r.createComponent(q,{ctx:e,watch:d,get sessionID(){return o.session.id}})})}),e.add($.MenuItem,()=>{const o=e.sessions.current();if(!(!o||!m(o)))return{id:"open",menu:"session.panel",title:"Memory",icon:"brain",keybind:`${e.id}.status`,opened:e.layout.state(t,o)!=="closed",run:y}}),e.add($.ComposerPill,{id:"memory",show(o){if(!m(o.session))return;const d=v(o.session),c=d?.status(),g=d?.unavailable(),f=g?"Unavailable":c?`Recall ${c.useMemories?"on":"off"} · learn ${c.generateMemories?"on":"off"}`:"Loading…";return{label:`Memory · ${f}`,title:`Inspect memory · ${f}`,icon:"brain",tone:g?"danger":c?.useMemories||c?.generateMemories?"success":void 0,run:y}}})}});exports.default=le;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PluginInput, PluginOptions } from "@opencode-ai/plugin";
|
|
1
|
+
import type { PluginInput, PluginOptions, ToolDefinition } from "@opencode-ai/plugin";
|
|
2
2
|
/** Test seam: wait for all hook-launched work, including follow-up phase 2. */
|
|
3
3
|
export declare function waitForBackgroundTasks(): Promise<void>;
|
|
4
4
|
/**
|
|
@@ -20,149 +20,6 @@ declare const _default: {
|
|
|
20
20
|
setup: typeof setupV2;
|
|
21
21
|
server(input: PluginInput, opts?: PluginOptions): Promise<{
|
|
22
22
|
dispose(): Promise<void>;
|
|
23
|
-
tool: {
|
|
24
|
-
memory_read: {
|
|
25
|
-
description: string;
|
|
26
|
-
args: {
|
|
27
|
-
path: import("zod").ZodString;
|
|
28
|
-
line_offset: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
29
|
-
max_lines: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
30
|
-
};
|
|
31
|
-
execute(args: {
|
|
32
|
-
path: string;
|
|
33
|
-
line_offset?: number | undefined;
|
|
34
|
-
max_lines?: number | undefined;
|
|
35
|
-
}, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
|
|
36
|
-
};
|
|
37
|
-
memory_search: {
|
|
38
|
-
description: string;
|
|
39
|
-
args: {
|
|
40
|
-
queries: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
|
|
41
|
-
match_mode: import("zod").ZodDefault<import("zod").ZodEnum<{
|
|
42
|
-
any: "any";
|
|
43
|
-
all_on_same_line: "all_on_same_line";
|
|
44
|
-
all_within_lines: "all_within_lines";
|
|
45
|
-
}>>;
|
|
46
|
-
line_count: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
47
|
-
path: import("zod").ZodOptional<import("zod").ZodString>;
|
|
48
|
-
cursor: import("zod").ZodOptional<import("zod").ZodString>;
|
|
49
|
-
context_lines: import("zod").ZodDefault<import("zod").ZodNumber>;
|
|
50
|
-
case_sensitive: import("zod").ZodDefault<import("zod").ZodBoolean>;
|
|
51
|
-
normalized: import("zod").ZodDefault<import("zod").ZodBoolean>;
|
|
52
|
-
since: import("zod").ZodOptional<import("zod").ZodString>;
|
|
53
|
-
until: import("zod").ZodOptional<import("zod").ZodString>;
|
|
54
|
-
max_results: import("zod").ZodDefault<import("zod").ZodNumber>;
|
|
55
|
-
};
|
|
56
|
-
execute(args: {
|
|
57
|
-
match_mode: "any" | "all_on_same_line" | "all_within_lines";
|
|
58
|
-
context_lines: number;
|
|
59
|
-
case_sensitive: boolean;
|
|
60
|
-
normalized: boolean;
|
|
61
|
-
max_results: number;
|
|
62
|
-
queries?: string[] | undefined;
|
|
63
|
-
line_count?: number | undefined;
|
|
64
|
-
path?: string | undefined;
|
|
65
|
-
cursor?: string | undefined;
|
|
66
|
-
since?: string | undefined;
|
|
67
|
-
until?: string | undefined;
|
|
68
|
-
}, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
|
|
69
|
-
};
|
|
70
|
-
memory_list: {
|
|
71
|
-
description: string;
|
|
72
|
-
args: {
|
|
73
|
-
path: import("zod").ZodDefault<import("zod").ZodString>;
|
|
74
|
-
cursor: import("zod").ZodOptional<import("zod").ZodString>;
|
|
75
|
-
max_results: import("zod").ZodDefault<import("zod").ZodNumber>;
|
|
76
|
-
};
|
|
77
|
-
execute(args: {
|
|
78
|
-
path: string;
|
|
79
|
-
max_results: number;
|
|
80
|
-
cursor?: string | undefined;
|
|
81
|
-
}, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
|
|
82
|
-
};
|
|
83
|
-
memory_add_note: {
|
|
84
|
-
description: string;
|
|
85
|
-
args: {
|
|
86
|
-
note: import("zod").ZodString;
|
|
87
|
-
title: import("zod").ZodOptional<import("zod").ZodString>;
|
|
88
|
-
};
|
|
89
|
-
execute(args: {
|
|
90
|
-
note: string;
|
|
91
|
-
title?: string | undefined;
|
|
92
|
-
}, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
|
|
93
|
-
};
|
|
94
|
-
memory_reset: {
|
|
95
|
-
description: string;
|
|
96
|
-
args: {
|
|
97
|
-
confirm: import("zod").ZodBoolean;
|
|
98
|
-
};
|
|
99
|
-
execute(args: {
|
|
100
|
-
confirm: boolean;
|
|
101
|
-
}, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
|
|
102
|
-
};
|
|
103
|
-
memory_inspect: {
|
|
104
|
-
description: string;
|
|
105
|
-
args: {
|
|
106
|
-
min_consolidated_threads: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
107
|
-
};
|
|
108
|
-
execute(args: {
|
|
109
|
-
min_consolidated_threads?: number | undefined;
|
|
110
|
-
}, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
|
|
111
|
-
};
|
|
112
|
-
memory_mode: {
|
|
113
|
-
description: string;
|
|
114
|
-
args: {
|
|
115
|
-
mode: import("zod").ZodEnum<{
|
|
116
|
-
enabled: "enabled";
|
|
117
|
-
disabled: "disabled";
|
|
118
|
-
polluted: "polluted";
|
|
119
|
-
}>;
|
|
120
|
-
sessionId: import("zod").ZodOptional<import("zod").ZodString>;
|
|
121
|
-
};
|
|
122
|
-
execute(args: {
|
|
123
|
-
mode: "enabled" | "disabled" | "polluted";
|
|
124
|
-
sessionId?: string | undefined;
|
|
125
|
-
}, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
|
|
126
|
-
};
|
|
127
|
-
} | {
|
|
128
|
-
memory_reset: {
|
|
129
|
-
description: string;
|
|
130
|
-
args: {
|
|
131
|
-
confirm: import("zod").ZodBoolean;
|
|
132
|
-
};
|
|
133
|
-
execute(args: {
|
|
134
|
-
confirm: boolean;
|
|
135
|
-
}, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
|
|
136
|
-
};
|
|
137
|
-
memory_inspect: {
|
|
138
|
-
description: string;
|
|
139
|
-
args: {
|
|
140
|
-
min_consolidated_threads: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
141
|
-
};
|
|
142
|
-
execute(args: {
|
|
143
|
-
min_consolidated_threads?: number | undefined;
|
|
144
|
-
}, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
|
|
145
|
-
};
|
|
146
|
-
memory_mode: {
|
|
147
|
-
description: string;
|
|
148
|
-
args: {
|
|
149
|
-
mode: import("zod").ZodEnum<{
|
|
150
|
-
enabled: "enabled";
|
|
151
|
-
disabled: "disabled";
|
|
152
|
-
polluted: "polluted";
|
|
153
|
-
}>;
|
|
154
|
-
sessionId: import("zod").ZodOptional<import("zod").ZodString>;
|
|
155
|
-
};
|
|
156
|
-
execute(args: {
|
|
157
|
-
mode: "enabled" | "disabled" | "polluted";
|
|
158
|
-
sessionId?: string | undefined;
|
|
159
|
-
}, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
|
|
160
|
-
};
|
|
161
|
-
memory_read?: undefined;
|
|
162
|
-
memory_search?: undefined;
|
|
163
|
-
memory_list?: undefined;
|
|
164
|
-
memory_add_note?: undefined;
|
|
165
|
-
};
|
|
166
23
|
config(input: {
|
|
167
24
|
agent?: Record<string, unknown>;
|
|
168
25
|
}): Promise<void>;
|
|
@@ -239,6 +96,7 @@ declare const _default: {
|
|
|
239
96
|
properties: unknown;
|
|
240
97
|
};
|
|
241
98
|
}): Promise<void>;
|
|
99
|
+
tool: MemoryTools;
|
|
242
100
|
}>;
|
|
243
101
|
};
|
|
244
102
|
export default _default;
|
|
@@ -261,3 +119,4 @@ export declare function applyPluginOptions(opts: PluginOptions, { modelFallback
|
|
|
261
119
|
export declare function injectAgentDefinitions(config: {
|
|
262
120
|
agent?: Record<string, unknown>;
|
|
263
121
|
}): void;
|
|
122
|
+
type MemoryTools = Record<"memory_reset" | "memory_inspect" | "memory_mode", ToolDefinition> & Partial<Record<"memory_read" | "memory_search" | "memory_list" | "memory_add_note", ToolDefinition>>;
|
|
@@ -17,6 +17,12 @@ export function isModelSelectionUnavailable(error, model) {
|
|
|
17
17
|
const tag = current._tag ?? current.name;
|
|
18
18
|
if (["InvalidRequestError", "Generate.ModelSelectionError"].includes(tag) && current.message === message)
|
|
19
19
|
return true;
|
|
20
|
+
// OpenCode 2.4 reports missing explicit models separately from provider failures.
|
|
21
|
+
if (model &&
|
|
22
|
+
(tag === "ModelNotFoundError" || tag === "Generate.ModelNotFoundError") &&
|
|
23
|
+
current.providerID === model.providerID &&
|
|
24
|
+
current.modelID === model.id)
|
|
25
|
+
return true;
|
|
20
26
|
if (tag === "ServiceUnavailableError" &&
|
|
21
27
|
current.service === "plugin" &&
|
|
22
28
|
current.message === PLUGIN_ACTIVATION_PENDING)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type MemoryStatus } from "./status-rpc.js";
|
|
2
|
+
export declare const activityLabels: Record<MemoryStatus["activity"], string>;
|
|
3
|
+
/** Keep the last good snapshot on disconnect; ignore late replies and abort on close. */
|
|
4
|
+
export declare function watchMemoryStatus(read: (signal: AbortSignal) => Promise<unknown>, subscribe: (listener: () => void) => () => void): {
|
|
5
|
+
status: import("solid-js").Accessor<MemoryStatus | null>;
|
|
6
|
+
unavailable: import("solid-js").Accessor<boolean>;
|
|
7
|
+
refreshing: import("solid-js").Accessor<boolean>;
|
|
8
|
+
updatedAt: import("solid-js").Accessor<number>;
|
|
9
|
+
refresh: () => Promise<void>;
|
|
10
|
+
signal: AbortSignal;
|
|
11
|
+
};
|
|
12
|
+
export declare function isMemoryRunning(status: MemoryStatus): boolean;
|
|
13
|
+
export type StatusRow = {
|
|
14
|
+
label: string;
|
|
15
|
+
value: string;
|
|
16
|
+
tone?: "ok" | "warn" | "muted";
|
|
17
|
+
};
|
|
18
|
+
export declare function statusRows(s: MemoryStatus, now: number, { includeReadinessDiagnostic }?: {
|
|
19
|
+
includeReadinessDiagnostic?: boolean | undefined;
|
|
20
|
+
}): StatusRow[];
|
|
21
|
+
export declare function usageRows(s: MemoryStatus, sessionID?: string): StatusRow[];
|
|
22
|
+
export declare function configRows(s: MemoryStatus): StatusRow[];
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import { createSignal, onCleanup } from "solid-js";
|
|
2
|
+
import { isMemoryStatus } from "./status-rpc.js";
|
|
3
|
+
export const activityLabels = {
|
|
4
|
+
idle: "Idle",
|
|
5
|
+
extracting: "Extracting",
|
|
6
|
+
consolidating: "Consolidating",
|
|
7
|
+
retrying: "Waiting to retry",
|
|
8
|
+
error: "Needs attention",
|
|
9
|
+
read_only: "Read only",
|
|
10
|
+
disabled: "Disabled",
|
|
11
|
+
stopping: "Stopping",
|
|
12
|
+
};
|
|
13
|
+
/** Keep the last good snapshot on disconnect; ignore late replies and abort on close. */
|
|
14
|
+
export function watchMemoryStatus(read, subscribe) {
|
|
15
|
+
const [status, setStatus] = createSignal(null);
|
|
16
|
+
const [unavailable, setUnavailable] = createSignal(false);
|
|
17
|
+
const [refreshing, setRefreshing] = createSignal(false);
|
|
18
|
+
const [updatedAt, setUpdatedAt] = createSignal(Date.now());
|
|
19
|
+
const lifetime = new AbortController();
|
|
20
|
+
let revision = 0;
|
|
21
|
+
const refresh = async () => {
|
|
22
|
+
const request = ++revision;
|
|
23
|
+
setRefreshing(true);
|
|
24
|
+
try {
|
|
25
|
+
const next = await read(AbortSignal.any([lifetime.signal, AbortSignal.timeout(5_000)]));
|
|
26
|
+
if (lifetime.signal.aborted || request !== revision)
|
|
27
|
+
return;
|
|
28
|
+
if (!isMemoryStatus(next))
|
|
29
|
+
throw new Error("invalid memory status payload");
|
|
30
|
+
setStatus(next);
|
|
31
|
+
setUpdatedAt(Date.now());
|
|
32
|
+
setUnavailable(false);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
if (!lifetime.signal.aborted && request === revision)
|
|
36
|
+
setUnavailable(true);
|
|
37
|
+
}
|
|
38
|
+
finally {
|
|
39
|
+
if (!lifetime.signal.aborted && request === revision)
|
|
40
|
+
setRefreshing(false);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const unsubscribe = subscribe(() => void refresh());
|
|
44
|
+
const timer = setInterval(() => void refresh(), 30_000);
|
|
45
|
+
onCleanup(() => {
|
|
46
|
+
lifetime.abort();
|
|
47
|
+
clearInterval(timer);
|
|
48
|
+
unsubscribe();
|
|
49
|
+
});
|
|
50
|
+
void refresh();
|
|
51
|
+
return { status, unavailable, refreshing, updatedAt, refresh, signal: lifetime.signal };
|
|
52
|
+
}
|
|
53
|
+
export function isMemoryRunning(status) {
|
|
54
|
+
return (status.activity === "consolidating" ||
|
|
55
|
+
status.activity === "extracting" ||
|
|
56
|
+
status.pipelines.some((pipeline) => pipeline.extracting > 0 || pipeline.phase2Status === "running"));
|
|
57
|
+
}
|
|
58
|
+
function elapsed(time, now) {
|
|
59
|
+
const minutes = Math.max(0, Math.floor((now - time) / 60_000));
|
|
60
|
+
if (minutes === 0)
|
|
61
|
+
return "just now";
|
|
62
|
+
if (minutes < 60)
|
|
63
|
+
return `${minutes}m ago`;
|
|
64
|
+
if (minutes < 1440)
|
|
65
|
+
return `${Math.floor(minutes / 60)}h ago`;
|
|
66
|
+
return `${Math.floor(minutes / 1440)}d ago`;
|
|
67
|
+
}
|
|
68
|
+
function remaining(time, now) {
|
|
69
|
+
if (time == null)
|
|
70
|
+
return "—";
|
|
71
|
+
const minutes = Math.max(0, Math.ceil((time - now) / 60_000));
|
|
72
|
+
if (minutes < 1)
|
|
73
|
+
return "in <1m";
|
|
74
|
+
if (minutes < 60)
|
|
75
|
+
return `in ${minutes}m`;
|
|
76
|
+
if (minutes < 1440)
|
|
77
|
+
return `in ${Math.floor(minutes / 60)}h ${minutes % 60}m`;
|
|
78
|
+
return `in ${Math.floor(minutes / 1440)}d`;
|
|
79
|
+
}
|
|
80
|
+
function formatTokens(n) {
|
|
81
|
+
if (n >= 1_000_000)
|
|
82
|
+
return `${(n / 1_000_000).toFixed(1)}M`;
|
|
83
|
+
if (n >= 1_000)
|
|
84
|
+
return `${(n / 1_000).toFixed(1)}K`;
|
|
85
|
+
return String(n);
|
|
86
|
+
}
|
|
87
|
+
function pipelineRows(s, now) {
|
|
88
|
+
return s.pipelines.flatMap((pipeline) => {
|
|
89
|
+
const version = pipeline.version.toUpperCase();
|
|
90
|
+
const paused = !s.generateMemories || (!s.dualWrite && pipeline.version !== s.version);
|
|
91
|
+
const extractionRetry = pipeline.phase1RetryAt != null && pipeline.phase1RetryAt > now;
|
|
92
|
+
const consolidationRetry = pipeline.phase2RetryAt != null && pipeline.phase2RetryAt > now;
|
|
93
|
+
const cooldown = pipeline.phase2CooldownUntil != null && pipeline.phase2CooldownUntil > now;
|
|
94
|
+
const consolidation = pipeline.phase2Status === "pending" ? "Queued" : pipeline.phase2Status === "failed" ? "Retry due" : "Idle";
|
|
95
|
+
return [
|
|
96
|
+
{ label: `${version} recaps`, value: `${pipeline.stage1Count} stored`, tone: "muted" },
|
|
97
|
+
{
|
|
98
|
+
label: `${version} extraction`,
|
|
99
|
+
value: pipeline.extracting
|
|
100
|
+
? `Running (${pipeline.extracting})`
|
|
101
|
+
: paused
|
|
102
|
+
? "Paused"
|
|
103
|
+
: extractionRetry
|
|
104
|
+
? `Retry ${remaining(pipeline.phase1RetryAt, now)}`
|
|
105
|
+
: "Idle",
|
|
106
|
+
tone: extractionRetry && !paused ? "warn" : "muted",
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
label: `${version} consolidation`,
|
|
110
|
+
value: pipeline.phase2Status === "running"
|
|
111
|
+
? "Running"
|
|
112
|
+
: paused
|
|
113
|
+
? "Paused"
|
|
114
|
+
: consolidationRetry
|
|
115
|
+
? `Retry ${remaining(pipeline.phase2RetryAt, now)}`
|
|
116
|
+
: cooldown
|
|
117
|
+
? `${consolidation} · cooldown ends ${remaining(pipeline.phase2CooldownUntil, now)}`
|
|
118
|
+
: pipeline.phase2Status === "pending"
|
|
119
|
+
? "Queued · next activity"
|
|
120
|
+
: consolidation,
|
|
121
|
+
tone: pipeline.lastError ? "warn" : "muted",
|
|
122
|
+
},
|
|
123
|
+
...(pipeline.lastError
|
|
124
|
+
? [{ label: `${version} last error`, value: pipeline.lastError, tone: "warn" }]
|
|
125
|
+
: []),
|
|
126
|
+
];
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
export function statusRows(s, now, { includeReadinessDiagnostic = true } = {}) {
|
|
130
|
+
return [
|
|
131
|
+
{ label: "Activity", value: activityLabels[s.activity] },
|
|
132
|
+
{ label: "Memory version", value: `${s.sessionVersion} (default ${s.version})` },
|
|
133
|
+
{ label: "Learning pipelines", value: s.dualWrite ? "v1 + v2" : s.version },
|
|
134
|
+
{
|
|
135
|
+
label: "V2 readiness",
|
|
136
|
+
value: `${s.v2Ready ? "Ready" : "Not ready"} · ${s.v2ConsolidatedThreads}/${s.minConsolidatedThreads} sessions`,
|
|
137
|
+
tone: s.v2Ready ? "ok" : "muted",
|
|
138
|
+
},
|
|
139
|
+
...(includeReadinessDiagnostic && s.v2NotReadyReason
|
|
140
|
+
? [{ label: "V2 not ready", value: s.v2NotReadyReason, tone: "muted" }]
|
|
141
|
+
: []),
|
|
142
|
+
...(s.v2SummaryBytes !== undefined
|
|
143
|
+
? [
|
|
144
|
+
{
|
|
145
|
+
label: "V2 summary",
|
|
146
|
+
value: s.v2SummaryBytes === null
|
|
147
|
+
? "Unreadable"
|
|
148
|
+
: s.v2InjectedSummaryBytes != null
|
|
149
|
+
? `${s.v2SummaryBytes} bytes on disk · ${s.v2InjectedSummaryBytes} injected${s.v2SummaryBytes >= 10000 ? " (capped)" : ""}`
|
|
150
|
+
: `${s.v2SummaryBytes} UTF-8 bytes`,
|
|
151
|
+
tone: "muted",
|
|
152
|
+
},
|
|
153
|
+
]
|
|
154
|
+
: []),
|
|
155
|
+
...pipelineRows(s, now),
|
|
156
|
+
{ label: "Use memories", value: s.useMemories ? "On" : "Off", tone: s.useMemories ? "ok" : "muted" },
|
|
157
|
+
{
|
|
158
|
+
label: "Learn from sessions",
|
|
159
|
+
value: s.generateMemories ? "On" : "Off",
|
|
160
|
+
tone: s.generateMemories ? "ok" : "muted",
|
|
161
|
+
},
|
|
162
|
+
...(s.sessionMode
|
|
163
|
+
? [
|
|
164
|
+
{
|
|
165
|
+
label: "This session",
|
|
166
|
+
value: s.sessionMode === "enabled"
|
|
167
|
+
? s.generateMemories
|
|
168
|
+
? "Eligible for learning"
|
|
169
|
+
: "Eligible (learning paused)"
|
|
170
|
+
: s.sessionMode === "disabled"
|
|
171
|
+
? "Not learning"
|
|
172
|
+
: "Excluded (external context)",
|
|
173
|
+
tone: (s.sessionMode === "enabled" && s.generateMemories ? "ok" : "muted"),
|
|
174
|
+
},
|
|
175
|
+
]
|
|
176
|
+
: []),
|
|
177
|
+
{ label: "Last consolidated", value: s.lastSuccessAt == null ? "Never" : elapsed(s.lastSuccessAt, now) },
|
|
178
|
+
...(s.retryAt == null ? [] : [{ label: "Next retry", value: remaining(s.retryAt, now), tone: "warn" }]),
|
|
179
|
+
];
|
|
180
|
+
}
|
|
181
|
+
export function usageRows(s, sessionID) {
|
|
182
|
+
const inj = s.injected;
|
|
183
|
+
const per = inj.sessionRequests > 0
|
|
184
|
+
? Math.round(inj.sessionTokens / inj.sessionRequests)
|
|
185
|
+
: inj.totalRequests > 0
|
|
186
|
+
? Math.round(inj.totalTokens / inj.totalRequests)
|
|
187
|
+
: 0;
|
|
188
|
+
return [
|
|
189
|
+
{ label: "Block size", value: per ? `~${formatTokens(per)} tokens / request` : "—" },
|
|
190
|
+
...(sessionID
|
|
191
|
+
? [{ label: "This session", value: `~${formatTokens(inj.sessionTokens)} tokens · ${inj.sessionRequests} req` }]
|
|
192
|
+
: []),
|
|
193
|
+
{ label: "Since start", value: `~${formatTokens(inj.totalTokens)} tokens · ${inj.totalRequests} req` },
|
|
194
|
+
];
|
|
195
|
+
}
|
|
196
|
+
export function configRows(s) {
|
|
197
|
+
return [
|
|
198
|
+
{ label: "Extraction", value: s.extractModel ?? "Host default" },
|
|
199
|
+
{ label: "Consolidation", value: s.consolidationModel ?? "Host default" },
|
|
200
|
+
{ label: "Codex import", value: s.codexImport ? "On" : "Off", tone: s.codexImport ? "ok" : "muted" },
|
|
201
|
+
{ label: "Location", value: s.memoryRoot },
|
|
202
|
+
];
|
|
203
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shared server↔
|
|
2
|
+
* Shared server↔UI wire contract for the memory panels.
|
|
3
3
|
*
|
|
4
4
|
* Dependency-free on purpose: the TUI bundle runs in the CLI sandbox, where
|
|
5
5
|
* only `@opencode/plugin/tui` (+ rendering peers) is guaranteed to resolve.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Shared server↔
|
|
2
|
+
* Shared server↔UI wire contract for the memory panels.
|
|
3
3
|
*
|
|
4
4
|
* Dependency-free on purpose: the TUI bundle runs in the CLI sandbox, where
|
|
5
5
|
* only `@opencode/plugin/tui` (+ rendering peers) is guaranteed to resolve.
|
package/dist/src/v2/tools.d.ts
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The memory tools' logic lives in tools/*.ts (V1 tool() definitions) and is
|
|
5
5
|
* reused verbatim: each V1 definition already bundles {description, args
|
|
6
|
-
* (
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* (Zod raw shape), execute}. Wrap that shape using the SDK's own tool.schema:
|
|
7
|
+
* its Zod objects implement StandardSchema, which V2 accepts directly.
|
|
8
|
+
* Keep version ownership in the SDK, then map only the result shape:
|
|
9
9
|
* V1 string | {output, metadata} → V2 {content, metadata}
|
|
10
10
|
* Inspect additionally reports the V2 host discovery scope and fallback reason.
|
|
11
11
|
*/
|
|
12
|
-
import {
|
|
12
|
+
import { tool } from "@opencode-ai/plugin";
|
|
13
13
|
type CallContext = {
|
|
14
14
|
sessionID: string;
|
|
15
15
|
messageID: string;
|
|
@@ -25,7 +25,7 @@ type Ask = (ctx: CallContext, request: {
|
|
|
25
25
|
interface V2ToolDefinition {
|
|
26
26
|
name: string;
|
|
27
27
|
description: string;
|
|
28
|
-
input:
|
|
28
|
+
input: ReturnType<typeof tool.schema.object>;
|
|
29
29
|
/**
|
|
30
30
|
* OpenCode 2 defaults plugin tools into Code Mode (`execute`). The read-path
|
|
31
31
|
* prompt tells the model to call these by name. Leaving the default hides
|
package/dist/src/v2/tools.js
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The memory tools' logic lives in tools/*.ts (V1 tool() definitions) and is
|
|
5
5
|
* reused verbatim: each V1 definition already bundles {description, args
|
|
6
|
-
* (
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* (Zod raw shape), execute}. Wrap that shape using the SDK's own tool.schema:
|
|
7
|
+
* its Zod objects implement StandardSchema, which V2 accepts directly.
|
|
8
|
+
* Keep version ownership in the SDK, then map only the result shape:
|
|
9
9
|
* V1 string | {output, metadata} → V2 {content, metadata}
|
|
10
10
|
* Inspect additionally reports the V2 host discovery scope and fallback reason.
|
|
11
11
|
*/
|
|
12
|
-
import {
|
|
12
|
+
import { tool } from "@opencode-ai/plugin";
|
|
13
13
|
import { memory_read, memory_search, memory_list, memory_add_note } from "../../tools/memory.js";
|
|
14
14
|
import { memory_inspect, memory_mode } from "../../tools/control.js";
|
|
15
15
|
import { pluginOptions } from "../options.js";
|
|
@@ -18,7 +18,7 @@ function adaptTool(name, v1, ask) {
|
|
|
18
18
|
return {
|
|
19
19
|
name,
|
|
20
20
|
description: v1.description,
|
|
21
|
-
input:
|
|
21
|
+
input: tool.schema.object(v1.args),
|
|
22
22
|
options: { codemode: false },
|
|
23
23
|
async execute(input, tctx) {
|
|
24
24
|
const v1ctx = {
|
package/dist/src/v2/tui.js
CHANGED
|
@@ -11,7 +11,7 @@ import { createElement as _$createElement } from "@opentui/solid";
|
|
|
11
11
|
import { createComponent as _$createComponent } from "@opentui/solid";
|
|
12
12
|
import { Plugin } from "@opencode/plugin/tui";
|
|
13
13
|
import { useTerminalDimensions } from "@opentui/solid";
|
|
14
|
-
import { createSignal
|
|
14
|
+
import { createSignal as createSignal2, For } from "solid-js";
|
|
15
15
|
|
|
16
16
|
// src/v2/status-rpc.ts
|
|
17
17
|
var MEMORY_STATUS_ACTIVITIES = [
|
|
@@ -231,8 +231,9 @@ function isMemoryStatus(value) {
|
|
|
231
231
|
return true;
|
|
232
232
|
}
|
|
233
233
|
|
|
234
|
-
// src/v2/
|
|
235
|
-
|
|
234
|
+
// src/v2/panel-status.ts
|
|
235
|
+
import { createSignal, onCleanup } from "solid-js";
|
|
236
|
+
var activityLabels = {
|
|
236
237
|
idle: "Idle",
|
|
237
238
|
extracting: "Extracting",
|
|
238
239
|
consolidating: "Consolidating",
|
|
@@ -242,9 +243,47 @@ var labels = {
|
|
|
242
243
|
disabled: "Disabled",
|
|
243
244
|
stopping: "Stopping"
|
|
244
245
|
};
|
|
246
|
+
function watchMemoryStatus(read, subscribe) {
|
|
247
|
+
const [status, setStatus] = createSignal(null);
|
|
248
|
+
const [unavailable, setUnavailable] = createSignal(false);
|
|
249
|
+
const [refreshing, setRefreshing] = createSignal(false);
|
|
250
|
+
const [updatedAt, setUpdatedAt] = createSignal(Date.now());
|
|
251
|
+
const lifetime = new AbortController;
|
|
252
|
+
let revision = 0;
|
|
253
|
+
const refresh = async () => {
|
|
254
|
+
const request = ++revision;
|
|
255
|
+
setRefreshing(true);
|
|
256
|
+
try {
|
|
257
|
+
const next = await read(AbortSignal.any([lifetime.signal, AbortSignal.timeout(5000)]));
|
|
258
|
+
if (lifetime.signal.aborted || request !== revision)
|
|
259
|
+
return;
|
|
260
|
+
if (!isMemoryStatus(next))
|
|
261
|
+
throw new Error("invalid memory status payload");
|
|
262
|
+
setStatus(next);
|
|
263
|
+
setUpdatedAt(Date.now());
|
|
264
|
+
setUnavailable(false);
|
|
265
|
+
} catch {
|
|
266
|
+
if (!lifetime.signal.aborted && request === revision)
|
|
267
|
+
setUnavailable(true);
|
|
268
|
+
} finally {
|
|
269
|
+
if (!lifetime.signal.aborted && request === revision)
|
|
270
|
+
setRefreshing(false);
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
const unsubscribe = subscribe(() => void refresh());
|
|
274
|
+
const timer = setInterval(() => void refresh(), 30000);
|
|
275
|
+
onCleanup(() => {
|
|
276
|
+
lifetime.abort();
|
|
277
|
+
clearInterval(timer);
|
|
278
|
+
unsubscribe();
|
|
279
|
+
});
|
|
280
|
+
refresh();
|
|
281
|
+
return { status, unavailable, refreshing, updatedAt, refresh, signal: lifetime.signal };
|
|
282
|
+
}
|
|
283
|
+
function isMemoryRunning(status) {
|
|
284
|
+
return status.activity === "consolidating" || status.activity === "extracting" || status.pipelines.some((pipeline) => pipeline.extracting > 0 || pipeline.phase2Status === "running");
|
|
285
|
+
}
|
|
245
286
|
function elapsed(time, now) {
|
|
246
|
-
if (time == null)
|
|
247
|
-
return "\u2014";
|
|
248
287
|
const minutes = Math.max(0, Math.floor((now - time) / 60000));
|
|
249
288
|
if (minutes === 0)
|
|
250
289
|
return "just now";
|
|
@@ -266,6 +305,92 @@ function remaining(time, now) {
|
|
|
266
305
|
return `in ${Math.floor(minutes / 60)}h ${minutes % 60}m`;
|
|
267
306
|
return `in ${Math.floor(minutes / 1440)}d`;
|
|
268
307
|
}
|
|
308
|
+
function formatTokens(n) {
|
|
309
|
+
if (n >= 1e6)
|
|
310
|
+
return `${(n / 1e6).toFixed(1)}M`;
|
|
311
|
+
if (n >= 1000)
|
|
312
|
+
return `${(n / 1000).toFixed(1)}K`;
|
|
313
|
+
return String(n);
|
|
314
|
+
}
|
|
315
|
+
function pipelineRows(s, now) {
|
|
316
|
+
return s.pipelines.flatMap((pipeline) => {
|
|
317
|
+
const version = pipeline.version.toUpperCase();
|
|
318
|
+
const paused = !s.generateMemories || !s.dualWrite && pipeline.version !== s.version;
|
|
319
|
+
const extractionRetry = pipeline.phase1RetryAt != null && pipeline.phase1RetryAt > now;
|
|
320
|
+
const consolidationRetry = pipeline.phase2RetryAt != null && pipeline.phase2RetryAt > now;
|
|
321
|
+
const cooldown = pipeline.phase2CooldownUntil != null && pipeline.phase2CooldownUntil > now;
|
|
322
|
+
const consolidation = pipeline.phase2Status === "pending" ? "Queued" : pipeline.phase2Status === "failed" ? "Retry due" : "Idle";
|
|
323
|
+
return [
|
|
324
|
+
{ label: `${version} recaps`, value: `${pipeline.stage1Count} stored`, tone: "muted" },
|
|
325
|
+
{
|
|
326
|
+
label: `${version} extraction`,
|
|
327
|
+
value: pipeline.extracting ? `Running (${pipeline.extracting})` : paused ? "Paused" : extractionRetry ? `Retry ${remaining(pipeline.phase1RetryAt, now)}` : "Idle",
|
|
328
|
+
tone: extractionRetry && !paused ? "warn" : "muted"
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
label: `${version} consolidation`,
|
|
332
|
+
value: pipeline.phase2Status === "running" ? "Running" : paused ? "Paused" : consolidationRetry ? `Retry ${remaining(pipeline.phase2RetryAt, now)}` : cooldown ? `${consolidation} \xB7 cooldown ends ${remaining(pipeline.phase2CooldownUntil, now)}` : pipeline.phase2Status === "pending" ? "Queued \xB7 next activity" : consolidation,
|
|
333
|
+
tone: pipeline.lastError ? "warn" : "muted"
|
|
334
|
+
},
|
|
335
|
+
...pipeline.lastError ? [{ label: `${version} last error`, value: pipeline.lastError, tone: "warn" }] : []
|
|
336
|
+
];
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
function statusRows(s, now, { includeReadinessDiagnostic = true } = {}) {
|
|
340
|
+
return [
|
|
341
|
+
{ label: "Activity", value: activityLabels[s.activity] },
|
|
342
|
+
{ label: "Memory version", value: `${s.sessionVersion} (default ${s.version})` },
|
|
343
|
+
{ label: "Learning pipelines", value: s.dualWrite ? "v1 + v2" : s.version },
|
|
344
|
+
{
|
|
345
|
+
label: "V2 readiness",
|
|
346
|
+
value: `${s.v2Ready ? "Ready" : "Not ready"} \xB7 ${s.v2ConsolidatedThreads}/${s.minConsolidatedThreads} sessions`,
|
|
347
|
+
tone: s.v2Ready ? "ok" : "muted"
|
|
348
|
+
},
|
|
349
|
+
...includeReadinessDiagnostic && s.v2NotReadyReason ? [{ label: "V2 not ready", value: s.v2NotReadyReason, tone: "muted" }] : [],
|
|
350
|
+
...s.v2SummaryBytes !== undefined ? [
|
|
351
|
+
{
|
|
352
|
+
label: "V2 summary",
|
|
353
|
+
value: s.v2SummaryBytes === null ? "Unreadable" : s.v2InjectedSummaryBytes != null ? `${s.v2SummaryBytes} bytes on disk \xB7 ${s.v2InjectedSummaryBytes} injected${s.v2SummaryBytes >= 1e4 ? " (capped)" : ""}` : `${s.v2SummaryBytes} UTF-8 bytes`,
|
|
354
|
+
tone: "muted"
|
|
355
|
+
}
|
|
356
|
+
] : [],
|
|
357
|
+
...pipelineRows(s, now),
|
|
358
|
+
{ label: "Use memories", value: s.useMemories ? "On" : "Off", tone: s.useMemories ? "ok" : "muted" },
|
|
359
|
+
{
|
|
360
|
+
label: "Learn from sessions",
|
|
361
|
+
value: s.generateMemories ? "On" : "Off",
|
|
362
|
+
tone: s.generateMemories ? "ok" : "muted"
|
|
363
|
+
},
|
|
364
|
+
...s.sessionMode ? [
|
|
365
|
+
{
|
|
366
|
+
label: "This session",
|
|
367
|
+
value: s.sessionMode === "enabled" ? s.generateMemories ? "Eligible for learning" : "Eligible (learning paused)" : s.sessionMode === "disabled" ? "Not learning" : "Excluded (external context)",
|
|
368
|
+
tone: s.sessionMode === "enabled" && s.generateMemories ? "ok" : "muted"
|
|
369
|
+
}
|
|
370
|
+
] : [],
|
|
371
|
+
{ label: "Last consolidated", value: s.lastSuccessAt == null ? "Never" : elapsed(s.lastSuccessAt, now) },
|
|
372
|
+
...s.retryAt == null ? [] : [{ label: "Next retry", value: remaining(s.retryAt, now), tone: "warn" }]
|
|
373
|
+
];
|
|
374
|
+
}
|
|
375
|
+
function usageRows(s, sessionID) {
|
|
376
|
+
const inj = s.injected;
|
|
377
|
+
const per = inj.sessionRequests > 0 ? Math.round(inj.sessionTokens / inj.sessionRequests) : inj.totalRequests > 0 ? Math.round(inj.totalTokens / inj.totalRequests) : 0;
|
|
378
|
+
return [
|
|
379
|
+
{ label: "Block size", value: per ? `~${formatTokens(per)} tokens / request` : "\u2014" },
|
|
380
|
+
...sessionID ? [{ label: "This session", value: `~${formatTokens(inj.sessionTokens)} tokens \xB7 ${inj.sessionRequests} req` }] : [],
|
|
381
|
+
{ label: "Since start", value: `~${formatTokens(inj.totalTokens)} tokens \xB7 ${inj.totalRequests} req` }
|
|
382
|
+
];
|
|
383
|
+
}
|
|
384
|
+
function configRows(s) {
|
|
385
|
+
return [
|
|
386
|
+
{ label: "Extraction", value: s.extractModel ?? "Host default" },
|
|
387
|
+
{ label: "Consolidation", value: s.consolidationModel ?? "Host default" },
|
|
388
|
+
{ label: "Codex import", value: s.codexImport ? "On" : "Off", tone: s.codexImport ? "ok" : "muted" },
|
|
389
|
+
{ label: "Location", value: s.memoryRoot }
|
|
390
|
+
];
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// src/v2/tui.tsx
|
|
269
394
|
function registerSlot(context, name, render) {
|
|
270
395
|
const slot = context.ui.slot;
|
|
271
396
|
const claim = slot.length <= 1 ? {
|
|
@@ -319,165 +444,13 @@ function colors(context) {
|
|
|
319
444
|
}
|
|
320
445
|
};
|
|
321
446
|
}
|
|
322
|
-
function
|
|
323
|
-
|
|
324
|
-
return `${(n / 1e6).toFixed(1)}M`;
|
|
325
|
-
if (n >= 1000)
|
|
326
|
-
return `${(n / 1000).toFixed(1)}K`;
|
|
327
|
-
return String(n);
|
|
328
|
-
}
|
|
329
|
-
async function fetchStatus(rpc, context, sessionID, signal) {
|
|
330
|
-
const result = await rpc.status(sessionID ? {
|
|
447
|
+
function watchStatus(rpc, context, sessionID) {
|
|
448
|
+
return watchMemoryStatus((signal) => rpc.status(sessionID ? {
|
|
331
449
|
sessionID
|
|
332
450
|
} : {}, {
|
|
333
451
|
location: context.location ?? context.data.location.default(),
|
|
334
|
-
signal
|
|
335
|
-
});
|
|
336
|
-
if (!isMemoryStatus(result))
|
|
337
|
-
throw new Error("invalid memory status payload");
|
|
338
|
-
return result;
|
|
339
|
-
}
|
|
340
|
-
function watchStatus(rpc, context, sessionID) {
|
|
341
|
-
const [status, setStatus] = createSignal(null);
|
|
342
|
-
const [unavailable, setUnavailable] = createSignal(false);
|
|
343
|
-
const [refreshing, setRefreshing] = createSignal(false);
|
|
344
|
-
const [updatedAt, setUpdatedAt] = createSignal(Date.now());
|
|
345
|
-
const lifetime = new AbortController;
|
|
346
|
-
let revision = 0;
|
|
347
|
-
const refresh = async () => {
|
|
348
|
-
const request = ++revision;
|
|
349
|
-
setRefreshing(true);
|
|
350
|
-
try {
|
|
351
|
-
const next = await fetchStatus(rpc, context, sessionID, lifetime.signal);
|
|
352
|
-
if (lifetime.signal.aborted || request !== revision)
|
|
353
|
-
return;
|
|
354
|
-
setStatus(next);
|
|
355
|
-
setUpdatedAt(Date.now());
|
|
356
|
-
setUnavailable(false);
|
|
357
|
-
} catch {
|
|
358
|
-
if (!lifetime.signal.aborted && request === revision)
|
|
359
|
-
setUnavailable(true);
|
|
360
|
-
} finally {
|
|
361
|
-
if (!lifetime.signal.aborted && request === revision)
|
|
362
|
-
setRefreshing(false);
|
|
363
|
-
}
|
|
364
|
-
};
|
|
365
|
-
const unsubscribe = rpc.events.on("changed", () => void refresh());
|
|
366
|
-
const timer = setInterval(() => void refresh(), 30000);
|
|
367
|
-
onCleanup(() => {
|
|
368
|
-
lifetime.abort();
|
|
369
|
-
clearInterval(timer);
|
|
370
|
-
unsubscribe();
|
|
371
|
-
});
|
|
372
|
-
refresh();
|
|
373
|
-
return {
|
|
374
|
-
status,
|
|
375
|
-
unavailable,
|
|
376
|
-
refreshing,
|
|
377
|
-
updatedAt,
|
|
378
|
-
refresh,
|
|
379
|
-
signal: lifetime.signal
|
|
380
|
-
};
|
|
381
|
-
}
|
|
382
|
-
function pipelineRows(s, now) {
|
|
383
|
-
return s.pipelines.flatMap((pipeline) => {
|
|
384
|
-
const version = pipeline.version.toUpperCase();
|
|
385
|
-
const paused = !s.generateMemories || !s.dualWrite && pipeline.version !== s.version;
|
|
386
|
-
const extractionRetry = pipeline.phase1RetryAt != null && pipeline.phase1RetryAt > now;
|
|
387
|
-
const consolidationRetry = pipeline.phase2RetryAt != null && pipeline.phase2RetryAt > now;
|
|
388
|
-
const cooldown = pipeline.phase2CooldownUntil != null && pipeline.phase2CooldownUntil > now;
|
|
389
|
-
const consolidation = pipeline.phase2Status === "pending" ? "Queued" : pipeline.phase2Status === "failed" ? "Retry due" : "Idle";
|
|
390
|
-
return [{
|
|
391
|
-
label: `${version} recaps`,
|
|
392
|
-
value: `${pipeline.stage1Count} stored`,
|
|
393
|
-
tone: "muted"
|
|
394
|
-
}, {
|
|
395
|
-
label: `${version} extraction`,
|
|
396
|
-
value: pipeline.extracting ? `Running (${pipeline.extracting})` : paused ? "Paused" : extractionRetry ? `Retry ${remaining(pipeline.phase1RetryAt, now)}` : "Idle",
|
|
397
|
-
tone: extractionRetry && !paused ? "warn" : "muted"
|
|
398
|
-
}, {
|
|
399
|
-
label: `${version} consolidation`,
|
|
400
|
-
value: pipeline.phase2Status === "running" ? "Running" : paused ? "Paused" : consolidationRetry ? `Retry ${remaining(pipeline.phase2RetryAt, now)}` : cooldown ? `${consolidation} \xB7 cooldown ends ${remaining(pipeline.phase2CooldownUntil, now)}` : pipeline.phase2Status === "pending" ? "Queued \xB7 next activity" : consolidation,
|
|
401
|
-
tone: pipeline.lastError ? "warn" : "muted"
|
|
402
|
-
}, ...pipeline.lastError ? [{
|
|
403
|
-
label: `${version} last error`,
|
|
404
|
-
value: pipeline.lastError,
|
|
405
|
-
tone: "warn"
|
|
406
|
-
}] : []];
|
|
407
|
-
});
|
|
408
|
-
}
|
|
409
|
-
function statusRows(s, now) {
|
|
410
|
-
return [{
|
|
411
|
-
label: "Activity",
|
|
412
|
-
value: labels[s.activity]
|
|
413
|
-
}, {
|
|
414
|
-
label: "Memory version",
|
|
415
|
-
value: `${s.sessionVersion} (default ${s.version})`
|
|
416
|
-
}, {
|
|
417
|
-
label: "Learning pipelines",
|
|
418
|
-
value: s.dualWrite ? "v1 + v2" : s.version
|
|
419
|
-
}, {
|
|
420
|
-
label: "V2 readiness",
|
|
421
|
-
value: `${s.v2Ready ? "Ready" : "Not ready"} \xB7 ${s.v2ConsolidatedThreads}/${s.minConsolidatedThreads} sessions`,
|
|
422
|
-
tone: s.v2Ready ? "ok" : "muted"
|
|
423
|
-
}, ...s.v2NotReadyReason ? [{
|
|
424
|
-
label: "V2 not ready",
|
|
425
|
-
value: s.v2NotReadyReason,
|
|
426
|
-
tone: "muted"
|
|
427
|
-
}] : [], ...s.v2SummaryBytes !== undefined ? [{
|
|
428
|
-
label: "V2 summary",
|
|
429
|
-
value: s.v2SummaryBytes === null ? "Unreadable" : s.v2InjectedSummaryBytes != null ? `${s.v2SummaryBytes} bytes on disk \xB7 ${s.v2InjectedSummaryBytes} injected${s.v2SummaryBytes >= 1e4 ? " (capped)" : ""}` : `${s.v2SummaryBytes} UTF-8 bytes`,
|
|
430
|
-
tone: "muted"
|
|
431
|
-
}] : [], ...pipelineRows(s, now), {
|
|
432
|
-
label: "Use memories",
|
|
433
|
-
value: s.useMemories ? "On" : "Off",
|
|
434
|
-
tone: s.useMemories ? "ok" : "muted"
|
|
435
|
-
}, {
|
|
436
|
-
label: "Learn from sessions",
|
|
437
|
-
value: s.generateMemories ? "On" : "Off",
|
|
438
|
-
tone: s.generateMemories ? "ok" : "muted"
|
|
439
|
-
}, ...s.sessionMode ? [{
|
|
440
|
-
label: "This session",
|
|
441
|
-
value: s.sessionMode === "enabled" ? s.generateMemories ? "Eligible for learning" : "Eligible (learning paused)" : s.sessionMode === "disabled" ? "Not learning" : "Excluded (external context)",
|
|
442
|
-
tone: s.sessionMode === "enabled" && s.generateMemories ? "ok" : "muted"
|
|
443
|
-
}] : [], {
|
|
444
|
-
label: "Last consolidated",
|
|
445
|
-
value: s.lastSuccessAt == null ? "Never" : elapsed(s.lastSuccessAt, now)
|
|
446
|
-
}, ...s.retryAt == null ? [] : [{
|
|
447
|
-
label: "Next retry",
|
|
448
|
-
value: remaining(s.retryAt, now),
|
|
449
|
-
tone: "warn"
|
|
450
|
-
}]];
|
|
451
|
-
}
|
|
452
|
-
function usageRows(s, sessionID) {
|
|
453
|
-
const inj = s.injected;
|
|
454
|
-
const per = inj.sessionRequests > 0 ? Math.round(inj.sessionTokens / inj.sessionRequests) : inj.totalRequests > 0 ? Math.round(inj.totalTokens / inj.totalRequests) : 0;
|
|
455
|
-
return [{
|
|
456
|
-
label: "Block size",
|
|
457
|
-
value: per ? `~${formatTokens(per)} tokens / request` : "\u2014"
|
|
458
|
-
}, ...sessionID ? [{
|
|
459
|
-
label: "This session",
|
|
460
|
-
value: `~${formatTokens(inj.sessionTokens)} tokens \xB7 ${inj.sessionRequests} req`
|
|
461
|
-
}] : [], {
|
|
462
|
-
label: "Since start",
|
|
463
|
-
value: `~${formatTokens(inj.totalTokens)} tokens \xB7 ${inj.totalRequests} req`
|
|
464
|
-
}];
|
|
465
|
-
}
|
|
466
|
-
function configRows(s) {
|
|
467
|
-
return [{
|
|
468
|
-
label: "Extraction",
|
|
469
|
-
value: s.extractModel ?? "Host default"
|
|
470
|
-
}, {
|
|
471
|
-
label: "Consolidation",
|
|
472
|
-
value: s.consolidationModel ?? "Host default"
|
|
473
|
-
}, {
|
|
474
|
-
label: "Codex import",
|
|
475
|
-
value: s.codexImport ? "On" : "Off",
|
|
476
|
-
tone: s.codexImport ? "ok" : "muted"
|
|
477
|
-
}, {
|
|
478
|
-
label: "Location",
|
|
479
|
-
value: s.memoryRoot
|
|
480
|
-
}];
|
|
452
|
+
signal
|
|
453
|
+
}), (listener) => rpc.events.on("changed", listener));
|
|
481
454
|
}
|
|
482
455
|
var TABS = ["Overview", "Controls"];
|
|
483
456
|
function MemoryDialog(context, sessionID) {
|
|
@@ -492,11 +465,11 @@ function MemoryDialog(context, sessionID) {
|
|
|
492
465
|
} = watchStatus(rpc, context, sessionID);
|
|
493
466
|
const dimensions = useTerminalDimensions();
|
|
494
467
|
const color = colors(context);
|
|
495
|
-
const [tab, setTab] =
|
|
496
|
-
const [cursor, setCursor] =
|
|
497
|
-
const [notice, setNotice] =
|
|
498
|
-
const [busy, setBusy] =
|
|
499
|
-
const [armed, setArmed] =
|
|
468
|
+
const [tab, setTab] = createSignal2("Overview");
|
|
469
|
+
const [cursor, setCursor] = createSignal2(0);
|
|
470
|
+
const [notice, setNotice] = createSignal2(null);
|
|
471
|
+
const [busy, setBusy] = createSignal2(null);
|
|
472
|
+
const [armed, setArmed] = createSignal2(false);
|
|
500
473
|
let scroll;
|
|
501
474
|
const call = async (id, method, input, done) => {
|
|
502
475
|
if (busy() || unavailable())
|
|
@@ -571,7 +544,7 @@ function MemoryDialog(context, sessionID) {
|
|
|
571
544
|
}, learning ? "This session is excluded from future learning." : "This session is eligible when global learning is on.")
|
|
572
545
|
});
|
|
573
546
|
}
|
|
574
|
-
const running = s
|
|
547
|
+
const running = isMemoryRunning(s);
|
|
575
548
|
list.push({
|
|
576
549
|
id: "now",
|
|
577
550
|
title: "Consolidate now",
|
package/dist/tools/control.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ToolDefinition } from "@opencode-ai/plugin";
|
|
1
2
|
/**
|
|
2
3
|
* Shared by the memory_reset tool (after user approval) and the OpenCode 2
|
|
3
4
|
* memory panel (whose confirmation is the approval).
|
|
@@ -6,36 +7,6 @@ export declare function performMemoryReset(): {
|
|
|
6
7
|
ok: boolean;
|
|
7
8
|
message: string;
|
|
8
9
|
};
|
|
9
|
-
export declare const memory_reset:
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
confirm: import("zod").ZodBoolean;
|
|
13
|
-
};
|
|
14
|
-
execute(args: {
|
|
15
|
-
confirm: boolean;
|
|
16
|
-
}, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
|
|
17
|
-
};
|
|
18
|
-
export declare const memory_inspect: {
|
|
19
|
-
description: string;
|
|
20
|
-
args: {
|
|
21
|
-
min_consolidated_threads: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
22
|
-
};
|
|
23
|
-
execute(args: {
|
|
24
|
-
min_consolidated_threads?: number | undefined;
|
|
25
|
-
}, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
|
|
26
|
-
};
|
|
27
|
-
export declare const memory_mode: {
|
|
28
|
-
description: string;
|
|
29
|
-
args: {
|
|
30
|
-
mode: import("zod").ZodEnum<{
|
|
31
|
-
enabled: "enabled";
|
|
32
|
-
disabled: "disabled";
|
|
33
|
-
polluted: "polluted";
|
|
34
|
-
}>;
|
|
35
|
-
sessionId: import("zod").ZodOptional<import("zod").ZodString>;
|
|
36
|
-
};
|
|
37
|
-
execute(args: {
|
|
38
|
-
mode: "enabled" | "disabled" | "polluted";
|
|
39
|
-
sessionId?: string | undefined;
|
|
40
|
-
}, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
|
|
41
|
-
};
|
|
10
|
+
export declare const memory_reset: ToolDefinition;
|
|
11
|
+
export declare const memory_inspect: ToolDefinition;
|
|
12
|
+
export declare const memory_mode: ToolDefinition;
|
package/dist/tools/memory.d.ts
CHANGED
|
@@ -1,70 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
max_lines: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
7
|
-
};
|
|
8
|
-
execute(args: {
|
|
9
|
-
path: string;
|
|
10
|
-
line_offset?: number | undefined;
|
|
11
|
-
max_lines?: number | undefined;
|
|
12
|
-
}, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
|
|
13
|
-
};
|
|
14
|
-
export declare const memory_list: {
|
|
15
|
-
description: string;
|
|
16
|
-
args: {
|
|
17
|
-
path: import("zod").ZodDefault<import("zod").ZodString>;
|
|
18
|
-
cursor: import("zod").ZodOptional<import("zod").ZodString>;
|
|
19
|
-
max_results: import("zod").ZodDefault<import("zod").ZodNumber>;
|
|
20
|
-
};
|
|
21
|
-
execute(args: {
|
|
22
|
-
path: string;
|
|
23
|
-
max_results: number;
|
|
24
|
-
cursor?: string | undefined;
|
|
25
|
-
}, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
|
|
26
|
-
};
|
|
27
|
-
export declare const memory_search: {
|
|
28
|
-
description: string;
|
|
29
|
-
args: {
|
|
30
|
-
queries: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
|
|
31
|
-
match_mode: import("zod").ZodDefault<import("zod").ZodEnum<{
|
|
32
|
-
any: "any";
|
|
33
|
-
all_on_same_line: "all_on_same_line";
|
|
34
|
-
all_within_lines: "all_within_lines";
|
|
35
|
-
}>>;
|
|
36
|
-
line_count: import("zod").ZodOptional<import("zod").ZodNumber>;
|
|
37
|
-
path: import("zod").ZodOptional<import("zod").ZodString>;
|
|
38
|
-
cursor: import("zod").ZodOptional<import("zod").ZodString>;
|
|
39
|
-
context_lines: import("zod").ZodDefault<import("zod").ZodNumber>;
|
|
40
|
-
case_sensitive: import("zod").ZodDefault<import("zod").ZodBoolean>;
|
|
41
|
-
normalized: import("zod").ZodDefault<import("zod").ZodBoolean>;
|
|
42
|
-
since: import("zod").ZodOptional<import("zod").ZodString>;
|
|
43
|
-
until: import("zod").ZodOptional<import("zod").ZodString>;
|
|
44
|
-
max_results: import("zod").ZodDefault<import("zod").ZodNumber>;
|
|
45
|
-
};
|
|
46
|
-
execute(args: {
|
|
47
|
-
match_mode: "any" | "all_on_same_line" | "all_within_lines";
|
|
48
|
-
context_lines: number;
|
|
49
|
-
case_sensitive: boolean;
|
|
50
|
-
normalized: boolean;
|
|
51
|
-
max_results: number;
|
|
52
|
-
queries?: string[] | undefined;
|
|
53
|
-
line_count?: number | undefined;
|
|
54
|
-
path?: string | undefined;
|
|
55
|
-
cursor?: string | undefined;
|
|
56
|
-
since?: string | undefined;
|
|
57
|
-
until?: string | undefined;
|
|
58
|
-
}, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
|
|
59
|
-
};
|
|
60
|
-
export declare const memory_add_note: {
|
|
61
|
-
description: string;
|
|
62
|
-
args: {
|
|
63
|
-
note: import("zod").ZodString;
|
|
64
|
-
title: import("zod").ZodOptional<import("zod").ZodString>;
|
|
65
|
-
};
|
|
66
|
-
execute(args: {
|
|
67
|
-
note: string;
|
|
68
|
-
title?: string | undefined;
|
|
69
|
-
}, context: import("@opencode-ai/plugin").ToolContext): Promise<import("@opencode-ai/plugin").ToolResult>;
|
|
70
|
-
};
|
|
1
|
+
import { type ToolDefinition } from "@opencode-ai/plugin";
|
|
2
|
+
export declare const memory_read: ToolDefinition;
|
|
3
|
+
export declare const memory_list: ToolDefinition;
|
|
4
|
+
export declare const memory_search: ToolDefinition;
|
|
5
|
+
export declare const memory_add_note: ToolDefinition;
|
package/dist/tools/memory.js
CHANGED
|
@@ -14,6 +14,7 @@ function sessionTool(definition) {
|
|
|
14
14
|
}
|
|
15
15
|
const tool = Object.assign(sessionTool, { schema: defineTool.schema });
|
|
16
16
|
const MAX_READ_BYTES = 256 * 1024;
|
|
17
|
+
// Keep public declarations on the SDK's type rather than a nested Zod import.
|
|
17
18
|
export const memory_read = tool({
|
|
18
19
|
description: "Read a file from the persistent memory workspace (MEMORY.md, rollout_summaries/*, skills/*, etc.). " +
|
|
19
20
|
"Paths are relative to the memory root and cannot escape it. Supports line_offset/max_lines for " +
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "opencode-codex-memory",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Persistent memory plugin for opencode — ports codex's two-phase memory system (extraction → consolidation → injection → citation feedback)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/src/index.js",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"types": "./dist/src/tui.d.ts",
|
|
22
22
|
"import": "./dist/src/tui.js"
|
|
23
23
|
},
|
|
24
|
+
"./gui-experimental": "./dist/gui-experimental.cjs",
|
|
24
25
|
"./tools/*": {
|
|
25
26
|
"import": "./dist/tools/*.js",
|
|
26
27
|
"types": "./dist/tools/*.d.ts"
|
|
@@ -43,7 +44,7 @@
|
|
|
43
44
|
},
|
|
44
45
|
"scripts": {
|
|
45
46
|
"dev": "bun --watch src/index.ts",
|
|
46
|
-
"build": "rm -rf dist && tsc && bun scripts/build-tui.ts && cp -R src/templates dist/src/templates && cp opencode.json dist/opencode.json",
|
|
47
|
+
"build": "rm -rf dist && tsc && bun scripts/build-tui.ts && bun scripts/build-gui.ts && cp -R src/templates dist/src/templates && cp opencode.json dist/opencode.json",
|
|
47
48
|
"smoke": "bun scripts/smoke.ts",
|
|
48
49
|
"contract": "bun scripts/check-opencode-contract.ts",
|
|
49
50
|
"contract:v2": "bun scripts/check-opencode2-contract.ts",
|
|
@@ -65,22 +66,23 @@
|
|
|
65
66
|
],
|
|
66
67
|
"license": "Apache-2.0",
|
|
67
68
|
"dependencies": {
|
|
68
|
-
"@opencode-ai/plugin": "
|
|
69
|
-
"@opencode/client": "2.
|
|
70
|
-
"diff": "
|
|
71
|
-
"isomorphic-git": "
|
|
72
|
-
"xdg-basedir": "
|
|
73
|
-
"zod": "4.1.8"
|
|
69
|
+
"@opencode-ai/plugin": "1.19.6",
|
|
70
|
+
"@opencode/client": "2.4.3",
|
|
71
|
+
"diff": "9.0.0",
|
|
72
|
+
"isomorphic-git": "1.44.21",
|
|
73
|
+
"xdg-basedir": "5.1.0"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
|
-
"@opencode/plugin": "2.
|
|
77
|
-
"@opencode/theme": "2.
|
|
78
|
-
"@opentui/core": "0.
|
|
79
|
-
"@opentui/solid": "0.
|
|
80
|
-
"@types/bun": "
|
|
81
|
-
"prettier": "
|
|
82
|
-
"solid-js": "1.9.
|
|
83
|
-
"typescript": "
|
|
76
|
+
"@opencode/plugin": "2.4.3",
|
|
77
|
+
"@opencode/theme": "2.4.3",
|
|
78
|
+
"@opentui/core": "0.9.12",
|
|
79
|
+
"@opentui/solid": "0.9.12",
|
|
80
|
+
"@types/bun": "1.4.5",
|
|
81
|
+
"prettier": "3.10.1",
|
|
82
|
+
"solid-js": "1.9.20",
|
|
83
|
+
"typescript": "7.0.2",
|
|
84
|
+
"vite": "7.3.7",
|
|
85
|
+
"vite-plugin-solid": "2.11.10"
|
|
84
86
|
},
|
|
85
87
|
"peerDependencies": {
|
|
86
88
|
"@opencode/client": ">=2.0.3",
|