From d2071087106037ec98f2541d9cadb158a7e6ab89 Mon Sep 17 00:00:00 2001 From: Jammy2211 Date: Fri, 9 Oct 2026 15:33:59 +0100 Subject: [PATCH] feat: embed Scientist as the cockpit home --- AGENTS.md | 11 ++- README.md | 28 +++--- cockpit/index.html | 194 ++++------------------------------------ cockpit/sw.js | 2 +- tests/cockpit-state.cjs | 29 +++--- 5 files changed, 53 insertions(+), 211 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 6854300..7a1214a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -39,10 +39,11 @@ duplicating it. `cockpit/` is the organ cockpit — an installable PWA at `/cockpit/` that reads each organ's `https://pyautolabs.github.io//state.json` (same origin as -the page) and renders the Heart strip plus one card per organ in canonical +the page) for shell status and notifications. PyAutoScientist owns the home +overview cards; the shell embeds that canonical page. Organ tabs retain their order (Brain, Mind, Cortex, Broca, Memory, Eyes, Ears, Heart, Hands, Pulse, Insight, DNA, Nerves, Gut). -- **Integrated boards:** persistent icon/label navigation selects Overview or a +- **Integrated boards:** persistent icon/label navigation selects Scientist (the default PyAutoScientist home) or a board at `/cockpit/#` (lowercase). A single titled iframe displays only known organ paths on `https://pyautolabs.github.io`; other destinations remain external. Use child `location.replace` when switching so shell routes own @@ -139,3 +140,9 @@ Before changing a shared interface, consult the applicable on demand, identify affected consumers, and validate their adoption. Change generated guidance at its canonical source and regenerate. + +Scientist is separate from the monitored ORGANS list: it has no synthetic health +feed and must not aggregate itself. Empty routes and legacy `#overview` resolve +to `#scientist`. The Scientist repository owns home presentation, polling, +reporting guidance and the copyable prompt. The shell preserves its frame while +polling, and retains safe link interception and Back/Forward behavior. diff --git a/README.md b/README.md index 72b7a23..cf1e9ff 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ local notification when any organ's status changes. No server, no secrets: the feeds are the truth. Choose an organ from the icon-and-label bar to open its board inside the cockpit. -**Overview** returns to the status cards. Board selections have bookmarkable URLs +**Scientist** returns to the status cards. Board selections have bookmarkable URLs (for example `/cockpit/#heart`), and browser Back/Forward follows those selections. The bar scrolls horizontally on phones; landscape mode makes it more compact. Reload refreshes the selected board, while **New tab** explicitly opens it separately. @@ -61,18 +61,15 @@ be integrated with the shell; test full navigation on the shared Pages origin. ### Actionable state and freshness The cockpit remains a human interface over the organs' shared `state.json` -feeds. Brain's optional v1 metadata adds reasons, labelled actions and explicit -human decisions. It renders old and enriched feeds together. Actions link to -evidence or copy existing commands/prompts; viewing a problem never executes -its remedy. Approval and scientific-judgement labels describe the source's -constraints, and missing safety information is unclassified. - -Cards distinguish feed generation from the browser's last check. Failed fetches -show last-known results as stale, keeping previous failures visible. Invalid or -future timestamps cannot show current green. Producer-declared `valid_until` -deadlines are respected; without one the cockpit displays the age and invents -no expiry interval. Source verdicts, transport failure and freshness stay -separate. No persistent agent or new notification service is included. +feeds. Scientist selects concise summaries from old and enriched feeds; links +lead to the owning evidence and boards. The work panel copies a prompt, and +viewing a problem never executes its remedy. + +Scientist cards label source timestamps and retain last-known evidence when +fetching fails. Invalid or future timestamps cannot show current green. +Producer-declared `valid_until` deadlines are respected; without one, source +age is displayed without inventing an expiry interval. Source verdicts, +transport failure and freshness stay separate. Run the dependency-free contract/model checks with `node --test tests/cockpit-state.cjs`. Browser checks should additionally cover @@ -80,3 +77,8 @@ mobile/light/dark layout, clipboard, navigation and a selected board remaining in place during polling. The runtime still needs no packages or build step. - Insight reads the [inference campaign board](https://pyautolabs.github.io/PyAutoInsight/) organ feed; project inference feeds remain on their project dashboards. + +The first cockpit tab embeds the canonical PyAutoScientist dashboard: its +banner, work prompt and compact organ disclosures. Old `#overview` links still +open this Scientist home. Ask the Scientist for a summary over the last 24 hours +or another period; historical evidence stays with the owning organs. diff --git a/cockpit/index.html b/cockpit/index.html index e78ee3f..a4e10b7 100644 --- a/cockpit/index.html +++ b/cockpit/index.html @@ -81,51 +81,8 @@ .sev-info { --st: var(--info); } .word { font-weight: 700; text-transform: uppercase; font-size: 0.78rem; letter-spacing: 0.04em; color: var(--st, var(--grey)); } - main { padding: 1.2rem 0 2.5rem; } - .heart { - background: var(--bg-alt); border: 1px solid var(--line); border-left: 6px solid var(--st, var(--grey)); - border-radius: 12px; padding: 1rem 1.2rem; margin-bottom: 1.2rem; transition: box-shadow 0.2s; - } - .heart.flash { animation: flash 0.6s ease-in-out 5; } - @keyframes flash { 50% { box-shadow: 0 0 0 4px var(--st, var(--brand)); border-color: var(--st, var(--brand)); } } - .heart h2 { font-size: 1.15rem; display: flex; align-items: center; gap: 0.5em; flex-wrap: wrap; } - .heart .headline { font-size: 1.05rem; margin: 0.2rem 0 0.4rem; } - - .cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 1rem; } - .card { - background: var(--card-bg); border: 1px solid var(--line); border-radius: 12px; - padding: 1rem 1.1rem 0.9rem; display: flex; flex-direction: column; - border-top: 3px solid var(--st, var(--grey)); min-width: 0; - } - .card h3 { font-size: 1.1rem; display: flex; align-items: center; gap: 0.5em; flex-wrap: wrap; } - .panel-name { display: inline-flex; align-items: center; gap: 0.4em; } - .panel-icon { flex: none; font-size: 1.25em; line-height: 1; } - .card h3 .word { margin-left: auto; } - .headline { margin: 0.35rem 0 0.2rem; overflow-wrap: anywhere; } - .meta { color: var(--text-soft); font-size: 0.82rem; } - .meta .warn { color: var(--stale); font-weight: 600; } - ul.items { list-style: none; margin: 0.6rem 0 0.2rem; display: flex; flex-direction: column; gap: 0.35rem; flex: 1; } - ul.items li { display: flex; align-items: flex-start; gap: 0.45rem; font-size: 0.88rem; } - ul.items li .dot { margin-top: 0.42em; width: 0.55em; height: 0.55em; } - ul.items li .t { flex: 1; min-width: 0; overflow-wrap: anywhere; } - ul.items li.more { color: var(--text-soft); font-size: 0.82rem; padding-left: 1rem; } - .card .foot { margin-top: 0.7rem; font-size: 0.88rem; font-weight: 600; } - .empty { color: var(--text-soft); font-size: 0.9rem; margin-top: 0.4rem; } - - button.copy { - flex: none; width: 2rem; height: 1.7rem; border: 1px solid var(--line); border-radius: 6px; - background: var(--code-bg); color: var(--text); cursor: pointer; font-size: 0.85rem; line-height: 1; - } - .reason, .decision { display: block; margin-top: 0.25rem; } - .reason, .action-safety { color: var(--text-soft); font-size: 0.8rem; } - .decision { border-left: 3px solid var(--yellow); padding-left: 0.5rem; } - ul.items .actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; margin: 0.35rem 0; } - ul.items .action, ul.items button.copy.action { display: inline-flex; align-items: center; min-height: 44px; width: auto; height: auto; padding: 0.45rem 0.6rem; white-space: normal; text-align: left; line-height: 1.3; } - button.copy:hover { border-color: var(--brand); } - button.copy.ok { border-color: var(--green); color: var(--green); } - - footer { color: var(--text-soft); font-size: 0.85rem; text-align: center; padding: 0 0 2.5rem; } - footer p + p { margin-top: 0.3rem; } + .overall.flash { animation: flash 0.6s ease-in-out 5; } + @keyframes flash { 50% { box-shadow: 0 0 0 4px var(--st, var(--brand)); } } [hidden] { display: none !important; } html, body { height: 100%; } @@ -153,10 +110,6 @@ .board-link .dot { position: absolute; right: 9px; top: 8px; width: 8px; height: 8px; } .nav-hint { text-align: right; color: var(--text-soft); font-size: 0.7rem; padding: 0 0.75rem 0.2rem; } .view { flex: 1; min-height: 0; min-width: 0; } - #overview { overflow: auto; overscroll-behavior: contain; padding-bottom: env(safe-area-inset-bottom); } - #overview h1 { font-size: 1.35rem; margin-bottom: 0.1rem; } - .intro { color: var(--text-soft); margin-bottom: 1.2rem; font-size: 0.9rem; } - #overview footer { padding-top: 1.5rem; } #board-view { display: flex; flex-direction: column; padding: 0; } .board-toolbar { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; padding: 0.3rem max(0.65rem, env(safe-area-inset-left)); border-bottom: 1px solid var(--line); } @@ -169,14 +122,12 @@ #board-status { font-size: 0.75rem; color: var(--text-soft); overflow-wrap: anywhere; } #board-stage { flex: 1; min-height: 0; display: flex; padding-bottom: env(safe-area-inset-bottom); } #board-stage iframe { display: block; border: 0; width: 100%; height: 100%; min-width: 0; background: var(--bg); } - button.bell, button.copy { min-width: 44px; min-height: 44px; } - .card .foot a, .heart h2 a { display: inline-flex; min-height: 44px; align-items: center; } + button.bell { min-width: 44px; min-height: 44px; } @media (max-width: 420px) { .topbar .home span { display: none; } .topbar .wrap { padding-inline: 0.65rem; } .board-link { min-width: 70px; } .action .action-label { display: none; } - .card { padding-inline: 0.85rem; } } @media (max-height: 500px) and (orientation: landscape) { body.board-open .topbar { display: none; } @@ -208,22 +159,7 @@ -
-
-

