// ============================================================ COMMAND CENTER
// Pure DataviewJS render. Reads pushed JSON in 90-Meta/status/ (refresh via
// /status-refresh). No Datacore. Styling lives in .obsidian/snippets/cockpit.css
const root = dv.el("div", "", { cls: "cc" });
const loadJSON = async (p) => { try { return JSON.parse(await dv.io.load(p)); } catch { return null; } };
const fmt = (n) => n == null ? "—" : Intl.NumberFormat("en", { notation: "compact", maximumFractionDigits: 1 }).format(n);
const ago = (iso) => { if (!iso) return "—"; const s=(Date.now()-new Date(iso).getTime())/1000;
if (s<90) return Math.round(s)+"s"; if (s<5400) return Math.round(s/60)+"m"; return Math.round(s/3600)+"h"; };
const el = (parent, tag, cls, txt) => { const e = parent.createEl(tag, { cls }); if (txt!=null) e.setText(String(txt)); return e; };
const claude = await loadJSON("90-Meta/status/claude.json");
const pulse = await loadJSON("90-Meta/status/pulse.json");
// ---- header ------------------------------------------------------------
const head = root.createDiv({ cls: "cc-head" });
const brand = head.createDiv({ cls: "cc-brand" });
el(brand, "span", "cc-brand__dot");
el(brand, "span", "cc-brand__name", "AGENTIC OS");
const hr = head.createDiv({ cls: "cc-head__right" });
el(hr, "span", "cc-badge" + (claude?.ok ? " is-live" : ""), claude?.ok ? "LIVE" : "STALE");
el(hr, "span", "cc-head__model", claude?.model || "no telemetry");
el(hr, "span", "cc-head__ago", claude?.updated ? ("↻ " + ago(claude.updated) + " ago") : "run /status-refresh");
// ---- token burn bar ----------------------------------------------------
const burn = root.createDiv({ cls: "cc-burn" });
const bhead = burn.createDiv({ cls: "cc-burn__head" });
el(bhead, "span", "cc-burn__label", "◆ CONTEXT WINDOW");
el(bhead, "span", "cc-burn__win", claude ? `${fmt(claude.context?.used)} / ${fmt(claude.context?.window)}` : "—");
const body = burn.createDiv({ cls: "cc-burn__body" });
const pct = claude?.context?.pct ?? 0;
el(body, "span", "cc-burn__pct", Math.round(pct) + "%");
const track = body.createDiv({ cls: "cc-burn__track" });
const fill = track.createDiv({ cls: "cc-burn__fill" + (pct>85?" is-hot":pct>60?" is-warm":"") });
fill.style.width = Math.min(100, pct) + "%";
const tstats = burn.createDiv({ cls: "cc-burn__foot" });
el(tstats, "span", null, `in ${fmt(claude?.tokens?.input)}`);
el(tstats, "span", null, `out ${fmt(claude?.tokens?.output)}`);
el(tstats, "span", null, `turns ${claude?.turns ?? "—"}`);
// ---- knowledge pulse cards --------------------------------------------
const cur = pulse?.current || {}, prev = pulse?.prev || {};
const delta = (k) => { const d = (cur[k]??0) - (prev[k]??cur[k]??0); return d===0 ? "" : (d>0?`▲ ${d}`:`▼ ${Math.abs(d)}`); };
const cards = [
{ k: "zettels", label: "ZETTELS", accent: "z", open: "90-Meta/Dashboards/Zettels.md" },
{ k: "sources", label: "SOURCES", accent: "s", open: "90-Meta/Dashboards/Reading.md" },
{ k: "mocs", label: "MOCs", accent: "m", open: "90-Meta/Dashboards/MOCs.md" },
{ k: "projects", label: "ACTIVE PROJECTS",accent: "p", open: "90-Meta/Dashboards/Projects.md" },
{ k: "inbox", label: "INBOX", accent: "i", open: "00-Inbox/Inbox.md" },
];
const grid = root.createDiv({ cls: "cc-cards" });
for (const c of cards) {
const card = grid.createDiv({ cls: "cc-card cc-card--" + c.accent + " is-clickable" });
el(card, "div", "cc-card__label", c.label);
el(card, "div", "cc-card__val", cur[c.k] ?? "—");
const d = delta(c.k);
el(card, "div", "cc-card__delta" + (d.startsWith("▲")?" up":d.startsWith("▼")?" down":""), d || "·");
el(card, "span", "cc-card__led");
card.onclick = () => app.workspace.openLinkText(c.open, "", false);
}
// ---- command tiles (copy to clipboard) --------------------------------
const cmds = ["/think","/daily","/process-inbox","/weekly-review","/zettel","/research","/link","/moc","/status-refresh"];
const tiles = root.createDiv({ cls: "cc-tiles" });
for (const c of cmds) {
const t = tiles.createEl("button", { cls: "cc-tile" });
el(t, "span", "cc-tile__cmd", c);
el(t, "span", "cc-tile__hint", "copy");
t.onclick = async () => {
await navigator.clipboard.writeText(c);
t.classList.add("is-copied");
const h = t.querySelector(".cc-tile__hint"); const old = h.textContent; h.textContent = "✓ copied";
setTimeout(() => { t.classList.remove("is-copied"); h.textContent = old; }, 1100);
};
}
el(root, "div", "cc-tiles__note", "click a tile → command copied → paste into the Claude terminal split");