| 1 | <!DOCTYPE html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <meta charset="utf-8"> |
| 5 | <meta name="viewport" content="width=device-width,initial-scale=1"> |
| 6 | <title>Thought Chains</title> |
| 7 | <!--TOKENS--> |
| 8 | <style> |
| 9 | *{box-sizing:border-box} |
| 10 | html,body{margin:0;padding:0} |
| 11 | body{background:var(--bg);color:var(--text);font-family:var(--font);font-size:14px;line-height:1.5} |
| 12 | .wrap{max-width:1180px;margin:0 auto;padding:14px} |
| 13 | header{display:flex;flex-wrap:wrap;align-items:center;gap:10px;margin-bottom:12px} |
| 14 | header h1{font-size:17px;margin:0;font-weight:700;letter-spacing:-.01em} |
| 15 | .chip{font-size:11px;color:var(--text-2);border:1px solid var(--line);border-radius:980px;padding:2px 10px;background:var(--bg-card)} |
| 16 | .chip b{color:var(--text);font-weight:600} |
| 17 | .spacer{flex:1} |
| 18 | button{background:var(--surface-2);color:var(--text);border:1px solid var(--line);border-radius:980px;padding:6px 14px;font:inherit;font-size:13px;font-weight:600;cursor:pointer} |
| 19 | button:hover{border-color:var(--line-2)} |
| 20 | button.danger{color:var(--red)} |
| 21 | button.primary{background:var(--blue);border-color:var(--blue);color:#fff} |
| 22 | .grid{display:grid;grid-template-columns:330px 1fr;gap:14px;align-items:start} |
| 23 | .card{background:var(--bg-card);border:1px solid var(--line);border-radius:14px;overflow:hidden} |
| 24 | .card h2{font-size:12px;text-transform:uppercase;letter-spacing:.08em;color:var(--text-2);margin:0;padding:10px 14px;border-bottom:1px solid var(--line);font-weight:600} |
| 25 | ul.chains{list-style:none;margin:0;padding:6px;max-height:70vh;overflow:auto} |
| 26 | ul.chains li{padding:9px 10px;border-radius:10px;cursor:pointer;border:1px solid transparent} |
| 27 | ul.chains li:hover{background:var(--surface-hover)} |
| 28 | ul.chains li.sel{background:var(--surface-2);border-color:var(--line-2)} |
| 29 | .cl-top{display:flex;align-items:baseline;gap:8px} |
| 30 | .cl-id{font-family:var(--mono);font-size:12px;color:var(--blue);font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap} |
| 31 | .cl-when{font-size:11px;color:var(--text-2);margin-left:auto;white-space:nowrap} |
| 32 | .cl-last{font-size:12px;color:var(--text-2);margin-top:3px;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden} |
| 33 | .cl-meta{display:flex;gap:6px;margin-top:6px;flex-wrap:wrap} |
| 34 | .pill{font-size:10px;font-weight:700;border-radius:980px;padding:1px 8px;border:1px solid var(--line);color:var(--text-2)} |
| 35 | .pill.b{color:var(--green);border-color:var(--green)} |
| 36 | .pill.t{color:var(--teal);border-color:var(--teal)} |
| 37 | .detail .empty{padding:36px 20px;text-align:center;color:var(--text-2)} |
| 38 | .detail .empty code{font-family:var(--mono);color:var(--text)} |
| 39 | .dhead{padding:12px 16px;border-bottom:1px solid var(--line);display:flex;flex-wrap:wrap;gap:10px;align-items:center} |
| 40 | .dhead .did{font-family:var(--mono);font-weight:700;color:var(--blue)} |
| 41 | .prog{flex:1;min-width:120px;max-width:280px;height:6px;border-radius:3px;background:var(--surface-2);overflow:hidden} |
| 42 | .prog i{display:block;height:100%;background:var(--blue);border-radius:3px} |
| 43 | .tl{list-style:none;margin:0;padding:14px 16px 18px 16px;position:relative} |
| 44 | .tl li{position:relative;padding:0 0 16px 30px} |
| 45 | .tl li::before{content:"";position:absolute;left:8px;top:18px;bottom:-2px;width:2px;background:var(--line)} |
| 46 | .tl li:last-child::before{display:none} |
| 47 | .tl .dot{position:absolute;left:2px;top:4px;width:14px;height:14px;border-radius:50%;border:3px solid var(--bg-card);background:var(--blue)} |
| 48 | .tl li.rev .dot{background:var(--orange)} |
| 49 | .tl li.br .dot{background:var(--green)} |
| 50 | .th-head{display:flex;flex-wrap:wrap;align-items:center;gap:8px;margin-bottom:4px} |
| 51 | .th-num{font-weight:700;font-size:13px} |
| 52 | .badge{font-size:10px;font-weight:700;text-transform:uppercase;letter-spacing:.05em;border-radius:980px;padding:1px 8px} |
| 53 | .badge.rev{color:var(--orange);border:1px solid var(--orange)} |
| 54 | .badge.br{color:var(--green);border:1px solid var(--green)} |
| 55 | .badge.fin{color:var(--purple);border:1px solid var(--purple)} |
| 56 | .th-more{font-size:11px;color:var(--text-2)} |
| 57 | .th-body{white-space:pre-wrap;word-wrap:break-word;font-size:13.5px;background:var(--surface-2);border:1px solid var(--line);border-radius:10px;padding:9px 12px;margin-top:2px} |
| 58 | .jsonwrap{margin-top:14px} |
| 59 | .jsonwrap pre{background:var(--code-bg);border:1px solid var(--line);border-radius:12px;padding:12px;font-family:var(--mono);font-size:11.5px;overflow:auto;max-height:340px;margin:8px 0 0} |
| 60 | .errbox{margin:12px 16px;padding:10px 12px;border:1px solid var(--red);border-radius:10px;color:var(--red);font-size:13px} |
| 61 | #backBtn{display:none} |
| 62 | @media (max-width:860px){ |
| 63 | .grid{grid-template-columns:1fr} |
| 64 | body[data-view=detail] #listCard{display:none} |
| 65 | body:not([data-view=detail]) .tlwrap{display:none} |
| 66 | body:not([data-view=detail]) .dhead{display:none} |
| 67 | body[data-view=detail] #backBtn{display:inline-block} |
| 68 | } |
| 69 | </style> |
| 70 | </head> |
| 71 | <body> |
| 72 | <div class="wrap"> |
| 73 | <header> |
| 74 | <button id="backBtn" type="button">Back</button> |
| 75 | <h1>Thought Chains</h1> |
| 76 | <span class="chip" id="chipChains">chains <b>-</b></span> |
| 77 | <span class="chip" id="chipThoughts">thoughts <b>-</b></span> |
| 78 | <span class="chip" id="chipState">state <b>-</b></span> |
| 79 | <span class="spacer"></span> |
| 80 | <button id="refreshBtn" type="button">Refresh</button> |
| 81 | <button id="clearBtn" type="button" class="danger">Clear</button> |
| 82 | <button class="embed-hide" id="themeToggle" type="button" title="Toggle appearance">Theme</button> |
| 83 | </header> |
| 84 | |
| 85 | <div class="grid"> |
| 86 | <div class="card" id="listCard"> |
| 87 | <h2>Chains</h2> |
| 88 | <ul class="chains" id="chains"></ul> |
| 89 | </div> |
| 90 | |
| 91 | <div class="card"> |
| 92 | <div class="dhead" id="dhead" style="display:none"> |
| 93 | <button id="backBtn2" type="button">Back</button> |
| 94 | <span class="did" id="dId"></span> |
| 95 | <span class="chip" id="dCount"></span> |
| 96 | <div class="prog"><i id="dProg" style="width:0%"></i></div> |
| 97 | </div> |
| 98 | <div class="tlwrap"> |
| 99 | <div class="empty" id="empty">Loading...</div> |
| 100 | <ul class="tl" id="tl"></ul> |
| 101 | </div> |
| 102 | <div id="errbox" class="errbox" style="display:none"></div> |
| 103 | <div class="jsonwrap" style="padding:0 16px 14px"> |
| 104 | <button id="jsonBtn" type="button">Show JSON</button> |
| 105 | <pre id="json" style="display:none"></pre> |
| 106 | </div> |
| 107 | </div> |
| 108 | </div> |
| 109 | </div> |
| 110 | <script> |
| 111 | (function(){ |
| 112 | var q=new URLSearchParams(location.search); |
| 113 | var HUB=q.get('plugin')||''; |
| 114 | var node=q.get('node')||''; |
| 115 | var sid=q.get('id')||''; |
| 116 | var pwd=q.get('pwd')||(node&&localStorage.getItem('bot_pwd_'+node))||localStorage.getItem('bot_active_pwd')||''; |
| 117 | var cur=null, lastJson=''; |
| 118 | |
| 119 | function api(action,extra){ |
| 120 | /* Hub-proxy route when served through /plugins?plugin=..., direct node |
| 121 | route when opened as /plugin_seqthink. Never call /plugins?plugin= on |
| 122 | the node itself: that is discovery and never dispatches. */ |
| 123 | var u=(HUB?'/plugins?plugin='+encodeURIComponent(HUB)+'&action='+action |
| 124 | :'/plugin_seqthink?action='+action); |
| 125 | if(extra)u+='&'+extra; |
| 126 | if(node)u+='&node='+encodeURIComponent(node); |
| 127 | if(sid)u+='&id='+encodeURIComponent(sid); |
| 128 | if(pwd)u+='&pwd='+encodeURIComponent(pwd); |
| 129 | return fetch(u,{headers:pwd?{'X-Bot-Password':pwd}:{}}).then(function(r){return r.json();}); |
| 130 | } |
| 131 | function esc(s){return String(s==null?'':s).replace(/[&<>"]/g,function(c){ |
| 132 | return {'&':'&','<':'<','>':'>','"':'"'}[c];});} |
| 133 | function fmt(ts){if(!ts)return '-';try{return new Date(ts*1000).toLocaleString();}catch(e){return String(ts);}} |
| 134 | function showErr(m){var e=document.getElementById('errbox');e.textContent=m;e.style.display='block';} |
| 135 | function clearErr(){document.getElementById('errbox').style.display='none';} |
| 136 | function setJson(o){lastJson=JSON.stringify(o,null,2);var j=document.getElementById('json');j.textContent=lastJson;} |
| 137 | |
| 138 | function renderList(d){ |
| 139 | var ul=document.getElementById('chains'); |
| 140 | var cs=(d&&d.chains)||[]; |
| 141 | document.getElementById('chipChains').innerHTML='chains <b>'+((d&&d.count!=null)?d.count:cs.length)+'</b>'; |
| 142 | var tot=0;cs.forEach(function(c){tot+=c.thoughts||0;}); |
| 143 | document.getElementById('chipThoughts').innerHTML='thoughts <b>'+tot+'</b>'; |
| 144 | document.getElementById('chipState').innerHTML='state <b>'+esc((d&&d.state_dir_name)||'-')+'</b>'; |
| 145 | ul.innerHTML=''; |
| 146 | if(!cs.length){ |
| 147 | if(!cur)document.getElementById('empty').innerHTML= |
| 148 | 'No thought chains recorded yet.<br>Call the <code>sequentialthinking</code> MCP tool '+ |
| 149 | '(<code>plugin_seqthink --mcp</code>) and press Refresh.'; |
| 150 | return; |
| 151 | } |
| 152 | cs.forEach(function(c){ |
| 153 | var li=document.createElement('li'); |
| 154 | if(c.id===cur)li.className='sel'; |
| 155 | var badges='<span class="pill t">thoughts '+esc(c.thoughts)+'</span>'; |
| 156 | if(c.branches&&c.branches.length)badges+='<span class="pill b">branches '+c.branches.length+'</span>'; |
| 157 | if(c.truncated)badges+='<span class="pill">capped</span>'; |
| 158 | li.innerHTML='<div class="cl-top"><span class="cl-id">'+esc(c.id)+'</span>'+ |
| 159 | '<span class="cl-when">'+esc(fmt(c.updated_at))+'</span></div>'+ |
| 160 | '<div class="cl-last">'+esc(c.last_head||'')+'</div>'+ |
| 161 | '<div class="cl-meta">'+badges+'</div>'; |
| 162 | li.onclick=function(){open(c.id);}; |
| 163 | ul.appendChild(li); |
| 164 | }); |
| 165 | } |
| 166 | |
| 167 | function renderDetail(d){ |
| 168 | var tl=document.getElementById('tl'); |
| 169 | var th=(d&&d.thoughts)||[]; |
| 170 | document.getElementById('dhead').style.display=th.length?'flex':'none'; |
| 171 | document.getElementById('dId').textContent=(d&&d.id)||''; |
| 172 | var last=th.length?th[th.length-1]:null; |
| 173 | var tt=last?(last.total_thoughts||0):0, tn=last?(last.thought_number||0):0; |
| 174 | document.getElementById('dCount').textContent=th.length+' thoughts'; |
| 175 | document.getElementById('dProg').style.width=(tt>0?Math.min(100,Math.round(100*tn/tt)):0)+'%'; |
| 176 | document.getElementById('empty').style.display=th.length?'none':'block'; |
| 177 | if(!th.length&&!document.getElementById('empty').textContent.trim()) |
| 178 | document.getElementById('empty').textContent='No thoughts in this chain.'; |
| 179 | tl.innerHTML=''; |
| 180 | th.forEach(function(t){ |
| 181 | var li=document.createElement('li'); |
| 182 | var cls=t.is_revision?'rev':(t.branch_from?'br':''); |
| 183 | if(cls)li.className=cls; |
| 184 | var badges='<span class="th-num">#'+esc(t.thought_number)+' / '+esc(t.total_thoughts)+'</span>'; |
| 185 | if(t.is_revision)badges+='<span class="badge rev">revision'+(t.revises?' of #'+esc(t.revises):'')+'</span>'; |
| 186 | if(t.branch_from)badges+='<span class="badge br">branch from #'+esc(t.branch_from)+ |
| 187 | (t.branch_id?' · '+esc(t.branch_id):'')+'</span>'; |
| 188 | if(!t.next_needed)badges+='<span class="badge fin">final</span>'; |
| 189 | var more=''; |
| 190 | if(t.needs_more)more=' <span class="th-more">needs more thoughts</span>'; |
| 191 | li.innerHTML='<span class="dot"></span>'+ |
| 192 | '<div class="th-head">'+badges+more+'</div>'+ |
| 193 | '<div class="th-body">'+esc(t.thought)+'</div>'; |
| 194 | tl.appendChild(li); |
| 195 | }); |
| 196 | } |
| 197 | |
| 198 | function open(id){ |
| 199 | cur=id; |
| 200 | document.body.setAttribute('data-view','detail'); |
| 201 | clearErr(); |
| 202 | api('chain','id='+encodeURIComponent(id)).then(function(d){ |
| 203 | if(!d||d.ok===false){showErr((d&&d.error)||'chain failed');return;} |
| 204 | renderDetail(d); |
| 205 | setJson(d); |
| 206 | }).catch(function(e){showErr('chain: '+e);}); |
| 207 | refreshList(); |
| 208 | } |
| 209 | function back(){ |
| 210 | cur=null; |
| 211 | document.body.removeAttribute('data-view'); |
| 212 | document.getElementById('tl').innerHTML=''; |
| 213 | document.getElementById('dhead').style.display='none'; |
| 214 | refreshList(); |
| 215 | } |
| 216 | function refreshList(){ |
| 217 | api('chains').then(function(d){ |
| 218 | if(!d||d.ok===false){showErr((d&&d.error)||'chains failed');return;} |
| 219 | renderList(d); |
| 220 | if(!cur)setJson(d); |
| 221 | }).catch(function(e){showErr('chains: '+e);}); |
| 222 | } |
| 223 | document.getElementById('refreshBtn').onclick=function(){cur?open(cur):refreshList();}; |
| 224 | document.getElementById('backBtn').onclick=back; |
| 225 | document.getElementById('backBtn2').onclick=back; |
| 226 | document.getElementById('jsonBtn').onclick=function(){ |
| 227 | var j=document.getElementById('json'); |
| 228 | var on=j.style.display!=='none'; |
| 229 | j.style.display=on?'none':'block'; |
| 230 | this.textContent=on?'Show JSON':'Hide JSON'; |
| 231 | }; |
| 232 | document.getElementById('clearBtn').onclick=function(){ |
| 233 | if(!window.confirm('Delete all recorded thought chains? This cannot be undone.'))return; |
| 234 | api('clear','confirm=1').then(function(d){ |
| 235 | if(!d||d.ok===false){showErr((d&&d.error)||'clear failed');return;} |
| 236 | cur=null;back(); |
| 237 | }).catch(function(e){showErr('clear: '+e);}); |
| 238 | }; |
| 239 | document.getElementById('themeToggle').onclick=function(){ |
| 240 | var t=document.documentElement.getAttribute('data-theme')==='dark'?'light':'dark'; |
| 241 | window.sxApplyTheme(t); |
| 242 | }; |
| 243 | refreshList(); |
| 244 | })(); |
| 245 | </script> |
| 246 | </body> |
| 247 | </html> |