feat(orchestrator): rename kvb-hub to Agent Orchestrator with the phase 2 surface
Surface (requirement 001 phase 2): navigation Stream (Inbox, Regeln) / Agents / Artifacts with keys 1-3 and hash routes (#graph and #tree redirect), header with title, command palette and settings only, server-side badges (unsnoozed inbox, beats within 900 s, open jobs), a Mayday banner with "aufheben", four stream chips with agent:/art:/seit: search, Filter and time menus, the inbox in main, an agents toolbar (Funk an alle with Newsletter, Broadcast, Pan-Pan, Security, Mayday; Priorität; Tag/Nacht), Post or Call in the agent panel, Ambiente in the settings and read-aloud over the seven classes with Mayday locked. Rename (decision 9): hub/ is orchestrator/, the package kvb_orchestrator, the unit kvb-orchestrator-runner.service, scripts/orchestrator.sh, environment KVB_ORCHESTRATOR_*, make targets orchestrator-*, the MCP server, image and compose project kvb-orchestrator, the guard header X-Kvb-Orchestrator and the message marker [kvb-orchestrator msg <id>]. install runs migrate first: it stops the old container, removes its image and code, moves state, approvals and pinned keys, swaps the MCP registration, the PermissionRequest hook and the runner unit, and changes nothing on a second run (scratch-HOME test with stub docker, claude and systemctl). Saved views fall back to the old localStorage key once. MEDUSA acceptances carried to the renamed paths: 82 rows whose lines are unchanged (reason prefixed "renamed from <old path>, line unchanged"), and 7 rows whose text changed only in the product name, the package name, a temp prefix or a new class argument, each upheld by one kvb-think-criticize skeptic (approval.py:60, messaging.py:53, server.py:56, tests/hub_support.py:64, passkey.py:205, page-agent.js:75, language.py:46). Cost 101 %: the longer name adds 15 tokens of skill text; the operator approved it with the commit. 🎯 Fix: 92 % 💥 Break: 4 % 💸 Cost: 101 % ⏱️ Time: – 🛡️ Security: 100 % 💰 Value: ? 🏆 Score: 87 🚦 Gate: ⚠️ cost 101 % > 100: ask the operator before the commit Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
54f3725aa1
commit
6f940b4415
125 files changed
+1725
-782
No files matched your search
@@ -0,0 +1,216 @@
|
||||
const Ambience = (() => {
|
||||
"use strict";
|
||||
const RAD = Math.PI / 180;
|
||||
const DAY_MS = 86400000;
|
||||
const J2000 = 2451545;
|
||||
const AU = 149597870.7;
|
||||
const EARTH = 6378.14;
|
||||
const GLASS = 0.8;
|
||||
const CARD = 0.92;
|
||||
const LIGHT_FROM = 4;
|
||||
const SKY = [
|
||||
[-90, "#03050b", "#070a14"],
|
||||
[-18, "#04060e", "#0a0f1f"],
|
||||
[-12, "#080d1f", "#18203d"],
|
||||
[-6, "#111c3d", "#3b3763"],
|
||||
[-3, "#1c2b5a", "#8a5b6c"],
|
||||
[0, "#2b4377", "#de8a5e"],
|
||||
[3, "#44679f", "#efab6d"],
|
||||
[6, "#5884bf", "#f1c690"],
|
||||
[12, "#5d92d0", "#c8dbee"],
|
||||
[30, "#4e89d5", "#b4d2f1"],
|
||||
[90, "#3f7fd8", "#a9cbef"],
|
||||
];
|
||||
const STAGES = [[-18, "night"], [-12, "astronomical"], [-6, "nautical"], [0, "civil"], [6, "golden"], [Infinity, "day"]];
|
||||
const THEMES = {
|
||||
light: {
|
||||
bg: "#eef2f7", panel: "#ffffff", sunken: "#f2f4f8", hover: "#eaeef5", text: "#121821", muted: "#434e5f", faint: "#6b7586",
|
||||
line: "#dde3eb", "line-strong": "#c7cfda", accent: "#2f55d4", "accent-soft": "#e6ecfd", "on-accent": "#ffffff",
|
||||
ok: "#16804a", "ok-soft": "#e3f3ea", bad: "#c2352a", "bad-soft": "#fcebea", warn: "#8a5200", "warn-soft": "#fff1d9",
|
||||
info: "#2a5bd0", "info-soft": "#e7eefc", violet: "#6f3fc4", "violet-soft": "#f0e9fb", teal: "#0b7f78", "teal-soft": "#def2f0",
|
||||
"neutral-soft": "#eceff4", direct: "#3a6ff7", broadcast: "#12a39a", alarm: "#e0453a", security: "#8a4bd8", grant: "#2f9e58",
|
||||
"add-bg": "#e7f6ec", "add-text": "#14632f", "del-bg": "#fdeeed", "del-text": "#9b2219", "hunk-bg": "#edf1fd",
|
||||
shadow: "0 1px 2px rgb(15 23 42 / 6%), 0 4px 14px rgb(15 23 42 / 6%)", "shadow-lift": "0 12px 36px rgb(15 23 42 / 16%)",
|
||||
},
|
||||
dark: {
|
||||
bg: "#0b0f15", panel: "#121821", sunken: "#0e131a", hover: "#1a212b", text: "#e7ebf2", muted: "#a3adbb", faint: "#6f7988",
|
||||
line: "#252d38", "line-strong": "#343e4b", accent: "#8fadff", "accent-soft": "#1b2440", "on-accent": "#0b1020",
|
||||
ok: "#4cc47e", "ok-soft": "#12291c", bad: "#ff7b72", "bad-soft": "#341614", warn: "#f2b84b", "warn-soft": "#33260f",
|
||||
info: "#7da5ff", "info-soft": "#18233f", violet: "#b994ff", "violet-soft": "#251a3b", teal: "#43c9bf", "teal-soft": "#0f2a28",
|
||||
"neutral-soft": "#1d242e", direct: "#6f9bff", broadcast: "#3cc7bd", alarm: "#ff6b61", security: "#b58cff", grant: "#4cc97a",
|
||||
"add-bg": "#0f2a1a", "add-text": "#8fe0aa", "del-bg": "#33151a", "del-text": "#ffaaa3", "hunk-bg": "#18213a",
|
||||
shadow: "0 1px 2px rgb(0 0 0 / 40%), 0 6px 18px rgb(0 0 0 / 28%)", "shadow-lift": "0 16px 44px rgb(0 0 0 / 55%)",
|
||||
},
|
||||
};
|
||||
const sin = (deg) => Math.sin(deg * RAD);
|
||||
const cos = (deg) => Math.cos(deg * RAD);
|
||||
const tan = (deg) => Math.tan(deg * RAD);
|
||||
const clamp = (value, low, high) => Math.min(Math.max(value, low), high);
|
||||
const asin = (value) => Math.asin(clamp(value, -1, 1)) / RAD;
|
||||
const acos = (value) => Math.acos(clamp(value, -1, 1)) / RAD;
|
||||
const atan2 = (y, x) => Math.atan2(y, x) / RAD;
|
||||
const wrap = (deg) => ((deg % 360) + 360) % 360;
|
||||
|
||||
function julian(ms) {
|
||||
return ms / DAY_MS + 2440587.5;
|
||||
}
|
||||
|
||||
function centuries(ms) {
|
||||
return (julian(ms) - J2000) / 36525;
|
||||
}
|
||||
|
||||
function sidereal(ms) {
|
||||
const days = julian(ms) - J2000;
|
||||
const t = days / 36525;
|
||||
return wrap(280.46061837 + 360.98564736629 * days + 0.000387933 * t * t - (t * t * t) / 38710000);
|
||||
}
|
||||
|
||||
function obliquity(t) {
|
||||
const omega = 125.04 - 1934.136 * t;
|
||||
return 23 + (26 + (21.448 - t * (46.815 + t * (0.00059 - t * 0.001813))) / 60) / 60 + 0.00256 * cos(omega);
|
||||
}
|
||||
|
||||
function equatorial(lambda, beta, eps) {
|
||||
return {
|
||||
ra: wrap(atan2(sin(lambda) * cos(eps) - tan(beta) * sin(eps), cos(lambda))),
|
||||
dec: asin(sin(beta) * cos(eps) + cos(beta) * sin(eps) * sin(lambda)),
|
||||
};
|
||||
}
|
||||
|
||||
function horizontal(ha, dec, lat) {
|
||||
return {
|
||||
alt: asin(sin(lat) * sin(dec) + cos(lat) * cos(dec) * cos(ha)),
|
||||
az: wrap(atan2(sin(ha), cos(ha) * sin(lat) - tan(dec) * cos(lat)) + 180),
|
||||
};
|
||||
}
|
||||
|
||||
function sun(ms, lat, lon) {
|
||||
const t = centuries(ms);
|
||||
const l0 = wrap(280.46646 + t * (36000.76983 + t * 0.0003032));
|
||||
const m = 357.52911 + t * (35999.05029 - 0.0001537 * t);
|
||||
const e = 0.016708634 - t * (0.000042037 + 0.0000001267 * t);
|
||||
const center = sin(m) * (1.914602 - t * (0.004817 + 0.000014 * t)) + sin(2 * m) * (0.019993 - 0.000101 * t) + sin(3 * m) * 0.000289;
|
||||
const lambda = wrap(l0 + center - 0.00569 - 0.00478 * sin(125.04 - 1934.136 * t));
|
||||
const eps = obliquity(t);
|
||||
const place = equatorial(lambda, 0, eps);
|
||||
const y = tan(eps / 2) ** 2;
|
||||
const eot = (4 * (y * sin(2 * l0) - 2 * e * sin(m) + 4 * e * y * sin(m) * cos(2 * l0) - 0.5 * y * y * sin(4 * l0) - 1.25 * e * e * sin(2 * m))) / RAD;
|
||||
const distance = (1.000001018 * (1 - e * e)) / (1 + e * cos(m + center));
|
||||
const minutes = (((ms % DAY_MS) + DAY_MS) % DAY_MS) / 60000;
|
||||
const ha = (minutes + eot + 4 * lon) / 4 - 180;
|
||||
return {...place, lambda, eot, distance, ha, ...horizontal(ha, place.dec, lat)};
|
||||
}
|
||||
|
||||
function moon(ms, lat, lon) {
|
||||
const t = centuries(ms);
|
||||
const anomaly = 134.9 + 477198.85 * t;
|
||||
const lambda = wrap(218.32 + 481267.881 * t + 6.29 * sin(anomaly) - 1.27 * sin(259.2 - 413335.38 * t) + 0.66 * sin(235.7 + 890534.23 * t)
|
||||
+ 0.21 * sin(269.9 + 954397.7 * t) - 0.19 * sin(357.5 + 35999.05 * t) - 0.11 * sin(186.6 + 966404.05 * t));
|
||||
const beta = 5.13 * sin(93.3 + 483202.03 * t) + 0.28 * sin(228.2 + 960400.87 * t) - 0.28 * sin(318.3 + 6003.18 * t) - 0.17 * sin(217.6 - 407332.2 * t);
|
||||
const parallax = 0.9508 + 0.0518 * cos(anomaly) + 0.0095 * cos(259.2 - 413335.38 * t) + 0.0078 * cos(235.7 + 890534.23 * t) + 0.0028 * cos(269.9 + 954397.7 * t);
|
||||
const place = equatorial(lambda, beta, obliquity(t));
|
||||
const distance = EARTH / sin(parallax);
|
||||
const ha = sidereal(ms) + lon - place.ra;
|
||||
const seen = horizontal(ha, place.dec, lat);
|
||||
const light = sun(ms, lat, lon);
|
||||
const dra = light.ra - place.ra;
|
||||
const elongation = acos(sin(light.dec) * sin(place.dec) + cos(light.dec) * cos(place.dec) * cos(dra));
|
||||
const phase = atan2(light.distance * AU * sin(elongation), distance - light.distance * AU * cos(elongation));
|
||||
const limb = wrap(atan2(cos(light.dec) * sin(dra), sin(light.dec) * cos(place.dec) - cos(light.dec) * sin(place.dec) * cos(dra)));
|
||||
const parallactic = atan2(sin(ha), tan(lat) * cos(place.dec) - sin(place.dec) * cos(ha));
|
||||
return {
|
||||
...place, lambda, beta, distance, phase, limb,
|
||||
alt: seen.alt - parallax * cos(seen.alt),
|
||||
az: seen.az,
|
||||
lit: (1 + cos(phase)) / 2,
|
||||
tilt: wrap(limb - parallactic),
|
||||
waxing: wrap(lambda - light.lambda) < 180,
|
||||
};
|
||||
}
|
||||
|
||||
function hex(text) {
|
||||
return [1, 3, 5].map((index) => parseInt(text.slice(index, index + 2), 16));
|
||||
}
|
||||
|
||||
function mix(from, to, share) {
|
||||
return from.map((value, index) => value + (to[index] - value) * share);
|
||||
}
|
||||
|
||||
function css(rgb) {
|
||||
return `rgb(${rgb.map((value) => Math.round(value)).join(" ")})`;
|
||||
}
|
||||
|
||||
function luminance(rgb) {
|
||||
const [r, g, b] = rgb.map((value) => {
|
||||
const channel = value / 255;
|
||||
return channel <= 0.04045 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4;
|
||||
});
|
||||
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
||||
}
|
||||
|
||||
function contrast(first, second) {
|
||||
const [high, low] = [luminance(first), luminance(second)].sort((a, b) => b - a);
|
||||
return (high + 0.05) / (low + 0.05);
|
||||
}
|
||||
|
||||
function skyAt(alt) {
|
||||
const level = clamp(alt, SKY[0][0], SKY[SKY.length - 1][0]);
|
||||
const index = Math.max(SKY.findIndex(([edge]) => edge >= level), 1);
|
||||
const [low, lowTop, lowBottom] = SKY[index - 1];
|
||||
const [high, highTop, highBottom] = SKY[index];
|
||||
const share = (level - low) / (high - low);
|
||||
return {top: mix(hex(lowTop), hex(highTop), share), bottom: mix(hex(lowBottom), hex(highBottom), share)};
|
||||
}
|
||||
|
||||
function stage(alt) {
|
||||
return STAGES.find(([edge]) => alt < edge)[1];
|
||||
}
|
||||
|
||||
function starlight(alt) {
|
||||
return clamp((-alt - 6) / 10, 0, 1);
|
||||
}
|
||||
|
||||
function modeAt(alt) {
|
||||
return alt >= LIGHT_FROM ? "light" : "dark";
|
||||
}
|
||||
|
||||
function modeOf(top, bottom) {
|
||||
return luminance(mix(hex(top), hex(bottom), 0.5)) > 0.2 ? "light" : "dark";
|
||||
}
|
||||
|
||||
function stars(count, seed) {
|
||||
let state = seed >>> 0;
|
||||
const next = () => {
|
||||
state = (Math.imul(state, 1664525) + 1013904223) >>> 0;
|
||||
return state / 4294967296;
|
||||
};
|
||||
return Array.from({length: count}, () => ({ra: next() * 360, dec: asin(next() * 2 - 1), glow: next() ** 2}));
|
||||
}
|
||||
|
||||
function minutesOf(text) {
|
||||
const [hours, minutes] = text.split(":").map(Number);
|
||||
return hours * 60 + minutes;
|
||||
}
|
||||
|
||||
function slotOf(date) {
|
||||
return {day: (date.getDay() + 6) % 7, minute: date.getHours() * 60 + date.getMinutes()};
|
||||
}
|
||||
|
||||
function covers(stream, slot) {
|
||||
const start = minutesOf(stream.from);
|
||||
const end = minutesOf(stream.to);
|
||||
if (start < end) {
|
||||
return stream.days.includes(slot.day) && slot.minute >= start && slot.minute < end;
|
||||
}
|
||||
return (stream.days.includes(slot.day) && slot.minute >= start) || (stream.days.includes((slot.day + 6) % 7) && slot.minute < end);
|
||||
}
|
||||
|
||||
function activeStream(streams, slot) {
|
||||
return streams.find((stream) => stream.on && covers(stream, slot)) || null;
|
||||
}
|
||||
|
||||
return {GLASS, CARD, SKY, THEMES, julian, sidereal, horizontal, sun, moon, hex, mix, css, luminance, contrast, skyAt, stage, starlight, modeAt, modeOf, stars, slotOf, activeStream};
|
||||
})();
|
||||
if (typeof module === "object" && module.exports) {
|
||||
module.exports = Ambience;
|
||||
}
|
||||
@@ -0,0 +1,476 @@
|
||||
<!doctype html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="color-scheme" content="light dark">
|
||||
<title>{% if state.badges.inbox %}({{ state.badges.inbox }}) {% endif %}Agent Orchestrator</title>
|
||||
<style nonce="{{ nonce }}">
|
||||
:root {
|
||||
--sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 24px; --sp-6: 32px; --sp-7: 48px;
|
||||
--fs-2xs: 11px; --fs-xs: 11.5px; --fs-sm: 12.5px; --fs-md: 14px; --fs-lg: 16px; --fs-xl: 18px; --fs-2xl: 22px; --fs-3xl: 34px;
|
||||
--lh: 1.55; --lh-tight: 1.25;
|
||||
--radius-sm: 8px; --radius: 14px; --radius-lg: 20px;
|
||||
--veil: 100%; --card: 100%;
|
||||
--blur: saturate(150%) blur(22px);
|
||||
--ease: cubic-bezier(.2, .7, .2, 1);
|
||||
--head: 104px;
|
||||
--sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
|
||||
--mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
--glass: color-mix(in srgb, var(--bg) var(--veil), transparent);
|
||||
--glass-panel: color-mix(in srgb, var(--panel) var(--veil), transparent);
|
||||
--glass-card: color-mix(in srgb, var(--panel) var(--card), transparent);
|
||||
}
|
||||
*, *::before, *::after { box-sizing: border-box; }
|
||||
html { -webkit-text-size-adjust: 100%; background: #05070d; }
|
||||
body { min-height: 100vh; margin: 0; background: transparent; color: var(--text); font: var(--fs-md)/var(--lh) var(--sans); -webkit-font-smoothing: antialiased; transition: color .8s var(--ease); }
|
||||
.sky { position: fixed; inset: 0; z-index: -1; display: block; width: 100vw; height: 100vh; pointer-events: none; }
|
||||
button, input, select { font: inherit; color: inherit; }
|
||||
code, pre { font-family: var(--mono); font-size: var(--fs-sm); }
|
||||
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 22%, transparent); }
|
||||
.top, .navbar, main, .drawer, .sheet-box, .palette-box, .toast, .sky-panel, .menu-box { -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur); transition: background-color .8s var(--ease), border-color .8s var(--ease); }
|
||||
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .22s; animation-timing-function: var(--ease); }
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
*, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; scroll-behavior: auto !important; }
|
||||
}
|
||||
.head { position: sticky; top: 0; z-index: 6; }
|
||||
.top { display: flex; align-items: center; gap: var(--sp-4); padding: var(--sp-3) var(--sp-5); background: var(--glass-panel); border-bottom: 1px solid var(--line); }
|
||||
.brand { display: flex; flex: 1; align-items: center; gap: var(--sp-3); min-width: 0; }
|
||||
.brand-text { display: grid; line-height: var(--lh-tight); }
|
||||
.sky-note { color: var(--muted); font-size: var(--fs-xs); white-space: nowrap; }
|
||||
.logo { width: 24px; height: 24px; border-radius: var(--radius-sm); background: linear-gradient(135deg, var(--accent), var(--violet)); box-shadow: inset 0 0 0 1px rgb(255 255 255 / 18%), var(--shadow); }
|
||||
h1 { margin: 0; font-size: var(--fs-lg); font-weight: 680; letter-spacing: -.01em; }
|
||||
.navbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-4); padding: var(--sp-2) var(--sp-5); background: var(--glass-panel); border-bottom: 1px solid var(--line); }
|
||||
.tabs { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-1) var(--sp-3); }
|
||||
.tab-group { display: inline-flex; align-items: center; gap: 2px; }
|
||||
.subtabs { display: inline-flex; gap: 2px; padding-left: var(--sp-1); border-left: 1px solid var(--line); }
|
||||
.subtabs button { font-size: var(--fs-sm); }
|
||||
.tabs button { display: inline-flex; align-items: center; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3); border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-weight: 560; cursor: pointer; transition: background .15s, color .15s; }
|
||||
.icon-btn { min-width: 34px; justify-content: center; font-size: var(--fs-lg); line-height: 1; }
|
||||
.btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
|
||||
.tabs button:hover { background: var(--hover); color: var(--text); }
|
||||
.tabs button[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
|
||||
.badge { min-width: 22px; padding: 0 7px; border-radius: 999px; background: var(--neutral-soft); color: var(--muted); font-size: var(--fs-xs); font-weight: 650; line-height: 20px; text-align: center; font-variant-numeric: tabular-nums; }
|
||||
.badge[hidden] { display: none; }
|
||||
.badge.urgent { background: var(--accent); color: var(--on-accent); }
|
||||
.badge.alarm { background: var(--alarm); color: #fff; }
|
||||
.tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 6px; }
|
||||
.banner { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-5); background: var(--alarm); color: #fff; font-weight: 650; }
|
||||
.banner[hidden] { display: none; }
|
||||
.banner .text { flex: 1; margin: 0; }
|
||||
.banner .btn { border-color: rgb(255 255 255 / 70%); background: transparent; color: #fff; }
|
||||
.menu { position: relative; }
|
||||
.menu > summary { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--panel); font-weight: 580; cursor: pointer; list-style: none; }
|
||||
.menu > summary::-webkit-details-marker { display: none; }
|
||||
.menu-box { position: absolute; top: calc(100% + 6px); z-index: 25; display: grid; gap: var(--sp-3); width: max-content; max-width: min(640px, calc(100vw - 32px)); padding: var(--sp-3) var(--sp-4); background: var(--glass-card); border: 1px solid var(--line-strong); border-radius: var(--radius); box-shadow: var(--shadow-lift); }
|
||||
.menu-box.end { right: 0; }
|
||||
.menu-box textarea { min-width: min(460px, calc(100vw - 64px)); }
|
||||
.menu-box h3 { margin: 0; color: var(--muted); font-size: var(--fs-xs); font-weight: 650; letter-spacing: .04em; text-transform: uppercase; }
|
||||
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3); }
|
||||
.classes { display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-3); }
|
||||
.updated { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: var(--fs-sm); white-space: nowrap; }
|
||||
.updated::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
|
||||
.updated.offline::before { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
|
||||
body.leitstand { --fs-xs: 13px; --fs-sm: 14px; --fs-md: 16px; --fs-lg: 18px; --fs-xl: 21px; --fs-2xl: 26px; --fs-3xl: 44px; }
|
||||
.shell { padding: var(--sp-4) var(--sp-4) var(--sp-6); }
|
||||
main { min-width: 0; min-height: calc(100vh - var(--head) - var(--sp-6) - var(--sp-4)); padding: var(--sp-5) var(--sp-5) 80px; background: var(--glass); border: 1px solid color-mix(in srgb, var(--line) 70%, transparent); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
|
||||
@media (max-width: 640px) {
|
||||
.top, .navbar, .banner { gap: var(--sp-2); padding: var(--sp-2) var(--sp-3); }
|
||||
.shell { padding: var(--sp-2) var(--sp-2) var(--sp-6); }
|
||||
main { padding: var(--sp-3) var(--sp-3) 88px; border-radius: var(--radius); }
|
||||
.menu-box { position: fixed; top: auto; right: var(--sp-2); left: var(--sp-2); width: auto; }
|
||||
.replay { flex-basis: 100%; min-width: 0; }
|
||||
.sheet { padding: 0; }
|
||||
.sheet-box { min-height: 100%; border-radius: 0; }
|
||||
.settings .grid { grid-template-columns: minmax(0, 1fr); }
|
||||
}
|
||||
.stack { display: grid; gap: 26px; }
|
||||
.group-title { display: flex; align-items: center; gap: 10px; margin: 0; font-size: var(--fs-sm); font-weight: 650; color: var(--muted); letter-spacing: .02em; text-transform: uppercase; }
|
||||
.count { min-width: 20px; padding: 0 7px; border-radius: 999px; background: var(--neutral-soft); color: var(--muted); font-size: var(--fs-xs); line-height: 19px; text-align: center; text-transform: none; }
|
||||
.card { min-width: 0; padding: var(--sp-4) var(--sp-4); background: var(--glass-card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); transition: background-color .8s var(--ease), border-color .8s var(--ease); }
|
||||
.card.alarm { border-color: color-mix(in srgb, var(--alarm) 45%, var(--line)); background: linear-gradient(0deg, var(--panel), color-mix(in srgb, var(--bad-soft) 70%, var(--panel))); }
|
||||
.card.flush { padding: 0; overflow: hidden; }
|
||||
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
|
||||
.muted { color: var(--muted); font-size: var(--fs-sm); }
|
||||
h2.title { margin: 0 0 2px; font-size: var(--fs-xl); font-weight: 650; letter-spacing: -.01em; overflow-wrap: anywhere; }
|
||||
h3 { margin: 0; font-size: var(--fs-lg); font-weight: 620; overflow-wrap: anywhere; }
|
||||
.who { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
|
||||
.text { margin: 8px 0 0; overflow-wrap: anywhere; white-space: pre-wrap; }
|
||||
.meta { display: flex; flex-wrap: wrap; gap: 6px 22px; margin: 8px 0 0; font-size: var(--fs-sm); }
|
||||
.meta div { display: flex; gap: 6px; min-width: 0; }
|
||||
.meta dt { color: var(--muted); }
|
||||
.meta dd { min-width: 0; margin: 0; overflow-wrap: anywhere; }
|
||||
.command { display: flex; align-items: center; gap: 10px; margin-top: 4px; padding: 7px 10px; background: var(--sunken); border: 1px solid var(--line); border-radius: 10px; }
|
||||
.command code { flex: 1; min-width: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
|
||||
pre.notes { max-height: 260px; margin: 12px 0 0; padding: 10px 12px; overflow: auto; background: var(--sunken); border: 1px solid var(--line); border-radius: 10px; white-space: pre-wrap; overflow-wrap: anywhere; }
|
||||
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 14px; }
|
||||
.spacer { flex: 1; }
|
||||
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--panel); color: var(--text); font-weight: 580; text-decoration: none; cursor: pointer; transition: background .15s, border-color .15s, transform .05s; }
|
||||
.btn:hover { background: var(--hover); }
|
||||
.btn:active { transform: translateY(1px); }
|
||||
.btn:disabled { opacity: .55; cursor: not-allowed; }
|
||||
.btn.small { padding: 4px 10px; font-size: var(--fs-sm); }
|
||||
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
|
||||
.btn.ghost:hover { background: var(--hover); color: var(--text); }
|
||||
.btn.primary { background: var(--ok); border-color: var(--ok); color: #fff; }
|
||||
.btn.primary:hover { background: color-mix(in srgb, var(--ok) 88%, #000); }
|
||||
.btn.danger { border-color: color-mix(in srgb, var(--bad) 55%, var(--line)); color: var(--bad); }
|
||||
.btn.danger:hover { background: var(--bad-soft); }
|
||||
.btn.soft { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
|
||||
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 1px 9px; border-radius: 999px; font-size: var(--fs-xs); font-weight: 650; line-height: 20px; white-space: nowrap; background: var(--neutral-soft); color: var(--muted); }
|
||||
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
|
||||
.pill[data-tone="ok"] { background: var(--ok-soft); color: var(--ok); }
|
||||
.pill[data-tone="bad"] { background: var(--bad-soft); color: var(--bad); }
|
||||
.pill[data-tone="warn"] { background: var(--warn-soft); color: var(--warn); }
|
||||
.pill[data-tone="info"] { background: var(--info-soft); color: var(--info); }
|
||||
.pill[data-tone="violet"] { background: var(--violet-soft); color: var(--violet); }
|
||||
.pill[data-tone="teal"] { background: var(--teal-soft); color: var(--teal); }
|
||||
.empty { display: grid; justify-items: center; gap: var(--sp-2); padding: var(--sp-7) var(--sp-5); background: var(--glass-card); border: 1px dashed var(--line-strong); border-radius: var(--radius); text-align: center; }
|
||||
.empty h2 { margin: 6px 0 0; font-size: var(--fs-lg); font-weight: 640; }
|
||||
.empty p { margin: 0; color: var(--muted); }
|
||||
.empty-mark { width: 40px; height: 40px; border-radius: 50%; background: radial-gradient(circle, var(--ok) 0 5px, var(--ok-soft) 6px); }
|
||||
.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 10px; }
|
||||
.chip { display: inline-flex; align-items: center; gap: 6px; max-width: 360px; padding: 5px 12px; overflow: hidden; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); color: var(--muted); font-weight: 560; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
|
||||
.chip:hover { color: var(--text); border-color: var(--line-strong); }
|
||||
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
|
||||
.chip.preset { font-weight: 650; }
|
||||
.chip .x { padding: 0 2px; border: 0; background: none; color: inherit; cursor: pointer; }
|
||||
.split { display: grid; grid-template-columns: minmax(220px, 320px) minmax(0, 1fr); gap: 14px; align-items: start; }
|
||||
@media (max-width: 860px) { .split, .graph-body { grid-template-columns: minmax(0, 1fr); } }
|
||||
.tree { position: sticky; top: 0; max-height: 70vh; padding: 10px 6px; overflow: auto; }
|
||||
.tree-title { margin: 6px 10px 4px; color: var(--muted); font-size: var(--fs-xs); font-weight: 650; letter-spacing: .04em; text-transform: uppercase; }
|
||||
.tree-list { margin: 0; padding: 0 0 0 10px; list-style: none; }
|
||||
.tree > div > .tree-section > .tree-list { padding-left: 0; }
|
||||
.tree summary { padding: 3px 8px; border-radius: 7px; color: var(--muted); font-size: var(--fs-sm); cursor: pointer; }
|
||||
.tree summary:hover { background: var(--hover); }
|
||||
.dir { font-family: var(--mono); font-size: var(--fs-sm); }
|
||||
.file-entry { display: flex; align-items: center; gap: 8px; width: 100%; padding: 4px 8px; border: 0; border-radius: 7px; background: transparent; text-align: left; cursor: pointer; }
|
||||
.file-entry:hover { background: var(--hover); }
|
||||
.file-entry[aria-current="true"] { background: var(--accent-soft); color: var(--accent); }
|
||||
.file-entry .name { flex: 1; min-width: 0; overflow: hidden; font-family: var(--mono); font-size: var(--fs-sm); text-overflow: ellipsis; white-space: nowrap; }
|
||||
.letter { display: inline-grid; place-items: center; flex: none; width: 18px; height: 18px; border-radius: 5px; background: var(--neutral-soft); color: var(--muted); font-family: var(--mono); font-size: var(--fs-2xs); font-weight: 700; }
|
||||
.letter[data-tone="ok"] { background: var(--ok-soft); color: var(--ok); }
|
||||
.letter[data-tone="bad"] { background: var(--bad-soft); color: var(--bad); }
|
||||
.letter[data-tone="info"] { background: var(--info-soft); color: var(--info); }
|
||||
.letter[data-tone="violet"] { background: var(--violet-soft); color: var(--violet); }
|
||||
.letter[data-tone="warn"] { background: var(--warn-soft); color: var(--warn); }
|
||||
.stat { display: inline-flex; gap: 6px; font-family: var(--mono); font-size: var(--fs-xs); font-variant-numeric: tabular-nums; }
|
||||
.stat .add { color: var(--ok); }
|
||||
.stat .del { color: var(--bad); }
|
||||
.diff-pane { padding: 0; overflow: hidden; }
|
||||
.diff-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--sunken); }
|
||||
.diff-head .path { overflow-wrap: anywhere; font-weight: 600; }
|
||||
.pad { margin: 0; padding: 18px 16px; }
|
||||
.diff-scroll { overflow: auto; max-height: 70vh; }
|
||||
table.diff { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: var(--fs-sm); line-height: 1.5; }
|
||||
table.diff td { padding: 0 10px; vertical-align: top; }
|
||||
table.diff td.num { width: 1%; min-width: 44px; color: var(--faint); text-align: right; user-select: none; white-space: nowrap; font-variant-numeric: tabular-nums; }
|
||||
table.diff td.sign { width: 1%; padding: 0 4px; color: var(--faint); user-select: none; }
|
||||
table.diff td.code { white-space: pre-wrap; overflow-wrap: anywhere; }
|
||||
table.diff tr.add { background: var(--add-bg); }
|
||||
table.diff tr.add td.code, table.diff tr.add td.sign { color: var(--add-text); }
|
||||
table.diff tr.del { background: var(--del-bg); }
|
||||
table.diff tr.del td.code, table.diff tr.del td.sign { color: var(--del-text); }
|
||||
table.diff tr.hunk td { padding-top: 4px; padding-bottom: 4px; background: var(--hunk-bg); color: var(--muted); }
|
||||
table.diff tr.more td { padding: 8px 16px; color: var(--muted); font-style: italic; }
|
||||
.feed { margin: 0; padding: 0; list-style: none; }
|
||||
.footnote { margin: 0; padding: 12px 18px; color: var(--muted); font-size: var(--fs-sm); }
|
||||
.entry { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 12px; padding: 10px 18px; border-bottom: 1px solid var(--line); }
|
||||
@media (max-width: 640px) {
|
||||
.entry { grid-template-columns: minmax(0, 1fr); padding: 10px 12px; }
|
||||
.msg-meta { display: flex; flex-wrap: wrap; align-items: center; }
|
||||
.tabs button { padding: 6px 8px; }
|
||||
}
|
||||
.entry:last-child { border-bottom: 0; }
|
||||
.entry:hover { background: var(--hover); }
|
||||
.entry.waiting { box-shadow: inset 3px 0 0 var(--warn); }
|
||||
.entry.alarm { background: color-mix(in srgb, var(--bad-soft) 75%, var(--panel)); }
|
||||
.entry pre { margin: 4px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
|
||||
.entry.k-transcript pre, .entry.k-cron pre, .entry.k-run pre { color: var(--muted); }
|
||||
.entry .line-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
|
||||
.msg-meta { display: grid; justify-items: start; align-content: start; gap: 4px; color: var(--muted); font-size: var(--fs-sm); }
|
||||
.route { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; }
|
||||
.route .headline { font-weight: 600; overflow-wrap: anywhere; }
|
||||
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 10px; }
|
||||
.filters select, .filters input, .field { padding: 6px 10px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--panel); }
|
||||
.filters input[type="search"] { flex: 1; min-width: 200px; }
|
||||
.graph { display: grid; gap: 14px; }
|
||||
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; padding: 10px 14px; }
|
||||
.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: 10px; background: var(--sunken); border: 1px solid var(--line); }
|
||||
.segmented button { padding: 4px 11px; border: 0; border-radius: 8px; background: transparent; color: var(--muted); font-size: var(--fs-sm); font-weight: 580; cursor: pointer; }
|
||||
.segmented button[aria-selected="true"], .segmented button[aria-pressed="true"] { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
|
||||
.replay { display: flex; flex: 1; align-items: center; gap: 10px; min-width: 280px; }
|
||||
.replay input[type="range"] { flex: 1; accent-color: var(--accent); }
|
||||
.window-label { color: var(--muted); font-size: var(--fs-sm); font-variant-numeric: tabular-nums; white-space: nowrap; }
|
||||
.graph-body { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 14px; align-items: start; }
|
||||
.stage-card { padding: 8px; }
|
||||
.stage svg { display: block; width: 100%; height: auto; max-height: calc(100vh - var(--head) - 120px); }
|
||||
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 6px 10px 4px; color: var(--muted); font-size: var(--fs-sm); }
|
||||
.legend span { display: inline-flex; align-items: center; gap: 6px; }
|
||||
.swatch { display: inline-block; width: 18px; height: 4px; border-radius: 2px; background: var(--c); }
|
||||
.panel { position: sticky; top: calc(var(--head) + 12px); max-height: calc(100vh - var(--head) - 24px); overflow: auto; }
|
||||
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
|
||||
.panel-title { margin: 0; font-size: var(--fs-xl); font-weight: 650; overflow-wrap: anywhere; }
|
||||
.panel h3, .drawer-body h3 { display: flex; align-items: center; gap: 8px; margin: 18px 0 8px; color: var(--muted); font-size: var(--fs-xs); font-weight: 650; letter-spacing: .04em; text-transform: uppercase; }
|
||||
.mini { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
|
||||
.mini li { display: grid; gap: 3px; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--sunken); font-size: var(--fs-sm); overflow-wrap: anywhere; }
|
||||
.mini .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
|
||||
.roles { color: var(--accent); font-size: var(--fs-sm); font-weight: 600; }
|
||||
.t-direct { --c: var(--direct); }
|
||||
.t-broadcast { --c: var(--broadcast); }
|
||||
.t-alarm { --c: var(--alarm); }
|
||||
.t-security { --c: var(--security); }
|
||||
.t-grant { --c: var(--grant); }
|
||||
.t-spawn { --c: var(--violet); }
|
||||
svg.chart { font-family: inherit; }
|
||||
svg .ring { fill: none; stroke: var(--line-strong); stroke-dasharray: 2 7; }
|
||||
svg .edge { fill: none; stroke: var(--c); stroke-linecap: round; opacity: .55; transition: opacity .15s; }
|
||||
svg .edge:hover { opacity: 1; }
|
||||
svg .tip { fill: var(--c); }
|
||||
svg .halo { fill: none; stroke: var(--c); opacity: .35; }
|
||||
svg .node { cursor: pointer; }
|
||||
svg .node circle { fill: var(--panel); stroke: var(--line-strong); stroke-width: 1.5; transition: stroke .15s; }
|
||||
svg .node:hover circle, svg .node:focus-visible circle { stroke: var(--accent); }
|
||||
svg .node:focus-visible { outline: none; }
|
||||
svg .node.k-operator circle { fill: var(--accent); stroke: color-mix(in srgb, var(--accent) 60%, var(--panel)); stroke-width: 6; }
|
||||
svg .node.k-chair circle { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 2; }
|
||||
svg .node.k-subagent circle { fill: var(--violet-soft); stroke: var(--violet); }
|
||||
svg .node.claimed circle { stroke: var(--ok); stroke-width: 2.2; }
|
||||
svg .node.selected circle { stroke: var(--accent); stroke-width: 3.5; }
|
||||
svg .label { fill: var(--text); font-size: var(--fs-sm); font-weight: 560; paint-order: stroke; stroke: var(--panel); stroke-width: 4px; stroke-linejoin: round; }
|
||||
svg .initial { fill: var(--muted); font-size: var(--fs-sm); font-weight: 700; pointer-events: none; }
|
||||
svg .k-operator .initial { fill: var(--on-accent); font-size: var(--fs-xl); }
|
||||
svg .k-chair .initial { fill: var(--accent); font-size: var(--fs-lg); }
|
||||
svg .group-arc { fill: none; stroke: var(--line-strong); stroke-width: 7; stroke-linecap: round; }
|
||||
svg .group-arc.k-operator, svg .group-arc.k-chair { stroke: var(--accent); }
|
||||
svg .tick { stroke: var(--c); stroke-linecap: round; opacity: .7; }
|
||||
svg .lane { fill: transparent; }
|
||||
svg .lane.odd { fill: var(--sunken); }
|
||||
svg .lane-label { fill: var(--text); font-size: var(--fs-sm); font-weight: 560; cursor: pointer; }
|
||||
svg .grid { stroke: var(--line); }
|
||||
svg .axis { fill: var(--muted); font-size: var(--fs-2xs); }
|
||||
svg .now { stroke: var(--accent); stroke-dasharray: 3 4; }
|
||||
svg .mark { stroke: var(--c); fill: var(--c); opacity: .75; }
|
||||
svg .mark line, svg .mark path { fill: none; stroke-width: 1.6; stroke-linecap: round; }
|
||||
svg .mark:hover { opacity: 1; }
|
||||
svg .mark:hover line, svg .mark:hover path { stroke-width: 2.6; }
|
||||
svg .pulse { fill: var(--c); filter: drop-shadow(0 0 4px var(--c)); }
|
||||
svg .pulse-ring { fill: none; stroke: var(--c); stroke-width: 2.5; }
|
||||
input[type="datetime-local"] { padding: 3px 6px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--panel); font-size: var(--fs-sm); }
|
||||
.custom { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; }
|
||||
.avatar { display: inline-grid; place-items: center; flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--sunken); border: 1px solid var(--line); font-size: var(--fs-lg); line-height: 1; }
|
||||
.avatar.big { width: 52px; height: 52px; font-size: var(--fs-3xl); }
|
||||
.linkish { padding: 0; border: 0; background: none; color: inherit; font-weight: 650; text-align: left; cursor: pointer; overflow-wrap: anywhere; }
|
||||
.linkish:hover { color: var(--accent); text-decoration: underline; }
|
||||
.drawer { position: fixed; top: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; width: min(480px, 100vw); background: var(--glass-card); border-left: 1px solid var(--line); box-shadow: var(--shadow-lift); }
|
||||
.drawer[hidden] { display: none; }
|
||||
.drawer-head { display: flex; align-items: center; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
|
||||
.drawer-body { overflow: auto; padding: 4px 18px 12px; }
|
||||
.drawer-form { display: grid; gap: 8px; padding: 12px 18px 18px; border-top: 1px solid var(--line); }
|
||||
textarea { width: 100%; min-height: 84px; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--panel); color: var(--text); font: inherit; resize: vertical; }
|
||||
.bubble { display: grid; gap: 3px; margin: 0 0 8px; padding: 8px 11px; border-radius: 12px; background: var(--sunken); border: 1px solid var(--line); font-size: var(--fs-sm); overflow-wrap: anywhere; white-space: pre-wrap; }
|
||||
.bubble.mine { margin-left: 34px; background: var(--accent-soft); border-color: transparent; }
|
||||
.bubble.theirs { margin-right: 34px; }
|
||||
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 40; display: grid; gap: 10px; width: min(440px, calc(100vw - 36px)); }
|
||||
.toast { padding: var(--sp-3) var(--sp-4); background: var(--glass-card); border: 1px solid var(--line-strong); border-left: 4px solid var(--ok); border-radius: 12px; box-shadow: var(--shadow-lift); cursor: pointer; }
|
||||
.toast.bad { border-left-color: var(--bad); }
|
||||
.toast.wait { border-left-color: var(--warn); cursor: default; }
|
||||
.toast pre { max-height: 180px; margin: 6px 0 0; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
|
||||
.undo-row { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
|
||||
.palette, .sheet { position: fixed; inset: 0; z-index: 50; display: grid; justify-items: center; align-items: start; padding: 10vh var(--sp-4) var(--sp-4); overflow: auto; background: rgb(0 0 0 / 32%); animation: fade .18s var(--ease); }
|
||||
.sheet { z-index: 30; padding-top: 5vh; }
|
||||
.palette[hidden], .sheet[hidden] { display: none; }
|
||||
.palette-box, .sheet-box { animation: rise .22s var(--ease); }
|
||||
@keyframes fade { from { opacity: 0; } }
|
||||
@keyframes rise { from { opacity: 0; transform: translateY(8px) scale(.99); } }
|
||||
.palette-box { width: min(620px, calc(100vw - 32px)); overflow: hidden; background: var(--glass-card); border: 1px solid var(--line-strong); border-radius: var(--radius); box-shadow: var(--shadow-lift); }
|
||||
.palette-box input { width: 100%; padding: 14px 16px; border: 0; background: transparent; font-size: var(--fs-lg); outline: none; }
|
||||
.palette-row { display: flex; align-items: center; gap: 6px; padding-right: 10px; border-bottom: 1px solid var(--line); }
|
||||
.palette-row input { flex: 1; min-width: 0; }
|
||||
.mic[aria-pressed="true"] { background: var(--bad-soft); color: var(--bad); }
|
||||
.palette-list { max-height: 55vh; margin: 0; padding: 6px; overflow: auto; list-style: none; }
|
||||
.palette-list li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
|
||||
.palette-list li[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); }
|
||||
.palette-list .muted { margin-left: auto; }
|
||||
.palette-plan { display: grid; gap: 8px; padding: 12px 16px 16px; }
|
||||
.palette-plan pre { margin: 0; padding: 8px 10px; background: var(--sunken); border-radius: 8px; white-space: pre-wrap; overflow-wrap: anywhere; }
|
||||
.sheet-box { width: min(760px, 100%); background: var(--glass-card); border: 1px solid var(--line-strong); border-radius: var(--radius); box-shadow: var(--shadow-lift); }
|
||||
.sheet-box.wide { width: min(1400px, 100%); }
|
||||
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
|
||||
.sheet-body { display: grid; gap: 14px; padding: 16px 18px 20px; }
|
||||
.options { display: grid; gap: 6px; margin-top: 8px; }
|
||||
.option { display: grid; gap: 2px; padding: 8px 11px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--panel); text-align: left; cursor: pointer; }
|
||||
.option:hover { background: var(--accent-soft); border-color: var(--accent); }
|
||||
.option.recommended { border-color: var(--ok); box-shadow: inset 3px 0 0 var(--ok); }
|
||||
.option span { color: var(--muted); font-size: var(--fs-sm); }
|
||||
.inbox-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
|
||||
.inbox-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
|
||||
.inbox-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
|
||||
.item { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--sp-2) var(--sp-3); padding: var(--sp-3); border: 1px solid var(--line); border-radius: 12px; background: var(--glass-card); }
|
||||
.item.cursor { outline: 2px solid var(--accent); outline-offset: 1px; }
|
||||
.item.green { box-shadow: inset 3px 0 0 var(--ok); }
|
||||
.item.red { box-shadow: inset 3px 0 0 var(--bad); }
|
||||
.item.held { opacity: .6; }
|
||||
.item input[type="checkbox"] { margin-top: 4px; accent-color: var(--accent); }
|
||||
.head-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 4px; }
|
||||
.item-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
|
||||
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: var(--fs-sm); cursor: pointer; }
|
||||
.order-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
|
||||
.order-list li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--sunken); cursor: grab; }
|
||||
.order-list li.dragging { opacity: .5; }
|
||||
.order-list .rank { min-width: 22px; color: var(--muted); font-variant-numeric: tabular-nums; }
|
||||
.board { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); gap: 14px; align-items: start; }
|
||||
.repos { display: grid; gap: 10px; }
|
||||
.repo { padding: 0; overflow: hidden; }
|
||||
.repo > summary { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 11px 16px; font-weight: 620; cursor: pointer; }
|
||||
.branch-row { display: grid; gap: 6px; padding: 9px 16px 9px 30px; border-top: 1px solid var(--line); }
|
||||
.branch-name { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
|
||||
.wt { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding: 7px 10px; border-radius: 8px; background: var(--sunken); font-size: var(--fs-sm); }
|
||||
.wt code { overflow-wrap: anywhere; }
|
||||
.rule-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; }
|
||||
.rule-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; align-items: end; }
|
||||
.rule-form label, .sound-row label { display: grid; gap: 4px; color: var(--muted); font-size: var(--fs-sm); }
|
||||
.sound-row { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(120px, 220px) auto; align-items: center; gap: var(--sp-3); padding: var(--sp-2) 0; border-bottom: 1px solid var(--line); }
|
||||
.settings { display: grid; gap: var(--sp-5); }
|
||||
.settings [hidden] { display: none; }
|
||||
.settings section { display: grid; gap: var(--sp-3); }
|
||||
.settings h3 { margin: 0; color: var(--muted); font-size: var(--fs-xs); font-weight: 650; letter-spacing: .04em; text-transform: uppercase; }
|
||||
.settings .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: var(--sp-3); align-items: end; }
|
||||
.settings label { display: grid; gap: var(--sp-1); color: var(--muted); font-size: var(--fs-sm); }
|
||||
.settings label.check { display: inline-flex; }
|
||||
.settings input[type="color"] { width: 100%; height: 36px; padding: 2px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--panel); }
|
||||
.settings input[type="range"] { accent-color: var(--accent); }
|
||||
.stream-row { display: grid; gap: var(--sp-2); padding: var(--sp-3); border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--sunken); }
|
||||
.days { display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-3); }
|
||||
.sheet-foot { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); padding-top: var(--sp-3); border-top: 1px solid var(--line); }
|
||||
.keys { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; }
|
||||
.keys dt { font-family: var(--mono); font-weight: 650; }
|
||||
.keys dd { margin: 0; color: var(--muted); }
|
||||
.space-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
|
||||
.stage canvas.space { display: block; width: 100%; height: clamp(360px, 68vh, 820px); border-radius: var(--radius-sm); cursor: grab; touch-action: none; }
|
||||
.stage canvas.space:active { cursor: grabbing; }
|
||||
.space-note { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; padding: 8px 10px 0; color: var(--muted); font-size: var(--fs-sm); }
|
||||
.space-list { padding: 6px 10px 2px; }
|
||||
.space-list summary { margin: 4px 0; color: var(--muted); font-size: var(--fs-sm); cursor: pointer; }
|
||||
body.sky-look .shell { visibility: hidden; }
|
||||
body.sky-look .sky { z-index: 5; pointer-events: auto; cursor: grab; touch-action: none; }
|
||||
body.sky-look .sky:active { cursor: grabbing; }
|
||||
.sky-panel { position: fixed; bottom: var(--sp-5); left: 50%; z-index: 8; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px; max-width: calc(100vw - 24px); padding: 8px 12px; transform: translateX(-50%); background: var(--glass-card); border: 1px solid var(--line-strong); border-radius: var(--radius); box-shadow: var(--shadow-lift); }
|
||||
.sky-panel[hidden] { display: none; }
|
||||
.compass { min-width: 220px; font-weight: 620; font-variant-numeric: tabular-nums; text-align: center; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas class="sky" id="sky" aria-hidden="true"></canvas>
|
||||
<div class="head" id="head">
|
||||
<header class="top">
|
||||
<div class="brand"><span class="logo" aria-hidden="true"></span><div class="brand-text"><h1>Agent Orchestrator</h1><span class="sky-note" id="sky-note"></span></div></div>
|
||||
<div class="tools">
|
||||
<button type="button" class="btn small ghost" id="palette-open" title="Befehle (Strg+K)" aria-label="Befehle">⌘K</button>
|
||||
<button type="button" class="btn small ghost icon-btn" id="settings-open" title="Einstellungen und Ambiente" aria-label="Einstellungen">⚙</button>
|
||||
</div>
|
||||
</header>
|
||||
<div class="navbar">
|
||||
<nav class="tabs" id="tabs" aria-label="Navigation"></nav>
|
||||
<span class="spacer"></span>
|
||||
<details class="menu" id="time"></details>
|
||||
<span class="updated" id="updated" aria-live="polite"></span>
|
||||
</div>
|
||||
<div class="banner" id="mayday" role="alert" hidden></div>
|
||||
</div>
|
||||
<div class="shell">
|
||||
<main id="main"></main>
|
||||
</div>
|
||||
<aside class="drawer" id="drawer" aria-label="Agent" hidden></aside>
|
||||
<div class="sheet" id="sheet" hidden></div>
|
||||
<div class="toasts" id="toasts" aria-live="polite"></div>
|
||||
<div class="palette" id="palette" hidden></div>
|
||||
<div class="sky-panel" id="sky-panel" role="group" aria-label="Blick in den Himmel" hidden></div>
|
||||
<script nonce="{{ nonce }}" id="state" type="application/json">{{ state | tojson }}</script>
|
||||
<script nonce="{{ nonce }}">
|
||||
{% include "ambience.js" %}
|
||||
</script>
|
||||
<script nonce="{{ nonce }}">
|
||||
{% include "voice.js" %}
|
||||
|
||||
{% include "nav.js" %}
|
||||
</script>
|
||||
<script nonce="{{ nonce }}">
|
||||
{# Jinja drops each file's last newline and trim_blocks the one after the tag: the blank lines keep consecutive modules on separate lines #}
|
||||
{% include "space-view.js" %}
|
||||
|
||||
{% include "space-scene.js" %}
|
||||
|
||||
{% include "space-paint.js" %}
|
||||
|
||||
{% include "space-pick.js" %}
|
||||
|
||||
{% include "space.js" %}
|
||||
</script>
|
||||
<script nonce="{{ nonce }}">
|
||||
(() => {
|
||||
"use strict";
|
||||
{% include "page-constants.js" %}
|
||||
|
||||
{% include "page-state.js" %}
|
||||
|
||||
{% include "page-dom.js" %}
|
||||
|
||||
{% include "page-api.js" %}
|
||||
|
||||
{% include "page-passkey.js" %}
|
||||
|
||||
{% include "page-board.js" %}
|
||||
|
||||
{% include "page-screens.js" %}
|
||||
|
||||
{% include "page-inbox.js" %}
|
||||
|
||||
{% include "page-review.js" %}
|
||||
|
||||
{% include "page-filters.js" %}
|
||||
|
||||
{% include "page-stream.js" %}
|
||||
|
||||
{% include "page-graph-layout.js" %}
|
||||
|
||||
{% include "page-graph-charts.js" %}
|
||||
|
||||
{% include "page-space-steer.js" %}
|
||||
|
||||
{% include "page-space-scene.js" %}
|
||||
|
||||
{% include "page-tree.js" %}
|
||||
|
||||
{% include "page-time.js" %}
|
||||
|
||||
{% include "page-pulses.js" %}
|
||||
|
||||
{% include "page-music.js" %}
|
||||
|
||||
{% include "page-sky.js" %}
|
||||
|
||||
{% include "page-radio.js" %}
|
||||
|
||||
{% include "page-settings.js" %}
|
||||
|
||||
{% include "page-speech.js" %}
|
||||
|
||||
{% include "page-alerts.js" %}
|
||||
|
||||
{% include "page-rules.js" %}
|
||||
|
||||
{% include "page-keyboard.js" %}
|
||||
|
||||
{% include "page-agent.js" %}
|
||||
|
||||
{% include "page-palette.js" %}
|
||||
|
||||
{% include "page-load.js" %}
|
||||
|
||||
{% include "page-boot.js" %}
|
||||
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,37 @@
|
||||
const Nav = (() => {
|
||||
"use strict";
|
||||
const TABS = [["stream", "Stream"], ["agents", "Agents"], ["artifacts", "Artifacts"]];
|
||||
const SUBS = {stream: [["inbox", "Inbox"], ["rules", "Regeln"]]};
|
||||
const VIEWS = [["orbit", "Orbit"], ["chord", "Chord"], ["swimlane", "Swimlane"], ["tree", "Tree"], ["3d", "3D"]];
|
||||
const OLD = {graph: ["agents", "orbit"], tree: ["artifacts", "tree"]};
|
||||
const known = (view) => VIEWS.some(([id]) => id === view);
|
||||
|
||||
function tabOf(screen) {
|
||||
return Object.keys(SUBS).find((tab) => SUBS[tab].some(([id]) => id === screen)) || screen;
|
||||
}
|
||||
|
||||
function hashOf(screen, view) {
|
||||
return tabOf(screen) === screen ? (view ? `#${screen}/${view}` : `#${screen}`) : `#${tabOf(screen)}/${screen}`;
|
||||
}
|
||||
|
||||
function route(hash) {
|
||||
const [head, sub] = decodeURIComponent(String(hash).replace(/^#/, "")).split("/");
|
||||
if (Object.hasOwn(OLD, head)) {
|
||||
const [screen, fallback] = OLD[head];
|
||||
const view = known(sub) ? sub : fallback;
|
||||
return {screen, view, redirect: hashOf(screen, view)};
|
||||
}
|
||||
if (Object.hasOwn(SUBS, head) && SUBS[head].some(([id]) => id === sub)) {
|
||||
return {screen: sub, view: null, redirect: null};
|
||||
}
|
||||
if (TABS.some(([id]) => id === head) && head !== "stream") {
|
||||
return {screen: head, view: known(sub) ? sub : null, redirect: null};
|
||||
}
|
||||
return {screen: "stream", view: null, redirect: null};
|
||||
}
|
||||
|
||||
return {TABS, SUBS, VIEWS, route, hashOf, tabOf};
|
||||
})();
|
||||
if (typeof module === "object" && module.exports) {
|
||||
module.exports = Nav;
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
function history(key) {
|
||||
const known = (people()[key] || {names: [nameOf(key)]}).names;
|
||||
const radio = state.radio.filter((row) => row.source === key || row.targets.includes(key)).map((row) => ({ts: row.ts, mine: row.from === HUMAN, who: row.from, text: row.text}));
|
||||
const sent = state.messages.filter((message) => known.includes(message.to) || message.to === "*").map((message) => ({ts: message.created_ts, mine: true, who: HUMAN, text: message.upload ? `${message.text}\n📎 ${message.upload}` : message.text, id: message.id}));
|
||||
const hubIds = new Set(sent.map((entry) => entry.id));
|
||||
const relayed = radio.filter((entry) => !(entry.who === HUMAN && [...hubIds].some((id) => entry.text.includes(`[kvb-orchestrator msg ${id}]`))));
|
||||
return [...relayed, ...sent].sort((a, b) => a.ts - b.ts).slice(-80);
|
||||
}
|
||||
|
||||
function drawDrawer() {
|
||||
if (!drawerDom) {
|
||||
return;
|
||||
}
|
||||
const node = state.graph.nodes.find((entry) => entry.id === ui.agent);
|
||||
const tasks = node ? node.tasks : [];
|
||||
const claims = node ? node.claims : [];
|
||||
drawerDom.info.replaceChildren(
|
||||
h("h3", {}, "Aufgaben", counter(tasks.length)),
|
||||
tasks.length ? h("ul", {class: "mini"}, tasks.map((task) => h("li", {},
|
||||
h("div", {class: "row"}, h("code", {}, task.task), status(task.status)),
|
||||
h("span", {}, dash(task.title)),
|
||||
h("span", {class: "roles"}, [task.worker ? "Worker" : "", task.letters ? `Rollen ${task.letters}` : ""].filter(Boolean).join(" · "))))) : h("p", {class: "muted"}, "Keine offenen Aufgaben."),
|
||||
h("h3", {}, "Claims", counter(claims.length)),
|
||||
claims.length ? h("ul", {class: "mini"}, claims.map((claim) => h("li", {},
|
||||
h("div", {class: "row"}, h("code", {}, claim.office), claim.beat === null ? null : h("span", {class: "muted"}, "Puls ", when(claim.beat))),
|
||||
h("span", {}, dash(claim.work)),
|
||||
h("span", {class: "muted"}, `${dash(claim.runtime)} · seit ${dash(claim.since)}`)))) : h("p", {class: "muted"}, "Keine Claims."));
|
||||
const rows = history(ui.agent);
|
||||
drawerDom.history.replaceChildren(rows.length
|
||||
? h("div", {}, rows.map((row) => h("div", {class: `bubble ${row.mine ? "mine" : "theirs"}`}, h("span", {class: "muted"}, `${row.who} · `, when(row.ts)), row.text)))
|
||||
: h("p", {class: "muted"}, "Kein Verlauf im gewählten Zeitraum."));
|
||||
}
|
||||
|
||||
async function loadSubagents(key, holder, life) {
|
||||
if (!SESSION_ID.test(key)) {
|
||||
holder.replaceChildren(h("p", {class: "muted"}, "Keine Session bekannt."));
|
||||
return;
|
||||
}
|
||||
let data = null;
|
||||
try {
|
||||
const response = await fetch(`/api/subagents?session=${encodeURIComponent(key)}`, {cache: "no-store"});
|
||||
data = response.ok ? await response.json() : null;
|
||||
} catch {
|
||||
data = null;
|
||||
}
|
||||
if (!data) {
|
||||
holder.replaceChildren(h("p", {class: "muted"}, "Subagenten nicht lesbar."));
|
||||
return;
|
||||
}
|
||||
life.textContent = stamp(data);
|
||||
const rows = data.subagents.map((row) => ({...row, session: key})).sort((a, b) => a.started - b.started);
|
||||
holder.replaceChildren(rows.length ? h("ul", {class: "mini"}, rows.map((row) => {
|
||||
const item = h("li", {},
|
||||
h("div", {class: "row"}, h("button", {type: "button", class: "linkish", title: "Transkript im Stream zeigen", on: {click: () => focusSub(row.session, row.id)}}, `${row.type}: ${row.description}`), row.finished ? pill("fertig", "neutral") : pill("läuft", "ok")),
|
||||
h("span", {class: "muted"}, `Tiefe ${row.depth} · `, when(row.started), stamp(row) ? ` · ${stamp(row)}` : ""));
|
||||
item.style.marginLeft = `${(row.depth - 1) * 18}px`;
|
||||
return item;
|
||||
})) : h("p", {class: "muted"}, "Keine Subagenten."));
|
||||
}
|
||||
|
||||
async function deliver(text, file, cls) {
|
||||
let upload = "";
|
||||
if (file) {
|
||||
if (file.size > UPLOAD_LIMIT) {
|
||||
toast("Datei zu groß", [`${file.name}: höchstens 50 MiB`], false);
|
||||
return false;
|
||||
}
|
||||
const stored = await send(`/api/uploads?name=${encodeURIComponent(file.name)}`, file, "application/octet-stream");
|
||||
if (!stored.ok || !stored.data) {
|
||||
toast("Upload fehlgeschlagen", [`${stored.status} ${stored.text}`.trim()], false);
|
||||
return false;
|
||||
}
|
||||
upload = stored.data.id;
|
||||
}
|
||||
return message(nameOf(ui.agent), text, upload, cls);
|
||||
}
|
||||
|
||||
async function message(to, text, upload, cls) {
|
||||
const label = TO_ONE.find(([id]) => id === cls)[1];
|
||||
const result = await sendJson("/api/messages", {to, text, upload, class: cls});
|
||||
if (!result.ok || !result.data) {
|
||||
toast(`${label} an ${to} fehlgeschlagen`, [`${result.status} ${result.text}`.trim()], false);
|
||||
return false;
|
||||
}
|
||||
toast(`${label} an ${to}: ${result.data.ok ? "gesendet" : "gespeichert, Senden fehlgeschlagen"}`, [`kvb-orchestrator msg ${result.data.id}`, ...runLines(result.data)], result.data.ok);
|
||||
await load();
|
||||
return true;
|
||||
}
|
||||
|
||||
function openAgent(who) {
|
||||
const drawer = document.getElementById("drawer");
|
||||
const key = agentKey(who);
|
||||
const name = nameOf(key);
|
||||
ui.agent = key;
|
||||
const text = h("textarea", {"aria-label": `Nachricht an ${name}`, placeholder: `Nachricht an ${name} …`});
|
||||
const file = h("input", {type: "file", class: "field", "aria-label": "Datei anhängen"});
|
||||
const button = h("button", {type: "submit", class: "btn primary"}, "Senden");
|
||||
const classes = choice("to-one", TO_ONE, "post");
|
||||
const form = h("form", {class: "drawer-form"}, text, file, classes,
|
||||
h("p", {class: "muted"}, "Post kommt am Ende des Zuges an, Call sofort mit Lesebestätigung; prüfbar mit operator_message."),
|
||||
h("div", {class: "actions"}, h("span", {class: "spacer"}), micButton(text), button));
|
||||
form.addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
if (!text.value.trim()) {
|
||||
return;
|
||||
}
|
||||
button.disabled = true;
|
||||
if (await deliver(text.value, file.files[0] || null, picked(classes))) {
|
||||
text.value = "";
|
||||
file.value = "";
|
||||
}
|
||||
button.disabled = false;
|
||||
});
|
||||
const info = h("div", {});
|
||||
const subs = h("div", {}, h("p", {class: "muted"}, "Lade Subagenten …"));
|
||||
const log = h("div", {"aria-live": "polite"});
|
||||
const life = h("span", {class: "muted"});
|
||||
const former = (people()[key] || {names: []}).names.filter((entry) => entry !== name);
|
||||
drawer.replaceChildren(
|
||||
h("div", {class: "drawer-head"}, face(name, true), life, h("div", {}, h("h2", {class: "panel-title"}, name), h("span", {class: "muted"}, former.length ? `Agent · früher ${former.join(", ")}` : "Agent")), h("span", {class: "spacer"}),
|
||||
h("button", {type: "button", class: "btn small ghost", "aria-label": "Schließen", on: {click: closeAgent}}, "×")),
|
||||
h("div", {class: "drawer-body"}, info, h("h3", {}, "Subagenten"), subs, h("h3", {}, "Verlauf"), log),
|
||||
form);
|
||||
drawer.hidden = false;
|
||||
drawerDom = {info, history: log};
|
||||
drawDrawer();
|
||||
loadSubagents(key, subs, life);
|
||||
text.focus();
|
||||
}
|
||||
|
||||
function closeAgent() {
|
||||
document.getElementById("drawer").hidden = true;
|
||||
drawerDom = null;
|
||||
ui.agent = null;
|
||||
}
|
||||
|
||||
function agentNames() {
|
||||
const names = new Set([...state.graph.nodes.filter((node) => node.kind === "session" || node.kind === "chair").map((node) => nameOf(node.id)), ...state.priority]);
|
||||
return [...names].sort((a, b) => a.localeCompare(b));
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
function play(kind, volume) {
|
||||
const sound = context();
|
||||
if (!sound) {
|
||||
return;
|
||||
}
|
||||
const level = Math.max(volume * 0.5, 0.0002);
|
||||
duck(Math.max(...TONES[kind].map(([, at, length]) => at + length)));
|
||||
for (const [frequency, at, length] of TONES[kind]) {
|
||||
const oscillator = sound.createOscillator();
|
||||
const gain = sound.createGain();
|
||||
const start = sound.currentTime + at;
|
||||
oscillator.type = kind === "mayday" ? "square" : "sine";
|
||||
oscillator.frequency.value = frequency;
|
||||
gain.gain.setValueAtTime(0.0001, start);
|
||||
gain.gain.exponentialRampToValueAtTime(level, start + 0.02);
|
||||
gain.gain.exponentialRampToValueAtTime(0.0001, start + length);
|
||||
oscillator.connect(gain).connect(sound.destination);
|
||||
oscillator.start(start);
|
||||
oscillator.stop(start + length + 0.05);
|
||||
}
|
||||
}
|
||||
|
||||
function notifyLabel() {
|
||||
const button = document.getElementById("notify");
|
||||
if (!button) {
|
||||
return;
|
||||
}
|
||||
const permission = "Notification" in window ? Notification.permission : "unsupported";
|
||||
const labels = {granted: "Benachrichtigungen an", denied: "Benachrichtigungen blockiert", default: "Benachrichtigungen aktivieren", unsupported: "Benachrichtigungen fehlen im Browser"};
|
||||
button.textContent = labels[permission] || labels.default;
|
||||
button.disabled = permission !== "default";
|
||||
}
|
||||
|
||||
async function askNotify() {
|
||||
if ("Notification" in window) {
|
||||
await Notification.requestPermission();
|
||||
}
|
||||
notifyLabel();
|
||||
}
|
||||
|
||||
function announce() {
|
||||
const alarms = new Map(alarmRows().map((row) => [`${row.ts}|${row.from}`, row]));
|
||||
const radio = new Set(state.radio.map((row) => `${row.ts}|${row.from}|${row.text.slice(0, 40)}`));
|
||||
if (known.inbox !== null && live()) {
|
||||
const fresh = state.inbox.filter((item) => !known.inbox.has(keyOf(item)));
|
||||
const newAlarms = [...alarms].filter(([key]) => !known.alarms.has(key)).map(([, row]) => row);
|
||||
const newRadio = state.radio.filter((row) => !known.radio.has(`${row.ts}|${row.from}|${row.text.slice(0, 40)}`));
|
||||
const direct = newRadio.filter((row) => row.to.includes(HUMAN));
|
||||
const present = {mayday: newAlarms.length > 0, review: fresh.some((item) => item.kind !== "operator"), direct: direct.length > 0, radio: newRadio.length > 0};
|
||||
const kind = SOUND_KINDS.map(([id]) => id).find((id) => present[id] && settings.sounds[id].on);
|
||||
if (kind) {
|
||||
play(kind, loudness(kind));
|
||||
}
|
||||
const lead = kind ? Math.max(...TONES[kind].map(([, at, length]) => at + length)) : 0;
|
||||
window.setTimeout(() => speakRows(newRadio), lead * 1000);
|
||||
if (settings.notify && "Notification" in window && Notification.permission === "granted") {
|
||||
for (const row of newAlarms) {
|
||||
new Notification(`${row.class === "mayday" ? "Mayday" : "Pan-Pan"} von ${dash(row.from)}`, {body: row.text.slice(0, 200), tag: `alarm-${row.ts}`, requireInteraction: row.class === "mayday"});
|
||||
}
|
||||
for (const item of fresh) {
|
||||
new Notification(`${ITEM_LABELS[item.kind]} wartet`, {body: item.title.slice(0, 200), tag: `item-${keyOf(item)}`, requireInteraction: item.kind === "ask"});
|
||||
}
|
||||
for (const row of direct) {
|
||||
new Notification(`Funk von ${dash(row.from)}`, {body: row.text.slice(0, 200), tag: `direct-${row.ts}`});
|
||||
}
|
||||
}
|
||||
}
|
||||
known.inbox = new Set(state.inbox.map(keyOf));
|
||||
known.alarms = new Set(alarms.keys());
|
||||
known.radio = radio;
|
||||
for (const batch of state.pending) {
|
||||
if (!known.batches.has(batch.id)) {
|
||||
known.batches.add(batch.id);
|
||||
const source = batch.source.startsWith("rule:") ? "Regel" : "Freigabe";
|
||||
undoToast(batch, `${source}: ${batch.items.map((item) => short(item.title)).join(", ")}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
async function send(path, body, type) {
|
||||
try {
|
||||
const response = await fetch(path, {method: "POST", headers: {"X-Kvb-Orchestrator": "1", "Content-Type": type}, body, cache: "no-store"});
|
||||
const text = await response.text();
|
||||
let data = null;
|
||||
try {
|
||||
data = JSON.parse(text);
|
||||
} catch {
|
||||
data = null;
|
||||
}
|
||||
return {ok: response.ok, status: response.status, text, data};
|
||||
} catch (error) {
|
||||
return {ok: false, status: 0, text: String(error), data: null};
|
||||
}
|
||||
}
|
||||
const sendJson = (path, payload) => send(path, JSON.stringify(payload), "application/json");
|
||||
const fail = (result) => [`${result.status} ${result.text}`.trim()];
|
||||
@@ -0,0 +1,128 @@
|
||||
async function act(action, label, payload) {
|
||||
ui.busy = true;
|
||||
const result = await sendJson(`/api/board/${action}`, payload);
|
||||
ui.busy = false;
|
||||
if (result.data && result.data.runs) {
|
||||
toast(`${label}: ${result.data.ok ? "erledigt" : "fehlgeschlagen"}`, runLines(result.data), result.data.ok);
|
||||
} else {
|
||||
toast(`${label}: fehlgeschlagen`, [`${result.status} ${result.text}`.trim()], false);
|
||||
}
|
||||
await load();
|
||||
return result.ok && result.data && result.data.ok;
|
||||
}
|
||||
|
||||
function confirmAct(action) {
|
||||
const [, label, question] = ACTIONS.find(([id]) => id === action);
|
||||
if (window.confirm(question)) {
|
||||
act(action, label, {});
|
||||
}
|
||||
}
|
||||
|
||||
function choice(name, options, picked) {
|
||||
return h("div", {class: "classes", role: "radiogroup", "aria-label": "Klasse"}, options.map(([id, label]) => h("label", {class: "check"},
|
||||
h("input", {type: "radio", name, value: id, checked: id === picked}), label)));
|
||||
}
|
||||
|
||||
const picked = (group) => group.querySelector("input:checked").value;
|
||||
|
||||
function toAll() {
|
||||
const text = h("textarea", {"aria-label": "Funk an alle", placeholder: "Nachricht an alle Agenten …", on: {input: (event) => {
|
||||
ui.draft = event.target.value;
|
||||
}}});
|
||||
text.value = ui.draft;
|
||||
const classes = choice("to-all", TO_ALL, "newsletter");
|
||||
const send = async () => {
|
||||
const cls = picked(classes);
|
||||
const label = TO_ALL.find(([id]) => id === cls)[1];
|
||||
if (!ui.draft.trim() || (cls === "mayday" && !window.confirm("Mayday an alle senden? Alle Agenten pausieren schreibende Schritte, bis du ihn aufhebst."))) {
|
||||
return;
|
||||
}
|
||||
if (await act("broadcast", `Funk an alle (${label})`, {text: ui.draft, class: cls})) {
|
||||
ui.draft = "";
|
||||
text.value = "";
|
||||
}
|
||||
};
|
||||
return h("details", {class: "menu", id: "to-all"}, h("summary", {}, "Funk an alle ▾"), h("div", {class: "menu-box"},
|
||||
text, classes, h("p", {class: "muted"}, "Newsletter kommt als Post am Ende des Zuges; Broadcast, Pan-Pan, Security und Mayday sofort."),
|
||||
h("div", {class: "actions"}, h("span", {class: "spacer"}), btn("Senden", "btn soft", send))));
|
||||
}
|
||||
|
||||
function openToAll() {
|
||||
go("agents", null);
|
||||
window.setTimeout(() => {
|
||||
const menu = document.getElementById("to-all");
|
||||
if (menu) {
|
||||
menu.open = true;
|
||||
menu.querySelector("textarea").focus();
|
||||
}
|
||||
}, 50);
|
||||
}
|
||||
|
||||
function agentsToolbar() {
|
||||
const clear = btn("Mayday aufheben", "btn small danger", () => confirmAct("clear-mayday"));
|
||||
const mode = h("span", {});
|
||||
const night = h("details", {class: "menu"}, h("summary", {}, "Tag/Nacht ▾"), h("div", {class: "menu-box"}, mode,
|
||||
h("p", {class: "muted"}, "Abend: Agenten beenden ihre Aufgabe. Sonnenuntergang: sie schlafen. Sonnenaufgang: alle wachen auf."),
|
||||
h("div", {class: "actions"}, ACTIONS.slice(1).map(([id, label]) => btn(label, "btn small", () => confirmAct(id))))));
|
||||
return {bar: h("div", {class: "toolbar", role: "toolbar", "aria-label": "Steuerung"}, toAll(), clear, btn("Priorität", "btn small", prioritySheet), night), clear, mode};
|
||||
}
|
||||
|
||||
function drawToolbar() {
|
||||
if (!graphDom || !graphDom.toolbar) {
|
||||
return;
|
||||
}
|
||||
const [mode, tone] = NIGHT[state.night] || [state.night, "neutral"];
|
||||
graphDom.toolbar.clear.disabled = !state.silence;
|
||||
graphDom.toolbar.mode.replaceChildren(pill(mode, tone));
|
||||
}
|
||||
|
||||
function priorityContent() {
|
||||
if (ui.order === null || ui.order.some((name) => !state.priority.includes(name)) || ui.order.length !== state.priority.length) {
|
||||
ui.order = [...state.priority];
|
||||
}
|
||||
const list = h("ol", {class: "order-list"});
|
||||
let dragged = null;
|
||||
ui.order.forEach((name, index) => {
|
||||
const item = h("li", {draggable: "true", "data-name": name}, h("span", {class: "rank"}, `${index + 1}.`), face(name, false), person(name));
|
||||
item.addEventListener("dragstart", (event) => {
|
||||
dragged = name;
|
||||
item.classList.add("dragging");
|
||||
event.dataTransfer.effectAllowed = "move";
|
||||
event.dataTransfer.setData("text/plain", name);
|
||||
});
|
||||
item.addEventListener("dragend", () => item.classList.remove("dragging"));
|
||||
item.addEventListener("dragover", (event) => event.preventDefault());
|
||||
item.addEventListener("drop", (event) => {
|
||||
event.preventDefault();
|
||||
if (dragged === null || dragged === name) {
|
||||
return;
|
||||
}
|
||||
const next = ui.order.filter((entry) => entry !== dragged);
|
||||
next.splice(next.indexOf(name) + (ui.order.indexOf(dragged) < ui.order.indexOf(name) ? 1 : 0), 0, dragged);
|
||||
ui.order = next;
|
||||
prioritySheet();
|
||||
});
|
||||
list.append(item);
|
||||
});
|
||||
const changed = JSON.stringify(ui.order) !== JSON.stringify(state.priority);
|
||||
return [
|
||||
ui.order.length ? list : h("p", {class: "muted"}, "Kein Agent mit offener Aufgabe."),
|
||||
h("div", {class: "actions"},
|
||||
h("span", {class: "muted"}, "Ziehen zum Umsortieren"),
|
||||
h("span", {class: "spacer"}),
|
||||
h("button", {type: "button", class: "btn ghost", disabled: !changed, on: {click: () => {
|
||||
ui.order = [...state.priority];
|
||||
prioritySheet();
|
||||
}}}, "Zurücksetzen"),
|
||||
h("button", {type: "button", class: "btn primary", disabled: !changed, on: {click: async () => {
|
||||
if (await act("order", "Priorität", {agents: ui.order})) {
|
||||
ui.order = null;
|
||||
prioritySheet();
|
||||
}
|
||||
}}}, "Reihenfolge speichern")),
|
||||
];
|
||||
}
|
||||
|
||||
function prioritySheet() {
|
||||
openSheet("Priorität der Agenten", priorityContent(), false);
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
document.getElementById("palette").addEventListener("click", (event) => {
|
||||
if (event.target === event.currentTarget) {
|
||||
closePalette();
|
||||
}
|
||||
});
|
||||
document.getElementById("sheet").addEventListener("click", (event) => {
|
||||
if (event.target === event.currentTarget) {
|
||||
closeSheet();
|
||||
}
|
||||
});
|
||||
document.getElementById("palette-open").addEventListener("click", openPalette);
|
||||
document.getElementById("settings-open").addEventListener("click", settingsSheet);
|
||||
document.addEventListener("click", (event) => closeMenus(event.target instanceof Element ? event.target.closest("details.menu") : null));
|
||||
document.addEventListener("fullscreenchange", () => {
|
||||
if (!document.fullscreenElement) {
|
||||
document.body.classList.remove("leitstand");
|
||||
}
|
||||
window.setTimeout(measure, 50);
|
||||
});
|
||||
document.addEventListener("pointerdown", context, {once: true});
|
||||
document.addEventListener("keydown", context, {once: true});
|
||||
document.addEventListener("pointerdown", unlock);
|
||||
document.addEventListener("keydown", keyboard);
|
||||
document.addEventListener("visibilitychange", refresh);
|
||||
window.addEventListener("hashchange", apply);
|
||||
window.addEventListener("resize", measure);
|
||||
window.addEventListener("resize", redrawSky);
|
||||
window.addEventListener("resize", requestSpace);
|
||||
skyPanel();
|
||||
radio.element = h("audio", {preload: "none"});
|
||||
radio.element.addEventListener("error", () => {
|
||||
if (radio.element.getAttribute("src")) {
|
||||
radio.playing = false;
|
||||
radio.url = "";
|
||||
tuneMusic(FADE / 1000);
|
||||
}
|
||||
});
|
||||
drawSky();
|
||||
musicButton();
|
||||
syncMusic();
|
||||
syncRadio();
|
||||
timeBar();
|
||||
notifyLabel();
|
||||
announce();
|
||||
measure();
|
||||
apply();
|
||||
drawTime();
|
||||
motion.asOf = ui.asOf;
|
||||
relayout(0);
|
||||
window.setInterval(refresh, 10000);
|
||||
window.setInterval(follow, 3000);
|
||||
window.setInterval(() => relayout(MOVE), RELAYOUT);
|
||||
window.setInterval(() => live() && drawSky(), 30000);
|
||||
window.setInterval(syncRadio, 20000);
|
||||
window.setInterval(() => {
|
||||
if (tree.dom && !document.hidden) {
|
||||
fetchTree();
|
||||
}
|
||||
}, 60000);
|
||||
@@ -0,0 +1,69 @@
|
||||
const NS = "http://www.w3.org/2000/svg";
|
||||
const DAY = 86400;
|
||||
const CHAIR = "Maintainer";
|
||||
const HUMAN = "Operator";
|
||||
const PRESETS = [[3600, "1 h"], [21600, "6 h"], [DAY, "24 h"], [7 * DAY, "7 d"], [0, "alle"], [-1, "eigener"]];
|
||||
const EMOJI = ["🦊", "🐙", "🦉", "🐝", "🐢", "🦄", "🐳", "🦋", "🐧", "🦁", "🐼", "🐨", "🦜", "🐬", "🦀", "🐸", "🦔", "🦩", "🐞", "🌵", "🍀", "🌻", "🍄", "🌙", "⭐", "🔥", "🌊", "⚡", "🎈", "🎲", "🧭", "🚀", "🪐", "🔭", "🧩", "🎯", "🪁", "🧪", "🔮", "🗿", "🌋", "🍉", "🍋", "🥨", "🐋", "🦚", "🐌", "🌈"];
|
||||
const PARTS = [["user", "Nutzer"], ["assistant", "Assistent"], ["tool_call", "Werkzeugaufruf"], ["tool_result", "Werkzeugergebnis"], ["system", "System"]];
|
||||
const PART_TONES = {user: "info", assistant: "ok", tool_call: "violet", tool_result: "teal", system: "neutral"};
|
||||
const KIND_TONES = {radio: "teal", review: "info", ask: "warn", decision: "violet", operator: "bad", register: "neutral", rename: "info", cron: "teal", rule: "ok", approval: "ok", run: "info", transcript: "neutral"};
|
||||
const ITEM_LABELS = {review: "Review", ask: "Ask", decision: "Entscheidung", operator: "Operator"};
|
||||
const NIGHT = {day: ["Tag", "ok"], evening: ["Abend", "warn"], sunset: ["Nacht", "violet"]};
|
||||
const ACTIONS = [["clear-mayday", "Mayday aufheben", "Die Funkstille des aktiven Maydays aufheben?"], ["evening", "Abend", "Alle Agenten in den Abend schicken (kvb-agent-relax)?"], ["sunset", "Sonnenuntergang", "Alle Agenten schlafen legen (kvb-agent-sleep)?"], ["sunrise", "Sonnenaufgang", "Alle Agenten wecken (kvb-agent-wakeup)?"]];
|
||||
const UPLOAD_LIMIT = 50 * 1024 * 1024;
|
||||
const STREAM_KEEP = 5000;
|
||||
const CLASSES = {post: "Post", call: "Call", newsletter: "Newsletter", broadcast: "Broadcast", mayday: "Mayday", "pan-pan": "Pan-Pan", security: "Security", receipt: "Gelesen", grant: "Freigabe"};
|
||||
const PILLS = {post: "info", call: "info", newsletter: "teal", broadcast: "teal", mayday: "bad", "pan-pan": "warn", security: "violet", receipt: "neutral", grant: "ok"};
|
||||
const LEGEND = [["direct", "Post / Call"], ["broadcast", "Newsletter / Broadcast"], ["alarm", "Mayday / Pan-Pan"], ["security", "Security"], ["grant", "Queue-Freigabe"]];
|
||||
const TO_ALL = [["newsletter", "Newsletter"], ["broadcast", "Broadcast"], ["pan-pan", "Pan-Pan"], ["security", "Security"], ["mayday", "Mayday"]];
|
||||
const TO_ONE = [["post", "Post"], ["call", "Call"]];
|
||||
const STATUS = {
|
||||
running: ["läuft", "ok"], queued: ["wartet", "info"], blocked: ["blockiert", "bad"], stale: ["veraltet", "warn"], pending: ["offen", "warn"], done: ["erledigt", "neutral"], stopped: ["gestoppt", "neutral"],
|
||||
approved: ["freigegeben", "ok"], rejected: ["abgelehnt", "bad"], allowed: ["erlaubt", "ok"], denied: ["abgelehnt", "bad"], expired: ["abgelaufen", "neutral"], decided: ["entschieden", "ok"], failed: ["fehlgeschlagen", "bad"], refused: ["verweigert", "bad"],
|
||||
};
|
||||
const SECTIONS = {staged: "Gestaged", unstaged: "Nicht gestaged", untracked: "Unversioniert"};
|
||||
const FILE_STATUS = {added: ["A", "ok"], deleted: ["D", "bad"], modified: ["M", "info"], renamed: ["R", "violet"], copied: ["C", "violet"], untracked: ["U", "warn"]};
|
||||
const SIGNS = {add: "+", del: "-", ctx: " ", meta: " "};
|
||||
const NODE_KINDS = {operator: "Operator", chair: "Chair", session: "Session", subagent: "Subagent"};
|
||||
const RADIUS = {operator: 30, chair: 22, session: 15, subagent: 6};
|
||||
const RINGS = [150, 300];
|
||||
const FEED_LIMIT = 300;
|
||||
const MOVE = 2000;
|
||||
const RELAYOUT = 60000;
|
||||
const SESSION_ID = /^[A-Za-z0-9_-]{1,128}$/;
|
||||
const STORE = {views: "kvb-orchestrator.views"};
|
||||
const SOUND_KINDS = [["mayday", "MAYDAY / PAN-PAN"], ["review", "Reviews, Asks, Entscheidungen"], ["direct", "Post und Calls an dich"], ["radio", "Aller Funk"]];
|
||||
const SPEECH_CLASSES = [["post", "Post"], ["call", "Call"], ["newsletter", "Newsletter"], ["broadcast", "Broadcast"], ["mayday", "MAYDAY"], ["pan-pan", "PAN-PAN"], ["security", "SECURITE"]];
|
||||
const SPEECH_QUEUE = 20;
|
||||
const SPEECH_QUIET = 60000;
|
||||
const SPEECH_FRESH = 300;
|
||||
const THEME_CHOICES = [["sky", "Himmel (folgt dem Licht draußen)"], ["light", "Immer hell"], ["dark", "Immer dunkel"], ["custom", "Eigene Farben"]];
|
||||
const COLOR_FIELDS = [["top", "Himmel oben"], ["bottom", "Himmel am Horizont"], ["accent", "Akzent"]];
|
||||
const STAGE_LABELS = {night: "Nacht", astronomical: "Astronomische Dämmerung", nautical: "Nautische Dämmerung", civil: "Bürgerliche Dämmerung", golden: "Goldene Stunde", day: "Tag"};
|
||||
const WEEKDAYS = ["Mo", "Di", "Mi", "Do", "Fr", "Sa", "So"];
|
||||
const COMPASS = [["N", "Norden"], ["NO", "Nordosten"], ["O", "Osten"], ["SO", "Südosten"], ["S", "Süden"], ["SW", "Südwesten"], ["W", "Westen"], ["NW", "Nordwesten"]];
|
||||
const AXES = [["time", "Zeit", "Tiefe = Zeit im gewählten Zeitraum: jeder Agent eine Weltlinie"], ["spawn", "Spawn-Tiefe", "Tiefe = Spawn-Tiefe: Subagenten hängen als Baum unter ihrer Session"]];
|
||||
const SUBS_TTL = 60000;
|
||||
const TURN = 10;
|
||||
const NUDGE = 40;
|
||||
const ZOOM = 1.2;
|
||||
const GLIDE = 320;
|
||||
const PLANE = 450;
|
||||
const SAVE_DELAY = 700;
|
||||
const TRACK_RETRY = 5000;
|
||||
const CALM = [1, 9 / 8, 5 / 4, 3 / 2, 5 / 3, 2];
|
||||
const TENSE = [1, 16 / 15, 6 / 5, 45 / 32, 3 / 2, 8 / 5];
|
||||
const BASE = 110;
|
||||
const FADE = 3000;
|
||||
const DUCK = 0.2;
|
||||
const TONES = {
|
||||
mayday: [[880, 0, 0.18], [660, 0.22, 0.18], [880, 0.44, 0.18], [660, 0.66, 0.18], [880, 0.88, 0.32]],
|
||||
review: [[660, 0, 0.14], [990, 0.16, 0.24]],
|
||||
direct: [[740, 0, 0.2]],
|
||||
radio: [[520, 0, 0.07]],
|
||||
};
|
||||
const KEYS = [["Strg+K", "Befehle, Ansichten, Agenten und KI-Befehl"], ["1 · 2 · 3", "Stream · Agents · Artifacts"], ["j / k", "Inbox: nächster / vorheriger Eintrag"], ["x", "Inbox: Eintrag auswählen"], ["a", "Inbox: Eintrag freigeben (3 s rückgängig)"], ["Enter", "Inbox: Eintrag öffnen"], ["/", "Stream durchsuchen"], ["h", "Himmel ansehen: ziehen dreht den Blick, Rad oder zwei Finger zoomen, Esc beendet"], ["Pfeile · + / − · 0", "3D-Graph und Himmel (fokussiert): drehen · zoomen · zurücksetzen"], ["Umschalt+Pfeile", "3D-Graph: verschieben (auch Umschalt+Ziehen)"], ["🎙 halten", "Spracheingabe ins Agentenfeld oder die Befehlszeile, nie automatisch gesendet"], ["?", "Diese Hilfe"], ["Esc", "Schließen"]];
|
||||
const calm = window.matchMedia("(prefers-reduced-motion: reduce)");
|
||||
const relative = new Intl.RelativeTimeFormat("de", {numeric: "auto"});
|
||||
const absolute = new Intl.DateTimeFormat("de-DE", {dateStyle: "medium", timeStyle: "short"});
|
||||
const clock = new Intl.DateTimeFormat("de-DE", {hour: "2-digit", minute: "2-digit"});
|
||||
@@ -0,0 +1,132 @@
|
||||
function build(node, attrs, children) {
|
||||
for (const [key, value] of Object.entries(attrs)) {
|
||||
if (key === "on") {
|
||||
for (const [name, handler] of Object.entries(value)) {
|
||||
node.addEventListener(name, handler);
|
||||
}
|
||||
} else if (value !== null && value !== undefined && value !== false) {
|
||||
node.setAttribute(key, value === true ? "" : String(value));
|
||||
}
|
||||
}
|
||||
for (const child of children.flat(Infinity)) {
|
||||
if (child !== null && child !== undefined && child !== false) {
|
||||
node.append(child instanceof Node ? child : String(child));
|
||||
}
|
||||
}
|
||||
return node;
|
||||
}
|
||||
const h = (tag, attrs, ...children) => build(document.createElement(tag), attrs, children);
|
||||
const s = (tag, attrs, ...children) => build(document.createElementNS(NS, tag), attrs, children);
|
||||
const dash = (value) => (value === "" || value === "-" || value === null || value === undefined ? "–" : value);
|
||||
const targetsOf = (row) => (row.to.length ? row.to.join(", ") : "alle");
|
||||
const fixed = (value) => value.toFixed(1);
|
||||
const short = (text) => (text.length > 80 ? `${text.slice(0, 80)}…` : text);
|
||||
const btn = (label, cls, run) => h("button", {type: "button", class: cls, on: {click: run}}, label);
|
||||
const nowSeconds = () => Date.now() / 1000;
|
||||
|
||||
function ago(ts) {
|
||||
const diff = ts - nowSeconds();
|
||||
const size = Math.abs(diff);
|
||||
if (size < 45) {
|
||||
return "gerade eben";
|
||||
}
|
||||
if (size < 3600) {
|
||||
return relative.format(Math.round(diff / 60), "minute");
|
||||
}
|
||||
if (size < DAY) {
|
||||
return relative.format(Math.round(diff / 3600), "hour");
|
||||
}
|
||||
return relative.format(Math.round(diff / DAY), "day");
|
||||
}
|
||||
const stampOf = (ts) => new Date(ts * 1000);
|
||||
const when = (ts) => h("time", {"data-ts": ts, datetime: stampOf(ts).toISOString(), title: absolute.format(stampOf(ts))}, ago(ts));
|
||||
const pill = (text, tone) => h("span", {class: "pill", "data-tone": tone}, text);
|
||||
const status = (value) => pill((STATUS[value] || [value])[0], (STATUS[value] || [value, "neutral"])[1]);
|
||||
const klass = (value) => pill(CLASSES[value] || value, PILLS[value] || "neutral");
|
||||
const counter = (value) => h("span", {class: "count"}, String(value));
|
||||
const meta = (pairs) => h("dl", {class: "meta"}, pairs.map(([label, value, title]) => h("div", {}, h("dt", {}, label), h("dd", {}, h("code", {title: title || null}, dash(value))))));
|
||||
const emptyState = (title, text) => h("div", {class: "empty"}, h("div", {class: "empty-mark", "aria-hidden": "true"}), h("h2", {}, title), h("p", {}, text));
|
||||
const live = () => ui.preset !== -1 && ui.asOf === null;
|
||||
const alarmRows = () => state.radio.filter((row) => (row.class === "mayday" || row.class === "pan-pan") && row.ts >= state.alarm_since).reverse();
|
||||
const keyOf = (item) => `${item.kind}:${item.id}`;
|
||||
const visibleInbox = () => state.inbox.filter((item) => ui.snoozed || !item.until);
|
||||
const waitingCount = () => state.inbox.filter((item) => !item.until).length;
|
||||
const isGreen = (item) => item.green && !item.held && !item.until && item.kind !== "operator";
|
||||
const selectable = (item) => !item.held && !(item.kind === "review" && item.gate !== "pass") && !(item.kind === "operator" && !item.runnable) && !(item.kind === "decision" && !item.recommended);
|
||||
const entryOf = (item, verb, label) => ({kind: item.kind, id: item.id, verb, label, sha256: item.sha256 || ""});
|
||||
|
||||
function tick() {
|
||||
for (const node of document.querySelectorAll("time[data-ts]")) {
|
||||
node.textContent = ago(Number(node.dataset.ts));
|
||||
}
|
||||
const updated = document.getElementById("updated");
|
||||
updated.classList.toggle("offline", ui.offline);
|
||||
updated.textContent = `${ui.offline ? "Keine Verbindung · " : ""}${live() ? "Live" : "Stand"} ${absolute.format(stampOf(live() ? state.now : state.until))}`;
|
||||
}
|
||||
|
||||
function avatar(name) {
|
||||
let hash = 2166136261;
|
||||
for (const char of String(name)) {
|
||||
hash = Math.imul(hash ^ char.codePointAt(0), 16777619) >>> 0;
|
||||
}
|
||||
return EMOJI[hash % EMOJI.length];
|
||||
}
|
||||
const face = (name, big) => h("span", {class: big ? "avatar big" : "avatar", "aria-hidden": "true"}, avatar(name));
|
||||
const person = (name) => (name && name !== "-" && name !== "alle" && name !== HUMAN ? h("button", {type: "button", class: "linkish", title: `${name} öffnen`, on: {click: () => openAgent(name)}}, name) : dash(name));
|
||||
const people = () => state.people || {};
|
||||
const labelOf = (key) => (people()[key] || {name: String(key).replace(/^name:/, "")}).name;
|
||||
const nameOf = (key) => (people()[key] || {now: String(key).replace(/^name:/, "")}).now;
|
||||
const agentKey = (who) => (people()[who] ? who : (Object.entries(people()).find(([, entry]) => entry.now === who || entry.names.includes(who)) || [who])[0]);
|
||||
const chairKey = () => (state.graph.nodes.find((node) => node.kind === "chair") || {id: CHAIR}).id;
|
||||
const stamp = (life) => [life.born ? `🐣 ${life.born}` : "", life.died ? `🪦 ${life.died}` : ""].filter(Boolean).join(" · ");
|
||||
|
||||
function toast(title, lines, good) {
|
||||
const box = h("div", {class: `toast${good ? "" : " bad"}`, role: "status", title: "Schließen"}, h("strong", {}, title), lines.length ? h("pre", {}, lines.join("\n")) : null);
|
||||
box.addEventListener("click", () => box.remove());
|
||||
document.getElementById("toasts").append(box);
|
||||
window.setTimeout(() => box.remove(), good ? 9000 : 20000);
|
||||
}
|
||||
|
||||
function runLines(data) {
|
||||
return (data.runs || []).flatMap((run) => [`$ ${run.command} → ${run.code}`, run.stdout.trim(), run.stderr.trim()].filter(Boolean));
|
||||
}
|
||||
|
||||
function copyButton(text) {
|
||||
const button = h("button", {type: "button", class: "btn small ghost", title: "In die Zwischenablage kopieren"}, "Kopieren");
|
||||
button.addEventListener("click", async () => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
button.textContent = "Kopiert";
|
||||
} catch {
|
||||
button.textContent = "Nicht möglich";
|
||||
}
|
||||
window.setTimeout(() => {
|
||||
button.textContent = "Kopieren";
|
||||
}, 1600);
|
||||
});
|
||||
return button;
|
||||
}
|
||||
|
||||
function closeMenus(keep) {
|
||||
for (const menu of document.querySelectorAll("details.menu[open]")) {
|
||||
if (menu !== keep) {
|
||||
menu.open = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function openSheet(title, body, wide) {
|
||||
const sheet = document.getElementById("sheet");
|
||||
sheet.replaceChildren(h("div", {class: `sheet-box${wide ? " wide" : ""}`, role: "dialog", "aria-modal": "true", "aria-label": title},
|
||||
h("div", {class: "sheet-head"}, h("h2", {class: "panel-title"}, title), h("span", {class: "spacer"}), h("button", {type: "button", class: "btn small ghost", "aria-label": "Schließen", on: {click: closeSheet}}, "×")),
|
||||
h("div", {class: "sheet-body"}, body)));
|
||||
sheet.hidden = false;
|
||||
}
|
||||
|
||||
function closeSheet() {
|
||||
const sheet = document.getElementById("sheet");
|
||||
sheet.hidden = true;
|
||||
sheet.replaceChildren();
|
||||
reviewDom = null;
|
||||
ui.review = null;
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
const activeKinds = () => (filter.view ? new Set(state.views[filter.view].kinds) : filter.kinds);
|
||||
const activeWaiting = () => (filter.view ? state.views[filter.view].waiting : filter.waiting);
|
||||
|
||||
function filterQuery() {
|
||||
const params = new URLSearchParams();
|
||||
if (filter.view) {
|
||||
params.set("view", filter.view);
|
||||
} else {
|
||||
params.set("kinds", [...filter.kinds].join(","));
|
||||
if (filter.waiting) {
|
||||
params.set("waiting", "1");
|
||||
}
|
||||
}
|
||||
for (const name of ["q", "agent", "session", "sub"]) {
|
||||
if (filter[name]) {
|
||||
params.set(name, filter[name]);
|
||||
}
|
||||
}
|
||||
if (filter.parts.size !== PARTS.length) {
|
||||
params.set("parts", [...filter.parts].join(","));
|
||||
}
|
||||
return params.toString();
|
||||
}
|
||||
|
||||
function windowKey() {
|
||||
if (ui.preset === -1) {
|
||||
return `custom:${ui.from}:${ui.to}`;
|
||||
}
|
||||
return `${ui.preset}:${ui.asOf === null ? "live" : ui.asOf}`;
|
||||
}
|
||||
|
||||
function customize() {
|
||||
if (filter.view) {
|
||||
filter.kinds = new Set(state.views[filter.view].kinds);
|
||||
filter.waiting = state.views[filter.view].waiting;
|
||||
filter.view = "";
|
||||
}
|
||||
filter.saved = "";
|
||||
}
|
||||
|
||||
function refilter() {
|
||||
drawFilters();
|
||||
drawStream();
|
||||
fetchEvents();
|
||||
}
|
||||
|
||||
function useView(id) {
|
||||
filter.view = id;
|
||||
filter.saved = "";
|
||||
filter.session = "";
|
||||
filter.sub = "";
|
||||
filter.agent = "";
|
||||
filter.q = "";
|
||||
if (ui.screen === "stream" && stream.dom) {
|
||||
stream.dom.search.value = "";
|
||||
refilter();
|
||||
} else {
|
||||
go("stream", null);
|
||||
}
|
||||
}
|
||||
|
||||
function useSaved(view) {
|
||||
filter.view = "";
|
||||
filter.saved = view.name;
|
||||
filter.kinds = new Set(view.kinds);
|
||||
filter.waiting = view.waiting;
|
||||
filter.q = view.q;
|
||||
filter.agent = view.agent;
|
||||
filter.session = "";
|
||||
filter.sub = "";
|
||||
if (ui.screen === "stream" && stream.dom) {
|
||||
stream.dom.search.value = filter.q;
|
||||
refilter();
|
||||
} else {
|
||||
go("stream", null);
|
||||
}
|
||||
}
|
||||
|
||||
function saveView() {
|
||||
const name = (window.prompt("Name der Ansicht", filter.saved || "") || "").trim();
|
||||
if (!name) {
|
||||
return;
|
||||
}
|
||||
const entry = {name: name.slice(0, 60), kinds: [...activeKinds()], waiting: activeWaiting(), q: filter.q, agent: filter.agent};
|
||||
userViews = [...userViews.filter((view) => view.name !== entry.name), entry];
|
||||
if (!keep(STORE.views, userViews)) {
|
||||
toast("Ansicht nur bis zum Neuladen gespeichert", ["Der Browser erlaubt kein localStorage."], false);
|
||||
}
|
||||
useSaved(entry);
|
||||
}
|
||||
|
||||
function dropView(name) {
|
||||
userViews = userViews.filter((view) => view.name !== name);
|
||||
keep(STORE.views, userViews);
|
||||
if (filter.saved === name) {
|
||||
filter.saved = "";
|
||||
}
|
||||
drawFilters();
|
||||
}
|
||||
|
||||
function drawFilters() {
|
||||
if (!stream.dom) {
|
||||
return;
|
||||
}
|
||||
const kinds = activeKinds();
|
||||
stream.dom.categories.replaceChildren(...Object.entries(state.views).map(([id, view]) => h("button", {type: "button", class: "chip preset", "aria-pressed": String(filter.view === id), on: {click: () => useView(id)}}, view.label)));
|
||||
const mine = userViews.map((view) => h("span", {class: "chip", "aria-pressed": String(!filter.view && filter.saved === view.name), role: "button", tabindex: 0, on: {
|
||||
click: () => useSaved(view),
|
||||
keydown: (event) => {
|
||||
if (event.key === "Enter") {
|
||||
useSaved(view);
|
||||
}
|
||||
},
|
||||
}}, view.name, h("button", {type: "button", class: "x", "aria-label": `${view.name} löschen`, on: {click: (event) => {
|
||||
event.stopPropagation();
|
||||
dropView(view.name);
|
||||
}}}, "×")));
|
||||
stream.dom.saved.replaceChildren(...mine, btn("+ Ansicht speichern", "btn small ghost", saveView));
|
||||
const kindChips = KINDS.map(([id, label]) => h("button", {type: "button", class: "chip", "aria-pressed": String(kinds.has(id)), on: {click: () => {
|
||||
customize();
|
||||
if (filter.kinds.has(id) && filter.kinds.size > 1) {
|
||||
filter.kinds.delete(id);
|
||||
} else {
|
||||
filter.kinds.add(id);
|
||||
}
|
||||
refilter();
|
||||
}}}, label));
|
||||
const waiting = h("button", {type: "button", class: "chip", "aria-pressed": String(activeWaiting()), on: {click: () => {
|
||||
customize();
|
||||
filter.waiting = !filter.waiting;
|
||||
refilter();
|
||||
}}}, "nur Wartendes");
|
||||
stream.dom.kinds.replaceChildren(waiting, ...kindChips);
|
||||
const parts = kinds.has("transcript") ? PARTS.map(([id, label]) => h("button", {type: "button", class: "chip", "aria-pressed": String(filter.parts.has(id)), on: {click: () => {
|
||||
if (filter.parts.has(id) && filter.parts.size > 1) {
|
||||
filter.parts.delete(id);
|
||||
} else {
|
||||
filter.parts.add(id);
|
||||
}
|
||||
refilter();
|
||||
}}}, label)) : [h("span", {class: "muted"}, "Erst mit der Art Transkripte.")];
|
||||
stream.dom.parts.replaceChildren(...parts);
|
||||
const focus = filter.sub || filter.session || filter.agent ? h("span", {class: "chip", "aria-pressed": "true"}, filter.sub ? `Subagent ${filter.sub.slice(0, 12)}` : filter.session ? `Session ${filter.session.slice(0, 8)}` : `Agent ${filter.agent}`,
|
||||
h("button", {type: "button", class: "x", "aria-label": "Filter entfernen", on: {click: () => {
|
||||
filter.sub = "";
|
||||
filter.session = "";
|
||||
filter.agent = "";
|
||||
refilter();
|
||||
}}}, "×")) : null;
|
||||
stream.dom.focus.replaceChildren(...(focus ? [focus] : []));
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
function orbit() {
|
||||
const nodes = state.graph.nodes;
|
||||
positions = layout(nodes);
|
||||
const svg = chartFrame(400, "Orbit: Operator in der Mitte; wer zusammen arbeitet oder funkt, rückt zusammen, Stille driften nach außen");
|
||||
svg.append(...RINGS.map((r) => s("circle", {class: "ring", r})));
|
||||
const edgeLayer = s("g", {});
|
||||
const halos = new Map();
|
||||
for (const link of aggregate()) {
|
||||
const from = positions.get(link.source);
|
||||
const shade = tone(link.cls);
|
||||
const words = `${link.count}× ${CLASSES[link.cls] || link.cls}`;
|
||||
if (!from) {
|
||||
continue;
|
||||
}
|
||||
if (link.target === "*") {
|
||||
const index = halos.get(link.source) || 0;
|
||||
halos.set(link.source, index + 1);
|
||||
edgeLayer.append(s("circle", {class: `halo t-${shade}`, cx: fixed(from.x), cy: fixed(from.y), r: radiusOf(link.source) + 7 + index * 7, "stroke-width": width(link.count)},
|
||||
s("title", {}, `${link.source} an alle: ${words}`)));
|
||||
continue;
|
||||
}
|
||||
const to = positions.get(link.target);
|
||||
if (!to || to === from) {
|
||||
continue;
|
||||
}
|
||||
const control = Space.bend(from, to);
|
||||
const start = toward(from, control, radiusOf(link.source) + 2);
|
||||
const end = toward(to, control, radiusOf(link.target) + 4);
|
||||
edgeLayer.append(s("path", {class: `edge t-${shade}`, d: `M${fixed(start.x)},${fixed(start.y)} Q${fixed(control.x)},${fixed(control.y)} ${fixed(end.x)},${fixed(end.y)}`, "stroke-width": fixed(width(link.count)), "marker-end": `url(#tip-${shade})`},
|
||||
s("title", {}, `${link.source} → ${link.target}: ${words}`)));
|
||||
}
|
||||
const nodeLayer = s("g", {}, nodes.map((node) => nodeMark(node, positions.get(node.id), node.kind === "operator" || node.kind === "subagent" ? null : RADIUS[node.kind] + 9)));
|
||||
const pulseLayer = s("g", {});
|
||||
svg.append(edgeLayer, nodeLayer, pulseLayer);
|
||||
graphDom.pulses = pulseLayer;
|
||||
return svg;
|
||||
}
|
||||
|
||||
function chord() {
|
||||
const nodes = state.graph.nodes.filter((node) => node.kind !== "subagent");
|
||||
const fresh = targets();
|
||||
const radius = 250;
|
||||
const step = (2 * Math.PI) / Math.max(nodes.length, 1);
|
||||
const spots = new Map(nodes.map((node) => {
|
||||
const angle = spotOf(node.id, fresh).chord;
|
||||
return [node.id, {x: radius * Math.cos(angle), y: radius * Math.sin(angle), angle}];
|
||||
}));
|
||||
const svg = chartFrame(450, "Chord: Nachrichten zwischen Agenten, Reihenfolge nach Nähe");
|
||||
const arcs = s("g", {});
|
||||
const point = (angle, r) => `${fixed(r * Math.cos(angle))},${fixed(r * Math.sin(angle))}`;
|
||||
for (const node of nodes) {
|
||||
const at = spots.get(node.id);
|
||||
const half = Math.min(step * 0.36, 0.5);
|
||||
arcs.append(s("path", {class: `group-arc k-${node.kind}`, d: `M${point(at.angle - half, radius + 14)} A${radius + 14},${radius + 14} 0 0 1 ${point(at.angle + half, radius + 14)}`}));
|
||||
}
|
||||
const pairs = new Map();
|
||||
const fans = new Map();
|
||||
for (const link of aggregate()) {
|
||||
const shade = tone(link.cls);
|
||||
if (!spots.has(link.source)) {
|
||||
continue;
|
||||
}
|
||||
if (link.target === "*") {
|
||||
const key = `${link.source}\u0000${shade}`;
|
||||
fans.set(key, {source: link.source, shade, count: (fans.has(key) ? fans.get(key).count : 0) + link.count});
|
||||
continue;
|
||||
}
|
||||
if (!spots.has(link.target) || link.target === link.source) {
|
||||
continue;
|
||||
}
|
||||
const [a, b] = [link.source, link.target].sort();
|
||||
const key = `${a}\u0000${b}\u0000${shade}`;
|
||||
pairs.set(key, {a, b, shade, count: (pairs.has(key) ? pairs.get(key).count : 0) + link.count});
|
||||
}
|
||||
const lanes = LEGEND.map(([name]) => name);
|
||||
for (const pair of pairs.values()) {
|
||||
const from = spots.get(pair.a);
|
||||
const to = spots.get(pair.b);
|
||||
const pull = 0.06 + 0.12 * lanes.indexOf(pair.shade);
|
||||
const control = {x: ((from.x + to.x) / 2) * pull, y: ((from.y + to.y) / 2) * pull};
|
||||
const start = toward(from, control, RADIUS.session + 2);
|
||||
const end = toward(to, control, RADIUS.session + 2);
|
||||
arcs.append(s("path", {class: `edge t-${pair.shade}`, d: `M${fixed(start.x)},${fixed(start.y)} Q${fixed(control.x)},${fixed(control.y)} ${fixed(end.x)},${fixed(end.y)}`, "stroke-width": fixed(width(pair.count))},
|
||||
s("title", {}, `${pair.a} ↔ ${pair.b}: ${pair.count}× ${LEGEND.find(([name]) => name === pair.shade)[1]}`)));
|
||||
}
|
||||
const offsets = new Map();
|
||||
for (const fan of fans.values()) {
|
||||
const at = spots.get(fan.source);
|
||||
const index = offsets.get(fan.source) || 0;
|
||||
offsets.set(fan.source, index + 1);
|
||||
const angle = at.angle + (index - 1) * 0.05;
|
||||
const length = Math.min(8 + 6 * Math.log2(1 + fan.count), 40);
|
||||
arcs.append(s("line", {class: `tick t-${fan.shade}`, x1: fixed((radius + 22) * Math.cos(angle)), y1: fixed((radius + 22) * Math.sin(angle)), x2: fixed((radius + 22 + length) * Math.cos(angle)), y2: fixed((radius + 22 + length) * Math.sin(angle)), "stroke-width": 4},
|
||||
s("title", {}, `${fan.source} an alle: ${fan.count}×`)));
|
||||
}
|
||||
svg.append(arcs, s("g", {}, nodes.map((node) => nodeMark(node, spots.get(node.id), 74))));
|
||||
return svg;
|
||||
}
|
||||
|
||||
function swimlane() {
|
||||
const rank = new Map([HUMAN, ...state.graph.layout.order].map((id, index) => [id, index]));
|
||||
const lanes = state.graph.nodes.filter((node) => node.kind !== "subagent").sort((a, b) => (rank.has(a.id) ? rank.get(a.id) : 1e6) - (rank.has(b.id) ? rank.get(b.id) : 1e6));
|
||||
const begin = state.since;
|
||||
const end = Math.max(state.until, state.since + 1);
|
||||
const left = 160;
|
||||
const right = 24;
|
||||
const top = 40;
|
||||
const lane = 36;
|
||||
const full = 1120;
|
||||
const height = top + lanes.length * lane + 12;
|
||||
const x = (ts) => left + ((ts - begin) / (end - begin)) * (full - left - right);
|
||||
const y = new Map(lanes.map((node, index) => [node.id, top + index * lane + lane / 2]));
|
||||
const svg = s("svg", {viewBox: `0 0 ${full} ${height}`, class: "chart", role: "img", "aria-label": "Swimlane: Nachrichten über die Zeit"}, defs());
|
||||
lanes.forEach((node, index) => {
|
||||
svg.append(s("rect", {class: index % 2 ? "lane odd" : "lane", x: 0, y: top + index * lane, width: full, height: lane}));
|
||||
svg.append(s("text", {class: "lane-label", x: 14, y: top + index * lane + lane / 2, dy: "0.35em", "text-anchor": "start", on: {click: () => select(node.id)}}, node.label));
|
||||
});
|
||||
for (let index = 0; index <= 6; index += 1) {
|
||||
const ts = begin + ((end - begin) * index) / 6;
|
||||
svg.append(s("line", {class: "grid", x1: fixed(x(ts)), x2: fixed(x(ts)), y1: top - 6, y2: height - 8}));
|
||||
svg.append(s("text", {class: "axis", x: fixed(x(ts)), y: top - 14, "text-anchor": index === 0 ? "start" : index === 6 ? "end" : "middle"}, (end - begin > DAY ? absolute : clock).format(stampOf(ts))));
|
||||
}
|
||||
if (live()) {
|
||||
svg.append(s("line", {class: "now", x1: fixed(x(end)), x2: fixed(x(end)), y1: top - 6, y2: height - 8}));
|
||||
}
|
||||
const marks = s("g", {});
|
||||
const arrows = (cls, ts, from, to, words) => {
|
||||
const x0 = fixed(x(ts));
|
||||
const y0 = y.get(from);
|
||||
if (y0 === undefined) {
|
||||
return;
|
||||
}
|
||||
const shade = tone(cls);
|
||||
const hint = s("title", {}, `${clock.format(stampOf(ts))} · ${dash(labelOf(from))} → ${to.length ? to.map(labelOf).join(", ") : "alle"}\n${words}`);
|
||||
if (!to.length) {
|
||||
const rays = [[-6, -13], [0, -15], [6, -13], [-6, 13], [0, 15], [6, 13]].map(([dx, dy]) => `M${x0},${y0} l${dx},${dy}`).join(" ");
|
||||
marks.append(s("g", {class: `mark t-${shade}`}, hint, s("path", {d: rays}), s("circle", {cx: x0, cy: y0, r: 3.5})));
|
||||
return;
|
||||
}
|
||||
const bundle = s("g", {class: `mark t-${shade}`}, hint, s("circle", {cx: x0, cy: y0, r: 3}));
|
||||
for (const target of to) {
|
||||
const y1 = y.get(target);
|
||||
if (y1 !== undefined && y1 !== y0) {
|
||||
bundle.append(s("line", {x1: x0, y1: y0, x2: x0, y2: y1 > y0 ? y1 - 6 : y1 + 6, "marker-end": `url(#tip-${shade})`}));
|
||||
}
|
||||
}
|
||||
marks.append(bundle);
|
||||
};
|
||||
for (const row of state.radio) {
|
||||
arrows(row.class, row.ts, row.source, row.targets, row.text.length > 120 ? `${row.text.slice(0, 120)}…` : row.text);
|
||||
}
|
||||
for (const grant of state.grants) {
|
||||
arrows("grant", grant.ts, chairKey(), [grant.target], `Queue-Freigabe ${grant.kind} (${grant.id})`);
|
||||
}
|
||||
svg.append(marks);
|
||||
return svg;
|
||||
}
|
||||
|
||||
function legend() {
|
||||
const axis = graph3d() ? depth() : "none";
|
||||
const words = {
|
||||
none: "Linienstärke = Anzahl · Nähe = Zusammenarbeit der letzten Zeit",
|
||||
time: "Weltlinie = Agent, Lage = Nähe der Zusammenarbeit zu ihrer Zeit · Bogen = ein Ereignis · Ebene = Stand der Wiedergabe",
|
||||
spawn: "Ebenen = Spawn-Tiefe · Bogen = Nachrichten im Zeitraum, Zahl im Stream",
|
||||
};
|
||||
return h("div", {class: "legend"}, LEGEND.map(([name, label]) => h("span", {}, h("i", {class: `swatch t-${name}`}), label)),
|
||||
axis === "none" ? null : h("span", {}, h("i", {class: "swatch t-spawn"}), "Spawn"),
|
||||
h("span", {class: "muted"}, words[axis]));
|
||||
}
|
||||
|
||||
function side() {
|
||||
const node = state.graph.nodes.find((entry) => entry.id === ui.node);
|
||||
if (!node) {
|
||||
const where = graph3d() ? "eine Weltlinie oder darunter auf ihren Namen" : "einen Knoten";
|
||||
return [h("h2", {class: "panel-title"}, "Details"), h("p", {class: "muted"}, `Klicke auf ${where}: sein Panel zeigt Aufgaben, Claims, Subagenten und Verlauf.`)];
|
||||
}
|
||||
const messages = state.radio.filter((row) => row.source === node.id || row.targets.includes(node.id)).slice(-10).reverse();
|
||||
return [
|
||||
h("div", {class: "panel-head"},
|
||||
h("div", {}, h("h2", {class: "panel-title"}, node.label), h("span", {class: "muted"}, `${NODE_KINDS[node.kind]}${node.parent ? ` von ${labelOf(node.parent)}` : ""}`)),
|
||||
h("button", {type: "button", class: "btn small ghost", "aria-label": "Schließen", on: {click: () => select(node.id)}}, "×")),
|
||||
h("h3", {}, "Letzte Nachrichten", counter(messages.length)),
|
||||
messages.length ? h("ul", {class: "mini"}, messages.map((row) => h("li", {},
|
||||
h("div", {class: "row"}, klass(row.class), when(row.ts)),
|
||||
h("span", {class: "muted"}, `${dash(row.from)} → ${targetsOf(row)}`),
|
||||
h("span", {}, row.text)))) : h("p", {class: "muted"}, "Keine Nachrichten im gewählten Zeitraum."),
|
||||
];
|
||||
}
|
||||
|
||||
function viewSwitch(screen) {
|
||||
return h("div", {class: "segmented", role: "group", "aria-label": "Ansicht"}, Nav.VIEWS.map(([id, name]) => h("button", {type: "button", "aria-pressed": String(ui.views[screen] === id), on: {click: () => go(screen, id)}}, name)));
|
||||
}
|
||||
|
||||
const later = (what) => emptyState(`${what} folgt`, "Diese Ansicht ist geplant und kommt mit dem nächsten Ausbau.");
|
||||
|
||||
function agentsScreen() {
|
||||
const view = ui.views.agents;
|
||||
const stageBox = h("div", {class: "stage"});
|
||||
const aside = h("aside", {class: "card panel", "aria-live": "polite"});
|
||||
const toolbar = agentsToolbar();
|
||||
graphDom = {stage: stageBox, aside, pulses: null, space: null, toolbar};
|
||||
const body = view === "tree" ? later("Der Spawn-Baum") : h("div", {class: "graph-body"}, h("div", {class: "card stage-card"}, stageBox, legend()), aside);
|
||||
return h("div", {class: "graph"}, toolbar.bar, h("div", {class: "card controls"}, viewSwitch("agents"), view === "3d" ? spaceTools() : null), body);
|
||||
}
|
||||
|
||||
function artifactsScreen() {
|
||||
const view = ui.views.artifacts;
|
||||
return h("div", {class: "graph"}, h("div", {class: "card controls"}, viewSwitch("artifacts")), view === "tree" ? treeScreen() : later(`Artifacts ${Nav.VIEWS.find(([id]) => id === view)[1]}`));
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
function aggregate() {
|
||||
const links = new Map();
|
||||
const add = (source, target, cls) => {
|
||||
const key = `${source}\u0000${target}\u0000${cls}`;
|
||||
const link = links.get(key) || {source, target, cls, count: 0};
|
||||
link.count += 1;
|
||||
links.set(key, link);
|
||||
};
|
||||
for (const row of state.radio) {
|
||||
for (const target of row.source ? (row.targets.length ? row.targets : ["*"]) : []) {
|
||||
add(row.source, target, row.class);
|
||||
}
|
||||
}
|
||||
for (const grant of state.grants) {
|
||||
add(chairKey(), grant.target, "grant");
|
||||
}
|
||||
const order = (link) => (tone(link.cls) === "alarm" ? 1e6 : 0) + link.count;
|
||||
return [...links.values()].sort((a, b) => order(a) - order(b));
|
||||
}
|
||||
|
||||
const width = (count) => Math.min(1.25 + Math.log2(1 + count) * 1.6, 9);
|
||||
const tone = (cls) => Space.TONES[cls] || "direct";
|
||||
|
||||
function defs() {
|
||||
return s("defs", {}, LEGEND.map(([name]) => s("marker", {id: `tip-${name}`, viewBox: "0 0 10 10", refX: 8, refY: 5, markerWidth: 9, markerHeight: 9, markerUnits: "userSpaceOnUse", orient: "auto-start-reverse", class: `t-${name}`},
|
||||
s("path", {class: "tip", d: "M0,0 L10,5 L0,10 z"}))));
|
||||
}
|
||||
|
||||
function toward(point, aim, gap) {
|
||||
const dx = aim.x - point.x;
|
||||
const dy = aim.y - point.y;
|
||||
const length = Math.hypot(dx, dy) || 1;
|
||||
return {x: point.x + (dx / length) * gap, y: point.y + (dy / length) * gap};
|
||||
}
|
||||
|
||||
function radiusOf(id) {
|
||||
const node = state.graph.nodes.find((entry) => entry.id === id);
|
||||
return node ? RADIUS[node.kind] : RADIUS.session;
|
||||
}
|
||||
|
||||
function targets() {
|
||||
const plan = state.graph.layout;
|
||||
const order = [HUMAN, ...plan.order];
|
||||
return new Map(order.map((id, index) => {
|
||||
const spot = plan.orbit[id] || {angle: -Math.PI / 2, radius: 0};
|
||||
return [id, {angle: spot.angle, radius: spot.radius, chord: -Math.PI / 2 + (2 * Math.PI * index) / order.length}];
|
||||
}));
|
||||
}
|
||||
|
||||
function step(now) {
|
||||
const progress = motion.duration ? Math.min((now - motion.start) / motion.duration, 1) : 1;
|
||||
const eased = Space.ease(progress);
|
||||
motion.current = new Map([...motion.target].map(([id, to]) => {
|
||||
const from = motion.from.get(id) || to;
|
||||
return [id, {angle: Space.turn(from.angle, to.angle, eased), radius: from.radius + (to.radius - from.radius) * eased, chord: Space.turn(from.chord, to.chord, eased)}];
|
||||
}));
|
||||
if (ui.views.agents !== "swimlane") {
|
||||
stage();
|
||||
}
|
||||
motion.frame = progress < 1 ? window.requestAnimationFrame(step) : 0;
|
||||
}
|
||||
|
||||
function relayout(duration) {
|
||||
const next = targets();
|
||||
motion.from = new Map([...next.keys()].map((id) => [id, motion.current.get(id) || next.get(id)]));
|
||||
motion.target = next;
|
||||
motion.start = performance.now();
|
||||
motion.duration = calm.matches ? 0 : duration;
|
||||
if (!motion.frame) {
|
||||
motion.frame = window.requestAnimationFrame(step);
|
||||
}
|
||||
}
|
||||
|
||||
function spotOf(id, fresh) {
|
||||
return motion.current.get(id) || fresh.get(id) || {angle: -Math.PI / 2, radius: RINGS[1], chord: -Math.PI / 2};
|
||||
}
|
||||
|
||||
function layout(nodes) {
|
||||
const fresh = targets();
|
||||
const spots = new Map();
|
||||
for (const node of nodes.filter((entry) => entry.kind !== "subagent")) {
|
||||
const at = spotOf(node.id, fresh);
|
||||
const radius = node.kind === "operator" ? 0 : at.radius;
|
||||
spots.set(node.id, {x: radius * Math.cos(at.angle), y: radius * Math.sin(at.angle), angle: at.angle});
|
||||
}
|
||||
const moons = new Map();
|
||||
for (const node of nodes.filter((entry) => entry.kind === "subagent")) {
|
||||
moons.set(node.parent, [...(moons.get(node.parent) || []), node]);
|
||||
}
|
||||
for (const [parent, list] of moons) {
|
||||
const base = spots.get(parent) || spots.get(chairKey()) || {x: 0, y: 0, angle: -Math.PI / 2};
|
||||
list.forEach((node, index) => spots.set(node.id, Space.moon(base, index, list.length)));
|
||||
}
|
||||
return spots;
|
||||
}
|
||||
|
||||
function caption(node, at, r, gap) {
|
||||
if (node.kind === "subagent") {
|
||||
return null;
|
||||
}
|
||||
if (gap === null) {
|
||||
return s("text", {class: "label", y: r + 17, "text-anchor": "middle"}, node.label);
|
||||
}
|
||||
const cos = Math.cos(at.angle);
|
||||
const sin = Math.sin(at.angle);
|
||||
const anchor = cos > 0.3 ? "start" : cos < -0.3 ? "end" : "middle";
|
||||
return s("text", {class: "label", x: fixed(cos * gap), y: fixed(sin * (gap + 3)), dy: "0.35em", "text-anchor": anchor}, node.label);
|
||||
}
|
||||
|
||||
function select(id) {
|
||||
ui.node = ui.node === id ? null : id;
|
||||
stage();
|
||||
drawSide();
|
||||
const node = state.graph.nodes.find((entry) => entry.id === id);
|
||||
if (ui.node !== null && node && node.kind !== "operator") {
|
||||
openAgent(node.kind === "subagent" ? node.parent : id);
|
||||
}
|
||||
}
|
||||
|
||||
function nodeMark(node, at, gap) {
|
||||
const r = RADIUS[node.kind];
|
||||
const classes = ["node", `k-${node.kind}`, ui.node === node.id ? "selected" : "", node.claims.length ? "claimed" : ""].filter(Boolean).join(" ");
|
||||
const tasks = node.tasks.length ? ` · ${node.tasks.length} Aufgaben` : "";
|
||||
return s("g", {
|
||||
class: classes, transform: `translate(${fixed(at.x)} ${fixed(at.y)})`, tabindex: 0, role: "button", "aria-label": `${node.label}, ${NODE_KINDS[node.kind]}`,
|
||||
on: {
|
||||
click: () => select(node.id),
|
||||
keydown: (event) => {
|
||||
if (event.key === "Enter" || event.key === " ") {
|
||||
event.preventDefault();
|
||||
select(node.id);
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
s("title", {}, `${node.label} · ${NODE_KINDS[node.kind]}${node.parent ? ` von ${labelOf(node.parent)}` : ""}${tasks}`),
|
||||
s("circle", {r}),
|
||||
node.kind === "subagent" ? null : s("text", {class: "initial", "text-anchor": "middle", dy: "0.35em"}, node.label.slice(0, 1).toUpperCase()),
|
||||
caption(node, at, r, gap));
|
||||
}
|
||||
|
||||
function chartFrame(size, label) {
|
||||
return s("svg", {viewBox: `${-size} ${-size} ${2 * size} ${2 * size}`, class: "chart", role: "img", "aria-label": label}, defs());
|
||||
}
|
||||
@@ -0,0 +1,230 @@
|
||||
async function submit(entries, label) {
|
||||
ui.busy = true;
|
||||
const signed = await proofFor(entries, label);
|
||||
if (signed === null) {
|
||||
ui.busy = false;
|
||||
await load();
|
||||
return false;
|
||||
}
|
||||
const result = await sendJson("/api/inbox/approve", {items: entries, proof: signed.proof});
|
||||
ui.busy = false;
|
||||
if (!result.ok || !result.data) {
|
||||
toast(`${label}: nicht möglich`, fail(result), false);
|
||||
await load();
|
||||
return false;
|
||||
}
|
||||
known.batches.add(result.data.id);
|
||||
ui.selected.clear();
|
||||
undoToast(result.data, label);
|
||||
await load();
|
||||
return true;
|
||||
}
|
||||
|
||||
function undoToast(batch, label) {
|
||||
const left = h("span", {class: "muted"});
|
||||
const button = h("button", {type: "button", class: "btn small"}, "Rückgängig");
|
||||
const box = h("div", {class: "toast wait", role: "status"}, h("strong", {}, label), h("div", {class: "undo-row"}, left, h("span", {class: "spacer"}), button));
|
||||
let timer = 0;
|
||||
const count = () => {
|
||||
const rest = Math.ceil(batch.due - nowSeconds());
|
||||
if (rest <= 0) {
|
||||
window.clearInterval(timer);
|
||||
box.remove();
|
||||
load();
|
||||
return;
|
||||
}
|
||||
left.textContent = `wird in ${rest} s wirksam`;
|
||||
};
|
||||
timer = window.setInterval(count, 250);
|
||||
button.addEventListener("click", async () => {
|
||||
window.clearInterval(timer);
|
||||
button.disabled = true;
|
||||
const result = await send(`/api/inbox/undo/${encodeURIComponent(batch.id)}`, "", "application/json");
|
||||
box.remove();
|
||||
toast(result.ok ? `Rückgängig: ${label}` : "Zu spät: schon wirksam", result.ok ? [] : [`${result.status} ${result.text}`.trim()], result.ok);
|
||||
await load();
|
||||
});
|
||||
document.getElementById("toasts").append(box);
|
||||
count();
|
||||
}
|
||||
|
||||
function approveOne(item) {
|
||||
if (item.kind === "decision") {
|
||||
if (!item.recommended) {
|
||||
openItem(item);
|
||||
return null;
|
||||
}
|
||||
return submit([entryOf(item, "approve", item.recommended)], `Entscheidung: ${item.recommended}`);
|
||||
}
|
||||
return submit([entryOf(item, "approve", "")], `${item.kind === "operator" ? "Ausführen" : "Freigabe"}: ${short(item.title)}`);
|
||||
}
|
||||
|
||||
const rejectOne = (item) => submit([entryOf(item, "reject", "")], `Ablehnung: ${short(item.title)}`);
|
||||
const chooseOne = (item, label) => submit([entryOf(item, "approve", label)], `Entscheidung: ${label}`);
|
||||
|
||||
function bulk(items, label) {
|
||||
const usable = items.filter(selectable);
|
||||
if (!usable.length) {
|
||||
toast(`${label}: nichts freizugeben`, [], false);
|
||||
return;
|
||||
}
|
||||
const rows = usable.map((item) => h("li", {},
|
||||
h("div", {class: "row"}, pill(ITEM_LABELS[item.kind], KIND_TONES[item.kind]), item.kind === "decision" ? h("span", {class: "muted"}, `→ ${item.recommended}`) : null),
|
||||
h("strong", {}, item.title),
|
||||
item.kind === "operator" ? h("div", {class: "command"}, h("code", {}, item.command)) : null,
|
||||
item.kind === "operator" ? h("span", {class: "muted"}, `in ${item.directory}`) : null,
|
||||
item.kind === "ask" ? h("div", {class: "command"}, h("code", {}, item.command)) : null));
|
||||
const confirm = h("button", {type: "button", class: "btn primary"}, `${usable.length} freigeben`);
|
||||
confirm.addEventListener("click", () => {
|
||||
closeSheet();
|
||||
submit(usable.map((item) => entryOf(item, "approve", item.kind === "decision" ? item.recommended : "")), `${label}: ${usable.length} Einträge`);
|
||||
});
|
||||
openSheet(label, [h("p", {class: "muted"}, "Jeder Eintrag und jeder volle Befehl, der freigegeben wird. Nach dem Klick signiert der Passkey die ganze Auswahl einmal; danach bleiben 3 s zum Rückgängigmachen."), h("ul", {class: "mini"}, rows), h("div", {class: "actions"}, h("span", {class: "spacer"}), btn("Abbrechen", "btn ghost", closeSheet), confirm)], false);
|
||||
confirm.focus();
|
||||
}
|
||||
|
||||
async function mark(item, until, pinned) {
|
||||
const result = await sendJson("/api/inbox/mark", {kind: item.kind, id: item.id, until, pinned});
|
||||
if (!result.ok) {
|
||||
toast("Merken fehlgeschlagen", [`${result.status} ${result.text}`.trim()], false);
|
||||
}
|
||||
await load();
|
||||
}
|
||||
|
||||
function tomorrow() {
|
||||
const date = new Date();
|
||||
date.setDate(date.getDate() + 1);
|
||||
date.setHours(8, 0, 0, 0);
|
||||
return date.getTime() / 1000;
|
||||
}
|
||||
|
||||
function toggle(item) {
|
||||
if (!item || !selectable(item)) {
|
||||
return;
|
||||
}
|
||||
const key = keyOf(item);
|
||||
if (ui.selected.has(key)) {
|
||||
ui.selected.delete(key);
|
||||
} else {
|
||||
ui.selected.add(key);
|
||||
}
|
||||
drawInbox();
|
||||
}
|
||||
|
||||
function actionsFor(item) {
|
||||
if (item.held) {
|
||||
return [h("span", {class: "muted"}, "wird wirksam …")];
|
||||
}
|
||||
const buttons = [];
|
||||
if (item.kind === "review" || item.kind === "ask") {
|
||||
buttons.push(btn("Freigeben", "btn small primary", () => approveOne(item)), btn("Ablehnen", "btn small danger", () => rejectOne(item)));
|
||||
} else if (item.kind === "decision" && item.recommended) {
|
||||
buttons.push(btn(`Empfehlung: ${item.recommended}`, "btn small primary", () => approveOne(item)));
|
||||
} else if (item.kind === "operator" && item.runnable) {
|
||||
buttons.push(btn("Ausführen", "btn small primary", () => approveOne(item)));
|
||||
}
|
||||
return buttons;
|
||||
}
|
||||
|
||||
function inboxItem(item, index) {
|
||||
const red = item.kind === "review" && item.gate !== "pass";
|
||||
const classes = ["item", isGreen(item) ? "green" : "", red ? "red" : "", item.held ? "held" : "", index === ui.cursor ? "cursor" : ""].filter(Boolean).join(" ");
|
||||
const box = h("input", {type: "checkbox", "aria-label": `${item.title} auswählen`, checked: ui.selected.has(keyOf(item)), disabled: !selectable(item), on: {change: () => toggle(item)}});
|
||||
return h("li", {class: classes, "data-index": index},
|
||||
box,
|
||||
h("div", {},
|
||||
h("div", {class: "head-row"},
|
||||
pill(ITEM_LABELS[item.kind], KIND_TONES[item.kind]),
|
||||
item.kind === "review" ? pill(item.gate === "pass" ? "Gate grün" : "Gate rot", item.gate === "pass" ? "ok" : "bad") : null,
|
||||
item.warnings.map((warning) => pill(warning, "bad")),
|
||||
item.pinned ? pill("angeheftet", "violet") : null,
|
||||
item.until ? pill(`bis ${absolute.format(stampOf(item.until))}`, "neutral") : null,
|
||||
h("span", {class: "spacer"}), when(item.ts)),
|
||||
h("button", {type: "button", class: "linkish", title: "Öffnen", on: {click: () => openItem(item)}}, item.title),
|
||||
item.agent ? h("div", {class: "muted"}, "von ", person(item.agent)) : null,
|
||||
item.kind === "review" ? h("div", {class: "muted"}, item.detail, item.score ? ` · ${item.score}` : "") : null,
|
||||
item.kind === "operator" && item.title !== item.command ? h("div", {class: "command"}, h("code", {}, item.command)) : null,
|
||||
item.kind === "operator" ? h("div", {class: "muted"}, `in ${dash(item.directory)}`, item.detail !== "-" ? ` · ${item.detail}` : "") : null,
|
||||
item.kind === "ask" ? h("div", {class: "muted"}, `in ${dash(item.directory)}`) : null,
|
||||
item.kind === "decision" ? h("div", {class: "options"}, item.options.map((option) => h("button", {
|
||||
type: "button", class: `option${option.label === item.recommended ? " recommended" : ""}`, disabled: item.held, on: {click: () => chooseOne(item, option.label)},
|
||||
}, h("strong", {}, option.label), option.description ? h("span", {}, option.description) : null))) : null),
|
||||
h("div", {class: "item-actions"},
|
||||
actionsFor(item),
|
||||
item.kind === "operator" ? copyButton(item.command) : null,
|
||||
h("span", {class: "spacer"}),
|
||||
btn("1 h", "btn small ghost", () => mark(item, nowSeconds() + 3600, item.pinned)),
|
||||
btn("morgen", "btn small ghost", () => mark(item, tomorrow(), item.pinned)),
|
||||
item.until ? btn("wecken", "btn small ghost", () => mark(item, 0, item.pinned)) : null,
|
||||
btn(item.pinned ? "lösen" : "anheften", "btn small ghost", () => mark(item, item.until, !item.pinned))));
|
||||
}
|
||||
|
||||
function inboxScreen() {
|
||||
inboxDom = h("div", {class: "inbox"});
|
||||
return inboxDom;
|
||||
}
|
||||
|
||||
function drawInbox() {
|
||||
if (!inboxDom) {
|
||||
return;
|
||||
}
|
||||
const items = visibleInbox();
|
||||
ui.cursor = Math.min(ui.cursor, Math.max(items.length - 1, 0));
|
||||
const present = new Set(items.map(keyOf));
|
||||
for (const key of [...ui.selected]) {
|
||||
if (!present.has(key)) {
|
||||
ui.selected.delete(key);
|
||||
}
|
||||
}
|
||||
const sig = JSON.stringify([items, [...ui.selected], ui.cursor, ui.snoozed, ui.busy, Math.floor(nowSeconds() / 60)]);
|
||||
if (sig === inboxSig) {
|
||||
return;
|
||||
}
|
||||
inboxSig = sig;
|
||||
const green = items.filter(isGreen);
|
||||
const chosen = items.filter((item) => ui.selected.has(keyOf(item)));
|
||||
const hidden = state.inbox.length - waitingCount();
|
||||
const snoozed = h("input", {type: "checkbox", checked: ui.snoozed, on: {change: (event) => {
|
||||
ui.snoozed = event.target.checked;
|
||||
drawInbox();
|
||||
}}});
|
||||
const choose = h("button", {type: "button", class: "btn small soft", disabled: !chosen.length || ui.busy, on: {click: () => bulk(chosen, "Auswahl freigeben")}}, `Auswahl freigeben (${chosen.length})`);
|
||||
const all = h("button", {type: "button", class: "btn small primary", disabled: !green.length || ui.busy, on: {click: () => bulk(green, "Alle grünen freigeben")}}, `Alle grünen freigeben (${green.length})`);
|
||||
inboxDom.replaceChildren(
|
||||
h("div", {class: "inbox-head"}, h("h2", {class: "group-title"}, "Inbox", counter(waitingCount())), h("span", {class: "spacer"}),
|
||||
hidden ? h("label", {class: "check"}, snoozed, `${hidden} zurückgestellt`) : null),
|
||||
h("div", {class: "inbox-actions"}, choose, all),
|
||||
onLocalhost() ? null : h("p", {class: "muted"}, "Freigaben signiert der Passkey nur unter ", localLink()),
|
||||
items.length ? h("ol", {class: "inbox-list"}, items.map(inboxItem)) : emptyState("Alles erledigt", "Gerade wartet nichts auf dich."));
|
||||
const current = inboxDom.querySelector(`.item[data-index="${ui.cursor}"]`);
|
||||
if (current && document.activeElement === document.body) {
|
||||
current.scrollIntoView({block: "nearest"});
|
||||
}
|
||||
}
|
||||
|
||||
function openItem(item) {
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
if (item.kind === "review") {
|
||||
reviewSheet(item.id);
|
||||
return;
|
||||
}
|
||||
const body = [
|
||||
h("div", {class: "who"}, pill(ITEM_LABELS[item.kind], KIND_TONES[item.kind]), item.agent ? face(item.agent, false) : null, item.agent ? person(item.agent) : null, when(item.ts)),
|
||||
h("p", {class: "text"}, item.title),
|
||||
item.command ? h("div", {class: "command"}, h("code", {}, item.command), copyButton(item.command)) : null,
|
||||
meta([["Verzeichnis", item.directory], ["Warnungen", item.warnings.join(", ")], ["Id", item.id]]),
|
||||
item.kind === "decision" ? h("div", {class: "options"}, item.options.map((option) => h("button", {
|
||||
type: "button", class: `option${option.label === item.recommended ? " recommended" : ""}`, disabled: item.held, on: {click: () => {
|
||||
closeSheet();
|
||||
chooseOne(item, option.label);
|
||||
}},
|
||||
}, h("strong", {}, option.label), option.description ? h("span", {}, option.description) : null))) : null,
|
||||
h("div", {class: "actions"}, h("span", {class: "spacer"}), actionsFor(item).map((node) => {
|
||||
node.addEventListener("click", closeSheet);
|
||||
return node;
|
||||
})),
|
||||
];
|
||||
openSheet(ITEM_LABELS[item.kind], body, false);
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
function helpSheet() {
|
||||
openSheet("Tastenkürzel", [h("dl", {class: "keys"}, KEYS.map(([key, text]) => [h("dt", {}, key), h("dd", {}, text)])),
|
||||
h("p", {class: "muted"}, "Leitstand: Vollbild mit großer Schrift für den zweiten Bildschirm, unter ⚙ Ambiente. j, k, x, a und Enter wirken in der Inbox.")], false);
|
||||
}
|
||||
|
||||
function overlayOpen() {
|
||||
return !document.getElementById("palette").hidden || !document.getElementById("sheet").hidden;
|
||||
}
|
||||
|
||||
function moveCursor(delta) {
|
||||
const items = visibleInbox();
|
||||
if (!items.length) {
|
||||
return;
|
||||
}
|
||||
ui.cursor = Math.min(Math.max(ui.cursor + delta, 0), items.length - 1);
|
||||
drawInbox();
|
||||
const current = inboxDom && inboxDom.querySelector(`.item[data-index="${ui.cursor}"]`);
|
||||
if (current) {
|
||||
current.scrollIntoView({block: "nearest"});
|
||||
}
|
||||
}
|
||||
|
||||
function keyboard(event) {
|
||||
const target = event.target;
|
||||
if ((event.ctrlKey || event.metaKey) && !event.altKey && event.key.toLowerCase() === "k") {
|
||||
event.preventDefault();
|
||||
if (document.getElementById("palette").hidden) {
|
||||
openPalette();
|
||||
} else {
|
||||
closePalette();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (event.key === "Escape") {
|
||||
if (!document.getElementById("palette").hidden) {
|
||||
closePalette();
|
||||
} else if (!document.getElementById("sheet").hidden) {
|
||||
closeSheet();
|
||||
} else if (space.look) {
|
||||
skyLook(false);
|
||||
} else if (ui.agent !== null) {
|
||||
closeAgent();
|
||||
} else {
|
||||
closeMenus();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (event.altKey || event.ctrlKey || event.metaKey || event.isComposing || overlayOpen()) {
|
||||
return;
|
||||
}
|
||||
if (target instanceof HTMLElement && (target.isContentEditable || ["INPUT", "TEXTAREA", "SELECT"].includes(target.tagName))) {
|
||||
return;
|
||||
}
|
||||
const inInbox = ui.screen === "inbox";
|
||||
const current = inInbox ? visibleInbox()[ui.cursor] : null;
|
||||
const index = Number(event.key) - 1;
|
||||
if (/^[1-3]$/.test(event.key)) {
|
||||
event.preventDefault();
|
||||
go(Nav.TABS[index][0], null);
|
||||
} else if (inInbox && (event.key === "j" || event.key === "k")) {
|
||||
event.preventDefault();
|
||||
moveCursor(event.key === "j" ? 1 : -1);
|
||||
} else if (inInbox && event.key === "x") {
|
||||
event.preventDefault();
|
||||
toggle(current);
|
||||
} else if (inInbox && event.key === "a") {
|
||||
event.preventDefault();
|
||||
if (current && !current.held) {
|
||||
approveOne(current);
|
||||
}
|
||||
} else if (event.key === "Enter" && current && target === document.body) {
|
||||
event.preventDefault();
|
||||
openItem(current);
|
||||
} else if (event.key === "/") {
|
||||
event.preventDefault();
|
||||
if (ui.screen !== "stream") {
|
||||
go("stream", null);
|
||||
}
|
||||
window.setTimeout(() => stream.dom && stream.dom.search.focus(), 0);
|
||||
} else if (event.key === "?") {
|
||||
event.preventDefault();
|
||||
helpSheet();
|
||||
} else if (event.key === "h") {
|
||||
event.preventDefault();
|
||||
skyLook(!space.look);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
async function load() {
|
||||
try {
|
||||
const response = await fetch(`/api/state?${windowQuery()}${wantsTrack() ? "&track=1" : ""}`, {cache: "no-store"});
|
||||
if (!response.ok) {
|
||||
throw new Error(String(response.status));
|
||||
}
|
||||
const next = await response.json();
|
||||
const previous = state.now;
|
||||
state = next;
|
||||
ui.offline = false;
|
||||
if (JSON.stringify(state.settings) !== settingsSig) {
|
||||
adoptSettings(state.settings);
|
||||
}
|
||||
tuneMusic(FADE / 1000);
|
||||
drawSky();
|
||||
announce();
|
||||
render(false);
|
||||
drawTime();
|
||||
drawDrawer();
|
||||
drawStream();
|
||||
if (motion.current.size === 0 || ui.asOf !== motion.asOf) {
|
||||
const first = motion.current.size === 0;
|
||||
motion.asOf = ui.asOf;
|
||||
relayout(first ? 0 : ui.playing ? 450 : MOVE);
|
||||
}
|
||||
pulses(state.radio.filter((row) => row.ts > previous));
|
||||
} catch {
|
||||
ui.offline = true;
|
||||
tick();
|
||||
}
|
||||
}
|
||||
|
||||
function refresh() {
|
||||
if (!ui.busy && !ui.playing && !document.hidden && String(window.getSelection()).length === 0) {
|
||||
load();
|
||||
}
|
||||
}
|
||||
|
||||
function follow() {
|
||||
if (ui.screen === "stream" && live() && !document.hidden) {
|
||||
fetchEvents();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
function context() {
|
||||
if (!audio) {
|
||||
try {
|
||||
audio = new window.AudioContext();
|
||||
} catch {
|
||||
audio = null;
|
||||
}
|
||||
}
|
||||
if (audio && audio.state === "suspended") {
|
||||
audio.resume().catch(() => null);
|
||||
}
|
||||
return audio;
|
||||
}
|
||||
|
||||
function glide(param, target, seconds) {
|
||||
const now = audio.currentTime;
|
||||
param.cancelScheduledValues(now);
|
||||
param.setValueAtTime(param.value, now);
|
||||
param.linearRampToValueAtTime(target, now + seconds);
|
||||
}
|
||||
|
||||
function impulse(sound) {
|
||||
const length = sound.sampleRate * 4;
|
||||
const buffer = sound.createBuffer(2, length, sound.sampleRate);
|
||||
for (let channel = 0; channel < 2; channel += 1) {
|
||||
const data = buffer.getChannelData(channel);
|
||||
for (let index = 0; index < length; index += 1) {
|
||||
data[index] = (Math.random() * 2 - 1) * (1 - index / length) ** 3;
|
||||
}
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
function musicLevel() {
|
||||
return settings.music.on && !radio.playing ? settings.music.volume * 0.3 * (music.ducked ? DUCK : 1) : 0;
|
||||
}
|
||||
|
||||
function note() {
|
||||
if (!music.gain) {
|
||||
return;
|
||||
}
|
||||
if (audio.state === "running") {
|
||||
const now = audio.currentTime;
|
||||
const scale = Math.random() < (music.tension ? 0.3 + 0.5 * music.tension : 0) ? TENSE : CALM;
|
||||
const frequency = BASE * 2 * scale[Math.floor(Math.random() * scale.length)] * (Math.random() < 0.3 ? 2 : 1);
|
||||
const level = audio.createGain();
|
||||
level.gain.setValueAtTime(0, now);
|
||||
level.gain.linearRampToValueAtTime(0.07, now + 2.5);
|
||||
level.gain.linearRampToValueAtTime(0, now + 8);
|
||||
level.connect(music.filter);
|
||||
for (const cents of [0, 5]) {
|
||||
const oscillator = audio.createOscillator();
|
||||
oscillator.type = "triangle";
|
||||
oscillator.frequency.value = frequency;
|
||||
oscillator.detune.value = cents;
|
||||
oscillator.connect(level);
|
||||
oscillator.start(now);
|
||||
oscillator.stop(now + 8.5);
|
||||
}
|
||||
}
|
||||
const slow = 4500 + Math.random() * 4000;
|
||||
const fast = 2400 + Math.random() * 2600;
|
||||
music.timer = window.setTimeout(note, slow + (fast - slow) * music.tension);
|
||||
}
|
||||
|
||||
function startMusic() {
|
||||
const sound = context();
|
||||
if (!sound || music.gain) {
|
||||
return;
|
||||
}
|
||||
const gain = sound.createGain();
|
||||
gain.gain.value = 0;
|
||||
gain.connect(sound.destination);
|
||||
const reverb = sound.createConvolver();
|
||||
reverb.buffer = impulse(sound);
|
||||
reverb.connect(gain);
|
||||
const filter = sound.createBiquadFilter();
|
||||
filter.type = "lowpass";
|
||||
filter.frequency.value = 700;
|
||||
filter.Q.value = 0.4;
|
||||
filter.connect(reverb);
|
||||
const dry = sound.createGain();
|
||||
dry.gain.value = 0.3;
|
||||
filter.connect(dry).connect(gain);
|
||||
music.drone = [BASE, BASE * 1.5].map((frequency) => {
|
||||
const oscillator = sound.createOscillator();
|
||||
const level = sound.createGain();
|
||||
const lfo = sound.createOscillator();
|
||||
const depth = sound.createGain();
|
||||
oscillator.frequency.value = frequency;
|
||||
level.gain.value = 0.04;
|
||||
lfo.frequency.value = 0.05 + Math.random() * 0.05;
|
||||
depth.gain.value = 0.02;
|
||||
lfo.connect(depth).connect(level.gain);
|
||||
oscillator.connect(level).connect(filter);
|
||||
oscillator.start();
|
||||
lfo.start();
|
||||
return {oscillator, lfo};
|
||||
});
|
||||
Object.assign(music, {gain, filter});
|
||||
note();
|
||||
}
|
||||
|
||||
function stopMusic() {
|
||||
if (!music.gain) {
|
||||
return;
|
||||
}
|
||||
const {gain, drone} = music;
|
||||
window.clearTimeout(music.timer);
|
||||
glide(gain.gain, 0, 2);
|
||||
music.gain = null;
|
||||
window.setTimeout(() => {
|
||||
for (const {oscillator, lfo} of drone) {
|
||||
oscillator.stop();
|
||||
lfo.stop();
|
||||
}
|
||||
gain.disconnect();
|
||||
}, 2500);
|
||||
}
|
||||
|
||||
function tuneMusic(seconds) {
|
||||
music.tension = Math.min(waitingCount() / 4, 1);
|
||||
if (music.gain) {
|
||||
glide(music.filter.frequency, 700 + 900 * music.tension, 4);
|
||||
glide(music.drone[1].oscillator.detune, 8 * music.tension, 6);
|
||||
glide(music.gain.gain, musicLevel(), seconds);
|
||||
}
|
||||
}
|
||||
|
||||
function syncMusic() {
|
||||
if (settings.music.on) {
|
||||
startMusic();
|
||||
} else {
|
||||
stopMusic();
|
||||
}
|
||||
tuneMusic(FADE / 1000);
|
||||
}
|
||||
|
||||
function musicButton() {
|
||||
const button = document.getElementById("music-toggle");
|
||||
if (!button) {
|
||||
return;
|
||||
}
|
||||
button.setAttribute("aria-pressed", String(settings.music.on));
|
||||
button.textContent = settings.music.on ? "♪ Musik an" : "♪ Musik";
|
||||
}
|
||||
|
||||
function toggleMusic() {
|
||||
context();
|
||||
saveSettings({...settings, music: {...settings.music, on: !settings.music.on}});
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
function paletteItems() {
|
||||
return [
|
||||
...Nav.TABS.flatMap(([id, label], index) => [{label: `Ansicht: ${label}`, hint: String(index + 1), run: () => go(id, null)}, ...(Nav.SUBS[id] || []).map(([sub, name]) => ({label: `Ansicht: ${label} › ${name}`, hint: Nav.hashOf(sub, null), run: () => go(sub, null)}))]),
|
||||
...["agents", "artifacts"].flatMap((screen) => Nav.VIEWS.map(([id, name]) => ({label: `${Nav.TABS.find(([tab]) => tab === screen)[1]}: ${name}`, hint: Nav.hashOf(screen, id), run: () => go(screen, id)}))),
|
||||
...Object.entries(state.views).map(([id, view]) => ({label: `Stream: ${view.label}`, hint: "Kategorie", run: () => useView(id)})),
|
||||
...userViews.map((view) => ({label: `Stream: ${view.name}`, hint: "eigene Ansicht", run: () => useSaved(view)})),
|
||||
...agentNames().map((name) => ({label: `${avatar(name)} ${name}`, hint: "Agent", run: () => openAgent(name)})),
|
||||
{label: "Funk an alle …", hint: "Newsletter, Broadcast, Pan-Pan, Security, Mayday", run: openToAll},
|
||||
...ACTIONS.map(([id, label]) => ({label, hint: id === "clear-mayday" ? "Mayday" : "Tag/Nacht", run: () => confirmAct(id)})),
|
||||
{label: "Priorität …", hint: "Reihenfolge der Agenten", run: prioritySheet},
|
||||
{label: "Regeln …", hint: "automatische Freigaben", run: () => go("rules", null)},
|
||||
{label: "Einstellungen …", hint: "Ambiente, Ort, Farben, Musik, Töne, Funk vorlesen, Radio", run: settingsSheet},
|
||||
{label: settings.music.on ? "Musik aus" : "Musik an", hint: "Ambiente", run: toggleMusic},
|
||||
{label: space.look ? "Himmel verlassen" : "Himmel ansehen", hint: "h", run: () => skyLook(!space.look)},
|
||||
{label: "Leitstand umschalten", hint: "Ambiente", run: toggleLeitstand},
|
||||
{label: "Benachrichtigungen aktivieren", hint: "Ambiente", run: askNotify},
|
||||
{label: "Tastenkürzel", hint: "?", run: helpSheet},
|
||||
];
|
||||
}
|
||||
|
||||
function drawPalette() {
|
||||
if (palette.plan) {
|
||||
return;
|
||||
}
|
||||
const raw = palette.input.value.trim();
|
||||
const q = raw.toLowerCase();
|
||||
const items = paletteItems().filter((item) => !q || item.label.toLowerCase().includes(q) || item.hint.toLowerCase().includes(q));
|
||||
if (raw) {
|
||||
items.push(state.llm
|
||||
? {label: `KI-Befehl: „${raw}“`, hint: "Tab", keep: true, run: () => askModel(raw)}
|
||||
: {label: "KI-Befehl ist aus", hint: "KVB_ORCHESTRATOR_LLM_URL und KVB_ORCHESTRATOR_LLM_MODEL in orchestrator/.env setzen", keep: true, run: () => toast("KI-Befehl ist aus", ["Setze KVB_ORCHESTRATOR_LLM_URL, KVB_ORCHESTRATOR_LLM_MODEL und KVB_ORCHESTRATOR_LLM_KEY_FILE in orchestrator/.env und installiere neu."], false)});
|
||||
}
|
||||
palette.items = items;
|
||||
palette.index = Math.min(palette.index, Math.max(items.length - 1, 0));
|
||||
palette.list.replaceChildren(...items.map((item, index) => h("li", {role: "option", "aria-selected": String(index === palette.index), on: {
|
||||
click: () => runPalette(index),
|
||||
mousemove: () => {
|
||||
if (palette.index !== index) {
|
||||
palette.index = index;
|
||||
drawPalette();
|
||||
}
|
||||
},
|
||||
}}, h("span", {}, item.label), h("span", {class: "muted"}, item.hint))));
|
||||
const current = palette.list.children[palette.index];
|
||||
if (current) {
|
||||
current.scrollIntoView({block: "nearest"});
|
||||
}
|
||||
}
|
||||
|
||||
function runPalette(index) {
|
||||
const item = palette.items[index];
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
if (!item.keep) {
|
||||
closePalette();
|
||||
}
|
||||
item.run();
|
||||
}
|
||||
|
||||
async function askModel(text) {
|
||||
palette.plan = {actions: [], rejected: [], busy: true};
|
||||
palette.list.replaceChildren(h("li", {}, h("span", {class: "muted"}, "Frage das Modell … (nur Befehl, Ids und Titel gehen hinaus)")));
|
||||
const result = await sendJson("/api/nl", {text});
|
||||
if (!palette.plan) {
|
||||
return;
|
||||
}
|
||||
if (!result.ok || !result.data) {
|
||||
palette.plan = null;
|
||||
palette.list.replaceChildren(h("li", {}, h("span", {}, `KI-Befehl fehlgeschlagen: ${result.status} ${result.text}`.trim())));
|
||||
return;
|
||||
}
|
||||
palette.plan = result.data;
|
||||
const actions = result.data.actions.map((action) => h("pre", {}, action.summary));
|
||||
const rejected = result.data.rejected.map((entry) => h("p", {class: "muted"}, `verworfen: ${entry.reason} · ${entry.action}`));
|
||||
palette.list.replaceChildren(h("li", {class: "palette-plan"},
|
||||
actions.length ? actions : h("p", {class: "muted"}, "Das Modell schlug keine gültige Aktion vor."),
|
||||
rejected,
|
||||
h("p", {class: "muted"}, actions.length ? "Enter führt genau diese Aktionen aus · Esc bricht ab" : "Esc schließt")));
|
||||
}
|
||||
|
||||
async function executePlan(plan) {
|
||||
for (const action of plan.actions) {
|
||||
const args = action.args;
|
||||
if (action.name === "approve" || action.name === "reject" || action.name === "choose") {
|
||||
await submit(args.items, action.summary.split("\n")[0]);
|
||||
} else if (action.name === "snooze" || action.name === "pin") {
|
||||
for (const key of args.keys) {
|
||||
const item = state.inbox.find((entry) => entry.kind === key.kind && entry.id === key.id);
|
||||
if (item) {
|
||||
await mark(item, action.name === "snooze" ? nowSeconds() + args.hours * 3600 : item.until, action.name === "pin" ? true : item.pinned);
|
||||
}
|
||||
}
|
||||
} else if (action.name === "view") {
|
||||
useView(args.name);
|
||||
} else if (action.name === "open") {
|
||||
go(args.view, null);
|
||||
} else if (action.name === "message") {
|
||||
await message(args.to, args.text, "", "post");
|
||||
} else if (action.name === "filter") {
|
||||
filter.q = args.q;
|
||||
if (ui.screen === "stream" && stream.dom) {
|
||||
stream.dom.search.value = args.q;
|
||||
refilter();
|
||||
} else {
|
||||
go("stream", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function openPalette() {
|
||||
const box = document.getElementById("palette");
|
||||
palette.input = h("input", {type: "text", placeholder: "Ansicht, Agent, Aktion – oder ein Befehl in Worten …", "aria-label": "Befehl", role: "combobox", "aria-expanded": "true"});
|
||||
palette.list = h("ul", {class: "palette-list", role: "listbox"});
|
||||
palette.index = 0;
|
||||
palette.plan = null;
|
||||
palette.input.addEventListener("input", () => {
|
||||
palette.index = 0;
|
||||
palette.plan = null;
|
||||
drawPalette();
|
||||
});
|
||||
palette.input.addEventListener("keydown", (event) => {
|
||||
if (palette.plan && event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
const plan = palette.plan;
|
||||
if (!plan.busy && plan.actions.length) {
|
||||
closePalette();
|
||||
executePlan(plan);
|
||||
}
|
||||
} else if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
||||
event.preventDefault();
|
||||
const size = Math.max(palette.items.length, 1);
|
||||
palette.index = (palette.index + (event.key === "ArrowDown" ? 1 : size - 1)) % size;
|
||||
drawPalette();
|
||||
} else if (event.key === "Tab" && palette.input.value.trim() && !palette.plan) {
|
||||
event.preventDefault();
|
||||
palette.index = palette.items.length - 1;
|
||||
runPalette(palette.index);
|
||||
} else if (event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
runPalette(palette.index);
|
||||
}
|
||||
});
|
||||
box.replaceChildren(h("div", {class: "palette-box", role: "dialog", "aria-label": "Befehle"}, h("div", {class: "palette-row"}, palette.input, micButton(palette.input)), palette.list));
|
||||
box.hidden = false;
|
||||
drawPalette();
|
||||
palette.input.focus();
|
||||
}
|
||||
|
||||
function closePalette() {
|
||||
document.getElementById("palette").hidden = true;
|
||||
palette.plan = null;
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
const RP_ID = "localhost";
|
||||
const ALGORITHMS = [-7, -8, -257];
|
||||
const onLocalhost = () => window.location.hostname === RP_ID;
|
||||
const localUrl = () => `http://${RP_ID}:${window.location.port}${window.location.pathname}${window.location.hash}`;
|
||||
const b64url = (buffer) => btoa(String.fromCharCode(...new Uint8Array(buffer))).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
||||
const unb64url = (text) => Uint8Array.from(atob(text.replace(/-/g, "+").replace(/_/g, "/").padEnd(Math.ceil(text.length / 4) * 4, "=")), (char) => char.charCodeAt(0));
|
||||
const localLink = () => h("a", {href: localUrl()}, localUrl());
|
||||
const KEEPASSXC_LOCALHOST = "KeePassXC lehnt Passkeys auf http://localhost ab, bis in KeePassXC unter Werkzeuge → Einstellungen → Browser-Integration → Fortgeschritten „Nutzung von localhost mit Passkeys zulassen“ (Allow using localhost with passkeys) angehakt ist; die Datenbank muss entsperrt sein. Sonst meldet KeePassXC-Browser „Passkeys request canceled.“ und Chrome öffnet seinen eigenen Passkey-Dialog.";
|
||||
|
||||
async function assertion(prepared, label) {
|
||||
if (!onLocalhost()) {
|
||||
toast(`${label}: nicht signiert`, [`Der Passkey signiert nur unter ${localUrl()}`], false);
|
||||
return null;
|
||||
}
|
||||
if (!prepared.credentials.length) {
|
||||
toast(`${label}: nicht signiert`, ["Kein Passkey gepinnt: Einstellungen → Passkey registrieren"], false);
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
const credential = await navigator.credentials.get({publicKey: {
|
||||
challenge: unb64url(prepared.challenge),
|
||||
rpId: RP_ID,
|
||||
allowCredentials: prepared.credentials.map((id) => ({type: "public-key", id: unb64url(id)})),
|
||||
userVerification: "preferred",
|
||||
timeout: 120000,
|
||||
}});
|
||||
const answer = credential.response;
|
||||
return {id: b64url(credential.rawId), clientDataJSON: b64url(answer.clientDataJSON), authenticatorData: b64url(answer.authenticatorData), signature: b64url(answer.signature)};
|
||||
} catch (error) {
|
||||
toast(`${label}: nicht signiert`, [`${(error && error.name) || error}: KeePassXC gesperrt oder abgebrochen; nichts wurde gesendet.`], false);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function proofFor(entries, label) {
|
||||
const result = await sendJson("/api/sign", {items: entries});
|
||||
if (!result.ok || !result.data) {
|
||||
toast(`${label}: nicht möglich`, fail(result), false);
|
||||
return null;
|
||||
}
|
||||
if (result.data.payload === null) {
|
||||
return {proof: null};
|
||||
}
|
||||
const signed = await assertion(result.data, label);
|
||||
return signed ? {proof: {payload: result.data.payload, assertion: signed}} : null;
|
||||
}
|
||||
|
||||
async function registerPasskey(output) {
|
||||
if (!onLocalhost()) {
|
||||
output.replaceChildren(h("p", {class: "muted"}, "nicht registriert: WebAuthn braucht die Domain ", localLink()));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const credential = await navigator.credentials.create({publicKey: {
|
||||
rp: {id: RP_ID, name: "Agent Orchestrator"},
|
||||
user: {id: crypto.getRandomValues(new Uint8Array(16)), name: "operator", displayName: "Agent Orchestrator Operator"},
|
||||
challenge: crypto.getRandomValues(new Uint8Array(32)),
|
||||
pubKeyCredParams: ALGORITHMS.map((alg) => ({type: "public-key", alg})),
|
||||
attestation: "none",
|
||||
authenticatorSelection: {residentKey: "preferred", userVerification: "preferred"},
|
||||
timeout: 120000,
|
||||
}});
|
||||
const answer = credential.response;
|
||||
const blob = b64url(new TextEncoder().encode(JSON.stringify({id: b64url(credential.rawId), attestationObject: b64url(answer.attestationObject), clientDataJSON: b64url(answer.clientDataJSON)})));
|
||||
const command = `python3 ~/.local/share/kvb-orchestrator/client/approval.py pin --port ${window.location.port} --approvers ~/.config/kvb-orchestrator/approvers.json --credential '${blob}'`;
|
||||
output.replaceChildren(
|
||||
h("p", {class: "muted"}, "Diesen Befehl im Terminal des Hosts ausführen, außerhalb jeder Sandbox; erst dann gilt der Passkey. Der Hub pinnt nie selbst."),
|
||||
h("div", {class: "command"}, h("code", {}, command), copyButton(command)),
|
||||
h("label", {}, "Credential", h("textarea", {class: "field", readonly: true, rows: 3}, blob)));
|
||||
} catch (error) {
|
||||
output.replaceChildren(h("p", {class: "muted"}, `nicht registriert: ${(error && error.name) || error}`), h("p", {class: "muted"}, KEEPASSXC_LOCALHOST));
|
||||
}
|
||||
}
|
||||
|
||||
function passkeySection() {
|
||||
const output = h("div", {class: "mini", "aria-live": "polite"});
|
||||
const keys = state.approvers.length
|
||||
? h("ul", {class: "mini"}, state.approvers.map((key) => h("li", {}, pill(key.alg, "ok"), " ", h("code", {title: key.id}, `${key.id.slice(0, 16)}…`))))
|
||||
: h("p", {class: "muted"}, "Kein Passkey gepinnt: Runner, Hook und Commit-Skills verweigern jede Freigabe.");
|
||||
return h("section", {}, h("h3", {}, "Passkey"),
|
||||
h("p", {class: "muted"}, "Freigaben von Asks, Reviews und Operator-Befehlen signiert ein Passkey in KeePassXC; Runner, Hook und Commit-Skills prüfen die Signatur selbst gegen die gepinnten Schlüssel."),
|
||||
keys,
|
||||
h("p", {class: "muted"}, KEEPASSXC_LOCALHOST),
|
||||
onLocalhost() ? null : h("p", {class: "muted"}, "WebAuthn braucht die Domain: ", localLink()),
|
||||
h("div", {}, btn("Passkey registrieren", "btn small soft", () => registerPasskey(output))),
|
||||
output);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
function animate(duration, frame, done) {
|
||||
const began = performance.now();
|
||||
const run = (now) => {
|
||||
const progress = Math.min((now - began) / duration, 1);
|
||||
frame(progress);
|
||||
if (progress < 1) {
|
||||
window.requestAnimationFrame(run);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
};
|
||||
window.requestAnimationFrame(run);
|
||||
}
|
||||
|
||||
function travel(layer, row, target) {
|
||||
const from = positions.get(row.source);
|
||||
const shade = tone(row.class);
|
||||
if (!layer.isConnected || !from) {
|
||||
return;
|
||||
}
|
||||
if (target === "*") {
|
||||
const ring = s("circle", {class: `pulse-ring t-${shade}`, cx: fixed(from.x), cy: fixed(from.y), r: 18});
|
||||
layer.append(ring);
|
||||
animate(1400, (t) => {
|
||||
ring.setAttribute("r", fixed(18 + 54 * t));
|
||||
ring.setAttribute("opacity", fixed(1 - t));
|
||||
}, () => ring.remove());
|
||||
return;
|
||||
}
|
||||
const to = positions.get(target);
|
||||
if (!to) {
|
||||
return;
|
||||
}
|
||||
const control = Space.bend(from, to);
|
||||
const dot = s("circle", {class: `pulse t-${shade}`, r: 5});
|
||||
layer.append(dot);
|
||||
animate(1200, (t) => {
|
||||
const u = 1 - t;
|
||||
dot.setAttribute("cx", fixed(u * u * from.x + 2 * u * t * control.x + t * t * to.x));
|
||||
dot.setAttribute("cy", fixed(u * u * from.y + 2 * u * t * control.y + t * t * to.y));
|
||||
}, () => dot.remove());
|
||||
}
|
||||
|
||||
function pulses(rows) {
|
||||
if (calm.matches || ui.screen !== "agents" || ui.views.agents !== "orbit" || !live() || !graphDom || !graphDom.pulses) {
|
||||
return;
|
||||
}
|
||||
const layer = graphDom.pulses;
|
||||
rows.slice(-24).forEach((row, index) => {
|
||||
for (const target of row.targets.length ? row.targets : ["*"]) {
|
||||
window.setTimeout(() => travel(layer, row, target), index * 260);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
function radioVolume() {
|
||||
if (radio.element) {
|
||||
radio.element.volume = Math.min(Math.max(radio.level * settings.music.volume * (music.ducked ? DUCK : 1), 0), 1);
|
||||
}
|
||||
}
|
||||
|
||||
function fadeRadio(target, done) {
|
||||
window.clearInterval(radio.timer);
|
||||
if (radio.level === target) {
|
||||
done();
|
||||
return;
|
||||
}
|
||||
const from = radio.level;
|
||||
const began = performance.now();
|
||||
radio.timer = window.setInterval(() => {
|
||||
const progress = Math.min((performance.now() - began) / FADE, 1);
|
||||
radio.level = from + (target - from) * progress;
|
||||
radioVolume();
|
||||
if (progress >= 1) {
|
||||
window.clearInterval(radio.timer);
|
||||
done();
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
|
||||
function stopStream() {
|
||||
radio.element.pause();
|
||||
radio.element.removeAttribute("src");
|
||||
radio.element.load();
|
||||
radio.playing = false;
|
||||
tuneMusic(FADE / 1000);
|
||||
}
|
||||
|
||||
function syncRadio() {
|
||||
const due = Ambience.activeStream(settings.streams, Ambience.slotOf(new Date()));
|
||||
const url = due ? due.url : "";
|
||||
if (url === radio.url && !radio.waiting) {
|
||||
return;
|
||||
}
|
||||
const origin = url ? new URL(url).origin : "";
|
||||
if (origin && !pageMedia.has(origin)) {
|
||||
if (state.media.includes(origin)) {
|
||||
window.location.reload();
|
||||
}
|
||||
return;
|
||||
}
|
||||
radio.url = url;
|
||||
radio.waiting = false;
|
||||
fadeRadio(0, () => {
|
||||
if (radio.url !== url) {
|
||||
return;
|
||||
}
|
||||
if (!url) {
|
||||
stopStream();
|
||||
return;
|
||||
}
|
||||
radio.element.src = url;
|
||||
radio.element.play().then(() => {
|
||||
radio.playing = true;
|
||||
tuneMusic(FADE / 1000);
|
||||
fadeRadio(1, () => null);
|
||||
}).catch(() => {
|
||||
radio.waiting = true;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function duck(seconds) {
|
||||
music.ducked += 1;
|
||||
tuneMusic(0.15);
|
||||
radioVolume();
|
||||
window.setTimeout(() => {
|
||||
music.ducked -= 1;
|
||||
tuneMusic(1.5);
|
||||
radioVolume();
|
||||
}, (seconds + 0.6) * 1000);
|
||||
}
|
||||
|
||||
function unlock() {
|
||||
if (settings.music.on) {
|
||||
context();
|
||||
}
|
||||
if (radio.waiting) {
|
||||
syncRadio();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
function fileList(id) {
|
||||
if (!files.has(id)) {
|
||||
files.set(id, "loading");
|
||||
fetch(`/reviews/${encodeURIComponent(id)}/files`, {cache: "no-store"})
|
||||
.then((response) => (response.ok ? response.json() : {files: null}))
|
||||
.then((data) => files.set(id, Array.isArray(data.files) ? data.files : null))
|
||||
.catch(() => files.set(id, null))
|
||||
.then(() => {
|
||||
if (ui.review === id) {
|
||||
drawReviewSheet();
|
||||
}
|
||||
});
|
||||
}
|
||||
return files.get(id);
|
||||
}
|
||||
|
||||
function reviewOf(id) {
|
||||
const pending = state.reviews.find((review) => review.id === id);
|
||||
if (pending) {
|
||||
return pending;
|
||||
}
|
||||
const entry = stream.events.find((row) => row.kind === "review" && row.ref.id === id);
|
||||
return entry ? {id, title: entry.title, notes: entry.text, created_ts: entry.ts, worktree: entry.ref.worktree, branch: entry.ref.branch, tree: entry.ref.tree, gate: entry.ref.gate, score: entry.ref.score, status: entry.ref.status} : null;
|
||||
}
|
||||
|
||||
function reviewSheet(id) {
|
||||
ui.review = id;
|
||||
ui.file = 0;
|
||||
drawReviewSheet();
|
||||
}
|
||||
|
||||
function drawReviewSheet() {
|
||||
const review = reviewOf(ui.review);
|
||||
if (!review) {
|
||||
closeSheet();
|
||||
toast("Review nicht mehr im Zeitraum", [], false);
|
||||
return;
|
||||
}
|
||||
const item = state.inbox.find((entry) => entry.kind === "review" && entry.id === review.id);
|
||||
const list = fileList(review.id);
|
||||
const treeNav = h("nav", {class: "card tree", "aria-label": "Geänderte Dateien"}, treePane(list));
|
||||
const diff = h("section", {class: "card diff-pane", "aria-label": "Diff"}, diffPane(list));
|
||||
const id = ui.review;
|
||||
const head = h("article", {class: "card"},
|
||||
h("div", {class: "card-head"}, h("div", {}, h("p", {class: "muted"}, "eingereicht ", when(review.created_ts))), h("div", {class: "who"}, status(review.status || "pending"), review.gate ? pill(review.gate === "pass" ? "Gate grün" : "Gate rot", review.gate === "pass" ? "ok" : "bad") : null)),
|
||||
meta([["Repo", review.worktree], ["Branch", review.branch], ["Tree", (review.tree || "").slice(0, 12), review.tree], ["Score", review.score]]),
|
||||
review.notes ? h("pre", {class: "notes"}, review.notes) : null,
|
||||
h("div", {class: "actions"},
|
||||
h("a", {class: "btn ghost", href: `/reviews/${encodeURIComponent(review.id)}/page`, target: "_blank", rel: "noopener noreferrer"}, "Vollständige Seite öffnen ↗"),
|
||||
h("span", {class: "spacer"}),
|
||||
item ? actionsFor(item).map((node) => {
|
||||
node.addEventListener("click", closeSheet);
|
||||
return node;
|
||||
}) : null));
|
||||
openSheet(review.title, [head, h("div", {class: "split"}, treeNav, diff)], true);
|
||||
ui.review = id;
|
||||
reviewDom = {tree: treeNav, diff};
|
||||
}
|
||||
|
||||
function nest(entries) {
|
||||
const root = {dirs: new Map(), files: []};
|
||||
for (const [file, index] of entries) {
|
||||
const parts = file.path.split("/");
|
||||
let node = root;
|
||||
for (const part of parts.slice(0, -1)) {
|
||||
if (!node.dirs.has(part)) {
|
||||
node.dirs.set(part, {dirs: new Map(), files: []});
|
||||
}
|
||||
node = node.dirs.get(part);
|
||||
}
|
||||
node.files.push([file, index, parts[parts.length - 1]]);
|
||||
}
|
||||
return root;
|
||||
}
|
||||
|
||||
function stat(file) {
|
||||
return h("span", {class: "stat"}, h("span", {class: "add"}, `+${file.added}`), h("span", {class: "del"}, `-${file.removed}`));
|
||||
}
|
||||
|
||||
function pick(index, list) {
|
||||
ui.file = index;
|
||||
for (const entry of reviewDom.tree.querySelectorAll(".file-entry")) {
|
||||
if (Number(entry.dataset.index) === index) {
|
||||
entry.setAttribute("aria-current", "true");
|
||||
} else {
|
||||
entry.removeAttribute("aria-current");
|
||||
}
|
||||
}
|
||||
reviewDom.diff.replaceChildren(diffPane(list));
|
||||
}
|
||||
|
||||
function branch(node, list) {
|
||||
const items = [];
|
||||
for (const [name, child] of [...node.dirs].sort(([a], [b]) => a.localeCompare(b))) {
|
||||
let label = name;
|
||||
let inner = child;
|
||||
while (!inner.files.length && inner.dirs.size === 1) {
|
||||
const [[next, deeper]] = inner.dirs;
|
||||
label = `${label}/${next}`;
|
||||
inner = deeper;
|
||||
}
|
||||
items.push(h("li", {}, h("details", {open: true}, h("summary", {}, h("span", {class: "dir"}, `${label}/`)), branch(inner, list))));
|
||||
}
|
||||
for (const [file, index, name] of node.files.sort((a, b) => a[2].localeCompare(b[2]))) {
|
||||
const [letter, tone] = FILE_STATUS[file.status] || ["?", "neutral"];
|
||||
items.push(h("li", {}, h("button", {
|
||||
type: "button", class: "file-entry", "data-index": index, "aria-current": index === ui.file ? "true" : null,
|
||||
title: file.old ? `${file.old} → ${file.path}` : file.path, on: {click: () => pick(index, list)},
|
||||
}, h("span", {class: "letter", "data-tone": tone}, letter), h("span", {class: "name"}, name), stat(file))));
|
||||
}
|
||||
return h("ul", {class: "tree-list"}, items);
|
||||
}
|
||||
|
||||
function treePane(list) {
|
||||
if (list === "loading") {
|
||||
return h("p", {class: "muted pad"}, "Lade Dateiliste …");
|
||||
}
|
||||
if (!Array.isArray(list) || !list.length) {
|
||||
return h("p", {class: "muted pad"}, "Keine Dateiliste. Die vollständige Seite zeigt alle Änderungen.");
|
||||
}
|
||||
const sections = [...new Set(list.map((file) => file.section))];
|
||||
return h("div", {}, sections.map((section) => h("div", {class: "tree-section"},
|
||||
sections.length > 1 ? h("h3", {class: "tree-title"}, SECTIONS[section] || section || "Dateien") : null,
|
||||
branch(nest(list.map((file, index) => [file, index]).filter(([file]) => file.section === section)), list))));
|
||||
}
|
||||
|
||||
function diffRow(line) {
|
||||
if (line.kind === "hunk" || line.kind === "more") {
|
||||
return h("tr", {class: line.kind}, h("td", {colspan: 3}), h("td", {class: "code"}, line.text));
|
||||
}
|
||||
return h("tr", {class: line.kind}, h("td", {class: "num"}, line.old), h("td", {class: "num"}, line.new), h("td", {class: "sign"}, SIGNS[line.kind] || " "), h("td", {class: "code"}, line.text));
|
||||
}
|
||||
|
||||
function diffPane(list) {
|
||||
if (!Array.isArray(list) || !list.length) {
|
||||
return h("p", {class: "muted pad"}, list === "loading" ? "Lade Änderungen …" : "Kein Diff verfügbar.");
|
||||
}
|
||||
const file = list[Math.min(ui.file, list.length - 1)];
|
||||
const [letter, tone] = FILE_STATUS[file.status] || ["?", "neutral"];
|
||||
return h("div", {},
|
||||
h("div", {class: "diff-head"},
|
||||
h("span", {class: "letter", "data-tone": tone}, letter),
|
||||
h("code", {class: "path"}, file.old ? `${file.old} → ${file.path}` : file.path),
|
||||
file.tags.map((tag) => pill(tag, "neutral")),
|
||||
h("span", {class: "spacer"}),
|
||||
stat(file)),
|
||||
file.detail ? h("p", {class: "muted pad"}, file.detail) : null,
|
||||
file.lines.length ? h("div", {class: "diff-scroll"}, h("table", {class: "diff"}, h("tbody", {}, file.lines.map(diffRow)))) : null);
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
function rulesScreen() {
|
||||
const kind = h("select", {class: "field", "aria-label": "Art"}, h("option", {value: "ask"}, "Ask: Werkzeug + Befehlsmuster"), h("option", {value: "review"}, "Review: Branch-Muster + Gate grün"), h("option", {value: "decision"}, "Entscheidung: Empfehlung nehmen"));
|
||||
const tool = h("input", {class: "field", type: "text", placeholder: "Bash", value: "Bash"});
|
||||
const pattern = h("input", {class: "field", type: "text", placeholder: "make test*"});
|
||||
const scope = h("input", {class: "field", type: "text", value: "*", placeholder: "/home/…/Repositories/*"});
|
||||
const expiry = new Date(Date.now() + 7 * DAY * 1000);
|
||||
const expires = h("input", {class: "field", type: "date", value: localInput(expiry.getTime() / 1000).slice(0, 10), required: true});
|
||||
const enabled = h("input", {type: "checkbox", checked: true});
|
||||
const toolField = h("label", {}, "Werkzeug (Glob)", tool);
|
||||
const scopeField = h("label", {}, "Verzeichnis (Glob)", scope);
|
||||
const hint = h("p", {class: "muted"});
|
||||
const sync = () => {
|
||||
toolField.hidden = kind.value !== "ask";
|
||||
scopeField.hidden = kind.value === "decision";
|
||||
pattern.placeholder = {ask: "make test*", review: "feature/*", decision: "* (Agent-Muster)"}[kind.value];
|
||||
hint.textContent = {
|
||||
ask: "Gibt passende Asks in passenden Verzeichnissen frei, nie einen Befehl mit Warnung (rm -r, push, --force, sudo, Pipe in eine Shell …). Der Passkey signiert die Regel einmal; der Hook prüft Signatur und Muster selbst.",
|
||||
review: "Gibt Reviews passender Branches und Worktrees frei, nur wenn ihr Gate grün ist. Der Passkey signiert die Regel einmal; der Commit-Skill prüft Signatur und Muster selbst.",
|
||||
decision: "Nimmt bei Entscheidungen passender Agenten die empfohlene Option; Entscheidungen bleiben unsigniert.",
|
||||
}[kind.value];
|
||||
};
|
||||
kind.addEventListener("change", sync);
|
||||
sync();
|
||||
const form = h("form", {class: "rule-form"}, h("label", {}, "Art", kind), toolField, h("label", {}, "Muster (Glob)", pattern), scopeField, h("label", {}, "Läuft ab am", expires), h("label", {class: "check"}, enabled, "aktiv"), h("button", {type: "submit", class: "btn primary"}, "Regel anlegen"));
|
||||
form.addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
const end = Date.parse(`${expires.value}T23:59:59`) / 1000;
|
||||
const fields = {
|
||||
kind: kind.value,
|
||||
tool: kind.value === "ask" ? tool.value.trim() : "",
|
||||
pattern: pattern.value.trim() || (kind.value === "decision" ? "*" : ""),
|
||||
scope: kind.value === "decision" ? "*" : scope.value.trim(),
|
||||
expires: Number.isFinite(end) ? end : 0,
|
||||
};
|
||||
const prepared = await sendJson("/api/rules/sign", fields);
|
||||
if (!prepared.ok || !prepared.data) {
|
||||
toast("Regel nicht angelegt", fail(prepared), false);
|
||||
return;
|
||||
}
|
||||
const signed = prepared.data.sign ? await assertion(prepared.data, "Regel") : null;
|
||||
if (prepared.data.sign && !signed) {
|
||||
return;
|
||||
}
|
||||
const result = await sendJson("/api/rules", {rule: prepared.data.payload, assertion: signed, enabled: enabled.checked});
|
||||
toast(result.ok ? "Regel angelegt" : "Regel nicht angelegt", result.ok ? [] : fail(result), result.ok);
|
||||
await load();
|
||||
});
|
||||
const change = async (rule, verb) => {
|
||||
const result = await send(`/api/rules/${encodeURIComponent(rule.id)}/${verb}`, "", "application/json");
|
||||
if (!result.ok) {
|
||||
toast("Regel nicht geändert", [`${result.status} ${result.text}`.trim()], false);
|
||||
}
|
||||
await load();
|
||||
};
|
||||
const now = nowSeconds();
|
||||
const list = state.rules.length ? h("div", {class: "mini"}, state.rules.map((rule) => h("div", {class: "rule-row"},
|
||||
pill(rule.kind, KIND_TONES[rule.kind]),
|
||||
rule.tool ? h("code", {}, rule.tool) : null,
|
||||
h("code", {}, rule.pattern),
|
||||
rule.kind === "decision" ? null : h("code", {title: "Verzeichnis"}, rule.scope || "–"),
|
||||
rule.kind === "decision" ? null : pill(rule.signed ? "signiert" : "unsigniert: wirkt nicht", rule.signed ? "ok" : "bad"),
|
||||
rule.expires <= now ? pill("abgelaufen", "bad") : h("span", {class: "muted"}, `bis ${absolute.format(stampOf(rule.expires))}`),
|
||||
rule.enabled ? pill("aktiv", "ok") : pill("aus", "neutral"),
|
||||
h("span", {class: "spacer"}),
|
||||
btn(rule.enabled ? "Ausschalten" : "Einschalten", "btn small", () => change(rule, rule.enabled ? "disable" : "enable")),
|
||||
btn("Löschen", "btn small danger", () => {
|
||||
if (window.confirm("Regel löschen?")) {
|
||||
change(rule, "delete");
|
||||
}
|
||||
})))) : h("p", {class: "muted"}, "Noch keine Regel. Jede automatische Freigabe erscheint im Stream und lässt sich 3 s lang rückgängig machen.");
|
||||
return h("div", {class: "stack"}, h("h2", {class: "title"}, "Regeln für automatische Freigaben"), list, h("div", {class: "card"}, hint, form));
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
const navButtons = new Map();
|
||||
|
||||
function tabButton(id, label, hint) {
|
||||
const badge = Object.hasOwn(state.badges, id) ? h("span", {class: "badge", hidden: true}) : null;
|
||||
const button = h("button", {type: "button", id: `tab-${id}`, "aria-controls": "main", title: hint ? `${label} (${hint})` : label, on: {click: () => go(id, null)}}, label, badge);
|
||||
navButtons.set(id, {button, badge});
|
||||
return button;
|
||||
}
|
||||
|
||||
document.getElementById("tabs").append(...Nav.TABS.map(([id, label], index) => h("div", {class: "tab-group"},
|
||||
tabButton(id, label, `Taste ${index + 1}`),
|
||||
Nav.SUBS[id] ? h("div", {class: "subtabs"}, Nav.SUBS[id].map(([sub, name]) => tabButton(sub, name, ""))) : null)));
|
||||
|
||||
function measure() {
|
||||
document.documentElement.style.setProperty("--head", `${document.getElementById("head").offsetHeight}px`);
|
||||
}
|
||||
|
||||
function go(screen, view) {
|
||||
const hash = Nav.hashOf(screen, view || ui.views[screen] || null);
|
||||
if (window.location.hash === hash) {
|
||||
apply();
|
||||
} else {
|
||||
window.location.hash = hash;
|
||||
}
|
||||
}
|
||||
|
||||
function apply() {
|
||||
const route = Nav.route(window.location.hash);
|
||||
if (route.redirect) {
|
||||
window.history.replaceState(null, "", route.redirect);
|
||||
}
|
||||
ui.screen = route.screen;
|
||||
if (route.view) {
|
||||
ui.views[route.screen] = route.view;
|
||||
}
|
||||
if (document.startViewTransition && drawn.screen && !calm.matches) {
|
||||
document.startViewTransition(() => render(true));
|
||||
} else {
|
||||
render(true);
|
||||
}
|
||||
}
|
||||
|
||||
function signature() {
|
||||
if (ui.screen === "agents") {
|
||||
return JSON.stringify([ui.views.agents, depth()]);
|
||||
}
|
||||
return JSON.stringify(ui.screen === "artifacts" ? [ui.views.artifacts] : ui.screen === "rules" ? state.rules : []);
|
||||
}
|
||||
|
||||
function screenOf() {
|
||||
return {stream: streamScreen, inbox: inboxScreen, rules: rulesScreen, agents: agentsScreen, artifacts: artifactsScreen}[ui.screen]();
|
||||
}
|
||||
|
||||
function render(force) {
|
||||
if (ui.node !== null && !state.graph.nodes.some((node) => node.id === ui.node)) {
|
||||
ui.node = null;
|
||||
}
|
||||
for (const [id, {button}] of navButtons) {
|
||||
button.setAttribute("aria-current", ui.screen === id ? "page" : "false");
|
||||
}
|
||||
const sig = signature();
|
||||
if (force || drawn.screen !== ui.screen || drawn.sig !== sig) {
|
||||
graphDom = null;
|
||||
stream.dom = null;
|
||||
tree.dom = null;
|
||||
inboxDom = null;
|
||||
inboxSig = "";
|
||||
const main = document.getElementById("main");
|
||||
main.setAttribute("aria-labelledby", `tab-${ui.screen}`);
|
||||
main.replaceChildren(screenOf());
|
||||
drawn.screen = ui.screen;
|
||||
drawn.sig = sig;
|
||||
}
|
||||
stage();
|
||||
drawSide();
|
||||
drawToolbar();
|
||||
drawInbox();
|
||||
drawStatus();
|
||||
tick();
|
||||
}
|
||||
|
||||
function drawStatus() {
|
||||
for (const [id, count] of Object.entries(state.badges)) {
|
||||
const {badge} = navButtons.get(id);
|
||||
badge.textContent = String(count);
|
||||
badge.hidden = count === 0;
|
||||
badge.className = `badge${id === "inbox" && count ? " urgent" : ""}`;
|
||||
}
|
||||
const banner = document.getElementById("mayday");
|
||||
const silence = state.silence;
|
||||
banner.hidden = !silence;
|
||||
banner.replaceChildren(...(silence ? [h("p", {class: "text"}, `MAYDAY · ${dash(silence.by)}: ${silence.text}`), btn("aufheben", "btn small", () => confirmAct("clear-mayday"))] : []));
|
||||
document.title = `${state.badges.inbox ? `(${state.badges.inbox}) ` : ""}Agent Orchestrator`;
|
||||
window.setTimeout(measure, 0);
|
||||
}
|
||||
|
||||
function toggleLeitstand() {
|
||||
const on = !document.body.classList.contains("leitstand");
|
||||
document.body.classList.toggle("leitstand", on);
|
||||
if (on && document.documentElement.requestFullscreen && !document.fullscreenElement) {
|
||||
document.documentElement.requestFullscreen().catch(() => null);
|
||||
}
|
||||
if (!on && document.fullscreenElement) {
|
||||
document.exitFullscreen().catch(() => null);
|
||||
}
|
||||
window.setTimeout(measure, 50);
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
function adoptSettings(next) {
|
||||
settings = next;
|
||||
settingsSig = JSON.stringify(next);
|
||||
if (space.edits === space.saved) {
|
||||
space.views = {graph: {...next.space.graph}, sky: {...next.space.sky}};
|
||||
space.glides = {graph: null, sky: null};
|
||||
requestSpace();
|
||||
}
|
||||
sky.mode = "";
|
||||
drawSky();
|
||||
syncMusic();
|
||||
syncRadio();
|
||||
musicButton();
|
||||
}
|
||||
|
||||
async function saveSettings(next) {
|
||||
const result = await sendJson("/api/settings", next);
|
||||
if (!result.ok || !result.data) {
|
||||
toast("Einstellungen nicht gespeichert", [`${result.status} ${result.text}`.trim()], false);
|
||||
return false;
|
||||
}
|
||||
const fresh = result.data.streams.map((stream) => new URL(stream.url).origin).filter((origin) => !pageMedia.has(origin));
|
||||
adoptSettings(result.data);
|
||||
if (fresh.length) {
|
||||
toast("Neuer Sender", ["Die Seite lädt neu, damit der Browser ihn abspielen darf."], true);
|
||||
window.setTimeout(() => window.location.reload(), 1500);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function streamRow(stream, rows, list) {
|
||||
const field = (attrs) => h("input", {class: "field", required: true, ...attrs});
|
||||
const name = field({type: "text", value: stream.name, placeholder: "Sendername", maxlength: 120});
|
||||
const url = field({type: "url", value: stream.url, placeholder: "https://…"});
|
||||
const from = field({type: "time", value: stream.from});
|
||||
const to = field({type: "time", value: stream.to === "24:00" ? "00:00" : stream.to});
|
||||
const on = h("input", {type: "checkbox", checked: stream.on});
|
||||
const days = WEEKDAYS.map((label, index) => h("input", {type: "checkbox", checked: stream.days.includes(index), "aria-label": label}));
|
||||
const entry = {read: () => ({
|
||||
name: name.value.trim(),
|
||||
url: url.value.trim(),
|
||||
from: from.value,
|
||||
to: to.value === "00:00" && stream.to === "24:00" ? "24:00" : to.value,
|
||||
days: days.flatMap((box, index) => (box.checked ? [index] : [])),
|
||||
on: on.checked,
|
||||
})};
|
||||
entry.row = h("div", {class: "stream-row"},
|
||||
h("div", {class: "grid"}, h("label", {}, "Name", name), h("label", {}, "Stream-URL", url), h("label", {}, "von", from), h("label", {}, "bis", to)),
|
||||
h("div", {class: "days"}, days.map((box, index) => h("label", {class: "check"}, box, WEEKDAYS[index])), h("label", {class: "check"}, on, "aktiv"), h("span", {class: "spacer"}),
|
||||
btn("Entfernen", "btn small danger", () => {
|
||||
rows.splice(rows.indexOf(entry), 1);
|
||||
entry.row.remove();
|
||||
})));
|
||||
rows.push(entry);
|
||||
list.append(entry.row);
|
||||
}
|
||||
|
||||
function ambience() {
|
||||
const tool = (id, label, title, run) => h("button", {type: "button", id, class: "btn small", title, on: {click: run}}, label);
|
||||
const section = h("section", {}, h("h3", {}, "Ambiente"), h("div", {class: "toolbar"},
|
||||
tool("sky-look", "🔭 Himmel", "Himmel ansehen: ziehen dreht den Blick (Taste h)", () => {
|
||||
closeSheet();
|
||||
skyLook(true);
|
||||
}),
|
||||
tool("music-toggle", "♪ Musik", "Generative Musik an oder aus", toggleMusic),
|
||||
tool("leitstand", "Leitstand", "Leitstand: Vollbild mit großer Schrift", toggleLeitstand),
|
||||
tool("notify", "Benachrichtigungen", "Desktop-Benachrichtigungen des Browsers erlauben", askNotify)));
|
||||
window.setTimeout(() => {
|
||||
musicButton();
|
||||
notifyLabel();
|
||||
}, 0);
|
||||
return section;
|
||||
}
|
||||
|
||||
function settingsSheet() {
|
||||
const number = (value, min, max, label) => h("input", {class: "field", type: "number", min, max, step: "any", value, required: true, "aria-label": label});
|
||||
const latitude = number(settings.latitude, -90, 90, "Breite");
|
||||
const longitude = number(settings.longitude, -180, 180, "Länge");
|
||||
const theme = h("select", {class: "field"}, THEME_CHOICES.map(([id, label]) => h("option", {value: id, selected: settings.theme === id}, label)));
|
||||
const colors = Object.fromEntries(COLOR_FIELDS.map(([id]) => [id, h("input", {type: "color", value: settings.colors[id]})]));
|
||||
const custom = h("div", {class: "grid"}, COLOR_FIELDS.map(([id, label]) => h("label", {}, label, colors[id])));
|
||||
const verdict = h("p", {class: "muted", "aria-live": "polite"});
|
||||
const judge = () => {
|
||||
custom.hidden = theme.value !== "custom";
|
||||
verdict.hidden = theme.value !== "custom";
|
||||
const panel = Ambience.THEMES[Ambience.modeOf(colors.top.value, colors.bottom.value)].panel;
|
||||
const ratio = Ambience.contrast(Ambience.hex(colors.accent.value), Ambience.hex(panel));
|
||||
verdict.textContent = `Akzent auf Flächen: Kontrast ${ratio.toFixed(1)} : 1${ratio < 3 ? " – zu schwach, wähle einen kräftigeren Akzent" : ""}`;
|
||||
};
|
||||
theme.addEventListener("change", judge);
|
||||
Object.values(colors).forEach((input) => input.addEventListener("input", judge));
|
||||
judge();
|
||||
const musicOn = h("input", {type: "checkbox", checked: settings.music.on});
|
||||
const volume = h("input", {type: "range", min: 0, max: 1, step: 0.05, value: settings.music.volume, "aria-label": "Gesamtlautstärke"});
|
||||
const tones = SOUND_KINDS.map(([id, label]) => {
|
||||
const on = h("input", {type: "checkbox", checked: settings.sounds[id].on, "aria-label": `${label} an`});
|
||||
const level = h("input", {type: "range", min: 0, max: 1, step: 0.05, value: settings.sounds[id].volume, "aria-label": `${label} Lautstärke`});
|
||||
const loudest = () => Math.max(...tones.map((tone) => Number(tone.level.value)), Number(volume.value));
|
||||
return {id, on, level, row: h("div", {class: "sound-row"}, h("strong", {}, label), h("label", {class: "check"}, on, "an"), level, btn("Test", "btn small ghost", () => play(id, id === "mayday" ? loudest() : Number(level.value))))};
|
||||
});
|
||||
const notify = h("input", {type: "checkbox", checked: settings.notify});
|
||||
const speechOn = h("input", {type: "checkbox", checked: settings.speech.on, disabled: !state.speech.tts});
|
||||
const spoken = SPEECH_CLASSES.map(([id, label]) => ({id, label, box: h("input", {type: "checkbox", checked: id === "mayday" || settings.speech.classes.includes(id), disabled: id === "mayday", title: id === "mayday" ? "MAYDAY wird immer vorgelesen" : null})}));
|
||||
const stations = Object.entries(people()).sort(([, a], [, b]) => a.now.localeCompare(b.now))
|
||||
.map(([key, entry]) => ({key, label: entry.now, box: h("input", {type: "checkbox", checked: !settings.speech.muted.includes(key), "aria-label": `${entry.now} vorlesen`})}));
|
||||
const absent = settings.speech.muted.filter((key) => !people()[key]);
|
||||
const sample = btn("Test", "btn small ghost", () => say({text: state.speech.sample, voice: state.speech.operator, tone: "direct", cls: "newsletter"}));
|
||||
sample.disabled = !state.speech.tts;
|
||||
const list = h("div", {class: "mini"});
|
||||
const rows = [];
|
||||
settings.streams.forEach((stream) => streamRow(stream, rows, list));
|
||||
const form = h("form", {class: "settings"},
|
||||
ambience(),
|
||||
h("section", {}, h("h3", {}, "Ort"), h("p", {class: "muted"}, "Sonne, Mond und Sterne stehen dort, wo du sie von hier aus siehst, Blick nach Süden; unter 🔭 Himmel (Taste h) drehst du den Blick. Dezimalgrad, Nord und Ost positiv."),
|
||||
h("div", {class: "grid"}, h("label", {}, "Breite", latitude), h("label", {}, "Länge", longitude))),
|
||||
h("section", {}, h("h3", {}, "Darstellung"), h("label", {}, "Farben", theme), custom, verdict),
|
||||
h("section", {}, h("h3", {}, "Musik"), h("p", {class: "muted"}, "Generative Ambient-Musik, offline erzeugt: ruhig bei leerer Inbox, etwas gespannter, wenn etwas wartet, leiser unter Meldungen."),
|
||||
h("div", {class: "grid"}, h("label", {class: "check"}, musicOn, "Musik an"), h("label", {}, "Gesamtlautstärke (Musik und Radio)", volume))),
|
||||
h("section", {}, h("h3", {}, "Töne und Benachrichtigungen"), h("p", {class: "muted"}, "MAYDAY und PAN-PAN sind immer am lautesten. Bei mehreren neuen Ereignissen spielt nur das dringendste."),
|
||||
tones.map((tone) => tone.row), h("label", {class: "check"}, notify, "Desktop-Benachrichtigungen zeigen, wenn der Browser sie erlaubt")),
|
||||
h("section", {}, h("h3", {}, "Funk vorlesen"),
|
||||
h("p", {class: "muted"}, state.speech.tts
|
||||
? "Neuer Funk wird in Seefunk-Sprechweise (SMCP) vorgelesen, eine Meldung nach der anderen, jede Station mit eigener Stimme; Musik und Radio werden solange leiser. Die Lautstärke folgt den Tönen oben, MAYDAY wird immer und am lautesten gesprochen."
|
||||
: `Der Funk bleibt stumm: ${state.speech.tts_off}.`),
|
||||
h("div", {class: "days"}, h("label", {class: "check"}, speechOn, "Funk vorlesen"), sample),
|
||||
h("div", {class: "days", role: "group", "aria-label": "Klassen"}, spoken.map((entry) => h("label", {class: "check"}, entry.box, entry.label))),
|
||||
stations.length ? h("div", {class: "days", role: "group", "aria-label": "Stationen"}, stations.map((entry) => h("label", {class: "check"}, entry.box, entry.label))) : null),
|
||||
h("section", {}, h("h3", {}, "Radio"), h("p", {class: "muted"}, "Internetradio zu festen Zeiten mit 3 s Ein- und Ausblenden; die Musik pausiert solange. Die Seite darf nur von diesen Adressen Ton laden."),
|
||||
list, h("div", {}, btn("+ Sender", "btn small soft", () => streamRow({name: "", url: "", from: "07:00", to: "09:00", days: [0, 1, 2, 3, 4], on: true}, rows, list)))),
|
||||
passkeySection(),
|
||||
h("div", {class: "sheet-foot"}, h("span", {class: "spacer"}), btn("Abbrechen", "btn ghost", closeSheet), h("button", {type: "submit", class: "btn primary"}, "Speichern")));
|
||||
form.addEventListener("submit", async (event) => {
|
||||
event.preventDefault();
|
||||
context();
|
||||
const next = {
|
||||
latitude: Number(latitude.value),
|
||||
longitude: Number(longitude.value),
|
||||
theme: theme.value,
|
||||
colors: Object.fromEntries(COLOR_FIELDS.map(([id]) => [id, colors[id].value])),
|
||||
music: {on: musicOn.checked, volume: Number(volume.value)},
|
||||
sounds: Object.fromEntries(tones.map((tone) => [tone.id, {on: tone.on.checked, volume: Number(tone.level.value)}])),
|
||||
notify: notify.checked,
|
||||
streams: rows.map((entry) => entry.read()),
|
||||
speech: {
|
||||
on: speechOn.checked,
|
||||
classes: spoken.filter((entry) => entry.box.checked).map((entry) => entry.id),
|
||||
muted: [...absent, ...stations.filter((entry) => !entry.box.checked).map((entry) => entry.key)],
|
||||
},
|
||||
space: savedSpace(),
|
||||
};
|
||||
if (await saveSettings(next)) {
|
||||
closeSheet();
|
||||
toast("Einstellungen gespeichert", [], true);
|
||||
}
|
||||
});
|
||||
openSheet("Einstellungen und Ambiente", [form], false);
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
const skyMoment = () => (live() ? Date.now() : (ui.asOf === null ? state.until : ui.asOf) * 1000);
|
||||
|
||||
function applyTheme(sun) {
|
||||
const custom = settings.theme === "custom";
|
||||
const mode = custom ? Ambience.modeOf(settings.colors.top, settings.colors.bottom) : settings.theme === "sky" ? Ambience.modeAt(sun.alt) : settings.theme;
|
||||
const glass = Boolean(window.CSS && CSS.supports("(backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))")) && !window.matchMedia("(prefers-reduced-transparency: reduce)").matches;
|
||||
const key = [mode, custom ? settings.colors.accent : "", glass].join("|");
|
||||
if (key === sky.mode) {
|
||||
return;
|
||||
}
|
||||
sky.mode = key;
|
||||
const root = document.documentElement;
|
||||
const tokens = Ambience.THEMES[mode];
|
||||
for (const [name, value] of Object.entries(tokens)) {
|
||||
root.style.setProperty(`--${name}`, value);
|
||||
}
|
||||
if (custom) {
|
||||
root.style.setProperty("--accent", settings.colors.accent);
|
||||
root.style.setProperty("--accent-soft", Ambience.css(Ambience.mix(Ambience.hex(settings.colors.accent), Ambience.hex(tokens.panel), 0.84)));
|
||||
}
|
||||
root.style.setProperty("--veil", `${glass ? Ambience.GLASS * 100 : 100}%`);
|
||||
root.style.setProperty("--card", `${glass ? Ambience.CARD * 100 : 100}%`);
|
||||
root.style.colorScheme = mode;
|
||||
root.dataset.mode = mode;
|
||||
requestSpace();
|
||||
}
|
||||
|
||||
function drawMoon(paint, at, radius, moon) {
|
||||
const tilt = (moon.tilt * Math.PI) / 180;
|
||||
paint.save();
|
||||
paint.translate(at.x, at.y);
|
||||
paint.rotate(Math.atan2(-Math.cos(tilt), -Math.sin(tilt)));
|
||||
const halo = paint.createRadialGradient(0, 0, radius, 0, 0, radius * 4);
|
||||
halo.addColorStop(0, `rgb(235 240 255 / ${(0.28 * moon.lit).toFixed(3)})`);
|
||||
halo.addColorStop(1, "rgb(235 240 255 / 0)");
|
||||
paint.fillStyle = halo;
|
||||
paint.fillRect(-radius * 4, -radius * 4, radius * 8, radius * 8);
|
||||
paint.fillStyle = "rgb(60 68 92 / 0.55)";
|
||||
paint.beginPath();
|
||||
paint.arc(0, 0, radius, 0, Math.PI * 2);
|
||||
paint.fill();
|
||||
paint.fillStyle = "#f3f0e4";
|
||||
paint.beginPath();
|
||||
paint.arc(0, 0, radius, -Math.PI / 2, Math.PI / 2, false);
|
||||
paint.ellipse(0, 0, Math.abs(2 * moon.lit - 1) * radius, radius, 0, Math.PI / 2, -Math.PI / 2, moon.lit < 0.5);
|
||||
paint.closePath();
|
||||
paint.fill();
|
||||
paint.restore();
|
||||
}
|
||||
|
||||
function drawSky() {
|
||||
const ms = skyMoment();
|
||||
const sun = Ambience.sun(ms, settings.latitude, settings.longitude);
|
||||
const moon = Ambience.moon(ms, settings.latitude, settings.longitude);
|
||||
applyTheme(sun);
|
||||
const view = seenView("sky");
|
||||
const facing = COMPASS[Space.compass(view.azimuth)];
|
||||
const turned = ["azimuth", "altitude", "fov"].some((key) => Math.abs(view[key] - Space.DEFAULTS.sky[key]) >= 0.5);
|
||||
const moonText = moon.alt > 0 ? ` · Mond ${Math.round(moon.lit * 100)} % ${moon.waxing ? "zunehmend" : "abnehmend"}` : "";
|
||||
document.getElementById("sky-note").textContent = `${sun.alt > 0 ? "☀" : "☾"} ${STAGE_LABELS[Ambience.stage(sun.alt)]}${moonText}${turned ? ` · Blick ${facing[0]}` : ""}`;
|
||||
if (space.look) {
|
||||
const words = `Blick nach ${facing[1]} · ${((Math.round(view.azimuth) % 360) + 360) % 360}° · Höhe ${Math.round(view.altitude)}° · Sichtfeld ${Math.round(view.fov)}°`;
|
||||
space.compass.textContent = words;
|
||||
sky.canvas.setAttribute("aria-label", `Himmel, ${words}. Pfeiltasten drehen den Blick, Plus und Minus zoomen, 0 setzt zurück, Esc beendet.`);
|
||||
}
|
||||
const canvas = sky.canvas;
|
||||
const paint = canvas.getContext("2d");
|
||||
if (!paint) {
|
||||
return;
|
||||
}
|
||||
const ratio = Math.min(window.devicePixelRatio || 1, 2);
|
||||
const width = window.innerWidth;
|
||||
const height = window.innerHeight;
|
||||
if (canvas.width !== Math.round(width * ratio) || canvas.height !== Math.round(height * ratio)) {
|
||||
canvas.width = Math.round(width * ratio);
|
||||
canvas.height = Math.round(height * ratio);
|
||||
}
|
||||
paint.setTransform(ratio, 0, 0, ratio, 0, 0);
|
||||
const sight = Space.lens(view, width, height);
|
||||
const place = (alt, az) => Space.place(sight, alt, az);
|
||||
const inside = (at, margin) => at.x >= -margin && at.x <= width + margin && at.y >= -margin && at.y <= height + margin;
|
||||
const seen = (body, at) => body.alt > -2 && Math.abs(at.lon) <= view.fov / 2 + 10 && inside(at, 100);
|
||||
const colors = settings.theme === "custom" ? {top: Ambience.hex(settings.colors.top), bottom: Ambience.hex(settings.colors.bottom)} : Ambience.skyAt(sun.alt);
|
||||
const low = place(0, view.azimuth);
|
||||
const high = place(90, view.azimuth);
|
||||
const air = paint.createLinearGradient(low.x + (high.x - low.x) / Space.REACH, low.y + (high.y - low.y) / Space.REACH, low.x, low.y);
|
||||
air.addColorStop(0, Ambience.css(colors.top));
|
||||
air.addColorStop(1, Ambience.css(colors.bottom));
|
||||
paint.fillStyle = air;
|
||||
paint.fillRect(0, 0, width, height);
|
||||
const dusk = Math.max(0, 1 - Math.abs(sun.alt) / 14);
|
||||
const glowAt = place(Math.max(sun.alt, -3), sun.az);
|
||||
if (dusk > 0 && Math.abs(glowAt.lon) <= 135) {
|
||||
const x = Math.min(Math.max(glowAt.x, sight.cx - sight.kx * 100), sight.cx + sight.kx * 100);
|
||||
const glow = paint.createRadialGradient(x, glowAt.y, 0, x, glowAt.y, width * 0.5);
|
||||
glow.addColorStop(0, `rgb(255 186 128 / ${(0.45 * dusk).toFixed(3)})`);
|
||||
glow.addColorStop(1, "rgb(255 186 128 / 0)");
|
||||
paint.fillStyle = glow;
|
||||
paint.fillRect(0, 0, width, height);
|
||||
}
|
||||
const light = Ambience.starlight(sun.alt);
|
||||
if (light > 0) {
|
||||
const spin = Ambience.sidereal(ms) + settings.longitude;
|
||||
paint.fillStyle = "#ffffff";
|
||||
for (const star of sky.stars) {
|
||||
const spot = Ambience.horizontal(spin - star.ra, star.dec, settings.latitude);
|
||||
const at = spot.alt > 1 ? place(spot.alt, spot.az) : null;
|
||||
if (at && Math.abs(at.lon) <= view.fov / 2 && inside(at, 4)) {
|
||||
paint.globalAlpha = light * (0.25 + 0.75 * star.glow);
|
||||
paint.beginPath();
|
||||
paint.arc(at.x, at.y, 0.5 + star.glow * 1.2, 0, Math.PI * 2);
|
||||
paint.fill();
|
||||
}
|
||||
}
|
||||
paint.globalAlpha = 1;
|
||||
}
|
||||
const sunAt = place(sun.alt, sun.az);
|
||||
if (seen(sun, sunAt)) {
|
||||
const at = sunAt;
|
||||
const halo = paint.createRadialGradient(at.x, at.y, 0, at.x, at.y, 90);
|
||||
halo.addColorStop(0, "rgb(255 236 200 / 0.55)");
|
||||
halo.addColorStop(1, "rgb(255 236 200 / 0)");
|
||||
paint.fillStyle = halo;
|
||||
paint.fillRect(at.x - 90, at.y - 90, 180, 180);
|
||||
paint.fillStyle = Ambience.css(Ambience.mix([255, 170, 90], [255, 246, 220], Math.min(Math.max(sun.alt / 20, 0), 1)));
|
||||
paint.beginPath();
|
||||
paint.arc(at.x, at.y, 15, 0, Math.PI * 2);
|
||||
paint.fill();
|
||||
}
|
||||
const moonAt = place(moon.alt, moon.az);
|
||||
if (seen(moon, moonAt)) {
|
||||
drawMoon(paint, moonAt, 12, moon);
|
||||
}
|
||||
const edge = Space.horizon(sight, 96);
|
||||
const bottom = Math.max(height, ...edge.map((at) => at.y)) + 2;
|
||||
const trace = (lift) => edge.forEach((at, index) => (index ? paint.lineTo(at.x, at.y + lift) : paint.moveTo(at.x, at.y + lift)));
|
||||
const ground = paint.createLinearGradient(0, low.y, 0, low.y + height - sight.cy);
|
||||
ground.addColorStop(0, Ambience.css(Ambience.mix(colors.bottom, [4, 6, 10], 0.72)));
|
||||
ground.addColorStop(1, Ambience.css(Ambience.mix(colors.bottom, [4, 6, 10], 0.9)));
|
||||
paint.fillStyle = ground;
|
||||
paint.beginPath();
|
||||
trace(0);
|
||||
paint.lineTo(edge[edge.length - 1].x, bottom);
|
||||
paint.lineTo(edge[0].x, bottom);
|
||||
paint.closePath();
|
||||
paint.fill();
|
||||
paint.strokeStyle = "rgb(255 255 255 / 0.18)";
|
||||
paint.lineWidth = 1;
|
||||
paint.beginPath();
|
||||
trace(0.5);
|
||||
paint.stroke();
|
||||
paint.fillStyle = "rgb(255 255 255 / 0.5)";
|
||||
paint.font = "600 11px system-ui, sans-serif";
|
||||
paint.textAlign = "center";
|
||||
COMPASS.forEach(([label], index) => {
|
||||
const at = place(0, index * 45);
|
||||
if (Math.abs(at.lon) <= view.fov / 2 + 0.5) {
|
||||
paint.fillText(label, Math.min(Math.max(at.x, 14), width - 14), at.y + 16);
|
||||
}
|
||||
});
|
||||
if (space.glides.sky) {
|
||||
redrawSky();
|
||||
}
|
||||
}
|
||||
|
||||
function redrawSky() {
|
||||
window.cancelAnimationFrame(sky.frame);
|
||||
sky.frame = window.requestAnimationFrame(drawSky);
|
||||
}
|
||||
|
||||
function skyLook(on) {
|
||||
const canvas = sky.canvas;
|
||||
space.look = on;
|
||||
document.body.classList.toggle("sky-look", on);
|
||||
document.getElementById("sky-panel").hidden = !on;
|
||||
if (on) {
|
||||
canvas.removeAttribute("aria-hidden");
|
||||
canvas.setAttribute("tabindex", "0");
|
||||
canvas.setAttribute("role", "application");
|
||||
canvas.setAttribute("aria-roledescription", "Himmel");
|
||||
drawSky();
|
||||
canvas.focus();
|
||||
return;
|
||||
}
|
||||
for (const name of ["tabindex", "role", "aria-roledescription", "aria-label"]) {
|
||||
canvas.removeAttribute(name);
|
||||
}
|
||||
canvas.setAttribute("aria-hidden", "true");
|
||||
document.getElementById("settings-open").focus();
|
||||
}
|
||||
|
||||
function skyPanel() {
|
||||
const panel = document.getElementById("sky-panel");
|
||||
const step = (text, label, run) => h("button", {type: "button", class: "btn small", title: label, "aria-label": label, on: {click: run}}, text);
|
||||
space.compass = h("span", {class: "compass", "aria-live": "polite"});
|
||||
panel.append(space.compass,
|
||||
step("◀", "Blick nach links drehen (Pfeil links)", () => skyHooks.turnStep(-1, 0)),
|
||||
step("▶", "Blick nach rechts drehen (Pfeil rechts)", () => skyHooks.turnStep(1, 0)),
|
||||
step("▲", "Blick heben (Pfeil hoch)", () => skyHooks.turnStep(0, -1)),
|
||||
step("▼", "Blick senken (Pfeil runter)", () => skyHooks.turnStep(0, 1)),
|
||||
step("−", "Sichtfeld weiten (Minus)", () => skyHooks.zoomStep(1 / ZOOM)),
|
||||
step("+", "Hineinzoomen (Plus)", () => skyHooks.zoomStep(ZOOM)),
|
||||
step("⟲ Zurücksetzen", "Blick zurücksetzen: Süden, Horizont, Sichtfeld 180° (Taste 0)", () => resetView("sky")),
|
||||
step("Fertig", "Himmel verlassen (Esc)", () => skyLook(false)));
|
||||
steer(sky.canvas, "sky", skyHooks);
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
function shownCursor() {
|
||||
const glide = space.cursor;
|
||||
if (glide.to === null) {
|
||||
return state.until;
|
||||
}
|
||||
const progress = calm.matches ? 1 : Math.min((performance.now() - glide.start) / PLANE, 1);
|
||||
return progress >= 1 ? glide.to : glide.from + (glide.to - glide.from) * Space.ease(progress);
|
||||
}
|
||||
|
||||
function sceneInput() {
|
||||
const span = [Math.min(Math.max(state.since, state.first), state.until), state.until];
|
||||
const range = ui.asOf !== null && ui.preset !== -1 ? [Math.min(state.first, span[0]), Math.max(state.now, span[1])] : span;
|
||||
const lives = {};
|
||||
const subagents = {};
|
||||
for (const [key, entry] of space.subs) {
|
||||
if (entry.data) {
|
||||
lives[key] = [entry.data.since, entry.data.until];
|
||||
subagents[key] = entry.data.subagents;
|
||||
}
|
||||
}
|
||||
return {
|
||||
axis: depth(), range, span, cursor: shownCursor(), nodes: state.graph.nodes, track: state.graph.track, now: Object.fromEntries(layout(state.graph.nodes)),
|
||||
lives, subagents, radio: state.radio, grants: state.grants, chair: chairKey(), cap: Space.ARC_CAP,
|
||||
};
|
||||
}
|
||||
|
||||
function buildSpace() {
|
||||
const input = sceneInput();
|
||||
space.sceneCursor = input.cursor;
|
||||
space.scene = Space.scene(input);
|
||||
}
|
||||
|
||||
function spaceLabel() {
|
||||
const hint = AXES.find(([id]) => id === depth())[2];
|
||||
return `3D-Graph, ${hint}. Pfeiltasten drehen, Umschalt+Pfeile verschieben, Plus und Minus zoomen, 0 setzt zurück. Alle Weltlinien stehen darunter als Schaltflächen.`;
|
||||
}
|
||||
|
||||
function stageSpace() {
|
||||
if (!graphDom.space) {
|
||||
const canvas = h("canvas", {class: "space", tabindex: 0, role: "application", "aria-roledescription": "3D-Graph", "aria-label": spaceLabel(), "aria-describedby": "space-help"});
|
||||
steer(canvas, "graph", graphHooks);
|
||||
graphDom.space = {canvas, note: h("div", {class: "space-note", "aria-live": "polite"}), list: h("div", {class: "space-list"}), data: null, version: -1, node: undefined, words: "", open: false};
|
||||
graphDom.stage.replaceChildren(canvas, graphDom.space.note, graphDom.space.list);
|
||||
}
|
||||
if (space.cursor.to !== state.until) {
|
||||
space.cursor = {from: space.cursor.to === null ? state.until : shownCursor(), to: state.until, start: performance.now()};
|
||||
}
|
||||
if (wantsTrack() && !state.graph.track.length && Date.now() - space.trackAsked > TRACK_RETRY) {
|
||||
space.trackAsked = Date.now();
|
||||
load();
|
||||
}
|
||||
buildSpace();
|
||||
const held = graphDom.space;
|
||||
if (held.data !== state || held.version !== space.version || held.node !== ui.node) {
|
||||
held.data = state;
|
||||
held.version = space.version;
|
||||
held.node = ui.node;
|
||||
drawSpaceList();
|
||||
refreshSubs();
|
||||
}
|
||||
drawSpaceNote();
|
||||
requestSpace();
|
||||
}
|
||||
|
||||
function drawSpaceNote() {
|
||||
const built = space.scene;
|
||||
const format = (ts) => absolute.format(stampOf(ts));
|
||||
const axis = built.axis === "time" ? `Zeitachse ${format(built.range[0])} – ${format(built.range[1])}` : `Stand ${format(built.span[1])}`;
|
||||
const words = `${built.lines.length} Weltlinien · ${built.arcs.length} Bögen · ${axis}${built.dropped ? ` · ${built.dropped} weitere Ereignisse nur im Stream` : ""}`;
|
||||
if (graphDom.space.words === words) {
|
||||
return;
|
||||
}
|
||||
graphDom.space.words = words;
|
||||
const dropped = built.dropped ? [h("span", {}, "Gezeichnet: Mayday und Pan-Pan, Spawns, Sicherheit, Freigaben, dann die neuesten."), btn("Funk im Stream", "btn small soft", () => useView("radio"))] : [];
|
||||
graphDom.space.note.replaceChildren(h("span", {}, words), ...dropped);
|
||||
}
|
||||
|
||||
function drawSpaceList() {
|
||||
const built = space.scene;
|
||||
const held = graphDom.space;
|
||||
const chip = (line) => {
|
||||
const text = line.kind === "twig" ? short(line.title) : Space.nameAt(line.timeline, built.span[1]);
|
||||
const former = [...new Set(line.timeline.map((entry) => entry.name))];
|
||||
const hint = line.kind === "twig" ? `${line.title} · Transkript im Stream zeigen` : `${NODE_KINDS[line.kind]}${former.length > 1 ? ` · Namen: ${former.join(" → ")}` : ""}`;
|
||||
return h("button", {type: "button", class: "chip", title: hint, "aria-label": `${text}: ${hint}`, "aria-pressed": String(line.node !== null && line.node === ui.node), on: {click: () => pickLine(line)}}, line.kind === "twig" ? text : [face(text, false), text]);
|
||||
};
|
||||
const twigs = built.lines.filter((line) => line.kind === "twig");
|
||||
const more = twigs.length ? h("details", {open: held.open}, h("summary", {}, `${twigs.length} Subagenten aus den Transkripten`), h("div", {class: "chips"}, twigs.map(chip))) : null;
|
||||
if (more) {
|
||||
more.addEventListener("toggle", () => {
|
||||
held.open = more.open;
|
||||
});
|
||||
}
|
||||
held.list.replaceChildren(h("div", {class: "chips", role: "group", "aria-label": "Weltlinien"}, built.lines.filter((line) => line.kind !== "twig").map(chip)), more || "");
|
||||
}
|
||||
|
||||
async function refreshSubs() {
|
||||
if (!graph3d() || space.loading) {
|
||||
return;
|
||||
}
|
||||
const due = state.graph.nodes.filter((node) => (node.kind === "session" || node.kind === "chair") && SESSION_ID.test(node.id))
|
||||
.filter((node) => !space.subs.has(node.id) || Date.now() - space.subs.get(node.id).at > SUBS_TTL);
|
||||
if (!due.length) {
|
||||
return;
|
||||
}
|
||||
space.loading = true;
|
||||
await Promise.all(due.map(async (node) => {
|
||||
let data = null;
|
||||
try {
|
||||
const response = await fetch(`/api/subagents?session=${encodeURIComponent(node.id)}`, {cache: "no-store"});
|
||||
data = response.ok ? await response.json() : null;
|
||||
} catch {
|
||||
data = null;
|
||||
}
|
||||
space.subs.set(node.id, {at: Date.now(), data});
|
||||
}));
|
||||
space.loading = false;
|
||||
space.version += 1;
|
||||
stage();
|
||||
}
|
||||
|
||||
function spaceStyle() {
|
||||
if (!space.style || space.styleKey !== sky.mode) {
|
||||
const css = window.getComputedStyle(document.documentElement);
|
||||
const value = (name) => css.getPropertyValue(`--${name}`).trim();
|
||||
const roles = {line: "line-strong", accent: "accent", muted: "muted", violet: "violet", direct: "direct", broadcast: "broadcast", alarm: "alarm", security: "security", grant: "grant", panel: "panel", text: "text"};
|
||||
space.styleKey = sky.mode;
|
||||
space.style = {
|
||||
colors: Object.fromEntries(Object.entries(roles).map(([role, name]) => [role, value(name)])),
|
||||
font: `560 ${value("fs-sm")} ${value("sans")}`, strong: `700 ${value("fs-sm")} ${value("sans")}`, level: "Tiefe",
|
||||
};
|
||||
}
|
||||
const built = space.scene;
|
||||
return {
|
||||
...space.style, selected: ui.node, cursor: live() ? "Jetzt" : "Stand",
|
||||
format: (ts) => (built.range[1] - built.range[0] > DAY ? absolute : clock).format(stampOf(ts)),
|
||||
};
|
||||
}
|
||||
|
||||
function requestSpace() {
|
||||
if (!space.frame) {
|
||||
space.frame = window.requestAnimationFrame(paintSpace);
|
||||
}
|
||||
}
|
||||
|
||||
function paintSpace() {
|
||||
space.frame = 0;
|
||||
if (!graph3d() || !graphDom || !graphDom.space || !space.scene) {
|
||||
return;
|
||||
}
|
||||
const canvas = graphDom.space.canvas;
|
||||
const paint = canvas.getContext("2d");
|
||||
if (!paint) {
|
||||
return;
|
||||
}
|
||||
const cursor = shownCursor();
|
||||
if (cursor !== space.sceneCursor) {
|
||||
buildSpace();
|
||||
}
|
||||
const ratio = Math.min(window.devicePixelRatio || 1, 2);
|
||||
const width = canvas.clientWidth;
|
||||
const height = canvas.clientHeight;
|
||||
if (canvas.width !== Math.round(width * ratio) || canvas.height !== Math.round(height * ratio)) {
|
||||
canvas.width = Math.round(width * ratio);
|
||||
canvas.height = Math.round(height * ratio);
|
||||
}
|
||||
paint.setTransform(ratio, 0, 0, ratio, 0, 0);
|
||||
space.cam = Space.camera(seenView("graph"), width, height);
|
||||
Space.paint(paint, space.scene, space.cam, spaceStyle());
|
||||
if (space.glides.graph || cursor !== space.cursor.to) {
|
||||
requestSpace();
|
||||
}
|
||||
}
|
||||
|
||||
function pickLine(line) {
|
||||
if (line.kind === "twig") {
|
||||
focusSub(line.session, line.sub);
|
||||
} else {
|
||||
select(line.node);
|
||||
}
|
||||
}
|
||||
|
||||
function pickSpace(x, y) {
|
||||
const hit = space.scene && space.cam ? Space.pick(space.scene, space.cam, x, y, 10) : null;
|
||||
if (!hit) {
|
||||
return;
|
||||
}
|
||||
if (hit.kind === "line") {
|
||||
pickLine(hit.line);
|
||||
} else if (hit.arc.kind === "spawn") {
|
||||
focusSub(hit.arc.source, hit.arc.sub);
|
||||
} else if (hit.arc.kind === "grant") {
|
||||
select(hit.arc.target);
|
||||
} else {
|
||||
useSaved({name: "", kinds: ["radio"], waiting: false, q: "", agent: hit.arc.row >= 0 ? state.radio[hit.arc.row].from : nameOf(hit.arc.source)});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
const depth = () => (space.views.graph.axis === "spawn" ? "spawn" : "time");
|
||||
|
||||
function spaceTools() {
|
||||
return h("div", {class: "space-tools"},
|
||||
h("div", {class: "segmented", role: "group", "aria-label": "Tiefenachse"}, AXES.map(([id, label, hint]) => h("button", {type: "button", "aria-pressed": String(depth() === id), title: hint, "aria-label": `Tiefenachse ${label}: ${hint}`, on: {click: () => chooseAxis(id)}}, label))),
|
||||
h("button", {type: "button", class: "btn small ghost", title: "Drehung, Zoom und Verschiebung zurücksetzen (Taste 0)", "aria-label": "3D-Ansicht zurücksetzen", on: {click: () => resetView("graph")}}, "⟲ Ansicht"),
|
||||
h("span", {class: "muted", id: "space-help"}, "Ziehen dreht · Umschalt+Ziehen verschiebt · Rad oder zwei Finger zoomen · Pfeile, + / −, 0"));
|
||||
}
|
||||
|
||||
const graph3d = () => ui.screen === "agents" && ui.views.agents === "3d";
|
||||
const wantsTrack = () => graph3d() && depth() === "time";
|
||||
|
||||
function chooseAxis(id) {
|
||||
if (id === depth()) {
|
||||
return;
|
||||
}
|
||||
setView("graph", {...space.views.graph, axis: id}, false);
|
||||
render(false);
|
||||
}
|
||||
|
||||
function stage() {
|
||||
if (!graphDom || ui.screen !== "agents" || ui.views.agents === "tree") {
|
||||
return;
|
||||
}
|
||||
graphDom.pulses = null;
|
||||
if (graph3d()) {
|
||||
stageSpace();
|
||||
return;
|
||||
}
|
||||
graphDom.stage.replaceChildren({orbit, chord, swimlane}[ui.views.agents]());
|
||||
}
|
||||
|
||||
function drawSide() {
|
||||
if (graphDom && ui.screen === "agents" && ui.views.agents !== "tree") {
|
||||
graphDom.aside.replaceChildren(...side());
|
||||
}
|
||||
}
|
||||
|
||||
function seenView(kind) {
|
||||
const glide = space.glides[kind];
|
||||
const progress = glide && !calm.matches ? Math.min((performance.now() - glide.start) / GLIDE, 1) : 1;
|
||||
if (progress >= 1) {
|
||||
space.glides[kind] = null;
|
||||
return space.views[kind];
|
||||
}
|
||||
return Space.tween(kind, glide.from, space.views[kind], Space.ease(progress));
|
||||
}
|
||||
|
||||
function settle(kind) {
|
||||
if (space.glides[kind]) {
|
||||
space.views[kind] = Space.clampView(kind, seenView(kind));
|
||||
space.glides[kind] = null;
|
||||
}
|
||||
}
|
||||
|
||||
function setView(kind, next, smooth) {
|
||||
space.glides[kind] = smooth && !calm.matches ? {from: seenView(kind), start: performance.now()} : null;
|
||||
space.views[kind] = Space.clampView(kind, next);
|
||||
space.edits += 1;
|
||||
window.clearTimeout(space.timer);
|
||||
space.timer = window.setTimeout(persistViews, SAVE_DELAY);
|
||||
if (kind === "graph") {
|
||||
requestSpace();
|
||||
} else {
|
||||
redrawSky();
|
||||
}
|
||||
}
|
||||
|
||||
const nudge = (kind, change, smooth) => setView(kind, change(space.views[kind]), smooth);
|
||||
const savedSpace = () => ({graph: Space.tidy(space.views.graph), sky: Space.tidy(space.views.sky)});
|
||||
|
||||
async function persistViews() {
|
||||
const mark = space.edits;
|
||||
if (await saveSettings({...settings, space: savedSpace()}) && space.edits === mark) {
|
||||
space.saved = mark;
|
||||
}
|
||||
}
|
||||
|
||||
function resetView(kind) {
|
||||
setView(kind, kind === "graph" ? {...Space.DEFAULTS.graph, axis: space.views.graph.axis} : {...Space.DEFAULTS.sky}, true);
|
||||
}
|
||||
|
||||
function steerKey(event, kind, hooks) {
|
||||
const arrows = {ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, -1], ArrowDown: [0, 1]};
|
||||
if (event.altKey || event.ctrlKey || event.metaKey) {
|
||||
return;
|
||||
}
|
||||
if (Object.hasOwn(arrows, event.key)) {
|
||||
const [x, y] = arrows[event.key];
|
||||
if (event.shiftKey && hooks.panStep) {
|
||||
hooks.panStep(x, y);
|
||||
} else {
|
||||
hooks.turnStep(x, y);
|
||||
}
|
||||
} else if (event.key === "+" || event.key === "=") {
|
||||
hooks.zoomStep(ZOOM);
|
||||
} else if (event.key === "-" || event.key === "_") {
|
||||
hooks.zoomStep(1 / ZOOM);
|
||||
} else if (event.key === "0") {
|
||||
resetView(kind);
|
||||
} else if (event.key === "Escape" && kind === "sky") {
|
||||
skyLook(false);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
}
|
||||
|
||||
function steer(element, kind, hooks) {
|
||||
const pointers = new Map();
|
||||
let travel = 0;
|
||||
let spread = 0;
|
||||
const gap = () => {
|
||||
const [a, b] = [...pointers.values()];
|
||||
return Math.hypot(a.x - b.x, a.y - b.y);
|
||||
};
|
||||
element.addEventListener("pointerdown", (event) => {
|
||||
if (event.pointerType === "mouse" && event.button !== 0) {
|
||||
return;
|
||||
}
|
||||
element.setPointerCapture(event.pointerId);
|
||||
pointers.set(event.pointerId, {x: event.clientX, y: event.clientY});
|
||||
settle(kind);
|
||||
travel = pointers.size === 1 ? 0 : Infinity;
|
||||
spread = pointers.size === 2 ? gap() : 0;
|
||||
});
|
||||
element.addEventListener("pointermove", (event) => {
|
||||
const last = pointers.get(event.pointerId);
|
||||
if (!last) {
|
||||
return;
|
||||
}
|
||||
const dx = event.clientX - last.x;
|
||||
const dy = event.clientY - last.y;
|
||||
pointers.set(event.pointerId, {x: event.clientX, y: event.clientY});
|
||||
travel += Math.abs(dx) + Math.abs(dy);
|
||||
if (pointers.size === 2) {
|
||||
const next = gap();
|
||||
if (spread > 0 && next > 0) {
|
||||
hooks.zoom(next / spread);
|
||||
}
|
||||
spread = next;
|
||||
} else if (pointers.size === 1 && travel > 3) {
|
||||
if (event.shiftKey && hooks.pan) {
|
||||
hooks.pan(dx, dy);
|
||||
} else {
|
||||
hooks.rotate(dx, dy);
|
||||
}
|
||||
}
|
||||
});
|
||||
const release = (event) => {
|
||||
if (!pointers.delete(event.pointerId)) {
|
||||
return;
|
||||
}
|
||||
spread = pointers.size === 2 ? gap() : 0;
|
||||
if (event.type === "pointerup" && !pointers.size && travel <= 3 && hooks.pick) {
|
||||
const box = element.getBoundingClientRect();
|
||||
hooks.pick(event.clientX - box.left, event.clientY - box.top);
|
||||
}
|
||||
};
|
||||
element.addEventListener("pointerup", release);
|
||||
element.addEventListener("pointercancel", release);
|
||||
element.addEventListener("wheel", (event) => {
|
||||
event.preventDefault();
|
||||
settle(kind);
|
||||
hooks.zoom(Math.exp(-event.deltaY * [1, 16, 400][event.deltaMode] * 0.0015));
|
||||
}, {passive: false});
|
||||
element.addEventListener("keydown", (event) => steerKey(event, kind, hooks));
|
||||
}
|
||||
|
||||
const graphHooks = {
|
||||
rotate: (dx, dy) => nudge("graph", (view) => ({...view, yaw: view.yaw - dx * 0.4, pitch: view.pitch + dy * 0.4}), false),
|
||||
pan: (dx, dy) => nudge("graph", (view) => ({...view, pan_x: view.pan_x + dx / (space.cam ? space.cam.scale : 1), pan_y: view.pan_y + dy / (space.cam ? space.cam.scale : 1)}), false),
|
||||
zoom: (factor) => nudge("graph", (view) => ({...view, zoom: view.zoom * factor}), false),
|
||||
turnStep: (x, y) => nudge("graph", (view) => ({...view, yaw: view.yaw - x * TURN, pitch: view.pitch + y * TURN}), true),
|
||||
panStep: (x, y) => nudge("graph", (view) => ({...view, pan_x: view.pan_x + x * NUDGE, pan_y: view.pan_y + y * NUDGE}), true),
|
||||
zoomStep: (factor) => nudge("graph", (view) => ({...view, zoom: view.zoom * factor}), true),
|
||||
pick: (x, y) => pickSpace(x, y),
|
||||
};
|
||||
|
||||
const skyLens = () => Space.lens(seenView("sky"), window.innerWidth, window.innerHeight);
|
||||
|
||||
const skyHooks = {
|
||||
rotate: (dx, dy) => {
|
||||
const sight = skyLens();
|
||||
nudge("sky", (view) => ({...view, azimuth: view.azimuth - dx / sight.kx, altitude: view.altitude + dy / sight.ky}), false);
|
||||
},
|
||||
pan: null,
|
||||
zoom: (factor) => nudge("sky", (view) => ({...view, fov: view.fov / factor}), false),
|
||||
turnStep: (x, y) => nudge("sky", (view) => ({...view, azimuth: view.azimuth + x * TURN, altitude: view.altitude - y * TURN}), true),
|
||||
panStep: null,
|
||||
zoomStep: (factor) => nudge("sky", (view) => ({...view, fov: view.fov / factor}), true),
|
||||
pick: null,
|
||||
};
|
||||
@@ -0,0 +1,173 @@
|
||||
function loudness(kind) {
|
||||
return Voice.loudness(kind, settings);
|
||||
}
|
||||
|
||||
function speechFailed(lines) {
|
||||
if (Date.now() - speech.warned > SPEECH_QUIET) {
|
||||
speech.warned = Date.now();
|
||||
toast("Funk vorlesen fehlgeschlagen", lines, false);
|
||||
}
|
||||
}
|
||||
|
||||
function say(item) {
|
||||
speech.pending = Voice.enqueue(speech.pending, item, SPEECH_QUEUE);
|
||||
pump();
|
||||
}
|
||||
|
||||
async function pump() {
|
||||
if (speech.busy || !speech.pending.length) {
|
||||
return;
|
||||
}
|
||||
const sound = context();
|
||||
if (!sound) {
|
||||
speech.pending = [];
|
||||
return;
|
||||
}
|
||||
const [item, ...rest] = speech.pending;
|
||||
speech.pending = rest;
|
||||
speech.busy = true;
|
||||
const next = () => {
|
||||
speech.busy = false;
|
||||
pump();
|
||||
};
|
||||
try {
|
||||
const response = await fetch("/api/tts", {method: "POST", headers: {"X-Kvb-Orchestrator": "1", "Content-Type": "application/json"}, body: JSON.stringify({text: item.text, voice: item.voice}), cache: "no-store"});
|
||||
if (!response.ok) {
|
||||
throw new Error(`${response.status} ${(await response.text()).trim()}`);
|
||||
}
|
||||
const buffer = await sound.decodeAudioData(await response.arrayBuffer());
|
||||
const source = sound.createBufferSource();
|
||||
const gain = sound.createGain();
|
||||
gain.gain.value = loudness(item.tone);
|
||||
source.buffer = buffer;
|
||||
source.connect(gain).connect(sound.destination);
|
||||
source.addEventListener("ended", next, {once: true});
|
||||
duck(buffer.duration);
|
||||
source.start();
|
||||
} catch (error) {
|
||||
speechFailed([String(error.message || error)]);
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
function speakRows(rows) {
|
||||
if (!settings.speech.on || !state.speech.tts) {
|
||||
return;
|
||||
}
|
||||
for (const row of rows.filter((entry) => entry.ts >= state.now - SPEECH_FRESH && Voice.speakable(entry, settings.speech))) {
|
||||
say({text: row.speech, voice: row.voice, tone: Voice.toneOf(row, HUMAN), cls: row.class});
|
||||
}
|
||||
}
|
||||
|
||||
function micButton(field) {
|
||||
const button = h("button", {type: "button", class: "btn small ghost icon-btn mic", "aria-pressed": "false", "aria-label": "Spracheingabe: gedrückt halten und sprechen", title: "Gedrückt halten und sprechen; der Text landet im Feld und wird nicht gesendet"}, "🎙");
|
||||
const reason = !window.isSecureContext || !navigator.mediaDevices
|
||||
? "Das Mikrofon braucht einen sicheren Kontext: öffne den Hub über 127.0.0.1 oder localhost"
|
||||
: !window.MediaRecorder ? "Dieser Browser kann nicht aufnehmen" : !state.speech.stt ? `Spracheingabe ist aus: ${state.speech.stt_off}` : "";
|
||||
if (reason) {
|
||||
button.disabled = true;
|
||||
button.title = reason;
|
||||
return button;
|
||||
}
|
||||
const press = (event) => {
|
||||
event.preventDefault();
|
||||
record(field, button);
|
||||
};
|
||||
button.addEventListener("pointerdown", press);
|
||||
for (const name of ["pointerup", "pointerleave", "pointercancel"]) {
|
||||
button.addEventListener(name, release);
|
||||
}
|
||||
button.addEventListener("keydown", (event) => {
|
||||
if ((event.key === " " || event.key === "Enter") && !event.repeat) {
|
||||
press(event);
|
||||
}
|
||||
});
|
||||
button.addEventListener("keyup", (event) => {
|
||||
if (event.key === " " || event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
release();
|
||||
}
|
||||
});
|
||||
return button;
|
||||
}
|
||||
|
||||
async function record(field, button) {
|
||||
if (mic.held || mic.recorder || mic.busy) {
|
||||
return;
|
||||
}
|
||||
mic.held = true;
|
||||
let media = null;
|
||||
try {
|
||||
media = await navigator.mediaDevices.getUserMedia({audio: {channelCount: 1, echoCancellation: true, noiseSuppression: true}});
|
||||
} catch (error) {
|
||||
mic.held = false;
|
||||
toast("Mikrofon nicht verfügbar", [String(error.message || error)], false);
|
||||
return;
|
||||
}
|
||||
if (!mic.held) {
|
||||
media.getTracks().forEach((track) => track.stop());
|
||||
return;
|
||||
}
|
||||
const recorder = new MediaRecorder(media);
|
||||
const chunks = [];
|
||||
recorder.addEventListener("dataavailable", (event) => {
|
||||
if (event.data.size) {
|
||||
chunks.push(event.data);
|
||||
}
|
||||
});
|
||||
recorder.addEventListener("stop", () => {
|
||||
media.getTracks().forEach((track) => track.stop());
|
||||
mic.recorder = null;
|
||||
button.setAttribute("aria-pressed", "false");
|
||||
transcribe(new Blob(chunks, {type: recorder.mimeType}), field, button);
|
||||
}, {once: true});
|
||||
mic.recorder = recorder;
|
||||
recorder.start();
|
||||
button.setAttribute("aria-pressed", "true");
|
||||
mic.timer = window.setTimeout(release, state.speech.seconds * 1000);
|
||||
}
|
||||
|
||||
function release() {
|
||||
mic.held = false;
|
||||
window.clearTimeout(mic.timer);
|
||||
if (mic.recorder && mic.recorder.state === "recording") {
|
||||
mic.recorder.stop();
|
||||
}
|
||||
}
|
||||
|
||||
async function transcribe(blob, field, button) {
|
||||
const sound = context();
|
||||
if (!sound || !blob.size) {
|
||||
return;
|
||||
}
|
||||
mic.busy = true;
|
||||
button.disabled = true;
|
||||
try {
|
||||
const decoded = await sound.decodeAudioData(await blob.arrayBuffer());
|
||||
const rate = state.speech.rate;
|
||||
const length = Voice.frames(decoded.duration, rate, state.speech.seconds);
|
||||
if (length < rate / 4) {
|
||||
throw new Error("zu kurz: halte die Taste, solange du sprichst");
|
||||
}
|
||||
const offline = new OfflineAudioContext(1, length, rate);
|
||||
const source = offline.createBufferSource();
|
||||
source.buffer = decoded;
|
||||
source.connect(offline.destination);
|
||||
source.start();
|
||||
const rendered = await offline.startRendering();
|
||||
const result = await send("/api/stt", Voice.wav(rendered.getChannelData(0), rate), "audio/wav");
|
||||
if (!result.ok || !result.data) {
|
||||
throw new Error(`${result.status} ${result.text}`.trim());
|
||||
}
|
||||
if (result.data.text) {
|
||||
field.value = [field.value.trim(), result.data.text].filter(Boolean).join(" ");
|
||||
field.dispatchEvent(new Event("input", {bubbles: true}));
|
||||
}
|
||||
field.focus();
|
||||
} catch (error) {
|
||||
toast("Spracheingabe fehlgeschlagen", [String(error.message || error)], false);
|
||||
} finally {
|
||||
mic.busy = false;
|
||||
button.disabled = false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
function stored(key, fallback) {
|
||||
try {
|
||||
const text = window.localStorage.getItem(key);
|
||||
return text === null ? fallback : JSON.parse(text);
|
||||
} catch {
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
function keep(key, value) {
|
||||
try {
|
||||
window.localStorage.setItem(key, JSON.stringify(value));
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function validViews(value) {
|
||||
const names = new Set(KINDS.map(([id]) => id));
|
||||
if (!Array.isArray(value)) {
|
||||
return [];
|
||||
}
|
||||
return value.filter((view) => view && typeof view.name === "string" && view.name && Array.isArray(view.kinds) && view.kinds.length && view.kinds.every((name) => names.has(name)))
|
||||
.map((view) => ({name: view.name.slice(0, 60), kinds: view.kinds, waiting: view.waiting === true, q: typeof view.q === "string" ? view.q : "", agent: typeof view.agent === "string" ? view.agent : ""}));
|
||||
}
|
||||
|
||||
let state = JSON.parse(document.getElementById("state").textContent);
|
||||
const KINDS = Object.entries(state.kinds);
|
||||
const ui = {screen: "stream", views: {agents: "orbit", artifacts: "tree"}, preset: DAY, from: null, to: null, asOf: null, playing: false, busy: false, offline: false, agent: null, order: null, draft: "", node: null, cursor: 0, selected: new Set(), snoozed: false, review: null, file: 0};
|
||||
const filter = {view: "fuer-dich", saved: "", kinds: new Set(state.views["fuer-dich"].kinds), waiting: true, q: "", agent: "", session: "", sub: "", parts: new Set(PARTS.map(([id]) => id))};
|
||||
const stream = {key: null, events: [], entries: [], last: 0, sessions: {}, busy: false, again: false, dom: null, error: ""};
|
||||
const tree = {data: null, busy: false, q: "", open: new Set(), dom: null};
|
||||
const palette = {items: [], index: 0, input: null, list: null, plan: null, box: null};
|
||||
const known = {inbox: null, alarms: null, radio: null, batches: new Set()};
|
||||
const motion = {current: new Map(), from: new Map(), target: new Map(), start: 0, duration: 0, frame: 0, asOf: undefined};
|
||||
const drawn = {screen: "", sig: ""};
|
||||
const files = new Map();
|
||||
const pageMedia = new Set(state.media);
|
||||
const sky = {canvas: document.getElementById("sky"), stars: Ambience.stars(320, 7), mode: "", frame: 0};
|
||||
const music = {gain: null, filter: null, drone: [], timer: 0, tension: 0, ducked: 0};
|
||||
const radio = {element: null, url: "", level: 0, timer: 0, playing: false, waiting: false};
|
||||
const speech = {pending: [], busy: false, warned: 0};
|
||||
const mic = {recorder: null, held: false, busy: false, timer: 0};
|
||||
const space = {
|
||||
views: {graph: {...state.settings.space.graph}, sky: {...state.settings.space.sky}}, glides: {graph: null, sky: null}, edits: 0, saved: 0, timer: 0,
|
||||
scene: null, sceneCursor: null, cam: null, frame: 0, look: false, compass: null, subs: new Map(), loading: false, version: 0,
|
||||
cursor: {from: 0, to: null, start: 0}, style: null, styleKey: "", trackAsked: 0,
|
||||
};
|
||||
let userViews = validViews(stored(STORE.views, stored("kvb-hub.views", [])));
|
||||
let settings = state.settings;
|
||||
let settingsSig = JSON.stringify(settings);
|
||||
let drawerDom = null;
|
||||
let timeDom = null;
|
||||
let graphDom = null;
|
||||
let reviewDom = null;
|
||||
let inboxDom = null;
|
||||
let replay = 0;
|
||||
let positions = new Map();
|
||||
let inboxSig = "";
|
||||
let audio = null;
|
||||
let searchTimer = 0;
|
||||
@@ -0,0 +1,186 @@
|
||||
async function fetchEvents() {
|
||||
if (stream.busy) {
|
||||
stream.again = true;
|
||||
return;
|
||||
}
|
||||
const key = `${windowKey()}&${filterQuery()}`;
|
||||
if (stream.key !== key) {
|
||||
stream.key = key;
|
||||
stream.events = [];
|
||||
stream.entries = [];
|
||||
stream.last = 0;
|
||||
}
|
||||
stream.busy = true;
|
||||
try {
|
||||
const response = await fetch(`/api/events?${windowQuery()}&${filterQuery()}&after=${stream.last}`, {cache: "no-store"});
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
if (stream.key === key) {
|
||||
const seen = new Set(stream.entries.map((entry) => entry.id));
|
||||
stream.events = data.events;
|
||||
stream.entries = [...stream.entries, ...data.entries.filter((entry) => !seen.has(entry.id))].sort((a, b) => a.ts - b.ts).slice(-STREAM_KEEP);
|
||||
stream.last = data.last;
|
||||
stream.sessions = data.sessions;
|
||||
stream.error = "";
|
||||
}
|
||||
} else {
|
||||
stream.error = `${response.status} ${(await response.text()).trim()}`;
|
||||
}
|
||||
} catch {
|
||||
ui.offline = true;
|
||||
}
|
||||
stream.busy = false;
|
||||
drawStream();
|
||||
if (stream.again) {
|
||||
stream.again = false;
|
||||
fetchEvents();
|
||||
}
|
||||
}
|
||||
|
||||
async function expand(entry, holder, button) {
|
||||
button.disabled = true;
|
||||
const response = await fetch(`/api/stream/${entry.ref.entry}`, {cache: "no-store"});
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
entry.text = data.text;
|
||||
entry.ref.truncated = false;
|
||||
holder.textContent = data.text;
|
||||
button.remove();
|
||||
} else {
|
||||
button.textContent = "Nicht mehr verfügbar";
|
||||
}
|
||||
}
|
||||
|
||||
function focusSub(session, sub) {
|
||||
filter.view = "";
|
||||
filter.saved = "";
|
||||
filter.kinds = new Set(["transcript"]);
|
||||
filter.waiting = false;
|
||||
filter.session = session;
|
||||
filter.sub = sub;
|
||||
closeAgent();
|
||||
if (ui.screen === "stream" && stream.dom) {
|
||||
refilter();
|
||||
} else {
|
||||
go("stream", null);
|
||||
}
|
||||
}
|
||||
|
||||
function inboxOf(entry) {
|
||||
const id = entry.kind === "operator" ? entry.ref.task : entry.ref.id;
|
||||
return state.inbox.find((item) => item.kind === entry.kind && item.id === id) || null;
|
||||
}
|
||||
|
||||
function kindPill(entry) {
|
||||
if (entry.kind === "radio") {
|
||||
return klass(entry.part);
|
||||
}
|
||||
if (entry.kind === "transcript") {
|
||||
return pill((PARTS.find(([id]) => id === entry.part) || [entry.part, entry.part])[1], PART_TONES[entry.part] || "neutral");
|
||||
}
|
||||
return pill((KINDS.find(([id]) => id === entry.kind) || [entry.kind, entry.kind])[1], KIND_TONES[entry.kind] || "neutral");
|
||||
}
|
||||
|
||||
function extras(entry) {
|
||||
const ref = entry.ref;
|
||||
if (entry.kind === "review") {
|
||||
return [status(ref.status), ref.gate ? pill(ref.gate === "pass" ? "Gate grün" : "Gate rot", ref.gate === "pass" ? "ok" : "bad") : null];
|
||||
}
|
||||
if (entry.kind === "ask") {
|
||||
return [status(ref.status), ...ref.warnings.map((warning) => pill(warning, "bad"))];
|
||||
}
|
||||
if (entry.kind === "decision") {
|
||||
return [status(ref.status), ref.choice ? pill(ref.choice, "ok") : null];
|
||||
}
|
||||
if (entry.kind === "cron") {
|
||||
return [pill(ref.active ? "aktiv" : "inaktiv", ref.active ? "ok" : "neutral")];
|
||||
}
|
||||
if (entry.kind === "run" || entry.kind === "operator" || entry.kind === "register") {
|
||||
return [ref.status ? status(ref.status) : null];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
function body(entry) {
|
||||
if (entry.kind === "transcript") {
|
||||
const text = h("pre", {}, entry.text);
|
||||
const more = entry.ref.truncated ? h("button", {type: "button", class: "btn small ghost"}, "Ganzen Text zeigen") : null;
|
||||
if (more) {
|
||||
more.addEventListener("click", () => expand(entry, text, more));
|
||||
}
|
||||
return [text, more];
|
||||
}
|
||||
if (entry.kind === "ask" || entry.kind === "operator") {
|
||||
const where = entry.kind === "ask" ? entry.ref.cwd : entry.ref.directory;
|
||||
return [h("div", {class: "command"}, h("code", {}, entry.kind === "ask" ? entry.text : entry.title), copyButton(entry.kind === "ask" ? entry.text : entry.title)), h("span", {class: "muted"}, `in ${dash(where)}`), entry.kind === "operator" && entry.text !== "-" ? h("p", {class: "text"}, entry.text) : null];
|
||||
}
|
||||
if (entry.kind === "review") {
|
||||
return [entry.text ? h("pre", {class: "notes"}, entry.text) : null, h("div", {class: "line-actions"}, btn("Diff ansehen", "btn small soft", () => reviewSheet(entry.ref.id)))];
|
||||
}
|
||||
if (entry.kind === "cron") {
|
||||
const ref = entry.ref;
|
||||
const ended = ref.deleted ? [" · beendet ", when(ref.deleted)] : [];
|
||||
return [entry.text ? h("pre", {}, entry.text) : null, h("span", {class: "muted"}, "angelegt ", when(ref.created), ended)];
|
||||
}
|
||||
if (entry.kind === "run") {
|
||||
return [entry.text ? h("pre", {}, entry.text) : null];
|
||||
}
|
||||
return [entry.text ? h("p", {class: "text"}, entry.text) : null];
|
||||
}
|
||||
|
||||
function eventRow(entry) {
|
||||
const item = entry.waiting ? inboxOf(entry) : null;
|
||||
const alarm = entry.kind === "radio" && (entry.part === "mayday" || entry.part === "pan-pan");
|
||||
const renamed = entry.now && entry.now !== entry.agent ? h("span", {title: `jetzt: ${entry.now}`}, person(entry.agent)) : person(entry.agent);
|
||||
const who = entry.agent ? [face(entry.agent, false), renamed] : entry.session ? h("strong", {title: entry.session}, entry.session.slice(0, 8)) : null;
|
||||
const headline = entry.kind === "transcript" || entry.kind === "ask" || entry.kind === "operator" ? null : h("span", {class: "headline"}, entry.title);
|
||||
return h("li", {class: `entry k-${entry.kind}${entry.waiting ? " waiting" : ""}${alarm ? " alarm" : ""}`},
|
||||
h("div", {class: "msg-meta"}, when(entry.ts), kindPill(entry), extras(entry)),
|
||||
h("div", {},
|
||||
h("div", {class: "route"}, who, entry.sub ? h("button", {type: "button", class: "linkish muted", on: {click: () => focusSub(entry.session, entry.sub)}}, `› Subagent ${entry.sub.slice(0, 12)}`) : null, entry.kind === "ask" ? h("strong", {}, entry.title) : null, headline),
|
||||
body(entry),
|
||||
item ? h("div", {class: "line-actions"}, actionsFor(item)) : null));
|
||||
}
|
||||
|
||||
function drawStream() {
|
||||
if (!stream.dom || ui.screen !== "stream") {
|
||||
return;
|
||||
}
|
||||
const floor = live() && ui.preset > 0 ? nowSeconds() - ui.preset : -Infinity;
|
||||
const rows = [...stream.events, ...stream.entries.filter((entry) => entry.ts >= floor)].sort((a, b) => b.ts - a.ts || (a.id < b.id ? 1 : -1));
|
||||
const shown = rows.slice(0, FEED_LIMIT);
|
||||
stream.dom.count.textContent = `${rows.length} Einträge${live() ? " · folgt live" : ""}`;
|
||||
if (stream.error) {
|
||||
stream.dom.list.replaceChildren(emptyState("Stream nicht lesbar", stream.error));
|
||||
return;
|
||||
}
|
||||
stream.dom.list.replaceChildren(rows.length
|
||||
? h("div", {class: "card flush"}, h("ol", {class: "feed"}, shown.map(eventRow)),
|
||||
rows.length > shown.length ? h("p", {class: "footnote"}, `${rows.length - shown.length} ältere Einträge ausgeblendet; grenze mit Filter oder Zeitraum ein.`) : null)
|
||||
: emptyState(stream.busy ? "Lade …" : "Keine Einträge", activeWaiting() ? "Gerade wartet nichts auf dich." : "Im gewählten Zeitraum und Filter gibt es nichts."));
|
||||
}
|
||||
|
||||
function streamScreen() {
|
||||
const search = h("input", {type: "search", placeholder: "Suchen … agent:Name art:funk seit:2h (/)", value: filter.q, "aria-label": "Stream durchsuchen: Wörter, agent:, art: und seit:", on: {input: (event) => {
|
||||
filter.q = event.target.value;
|
||||
filter.saved = "";
|
||||
window.clearTimeout(searchTimer);
|
||||
searchTimer = window.setTimeout(fetchEvents, 300);
|
||||
}}});
|
||||
const count = h("span", {class: "muted"});
|
||||
const categories = h("div", {class: "chips", role: "group", "aria-label": "Kategorien"});
|
||||
const kinds = h("div", {class: "chips", role: "group", "aria-label": "Arten"});
|
||||
const parts = h("div", {class: "chips", role: "group", "aria-label": "Transkript-Teile"});
|
||||
const saved = h("div", {class: "chips", role: "group", "aria-label": "Gespeicherte Ansichten"});
|
||||
const focus = h("div", {class: "chips"});
|
||||
const list = h("div", {});
|
||||
const more = h("details", {class: "menu"}, h("summary", {}, "Filter ▾"), h("div", {class: "menu-box end"},
|
||||
h("h3", {}, "Arten"), kinds, h("h3", {}, "Transkript-Teile"), parts, h("h3", {}, "Gespeicherte Ansichten"), saved, h("h3", {}, "Eigener Zeitraum"), customRange()));
|
||||
stream.dom = {search, count, categories, kinds, parts, saved, focus, list};
|
||||
window.setTimeout(() => {
|
||||
drawFilters();
|
||||
drawStream();
|
||||
fetchEvents();
|
||||
}, 0);
|
||||
return h("div", {}, h("div", {class: "filters"}, categories, search, more, count), focus, list);
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
function windowQuery() {
|
||||
if (ui.preset === -1) {
|
||||
return `from=${Math.floor(ui.from)}&to=${Math.ceil(ui.to)}`;
|
||||
}
|
||||
const end = ui.asOf === null ? nowSeconds() : ui.asOf;
|
||||
const begin = ui.preset === 0 ? 0 : end - ui.preset;
|
||||
return `from=${Math.floor(begin)}${ui.asOf === null ? "" : `&to=${Math.ceil(end)}`}`;
|
||||
}
|
||||
|
||||
const localInput = (ts) => {
|
||||
const date = stampOf(ts);
|
||||
return new Date(date.getTime() - date.getTimezoneOffset() * 60000).toISOString().slice(0, 16);
|
||||
};
|
||||
|
||||
function customRange() {
|
||||
const from = h("input", {type: "datetime-local", "aria-label": "Von", value: localInput(ui.from === null ? state.since : ui.from)});
|
||||
const to = h("input", {type: "datetime-local", "aria-label": "Bis", value: localInput(ui.to === null ? state.until : ui.to)});
|
||||
return h("span", {class: "custom"}, from, h("span", {class: "muted"}, "bis"), to,
|
||||
h("button", {type: "button", class: "btn small soft", on: {click: () => {
|
||||
const begin = Date.parse(from.value) / 1000;
|
||||
const end = Date.parse(to.value) / 1000;
|
||||
if (!Number.isFinite(begin) || !Number.isFinite(end) || begin >= end) {
|
||||
toast("Zeitraum ungültig", ["„Von“ muss vor „Bis“ liegen."], false);
|
||||
return;
|
||||
}
|
||||
stopReplay();
|
||||
ui.preset = -1;
|
||||
ui.from = begin;
|
||||
ui.to = end;
|
||||
reload();
|
||||
}}}, "Anwenden"));
|
||||
}
|
||||
|
||||
function timeBar() {
|
||||
const bar = document.getElementById("time");
|
||||
const presets = h("div", {class: "segmented", role: "group", "aria-label": "Zeitraum"});
|
||||
const summary = h("summary", {title: "Zeitraum und Wiedergabe"});
|
||||
const slider = h("input", {type: "range", min: 0, max: 1000, step: 1, value: 1000, "aria-label": "Stand der Wiedergabe"});
|
||||
const play = h("button", {type: "button", class: "btn small soft"}, "▶ Wiedergabe");
|
||||
const liveButton = h("button", {type: "button", class: "btn small ghost"}, "Live");
|
||||
const label = h("span", {class: "window-label"});
|
||||
for (const [seconds, name] of PRESETS.filter(([seconds]) => seconds !== -1)) {
|
||||
presets.append(h("button", {type: "button", "data-preset": seconds, on: {click: () => choosePreset(seconds)}}, name));
|
||||
}
|
||||
slider.addEventListener("input", () => {
|
||||
stopReplay();
|
||||
const span = state.now - state.first;
|
||||
ui.asOf = Number(slider.value) >= 1000 ? null : state.first + (span * Number(slider.value)) / 1000;
|
||||
reload();
|
||||
});
|
||||
play.addEventListener("click", () => (ui.playing ? stopReplay() : startReplay()));
|
||||
liveButton.addEventListener("click", () => {
|
||||
stopReplay();
|
||||
ui.asOf = null;
|
||||
if (ui.preset === -1) {
|
||||
ui.preset = DAY;
|
||||
}
|
||||
reload();
|
||||
});
|
||||
bar.append(summary, h("div", {class: "menu-box end"}, h("h3", {}, "Zeitraum"), presets, h("h3", {}, "Wiedergabe"), h("div", {class: "replay"}, play, slider, liveButton), label,
|
||||
h("p", {class: "muted"}, "Einen eigenen Zeitraum setzt Filter ▾ im Stream.")));
|
||||
timeDom = {summary, presets, slider, play, live: liveButton, label};
|
||||
}
|
||||
|
||||
function reload() {
|
||||
load();
|
||||
if (ui.screen === "stream") {
|
||||
fetchEvents();
|
||||
}
|
||||
}
|
||||
|
||||
function choosePreset(seconds) {
|
||||
stopReplay();
|
||||
ui.preset = seconds;
|
||||
reload();
|
||||
}
|
||||
|
||||
function drawTime() {
|
||||
if (!timeDom) {
|
||||
return;
|
||||
}
|
||||
for (const button of timeDom.presets.children) {
|
||||
button.setAttribute("aria-pressed", String(Number(button.dataset.preset) === ui.preset));
|
||||
}
|
||||
timeDom.summary.textContent = `${(PRESETS.find(([seconds]) => seconds === ui.preset) || [0, "eigener"])[1]}${ui.asOf === null ? "" : " · Wiedergabe"} ▾`;
|
||||
timeDom.slider.disabled = ui.preset === -1;
|
||||
timeDom.play.disabled = ui.preset === -1;
|
||||
timeDom.live.disabled = live();
|
||||
const span = Math.max(state.now - state.first, 1);
|
||||
if (!ui.playing) {
|
||||
timeDom.slider.value = String(ui.asOf === null ? 1000 : Math.round((1000 * (ui.asOf - state.first)) / span));
|
||||
}
|
||||
timeDom.label.textContent = `${absolute.format(stampOf(state.since))} – ${absolute.format(stampOf(state.until))}${live() ? " · live" : ""}`;
|
||||
}
|
||||
|
||||
function startReplay() {
|
||||
if (ui.preset === -1) {
|
||||
return;
|
||||
}
|
||||
const began = state.first;
|
||||
const span = Math.max(state.now - began, 1);
|
||||
const resume = ui.asOf !== null && ui.asOf < state.now - 60;
|
||||
let progress = resume ? (ui.asOf - began) / span : 0;
|
||||
ui.playing = true;
|
||||
timeDom.play.textContent = "❚❚ Pause";
|
||||
const advance = async () => {
|
||||
if (!ui.playing) {
|
||||
return;
|
||||
}
|
||||
progress = Math.min(progress + 1 / 48, 1);
|
||||
ui.asOf = progress >= 1 ? null : began + span * progress;
|
||||
timeDom.slider.value = String(Math.round(progress * 1000));
|
||||
await load();
|
||||
if (ui.screen === "stream") {
|
||||
fetchEvents();
|
||||
}
|
||||
if (progress >= 1) {
|
||||
stopReplay();
|
||||
} else if (ui.playing) {
|
||||
replay = window.setTimeout(advance, 500);
|
||||
}
|
||||
};
|
||||
advance();
|
||||
}
|
||||
|
||||
function stopReplay() {
|
||||
ui.playing = false;
|
||||
window.clearTimeout(replay);
|
||||
if (timeDom) {
|
||||
timeDom.play.textContent = "▶ Wiedergabe";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
function treeScreen() {
|
||||
const search = h("input", {type: "search", placeholder: "Repo, Branch, Pfad oder Agent filtern …", value: tree.q, "aria-label": "Tree filtern", on: {input: (event) => {
|
||||
tree.q = event.target.value;
|
||||
drawTree();
|
||||
}}});
|
||||
const count = h("span", {class: "muted"});
|
||||
const list = h("div", {class: "repos"});
|
||||
tree.dom = {list, count};
|
||||
window.setTimeout(() => {
|
||||
drawTree();
|
||||
fetchTree();
|
||||
}, 0);
|
||||
return h("div", {}, h("div", {class: "filters"}, search, count, btn("Neu laden", "btn small soft", fetchTree)), list);
|
||||
}
|
||||
|
||||
async function fetchTree() {
|
||||
if (tree.busy) {
|
||||
return;
|
||||
}
|
||||
tree.busy = true;
|
||||
try {
|
||||
const response = await fetch("/api/tree", {cache: "no-store"});
|
||||
if (response.ok) {
|
||||
tree.data = await response.json();
|
||||
}
|
||||
} catch {
|
||||
ui.offline = true;
|
||||
}
|
||||
tree.busy = false;
|
||||
drawTree();
|
||||
}
|
||||
|
||||
function worktreeRow(wt) {
|
||||
const review = wt.review;
|
||||
return h("div", {class: "wt"},
|
||||
h("code", {}, wt.path),
|
||||
h("span", {class: "muted", title: wt.head}, wt.head.slice(0, 10)),
|
||||
wt.dirty === null ? pill("fehlt", "neutral") : wt.dirty ? pill("geändert", "warn") : pill("sauber", "ok"),
|
||||
wt.workers.length ? h("span", {class: "who"}, wt.workers.map((name) => [face(name, false), person(name)])) : h("span", {class: "muted"}, "niemand"),
|
||||
review ? [status(review.status), review.gate ? pill(review.gate === "pass" ? "Gate grün" : "Gate rot", review.gate === "pass" ? "ok" : "bad") : null] : null,
|
||||
copyButton(wt.path));
|
||||
}
|
||||
|
||||
function drawTree() {
|
||||
if (!tree.dom) {
|
||||
return;
|
||||
}
|
||||
if (!tree.data) {
|
||||
tree.dom.list.replaceChildren(emptyState(tree.busy ? "Lese Repositories …" : "Kein Tree", "Die Repositories werden höchstens jede Minute neu gelesen."));
|
||||
return;
|
||||
}
|
||||
const q = tree.q.trim().toLowerCase();
|
||||
const hit = (...texts) => !q || texts.some((text) => String(text).toLowerCase().includes(q));
|
||||
const repos = [];
|
||||
for (const repo of tree.data.repos) {
|
||||
const branches = repo.branches.filter((entry) => hit(repo.name, entry.name, ...entry.worktrees.flatMap((wt) => [wt.path, ...wt.workers])));
|
||||
const detached = repo.detached.filter((wt) => hit(repo.name, wt.path, ...wt.workers));
|
||||
if (branches.length || detached.length) {
|
||||
repos.push({repo, branches, detached});
|
||||
}
|
||||
}
|
||||
tree.dom.count.textContent = `${repos.length} Repositories · Stand ${clock.format(stampOf(tree.data.scanned))}`;
|
||||
if (!repos.length) {
|
||||
tree.dom.list.replaceChildren(emptyState("Nichts gefunden", "Kein Repository passt zum Filter."));
|
||||
return;
|
||||
}
|
||||
tree.dom.list.replaceChildren(...repos.map(({repo, branches, detached}) => {
|
||||
const trees = repo.branches.flatMap((entry) => entry.worktrees).concat(repo.detached);
|
||||
const dirty = trees.filter((wt) => wt.dirty).length;
|
||||
const details = h("details", {class: "card repo", open: Boolean(q) || tree.open.has(repo.path)},
|
||||
h("summary", {}, h("span", {}, repo.name), counter(`${repo.branches.length} Branches`), counter(`${trees.length} Worktrees`), dirty ? pill(`${dirty} geändert`, "warn") : null),
|
||||
branches.map((entry) => h("div", {class: "branch-row"},
|
||||
h("div", {class: "branch-name"}, h("strong", {}, entry.name), entry.upstream ? h("span", {class: "muted"}, `↔ ${entry.upstream}`) : h("span", {class: "muted"}, "ohne Upstream"),
|
||||
entry.ahead ? pill(`${entry.ahead} voraus`, "info") : null, entry.behind ? pill(`${entry.behind} zurück`, "warn") : null, entry.gone ? pill("Upstream weg", "bad") : null,
|
||||
h("span", {class: "muted", title: entry.head}, entry.head.slice(0, 10))),
|
||||
entry.worktrees.map(worktreeRow))),
|
||||
detached.length ? h("div", {class: "branch-row"}, h("div", {class: "branch-name"}, h("strong", {}, "losgelöster HEAD")), detached.map(worktreeRow)) : null);
|
||||
details.addEventListener("toggle", () => {
|
||||
if (details.open) {
|
||||
tree.open.add(repo.path);
|
||||
} else {
|
||||
tree.open.delete(repo.path);
|
||||
}
|
||||
});
|
||||
return details;
|
||||
}));
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
const SpacePaint = (() => {
|
||||
"use strict";
|
||||
const {clamp, project, depthSort} = typeof SpaceView === "object" ? SpaceView : require("./space-view.js");
|
||||
const LOOKS = {
|
||||
guide: ["line", 1, 1],
|
||||
"line:operator": ["accent", 2.4, 0.9],
|
||||
"line:chair": ["accent", 2, 0.85],
|
||||
"line:session": ["muted", 1.6, 0.8],
|
||||
"line:subagent": ["violet", 1.2, 0.75],
|
||||
"line:twig": ["violet", 1, 0.6],
|
||||
"line:selected": ["accent", 3.2, 1],
|
||||
"arc:direct": ["direct", 1.3, 0.6],
|
||||
"arc:broadcast": ["broadcast", 1.2, 0.55],
|
||||
"arc:alarm": ["alarm", 2, 0.9],
|
||||
"arc:security": ["security", 1.5, 0.75],
|
||||
"arc:grant": ["grant", 1.6, 0.75],
|
||||
"arc:spawn": ["violet", 1.4, 0.8],
|
||||
};
|
||||
const DISCS = {operator: 9, chair: 7, session: 5.5, subagent: 3.5, twig: 3};
|
||||
const RIM = 330;
|
||||
const HALO = 14;
|
||||
const SLICE = 25;
|
||||
const ROUND = 48;
|
||||
const MARGIN = 40;
|
||||
|
||||
function ring(center, radius, count) {
|
||||
return Array.from({length: count}, (_, index) => {
|
||||
const angle = (2 * Math.PI * index) / count;
|
||||
return {x: center.x + radius * Math.cos(angle), y: center.y + radius * Math.sin(angle), z: center.z};
|
||||
});
|
||||
}
|
||||
|
||||
function arcPoints(arc) {
|
||||
return arc.kind === "broadcast" ? ring(arc.from, HALO, 12) : [arc.from, arc.via, arc.to];
|
||||
}
|
||||
|
||||
function visible(cam, marks) {
|
||||
let [left, right, upper, lower] = [Infinity, -Infinity, Infinity, -Infinity];
|
||||
for (const mark of marks) {
|
||||
if (mark === null) {
|
||||
return false;
|
||||
}
|
||||
left = Math.min(left, mark.x);
|
||||
right = Math.max(right, mark.x);
|
||||
upper = Math.min(upper, mark.y);
|
||||
lower = Math.max(lower, mark.y);
|
||||
}
|
||||
return right >= -MARGIN && left <= cam.width + MARGIN && lower >= -MARGIN && upper <= cam.height + MARGIN;
|
||||
}
|
||||
|
||||
function mean(marks) {
|
||||
return marks.reduce((sum, mark) => sum + mark.depth, 0) / marks.length;
|
||||
}
|
||||
|
||||
function pen(ctx, colors, look) {
|
||||
const [role, width, alpha] = LOOKS[look];
|
||||
ctx.strokeStyle = colors[role];
|
||||
ctx.lineWidth = width;
|
||||
ctx.globalAlpha = alpha;
|
||||
}
|
||||
|
||||
function paint(ctx, built, cam, style) {
|
||||
const colors = style.colors;
|
||||
const stats = {items: 0, arcs: 0, culled: 0, batches: 0, labels: 0};
|
||||
const buckets = new Map(Object.keys(LOOKS).map((look) => [look, []]));
|
||||
const others = [];
|
||||
const marksOf = (points) => points.map((entry) => project(cam, entry));
|
||||
const stroke = (look, marks, type, closed) => {
|
||||
if (!visible(cam, marks)) {
|
||||
stats.culled += 1;
|
||||
return false;
|
||||
}
|
||||
buckets.get(look).push({type, look, marks, closed, depth: Math.round(mean(marks) / SLICE) * SLICE});
|
||||
return true;
|
||||
};
|
||||
const label = (at, text, tone, strong) => {
|
||||
const mark = project(cam, at);
|
||||
if (mark && visible(cam, [mark])) {
|
||||
others.push({type: "label", mark, text, tone, strong, depth: mark.depth - 1});
|
||||
}
|
||||
};
|
||||
for (const guide of built.guides) {
|
||||
const marks = marksOf(ring({x: 0, y: 0, z: guide.z}, RIM, ROUND));
|
||||
if (stroke("guide", marks, "path", true)) {
|
||||
label({x: 0, y: -RIM, z: guide.z}, built.axis === "time" ? style.format(guide.ts) : `${style.level} ${guide.level}`, "muted", false);
|
||||
}
|
||||
}
|
||||
if (built.plane) {
|
||||
const marks = marksOf(ring({x: 0, y: 0, z: built.plane.z}, RIM, ROUND));
|
||||
if (visible(cam, marks)) {
|
||||
others.push({type: "plane", marks, depth: mean(marks)});
|
||||
label({x: RIM * Math.SQRT1_2, y: -RIM * Math.SQRT1_2, z: built.plane.z}, `${style.cursor} ${style.format(built.plane.ts)}`, "accent", true);
|
||||
}
|
||||
}
|
||||
built.lines.forEach((line) => {
|
||||
const marks = marksOf(line.points);
|
||||
const look = line.node !== null && line.node === style.selected ? "line:selected" : `line:${line.kind}`;
|
||||
for (let index = 1; index < marks.length; index += 1) {
|
||||
stroke(look, [marks[index - 1], marks[index]], "path", false);
|
||||
}
|
||||
const tail = marks[marks.length - 1];
|
||||
if ((line.alive || built.axis !== "time") && tail && visible(cam, [tail])) {
|
||||
others.push({type: "disc", mark: tail, look, radius: DISCS[line.kind] * clamp(tail.size, 0.5, 2.5), dim: !line.alive, depth: tail.depth - 0.5});
|
||||
}
|
||||
});
|
||||
for (const arc of built.arcs) {
|
||||
if (stroke(`arc:${arc.tone}`, marksOf(arcPoints(arc)), arc.kind === "broadcast" ? "path" : "curve", arc.kind === "broadcast")) {
|
||||
stats.arcs += 1;
|
||||
}
|
||||
}
|
||||
for (const entry of built.labels) {
|
||||
label(entry.at, entry.text, "text", built.lines[entry.line].node !== null && built.lines[entry.line].node === style.selected);
|
||||
}
|
||||
const items = depthSort([...[...buckets.values()].flat(), ...others]);
|
||||
stats.items = items.length;
|
||||
ctx.clearRect(0, 0, cam.width, cam.height);
|
||||
ctx.lineCap = "round";
|
||||
ctx.lineJoin = "round";
|
||||
ctx.textAlign = "center";
|
||||
let open = "";
|
||||
const flush = () => {
|
||||
if (open) {
|
||||
ctx.stroke();
|
||||
stats.batches += 1;
|
||||
open = "";
|
||||
}
|
||||
};
|
||||
for (const item of items) {
|
||||
const marks = item.marks;
|
||||
if (item.type === "path" || item.type === "curve") {
|
||||
if (item.look !== open) {
|
||||
flush();
|
||||
pen(ctx, colors, item.look);
|
||||
ctx.beginPath();
|
||||
open = item.look;
|
||||
}
|
||||
ctx.moveTo(marks[0].x, marks[0].y);
|
||||
if (item.type === "curve") {
|
||||
ctx.quadraticCurveTo(marks[1].x, marks[1].y, marks[2].x, marks[2].y);
|
||||
} else {
|
||||
for (let index = 1; index < marks.length; index += 1) {
|
||||
ctx.lineTo(marks[index].x, marks[index].y);
|
||||
}
|
||||
if (item.closed) {
|
||||
ctx.closePath();
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
flush();
|
||||
if (item.type === "plane") {
|
||||
ctx.beginPath();
|
||||
marks.forEach((mark, index) => (index ? ctx.lineTo(mark.x, mark.y) : ctx.moveTo(mark.x, mark.y)));
|
||||
ctx.closePath();
|
||||
ctx.globalAlpha = 0.1;
|
||||
ctx.fillStyle = colors.accent;
|
||||
ctx.fill();
|
||||
ctx.globalAlpha = 0.55;
|
||||
ctx.strokeStyle = colors.accent;
|
||||
ctx.lineWidth = 1.2;
|
||||
ctx.stroke();
|
||||
} else if (item.type === "disc") {
|
||||
ctx.beginPath();
|
||||
ctx.arc(item.mark.x, item.mark.y, item.radius, 0, 2 * Math.PI);
|
||||
ctx.globalAlpha = item.dim ? 0.5 : 1;
|
||||
ctx.fillStyle = colors.panel;
|
||||
ctx.fill();
|
||||
pen(ctx, colors, item.look);
|
||||
ctx.globalAlpha = item.dim ? 0.5 : 1;
|
||||
ctx.stroke();
|
||||
} else {
|
||||
stats.labels += 1;
|
||||
ctx.globalAlpha = 1;
|
||||
ctx.font = item.strong ? style.strong : style.font;
|
||||
ctx.lineWidth = 4;
|
||||
ctx.strokeStyle = colors.panel;
|
||||
ctx.strokeText(item.text, item.mark.x, item.mark.y - 10);
|
||||
ctx.fillStyle = colors[item.tone];
|
||||
ctx.fillText(item.text, item.mark.x, item.mark.y - 10);
|
||||
}
|
||||
}
|
||||
flush();
|
||||
ctx.globalAlpha = 1;
|
||||
return stats;
|
||||
}
|
||||
|
||||
return {arcPoints, paint};
|
||||
})();
|
||||
if (typeof module === "object" && module.exports) {
|
||||
module.exports = SpacePaint;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
const SpacePick = (() => {
|
||||
"use strict";
|
||||
const {clamp, project} = typeof SpaceView === "object" ? SpaceView : require("./space-view.js");
|
||||
const {arcPoints} = typeof SpacePaint === "object" ? SpacePaint : require("./space-paint.js");
|
||||
const CURVE = 8;
|
||||
|
||||
function gap(x, y, a, b) {
|
||||
const dx = b.x - a.x;
|
||||
const dy = b.y - a.y;
|
||||
const length = dx * dx + dy * dy;
|
||||
const share = length ? clamp(((x - a.x) * dx + (y - a.y) * dy) / length, 0, 1) : 0;
|
||||
return Math.hypot(a.x + dx * share - x, a.y + dy * share - y);
|
||||
}
|
||||
|
||||
function nearest(x, y, marks) {
|
||||
if (marks.some((mark) => mark === null)) {
|
||||
return {distance: Infinity, depth: Infinity};
|
||||
}
|
||||
if (marks.length === 1) {
|
||||
return {distance: Math.hypot(marks[0].x - x, marks[0].y - y), depth: marks[0].depth};
|
||||
}
|
||||
let best = {distance: Infinity, depth: Infinity};
|
||||
for (let index = 1; index < marks.length; index += 1) {
|
||||
const distance = gap(x, y, marks[index - 1], marks[index]);
|
||||
if (distance < best.distance) {
|
||||
best = {distance, depth: (marks[index - 1].depth + marks[index].depth) / 2};
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
function curve(marks) {
|
||||
if (marks.some((mark) => mark === null)) {
|
||||
return marks;
|
||||
}
|
||||
const [a, b, c] = marks;
|
||||
return Array.from({length: CURVE + 1}, (_, index) => {
|
||||
const t = index / CURVE;
|
||||
const u = 1 - t;
|
||||
return {x: u * u * a.x + 2 * u * t * b.x + t * t * c.x, y: u * u * a.y + 2 * u * t * b.y + t * t * c.y, depth: u * u * a.depth + 2 * u * t * b.depth + t * t * c.depth};
|
||||
});
|
||||
}
|
||||
|
||||
function pick(built, cam, x, y, reach) {
|
||||
let best = null;
|
||||
const consider = (found, hit) => {
|
||||
if (found.distance > reach) {
|
||||
return;
|
||||
}
|
||||
if (!best || found.distance < best.distance - 0.5 || (found.distance <= best.distance + 0.5 && found.depth < best.depth)) {
|
||||
best = {...hit, distance: found.distance, depth: found.depth};
|
||||
}
|
||||
};
|
||||
built.lines.forEach((line, index) => consider(nearest(x, y, line.points.map((entry) => project(cam, entry))), {kind: "line", index, line}));
|
||||
built.arcs.forEach((arc, index) => {
|
||||
const marks = arcPoints(arc).map((entry) => project(cam, entry));
|
||||
consider(nearest(x, y, arc.kind === "broadcast" ? [...marks, marks[0]] : curve(marks)), {kind: "arc", index, arc});
|
||||
});
|
||||
return best;
|
||||
}
|
||||
|
||||
return {pick};
|
||||
})();
|
||||
if (typeof module === "object" && module.exports) {
|
||||
module.exports = SpacePick;
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
const SpaceScene = (() => {
|
||||
"use strict";
|
||||
const {LEVELS, clamp, turn, depthOf} = typeof SpaceView === "object" ? SpaceView : require("./space-view.js");
|
||||
const TONES = {post: "direct", call: "direct", receipt: "direct", newsletter: "broadcast", broadcast: "broadcast", mayday: "alarm", "pan-pan": "alarm", security: "security", grant: "grant", spawn: "spawn"};
|
||||
const RANKS = {alarm: 0, spawn: 1, security: 2, grant: 3, direct: 4, broadcast: 5};
|
||||
const MOON = 38;
|
||||
const MOON_SPREAD = 0.5;
|
||||
const TWIG = 30;
|
||||
const TWIG_SPREAD = 0.45;
|
||||
const ARC_CAP = 1500;
|
||||
|
||||
function bend(from, to) {
|
||||
const dx = to.x - from.x;
|
||||
const dy = to.y - from.y;
|
||||
const length = Math.hypot(dx, dy) || 1;
|
||||
return {x: ((from.x + to.x) / 2) * 0.82 - (dy / length) * 22, y: ((from.y + to.y) / 2) * 0.82 + (dx / length) * 22};
|
||||
}
|
||||
|
||||
function satellite(base, index, count, reach, spread) {
|
||||
const angle = base.angle + (index - (count - 1) / 2) * spread;
|
||||
return {x: base.x + reach * Math.cos(angle), y: base.y + reach * Math.sin(angle), angle};
|
||||
}
|
||||
|
||||
function moon(base, index, count) {
|
||||
return satellite(base, index, count, MOON, MOON_SPREAD);
|
||||
}
|
||||
|
||||
function nameAt(timeline, ts) {
|
||||
const valid = timeline.filter((entry) => entry.since <= ts);
|
||||
return (valid.length ? valid[valid.length - 1] : timeline[0]).name;
|
||||
}
|
||||
|
||||
function spotAt(track, id, ts) {
|
||||
let after = 0;
|
||||
while (after < track.length && track[after].ts < ts) {
|
||||
after += 1;
|
||||
}
|
||||
const late = track[Math.min(after, track.length - 1)].orbit[id];
|
||||
const early = track[Math.max(after - 1, 0)].orbit[id];
|
||||
if (!late || !early) {
|
||||
return late || early || null;
|
||||
}
|
||||
const span = after > 0 && after < track.length ? track[after].ts - track[after - 1].ts : 0;
|
||||
const share = span > 0 ? (ts - track[after - 1].ts) / span : 1;
|
||||
return {angle: turn(early.angle, late.angle, share), radius: early.radius + (late.radius - early.radius) * share};
|
||||
}
|
||||
|
||||
function born(row) {
|
||||
return row.since === null ? row.started : row.since;
|
||||
}
|
||||
|
||||
function tree(rows) {
|
||||
const order = [...rows].sort((a, b) => born(a) - born(b) || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0));
|
||||
const parents = {};
|
||||
order.forEach((row, index) => {
|
||||
const elders = order.slice(0, index).filter((other) => other.depth === row.depth - 1);
|
||||
const living = elders.filter((other) => other.until === null || other.until >= born(row));
|
||||
const chosen = (living.length ? living : elders).at(-1);
|
||||
parents[row.id] = row.depth > 1 && chosen ? chosen.id : "";
|
||||
});
|
||||
return {order, parents};
|
||||
}
|
||||
|
||||
function capArcs(arcs, cap) {
|
||||
if (arcs.length <= cap) {
|
||||
return {kept: arcs, dropped: 0};
|
||||
}
|
||||
const ranks = arcs.map((arc) => (Object.hasOwn(RANKS, arc.tone) ? RANKS[arc.tone] : RANKS.direct));
|
||||
const order = arcs.map((arc, index) => index).sort((a, b) => ranks[a] - ranks[b] || arcs[b].ts - arcs[a].ts || a - b);
|
||||
const chosen = order.slice(0, cap).sort((a, b) => a - b);
|
||||
return {kept: chosen.map((index) => arcs[index]), dropped: arcs.length - cap};
|
||||
}
|
||||
|
||||
function scene(input) {
|
||||
const {axis, range, span, cursor, nodes, track, now, lives, subagents, radio, grants, chair, cap} = input;
|
||||
const floor = span[0];
|
||||
const top = Math.max(Math.min(cursor, span[1]), floor);
|
||||
const last = track.length ? track[track.length - 1].ts : -Infinity;
|
||||
const byId = new Map(nodes.map((node) => [node.id, node]));
|
||||
const moons = new Map();
|
||||
for (const node of nodes.filter((entry) => entry.kind === "subagent")) {
|
||||
moons.set(node.parent, [...(moons.get(node.parent) || []), node]);
|
||||
}
|
||||
const lines = [];
|
||||
const labels = [];
|
||||
const arcs = [];
|
||||
const point = (spot, ts, level) => ({x: spot.x, y: spot.y, z: depthOf(axis, {ts, level}, range), ts});
|
||||
const headed = (spot) => ({x: spot.x, y: spot.y, angle: spot.x === 0 && spot.y === 0 ? -Math.PI / 2 : Math.atan2(spot.y, spot.x)});
|
||||
const stamps = (start, end) => (axis === "time" && start < end ? [start, ...track.map((sample) => sample.ts).filter((ts) => ts > start && ts < end), end] : [end]);
|
||||
|
||||
function anchor(id, ts) {
|
||||
const node = byId.get(id);
|
||||
if (!node || node.kind === "operator") {
|
||||
return {x: 0, y: 0};
|
||||
}
|
||||
if (node.kind === "subagent") {
|
||||
const family = moons.get(node.parent);
|
||||
return moon(headed(anchor(byId.has(node.parent) ? node.parent : chair, ts)), family.indexOf(node), family.length);
|
||||
}
|
||||
const spot = axis === "time" && ts < last ? spotAt(track, id, ts) : null;
|
||||
return spot ? {x: spot.radius * Math.cos(spot.angle), y: spot.radius * Math.sin(spot.angle)} : now[id] || {x: 0, y: 0};
|
||||
}
|
||||
|
||||
function within(life) {
|
||||
const start = Math.max(floor, life && life[0] !== null ? life[0] : floor);
|
||||
const end = Math.min(top, life && life[1] !== null ? life[1] : top);
|
||||
return start <= end ? [start, end] : [floor, top];
|
||||
}
|
||||
|
||||
function addLine(entry, place, start, end) {
|
||||
const points = stamps(start, end).map((ts) => point(place(ts), ts, entry.level));
|
||||
const index = lines.length;
|
||||
lines.push({...entry, points});
|
||||
if (entry.kind === "subagent" || (entry.kind === "twig" && !entry.alive)) {
|
||||
return;
|
||||
}
|
||||
const tail = points[points.length - 1];
|
||||
labels.push({line: index, at: tail, text: nameAt(entry.timeline, tail.ts)});
|
||||
if (axis !== "time") {
|
||||
return;
|
||||
}
|
||||
const head = points[0];
|
||||
const changes = entry.timeline.filter((change) => change.since > head.ts && change.since < tail.ts);
|
||||
for (const change of changes) {
|
||||
labels.push({line: index, at: point(place(change.since), change.since, entry.level), text: change.name});
|
||||
}
|
||||
if (changes.length) {
|
||||
labels.push({line: index, at: head, text: nameAt(entry.timeline, head.ts)});
|
||||
}
|
||||
}
|
||||
|
||||
function connect(source, targets, tone, ts, row, count, kind) {
|
||||
const moment = axis === "time" ? ts : top;
|
||||
const from = point(anchor(source, moment), moment, 0);
|
||||
if (!targets.length) {
|
||||
arcs.push({kind: "broadcast", tone, ts, source, target: "*", sub: "", row, count, from, via: from, to: from});
|
||||
return;
|
||||
}
|
||||
for (const target of targets) {
|
||||
if (target !== source && byId.has(target)) {
|
||||
const to = point(anchor(target, moment), moment, 0);
|
||||
arcs.push({kind, tone, ts, source, target, sub: "", row, count, from, via: {...bend(from, to), z: from.z}, to});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const node of nodes) {
|
||||
const owner = node.kind === "subagent" ? node.parent : node.id;
|
||||
const [start, end] = within(lives[owner]);
|
||||
const timeline = node.timeline && node.timeline.length ? node.timeline : [{name: node.label, since: floor}];
|
||||
addLine({node: node.id, kind: node.kind, session: owner, sub: "", level: node.kind === "subagent" ? 1 : 0, timeline, title: node.label, alive: end >= top}, (ts) => anchor(node.id, ts), start, end);
|
||||
}
|
||||
for (const session of Object.keys(subagents).sort()) {
|
||||
if (!byId.has(session)) {
|
||||
continue;
|
||||
}
|
||||
const {order, parents} = tree(subagents[session]);
|
||||
const families = new Map();
|
||||
for (const row of order) {
|
||||
families.set(parents[row.id], [...(families.get(parents[row.id]) || []), row.id]);
|
||||
}
|
||||
const chains = new Map();
|
||||
for (const row of order) {
|
||||
const family = families.get(parents[row.id]);
|
||||
chains.set(row.id, [...(chains.get(parents[row.id]) || []), {index: family.indexOf(row.id), count: family.length}]);
|
||||
}
|
||||
const reach = (chain, ts) => chain.reduce((spot, link) => satellite(spot, link.index, link.count, TWIG, TWIG_SPREAD), headed(anchor(session, ts)));
|
||||
for (const row of order) {
|
||||
const since = born(row);
|
||||
if (since > top || (row.until !== null && row.until < floor)) {
|
||||
continue;
|
||||
}
|
||||
const chain = chains.get(row.id);
|
||||
const end = Math.min(top, row.until === null ? top : row.until);
|
||||
const alive = row.until === null || row.until >= top;
|
||||
const name = row.type || "Subagent";
|
||||
addLine({node: null, kind: "twig", session, sub: row.id, level: row.depth, timeline: [{name, since}], title: `${name}: ${row.description}`, alive}, (ts) => reach(chain, ts), Math.max(floor, since), end);
|
||||
if (axis !== "time" || since >= floor) {
|
||||
const moment = axis === "time" ? since : end;
|
||||
const from = point(reach(chain.slice(0, -1), moment), moment, row.depth - 1);
|
||||
const to = point(reach(chain, moment), moment, row.depth);
|
||||
arcs.push({kind: "spawn", tone: "spawn", ts: since, source: session, target: session, sub: row.id, row: -1, count: 1, from, via: {x: (from.x + to.x) / 2, y: (from.y + to.y) / 2, z: (from.z + to.z) / 2}, to});
|
||||
}
|
||||
}
|
||||
}
|
||||
const heard = radio.map((row, index) => ({row, index})).filter(({row}) => row.ts >= floor && row.ts <= top && byId.has(row.source));
|
||||
const granted = grants.map((grant, index) => ({grant, index})).filter(({grant}) => grant.ts >= floor && grant.ts <= top && byId.has(chair));
|
||||
if (axis === "time") {
|
||||
for (const {row, index} of heard) {
|
||||
connect(row.source, row.targets, TONES[row.class] || "direct", row.ts, index, 1, "message");
|
||||
}
|
||||
for (const {grant, index} of granted) {
|
||||
connect(chair, [grant.target], "grant", grant.ts, index, 1, "grant");
|
||||
}
|
||||
} else {
|
||||
const groups = new Map();
|
||||
const gather = (source, targets, tone, ts, kind) => {
|
||||
for (const target of targets.length ? targets : ["*"]) {
|
||||
const key = `${kind}\u0000${source}\u0000${target}\u0000${tone}`;
|
||||
const group = groups.get(key) || {source, target, tone, ts, kind, count: 0};
|
||||
group.count += 1;
|
||||
group.ts = Math.max(group.ts, ts);
|
||||
groups.set(key, group);
|
||||
}
|
||||
};
|
||||
for (const {row} of heard) {
|
||||
gather(row.source, row.targets, TONES[row.class] || "direct", row.ts, "message");
|
||||
}
|
||||
for (const {grant} of granted) {
|
||||
gather(chair, [grant.target], "grant", grant.ts, "grant");
|
||||
}
|
||||
for (const group of groups.values()) {
|
||||
connect(group.source, group.target === "*" ? [] : [group.target], group.tone, group.ts, -1, group.count, group.kind);
|
||||
}
|
||||
}
|
||||
const {kept, dropped} = capArcs(arcs, cap);
|
||||
const levels = [...new Set(lines.map((line) => clamp(line.level, 0, LEVELS)))].sort((a, b) => a - b);
|
||||
const guides = axis === "time" ? range.map((ts) => ({z: depthOf(axis, {ts, level: 0}, range), ts, level: 0})) : levels.map((level) => ({z: depthOf(axis, {ts: top, level}, range), ts: top, level}));
|
||||
const plane = axis === "time" ? {z: depthOf(axis, {ts: top, level: 0}, range), ts: top} : null;
|
||||
return {axis, range, span: [floor, top], lines, labels, arcs: kept, guides, plane, total: arcs.length, dropped};
|
||||
}
|
||||
|
||||
return {TONES, ARC_CAP, bend, moon, nameAt, tree, capArcs, scene};
|
||||
})();
|
||||
if (typeof module === "object" && module.exports) {
|
||||
module.exports = SpaceScene;
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
const SpaceView = (() => {
|
||||
"use strict";
|
||||
const RAD = Math.PI / 180;
|
||||
const DEFAULTS = {
|
||||
graph: {axis: "none", yaw: 30, pitch: 20, zoom: 1, pan_x: 0, pan_y: 0},
|
||||
sky: {azimuth: 180, altitude: 0, fov: 180},
|
||||
};
|
||||
const LIMITS = {
|
||||
graph: {yaw: [-180, 180], pitch: [-90, 90], zoom: [0.25, 4], pan_x: [-2000, 2000], pan_y: [-2000, 2000]},
|
||||
sky: {azimuth: [0, 360], altitude: [-30, 85], fov: [20, 240]},
|
||||
};
|
||||
const AXES = ["none", "time", "spawn"];
|
||||
const DEPTH = 600;
|
||||
const LEVELS = 4;
|
||||
const FRAME = 860;
|
||||
const DISTANCE = 1600;
|
||||
const NEAR = 120;
|
||||
const HORIZON = 0.86;
|
||||
const REACH = 0.94;
|
||||
const clamp = (value, low, high) => Math.min(Math.max(value, low), high);
|
||||
const signed = (deg) => ((((deg + 180) % 360) + 360) % 360) - 180;
|
||||
const around = (deg) => ((deg % 360) + 360) % 360;
|
||||
|
||||
function ease(progress) {
|
||||
return progress < 0.5 ? 4 * progress ** 3 : 1 - (-2 * progress + 2) ** 3 / 2;
|
||||
}
|
||||
|
||||
function turn(from, to, share) {
|
||||
const full = 2 * Math.PI;
|
||||
const delta = ((((to - from + Math.PI) % full) + full) % full) - Math.PI;
|
||||
return from + delta * share;
|
||||
}
|
||||
|
||||
function rotation(yaw, pitch) {
|
||||
const [cy, sy, cp, sp] = [Math.cos(yaw * RAD), Math.sin(yaw * RAD), Math.cos(pitch * RAD), Math.sin(pitch * RAD)];
|
||||
return [cy, 0, sy, sp * sy, cp, -sp * cy, -cp * sy, sp, cp * cy];
|
||||
}
|
||||
|
||||
function apply(matrix, point) {
|
||||
return {
|
||||
x: matrix[0] * point.x + matrix[1] * point.y + matrix[2] * point.z,
|
||||
y: matrix[3] * point.x + matrix[4] * point.y + matrix[5] * point.z,
|
||||
z: matrix[6] * point.x + matrix[7] * point.y + matrix[8] * point.z,
|
||||
};
|
||||
}
|
||||
|
||||
function camera(view, width, height) {
|
||||
return {matrix: rotation(view.yaw, view.pitch), scale: (Math.min(width, height) / FRAME) * view.zoom, panX: view.pan_x, panY: view.pan_y, cx: width / 2, cy: height / 2, width, height};
|
||||
}
|
||||
|
||||
function project(cam, point) {
|
||||
const turned = apply(cam.matrix, point);
|
||||
const reach = DISTANCE + turned.z;
|
||||
if (reach < NEAR) {
|
||||
return null;
|
||||
}
|
||||
const size = (cam.scale * DISTANCE) / reach;
|
||||
return {x: cam.cx + (turned.x + cam.panX) * size, y: cam.cy + (turned.y + cam.panY) * size, depth: turned.z, size};
|
||||
}
|
||||
|
||||
function depthSort(items) {
|
||||
return [...items].sort((a, b) => b.depth - a.depth);
|
||||
}
|
||||
|
||||
function depthOf(axis, sample, range) {
|
||||
if (axis === "time") {
|
||||
const [low, high] = range;
|
||||
const share = high > low ? clamp((sample.ts - low) / (high - low), 0, 1) : 1;
|
||||
return DEPTH * (0.5 - share);
|
||||
}
|
||||
if (axis === "spawn") {
|
||||
return -DEPTH / 2 + (DEPTH / LEVELS) * clamp(sample.level, 0, LEVELS);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function clampView(kind, view) {
|
||||
const limits = LIMITS[kind];
|
||||
const wrapped = kind === "graph" ? {...view, yaw: signed(view.yaw)} : {...view, azimuth: around(view.azimuth)};
|
||||
return Object.fromEntries(Object.entries(wrapped).map(([key, value]) => [key, Object.hasOwn(limits, key) ? clamp(value, limits[key][0], limits[key][1]) : value]));
|
||||
}
|
||||
|
||||
function tidy(view) {
|
||||
return Object.fromEntries(Object.entries(view).map(([key, value]) => [key, typeof value === "number" ? Math.round(value * 100) / 100 : value]));
|
||||
}
|
||||
|
||||
function tween(kind, from, to, share) {
|
||||
const angle = kind === "graph" ? "yaw" : "azimuth";
|
||||
return Object.fromEntries(Object.entries(to).map(([key, value]) => {
|
||||
if (typeof value !== "number") {
|
||||
return [key, value];
|
||||
}
|
||||
if (key === angle) {
|
||||
return [key, turn(from[key] * RAD, value * RAD, share) / RAD];
|
||||
}
|
||||
return [key, from[key] + (value - from[key]) * share];
|
||||
}));
|
||||
}
|
||||
|
||||
function lens(view, width, height) {
|
||||
return {matrix: rotation(-view.azimuth, -view.altitude), kx: width / view.fov, ky: ((REACH * HORIZON * height) / 90) * (180 / view.fov), cx: width / 2, cy: HORIZON * height, width, height, view};
|
||||
}
|
||||
|
||||
function place(sight, alt, az) {
|
||||
const flat = Math.cos(alt * RAD);
|
||||
const turned = apply(sight.matrix, {x: Math.sin(az * RAD) * flat, y: -Math.sin(alt * RAD), z: Math.cos(az * RAD) * flat});
|
||||
const lon = Math.atan2(turned.x, turned.z) / RAD;
|
||||
const lat = Math.asin(clamp(-turned.y, -1, 1)) / RAD;
|
||||
return {x: sight.cx + sight.kx * lon, y: sight.cy - sight.ky * lat, lon, lat};
|
||||
}
|
||||
|
||||
function horizon(sight, steps) {
|
||||
return Array.from({length: steps + 1}, (_, index) => place(sight, 0, sight.view.azimuth - 180 + (360 * index) / steps)).sort((a, b) => a.x - b.x);
|
||||
}
|
||||
|
||||
function compass(azimuth) {
|
||||
return Math.round(around(azimuth) / 45) % 8;
|
||||
}
|
||||
|
||||
return {
|
||||
DEFAULTS, LIMITS, AXES, DEPTH, LEVELS, REACH,
|
||||
clamp, ease, turn, rotation, apply, camera, project, depthSort, depthOf, clampView, tidy, tween, lens, place, horizon, compass,
|
||||
};
|
||||
})();
|
||||
if (typeof module === "object" && module.exports) {
|
||||
module.exports = SpaceView;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
const Space = (() => {
|
||||
"use strict";
|
||||
const {DEFAULTS, LIMITS, AXES, DEPTH, REACH, ease, turn, rotation, apply, camera, project, depthSort, depthOf, clampView, tidy, tween, lens, place, horizon, compass} = typeof SpaceView === "object" ? SpaceView : require("./space-view.js");
|
||||
const {TONES, ARC_CAP, bend, moon, nameAt, tree, capArcs, scene} = typeof SpaceScene === "object" ? SpaceScene : require("./space-scene.js");
|
||||
const {paint} = typeof SpacePaint === "object" ? SpacePaint : require("./space-paint.js");
|
||||
const {pick} = typeof SpacePick === "object" ? SpacePick : require("./space-pick.js");
|
||||
|
||||
return {
|
||||
DEFAULTS, LIMITS, AXES, TONES, ARC_CAP, DEPTH, REACH,
|
||||
ease, turn, bend, moon, rotation, apply, camera, project, depthSort, depthOf, clampView, tidy, tween, nameAt, tree, capArcs, scene, paint, pick,
|
||||
lens, place, horizon, compass,
|
||||
};
|
||||
})();
|
||||
if (typeof module === "object" && module.exports) {
|
||||
module.exports = Space;
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
const Voice = (() => {
|
||||
"use strict";
|
||||
const RANKS = {mayday: 0, "pan-pan": 1, security: 2};
|
||||
const ALARMS = new Set(["mayday", "pan-pan"]);
|
||||
const ROUTINE = 3;
|
||||
|
||||
function toneOf(row, human) {
|
||||
if (ALARMS.has(row.class)) {
|
||||
return "mayday";
|
||||
}
|
||||
return row.class === "security" || row.to.includes(human) ? "direct" : "radio";
|
||||
}
|
||||
|
||||
function loudness(tone, settings) {
|
||||
if (tone !== "mayday") {
|
||||
return settings.sounds[tone].volume;
|
||||
}
|
||||
return Math.max(...Object.values(settings.sounds).map((sound) => sound.volume), settings.music.volume);
|
||||
}
|
||||
|
||||
function speakable(row, speech) {
|
||||
if (!speech.on || !row.speech || !row.voice) {
|
||||
return false;
|
||||
}
|
||||
return row.class === "mayday" || (speech.classes.includes(row.class) && !speech.muted.includes(row.source));
|
||||
}
|
||||
|
||||
function rank(item) {
|
||||
return Object.hasOwn(RANKS, item.cls) ? RANKS[item.cls] : ROUTINE;
|
||||
}
|
||||
|
||||
function enqueue(pending, item, limit) {
|
||||
const at = pending.findIndex((other) => rank(other) > rank(item));
|
||||
const next = at < 0 ? [...pending, item] : [...pending.slice(0, at), item, ...pending.slice(at)];
|
||||
return next.slice(0, limit);
|
||||
}
|
||||
|
||||
function frames(duration, rate, seconds) {
|
||||
return Math.max(Math.min(Math.ceil(duration * rate), rate * seconds), 0);
|
||||
}
|
||||
|
||||
function wav(samples, rate) {
|
||||
const size = samples.length * 2;
|
||||
const buffer = new ArrayBuffer(44 + size);
|
||||
const view = new DataView(buffer);
|
||||
const text = (offset, value) => [...value].forEach((char, index) => view.setUint8(offset + index, char.charCodeAt(0)));
|
||||
text(0, "RIFF");
|
||||
view.setUint32(4, 36 + size, true);
|
||||
text(8, "WAVE");
|
||||
text(12, "fmt ");
|
||||
view.setUint32(16, 16, true);
|
||||
view.setUint16(20, 1, true);
|
||||
view.setUint16(22, 1, true);
|
||||
view.setUint32(24, rate, true);
|
||||
view.setUint32(28, rate * 2, true);
|
||||
view.setUint16(32, 2, true);
|
||||
view.setUint16(34, 16, true);
|
||||
text(36, "data");
|
||||
view.setUint32(40, size, true);
|
||||
samples.forEach((sample, index) => {
|
||||
const level = Math.max(-1, Math.min(1, sample));
|
||||
view.setInt16(44 + index * 2, level < 0 ? level * 0x8000 : level * 0x7fff, true);
|
||||
});
|
||||
return buffer;
|
||||
}
|
||||
|
||||
return {toneOf, loudness, speakable, enqueue, frames, wav};
|
||||
})();
|
||||
if (typeof module === "object" && module.exports) {
|
||||
module.exports = Voice;
|
||||
}
|
||||
Reference in new issue
Block a user