Add state-hub v0.1 — local-first state service for the Custodian
Implements the first live layer of the Custodian cognitive infrastructure:
PostgreSQL schema, FastAPI REST API, FastMCP stdio server, and Observable
Framework telemetry dashboard.
- state-hub/: full stack (docker-compose, FastAPI, Alembic, MCP server, dashboard)
- 5 DB tables: topics, workstreams, tasks, decisions, progress_events
- 11 MCP tools + 5 resources registered in .mcp.json
- Observable dashboard: Overview, Workstreams, Decisions, Progress pages
- CLAUDE.md: session protocol (get_state_summary / add_progress_event ritual)
- ~/.claude/CLAUDE.md: global cross-project reference to the hub
- scripts/pull_image.py: WSL2 TLS-resilient Docker image downloader
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-24 17:47:49 +01:00
|
|
|
---
|
|
|
|
|
title: Progress
|
|
|
|
|
---
|
|
|
|
|
|
2026-02-24 23:19:26 +01:00
|
|
|
```js
|
2026-05-06 04:04:53 +02:00
|
|
|
import {POLL_HEAVY, apiFetch, pollDelay, sleep} from "./components/config.js";
|
2026-02-24 23:19:26 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
const progState = (async function*() {
|
2026-05-06 04:04:53 +02:00
|
|
|
let failures = 0;
|
2026-02-24 23:19:26 +01:00
|
|
|
while (true) {
|
2026-03-30 00:42:09 +02:00
|
|
|
let data = [], tokenEvents = [], ok = false;
|
2026-02-24 23:19:26 +01:00
|
|
|
try {
|
2026-03-30 00:42:09 +02:00
|
|
|
const [r1, r2] = await Promise.all([
|
2026-05-06 04:04:53 +02:00
|
|
|
apiFetch("/progress/?limit=500"),
|
|
|
|
|
apiFetch("/token-events/?limit=1000"),
|
2026-03-30 00:42:09 +02:00
|
|
|
]);
|
|
|
|
|
ok = r1.ok;
|
|
|
|
|
data = ok ? await r1.json() : [];
|
|
|
|
|
tokenEvents = r2.ok ? await r2.json() : [];
|
2026-02-24 23:19:26 +01:00
|
|
|
} catch {}
|
2026-05-06 04:04:53 +02:00
|
|
|
failures = ok ? 0 : failures + 1;
|
2026-03-30 00:42:09 +02:00
|
|
|
yield {data, tokenEvents, ok, ts: new Date()};
|
2026-05-06 04:04:53 +02:00
|
|
|
await sleep(pollDelay({ok, base: POLL_HEAVY, failures}));
|
2026-02-24 23:19:26 +01:00
|
|
|
}
|
|
|
|
|
})();
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```js
|
2026-03-30 00:42:09 +02:00
|
|
|
const data = progState.data ?? [];
|
|
|
|
|
const tokenEvents = progState.tokenEvents ?? [];
|
|
|
|
|
const _ok = progState.ok ?? false;
|
2026-02-24 23:19:26 +01:00
|
|
|
const _ts = progState.ts;
|
|
|
|
|
```
|
|
|
|
|
|
Add state-hub v0.1 — local-first state service for the Custodian
Implements the first live layer of the Custodian cognitive infrastructure:
PostgreSQL schema, FastAPI REST API, FastMCP stdio server, and Observable
Framework telemetry dashboard.
- state-hub/: full stack (docker-compose, FastAPI, Alembic, MCP server, dashboard)
- 5 DB tables: topics, workstreams, tasks, decisions, progress_events
- 11 MCP tools + 5 resources registered in .mcp.json
- Observable dashboard: Overview, Workstreams, Decisions, Progress pages
- CLAUDE.md: session protocol (get_state_summary / add_progress_event ritual)
- ~/.claude/CLAUDE.md: global cross-project reference to the hub
- scripts/pull_image.py: WSL2 TLS-resilient Docker image downloader
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-24 17:47:49 +01:00
|
|
|
# Progress Log
|
|
|
|
|
|
|
|
|
|
```js
|
dashboard: move live indicator to TOC sidebar on all pages; add live-data docs
- All four pages (index, workstreams, decisions, progress) now inject the
live indicator into #observablehq-toc via injectTocTop("live-indicator", el)
Left-aligned (no text-align: right), position:relative + padding-right for
the ? button affordance
- decisions.md: splits the former combined "decisions-sidebar" widget into two
separate injectTocTop calls — KPI box first (ends lower), live indicator
second (ends at top); both now have their own stable ids
- withDocHelp(_liveEl, "/docs/live-data") wires the ? button on every page
- src/docs/live-data.md: new documentation page explaining poll interval (15s),
indicator colour semantics, offline recovery, and which endpoints each page hits
- Removes the .live-bar CSS class from all pages; replaces with .live-indicator
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-26 16:18:09 +01:00
|
|
|
import {injectTocTop} from "./components/toc-sidebar.js";
|
|
|
|
|
import {withDocHelp} from "./components/doc-overlay.js";
|
|
|
|
|
|
|
|
|
|
const _liveEl = html`<div class="live-indicator">
|
2026-02-24 23:19:26 +01:00
|
|
|
<span style="color:${_ok ? 'var(--theme-foreground-focus)' : 'red'}">●</span>
|
|
|
|
|
${_ok
|
|
|
|
|
? `Live · updated ${_ts?.toLocaleTimeString()} · ${data.length} events total`
|
dashboard: move live indicator to TOC sidebar on all pages; add live-data docs
- All four pages (index, workstreams, decisions, progress) now inject the
live indicator into #observablehq-toc via injectTocTop("live-indicator", el)
Left-aligned (no text-align: right), position:relative + padding-right for
the ? button affordance
- decisions.md: splits the former combined "decisions-sidebar" widget into two
separate injectTocTop calls — KPI box first (ends lower), live indicator
second (ends at top); both now have their own stable ids
- withDocHelp(_liveEl, "/docs/live-data") wires the ? button on every page
- src/docs/live-data.md: new documentation page explaining poll interval (15s),
indicator colour semantics, offline recovery, and which endpoints each page hits
- Removes the .live-bar CSS class from all pages; replaces with .live-indicator
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-26 16:18:09 +01:00
|
|
|
: html`<span style="color:red">Offline — run: <code>make api</code></span>`}
|
|
|
|
|
</div>`;
|
|
|
|
|
withDocHelp(_liveEl, "/docs/live-data");
|
|
|
|
|
injectTocTop("live-indicator", _liveEl);
|
2026-02-26 18:03:05 +01:00
|
|
|
|
|
|
|
|
const _h1 = document.querySelector("#observablehq-main h1");
|
|
|
|
|
if (_h1) { _h1.style.position = "relative"; withDocHelp(_h1, "/docs/progress-log"); }
|
Add state-hub v0.1 — local-first state service for the Custodian
Implements the first live layer of the Custodian cognitive infrastructure:
PostgreSQL schema, FastAPI REST API, FastMCP stdio server, and Observable
Framework telemetry dashboard.
- state-hub/: full stack (docker-compose, FastAPI, Alembic, MCP server, dashboard)
- 5 DB tables: topics, workstreams, tasks, decisions, progress_events
- 11 MCP tools + 5 resources registered in .mcp.json
- Observable dashboard: Overview, Workstreams, Decisions, Progress pages
- CLAUDE.md: session protocol (get_state_summary / add_progress_event ritual)
- ~/.claude/CLAUDE.md: global cross-project reference to the hub
- scripts/pull_image.py: WSL2 TLS-resilient Docker image downloader
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-24 17:47:49 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## Event Volume (Last 30 Days)
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
import * as Plot from "npm:@observablehq/plot";
|
|
|
|
|
|
2026-02-24 23:19:26 +01:00
|
|
|
const cutoff = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000);
|
2026-03-30 00:48:22 +02:00
|
|
|
|
2026-02-24 23:19:26 +01:00
|
|
|
const byDay = Object.entries(
|
|
|
|
|
data
|
|
|
|
|
.filter(e => new Date(e.created_at) >= cutoff)
|
2026-03-30 00:48:22 +02:00
|
|
|
.reduce((acc, e) => { const d = e.created_at.slice(0, 10); acc[d] = (acc[d] ?? 0) + 1; return acc; }, {})
|
2026-02-24 23:19:26 +01:00
|
|
|
).sort().map(([day, count]) => ({day, count}));
|
|
|
|
|
|
2026-03-30 00:42:09 +02:00
|
|
|
const tokensByDay = Object.entries(
|
|
|
|
|
tokenEvents
|
|
|
|
|
.filter(e => new Date(e.created_at) >= cutoff)
|
2026-03-30 00:48:22 +02:00
|
|
|
.reduce((acc, e) => { const d = e.created_at.slice(0, 10); acc[d] = (acc[d] ?? 0) + (e.tokens_in || 0) + (e.tokens_out || 0); return acc; }, {})
|
2026-03-30 00:42:09 +02:00
|
|
|
).sort().map(([day, tokens]) => ({day, tokens}));
|
|
|
|
|
|
2026-03-30 00:48:22 +02:00
|
|
|
// Scale tokens onto the events axis for dual-axis display
|
|
|
|
|
const maxEvents = Math.max(1, ...byDay.map(d => d.count));
|
|
|
|
|
const maxTokens = Math.max(1, ...tokensByDay.map(d => d.tokens));
|
|
|
|
|
const ratio = maxTokens / maxEvents;
|
|
|
|
|
const fmtTokens = v => { const t = v * ratio; return t >= 1e6 ? (t/1e6).toFixed(1)+"M" : t >= 1e3 ? Math.round(t/1e3)+"k" : String(Math.round(t)); };
|
|
|
|
|
|
|
|
|
|
display(byDay.length === 0
|
|
|
|
|
? html`<p style="color:gray">No events in the last 30 days.</p>`
|
2026-03-30 00:42:09 +02:00
|
|
|
: Plot.plot({
|
2026-03-30 00:48:22 +02:00
|
|
|
title: "Progress events & tokens per day (30-day window)",
|
2026-03-30 00:42:09 +02:00
|
|
|
x: {label: "Date", tickRotate: -30},
|
2026-03-30 00:48:22 +02:00
|
|
|
y: {label: "← Events", grid: true},
|
|
|
|
|
marginBottom: 60,
|
|
|
|
|
marginRight: tokensByDay.length > 0 ? 70 : 20,
|
|
|
|
|
width: 750,
|
2026-03-30 00:42:09 +02:00
|
|
|
marks: [
|
2026-03-30 00:48:22 +02:00
|
|
|
Plot.areaY(byDay, {x: "day", y: "count", fill: "steelblue", fillOpacity: 0.25}),
|
|
|
|
|
Plot.lineY(byDay, {x: "day", y: "count", stroke: "steelblue", strokeWidth: 1.5}),
|
|
|
|
|
Plot.tip(byDay, Plot.pointerX({x: "day", y: "count",
|
|
|
|
|
title: d => `${d.day}\n${d.count} event${d.count === 1 ? "" : "s"}`})),
|
|
|
|
|
...(tokensByDay.length > 0 ? [
|
|
|
|
|
Plot.areaY(tokensByDay, {x: "day", y: d => d.tokens / ratio, fill: "#f28e2b", fillOpacity: 0.2}),
|
|
|
|
|
Plot.lineY(tokensByDay, {x: "day", y: d => d.tokens / ratio, stroke: "#f28e2b", strokeWidth: 1.5}),
|
|
|
|
|
Plot.tip(tokensByDay, Plot.pointerX({x: "day", y: d => d.tokens / ratio,
|
|
|
|
|
title: d => `${d.day}\n${d.tokens.toLocaleString()} tokens`})),
|
|
|
|
|
Plot.axisY({anchor: "right", label: "Tokens →", tickFormat: fmtTokens}),
|
|
|
|
|
] : []),
|
2026-03-30 00:42:09 +02:00
|
|
|
Plot.ruleY([0]),
|
|
|
|
|
],
|
|
|
|
|
})
|
|
|
|
|
);
|
2026-03-30 00:48:22 +02:00
|
|
|
|
|
|
|
|
if (byDay.length > 0) display(html`<div style="font-size:0.78rem;display:flex;gap:1.2rem;margin-top:0.4rem;color:var(--theme-foreground-muted)">
|
|
|
|
|
<span><span style="color:steelblue">▬</span> Events (left axis)</span>
|
|
|
|
|
${tokensByDay.length > 0 ? html`<span><span style="color:#f28e2b">▬</span> Tokens (right axis)</span>` : html`<span style="font-style:italic">No token data yet</span>`}
|
|
|
|
|
</div>`);
|
2026-03-30 00:42:09 +02:00
|
|
|
```
|
|
|
|
|
|
2026-02-26 17:06:28 +01:00
|
|
|
## Event Log
|
|
|
|
|
|
2026-02-26 16:49:33 +01:00
|
|
|
```js
|
|
|
|
|
const authorOpts = ["(all)", ...new Set(data.map(e => e.author ?? "unknown"))].sort();
|
|
|
|
|
const typeOpts = ["(all)", ...new Set(data.map(e => e.event_type))].sort();
|
|
|
|
|
|
|
|
|
|
const authorFilter = view(Inputs.select(authorOpts, {label: "Author"}));
|
|
|
|
|
const typeFilter = view(Inputs.select(typeOpts, {label: "Event type"}));
|
|
|
|
|
const sinceFilter = view(Inputs.date({label: "Since"}));
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
```js
|
|
|
|
|
const filtered = data.filter(e =>
|
|
|
|
|
(authorFilter === "(all)" || (e.author ?? "unknown") === authorFilter) &&
|
|
|
|
|
(typeFilter === "(all)" || e.event_type === typeFilter) &&
|
|
|
|
|
(!sinceFilter || new Date(e.created_at) >= sinceFilter)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
display(html`<p><strong>${filtered.length}</strong> events shown (append-only, no deletions).</p>`);
|
|
|
|
|
|
|
|
|
|
display(Inputs.table(filtered.map(e => ({
|
|
|
|
|
Time: new Date(e.created_at).toLocaleString(),
|
|
|
|
|
Type: e.event_type,
|
|
|
|
|
Author: e.author ?? "—",
|
|
|
|
|
Summary: e.summary,
|
|
|
|
|
})), {rows: 50}));
|
|
|
|
|
```
|
|
|
|
|
|
2026-02-24 23:19:26 +01:00
|
|
|
<style>
|
2026-02-26 16:42:00 +01:00
|
|
|
.live-indicator { font-size: 0.8rem; color: gray; position: relative; padding: 0.55rem 1.8rem 0.55rem 0.7rem; margin-bottom: 0.75rem; }
|
2026-02-24 23:19:26 +01:00
|
|
|
</style>
|