diff --git a/docs/data/generated/dev-docs.json b/docs/data/generated/dev-docs.json index 5b5b2dfdb..eea13369f 100644 --- a/docs/data/generated/dev-docs.json +++ b/docs/data/generated/dev-docs.json @@ -190,7 +190,7 @@ "url": "/dev/prds/dashboard-live-state/", "title": "Dashboard live state", "section": "PRDs", - "body": "# Dashboard live state\n\n**Status:** Approved\n\n## Decision\n\nThe dashboard must not require passive **Refresh** buttons. One app-wide Pinia\nstore owns the existing `/events` EventSource and translates backend events\ninto resource revision counters. Pages load their authoritative HTTP projection\non entry and re-read it when the relevant revision changes. Event payloads are\ninvalidation signals, not substitute read models.\n\nSSE remains the transport. Dashboard updates are server-to-client only, and the\nexisting stream already provides replay, reconnect, and persisted ordering; a\nWebSocket would add a second transport without adding a capability.\n\nThe first slice covers resources for which the backend already emits a truthful\nsignal:\n\n- task events invalidate the dashboard, task board, workflow statistics, and\n the matching task-run page;\n- capture events invalidate the capture list;\n- curator events invalidate curator status, and curator actions also invalidate\n the skill catalogue;\n- update reports invalidate System status;\n- opening a page always loads its resource, and reopening the SSE stream\n invalidates mounted projections after a connection loss.\n\nLogs retain their dedicated SSE tail. Local mutations continue to re-read their\nown resource after success. Configuration, channels, and catalogues that have no\nbackend change event load on route entry; future write contracts must emit an\nowner-specific event rather than introduce polling or restore a button.\n\n## Boundaries\n\nThe Pinia store owns browser connection state and invalidation only. It does not\nbecome an alternate backend cache or copy domain state into a generic global\nobject. Existing feature modules continue to own their DTOs and API reads.\n\nOperational commands are not refresh controls. Channel **Reload** remains an\nexplicit adapter lifecycle action. Authentication recovery is also not a data\nrefresh: a 401 moves the application into shared authentication state; reloading\nthe same URL cannot restore Archie's missing or rotated token and must not be\noffered as a fix.\n\n## Verification\n\n- No passive page action renders the label **Refresh** or **Retry** for a read.\n- Only one shared `/events` EventSource is opened by the application.\n- Resource classification tests distinguish task, capture, curator, skill, and\n update invalidations.\n- UI tests, type checking, generated asset freshness, and `task check` pass.\n" + "body": "# Dashboard live state\n\n**Status:** Approved\n\n## Decision\n\nThe dashboard must not require passive **Refresh** buttons. One app-wide Pinia\nstore owns the existing `/api/stream` EventSource and translates backend events\ninto resource revision counters. Pages load their authoritative HTTP projection\non entry and re-read it when the relevant revision changes. Event payloads are\ninvalidation signals, not substitute read models.\n\nSSE remains the transport. Dashboard updates are server-to-client only, and the\nexisting stream already provides replay, reconnect, and persisted ordering; a\nWebSocket would add a second transport without adding a capability.\n\nThe first slice covers resources for which the backend already emits a truthful\nsignal:\n\n- task events invalidate the dashboard, task board, workflow statistics, and\n the matching task-run page;\n- capture events invalidate the capture list;\n- curator events invalidate curator status, and curator actions also invalidate\n the skill catalogue;\n- update reports invalidate System status;\n- opening a page always loads its resource, and reopening the SSE stream\n invalidates mounted projections after a connection loss.\n\nLogs retain their dedicated SSE tail. Local mutations continue to re-read their\nown resource after success. Configuration, channels, and catalogues that have no\nbackend change event load on route entry; future write contracts must emit an\nowner-specific event rather than introduce polling or restore a button.\n\n## Boundaries\n\nThe Pinia store owns browser connection state and invalidation only. It does not\nbecome an alternate backend cache or copy domain state into a generic global\nobject. Existing feature modules continue to own their DTOs and API reads.\n\nOperational commands are not refresh controls. Channel **Reload** remains an\nexplicit adapter lifecycle action. Authentication recovery is also not a data\nrefresh: a 401 moves the application into shared authentication state; reloading\nthe same URL cannot restore Archie's missing or rotated token and must not be\noffered as a fix.\n\n## Verification\n\n- No passive page action renders the label **Refresh** or **Retry** for a read.\n- Only one shared `/api/stream` EventSource is opened by the application.\n- Resource classification tests distinguish task, capture, curator, skill, and\n update invalidations.\n- UI tests, type checking, generated asset freshness, and `task check` pass.\n" }, { "url": "/dev/prds/dashboard-navigation-groups/", diff --git a/docs/prds/dashboard-live-state.md b/docs/prds/dashboard-live-state.md index 486c8432b..84b8945db 100644 --- a/docs/prds/dashboard-live-state.md +++ b/docs/prds/dashboard-live-state.md @@ -5,7 +5,7 @@ ## Decision The dashboard must not require passive **Refresh** buttons. One app-wide Pinia -store owns the existing `/events` EventSource and translates backend events +store owns the existing `/api/stream` EventSource and translates backend events into resource revision counters. Pages load their authoritative HTTP projection on entry and re-read it when the relevant revision changes. Event payloads are invalidation signals, not substitute read models. @@ -46,7 +46,7 @@ offered as a fix. ## Verification - No passive page action renders the label **Refresh** or **Retry** for a read. -- Only one shared `/events` EventSource is opened by the application. +- Only one shared `/api/stream` EventSource is opened by the application. - Resource classification tests distinguish task, capture, curator, skill, and update invalidations. - UI tests, type checking, generated asset freshness, and `task check` pass. diff --git a/internal/webui/api_logs.go b/internal/webui/api_logs.go index 6650ef437..c931045a6 100644 --- a/internal/webui/api_logs.go +++ b/internal/webui/api_logs.go @@ -14,7 +14,7 @@ import ( // // This handler is transport only: parsing the log format belongs to the // logging package, which owns it. Live output reaches the dashboard over the -// existing /events stream; this endpoint exists so the view has history from +// existing /api/stream stream; this endpoint exists so the view has history from // before the browser connected, which is the whole reason file logging landed // first. func (s *Server) handleLogs(w http.ResponseWriter, r *http.Request) { diff --git a/internal/webui/event_pump_test.go b/internal/webui/event_pump_test.go index c2f953073..7cb05fe00 100644 --- a/internal/webui/event_pump_test.go +++ b/internal/webui/event_pump_test.go @@ -85,7 +85,7 @@ func TestEventPumpKeepsItsWatermarkAcrossAStoreFailure(t *testing.T) { } // The bead's headline claim: an event written to the State Store by another -// process reaches a browser hanging on /events, with no in-process bus. +// process reaches a browser hanging on /api/stream, with no in-process bus. func TestEventPumpReachesALiveSSEClient(t *testing.T) { srv := newRemoteTestServer(t) pump := newTestPump(t, srv) @@ -123,7 +123,7 @@ func TestEventPumpReachesALiveSSEClient(t *testing.T) { } } -// newSSETestServer serves the dashboard's real route set, so /events goes +// newSSETestServer serves the dashboard's real route set, so /api/stream goes // through requireToken and the mux exactly as a browser reaches it. func newSSETestServer(t *testing.T, srv *Server) *httptest.Server { t.Helper() @@ -132,25 +132,25 @@ func newSSETestServer(t *testing.T, srv *Server) *httptest.Server { return ts } -// openSSEStream connects to /events and relays each response line on a +// openSSEStream connects to /api/stream and relays each response line on a // channel. The request context ends the handler, which is what lets the // test server close. func openSSEStream(t *testing.T, ctx context.Context, ts *httptest.Server) <-chan string { t.Helper() - req, err := http.NewRequestWithContext(ctx, http.MethodGet, ts.URL+"/events", nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, ts.URL+"/api/stream", nil) if err != nil { t.Fatalf("sse request: %v", err) } resp, err := ts.Client().Do(req) if err != nil { - t.Fatalf("GET /events: %v", err) + t.Fatalf("GET /api/stream: %v", err) } // Closed at cleanup rather than by the reader goroutine: the body is the // live stream and must outlive this function, but it still has exactly // one owner and one close. t.Cleanup(func() { _ = resp.Body.Close() }) if resp.StatusCode != http.StatusOK { - t.Fatalf("GET /events = %d, want 200", resp.StatusCode) + t.Fatalf("GET /api/stream = %d, want 200", resp.StatusCode) } lines := make(chan string, 64) go func() { @@ -243,3 +243,28 @@ func TestPumpPriming(t *testing.T) { }) } } + +// A dashboard route reloaded in the browser must get the app shell. The live +// stream once sat at /events, the same path as the Events page, so a reload +// there rendered the raw event stream instead of the page. +func TestDashboardRoutesServeTheAppShell(t *testing.T) { + ts := newSSETestServer(t, &Server{}) + for _, path := range []string{"/events", "/events?tab=inspector"} { + t.Run(path, func(t *testing.T) { + ctx, cancel := context.WithTimeout(t.Context(), 2*time.Second) + defer cancel() + req, err := http.NewRequestWithContext(ctx, http.MethodGet, ts.URL+path, nil) + if err != nil { + t.Fatal(err) + } + resp, err := http.DefaultClient.Do(req) + if err != nil { + t.Fatalf("GET %s: %v", path, err) + } + defer resp.Body.Close() + if ct := resp.Header.Get("Content-Type"); strings.HasPrefix(ct, "text/event-stream") { + t.Fatalf("GET %s served the event stream, want the app shell", path) + } + }) + } +} diff --git a/internal/webui/server.go b/internal/webui/server.go index d8e275e76..10e370c21 100644 --- a/internal/webui/server.go +++ b/internal/webui/server.go @@ -310,7 +310,7 @@ func (s *Server) Handler() http.Handler { s.registerChatRoutes(mux) mux.HandleFunc("GET /health/detailed", s.handleHealthDetailed) - mux.HandleFunc("GET /events", s.handleSSE) + mux.HandleFunc("GET /api/stream", s.handleSSE) mux.Handle("GET /", s.assets()) top := http.NewServeMux() diff --git a/internal/webui/sse_test.go b/internal/webui/sse_test.go index dd955ac07..ce798f011 100644 --- a/internal/webui/sse_test.go +++ b/internal/webui/sse_test.go @@ -252,7 +252,7 @@ func TestSSESinceDegradesUnparseableCursorToBeginning(t *testing.T) { } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - req := httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/events", nil) + req := httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/api/stream", nil) if tt.since != "" { q := req.URL.Query() q.Set("since", tt.since) diff --git a/internal/webui/webui_test.go b/internal/webui/webui_test.go index 5b70d4c7f..4267d5f4f 100644 --- a/internal/webui/webui_test.go +++ b/internal/webui/webui_test.go @@ -316,7 +316,7 @@ func TestHandleSSEEventsSinceError(t *testing.T) { ctx, cancel := context.WithTimeout(t.Context(), 3*time.Second) defer cancel() - req, err := http.NewRequestWithContext(ctx, http.MethodGet, ts.URL+"/events?since=0", nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, ts.URL+"/api/stream?since=0", nil) if err != nil { t.Fatal(err) } @@ -362,7 +362,7 @@ func TestHandleSSEUsesLastEventIDForCatchUp(t *testing.T) { ts := httptest.NewServer(srv.Handler()) t.Cleanup(ts.Close) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, ts.URL+"/events", nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, ts.URL+"/api/stream", nil) if err != nil { t.Fatal(err) } @@ -407,7 +407,7 @@ func TestHandleSSEBacklogAndLive(t *testing.T) { // The request carries t.Context() so the SSE stream is torn down when // the test ends rather than leaking the connection and its goroutine. - req, err := http.NewRequestWithContext(ctx, http.MethodGet, ts.URL+"/events", nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, ts.URL+"/api/stream", nil) if err != nil { t.Fatal(err) } @@ -454,7 +454,7 @@ func TestHandleSSEFiltersTurnCompletedFromLiveBroadcast(t *testing.T) { ts := httptest.NewServer(srv.Handler()) t.Cleanup(ts.Close) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, ts.URL+"/events", nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, ts.URL+"/api/stream", nil) if err != nil { t.Fatal(err) } diff --git a/ui/dist/assets/index.js b/ui/dist/assets/index.js index 6ddabdd37..bf6ab75ba 100644 --- a/ui/dist/assets/index.js +++ b/ui/dist/assets/index.js @@ -2,7 +2,7 @@ var e=Object.defineProperty,t=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],en `&&(e.tagName===`PRE`||e.tagName===`TEXTAREA`)&&(n=n.slice(1));let{textContent:r}=e;r!==n&&r!==n.replace(/\r\n|\r/g,` `)&&(ki(e,0)||yi(),e.textContent=t.children)}if(d){if(_||b||!o||f&48){let t=e.tagName.includes(`-`),i=e.namespaceURI.includes(`svg`)?`svg`:e.namespaceURI.includes(`MathML`)?`mathml`:void 0;for(let a in d)if(_&&(a.endsWith(`value`)||a===`indeterminate`)||c(a)&&!re(a)||a[0]===`.`||t&&!re(a)||u&&u.includes(a)){if(Ei(e,a,d[a]))continue;r(e,a,null,d[a],i,n)}}else if(d.onClick)r(e,`onClick`,null,d.onClick,void 0,n);else if(f&4&&cn(d.style))for(let e in d.style)d.style[e]}let x;(x=d&&d.onVnodeBeforeMount)&&Ns(x,n,t),h&&wr(t,null,n,`beforeMount`),((x=d&&d.onVnodeMounted)||h||l)&&ls(()=>{x&&Ns(x,n,t),l&&g.enter(e),h&&wr(t,null,n,`mounted`)},i)}return e.nextSibling},m=(e,t,r,o,s,c,u)=>{u||=!!t.dynamicChildren;let d=t.children,p=d.length,m=!1;for(let t=0;t
{let{slotScopeIds:c}=t;c&&(i=i?i.concat(c):c);let d=o(e),f=m(a(e),t,d,n,r,i,s);return f&&Ci(f)&&f.data===`]`?a(t.anchor=f):(yi(),l(t.anchor=u(`]`),d,f),f)},g=(e,t,r,i,c,l)=>{if(ji(e,t)||yi(),t.el=null,l){let t=_(e);for(;;){let n=a(e);if(n&&n!==t)s(n);else break}}let u=a(e),d=o(e);return s(e),n(null,t,d,u,r,i,Si(d),c),r&&(r.vnode.el=t.el,So(r,t.el)),u},_=(e,t=`[`,n=`]`)=>{let r=0;for(;e;)if(e=a(e),e&&Ci(e)&&(e.data===t&&r++,e.data===n)){if(r===0)return a(e);r--}return e},v=(e,t,n)=>{let r=t.parentNode;r&&r.replaceChild(e,t);let i=n;for(;i;)i.vnode.el===t&&(i.vnode.el=i.subTree.el=e),i=i.parent},y=e=>e.nodeType===1&&e.tagName===`TEMPLATE`;return[d,f]}var Ti=new Set([`src`,`srcset`,`href`,`poster`]);function Ei(e,t,n){return Ti.has(t)?e.getAttribute(t)===(n==null?null:`${n}`):!1}var Di=`data-allow-mismatch`,Oi={0:`text`,1:`children`,2:`class`,3:`style`,4:`attribute`};function ki(e,t){if(t===0||t===1)for(;e&&!e.hasAttribute(Di);)e=e.parentElement;return Ai(e&&e.getAttribute(Di),t)}function Ai(e,t){if(e==null)return!1;if(e===``)return!0;{let n=e.split(`,`);return t===0&&n.includes(`children`)?!0:n.includes(Oi[t])}}function ji(e,t){return ki(e.parentElement,1)||Mi(e)||Ni(t)}function Mi(e){return e.nodeType===1&&Ai(e.getAttribute(Di),1)}function Ni({props:e}){let t=e&&e[Di];return typeof t==`string`&&Ai(t,1)}var Pi=ge().requestIdleCallback||(e=>setTimeout(e,1)),Fi=ge().cancelIdleCallback||(e=>clearTimeout(e)),Ii=(e=1e4)=>t=>{let n=Pi(t,{timeout:e});return()=>Fi(n)};function Li(e){let{top:t,left:n,bottom:r,right:i}=e.getBoundingClientRect(),{innerHeight:a,innerWidth:o}=window;return(t>0&&t0&&r0&&ne.slice(1,-1).indexOf(`:`)===-1?void 0:(()=>{let t=e.slice(1,-1),n=t.indexOf(`:`),r=t.slice(0,n);return r?tf+r:void 0})(),of=e=>{let{theme:t,classGroups:n}=e;return sf(n,t)},sf=(e,t)=>{let n=Qd();for(let r in e){let i=e[r];cf(i,n,r,t)}return n},cf=(e,t,n,r)=>{let i=e.length;for(let a=0;a{if(typeof e==`string`){uf(e,t,n);return}if(typeof e==`function`){df(e,t,n,r);return}ff(e,t,n,r)},uf=(e,t,n)=>{let r=e===``?t:pf(t,e);r.classGroupId=n},df=(e,t,n,r)=>{if(mf(e)){cf(e(r),t,n,r);return}t.validators===null&&(t.validators=[]),t.validators.push(Zd(n,e))},ff=(e,t,n,r)=>{let i=Object.entries(e),a=i.length;for(let e=0;e{let n=e,r=t.split($d),i=r.length;for(let e=0;e`isThemeGetter`in e&&e.isThemeGetter===!0,hf=e=>{if(e<1)return{get:()=>void 0,set:()=>{}};let t=0,n=Object.create(null),r=Object.create(null),i=(i,a)=>{n[i]=a,t++,t>e&&(t=0,r=n,n=Object.create(null))};return{get(e){let t=n[e];if(t!==void 0)return t;if((t=r[e])!==void 0)return i(e,t),t},set(e,t){e in n?n[e]=t:i(e,t)}}},gf=`!`,_f=`:`,vf=[],yf=(e,t,n,r,i)=>({modifiers:e,hasImportantModifier:t,baseClassName:n,maybePostfixModifierPosition:r,isExternal:i}),bf=e=>{let{prefix:t,experimentalParseClassName:n}=e,r=e=>{let t=[],n=0,r=0,i=0,a,o=e.length;for(let s=0;s