During interviewing/review status, the Plan tab now displays the raw MEMORY.md content with simple markdown rendering instead of the structured phase/step list. This lets users verify their input is being captured in real-time. Switches back to structured view on executing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1001 lines
29 KiB
HTML
1001 lines
29 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
|
|
<title>PicoClaw Dashboard</title>
|
|
<script src="https://telegram.org/js/telegram-web-app.js"></script>
|
|
<style>
|
|
:root {
|
|
--bg: var(--tg-theme-bg-color, #ffffff);
|
|
--text: var(--tg-theme-text-color, #000000);
|
|
--hint: var(--tg-theme-hint-color, #999999);
|
|
--link: var(--tg-theme-link-color, #2481cc);
|
|
--btn: var(--tg-theme-button-color, #2481cc);
|
|
--btn-text: var(--tg-theme-button-text-color, #ffffff);
|
|
--secondary-bg: var(--tg-theme-secondary-bg-color, #f0f0f0);
|
|
--done: #34c759;
|
|
--current: var(--btn);
|
|
--pending-phase: var(--hint);
|
|
/* Liquid Glass */
|
|
--glass-bg: rgba(255, 255, 255, 0.55);
|
|
--glass-border: rgba(0, 0, 0, 0.08);
|
|
--glass-border-interactive: rgba(0, 0, 0, 0.15);
|
|
--glass-shadow: rgba(0, 0, 0, 0.06);
|
|
--glass-divider: rgba(0, 0, 0, 0.06);
|
|
--tab-bar-bg: rgba(255, 255, 255, 0.72);
|
|
--tab-track-bg: rgba(0, 0, 0, 0.06);
|
|
--tab-pill-bg: rgba(255, 255, 255, 0.9);
|
|
}
|
|
|
|
@media (prefers-color-scheme: dark) {
|
|
:root {
|
|
--bg: var(--tg-theme-bg-color, #1c1c1e);
|
|
--text: var(--tg-theme-text-color, #ffffff);
|
|
--hint: var(--tg-theme-hint-color, #8e8e93);
|
|
--link: var(--tg-theme-link-color, #5ac8fa);
|
|
--btn: var(--tg-theme-button-color, #5ac8fa);
|
|
--btn-text: var(--tg-theme-button-text-color, #ffffff);
|
|
--secondary-bg: var(--tg-theme-secondary-bg-color, #2c2c2e);
|
|
/* Liquid Glass — dark */
|
|
--glass-bg: rgba(255, 255, 255, 0.08);
|
|
--glass-border: rgba(255, 255, 255, 0.1);
|
|
--glass-border-interactive: rgba(255, 255, 255, 0.22);
|
|
--glass-shadow: rgba(0, 0, 0, 0.2);
|
|
--glass-divider: rgba(255, 255, 255, 0.08);
|
|
--tab-bar-bg: rgba(28, 28, 30, 0.72);
|
|
--tab-track-bg: rgba(255, 255, 255, 0.1);
|
|
--tab-pill-bg: rgba(255, 255, 255, 0.16);
|
|
}
|
|
}
|
|
|
|
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
background: var(--bg);
|
|
color: var(--text);
|
|
font-size: 14px;
|
|
padding-bottom: 80px;
|
|
}
|
|
|
|
.tabs {
|
|
display: flex;
|
|
position: sticky;
|
|
top: 0;
|
|
z-index: 10;
|
|
padding: 8px 12px;
|
|
background: var(--tab-bar-bg);
|
|
-webkit-backdrop-filter: saturate(180%) blur(20px);
|
|
backdrop-filter: saturate(180%) blur(20px);
|
|
}
|
|
|
|
.tabs-inner {
|
|
display: flex;
|
|
position: relative;
|
|
width: 100%;
|
|
background: var(--tab-track-bg);
|
|
border-radius: 10px;
|
|
padding: 2px;
|
|
}
|
|
|
|
.tab-indicator {
|
|
position: absolute;
|
|
top: 2px;
|
|
bottom: 2px;
|
|
left: 2px;
|
|
width: calc(25% - 2px);
|
|
border-radius: 8px;
|
|
background: var(--tab-pill-bg);
|
|
box-shadow: 0 0.5px 2px rgba(0,0,0,0.12), 0 0.5px 1px rgba(0,0,0,0.08);
|
|
transition: transform 0.38s cubic-bezier(0.25, 1, 0.5, 1);
|
|
z-index: 0;
|
|
}
|
|
|
|
.tab {
|
|
flex: 1;
|
|
padding: 7px 4px;
|
|
text-align: center;
|
|
font-size: 13px;
|
|
font-weight: 500;
|
|
color: var(--hint);
|
|
border: none;
|
|
background: none;
|
|
cursor: pointer;
|
|
transition: color 0.25s ease;
|
|
position: relative;
|
|
z-index: 1;
|
|
-webkit-tap-highlight-color: transparent;
|
|
}
|
|
|
|
.tab.active {
|
|
color: var(--text);
|
|
font-weight: 600;
|
|
}
|
|
|
|
.panel { display: none; padding: 16px; }
|
|
.panel.active { display: block; }
|
|
|
|
.card {
|
|
background: var(--glass-bg);
|
|
border: 1px solid var(--glass-border);
|
|
border-radius: 16px;
|
|
padding: 16px;
|
|
margin-bottom: 12px;
|
|
box-shadow: 0 1px 3px var(--glass-shadow);
|
|
-webkit-backdrop-filter: blur(12px);
|
|
backdrop-filter: blur(12px);
|
|
}
|
|
|
|
.card-title {
|
|
font-size: 12px;
|
|
color: var(--hint);
|
|
margin-bottom: 8px;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.6px;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.card-value {
|
|
font-size: 22px;
|
|
font-weight: 700;
|
|
}
|
|
|
|
/* Plan - phase/step list */
|
|
.phase {
|
|
margin-bottom: 16px;
|
|
}
|
|
|
|
.phase-header {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
padding: 10px 0 8px;
|
|
font-weight: 600;
|
|
font-size: 15px;
|
|
}
|
|
|
|
.phase-indicator {
|
|
width: 24px;
|
|
height: 24px;
|
|
border-radius: 50%;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
font-size: 11px;
|
|
font-weight: 700;
|
|
color: #fff;
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.phase-indicator.done { background: var(--done); }
|
|
.phase-indicator.current { background: var(--current); }
|
|
.phase-indicator.pending { background: var(--glass-divider); color: var(--hint); }
|
|
|
|
.phase-title { flex: 1; }
|
|
.phase-progress {
|
|
font-size: 12px;
|
|
color: var(--hint);
|
|
font-weight: 500;
|
|
}
|
|
|
|
.step {
|
|
display: flex;
|
|
align-items: flex-start;
|
|
gap: 10px;
|
|
padding: 12px 14px 12px 34px;
|
|
margin-bottom: 6px;
|
|
border-radius: 12px;
|
|
cursor: pointer;
|
|
transition: transform 0.2s cubic-bezier(0.25, 1, 0.5, 1), box-shadow 0.2s;
|
|
-webkit-tap-highlight-color: transparent;
|
|
}
|
|
|
|
.step:active { transform: scale(0.97); }
|
|
.step:not(.step-done) {
|
|
background: var(--glass-bg);
|
|
border: 1px solid var(--glass-border-interactive);
|
|
box-shadow: 0 0.5px 2px var(--glass-shadow);
|
|
}
|
|
|
|
.step-check {
|
|
width: 22px;
|
|
height: 22px;
|
|
border-radius: 50%;
|
|
border: 2px solid var(--hint);
|
|
flex-shrink: 0;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
margin-top: 0;
|
|
transition: all 0.2s;
|
|
}
|
|
|
|
.step-check.done {
|
|
background: var(--done);
|
|
border-color: var(--done);
|
|
}
|
|
|
|
.step-check.done::after {
|
|
content: '';
|
|
width: 6px;
|
|
height: 10px;
|
|
border: solid #fff;
|
|
border-width: 0 2px 2px 0;
|
|
transform: rotate(45deg);
|
|
margin-top: -2px;
|
|
}
|
|
|
|
.step-text {
|
|
flex: 1;
|
|
font-size: 14px;
|
|
line-height: 1.4;
|
|
}
|
|
|
|
.step-text.done {
|
|
color: var(--hint);
|
|
text-decoration: line-through;
|
|
}
|
|
|
|
/* Skills */
|
|
.skill-item {
|
|
background: var(--glass-bg);
|
|
border-radius: 16px;
|
|
padding: 14px 14px 14px 16px;
|
|
margin-bottom: 10px;
|
|
cursor: pointer;
|
|
transition: transform 0.2s cubic-bezier(0.25, 1, 0.5, 1), box-shadow 0.2s, border-color 0.2s;
|
|
border: 1px solid var(--glass-border-interactive);
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 12px;
|
|
box-shadow: 0 1px 3px var(--glass-shadow);
|
|
-webkit-backdrop-filter: blur(12px);
|
|
backdrop-filter: blur(12px);
|
|
-webkit-tap-highlight-color: transparent;
|
|
}
|
|
|
|
.skill-item:active {
|
|
transform: scale(0.98);
|
|
}
|
|
.skill-item.selected {
|
|
border-color: var(--btn);
|
|
box-shadow: 0 2px 8px var(--glass-shadow);
|
|
}
|
|
|
|
.skill-body { flex: 1; min-width: 0; }
|
|
|
|
.skill-name {
|
|
font-weight: 600;
|
|
font-size: 15px;
|
|
margin-bottom: 4px;
|
|
}
|
|
|
|
.skill-desc {
|
|
font-size: 13px;
|
|
color: var(--hint);
|
|
line-height: 1.4;
|
|
}
|
|
|
|
.skill-source {
|
|
display: inline-block;
|
|
font-size: 11px;
|
|
padding: 3px 10px;
|
|
border-radius: 20px;
|
|
background: var(--tab-track-bg);
|
|
color: var(--hint);
|
|
margin-top: 6px;
|
|
font-weight: 500;
|
|
}
|
|
|
|
.skill-arrow {
|
|
color: var(--hint);
|
|
font-size: 22px;
|
|
flex-shrink: 0;
|
|
transition: color 0.2s;
|
|
}
|
|
.skill-item.selected .skill-arrow { color: var(--btn); }
|
|
|
|
/* Stats */
|
|
.stat-row {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
padding: 11px 0;
|
|
border-bottom: 1px solid var(--glass-divider);
|
|
}
|
|
|
|
.stat-row:last-child { border-bottom: none; }
|
|
.stat-label { color: var(--hint); font-size: 14px; }
|
|
.stat-value { font-weight: 600; font-size: 14px; }
|
|
|
|
/* Send bar */
|
|
.send-bar {
|
|
position: fixed;
|
|
bottom: 0;
|
|
left: 0;
|
|
right: 0;
|
|
background: var(--tab-bar-bg);
|
|
-webkit-backdrop-filter: saturate(180%) blur(20px);
|
|
backdrop-filter: saturate(180%) blur(20px);
|
|
padding: 12px 16px;
|
|
display: flex;
|
|
gap: 8px;
|
|
border-top: 1px solid var(--glass-divider);
|
|
}
|
|
|
|
.send-input {
|
|
flex: 1;
|
|
padding: 10px 16px;
|
|
border-radius: 20px;
|
|
border: 1px solid var(--glass-border-interactive);
|
|
background: var(--glass-bg);
|
|
color: var(--text);
|
|
font-size: 14px;
|
|
outline: none;
|
|
-webkit-backdrop-filter: blur(8px);
|
|
backdrop-filter: blur(8px);
|
|
transition: border-color 0.2s;
|
|
}
|
|
|
|
.send-input:focus { border-color: var(--btn); }
|
|
|
|
.send-btn {
|
|
padding: 10px 20px;
|
|
border-radius: 20px;
|
|
border: none;
|
|
background: var(--btn);
|
|
color: var(--btn-text);
|
|
font-size: 14px;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
transition: transform 0.2s cubic-bezier(0.25, 1, 0.5, 1), background 0.15s;
|
|
-webkit-tap-highlight-color: transparent;
|
|
}
|
|
|
|
.send-btn:active { transform: scale(0.95); }
|
|
.send-btn:disabled { opacity: 0.5; }
|
|
.send-btn.sent { background: var(--done); }
|
|
|
|
.empty-state {
|
|
text-align: center;
|
|
color: var(--hint);
|
|
padding: 48px 20px;
|
|
font-size: 15px;
|
|
}
|
|
|
|
.loading {
|
|
text-align: center;
|
|
color: var(--hint);
|
|
padding: 48px 20px;
|
|
font-size: 15px;
|
|
}
|
|
|
|
.cmd-tiles {
|
|
display: grid;
|
|
grid-template-columns: 1fr 1fr;
|
|
gap: 10px;
|
|
}
|
|
|
|
.cmd-tile {
|
|
padding: 16px 14px;
|
|
border-radius: 14px;
|
|
border: 1px solid var(--glass-border-interactive);
|
|
background: var(--glass-bg);
|
|
color: var(--text);
|
|
font-size: 15px;
|
|
font-weight: 600;
|
|
cursor: pointer;
|
|
transition: transform 0.2s cubic-bezier(0.25, 1, 0.5, 1), background 0.15s;
|
|
text-align: center;
|
|
box-shadow: 0 1px 3px var(--glass-shadow);
|
|
-webkit-backdrop-filter: blur(12px);
|
|
backdrop-filter: blur(12px);
|
|
-webkit-tap-highlight-color: transparent;
|
|
}
|
|
|
|
.cmd-tile:active {
|
|
transform: scale(0.96);
|
|
}
|
|
|
|
.cmd-tile.sent {
|
|
background: var(--btn);
|
|
color: var(--btn-text);
|
|
border-color: var(--btn);
|
|
}
|
|
|
|
/* MEMORY.md raw display */
|
|
.memory-view {
|
|
font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
|
|
font-size: 13px;
|
|
line-height: 1.6;
|
|
white-space: pre-wrap;
|
|
word-break: break-word;
|
|
padding: 14px 16px;
|
|
background: var(--glass-bg);
|
|
border: 1px solid var(--glass-border);
|
|
border-radius: 16px;
|
|
box-shadow: 0 1px 3px var(--glass-shadow);
|
|
-webkit-backdrop-filter: blur(12px);
|
|
backdrop-filter: blur(12px);
|
|
}
|
|
|
|
.memory-view .md-h1 {
|
|
font-size: 18px;
|
|
font-weight: 700;
|
|
margin: 16px 0 8px;
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
}
|
|
.memory-view .md-h1:first-child { margin-top: 0; }
|
|
|
|
.memory-view .md-h2 {
|
|
font-size: 15px;
|
|
font-weight: 700;
|
|
margin: 14px 0 6px;
|
|
color: var(--link);
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
}
|
|
|
|
.memory-view .md-h3 {
|
|
font-size: 14px;
|
|
font-weight: 600;
|
|
margin: 12px 0 4px;
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
}
|
|
|
|
.memory-view .md-checkbox {
|
|
margin: 2px 0;
|
|
}
|
|
|
|
.memory-view .md-checkbox-icon {
|
|
display: inline-block;
|
|
width: 16px;
|
|
height: 16px;
|
|
border-radius: 4px;
|
|
border: 1.5px solid var(--hint);
|
|
vertical-align: middle;
|
|
margin-right: 6px;
|
|
position: relative;
|
|
top: -1px;
|
|
}
|
|
|
|
.memory-view .md-checkbox-icon.checked {
|
|
background: var(--done);
|
|
border-color: var(--done);
|
|
}
|
|
|
|
.memory-view .md-checkbox-icon.checked::after {
|
|
content: '';
|
|
position: absolute;
|
|
left: 4px;
|
|
top: 1px;
|
|
width: 4px;
|
|
height: 8px;
|
|
border: solid #fff;
|
|
border-width: 0 1.5px 1.5px 0;
|
|
transform: rotate(45deg);
|
|
}
|
|
|
|
.memory-view .md-quote {
|
|
border-left: 3px solid var(--hint);
|
|
padding-left: 10px;
|
|
color: var(--hint);
|
|
margin: 4px 0;
|
|
}
|
|
|
|
.memory-view .md-bullet {
|
|
margin: 2px 0;
|
|
padding-left: 12px;
|
|
text-indent: -12px;
|
|
}
|
|
|
|
.memory-view .md-bullet::before {
|
|
content: '\2022 ';
|
|
color: var(--hint);
|
|
}
|
|
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<div class="tabs">
|
|
<div class="tabs-inner">
|
|
<div class="tab-indicator"></div>
|
|
<button class="tab active" data-panel="plan">Plan</button>
|
|
<button class="tab" data-panel="skills">Skills</button>
|
|
<button class="tab" data-panel="session">Session</button>
|
|
<button class="tab" data-panel="config">Config</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="plan" class="panel active">
|
|
<div class="loading" id="plan-loading">Loading plan...</div>
|
|
<div id="plan-content" style="display:none"></div>
|
|
</div>
|
|
|
|
<div id="skills" class="panel">
|
|
<div class="loading" id="skills-loading">Loading skills...</div>
|
|
<div id="skills-list" style="display:none"></div>
|
|
</div>
|
|
|
|
<div id="session" class="panel">
|
|
<div class="loading" id="session-loading">Loading session...</div>
|
|
<div id="session-content" style="display:none"></div>
|
|
</div>
|
|
|
|
<div id="config" class="panel">
|
|
<div class="card">
|
|
<div class="card-title">Quick Commands</div>
|
|
<div class="cmd-tiles">
|
|
<button class="cmd-tile" data-cmd="/session">/session</button>
|
|
<button class="cmd-tile" data-cmd="/skills">/skills</button>
|
|
<button class="cmd-tile" data-cmd="/plan clear">/plan clear</button>
|
|
</div>
|
|
</div>
|
|
<div class="card">
|
|
<div class="card-title">Custom Command</div>
|
|
<div style="display:flex;gap:8px;margin-top:8px">
|
|
<input id="custom-cmd" class="send-input" placeholder="/command args..." style="flex:1">
|
|
<button class="send-btn" onclick="sendCustomCmd()">Send</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="send-bar" id="send-bar" style="display:none">
|
|
<input id="skill-msg" class="send-input" placeholder="Message for skill...">
|
|
<button class="send-btn" id="send-skill-btn" onclick="sendSkillCommand()">Send</button>
|
|
</div>
|
|
|
|
<script>
|
|
const tg = window.Telegram.WebApp;
|
|
tg.ready();
|
|
|
|
const API_BASE = location.origin;
|
|
let initData = tg.initData || '';
|
|
let selectedSkill = null;
|
|
|
|
// Tab switching — always re-fetch data on tab switch
|
|
const tabs = document.querySelectorAll('.tab');
|
|
const tabIndicator = document.querySelector('.tab-indicator');
|
|
|
|
function moveIndicator(index) {
|
|
tabIndicator.style.transform = 'translateX(' + (index * 100) + '%)';
|
|
}
|
|
|
|
tabs.forEach((tab, index) => {
|
|
tab.addEventListener('click', () => {
|
|
tabs.forEach(t => t.classList.remove('active'));
|
|
document.querySelectorAll('.panel').forEach(p => p.classList.remove('active'));
|
|
tab.classList.add('active');
|
|
document.getElementById(tab.dataset.panel).classList.add('active');
|
|
moveIndicator(index);
|
|
|
|
document.getElementById('send-bar').style.display =
|
|
tab.dataset.panel === 'skills' && selectedSkill ? 'flex' : 'none';
|
|
|
|
if (tab.dataset.panel === 'plan') loadPlan();
|
|
if (tab.dataset.panel === 'skills') loadSkills();
|
|
if (tab.dataset.panel === 'session') loadSession();
|
|
});
|
|
});
|
|
|
|
// Quick command tiles
|
|
document.querySelectorAll('.cmd-tile').forEach(tile => {
|
|
tile.addEventListener('click', async () => {
|
|
const ok = await sendCommand(tile.dataset.cmd);
|
|
if (ok) flashSent(tile);
|
|
});
|
|
});
|
|
|
|
async function sendCommand(cmd) {
|
|
if (!cmd.startsWith('/')) return false;
|
|
try {
|
|
const res = await fetch(API_BASE + '/miniapp/api/command?initData=' + encodeURIComponent(initData), {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ command: cmd }),
|
|
});
|
|
if (!res.ok) throw new Error('API error: ' + res.status);
|
|
return true;
|
|
} catch (e) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
async function sendCustomCmd() {
|
|
const input = document.getElementById('custom-cmd');
|
|
const btn = input.nextElementSibling;
|
|
const cmd = input.value.trim();
|
|
if (!cmd) return;
|
|
if (!cmd.startsWith('/')) return;
|
|
const ok = await sendCommand(cmd);
|
|
if (ok) {
|
|
input.value = '';
|
|
flashSent(btn);
|
|
}
|
|
}
|
|
|
|
async function sendSkillCommand() {
|
|
if (!selectedSkill) return;
|
|
const msg = document.getElementById('skill-msg').value.trim();
|
|
const cmd = msg ? '/skill ' + selectedSkill + ' ' + msg : '/skill ' + selectedSkill;
|
|
const btn = document.getElementById('send-skill-btn');
|
|
const ok = await sendCommand(cmd);
|
|
if (ok) flashSent(btn);
|
|
}
|
|
|
|
async function startPlan() {
|
|
const input = document.getElementById('plan-task');
|
|
const btn = input.nextElementSibling;
|
|
const task = input.value.trim();
|
|
if (!task) return;
|
|
const ok = await sendCommand('/plan ' + task);
|
|
if (ok) {
|
|
input.value = '';
|
|
flashSent(btn);
|
|
}
|
|
}
|
|
|
|
function flashSent(el) {
|
|
el.classList.add('sent');
|
|
setTimeout(() => el.classList.remove('sent'), 600);
|
|
}
|
|
|
|
async function apiFetch(path) {
|
|
const sep = path.includes('?') ? '&' : '?';
|
|
const res = await fetch(API_BASE + path + sep + 'initData=' + encodeURIComponent(initData));
|
|
if (!res.ok) throw new Error('API error: ' + res.status);
|
|
return res.json();
|
|
}
|
|
|
|
// ── Plan tab ──
|
|
function renderPlanFromData(data) {
|
|
var loading = document.getElementById('plan-loading');
|
|
var el = document.getElementById('plan-content');
|
|
loading.style.display = 'none';
|
|
el.style.display = 'block';
|
|
|
|
if (!data.has_plan) {
|
|
el.innerHTML =
|
|
'<div class="empty-state">No active plan.</div>' +
|
|
'<div class="card" style="margin-top:16px">' +
|
|
'<div class="card-title">Start a Plan</div>' +
|
|
'<div style="display:flex;gap:8px;margin-top:8px">' +
|
|
'<input id="plan-task" class="send-input" placeholder="Describe your task...">' +
|
|
'<button class="send-btn" onclick="startPlan()">Start</button>' +
|
|
'</div>' +
|
|
'</div>';
|
|
return;
|
|
}
|
|
|
|
var html = '';
|
|
html += '<div class="card">' +
|
|
'<div class="card-title">Status</div>' +
|
|
'<div class="card-value">' + escapeHtml(data.status) + '</div>' +
|
|
'<div style="color:var(--hint);margin-top:4px">Phase ' + data.current_phase + ' / ' + data.total_phases + '</div>' +
|
|
'</div>';
|
|
|
|
if (data.status === 'interviewing' || data.status === 'review') {
|
|
// Show raw MEMORY.md content during interview/review
|
|
if (data.memory) {
|
|
html += '<div class="memory-view">' + renderSimpleMarkdown(data.memory) + '</div>';
|
|
}
|
|
} else {
|
|
// Show structured phase/step list during executing
|
|
if (data.phases && data.phases.length > 0) {
|
|
html += renderPhases(data.phases, data.current_phase);
|
|
}
|
|
}
|
|
|
|
el.innerHTML = html;
|
|
}
|
|
|
|
function renderSimpleMarkdown(text) {
|
|
var lines = text.split('\n');
|
|
var out = [];
|
|
for (var i = 0; i < lines.length; i++) {
|
|
var line = lines[i];
|
|
// Headings
|
|
if (/^### /.test(line)) {
|
|
out.push('<div class="md-h3">' + escapeHtml(line.slice(4)) + '</div>');
|
|
} else if (/^## /.test(line)) {
|
|
out.push('<div class="md-h2">' + escapeHtml(line.slice(3)) + '</div>');
|
|
} else if (/^# /.test(line)) {
|
|
out.push('<div class="md-h1">' + escapeHtml(line.slice(2)) + '</div>');
|
|
// Checkboxes
|
|
} else if (/^- \[x\] /.test(line)) {
|
|
out.push('<div class="md-checkbox"><span class="md-checkbox-icon checked"></span>' + escapeHtml(line.slice(6)) + '</div>');
|
|
} else if (/^- \[ \] /.test(line)) {
|
|
out.push('<div class="md-checkbox"><span class="md-checkbox-icon"></span>' + escapeHtml(line.slice(6)) + '</div>');
|
|
// Blockquote
|
|
} else if (/^> /.test(line)) {
|
|
out.push('<div class="md-quote">' + escapeHtml(line.slice(2)) + '</div>');
|
|
// Bullet list
|
|
} else if (/^- /.test(line)) {
|
|
out.push('<div class="md-bullet">' + escapeHtml(line.slice(2)) + '</div>');
|
|
// Empty line
|
|
} else if (line.trim() === '') {
|
|
out.push('<br>');
|
|
// Plain text
|
|
} else {
|
|
out.push('<div>' + escapeHtml(line) + '</div>');
|
|
}
|
|
}
|
|
return out.join('');
|
|
}
|
|
|
|
async function loadPlan() {
|
|
var loading = document.getElementById('plan-loading');
|
|
var el = document.getElementById('plan-content');
|
|
loading.style.display = 'block';
|
|
loading.textContent = 'Loading plan...';
|
|
el.style.display = 'none';
|
|
|
|
try {
|
|
var data = await apiFetch('/miniapp/api/plan');
|
|
renderPlanFromData(data);
|
|
} catch (e) {
|
|
loading.textContent = 'Failed to load plan.';
|
|
loading.style.display = 'block';
|
|
el.style.display = 'none';
|
|
}
|
|
}
|
|
|
|
function renderPhases(phases, currentPhase) {
|
|
let html = '';
|
|
for (const phase of phases) {
|
|
const doneCount = phase.steps.filter(s => s.done).length;
|
|
const total = phase.steps.length;
|
|
|
|
let indicatorClass, indicator;
|
|
if (phase.number < currentPhase || (total > 0 && doneCount === total)) {
|
|
indicatorClass = 'done';
|
|
indicator = '\u2713';
|
|
} else if (phase.number === currentPhase) {
|
|
indicatorClass = 'current';
|
|
indicator = String(phase.number);
|
|
} else {
|
|
indicatorClass = 'pending';
|
|
indicator = String(phase.number);
|
|
}
|
|
|
|
html += '<div class="phase">';
|
|
html += '<div class="phase-header">';
|
|
html += '<div class="phase-indicator ' + indicatorClass + '">' + indicator + '</div>';
|
|
html += '<span class="phase-title">' + escapeHtml(phase.title || 'Phase ' + phase.number) + '</span>';
|
|
if (total > 0) {
|
|
html += '<span class="phase-progress">' + doneCount + '/' + total + '</span>';
|
|
}
|
|
html += '</div>';
|
|
|
|
// Steps
|
|
for (const step of phase.steps) {
|
|
const checkClass = step.done ? 'done' : '';
|
|
const textClass = step.done ? 'done' : '';
|
|
const stepClass = step.done ? 'step step-done' : 'step';
|
|
html += '<div class="' + stepClass + '" data-phase="' + phase.number + '" data-step="' + step.index + '" data-done="' + step.done + '">';
|
|
html += '<div class="step-check ' + checkClass + '"></div>';
|
|
html += '<div class="step-text ' + textClass + '">' + escapeHtml(step.description) + '</div>';
|
|
html += '</div>';
|
|
}
|
|
|
|
html += '</div>';
|
|
}
|
|
|
|
return html;
|
|
}
|
|
|
|
// Delegate click on steps — tap to mark done (sends command, closes app)
|
|
document.getElementById('plan-content').addEventListener('click', function(e) {
|
|
const step = e.target.closest('.step');
|
|
if (!step) return;
|
|
if (step.dataset.done === 'true') return; // already done
|
|
|
|
const phase = step.dataset.phase;
|
|
const stepIdx = step.dataset.step;
|
|
sendCommand('/plan done ' + stepIdx);
|
|
});
|
|
|
|
// ── Skills tab ──
|
|
function renderSkillsFromData(data) {
|
|
var loading = document.getElementById('skills-loading');
|
|
var el = document.getElementById('skills-list');
|
|
loading.style.display = 'none';
|
|
el.style.display = 'block';
|
|
|
|
if (!data || data.length === 0) {
|
|
el.innerHTML = '<div class="empty-state">No skills installed.</div>';
|
|
return;
|
|
}
|
|
|
|
el.innerHTML = data.map(function(s) {
|
|
return '<div class="skill-item" data-skill="' + escapeAttr(s.name) + '">' +
|
|
'<div class="skill-body">' +
|
|
'<div class="skill-name">' + escapeHtml(s.name) + '</div>' +
|
|
'<div class="skill-desc">' + escapeHtml(s.description || 'No description') + '</div>' +
|
|
'<span class="skill-source">' + escapeHtml(s.source) + '</span>' +
|
|
'</div>' +
|
|
'<span class="skill-arrow">\u203A</span>' +
|
|
'</div>';
|
|
}).join('');
|
|
|
|
if (selectedSkill) {
|
|
var prev = el.querySelector('[data-skill="' + CSS.escape(selectedSkill) + '"]');
|
|
if (prev) prev.classList.add('selected');
|
|
}
|
|
|
|
el.querySelectorAll('.skill-item').forEach(function(item) {
|
|
item.addEventListener('click', function() {
|
|
if (selectedSkill === item.dataset.skill) {
|
|
item.classList.remove('selected');
|
|
selectedSkill = null;
|
|
document.getElementById('send-bar').style.display = 'none';
|
|
return;
|
|
}
|
|
el.querySelectorAll('.skill-item').forEach(function(i) { i.classList.remove('selected'); });
|
|
item.classList.add('selected');
|
|
selectedSkill = item.dataset.skill;
|
|
document.getElementById('send-bar').style.display = 'flex';
|
|
document.getElementById('skill-msg').placeholder = 'Message for /' + selectedSkill + '...';
|
|
document.getElementById('skill-msg').focus();
|
|
});
|
|
});
|
|
}
|
|
|
|
async function loadSkills() {
|
|
var loading = document.getElementById('skills-loading');
|
|
var el = document.getElementById('skills-list');
|
|
loading.style.display = 'block';
|
|
loading.textContent = 'Loading skills...';
|
|
el.style.display = 'none';
|
|
|
|
try {
|
|
var data = await apiFetch('/miniapp/api/skills');
|
|
renderSkillsFromData(data);
|
|
} catch (e) {
|
|
loading.textContent = 'Failed to load skills.';
|
|
loading.style.display = 'block';
|
|
el.style.display = 'none';
|
|
}
|
|
}
|
|
|
|
// ── Session tab ──
|
|
function formatAge(sec) {
|
|
if (sec < 60) return sec + 's ago';
|
|
if (sec < 3600) return Math.floor(sec / 60) + 'm ago';
|
|
return Math.floor(sec / 3600) + 'h ago';
|
|
}
|
|
|
|
function shortSessionKey(key) {
|
|
// "agent:default:telegram:123" → "telegram:123"
|
|
var parts = key.split(':');
|
|
if (parts.length > 2) return parts.slice(2).join(':');
|
|
return key;
|
|
}
|
|
|
|
function renderActiveSessions(sessions) {
|
|
if (!sessions || sessions.length === 0) {
|
|
return '<div class="card">' +
|
|
'<div class="card-title">Active Sessions</div>' +
|
|
'<div style="color:var(--hint);font-size:13px">No active sessions</div>' +
|
|
'</div>';
|
|
}
|
|
var html = '<div class="card"><div class="card-title">Active Sessions</div>';
|
|
for (var i = 0; i < sessions.length; i++) {
|
|
var s = sessions[i];
|
|
var touchDir = s.touch_dir || '\u2014';
|
|
html += '<div style="padding:6px 0;border-bottom:1px solid var(--secondary-bg)">' +
|
|
'<div style="display:flex;align-items:center;gap:6px">' +
|
|
'<span style="color:var(--done);font-size:10px">\u25CF</span>' +
|
|
'<span style="font-weight:600;font-size:13px">' + escapeHtml(shortSessionKey(s.session_key)) + '</span>' +
|
|
'<span style="margin-left:auto;color:var(--hint);font-size:12px">' + formatAge(s.age_sec) + '</span>' +
|
|
'</div>' +
|
|
'<div style="color:var(--hint);font-size:12px;padding-left:16px">touch: ' + escapeHtml(touchDir) + '</div>' +
|
|
'</div>';
|
|
}
|
|
html += '</div>';
|
|
return html;
|
|
}
|
|
|
|
function renderSessionFromData(sessions, stats) {
|
|
var loading = document.getElementById('session-loading');
|
|
var el = document.getElementById('session-content');
|
|
loading.style.display = 'none';
|
|
el.style.display = 'block';
|
|
|
|
var html = renderActiveSessions(sessions);
|
|
|
|
if (!stats || stats.status === 'stats not enabled') {
|
|
html += '<div class="empty-state">Stats tracking not enabled.<br>Start gateway with --stats flag.</div>';
|
|
el.innerHTML = html;
|
|
return;
|
|
}
|
|
|
|
var since = stats.since ? new Date(stats.since).toLocaleDateString() : 'N/A';
|
|
var today = stats.today || {};
|
|
html +=
|
|
'<div class="card">' +
|
|
'<div class="card-title">Today</div>' +
|
|
'<div class="stat-row"><span class="stat-label">Prompts</span><span class="stat-value">' + (today.prompts || 0) + '</span></div>' +
|
|
'<div class="stat-row"><span class="stat-label">Requests</span><span class="stat-value">' + (today.requests || 0) + '</span></div>' +
|
|
'<div class="stat-row"><span class="stat-label">Tokens</span><span class="stat-value">' + formatTokens(today.total_tokens || 0) + '</span></div>' +
|
|
'</div>' +
|
|
'<div class="card">' +
|
|
'<div class="card-title">All Time (since ' + escapeHtml(since) + ')</div>' +
|
|
'<div class="stat-row"><span class="stat-label">Prompts</span><span class="stat-value">' + (stats.total_prompts || 0) + '</span></div>' +
|
|
'<div class="stat-row"><span class="stat-label">Requests</span><span class="stat-value">' + (stats.total_requests || 0) + '</span></div>' +
|
|
'<div class="stat-row"><span class="stat-label">Total Tokens</span><span class="stat-value">' + formatTokens(stats.total_tokens || 0) + '</span></div>' +
|
|
'<div class="stat-row"><span class="stat-label">Prompt Tokens</span><span class="stat-value">' + formatTokens(stats.total_prompt_tokens || 0) + '</span></div>' +
|
|
'<div class="stat-row"><span class="stat-label">Completion Tokens</span><span class="stat-value">' + formatTokens(stats.total_completion_tokens || 0) + '</span></div>' +
|
|
'</div>';
|
|
|
|
el.innerHTML = html;
|
|
}
|
|
|
|
async function loadSession() {
|
|
var loading = document.getElementById('session-loading');
|
|
var el = document.getElementById('session-content');
|
|
loading.style.display = 'block';
|
|
loading.textContent = 'Loading session...';
|
|
el.style.display = 'none';
|
|
|
|
try {
|
|
var results = await Promise.all([
|
|
apiFetch('/miniapp/api/session'),
|
|
apiFetch('/miniapp/api/sessions').catch(function() { return []; }),
|
|
]);
|
|
renderSessionFromData(results[1], results[0]);
|
|
} catch (e) {
|
|
loading.textContent = 'Failed to load session.';
|
|
loading.style.display = 'block';
|
|
el.style.display = 'none';
|
|
}
|
|
}
|
|
|
|
function formatTokens(n) {
|
|
if (n >= 1000000) return (n / 1000000).toFixed(1) + 'M';
|
|
if (n >= 1000) return (n / 1000).toFixed(1) + 'K';
|
|
return String(n);
|
|
}
|
|
|
|
function escapeHtml(s) {
|
|
if (!s) return '';
|
|
return s.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
}
|
|
|
|
function escapeAttr(s) {
|
|
if (!s) return '';
|
|
return s.replace(/&/g, '&').replace(/"/g, '"').replace(/'/g, ''');
|
|
}
|
|
|
|
// ── SSE real-time updates ──
|
|
var eventSource = null;
|
|
|
|
function connectSSE() {
|
|
if (eventSource) eventSource.close();
|
|
eventSource = new EventSource(
|
|
API_BASE + '/miniapp/api/events?initData=' + encodeURIComponent(initData)
|
|
);
|
|
eventSource.addEventListener('plan', function(e) {
|
|
try { renderPlanFromData(JSON.parse(e.data)); } catch(err) {}
|
|
});
|
|
eventSource.addEventListener('session', function(e) {
|
|
try {
|
|
var d = JSON.parse(e.data);
|
|
renderSessionFromData(d.sessions, d.stats);
|
|
} catch(err) {}
|
|
});
|
|
eventSource.addEventListener('skills', function(e) {
|
|
try { renderSkillsFromData(JSON.parse(e.data)); } catch(err) {}
|
|
});
|
|
eventSource.onerror = function() {
|
|
// Browser will auto-reconnect EventSource
|
|
};
|
|
}
|
|
|
|
connectSSE();
|
|
|
|
// Initial load (fallback for tabs not covered by initial SSE burst)
|
|
loadPlan();
|
|
</script>
|
|
</body>
|
|
</html>
|