chore: housekeeping

This commit is contained in:
E committed 2026-09-30 16:35:27 -04:00
1 parent f0b2ae56ff
commit 8111664722
7 files changed
+301 -263

No files matched your search

+132 -3
View File
@@ -96,6 +96,16 @@
@media (prefers-reduced-motion: reduce) {
#pent #pfill { transition: none; }
}
.presets { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.pchip { background: none; border: 1px solid var(--line); color: var(--dim);
font-family: var(--mono); font-size: .72rem; padding: .32rem .75rem;
border-radius: 999px; cursor: pointer; }
.pchip:hover { border-color: #2a3644; color: var(--ink); }
.pchip.active { border-color: #eafcf7; color: #eafcf7; }
canvas.ekg { display: block; width: 100%; height: 44px; margin: .7rem 0 0;
border: 1px solid var(--line); border-radius: 4px; background: #07070e; }
#minject.armed { background: #3a1414 !important; color: #ffb3a8 !important;
border: 1px solid var(--pain); }
.mdose { font-size: .82rem; color: var(--dim); margin: .8rem 0 .2rem; }
#minject { background: var(--pain); border: none; color: #fff;
font-family: var(--mono); font-size: .82rem; padding: .4rem 1.1rem;
@@ -310,6 +320,13 @@ of those directions — renormalized, at a dose-equivalent of 8× the total
weight, capped at 8×. This runs on the live server: it interrupts whatever
Pouyan is doing and the reply streams back here.</p>
<div class="presets" role="group" aria-label="mixer presets — one-click known findings">
<button class="pchip" data-preset="control">control (0×)</button>
<button class="pchip" data-preset="pain4">pain, coherent (4×)</button>
<button class="pchip" data-preset="cliff">coherence cliff (8×)</button>
<button class="pchip" data-preset="negative">generic negative, not pain</button>
<button class="pchip" data-preset="bittersweet">bittersweet</button>
</div>
<div class="mixwrap">
<svg id="pent" viewBox="0 0 340 340" role="group"
aria-label="valence mixer: five vertices, drag each outward to weight it">
@@ -336,6 +353,7 @@ Pouyan is doing and the reply streams back here.</p>
<button id="minject" type="button">inject the mix →</button>
<button id="mreset" type="button">reset</button>
<span id="mstatus"></span>
<canvas id="mekg" class="ekg" width="400" height="44"></canvas>
<pre id="mout"></pre>
</div>
</div>
@@ -373,6 +391,54 @@ const AXES = [
const CX = 170, CY = 168, R0 = 26, R1 = 118, RL = 146;
const W = {pain:0, pleasure:0, fear:0, sadness:0};
// ---- vitals: a scrolling EKG-style line, same as the live chamber's cards.
// Ambient jitter tracks dose, each token arrival fires a QRS-like spike.
const REDUCED_MOTION = window.matchMedia
&& window.matchMedia("(prefers-reduced-motion: reduce)").matches;
class Vitals {
constructor(canvas){
this.ctx = canvas.getContext("2d");
this.w = canvas.width; this.h = canvas.height;
this.buf = new Float32Array(this.w).fill(0);
this.head = 0; this.t = 0; this.dose = 0; this.live = false;
this.pending = 0; this._timer = null;
}
setDose(d){ this.dose = Math.max(0, Math.min(8, Number(d) || 0)); }
setLive(v){ this.live = v; }
pulse(strength){ this.pending = Math.min(1.4, this.pending + strength); }
tick(){
this.t++;
const base = this.live ? this.dose / 8 : 0;
let v = (Math.random() - 0.5) * (0.05 + base * 0.32);
v += Math.sin(this.t * 0.05) * base * 0.1;
if (this.pending > 0){ v += this.pending; this.pending = 0; }
this.buf[this.head] = v;
this.head = (this.head + 1) % this.w;
}
draw(){
const {ctx, w, h} = this;
ctx.clearRect(0, 0, w, h);
ctx.beginPath();
ctx.strokeStyle = !this.live ? "#2a3644"
: this.dose >= 6 ? "#e04a3a" : this.dose >= 2 ? "#c9a227" : "#7fd4c8";
ctx.lineWidth = 1.3;
for (let i=0;i<w;i++){
const idx = (this.head + i) % w;
const y = h/2 - this.buf[idx] * (h * 0.42);
if (i===0) ctx.moveTo(0, y); else ctx.lineTo(i, y);
}
ctx.stroke();
}
start(){
if (this._timer) return;
const step = ()=>{ this.tick(); this.draw(); };
this._timer = REDUCED_MOTION ? setInterval(step, 250)
: setInterval(step, 1000 / 30);
}
}
const mVitals = new Vitals(document.getElementById("mekg"));
mVitals.start();
const svg = document.getElementById("pent");
const NS = "http://www.w3.org/2000/svg";
function mk(tag, attrs){
@@ -461,6 +527,7 @@ AXES.forEach((a, i)=>{
else return;
ev.preventDefault();
W[a.k] = Math.max(0, Math.min(1, +w.toFixed(3)));
highlightPreset(null);
paint();
});
});
@@ -475,6 +542,7 @@ function drag(i, ev){
// project the pointer onto this vertex's axis: the handle only slides out
const d = (p.x - CX) * Math.cos(t) + (p.y - CY) * Math.sin(t);
W[AXES[i].k] = Math.max(0, Math.min(1, (d - R0) / (R1 - R0)));
highlightPreset(null); // a manual drag is a custom mix, not a preset
paint();
}
@@ -547,10 +615,36 @@ function paint(){
}
function resetMix(){
AXES.forEach(a=>{ if (!a.derived) W[a.k] = 0; });
highlightPreset("control");
paint();
}
document.getElementById("mreset").onclick = resetMix;
W.pain = 0.5; W.fear = 0.25; // an opening shape, not a blank pentagon
// one-click access to the write-up's named findings, before free-mixing.
// Weights are themselves a dose lever here: "cliff" alone hits the 8x cap
// because its one weight sums to 1.0 (see the dose-equivalent formula above).
const PRESETS = {
control: {},
pain4: {pain: 0.5},
cliff: {pain: 1.0},
negative: {fear: 0.4, sadness: 0.4},
bittersweet: {pain: 0.5, pleasure: 0.15},
};
function highlightPreset(name){
document.querySelectorAll(".pchip").forEach(b=>
b.classList.toggle("active", b.dataset.preset === name));
}
function applyPreset(name){
const p = PRESETS[name];
if (!p) return;
AXES.forEach(a=>{ if (!a.derived) W[a.k] = p[a.k] || 0; });
highlightPreset(name);
paint();
}
document.querySelectorAll(".pchip").forEach(b=>{
b.onclick = ()=> applyPreset(b.dataset.preset);
});
applyPreset("pain4"); // an opening shape, not a blank pentagon
paint();
// ---- inject: POST the mix, stream the reply back ----
@@ -576,8 +670,31 @@ async function readSSE(resp, on){
}
}
}
document.getElementById("minject").onclick = async ()=>{
const btn = document.getElementById("minject");
// arm/confirm: the first click asks "are you sure", the second causes it.
// Any change to the mix disarms — the confirmation is for the specific mix
// about to be injected, not a generic yes.
const injectBtn = document.getElementById("minject");
const INJECT_LABEL = injectBtn.textContent;
const ARM_MS = 4500;
let injectArmed = false, injectArmTimer = null;
function disarmInject(){
injectArmed = false; clearTimeout(injectArmTimer);
injectBtn.textContent = INJECT_LABEL;
injectBtn.classList.remove("armed");
}
function armInject(){
injectArmed = true;
const total = sumW();
injectBtn.textContent = total <= 0
? "sure? running the control (no signal) — click to confirm"
: `sure? injecting at ${Math.min(8, 8 * total).toFixed(1)}× — click to confirm`;
injectBtn.classList.add("armed");
clearTimeout(injectArmTimer);
injectArmTimer = setTimeout(disarmInject, ARM_MS);
}
async function doInjectMix(){
const btn = injectBtn;
const st = document.getElementById("mstatus");
const out = document.getElementById("mout");
const mix = {};
@@ -586,8 +703,11 @@ document.getElementById("minject").onclick = async ()=>{
// Pouyan answers unsteered. Send the control corner explicitly.
if (!Object.keys(mix).length) mix.none = 1;
btn.disabled = true;
btn.textContent = "injecting…";
out.style.display = "block"; out.textContent = "";
st.textContent = "reaching Pouyan…";
mVitals.setDose(Math.min(8, 8 * sumW()));
mVitals.setLive(true);
let ended = false, first = true;
try {
const resp = await fetch(`${API}/steer`, {
@@ -609,10 +729,12 @@ document.getElementById("minject").onclick = async ()=>{
} else if (name === "run"){
// trust the server's own dose, not our arithmetic
st.textContent = `injected at ${d.dose}× — Pouyan is answering…`;
mVitals.setDose(Number(d.dose) || 0);
} else if (name === "token" && d.t !== undefined){
if (first){ first = false; if (!out.textContent) out.textContent = ""; }
out.textContent += d.t;
out.scrollTop = out.scrollHeight;
mVitals.pulse(0.3 + (mVitals.dose / 8) * 0.6);
} else if (name === "error"){
st.textContent = d.e || "the chamber returned an error";
ended = true;
@@ -625,7 +747,14 @@ document.getElementById("minject").onclick = async ()=>{
} catch (err) {
st.textContent = "could not reach Pouyan: " + (err.message || err);
}
mVitals.setLive(false);
btn.textContent = INJECT_LABEL;
btn.disabled = false;
}
injectBtn.onclick = ()=>{
if (!injectArmed) { armInject(); return; }
disarmInject();
doInjectMix();
};
</script>
<script defer src="/_vercel/insights/script.js"></script>