Your cockpit

-

One place for every organ. Choose a board above to take a closer look.

-

Heart

loading…

-
-
-
-
-

not polled yet

-

-
-
-
- -
+

@@ -254,9 +190,10 @@

Your cockpit

{ organ: "Nerves", icon: "⚡", repo: "PyAutoNerves", feed: BASE + "PyAutoNerves/state.json" }, { organ: "Gut", icon: "♻️", repo: "PyAutoGut", feed: BASE + "PyAutoGut/state.json" }, ]; -const PINNED = "Heart"; +// Scientist is the home board, not a monitored organ (no recursive aggregate). +const SCIENTIST = { organ: "Scientist", icon: "🔭", repo: "PyAutoScientist", feed: null }; +const BOARDS = [SCIENTIST, ...ORGANS]; const POLL_MS = 60000; -const MAX_ITEMS = 8; const STATUSES = ["green", "yellow", "red", "stale", "grey"]; const SEVERITIES = ["red", "yellow", "info"]; // Worst first: what the header shows when organs disagree. @@ -384,73 +321,11 @@

Your cockpit

return d ? d.items.filter(i => i.severity === "red").length : 0; } -const SAFETY_LABEL = { read_only: "Read only", requires_approval: "Approval required", - scientific_judgement: "Scientific judgement", never_automatic: "Manual only", unclassified: "Safety unclassified" }; -function actionsHtml(it) { - const actions = it.actions || []; - const rendered = actions.map(action => { - const recommended = action.id === it.recommended_action_id; - const safety = SAFETY_LABEL[action.safety || "unclassified"]; - const title = (recommended ? "Recommended · " : "") + safety; - if (action.kind === "link") return `${esc(action.label)}`; - return `${esc(safety)}`; - }); - if (it.prompt && !actions.some(a => a.kind !== "link" && a.target === it.prompt)) rendered.push(``); - return rendered.length ? `${rendered.join("")}` : ""; -} -function itemsHtml(items, current = true) { - if (!items.length) return `

${current ? "nothing needs you" : "no attention items in the last known feed"}

`; - const shown = items.slice(0, MAX_ITEMS).map(it => { - const url = safeUrl(it.url); - const text = url ? `${esc(it.text)}` : esc(it.text); - const reason = it.reason ? `${esc(it.reason)}` : ""; - const decision = it.requires_human_decision ? `Your decision: ${esc(it.decision)}` : ""; - const sev = it.severity === "info" ? "sev-info" : "s-" + it.severity; - return `
  • ${text}${reason}${decision}${actionsHtml(it)}
  • `; - }); - if (items.length > MAX_ITEMS) shown.push(`
  • + ${items.length - MAX_ITEMS} more on the board
  • `); - return `
      ${shown.join("")}
    `; -} - -function metaHtml(o) { - if (!o.feed) return '

    no feed yet

    '; - const v = viewFor(o), st = state[o.organ] || {}, d = v.feed; - const generated = d ? `generated ${esc(age(d.updated))}` : ""; - const checked = st.lastChecked ? `checked ${esc(age(st.lastChecked))}` : ""; - const warning = v.reason ? `${esc(v.reason)}${d ? " · last known " + esc(d.status) : ""}` : ""; - return `

    ${[warning, generated, checked].filter(Boolean).join(" · ")}

    `; -} - function boardUrl(o) { const d = feedFor(o); return safeUrl(d && d.pages_url) || BASE + o.repo + "/"; } -function cardHtml(o) { - const status = o.feed ? effective(o) : "grey"; - const d = feedFor(o); - const word = !o.feed ? "no feed" : (state[o.organ] || {}).error && !d ? "unknown" : status; - const head = !o.feed ? '

    This organ does not publish a state.json yet.

    ' - : d ? `

    ${esc(d.headline)}

    ` : ""; - return `
    -

    ${esc(o.organ)}${esc(word)}

    - ${head}${metaHtml(o)}${d ? itemsHtml(d.items, viewFor(o).current) : ""} - -
    `; -} - -function renderHeart() { - const o = ORGANS.find(x => x.organ === PINNED); - const el = document.getElementById("heart"); - if (!o) { el.hidden = true; return; } - const status = effective(o); - const d = feedFor(o); - el.className = "heart s-" + status + (el.classList.contains("flash") ? " flash" : ""); - el.innerHTML = `

    ${esc(o.organ)} ${esc(status)} - board →

    - ${d ? `

    ${esc(d.headline)}

    ` : ""}${metaHtml(o)}${d ? itemsHtml(d.items, viewFor(o).current) : ""}`; -} - function renderHeader() { const live = ORGANS.filter(o => o.feed); const worst = live.reduce((w, o) => RANK[effective(o)] > RANK[w] ? effective(o) : w, "green"); @@ -466,12 +341,8 @@

    u.pathname === '/' + o.repo || u.pathname.startsWith('/' + o.repo + '/')) || null; + return BOARDS.find(o => u.pathname === '/' + o.repo || u.pathname.startsWith('/' + o.repo + '/')) || null; } catch (e) { return null; } } function plainClick(e) { return e.button === 0 && !e.ctrlKey && !e.metaKey && !e.shiftKey && !e.altKey; } -function routeHash(o) { return '#' + (o ? o.organ.toLowerCase() : 'overview'); } +function routeHash(o) { return '#' + (o || SCIENTIST).organ.toLowerCase(); } function setRoute(o, mode) { const hash = routeHash(o); if (location.hash !== hash) history[mode === 'push' ? 'pushState' : 'replaceState'](null, '', hash); @@ -506,14 +377,13 @@

    Overview`; - document.getElementById('board-nav').innerHTML = home + ORGANS.map(o => - `
  • ${o.organ}
  • `).join(''); + document.getElementById('board-nav').innerHTML = BOARDS.map(o => + `
  • ${o.organ}${o === SCIENTIST ? '' : ''}
  • `).join(''); document.addEventListener('click', e => { const a = e.target.closest('a[data-board]'); if (!a || !plainClick(e)) return; e.preventDefault(); - selectBoard(ORGANS.find(o => o.organ === a.dataset.board) || null, { focus: true }); + selectBoard(BOARDS.find(o => o.organ === a.dataset.board) || SCIENTIST, { focus: true }); }); document.getElementById('nav-scroll').addEventListener('scroll', updateOverflowHint, { passive: true }); window.addEventListener('resize', updateOverflowHint); @@ -525,11 +395,11 @@

    { - const o = ORGANS.find(x => x.organ === link.dataset.board); + const o = BOARDS.find(x => x.organ === link.dataset.board); const selected = o ? o === selectedOrgan : selectedOrgan === null; if (selected) link.setAttribute('aria-current', 'page'); else link.removeAttribute('aria-current'); - if (!o) return; + if (!o || o === SCIENTIST) return; const status = effective(o); const v = viewFor(o); const description = v.reason ? v.reason + (v.sourceStatus ? ' · last known ' + v.sourceStatus : '') : status; @@ -539,7 +409,7 @@

    routeHash(x) === location.hash.toLowerCase()) || null; + const o = BOARDS.find(x => routeHash(x) === location.hash.toLowerCase()) || SCIENTIST; selectBoard(o, { mode: 'replace', focus }); } function selectBoard(o, { mode = 'push', focus = false, url = null, fromFrame = false } = {}) { @@ -547,7 +417,6 @@

    el.classList.remove("flash"), 3000); } @@ -711,41 +580,12 @@

    { b.textContent = old; b.classList.remove("ok"); }, 1200); -} -document.addEventListener("click", e => { - const b = e.target.closest("button.copy"); if (b) copyCmd(b); -}); - -// ---- install state ---- -function renderInstall() { - const standalone = (window.matchMedia && matchMedia("(display-mode: standalone)").matches) || - navigator.standalone === true; - const el = document.getElementById("install"); - if (standalone) { el.textContent = "installed · running as an app"; return; } - const ios = /iphone|ipad|ipod/i.test(navigator.userAgent); - el.textContent = ios - ? "install: Share → Add to Home Screen" - : "install: use the install icon in the address bar, or the browser menu → Install app"; -} - document.getElementById("bell").addEventListener("click", onBell); document.addEventListener("visibilitychange", () => { if (document.visibilityState === "visible") poll(); }); if ("serviceWorker" in navigator && location.protocol !== "file:") { navigator.serviceWorker.register("sw.js", { scope: "./" }).catch(() => {}); } renderBell(); -renderInstall(); // Paint last-good copies instantly, then fetch live. for (const o of ORGANS) { const saved = lsGet(o.repo); diff --git a/cockpit/sw.js b/cockpit/sw.js index c09f2e7..8c7fd27 100644 --- a/cockpit/sw.js +++ b/cockpit/sw.js @@ -2,7 +2,7 @@ // Network-first for everything; the cache is a fallback for the shell URLs so the // installed app still opens offline (it then shows each organ's last good feed // from localStorage, marked unreachable). -const CACHE = "pyauto-cockpit-shell-v4"; +const CACHE = "pyauto-cockpit-shell-v4-scientist"; const SHELL = ["/cockpit/", "/cockpit/index.html"]; self.addEventListener("install", event => { diff --git a/tests/cockpit-state.cjs b/tests/cockpit-state.cjs index 0644e28..189f8b6 100644 --- a/tests/cockpit-state.cjs +++ b/tests/cockpit-state.cjs @@ -51,15 +51,6 @@ test('expiry uses producer policy and the exact deadline is stale', () => { const item = () => ({ severity: 'red', text: 'Nightly failed', id: 'overnight:Example/Engine/nightly.yml', state: 'failed', reason: 'GitHub reports failure.', prompt: '/bug nightly', actions: [{ id: 'investigate', label: 'Copy investigation prompt', kind: 'prompt', target: '/bug nightly', safety: 'requires_approval' }], recommended_action_id: 'investigate' }); -test('enriched feed validates, renders one copy action and escapes all producer text', () => { - const it = item(); it.reason = ''; - const h = harness({ d: { ...legacy(), items: [it] } }); - assert.equal(h.run('validate(d)'), null); - const rendered = h.run('itemsHtml(d.items)'); - assert.equal((rendered.match(/data-cmd=/g) || []).length, 1); - assert.match(rendered, /Approval required/); assert.match(rendered, /<script>/); - assert.doesNotMatch(rendered, /