index.html was loading map.js via <script src="map.js"> but the file was not embedded or served, causing a 404 that left loadMapAsset undefined → connectOrchWs() threw before creating the WebSocket → status stayed at "Connecting…" forever. - //go:embed now includes static/map.js alongside static/index.html - Added /miniapp/map.js route served from embedded FS - Updated script src to absolute path /miniapp/map.js - map.js stays as a readable standalone file (not inlined) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2002 lines
65 KiB
HTML
2002 lines
65 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(100%/7 - 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;
|
|
}
|
|
|
|
.hidden { display: none !important; }
|
|
|
|
.glass {
|
|
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);
|
|
}
|
|
.glass-interactive { border-color: var(--glass-border-interactive); }
|
|
|
|
.panel { display: none; padding: 16px; }
|
|
.panel.active { display: block; }
|
|
|
|
.card {
|
|
padding: 16px;
|
|
margin-bottom: 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 {
|
|
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;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 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;
|
|
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;
|
|
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;
|
|
-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;
|
|
}
|
|
|
|
.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);
|
|
}
|
|
|
|
/* Slide to Approve */
|
|
.slide-approve-wrap {
|
|
margin-top: 16px;
|
|
}
|
|
|
|
.slide-approve-track {
|
|
position: relative;
|
|
height: 56px;
|
|
border-radius: 28px;
|
|
overflow: hidden;
|
|
touch-action: none;
|
|
border: 1.5px solid;
|
|
border-image: linear-gradient(135deg, var(--btn), var(--glass-border)) 1;
|
|
border-image: none;
|
|
border-color: var(--btn);
|
|
box-shadow: 0 2px 8px rgba(0,0,0,0.18), inset 0 1px 0 rgba(255,255,255,0.08);
|
|
transition: background 0.3s, border-color 0.3s, box-shadow 0.3s;
|
|
}
|
|
|
|
.slide-approve-track.approved {
|
|
background: var(--done);
|
|
border-color: var(--done);
|
|
box-shadow: 0 0 16px rgba(76,175,80,0.4), 0 2px 8px rgba(0,0,0,0.18);
|
|
}
|
|
|
|
.slide-approve-thumb {
|
|
position: absolute;
|
|
top: 3px;
|
|
left: 3px;
|
|
width: 50px;
|
|
height: 50px;
|
|
border-radius: 50%;
|
|
background: var(--btn);
|
|
color: var(--btn-text);
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
cursor: grab;
|
|
transition: left 0.3s cubic-bezier(0.25, 1, 0.5, 1);
|
|
z-index: 1;
|
|
user-select: none;
|
|
-webkit-user-select: none;
|
|
box-shadow: 0 2px 6px rgba(0,0,0,0.25);
|
|
}
|
|
|
|
.slide-approve-thumb svg {
|
|
width: 22px;
|
|
height: 22px;
|
|
}
|
|
|
|
.slide-approve-thumb.dragging {
|
|
transition: none;
|
|
cursor: grabbing;
|
|
}
|
|
|
|
@keyframes shimmer {
|
|
0%, 100% { opacity: 0.7; }
|
|
50% { opacity: 1; }
|
|
}
|
|
|
|
.slide-approve-label {
|
|
position: absolute;
|
|
top: 0;
|
|
left: 0;
|
|
right: 0;
|
|
bottom: 0;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
color: var(--text);
|
|
font-size: 15px;
|
|
font-weight: 600;
|
|
pointer-events: none;
|
|
user-select: none;
|
|
-webkit-user-select: none;
|
|
transition: color 0.3s;
|
|
animation: shimmer 2.5s ease-in-out infinite;
|
|
}
|
|
|
|
.slide-approve-track.approved .slide-approve-label {
|
|
color: #fff;
|
|
animation: none;
|
|
}
|
|
|
|
/* Git log */
|
|
.git-commit {
|
|
display: flex;
|
|
gap: 8px;
|
|
padding: 10px 12px;
|
|
border-bottom: 1px solid var(--glass-border);
|
|
font-size: 13px;
|
|
line-height: 1.4;
|
|
}
|
|
.git-commit:last-child { border-bottom: none; }
|
|
.git-hash {
|
|
font-family: monospace;
|
|
color: var(--btn);
|
|
flex-shrink: 0;
|
|
}
|
|
.git-subject { flex: 1; color: var(--text); }
|
|
.git-meta { color: var(--hint); font-size: 11px; flex-shrink: 0; text-align: right; }
|
|
.git-status {
|
|
font-family: monospace;
|
|
font-weight: 700;
|
|
font-size: 12px;
|
|
flex-shrink: 0;
|
|
width: 24px;
|
|
text-align: center;
|
|
}
|
|
.git-status-m { color: #e2b93d; }
|
|
.git-status-a { color: #4caf50; }
|
|
.git-status-d { color: #ef5350; }
|
|
.git-status-u { color: var(--hint); }
|
|
|
|
.git-repo-item {
|
|
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;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 12px;
|
|
-webkit-tap-highlight-color: transparent;
|
|
}
|
|
.git-repo-item:active { transform: scale(0.98); }
|
|
.git-repo-body { flex: 1; min-width: 0; }
|
|
.git-repo-name { font-weight: 600; font-size: 15px; margin-bottom: 4px; }
|
|
.git-repo-branch {
|
|
font-size: 13px;
|
|
color: var(--hint);
|
|
font-family: monospace;
|
|
}
|
|
.git-repo-arrow {
|
|
color: var(--hint);
|
|
font-size: 22px;
|
|
flex-shrink: 0;
|
|
}
|
|
.git-back-btn {
|
|
display: inline-flex;
|
|
align-items: center;
|
|
gap: 4px;
|
|
color: var(--btn);
|
|
font-size: 14px;
|
|
font-weight: 600;
|
|
background: none;
|
|
border: none;
|
|
cursor: pointer;
|
|
padding: 8px 0;
|
|
margin-bottom: 8px;
|
|
-webkit-tap-highlight-color: transparent;
|
|
}
|
|
.git-back-btn:active { opacity: 0.6; }
|
|
|
|
/* Dev header */
|
|
.dev-header {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
padding: 8px 4px;
|
|
margin-bottom: 8px;
|
|
}
|
|
.dev-header-title { font-weight: 600; font-size: 15px; }
|
|
.dev-header-target {
|
|
color: var(--hint);
|
|
font-size: 13px;
|
|
margin-left: auto;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
/* Dev target cards */
|
|
.dev-target-item {
|
|
padding: 12px 14px;
|
|
margin-bottom: 8px;
|
|
cursor: pointer;
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
transition: transform 0.2s cubic-bezier(0.25, 1, 0.5, 1), box-shadow 0.2s, border-color 0.2s;
|
|
-webkit-tap-highlight-color: transparent;
|
|
}
|
|
.dev-target-item:active { transform: scale(0.98); }
|
|
.dev-target-item.active {
|
|
border-color: var(--btn);
|
|
box-shadow: 0 2px 8px var(--glass-shadow);
|
|
}
|
|
.dev-target-dot {
|
|
width: 10px;
|
|
height: 10px;
|
|
border-radius: 50%;
|
|
flex-shrink: 0;
|
|
background: var(--hint);
|
|
}
|
|
.dev-target-dot.on { background: var(--done); }
|
|
.dev-target-name { font-weight: 600; font-size: 14px; }
|
|
.dev-target-url {
|
|
color: var(--hint);
|
|
font-size: 13px;
|
|
margin-left: auto;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
}
|
|
.dev-target-delete {
|
|
flex-shrink: 0;
|
|
width: 24px;
|
|
height: 24px;
|
|
padding: 6px;
|
|
margin: -6px;
|
|
margin-left: 8px;
|
|
border-radius: 50%;
|
|
color: var(--hint);
|
|
cursor: pointer;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
transition: color 0.15s, background 0.15s;
|
|
-webkit-tap-highlight-color: transparent;
|
|
}
|
|
.dev-target-delete:active {
|
|
color: #ff3b30;
|
|
background: rgba(255, 59, 48, 0.1);
|
|
}
|
|
|
|
/* Log viewer */
|
|
.log-filter-chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
|
|
.log-filter-chip {
|
|
padding: 4px 10px;
|
|
border-radius: 12px;
|
|
font-size: 12px;
|
|
font-weight: 500;
|
|
border: 1px solid var(--glass-border-interactive);
|
|
background: var(--glass-bg);
|
|
color: var(--hint);
|
|
cursor: pointer;
|
|
transition: all 0.2s;
|
|
-webkit-tap-highlight-color: transparent;
|
|
}
|
|
.log-filter-chip.active {
|
|
background: var(--btn);
|
|
color: var(--btn-text);
|
|
border-color: var(--btn);
|
|
}
|
|
#logs-content {
|
|
max-height: 50vh;
|
|
overflow-y: auto;
|
|
-webkit-overflow-scrolling: touch;
|
|
}
|
|
.log-entry {
|
|
display: flex;
|
|
align-items: flex-start;
|
|
gap: 6px;
|
|
padding: 3px 0;
|
|
font-size: 11px;
|
|
font-family: 'SF Mono', 'Menlo', 'Consolas', monospace;
|
|
line-height: 1.4;
|
|
border-bottom: 1px solid var(--glass-divider);
|
|
}
|
|
.log-ts { color: var(--hint); flex-shrink: 0; white-space: nowrap; }
|
|
.log-badge {
|
|
flex-shrink: 0;
|
|
padding: 0 4px;
|
|
border-radius: 4px;
|
|
font-size: 9px;
|
|
font-weight: 700;
|
|
text-transform: uppercase;
|
|
line-height: 16px;
|
|
}
|
|
.log-badge.error { background: rgba(255,59,48,0.15); color: #ff3b30; }
|
|
.log-badge.warn { background: rgba(255,204,0,0.15); color: #cc9900; }
|
|
.log-badge.info { background: rgba(52,199,89,0.12); color: #34c759; }
|
|
.log-badge.debug { background: rgba(142,142,147,0.12); color: #8e8e93; }
|
|
.log-comp { color: var(--link); flex-shrink: 0; font-size: 10px; }
|
|
.log-msg { flex: 1; word-break: break-all; color: var(--text); }
|
|
.log-fields { color: var(--hint); font-size: 10px; }
|
|
.log-actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
|
|
.log-snap-btn {
|
|
padding: 6px 12px;
|
|
border-radius: 10px;
|
|
font-size: 12px;
|
|
font-weight: 500;
|
|
background: var(--glass-bg);
|
|
border: 1px solid var(--glass-border-interactive);
|
|
color: var(--text);
|
|
cursor: pointer;
|
|
}
|
|
|
|
/* ── Orch panel ── */
|
|
.orch-room-row { display:flex; align-items:flex-start; padding:12px 0; }
|
|
.orch-side { display:flex; flex-direction:column; align-items:center; gap:12px; padding-top:20px; width:40px; flex-shrink:0; }
|
|
.orch-badge { display:flex; flex-direction:column; align-items:center; gap:3px; opacity:0.3; transition:opacity 0.3s; }
|
|
.orch-badge.alive { opacity:1; }
|
|
.orch-badge.alive .orch-badge-label { color:#4a6ac0; }
|
|
.orch-badge.alive .orch-badge-dot { background:#4ade80; }
|
|
.orch-badge.toolcall .orch-badge-dot { background:#fb923c; animation:orch-blink 0.2s step-end infinite; }
|
|
.orch-badge.waiting .orch-badge-dot { background:#60a5fa; }
|
|
.orch-badge.talking .orch-badge-label{ color:#facc15; }
|
|
.orch-badge.talking .orch-badge-dot { background:#facc15; animation:orch-blink 0.6s step-end infinite; }
|
|
.orch-badge-emoji { font-size:16px; line-height:1; }
|
|
.orch-badge-label { font-size:7px; color:var(--hint); letter-spacing:0.05em; text-transform:uppercase; }
|
|
.orch-badge-dot { width:4px; height:4px; border-radius:50%; background:var(--hint); }
|
|
@keyframes orch-blink { 50% { opacity:0; } }
|
|
.orch-canvas-wrap { flex:1; min-width:0; border-radius:12px; overflow:hidden; background:#060810; }
|
|
.orch-canvas-wrap canvas { image-rendering:pixelated; image-rendering:crisp-edges; display:block; width:100%; aspect-ratio:1/1; }
|
|
.orch-status { text-align:center; font-size:11px; color:var(--hint); padding:6px 0 4px; }
|
|
.orch-dot { display:inline-block; width:6px; height:6px; border-radius:50%; background:var(--hint); margin-right:4px; vertical-align:middle; }
|
|
.orch-dot.on { background:#4ade80; }
|
|
|
|
</style>
|
|
<link href="https://fonts.googleapis.com/css2?family=Silkscreen&display=swap" rel="stylesheet">
|
|
<script src="/miniapp/map.js"></script>
|
|
</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="git">Git</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>
|
|
<button class="tab" data-panel="dev">Dev</button>
|
|
<button class="tab" data-panel="orch">Orch</button>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="plan" class="panel active">
|
|
<div class="loading" id="plan-loading">Loading plan...</div>
|
|
<div id="plan-content" class="hidden"></div>
|
|
</div>
|
|
|
|
<div id="skills" class="panel">
|
|
<div class="loading" id="skills-loading">Loading skills...</div>
|
|
<div id="skills-list" class="hidden"></div>
|
|
</div>
|
|
|
|
<div id="session" class="panel">
|
|
<div class="loading" id="session-loading">Loading session...</div>
|
|
<div id="session-content" class="hidden"></div>
|
|
<div id="context-content"></div>
|
|
</div>
|
|
|
|
<div id="config" class="panel">
|
|
<div class="card glass">
|
|
<div class="card-title">Quick Commands</div>
|
|
<div class="cmd-tiles">
|
|
<button class="cmd-tile glass glass-interactive" data-cmd="/session">/session</button>
|
|
<button class="cmd-tile glass glass-interactive" data-cmd="/skills">/skills</button>
|
|
<button class="cmd-tile glass glass-interactive" data-cmd="/plan clear">/plan clear</button>
|
|
</div>
|
|
</div>
|
|
<div class="card glass">
|
|
<div class="card-title">Custom Command</div>
|
|
<div style="display:flex;gap:8px;margin-top:8px">
|
|
<input id="custom-cmd" class="send-input glass glass-interactive" placeholder="/command args..." style="flex:1">
|
|
<button class="send-btn" onclick="sendCustomCmd()">Send</button>
|
|
</div>
|
|
</div>
|
|
<div class="card glass" id="logs-section">
|
|
<div style="display:flex;align-items:center;gap:8px;margin-bottom:8px">
|
|
<span class="card-title" style="margin:0">Logs</span>
|
|
<span id="logs-status" class="dev-target-dot"></span>
|
|
</div>
|
|
<div class="log-filter-chips">
|
|
<button class="log-filter-chip active" data-component="">All</button>
|
|
<button class="log-filter-chip" data-component="telego">Telego</button>
|
|
<button class="log-filter-chip" data-component="dev-console">Console</button>
|
|
</div>
|
|
<div id="logs-content"></div>
|
|
<div class="log-actions">
|
|
<button class="log-snap-btn" onclick="saveLogSnapshot()">Save Snapshot</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="git" class="panel">
|
|
<div class="loading" id="git-loading">Loading git log...</div>
|
|
<div id="git-content" class="hidden"></div>
|
|
</div>
|
|
|
|
<div id="dev" class="panel">
|
|
<div id="dev-header" class="dev-header">
|
|
<span id="dev-dot" class="dev-target-dot"></span>
|
|
<span class="dev-header-title">Dev Preview</span>
|
|
<span id="dev-header-target" class="dev-header-target"></span>
|
|
</div>
|
|
<div id="dev-targets-list"></div>
|
|
<div id="dev-iframe-wrap" class="hidden" style="margin-top:8px">
|
|
<div class="card glass" style="padding:0;overflow:hidden">
|
|
<iframe id="dev-iframe" src="" style="width:100%;height:70vh;border:none;border-radius:16px"></iframe>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="orch" class="panel">
|
|
<div class="orch-room-row">
|
|
<div class="orch-side" id="orch-panel-left">
|
|
<div class="orch-badge alive" id="orch-badge-conductor">
|
|
<div class="orch-badge-emoji">👑</div>
|
|
<div class="orch-badge-label">CNDR</div>
|
|
<div class="orch-badge-dot"></div>
|
|
</div>
|
|
<div class="orch-badge alive" id="orch-badge-secretary">
|
|
<div class="orch-badge-emoji">👩💼</div>
|
|
<div class="orch-badge-label">SEC</div>
|
|
<div class="orch-badge-dot"></div>
|
|
</div>
|
|
</div>
|
|
<div class="orch-canvas-wrap">
|
|
<canvas id="orch-canvas" width="320" height="320"></canvas>
|
|
</div>
|
|
<div class="orch-side" id="orch-panel-right">
|
|
<div class="orch-badge" id="orch-badge-s0">
|
|
<div class="orch-badge-emoji">🔍</div>
|
|
<div class="orch-badge-label">SCOUT</div>
|
|
<div class="orch-badge-dot"></div>
|
|
</div>
|
|
<div class="orch-badge" id="orch-badge-s1">
|
|
<div class="orch-badge-emoji">📊</div>
|
|
<div class="orch-badge-label">ANLY</div>
|
|
<div class="orch-badge-dot"></div>
|
|
</div>
|
|
<div class="orch-badge" id="orch-badge-s2">
|
|
<div class="orch-badge-emoji">💻</div>
|
|
<div class="orch-badge-label">CODE</div>
|
|
<div class="orch-badge-dot"></div>
|
|
</div>
|
|
<div class="orch-badge" id="orch-badge-s3">
|
|
<div class="orch-badge-emoji">🔧</div>
|
|
<div class="orch-badge-label">WRKR</div>
|
|
<div class="orch-badge-dot"></div>
|
|
</div>
|
|
<div class="orch-badge" id="orch-badge-s4">
|
|
<div class="orch-badge-emoji">🎯</div>
|
|
<div class="orch-badge-label">CORD</div>
|
|
<div class="orch-badge-dot"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="orch-status">
|
|
<span class="orch-dot" id="orch-status-dot"></span>
|
|
<span id="orch-status-text">Connecting…</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="send-bar hidden" id="send-bar">
|
|
<input id="skill-msg" class="send-input glass glass-interactive" 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;
|
|
var lastSSE = { plan: 0, skills: 0, session: 0, dev: 0 };
|
|
|
|
// Tab switching — re-fetch data unless SSE delivered recently
|
|
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').classList.toggle('hidden',
|
|
!(tab.dataset.panel === 'skills' && selectedSkill));
|
|
|
|
var p = tab.dataset.panel;
|
|
var fresh = lastSSE[p] && (Date.now() - lastSSE[p] < 5000);
|
|
if (p === 'plan' && !fresh) loadPlan();
|
|
if (p === 'skills' && !fresh) loadSkills();
|
|
if (p === 'session' && !fresh) loadSession();
|
|
if (p === 'git') loadGit();
|
|
if (p === 'dev' && !fresh) loadDev();
|
|
if (p === 'config') connectLogsWs();
|
|
else disconnectLogsWs();
|
|
if (p === 'orch') connectOrchWs();
|
|
else disconnectOrchWs();
|
|
});
|
|
});
|
|
|
|
// 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.classList.add('hidden');
|
|
el.classList.remove('hidden');
|
|
|
|
if (!data.has_plan) {
|
|
el.innerHTML = `<div class="empty-state">No active plan.</div>
|
|
<div class="card glass" 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 glass glass-interactive" placeholder="Describe your task...">
|
|
<button class="send-btn" onclick="startPlan()">Start</button>
|
|
</div>
|
|
</div>`;
|
|
return;
|
|
}
|
|
|
|
var html = `<div class="card glass">
|
|
<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') {
|
|
if (data.memory) {
|
|
html += `<div class="memory-view glass">${renderSimpleMarkdown(data.memory)}</div>`;
|
|
}
|
|
if (data.status === 'review') {
|
|
html += `<div class="slide-approve-wrap">
|
|
<div class="slide-approve-track glass glass-interactive" data-cmd="/plan start">
|
|
<div class="slide-approve-thumb"><svg viewBox="0 0 24 24"><path d="M5 12h14m-6-6 6 6-6 6" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" fill="none"/></svg></div>
|
|
<div class="slide-approve-label">Slide to Approve</div>
|
|
</div>
|
|
</div>
|
|
<div class="slide-approve-wrap">
|
|
<div class="slide-approve-track glass glass-interactive" data-cmd="/plan start clear" style="border-color:var(--warn,#ff9800)">
|
|
<div class="slide-approve-thumb" style="background:var(--warn,#ff9800)"><svg viewBox="0 0 24 24"><path d="M5 12h14m-6-6 6 6-6 6" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" fill="none"/></svg></div>
|
|
<div class="slide-approve-label">Approve & Clear History</div>
|
|
</div>
|
|
</div>`;
|
|
}
|
|
} else {
|
|
if (data.phases && data.phases.length > 0) {
|
|
html += renderPhases(data.phases, data.current_phase);
|
|
}
|
|
}
|
|
|
|
el.innerHTML = html;
|
|
if (data.status === 'review') setupSlideApprove();
|
|
}
|
|
|
|
var slideApproveAC = null;
|
|
function setupSlideApprove() {
|
|
if (slideApproveAC) slideApproveAC.abort();
|
|
slideApproveAC = new AbortController();
|
|
var signal = slideApproveAC.signal;
|
|
|
|
var tracks = document.querySelectorAll('.slide-approve-track');
|
|
if (!tracks.length) return;
|
|
|
|
tracks.forEach(function(track) {
|
|
var thumb = track.querySelector('.slide-approve-thumb');
|
|
var label = track.querySelector('.slide-approve-label');
|
|
var cmd = track.getAttribute('data-cmd') || '/plan start';
|
|
var dragging = false;
|
|
var startX = 0;
|
|
var thumbStartLeft = 0;
|
|
|
|
function getMaxLeft() {
|
|
return track.offsetWidth - thumb.offsetWidth - 6;
|
|
}
|
|
|
|
function markAllApproved() {
|
|
tracks.forEach(function(t) {
|
|
t.classList.add('approved');
|
|
t.querySelector('.slide-approve-label').textContent = 'Approved!';
|
|
t.querySelector('.slide-approve-thumb').classList.add('hidden');
|
|
});
|
|
}
|
|
|
|
function onStart(e) {
|
|
if (track.classList.contains('approved')) return;
|
|
dragging = true;
|
|
thumb.classList.add('dragging');
|
|
var clientX = e.touches ? e.touches[0].clientX : e.clientX;
|
|
startX = clientX;
|
|
thumbStartLeft = thumb.offsetLeft - 3;
|
|
e.preventDefault();
|
|
}
|
|
|
|
function onMove(e) {
|
|
if (!dragging) return;
|
|
var clientX = e.touches ? e.touches[0].clientX : e.clientX;
|
|
var dx = clientX - startX;
|
|
var newLeft = Math.max(0, Math.min(thumbStartLeft + dx, getMaxLeft()));
|
|
thumb.style.left = (newLeft + 3) + 'px';
|
|
e.preventDefault();
|
|
}
|
|
|
|
function onEnd(e) {
|
|
if (!dragging) return;
|
|
dragging = false;
|
|
thumb.classList.remove('dragging');
|
|
var currentLeft = thumb.offsetLeft - 3;
|
|
var maxLeft = getMaxLeft();
|
|
if (currentLeft >= maxLeft * 0.8) {
|
|
markAllApproved();
|
|
sendCommand(cmd);
|
|
} else {
|
|
thumb.style.left = '3px';
|
|
}
|
|
}
|
|
|
|
thumb.addEventListener('touchstart', onStart, { passive: false, signal: signal });
|
|
thumb.addEventListener('mousedown', onStart, { signal: signal });
|
|
document.addEventListener('touchmove', onMove, { passive: false, signal: signal });
|
|
document.addEventListener('mousemove', onMove, { signal: signal });
|
|
document.addEventListener('touchend', onEnd, { signal: signal });
|
|
document.addEventListener('mouseup', onEnd, { signal: signal });
|
|
});
|
|
}
|
|
|
|
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 loadTab(loadingId, contentId, label, fetchFn, renderFn) {
|
|
var loading = document.getElementById(loadingId);
|
|
var el = document.getElementById(contentId);
|
|
loading.classList.remove('hidden');
|
|
loading.textContent = 'Loading ' + label + '...';
|
|
el.classList.add('hidden');
|
|
try { renderFn(await fetchFn()); }
|
|
catch (e) { loading.textContent = 'Failed to load ' + label + '.'; }
|
|
}
|
|
|
|
function loadPlan() {
|
|
return loadTab('plan-loading', 'plan-content', 'plan',
|
|
function() { return apiFetch('/miniapp/api/plan'); },
|
|
renderPlanFromData);
|
|
}
|
|
|
|
function renderPhases(phases, currentPhase) {
|
|
return phases.map(phase => {
|
|
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);
|
|
}
|
|
|
|
const progressHtml = total > 0 ? `<span class="phase-progress">${doneCount}/${total}</span>` : '';
|
|
const stepsHtml = phase.steps.map(step => {
|
|
const doneClass = step.done ? 'done' : '';
|
|
const stepClass = step.done ? 'step step-done' : 'step';
|
|
return `<div class="${stepClass}" data-phase="${phase.number}" data-step="${step.index}" data-done="${step.done}">
|
|
<div class="step-check ${doneClass}"></div>
|
|
<div class="step-text ${doneClass}">${escapeHtml(step.description)}</div>
|
|
</div>`;
|
|
}).join('');
|
|
|
|
return `<div class="phase">
|
|
<div class="phase-header">
|
|
<div class="phase-indicator ${indicatorClass}">${indicator}</div>
|
|
<span class="phase-title">${escapeHtml(phase.title || 'Phase ' + phase.number)}</span>
|
|
${progressHtml}
|
|
</div>
|
|
${stepsHtml}
|
|
</div>`;
|
|
}).join('');
|
|
}
|
|
|
|
// 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.classList.add('hidden');
|
|
el.classList.remove('hidden');
|
|
|
|
if (!data || data.length === 0) {
|
|
el.innerHTML = '<div class="empty-state">No skills installed.</div>';
|
|
return;
|
|
}
|
|
|
|
el.innerHTML = data.map(s => `<div class="skill-item glass glass-interactive" 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');
|
|
}
|
|
}
|
|
|
|
// Delegate click on skills — single listener, registered once
|
|
document.getElementById('skills-list').addEventListener('click', function(e) {
|
|
var item = e.target.closest('.skill-item');
|
|
if (!item) return;
|
|
var el = document.getElementById('skills-list');
|
|
if (selectedSkill === item.dataset.skill) {
|
|
item.classList.remove('selected');
|
|
selectedSkill = null;
|
|
document.getElementById('send-bar').classList.add('hidden');
|
|
return;
|
|
}
|
|
el.querySelectorAll('.skill-item').forEach(function(i) { i.classList.remove('selected'); });
|
|
item.classList.add('selected');
|
|
selectedSkill = item.dataset.skill;
|
|
document.getElementById('send-bar').classList.remove('hidden');
|
|
document.getElementById('skill-msg').placeholder = 'Message for /' + selectedSkill + '...';
|
|
document.getElementById('skill-msg').focus();
|
|
});
|
|
|
|
function loadSkills() {
|
|
return loadTab('skills-loading', 'skills-list', 'skills',
|
|
function() { return apiFetch('/miniapp/api/skills'); },
|
|
renderSkillsFromData);
|
|
}
|
|
|
|
// ── 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 glass">
|
|
<div class="card-title">Active Sessions</div>
|
|
<div style="color:var(--hint);font-size:13px">No active sessions</div>
|
|
</div>`;
|
|
}
|
|
return `<div class="card glass"><div class="card-title">Active Sessions</div>
|
|
${sessions.map(s => {
|
|
var touchDir = s.touch_dir || '\u2014';
|
|
return `<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>`;
|
|
}).join('')}
|
|
</div>`;
|
|
}
|
|
|
|
function renderSessionFromData(sessions, stats) {
|
|
var loading = document.getElementById('session-loading');
|
|
var el = document.getElementById('session-content');
|
|
loading.classList.add('hidden');
|
|
el.classList.remove('hidden');
|
|
|
|
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 glass">
|
|
<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 glass">
|
|
<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;
|
|
}
|
|
|
|
var cachedContextInfo = null;
|
|
|
|
function renderContextCard(ctx) {
|
|
if (!ctx) return '';
|
|
cachedContextInfo = ctx;
|
|
var wd = ctx.work_dir || '\u2014';
|
|
var pwd = ctx.plan_work_dir || '\u2014';
|
|
var ws = ctx.workspace || '\u2014';
|
|
var filesHtml = '';
|
|
if (ctx.bootstrap && ctx.bootstrap.length) {
|
|
filesHtml = ctx.bootstrap.map(function(b) {
|
|
var path = b.path ? escapeHtml(b.path) : '\u2014';
|
|
var scope = b.scope === 'global' ? 'global' : 'project';
|
|
var found = b.path ? 'var(--text)' : 'var(--hint)';
|
|
return `<div style="display:flex;gap:8px;padding:2px 0;font-size:12px">
|
|
<span style="min-width:90px;font-weight:600;color:${found}">${escapeHtml(b.name)}</span>
|
|
<span style="color:var(--hint);flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap" title="${path}">${path}</span>
|
|
<span style="color:var(--hint);font-size:11px">${scope}</span>
|
|
</div>`;
|
|
}).join('');
|
|
}
|
|
return `<div class="card glass">
|
|
<div class="card-title">Context</div>
|
|
<div style="font-size:12px">
|
|
<div class="stat-row"><span class="stat-label">workDir</span><span class="stat-value" style="font-size:12px;overflow:hidden;text-overflow:ellipsis" title="${escapeHtml(wd)}">${escapeHtml(wd)}</span></div>
|
|
<div class="stat-row"><span class="stat-label">planWorkDir</span><span class="stat-value" style="font-size:12px;overflow:hidden;text-overflow:ellipsis" title="${escapeHtml(pwd)}">${escapeHtml(pwd)}</span></div>
|
|
<div class="stat-row"><span class="stat-label">workspace</span><span class="stat-value" style="font-size:12px;overflow:hidden;text-overflow:ellipsis" title="${escapeHtml(ws)}">${escapeHtml(ws)}</span></div>
|
|
</div>
|
|
<div style="margin-top:8px">${filesHtml}</div>
|
|
<div style="margin-top:8px;text-align:center">
|
|
<button onclick="toggleSystemPrompt()" style="background:var(--secondary-bg);color:var(--text);border:none;padding:6px 12px;border-radius:8px;font-size:12px;cursor:pointer" id="prompt-toggle-btn">Show System Prompt</button>
|
|
</div>
|
|
<pre id="system-prompt-view" style="display:none;margin-top:8px;font-size:11px;max-height:400px;overflow:auto;background:var(--secondary-bg);padding:8px;border-radius:6px;white-space:pre-wrap;word-break:break-word"></pre>
|
|
</div>`;
|
|
}
|
|
|
|
function toggleSystemPrompt() {
|
|
var view = document.getElementById('system-prompt-view');
|
|
var btn = document.getElementById('prompt-toggle-btn');
|
|
if (!view || !btn) return;
|
|
if (view.style.display === 'none') {
|
|
btn.textContent = 'Loading...';
|
|
apiFetch('/miniapp/api/prompt').then(function(data) {
|
|
view.textContent = data.prompt || '(empty)';
|
|
view.style.display = 'block';
|
|
btn.textContent = 'Hide System Prompt';
|
|
}).catch(function() {
|
|
btn.textContent = 'Show System Prompt';
|
|
});
|
|
} else {
|
|
view.style.display = 'none';
|
|
btn.textContent = 'Show System Prompt';
|
|
}
|
|
}
|
|
|
|
function renderContextFromData(ctx) {
|
|
var el = document.getElementById('context-content');
|
|
if (el) el.innerHTML = renderContextCard(ctx);
|
|
}
|
|
|
|
function loadSession() {
|
|
return loadTab('session-loading', 'session-content', 'session',
|
|
function() {
|
|
return Promise.all([
|
|
apiFetch('/miniapp/api/session'),
|
|
apiFetch('/miniapp/api/sessions').catch(function() { return []; }),
|
|
apiFetch('/miniapp/api/context').catch(function() { return null; }),
|
|
]);
|
|
},
|
|
function(results) {
|
|
renderSessionFromData(results[1], results[0]);
|
|
renderContextFromData(results[2]);
|
|
});
|
|
}
|
|
|
|
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, ''');
|
|
}
|
|
|
|
// ── Git tab ──
|
|
var gitSelectedRepo = null;
|
|
|
|
function loadGit() {
|
|
gitSelectedRepo = null;
|
|
return loadTab('git-loading', 'git-content', 'repositories',
|
|
function() { return apiFetch('/miniapp/api/git'); },
|
|
renderGitRepos);
|
|
}
|
|
|
|
function renderGitRepos(repos) {
|
|
var loading = document.getElementById('git-loading');
|
|
var el = document.getElementById('git-content');
|
|
loading.classList.add('hidden');
|
|
el.classList.remove('hidden');
|
|
|
|
if (!repos || repos.length === 0) {
|
|
el.innerHTML = '<div class="empty-state">No git repositories found.</div>';
|
|
return;
|
|
}
|
|
|
|
el.innerHTML = repos.map(function(r) {
|
|
return '<div class="git-repo-item glass glass-interactive" data-repo="' + escapeAttr(r.name) + '">' +
|
|
'<div class="git-repo-body">' +
|
|
'<div class="git-repo-name">' + escapeHtml(r.name) + '</div>' +
|
|
'<div class="git-repo-branch">' + escapeHtml(r.branch || '?') + '</div>' +
|
|
'</div>' +
|
|
'<span class="git-repo-arrow">\u203A</span>' +
|
|
'</div>';
|
|
}).join('');
|
|
}
|
|
|
|
document.getElementById('git-content').addEventListener('click', function(e) {
|
|
var item = e.target.closest('.git-repo-item');
|
|
if (!item) return;
|
|
loadGitDetail(item.dataset.repo);
|
|
});
|
|
|
|
function loadGitDetail(name) {
|
|
gitSelectedRepo = name;
|
|
return loadTab('git-loading', 'git-content', name,
|
|
function() { return apiFetch('/miniapp/api/git?repo=' + encodeURIComponent(name)); },
|
|
renderGitDetail);
|
|
}
|
|
|
|
function renderGitDetail(repo) {
|
|
var loading = document.getElementById('git-loading');
|
|
var el = document.getElementById('git-content');
|
|
loading.classList.add('hidden');
|
|
el.classList.remove('hidden');
|
|
|
|
var html = '<button class="git-back-btn" onclick="loadGit()">\u2190 ' + escapeHtml(repo.name || gitSelectedRepo) + '</button>';
|
|
|
|
html += '<div class="card glass"><div class="card-title">' +
|
|
escapeHtml(repo.name) + ' — ' + escapeHtml(repo.branch || '?') + '</div>';
|
|
|
|
if (repo.modified && repo.modified.length > 0) {
|
|
html += '<div style="padding:4px 12px 8px;font-size:12px;color:var(--hint)">Changes (' + repo.modified.length + ')</div>';
|
|
repo.modified.forEach(function(f) {
|
|
html += '<div class="git-commit">' +
|
|
'<span class="git-status git-status-' + (f.status === '??' ? 'u' : f.status.toLowerCase()) + '">' + escapeHtml(f.status) + '</span>' +
|
|
'<span class="git-subject">' + escapeHtml(f.path) + '</span>' +
|
|
'</div>';
|
|
});
|
|
}
|
|
|
|
if (repo.commits && repo.commits.length > 0) {
|
|
html += '<div style="padding:4px 12px 8px;font-size:12px;color:var(--hint)">Commits</div>';
|
|
repo.commits.forEach(function(c) {
|
|
html += '<div class="git-commit">' +
|
|
'<span class="git-hash">' + escapeHtml(c.hash) + '</span>' +
|
|
'<span class="git-subject">' + escapeHtml(c.subject) + '</span>' +
|
|
'<span class="git-meta">' + escapeHtml(c.date) + '</span>' +
|
|
'</div>';
|
|
});
|
|
} else {
|
|
html += '<div style="padding:12px;color:var(--hint)">No commits found.</div>';
|
|
}
|
|
html += '</div>';
|
|
|
|
el.innerHTML = html;
|
|
}
|
|
|
|
// ── Dev tab ──
|
|
var devActiveId = '';
|
|
|
|
function renderDevFromData(data) {
|
|
var dot = document.getElementById('dev-dot');
|
|
var headerTarget = document.getElementById('dev-header-target');
|
|
var targetsList = document.getElementById('dev-targets-list');
|
|
var iframeWrap = document.getElementById('dev-iframe-wrap');
|
|
var iframe = document.getElementById('dev-iframe');
|
|
|
|
var targets = data.targets || [];
|
|
devActiveId = data.active_id || '';
|
|
|
|
if (data.active) {
|
|
dot.classList.add('on');
|
|
headerTarget.textContent = data.target ? data.target.replace(/^https?:\/\//, '') : '';
|
|
iframeWrap.classList.remove('hidden');
|
|
var iframeSrc = location.origin + '/miniapp/dev/';
|
|
if (iframe.src !== iframeSrc) iframe.src = iframeSrc;
|
|
} else {
|
|
dot.classList.remove('on');
|
|
headerTarget.textContent = '';
|
|
iframeWrap.classList.add('hidden');
|
|
iframe.src = '';
|
|
}
|
|
|
|
if (targets.length === 0) {
|
|
targetsList.innerHTML = '<div class="empty-state">No targets registered.<br>Ask the agent to start a dev server.</div>';
|
|
return;
|
|
}
|
|
|
|
targetsList.innerHTML = targets.map(function(t) {
|
|
var isActive = t.id === devActiveId;
|
|
var activeClass = isActive ? ' active' : '';
|
|
var dotClass = isActive ? ' on' : '';
|
|
var displayUrl = t.target.replace(/^https?:\/\//, '');
|
|
return '<div class="dev-target-item glass glass-interactive' + activeClass + '" data-dev-id="' + escapeAttr(t.id) + '">' +
|
|
'<span class="dev-target-dot' + dotClass + '"></span>' +
|
|
'<span class="dev-target-name">' + escapeHtml(t.name) + '</span>' +
|
|
'<span class="dev-target-url">' + escapeHtml(displayUrl) + '</span>' +
|
|
'<span class="dev-target-delete" data-del-id="' + escapeAttr(t.id) + '" data-del-name="' + escapeAttr(t.name) + '">×</span>' +
|
|
'</div>';
|
|
}).join('');
|
|
}
|
|
|
|
// Delegate click on target cards
|
|
document.getElementById('dev-targets-list').addEventListener('click', function(e) {
|
|
var delBtn = e.target.closest('.dev-target-delete');
|
|
if (delBtn) {
|
|
e.stopPropagation();
|
|
var id = delBtn.dataset.delId;
|
|
var name = delBtn.dataset.delName;
|
|
if (confirm('Remove "' + name + '"?')) {
|
|
postDevUnregister(id);
|
|
}
|
|
return;
|
|
}
|
|
var card = e.target.closest('[data-dev-id]');
|
|
if (!card) return;
|
|
postDevAction(card.dataset.devId);
|
|
});
|
|
|
|
async function postDevAction(id) {
|
|
var action = (id === devActiveId) ? 'deactivate' : 'activate';
|
|
var body = action === 'activate' ? { action: 'activate', id: id } : { action: 'deactivate' };
|
|
|
|
try {
|
|
var res = await fetch(API_BASE + '/miniapp/api/dev?initData=' + encodeURIComponent(initData), {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(body),
|
|
});
|
|
var data = await res.json();
|
|
if (!data.error) renderDevFromData(data);
|
|
} catch(e) {}
|
|
}
|
|
|
|
async function postDevUnregister(id) {
|
|
try {
|
|
var res = await fetch(API_BASE + '/miniapp/api/dev?initData=' + encodeURIComponent(initData), {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ action: 'unregister', id: id }),
|
|
});
|
|
var data = await res.json();
|
|
if (!data.error) renderDevFromData(data);
|
|
} catch(e) {}
|
|
}
|
|
|
|
function loadDev() {
|
|
apiFetch('/miniapp/api/dev').then(renderDevFromData).catch(function() {});
|
|
}
|
|
|
|
// ── 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 { lastSSE.plan = Date.now(); renderPlanFromData(JSON.parse(e.data)); } catch(err) {}
|
|
});
|
|
eventSource.addEventListener('session', function(e) {
|
|
try {
|
|
lastSSE.session = Date.now();
|
|
var d = JSON.parse(e.data);
|
|
renderSessionFromData(d.sessions, d.stats);
|
|
} catch(err) {}
|
|
});
|
|
eventSource.addEventListener('skills', function(e) {
|
|
try { lastSSE.skills = Date.now(); renderSkillsFromData(JSON.parse(e.data)); } catch(err) {}
|
|
});
|
|
eventSource.addEventListener('dev', function(e) {
|
|
try { lastSSE.dev = Date.now(); renderDevFromData(JSON.parse(e.data)); } catch(err) {}
|
|
});
|
|
eventSource.addEventListener('context', function(e) {
|
|
try { renderContextFromData(JSON.parse(e.data)); } catch(err) {}
|
|
});
|
|
eventSource.addEventListener('prompt', function(e) {
|
|
try {
|
|
var d = JSON.parse(e.data);
|
|
var view = document.getElementById('system-prompt-view');
|
|
if (view && view.style.display !== 'none') {
|
|
view.textContent = d.prompt || '(empty)';
|
|
}
|
|
} catch(err) {}
|
|
});
|
|
eventSource.onerror = function() {
|
|
// Browser will auto-reconnect EventSource
|
|
};
|
|
}
|
|
|
|
connectSSE();
|
|
|
|
// Initial load (fallback for tabs not covered by initial SSE burst)
|
|
loadPlan();
|
|
|
|
// ── Logs WebSocket ──
|
|
var logsWs = null;
|
|
var logsComponent = '';
|
|
var logsEntries = [];
|
|
var logsReconnectTimer = null;
|
|
|
|
function connectLogsWs() {
|
|
if (logsWs && logsWs.readyState <= 1) return;
|
|
var wsProto = (location.protocol === 'https:') ? 'wss:' : 'ws:';
|
|
var wsUrl = wsProto + '//' + location.host + '/miniapp/api/logs/ws?initData=' +
|
|
encodeURIComponent(initData);
|
|
if (logsComponent) wsUrl += '&component=' + encodeURIComponent(logsComponent);
|
|
|
|
logsWs = new WebSocket(wsUrl);
|
|
var statusDot = document.getElementById('logs-status');
|
|
|
|
logsWs.onopen = function() {
|
|
statusDot.classList.add('on');
|
|
};
|
|
|
|
logsWs.onmessage = function(e) {
|
|
var msg = JSON.parse(e.data);
|
|
if (msg.type === 'init') {
|
|
logsEntries = msg.entries || [];
|
|
} else if (msg.type === 'entry') {
|
|
logsEntries.push(msg.entry);
|
|
if (logsEntries.length > 200) logsEntries.shift();
|
|
}
|
|
renderLogs();
|
|
};
|
|
|
|
logsWs.onclose = function() {
|
|
statusDot.classList.remove('on');
|
|
logsWs = null;
|
|
// Auto-reconnect if Config tab is active
|
|
var activeTab = document.querySelector('.tab.active');
|
|
if (activeTab && activeTab.dataset.panel === 'config') {
|
|
logsReconnectTimer = setTimeout(connectLogsWs, 3000);
|
|
}
|
|
};
|
|
|
|
logsWs.onerror = function() {
|
|
// onclose will handle reconnect
|
|
};
|
|
}
|
|
|
|
function disconnectLogsWs() {
|
|
if (logsReconnectTimer) { clearTimeout(logsReconnectTimer); logsReconnectTimer = null; }
|
|
if (logsWs) { logsWs.close(); logsWs = null; }
|
|
document.getElementById('logs-status').classList.remove('on');
|
|
}
|
|
|
|
function renderLogs() {
|
|
var container = document.getElementById('logs-content');
|
|
var wasScrolledToBottom = container.scrollHeight - container.scrollTop - container.clientHeight < 30;
|
|
var html = '';
|
|
for (var i = 0; i < logsEntries.length; i++) {
|
|
var e = logsEntries[i];
|
|
var lvl = (e.level || 'info').toLowerCase();
|
|
var ts = e.timestamp ? e.timestamp.substring(11, 19) : '';
|
|
var comp = e.component ? '<span class="log-comp">' + escapeHtml(e.component) + '</span>' : '';
|
|
var fields = '';
|
|
if (e.fields && typeof e.fields === 'object') {
|
|
var parts = [];
|
|
for (var k in e.fields) {
|
|
if (e.fields.hasOwnProperty(k)) parts.push(k + '=' + e.fields[k]);
|
|
}
|
|
if (parts.length) fields = ' <span class="log-fields">{' + escapeHtml(parts.join(', ')) + '}</span>';
|
|
}
|
|
html += '<div class="log-entry">' +
|
|
'<span class="log-ts">' + ts + '</span>' +
|
|
'<span class="log-badge ' + lvl + '">' + lvl + '</span>' +
|
|
comp +
|
|
'<span class="log-msg">' + escapeHtml(e.message || '') + fields + '</span>' +
|
|
'</div>';
|
|
}
|
|
container.innerHTML = html;
|
|
if (wasScrolledToBottom) container.scrollTop = container.scrollHeight;
|
|
}
|
|
|
|
// Filter chip click
|
|
document.querySelector('.log-filter-chips').addEventListener('click', function(e) {
|
|
var chip = e.target.closest('.log-filter-chip');
|
|
if (!chip) return;
|
|
document.querySelectorAll('.log-filter-chip').forEach(function(c) { c.classList.remove('active'); });
|
|
chip.classList.add('active');
|
|
logsComponent = chip.dataset.component || '';
|
|
logsEntries = [];
|
|
renderLogs();
|
|
disconnectLogsWs();
|
|
connectLogsWs();
|
|
});
|
|
|
|
// ─── Orchestration room ───────────────────────────────────────────────────
|
|
var orchCanvas = null, orchCtx = null, orchInited = false;
|
|
var orchWs = null, orchReconnectTimer = null;
|
|
var _orchLastTs = null;
|
|
var _orchBOB = [0, -1, -2, -1];
|
|
var _orchFRAME_MS = {idle:450, waiting:650, toolcall:90, talking:280, entering:220, exiting:220};
|
|
var _orchWALK = 55;
|
|
var _orchConductor, _orchSecretary, _orchSubagents, _orchSlots, _orchFreeSlots;
|
|
|
|
function _orchMakeChar(id, emoji, home) {
|
|
return {id:id, emoji:emoji, x:home.x, y:home.y, home:home, target:null, state:'idle',
|
|
frame:0, frameTimer:0, bubble:null, alive:false, _onArrive:null};
|
|
}
|
|
function _orchInitChars() {
|
|
_orchConductor = _orchMakeChar('conductor', '👑', MAP_POSITIONS.conductor);
|
|
_orchSecretary = _orchMakeChar('secretary', '👩💼', MAP_POSITIONS.secretary);
|
|
_orchConductor.alive = true; _orchSecretary.alive = true;
|
|
var ps = [{id:'s0',emoji:'🔍'},{id:'s1',emoji:'📊'},{id:'s2',emoji:'💻'},
|
|
{id:'s3',emoji:'🔧'},{id:'s4',emoji:'🎯'}];
|
|
_orchSubagents = ps.map(function(p,i){
|
|
var c = _orchMakeChar(p.id, p.emoji, MAP_POSITIONS.stations[i]);
|
|
c.x = MAP_POSITIONS.door.x; c.y = MAP_POSITIONS.door.y; return c;
|
|
});
|
|
_orchSlots = {}; _orchFreeSlots = _orchSubagents.slice();
|
|
}
|
|
function _orchAllChars() { return [_orchConductor, _orchSecretary].concat(_orchSubagents); }
|
|
|
|
function _orchSyncBadge(id, state, alive) {
|
|
var el = document.getElementById('orch-badge-' + id); if (!el) return;
|
|
el.className = 'orch-badge'
|
|
+ (alive ? ' alive' : '')
|
|
+ (state==='talking' ? ' talking' : '')
|
|
+ (state==='toolcall'? ' toolcall' : '')
|
|
+ (state==='waiting' ? ' waiting' : '');
|
|
}
|
|
function _orchSetState(c, state) { c.state=state; _orchSyncBadge(c.id, state, c.alive); }
|
|
function _orchMoveTo(c, pos, cb) { c.target=pos; c._onArrive=cb||null; }
|
|
function _orchSay(c, text, ttl) { c.bubble={text:text, ttl:ttl||2200}; }
|
|
|
|
function _orchCharForId(id) {
|
|
if (id === 'heartbeat') return _orchSecretary;
|
|
if (_orchSlots[id]) return _orchSlots[id];
|
|
return _orchConductor;
|
|
}
|
|
function _orchSpawn(id) {
|
|
if (/^subagent-/.test(id)) {
|
|
var c = _orchFreeSlots.shift(); if (!c) return;
|
|
_orchSlots[id]=c; c.alive=true;
|
|
c.x=MAP_POSITIONS.door.x; c.y=MAP_POSITIONS.door.y;
|
|
_orchSetState(c,'entering');
|
|
_orchMoveTo(c, c.home, function(){ _orchSetState(c,'idle'); });
|
|
} else {
|
|
var ch = _orchCharForId(id); ch.alive=true; _orchSetState(ch,'waiting');
|
|
}
|
|
}
|
|
function _orchGC(id) {
|
|
if (/^subagent-/.test(id)) {
|
|
var c=_orchSlots[id]; if (!c) return;
|
|
delete _orchSlots[id]; _orchFreeSlots.push(c);
|
|
_orchSetState(c,'exiting');
|
|
_orchMoveTo(c, MAP_POSITIONS.door, function(){ c.alive=false; _orchSetState(c,'idle'); });
|
|
} else {
|
|
var ch=_orchCharForId(id); ch.alive=false; _orchSetState(ch,'idle');
|
|
}
|
|
}
|
|
function _orchConverse(fromId, toId, text) {
|
|
var from=_orchCharForId(fromId), to=_orchCharForId(toId);
|
|
if (!from||!to||from===to) return;
|
|
var label=(text||'').slice(0,18);
|
|
var mid={x:(from.x+to.x)/2, y:(from.y+to.y)/2};
|
|
_orchSetState(from,'talking'); _orchSetState(to,'talking');
|
|
_orchMoveTo(from, {x:mid.x-18,y:mid.y}, function(){ _orchSay(from,label,2400); });
|
|
_orchMoveTo(to, {x:mid.x+18,y:mid.y}, function(){
|
|
setTimeout(function(){
|
|
_orchMoveTo(from, from.home, function(){ _orchSetState(from,'idle'); });
|
|
_orchMoveTo(to, to.home, function(){ _orchSetState(to, 'idle'); });
|
|
}, 2600);
|
|
});
|
|
}
|
|
function _orchUpdate(dt) {
|
|
_orchAllChars().forEach(function(c){
|
|
if (!c.alive && c.state!=='entering') return;
|
|
c.frameTimer+=dt;
|
|
var dur=_orchFRAME_MS[c.state]||450;
|
|
if (c.frameTimer>=dur){ c.frame=(c.frame+1)%4; c.frameTimer-=dur; }
|
|
if (c.target){
|
|
var dx=c.target.x-c.x, dy=c.target.y-c.y, dist=Math.sqrt(dx*dx+dy*dy);
|
|
if (dist>1.5){ var spd=_orchWALK*dt/1000; c.x+=dx/dist*spd; c.y+=dy/dist*spd; }
|
|
else { c.x=c.target.x; c.y=c.target.y; c.target=null; if(c._onArrive){c._onArrive();c._onArrive=null;} }
|
|
}
|
|
if (c.bubble){ c.bubble.ttl-=dt; if(c.bubble.ttl<=0) c.bubble=null; }
|
|
});
|
|
}
|
|
function _orchDrawBubble(c) {
|
|
if (!c.bubble) return;
|
|
var yOff=_orchBOB[c.frame], bx=c.x, by=c.y+yOff-18;
|
|
orchCtx.font='7px Silkscreen,monospace';
|
|
var tw=orchCtx.measureText(c.bubble.text).width, pw=tw+8, ph=12;
|
|
var lx=Math.max(4,Math.min(316-pw, bx-pw/2));
|
|
orchCtx.fillStyle='#facc15';
|
|
orchCtx.fillRect(Math.floor(lx),Math.floor(by-ph),Math.ceil(pw),Math.ceil(ph));
|
|
orchCtx.fillRect(Math.floor(bx)-1,Math.floor(by),3,3);
|
|
orchCtx.fillStyle='#0a0a00'; orchCtx.textAlign='left'; orchCtx.textBaseline='middle';
|
|
orchCtx.fillText(c.bubble.text, Math.floor(lx+4), Math.floor(by-ph/2));
|
|
}
|
|
function _orchDrawChar(c) {
|
|
if (!c.alive && c.state!=='entering' && c.state!=='exiting') return;
|
|
var yOff=_orchBOB[c.frame], cx=Math.floor(c.x), cy=Math.floor(c.y+yOff);
|
|
if (c.state==='toolcall'){
|
|
orchCtx.fillStyle='rgba(251,146,60,0.35)'; orchCtx.beginPath();
|
|
orchCtx.arc(cx,cy,13,0,Math.PI*2); orchCtx.fill();
|
|
} else if (c.state==='waiting'){
|
|
orchCtx.fillStyle='rgba(96,165,250,0.25)'; orchCtx.beginPath();
|
|
orchCtx.arc(cx,cy,11,0,Math.PI*2); orchCtx.fill();
|
|
}
|
|
orchCtx.font='18px serif'; orchCtx.textAlign='center'; orchCtx.textBaseline='middle';
|
|
orchCtx.fillText(c.emoji, cx, cy);
|
|
orchCtx.font='6px Silkscreen,monospace'; orchCtx.textAlign='center'; orchCtx.textBaseline='top';
|
|
orchCtx.fillStyle=c.state==='talking'?'#facc15':'#3a4a7a';
|
|
orchCtx.fillText(c.id.toUpperCase(), cx, cy+11);
|
|
_orchDrawBubble(c);
|
|
}
|
|
function _orchRender(ts) {
|
|
if (_orchLastTs===null) _orchLastTs=ts;
|
|
var dt=Math.min(ts-_orchLastTs,80); _orchLastTs=ts;
|
|
_orchUpdate(dt);
|
|
orchCtx.imageSmoothingEnabled=false;
|
|
drawMap(orchCtx);
|
|
_orchAllChars().forEach(_orchDrawChar);
|
|
requestAnimationFrame(_orchRender);
|
|
}
|
|
function orchInit() {
|
|
if (orchInited) return; orchInited=true;
|
|
orchCanvas=document.getElementById('orch-canvas');
|
|
orchCtx=orchCanvas.getContext('2d');
|
|
orchCtx.imageSmoothingEnabled=false;
|
|
_orchInitChars();
|
|
loadMapAsset(function(){ _orchLastTs=null; requestAnimationFrame(_orchRender); });
|
|
}
|
|
function connectOrchWs() {
|
|
orchInit();
|
|
if (orchWs && orchWs.readyState<=1) return;
|
|
var proto=location.protocol==='https:'?'wss:':'ws:';
|
|
var url=proto+'//'+location.host+'/miniapp/api/orchestration/ws?initData='+encodeURIComponent(initData);
|
|
orchWs=new WebSocket(url);
|
|
orchWs.onopen=function(){
|
|
document.getElementById('orch-status-dot').classList.add('on');
|
|
document.getElementById('orch-status-text').textContent='Live';
|
|
};
|
|
orchWs.onmessage=function(e){
|
|
var msg; try{ msg=JSON.parse(e.data); }catch(_){ return; }
|
|
if (msg.type==='init') {
|
|
(msg.agents||[]).forEach(function(info){
|
|
_orchSpawn(info.id);
|
|
if (info.state && info.state!=='idle'){
|
|
var c=_orchCharForId(info.id); if(c) _orchSetState(c, info.state);
|
|
}
|
|
});
|
|
} else if (msg.type==='event') {
|
|
var ev=msg.event||{};
|
|
if (ev.type==='agent_spawn') _orchSpawn(ev.id);
|
|
if (ev.type==='agent_state') { var c=_orchCharForId(ev.id); if(c) _orchSetState(c,ev.state); }
|
|
if (ev.type==='agent_gc') _orchGC(ev.id);
|
|
if (ev.type==='conversation') _orchConverse(ev.from, ev.to, ev.text);
|
|
}
|
|
};
|
|
orchWs.onclose=function(){
|
|
document.getElementById('orch-status-dot').classList.remove('on');
|
|
document.getElementById('orch-status-text').textContent='Disconnected';
|
|
orchWs=null;
|
|
var at=document.querySelector('.tab.active');
|
|
if (at && at.dataset.panel==='orch') orchReconnectTimer=setTimeout(connectOrchWs,3000);
|
|
};
|
|
orchWs.onerror=function(){};
|
|
}
|
|
function disconnectOrchWs() {
|
|
if (orchReconnectTimer){ clearTimeout(orchReconnectTimer); orchReconnectTimer=null; }
|
|
if (orchWs){ orchWs.close(); orchWs=null; }
|
|
var dot=document.getElementById('orch-status-dot');
|
|
var txt=document.getElementById('orch-status-text');
|
|
if (dot) dot.classList.remove('on');
|
|
if (txt) txt.textContent='Offline';
|
|
}
|
|
|
|
async function saveLogSnapshot() {
|
|
try {
|
|
var res = await fetch(API_BASE + '/miniapp/api/logs/snapshot?initData=' + encodeURIComponent(initData), {
|
|
method: 'POST'
|
|
});
|
|
if (!res.ok) throw new Error('API error: ' + res.status);
|
|
var data = await res.json();
|
|
if (data.download_url) {
|
|
var a = document.createElement('a');
|
|
a.href = API_BASE + data.download_url + '?initData=' + encodeURIComponent(initData);
|
|
a.download = '';
|
|
document.body.appendChild(a);
|
|
a.click();
|
|
document.body.removeChild(a);
|
|
}
|
|
} catch(e) {
|
|
// silent fail
|
|
}
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|