feat(webui): show which process is running which settings version

The settings page now reads apply status beside each resource: every known
process with the version it applied, its error if it rejected the edit, and
whether it is still reporting at all. It re-reads after each save, so the page
reflects what the processes did with an edit rather than what was stored.

The server derives liveness only, because it knows whether a record went stale
but not which version the page is showing. The client compares against the
resource it is rendering, which is what turns a live record on an older
version into a pending restart.

A process that stopped re-stamping and one that never reported are separate
rows with separate wording, and neither is an error: the setting may be fine
and the process simply absent, which an operator acts on differently. A failed
apply-status read leaves the previous rows rather than taking the settings
page down with it.

state-store-contract.md gains the pair in its inventory and its count moves
from 45 to 47, with the note that this read is a list rather than the
config-snapshot pair's found=false singleton.

Closes archie-core-pskb.
This commit is contained in:
sam committed 2026-09-21 15:57:46 +10:00
1 parent be4e29c91b
commit db7478dbdc
10 files changed
+358 -5

No files matched your search

+12 -2
View File
@@ -262,9 +262,10 @@ Methods are named after the store methods so the mapping is unambiguous. `workfl
| Dispatch | `ArmedBindingsForSource`, `RecordDispatch`, `ListUndispatchedCaptures` |
| BindingTaskCreator | `EnqueueBindingTask` |
| Config snapshot | `PutConfigSnapshot`, `GetConfigSnapshot` |
| Apply status | `PutApplyStatus`, `ListApplyStatus` |
| Task log | `ReadTaskLog`, `StreamTaskLogContent` |
That is **45 unique contract RPCs** across one service (the `TaskEvents.Close` method is dropped).
That is **47 unique contract RPCs** across one service (the `TaskEvents.Close` method is dropped).
`Close()` is **excluded** from the wire (it is server lifecycle, not a client call) — see §11.
The config-snapshot pair was added by `archie-core-ymut` (see
@@ -275,6 +276,15 @@ neither. `ConfigSnapshot.document` is opaque to this contract — the store neit
validates it, and `schema` names the projection so a reader can refuse a shape it does not
understand.
The apply-status pair was added by `archie-core-pskb` (see
`docs/prds/control-plane-apply-status.md`). It is administrative for the same reason as the
config-snapshot pair, and deny-by-default in `authorizesTaskScopedCall` covers it without a
new rule. Unlike that pair, the read is a list: `ListApplyStatus` returns every process's
record and an empty slice means nothing has reported yet, so the `found=false` convention for
absent single rows does not apply. The rows are keyed on `(process, kind)` and replaced in
place, because each process re-stamps its record on an interval and no reader wants a history
of re-stamps.
The task-log pair was added by `archie-core-iaqx` (see `docs/prds/ui-service-boundary.md`'s
route inventory). It is the one surface whose payload is not a row: the store service reads
them out of the state directory it owns with `internal/logging`'s own reader, so the wire
@@ -664,7 +674,7 @@ an explicit operator decision.
(`workflow.Store` + `workflow.Task`/`Status`/`Source`, per dependency rules #2 and #7);
daemon/webui store surfaces stay **producer-owned** in `internal/store`. `store.WorkflowStore`
is superseded by `workflow.Store`.
- **One `StateStore` gRPC service** (45 contract RPCs, grouped by contract) + narrow Go consumer facades
- **One `StateStore` gRPC service** (47 contract RPCs, grouped by contract) + narrow Go consumer facades
(≤8) on `staterpc.Client` — mirrors the single-`ChatService` precedent.
- **Domain type relocation** (`Task`/`Status`/`Source` → `internal/domain/workflow`) is a
Phase 2 prerequisite, pulled forward from migration-decisions §4 (minimal bound,
+3
View File
@@ -79,6 +79,9 @@ func compose(d deps) *webui.Server {
// client already carries them: withholding them would degrade two pages
// that have an owner, which is a different thing from the intake surfaces
// below.
if applyStatus, ok := d.Store.(storecontract.ApplyStatusStore); ok {
srv.ApplyStatus = applyStatus
}
if mappings, ok := d.Store.(storecontract.MappingStore); ok {
srv.Mappings = mappings
}
+80
View File
@@ -0,0 +1,80 @@
package webui
import (
"net/http"
"time"
"github.com/samcharles93/archie-core/internal/domain/applystatus"
"github.com/samcharles93/archie-core/internal/domain/storecontract"
)
// The readings an operator acts on. A process is current when it is running
// what it last reported, failed when it rejected what the store holds, and
// unknown when it has stopped re-stamping: a record that outlived its process
// must never read as current (docs/prds/control-plane-apply-status.md).
const (
applyStateCurrent = "current"
applyStateFailed = "failed"
applyStateUnknown = "unknown"
)
type applyStatusRecord struct {
Process string `json:"process"`
Kind string `json:"kind"`
AppliedVersion int64 `json:"applied_version"`
Error string `json:"error,omitempty"`
ReportedAt time.Time `json:"reported_at"`
State string `json:"state"`
}
type applyStatusView struct {
Records []applyStatusRecord `json:"records"`
// Processes is every name a record may carry, so the page can show a
// process that has never reported at all rather than omitting the column.
Processes []string `json:"processes"`
}
// handleApplyStatus reports which version of each control-plane resource each
// process is running. A process with no apply-status wiring renders an empty
// page rather than failing: that is a deployment fact, not an error.
func (s *Server) handleApplyStatus(w http.ResponseWriter, r *http.Request) {
view := applyStatusView{Records: []applyStatusRecord{}, Processes: applystatus.Processes()}
if s.ApplyStatus == nil {
writeJSON(w, view)
return
}
records, err := s.ApplyStatus.ListApplyStatus(r.Context())
if err != nil {
http.Error(w, "apply status unavailable", http.StatusServiceUnavailable)
return
}
now := s.clock()
for _, record := range records {
view.Records = append(view.Records, applyStatusRecord{
Process: record.Process, Kind: record.Kind, AppliedVersion: record.AppliedVersion,
Error: record.Error, ReportedAt: record.ReportedAt, State: applyState(record, now),
})
}
writeJSON(w, view)
}
// applyState reads staleness before the error: a process that stopped
// reporting is unknown whatever its last report said, because that report
// describes a process that may no longer exist.
func applyState(record storecontract.ApplyStatus, now time.Time) string {
switch {
case applystatus.Stale(record.ReportedAt, now):
return applyStateUnknown
case record.Error != "":
return applyStateFailed
default:
return applyStateCurrent
}
}
func (s *Server) clock() time.Time {
if s.now != nil {
return s.now()
}
return time.Now().UTC()
}
+102
View File
@@ -0,0 +1,102 @@
package webui
import (
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/samcharles93/archie-core/internal/domain/applystatus"
"github.com/samcharles93/archie-core/internal/domain/storecontract"
)
type stubApplyStatus struct {
records []storecontract.ApplyStatus
err error
}
func (s stubApplyStatus) PutApplyStatus(_ context.Context, _ storecontract.ApplyStatus) error {
return nil
}
func (s stubApplyStatus) ListApplyStatus(context.Context) ([]storecontract.ApplyStatus, error) {
return s.records, s.err
}
func applyStatusResponse(t *testing.T, server *Server) applyStatusView {
t.Helper()
recorder := httptest.NewRecorder()
server.Handler().ServeHTTP(recorder, httptest.NewRequestWithContext(t.Context(), http.MethodGet, "/api/control-plane/apply-status", nil))
if recorder.Code != http.StatusOK {
t.Fatalf("GET apply-status = %d, want 200: %s", recorder.Code, recorder.Body.String())
}
var view applyStatusView
if err := json.Unmarshal(recorder.Body.Bytes(), &view); err != nil {
t.Fatalf("decode apply status: %v (body %s)", err, recorder.Body.String())
}
return view
}
// TestApplyStatusDerivesState pins the three readings an operator acts on: a
// process on the current version is live, one on an older version of a
// restart-required kind is pending a restart, and one that has stopped
// re-stamping is unknown rather than current (archie-core-pskb).
func TestApplyStatusDerivesState(t *testing.T) {
now := time.Date(2026, 9, 21, 12, 0, 0, 0, time.UTC)
server := &Server{ApplyStatus: stubApplyStatus{records: []storecontract.ApplyStatus{
{Process: applystatus.Daemon, Kind: "tool-settings", AppliedVersion: 4, ReportedAt: now.Add(-10 * time.Second)},
{Process: applystatus.Gateway, Kind: "tool-settings", AppliedVersion: 3, ReportedAt: now.Add(-10 * time.Second)},
{Process: applystatus.Messaging, Kind: "tool-settings", AppliedVersion: 4, ReportedAt: now.Add(-10 * time.Minute)},
}}}
server.now = func() time.Time { return now }
got := applyStatusResponse(t, server)
states := map[string]string{}
for _, record := range got.Records {
states[record.Process] = record.State
}
for process, want := range map[string]string{
applystatus.Daemon: applyStateCurrent,
applystatus.Gateway: applyStateCurrent,
applystatus.Messaging: applyStateUnknown,
} {
if states[process] != want {
t.Errorf("%s state = %q, want %q", process, states[process], want)
}
}
}
// TestApplyStatusReportsAnError pins that a process that rejected an edit
// reads as failed with its error, and keeps showing the version still live
// in it.
func TestApplyStatusReportsAnError(t *testing.T) {
now := time.Date(2026, 9, 21, 12, 0, 0, 0, time.UTC)
server := &Server{ApplyStatus: stubApplyStatus{records: []storecontract.ApplyStatus{
{
Process: applystatus.Daemon, Kind: "tool-settings", AppliedVersion: 3,
Error: "validate database settings: bad policy", ReportedAt: now,
},
}}}
server.now = func() time.Time { return now }
got := applyStatusResponse(t, server)
if len(got.Records) != 1 {
t.Fatalf("got %d records, want 1", len(got.Records))
}
record := got.Records[0]
if record.State != applyStateFailed || record.Error == "" || record.AppliedVersion != 3 {
t.Fatalf("record = %+v, want failed with its error and version 3 still live", record)
}
}
// TestApplyStatusWithoutAStoreIsEmptyNotAnError: a process with no apply
// status wiring must render an empty page, the same way the capture list
// reports disabled rather than failing the dashboard.
func TestApplyStatusWithoutAStoreIsEmptyNotAnError(t *testing.T) {
got := applyStatusResponse(t, &Server{})
if len(got.Records) != 0 {
t.Fatalf("got %d records from a server with no store, want none", len(got.Records))
}
}
+10
View File
@@ -14,6 +14,7 @@ import (
"log/slog"
"net/http"
"sync"
"time"
"github.com/samcharles93/archie-core/internal/channels/status"
controlpb "github.com/samcharles93/archie-core/internal/contracts/controlplane/v1"
@@ -87,6 +88,14 @@ type Server struct {
ControlPlane controlpb.ControlPlaneServiceClient
Identities identity.Repository
// ApplyStatus reports which control-plane resource version each process
// is running. Optional: nil renders an empty page rather than failing the
// dashboard (docs/prds/control-plane-apply-status.md).
ApplyStatus storecontract.ApplyStatusStore
// now is the clock applyState reads staleness against. Nil means
// time.Now; tests set it to pin a record's age.
now func() time.Time
// Token gates access. Empty means no check, which is how loopback binds
// stay frictionless -- see IsLoopback.
Token string
@@ -247,6 +256,7 @@ func (s *Server) registerMappingAndBindingRoutes(mux *http.ServeMux) {
func (s *Server) registerConfigAndLogRoutes(mux *http.ServeMux) {
mux.HandleFunc("GET /api/control-plane/catalog", s.handleControlPlaneCatalog)
mux.HandleFunc("GET /api/control-plane/apply-status", s.handleApplyStatus)
mux.HandleFunc("GET /api/control-plane/resources/{kind}", s.handleControlPlaneQuery)
mux.HandleFunc("GET /api/control-plane/resources/{kind}/history", s.handleControlPlaneHistory)
mux.HandleFunc("POST /api/control-plane/resources/{kind}/commands/{command}", s.handleControlPlaneCommand)
+2 -2
View File
@@ -15,5 +15,5 @@ var e=Object.defineProperty,t=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],en
Defaulting to \`null\`.`),null)}function Tx(e){return Cx(e)&&!Number.isNaN(e)&&e>0?e:(console.error(`Invalid prop \`max\` of value \`${e}\` supplied to \`ProgressRoot\`. Only numbers greater than 0 are valid max values. Defaulting to \`${bx}\`.`),bx)}var Ex=N({__name:`ProgressRoot`,props:{modelValue:{type:[Number,null],required:!1},max:{type:Number,required:!1,default:bx},getValueLabel:{type:Function,required:!1,default:(e,t)=>Cx(e)?`${Math.round(e/t*bx)}%`:void 0},getValueText:{type:Function,required:!1},asChild:{type:Boolean,required:!1},as:{type:null,required:!1}},emits:[`update:modelValue`,`update:max`],setup(e,{emit:t}){let n=e,r=t;X();let i=yh(n,`modelValue`,r,{passive:n.modelValue===void 0}),a=yh(n,`max`,r,{passive:n.max===void 0});M(()=>i.value,async e=>{let t=wx(e,n.max);t!==e&&(await ar(),i.value=t)},{immediate:!0}),M(()=>n.max,e=>{let t=Tx(n.max);t!==e&&(a.value=t)},{immediate:!0});let o=G(()=>Um(i.value)?`indeterminate`:i.value===a.value?`complete`:`loading`);return Sx({modelValue:i,max:a,progressState:o}),(e,t)=>(L(),z(A(Z),{"as-child":e.asChild,as:e.as,"aria-valuemax":A(a),"aria-valuemin":0,"aria-valuenow":Cx(A(i))?A(i):void 0,"aria-valuetext":e.getValueText?.(A(i),A(a)),"aria-label":e.getValueLabel(A(i),A(a)),role:`progressbar`,"data-state":o.value,"data-value":A(i)??void 0,"data-max":A(a)},{default:j(()=>[F(e.$slots,`default`,{modelValue:A(i)})]),_:3},8,[`as-child`,`as`,`aria-valuemax`,`aria-valuenow`,`aria-valuetext`,`aria-label`,`data-state`,`data-value`,`data-max`]))}}),Dx=N({__name:`ProgressIndicator`,props:{asChild:{type:Boolean,required:!1},as:{type:null,required:!1}},setup(e){let t=e,n=xx();return X(),(e,r)=>(L(),z(A(Z),W(t,{"data-state":A(n).progressState.value,"data-value":A(n).modelValue?.value??void 0,"data-max":A(n).max.value}),{default:j(()=>[F(e.$slots,`default`)]),_:3},16,[`data-state`,`data-value`,`data-max`]))}}),Ox=[` `,`Enter`,`ArrowUp`,`ArrowDown`],kx=[` `,`Enter`];function Ax(e,t,n){return e===void 0?!1:Array.isArray(e)?e.some(e=>jx(e,t,n)):jx(e,t,n)}function jx(e,t,n){return e===void 0||t===void 0?!1:typeof e==`string`?e===t:typeof n==`function`?n(e,t):typeof n==`string`?e?.[n]===t?.[n]:Rm(e,t)}function Mx(e){return e==null||e===``||Array.isArray(e)&&e.length===0}var Nx=[`value`],[Px,Fx]=Bm(`SelectRoot`),Ix=N({inheritAttrs:!1,__name:`SelectRoot`,props:{open:{type:Boolean,required:!1,default:void 0},defaultOpen:{type:Boolean,required:!1},defaultValue:{type:null,required:!1},modelValue:{type:null,required:!1,default:void 0},nullableValue:{type:String,required:!1,default:``},by:{type:[String,Function],required:!1},dir:{type:String,required:!1},multiple:{type:Boolean,required:!1},autocomplete:{type:String,required:!1},disabled:{type:Boolean,required:!1},name:{type:String,required:!1},required:{type:Boolean,required:!1}},emits:[`update:modelValue`,`update:open`],setup(e,{emit:t}){let n=e,r=t,{required:i,disabled:a,multiple:o,dir:s}=En(n),c=yh(n,`modelValue`,r,{defaultValue:n.defaultValue??(o.value?[]:void 0),passive:n.modelValue===void 0,deep:!0}),l=yh(n,`open`,r,{defaultValue:n.defaultOpen,passive:n.open===void 0}),u=k(),d=k(),f=k({x:0,y:0}),p=G(()=>o.value&&Array.isArray(c.value)?c.value?.length===0:Um(c.value));D_({isProvider:!0});let m=Fh(s),h=Bh(u),g=k(new Set),_=G(()=>Array.from(g.value).map(e=>e.value).join(`;`));function v(e){if(o.value){let t=Array.isArray(c.value)?[...c.value]:[],r=t.findIndex(t=>jx(t,e,n.by));r===-1?t.push(e):t.splice(r,1),c.value=[...t]}else c.value=e}function y(e){return Array.from(g.value).find(t=>Ax(e,t.value,n.by))}return Fx({triggerElement:u,onTriggerChange:e=>{u.value=e},valueElement:d,onValueElementChange:e=>{d.value=e},contentId:``,modelValue:c,onValueChange:v,by:n.by,open:l,multiple:o,required:i,onOpenChange:e=>{l.value=e},dir:m,triggerPointerDownPosRef:f,disabled:a,isEmptyModelValue:p,optionsSet:g,onOptionAdd:e=>{let t=y(e.value);t&&g.value.delete(t),g.value.add(e)},onOptionRemove:e=>{let t=y(e.value);t&&g.value.delete(t)}}),(e,t)=>(L(),z(A(B_),null,{default:j(()=>[F(e.$slots,`default`,{modelValue:A(c),open:A(l)}),A(h)&&e.name?(L(),z(Lx,{key:_.value,"aria-hidden":`true`,tabindex:`-1`,multiple:A(o),required:A(i),name:e.name,autocomplete:e.autocomplete,disabled:A(a),value:A(c)},{default:j(()=>[A(Um)(A(c))?(L(),R(`option`,{key:0,value:e.nullableValue},null,8,Nx)):U(`v-if`,!0),(L(!0),R(I,null,P(Array.from(g.value),e=>(L(),R(`option`,W({key:e.value??``},{ref_for:!0},e),null,16))),128))]),_:1},8,[`multiple`,`required`,`name`,`autocomplete`,`disabled`,`value`])):U(`v-if`,!0)]),_:3}))}}),Lx=N({__name:`BubbleSelect`,props:{autocomplete:{type:String,required:!1},autofocus:{type:Boolean,required:!1},disabled:{type:Boolean,required:!1},form:{type:String,required:!1},multiple:{type:Boolean,required:!1},name:{type:String,required:!1},required:{type:Boolean,required:!1},size:{type:Number,required:!1},value:{type:null,required:!1}},setup(e){let t=e,n=k(),r=Px();M(()=>t.value,(e,t)=>{let r=window.HTMLSelectElement.prototype,i=Object.getOwnPropertyDescrLine truncated
`),r=[],i=null,a=null,o=()=>{r.length&&(t.push({kind:`p`,inline:nT(r.join(` `))}),r=[])},s=()=>{i&&=(t.push({kind:i.tag,items:i.items.map(e=>nT(e))}),null)};for(let e=0;e<n.length;e++){let c=n[e];if(c.startsWith("```")){o(),s(),a?(t.push({kind:`pre`,code:a.join(`
`)}),a=null):a=[];continue}if(a){a.push(c);continue}let l=iT(c),u=e+1<n.length?iT(n[e+1]):null;if(l&&u&&aT(u)&&l.length===u.length){o(),s();let r=[];for(e+=2;e<n.length;e++){let t=iT(n[e]);if(!t||t.length!==l.length){e--;break}r.push(t)}t.push({kind:`table`,head:l.map(e=>nT(e)),rows:r.map(e=>e.map(e=>nT(e)))});continue}if(!c.trim()){o(),s();continue}let d=c.match(/^(#{1,3})\s+(.+)$/);if(d){o(),s(),t.push({kind:`h${d[1].length}`,inline:nT(d[2])});continue}let f=c.match(/^\s*[-*]\s+(.+)$/),p=c.match(/^\s*\d+[.)]\s+(.+)$/);if(f||p){o();let e=p?`ol`:`ul`;(!i||i.tag!==e)&&(s(),i={tag:e,items:[]}),i.items.push((f||p)[1]);continue}if(c.startsWith(`>`)){o(),s(),t.push({kind:`blockquote`,inline:nT(c.replace(/^>\s?/,``))});continue}r.push(c)}return o(),s(),a&&t.push({kind:`pre`,code:a.join(`
`)}),t}function iT(e){let t=String(e||``).trim();if(!t.includes(`|`))return null;let n=t.replace(/^\|/,``).replace(/\|$/,``).split(`|`).map(e=>e.trim());return n.length>1&&n.every(e=>e!==``)?n:null}function aT(e){return e.every(e=>/^:?-{3,}:?$/.test(e))}var oT={class:`[overflow-wrap:anywhere]`},sT={key:0,class:`my-2 overflow-auto rounded-md border border-border bg-background/60 p-3`},cT={class:`font-mono text-[0.85em]`},lT={key:1,class:`my-3 w-full border-collapse text-[0.92em]`},uT={key:2,class:`my-2 border-l-[3px] border-primary pl-3 text-fg-muted`},dT={key:3,class:`mt-1 mb-2 text-xl leading-tight font-semibold tracking-[-0.02em]`},fT={key:4,class:`mt-1 mb-2 text-lg leading-tight font-semibold tracking-[-0.02em]`},pT={key:5,class:`mt-1 mb-2 text-base leading-tight font-semibold tracking-[-0.02em]`},mT={key:6,class:`my-2.5 flex list-disc flex-col gap-1 pl-5`},hT={key:7,class:`my-2.5 flex list-decimal flex-col gap-1 pl-5`},gT={key:8,class:`mb-2.5 last:mb-0`},_T=N({__name:`ChatMarkdown`,props:{text:{}},setup(e){let t=e,n=G(()=>rT(t.text));return(e,t)=>(L(),R(`div`,oT,[(L(!0),R(I,null,P(n.value,(e,t)=>(L(),R(I,{key:t},[e.kind===`pre`?(L(),R(`pre`,sT,[B(`code`,cT,O(e.code),1)])):e.kind===`table`?(L(),R(`table`,lT,[B(`thead`,null,[B(`tr`,null,[(L(!0),R(I,null,P(e.head,(e,t)=>(L(),R(`th`,{key:t,class:`border border-border bg-muted px-2 py-1.5 text-left font-semibold`},[V(eT,{inline:e},null,8,[`inline`])]))),128))])]),B(`tbody`,null,[(L(!0),R(I,null,P(e.rows,(e,t)=>(L(),R(`tr`,{key:t},[(L(!0),R(I,null,P(e,(e,t)=>(L(),R(`td`,{key:t,class:`border border-border px-2 py-1.5 text-left`},[V(eT,{inline:e},null,8,[`inline`])]))),128))]))),128))])])):e.kind===`blockquote`?(L(),R(`blockquote`,uT,[V(eT,{inline:e.inline},null,8,[`inline`])])):e.kind===`h1`?(L(),R(`h1`,dT,[V(eT,{inline:e.inline},null,8,[`inline`])])):e.kind===`h2`?(L(),R(`h2`,fT,[V(eT,{inline:e.inline},null,8,[`inline`])])):e.kind===`h3`?(L(),R(`h3`,pT,[V(eT,{inline:e.inline},null,8,[`inline`])])):e.kind===`ul`?(L(),R(`ul`,mT,[(L(!0),R(I,null,P(e.items,(e,t)=>(L(),R(`li`,{key:t},[V(eT,{inline:e},null,8,[`inline`])]))),128))])):e.kind===`ol`?(L(),R(`ol`,hT,[(L(!0),R(I,null,P(e.items,(e,t)=>(L(),R(`li`,{key:t},[V(eT,{inline:e},null,8,[`inline`])]))),128))])):e.kind===`p`?(L(),R(`p`,gT,[V(eT,{inline:e.inline},null,8,[`inline`])])):U(``,!0)],64))),128))]))}}),vT={class:`truncate`},yT=N({__name:`ChatNavChip`,props:{path:{},label:{}},setup(e){return(t,n)=>{let r=ma(`RouterLink`);return L(),z(r,{to:e.path,title:`Go to ${e.label||e.path}`,class:`inline-flex max-w-full items-center gap-1.5 rounded-full border border-primary/45 bg-primary-soft px-2.5 py-1 text-xs font-semibold text-link transition-colors hover:border-primary hover:bg-primary/15 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary`},{default:j(()=>[V(A(yd),{"aria-hidden":`true`,class:`size-3.5 shrink-0`}),B(`span`,vT,O(e.label||e.path),1)]),_:1},8,[`to`,`title`])}}}),bT={key:1,class:`flex items-baseline gap-1.5 [overflow-wrap:anywhere]`},xT={class:`font-semibold text-foreground`},ST={key:0,class:`font-mono text-[0.95em] text-fg-subtle`},CT=N({__name:`ChatToolCall`,props:{tool:{},streaming:{type:Boolean}},setup(e){let t=e,n=G(()=>t.tool.name||t.tool.Name||t.tool.tool||`tool`),r=G(()=>t.tool.parameters||t.tool.Parameters||``),i=G(()=>!!(t.tool.err||t.tool.Err||t.tool.failed)),a=G(()=>t.tool.summary||t.tool.Summary||t.tool.text||t.tool.err||t.tool.Err||(t.streaming?i.value?`failed`:`running…`:`done`));return(t,o)=>e.tool.path?(L(),z(yT,{key:0,path:e.tool.path,label:e.tool.label},null,8,[`path`,`label`])):(L(),R(`div`,bT,[V(A(Kd),{"aria-hidden":`true`,class:`size-3.5 shrink-0 self-center text-fg-subtle`}),B(`span`,xT,O(n.value),1),r.value?(L(),R(`code`,ST,O(r.value),1)):U(``,!0),B(`span`,{class:D(A(J)(`text-fg-muted`,i.value&&`text-danger`))},O(a.value),3)]))}}),wT={key:0,class:`mb-2 grid gap-0.5 text-xs`},TT={key:2,class:`whitespace-pre-wrap`},ET=N({__name:`ChatBubble`,props:{text:{},tools:{default:()=>[]},assistant:{type:Boolean,default:!1},streaming:{type:Boolean,default:!1}},setup(e){return(t,n)=>(L(),R(`div`,{class:D([`flex`,e.assistant?`justify-start`:`justify-end`])},[B(`div`,{class:D(A(J)(`max-w-[min(78ch,86%)] rounded-[0.85rem] px-4 py-3 leading-normal [overflow-wrap:anywhere]`,e.assistant?`bg-muted`:`bg-primary/15`))},[e.assistant&&e.tools.length?(L(),R(`div`,wT,[(L(!0),R(I,null,P(e.tools,(t,n)=>(L(),z(CT,{key:n,tool:t,streaming:e.streaming},null,8,[`tool`,`streaming`]))),128))])):U(``,!0),e.assistant?(L(),z(_T,{key:1,text:e.text},null,8,[`text`])):(L(),R(`div`,TT,O(e.text),1)),F(t.$slots,`default`)],2)],2))}}),DT={class:`w-full self-center justify-self-center py-6 text-center`},OT={class:`grid gap-2`},kT=[`onClick`],AT=N({__name:`ChatEmptyState`,emits:[`prompt`],setup(e,{emit:t}){let n=t,r=[`Summarise active tasks`,`Show running agents`,`Check system status`];return(e,t)=>(L(),R(`div`,DT,[t[0]||=B(`span`,{"aria-hidden":`true`,class:`mx-auto mb-3 grid size-9 placLine truncated
`).map(e=>e.trim()).find(Boolean)||``,r=n.length>gj?`${n.slice(0,gj).trimEnd()}…`:n;return{text:r,full:t,truncated:r!==t}}var vj=[`title`],yj=N({__name:`ActivityRow`,props:{event:{}},emits:[`open`],setup(e,{emit:t}){let n=e,r=t,i=G(()=>VA(n.event)),a=G(()=>_j(n.event));function o(){i.value>0&&r(`open`,i.value)}let s=G(()=>n.event.at?ak(n.event.at):`—`);return(e,t)=>(L(),z(A(IO),{class:D(i.value>0?`cursor-pointer`:``),role:i.value>0?`link`:void 0,tabindex:i.value>0?0:void 0,title:i.value>0?`Open task details`:void 0,onClick:o,onKeydown:[du(lu(o,[`prevent`]),[`enter`]),du(lu(o,[`prevent`]),[`space`])]},{default:j(()=>[V(A($),{class:`font-medium`},{default:j(()=>[H(O(n.event.kind||n.event.type||`event`),1)]),_:1}),V(A($),{class:`font-mono`},{default:j(()=>[H(O(i.value>0?`#${i.value}`:`—`),1)]),_:1}),V(A($),{class:`w-[55%] max-w-0`},{default:j(()=>[B(`span`,{class:`block truncate`,title:a.value.truncated?a.value.full:void 0},O(a.value.text),9,vj)]),_:1}),V(A($),null,{default:j(()=>[H(O(s.value),1)]),_:1})]),_:1},8,[`class`,`role`,`tabindex`,`title`,`onKeydown`]))}}),bj={role:`region`,"aria-label":`Live activity`,"aria-live":`polite`},xj=N({__name:`LiveActivityCard`,setup(e){let t=$T(),{activity:n,streamKind:r,streamState:i}=ad(JD());function a(e){t.push(`/tasks?task=${encodeURIComponent(e)}`)}return(e,t)=>(L(),z(A(_O),null,{default:j(()=>[V(A(SO),null,{default:j(()=>[V(A(CO),null,{default:j(()=>[...t[0]||=[H(`Live activity`,-1)]]),_:1}),V(A(bO),null,{default:j(()=>[...t[1]||=[H(`Last 50, newest first`,-1)]]),_:1}),V(A(vO),null,{default:j(()=>[V(A(zO),{variant:A(r)},{default:j(()=>[H(O(A(i)),1)]),_:1},8,[`variant`])]),_:1})]),_:1}),V(A(yO),null,{default:j(()=>[B(`div`,bj,[V(A(PO),null,{default:j(()=>[V(A(RO),null,{default:j(()=>[V(A(IO),null,{default:j(()=>[V(A(LO),null,{default:j(()=>[...t[2]||=[H(`Event`,-1)]]),_:1}),V(A(LO),null,{default:j(()=>[...t[3]||=[H(`Task`,-1)]]),_:1}),V(A(LO),null,{default:j(()=>[...t[4]||=[H(`Detail`,-1)]]),_:1}),V(A(LO),null,{default:j(()=>[...t[5]||=[H(`When`,-1)]]),_:1})]),_:1})]),_:1}),V(A(FO),null,{default:j(()=>[A(n).length?(L(!0),R(I,{key:1},P(A(n),(e,t)=>(L(),z(yj,{key:t,event:e,onOpen:a},null,8,[`event`]))),128)):(L(),z(A(IO),{key:0},{default:j(()=>[V(A($),{colspan:`4`},{default:j(()=>[V(A(wO),null,{default:j(()=>[V(A(DO),null,{default:j(()=>[V(A(AO),null,{default:j(()=>[...t[6]||=[H(`Waiting for activity`,-1)]]),_:1})]),_:1})]),_:1})]),_:1})]),_:1}))]),_:1})]),_:1})])]),_:1})]),_:1}))}}),Sj=N({__name:`Progress`,props:{modelValue:{default:0},max:{},getValueLabel:{},getValueText:{},asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array]}},setup(e){let t=e,n=QS(t,`class`);return(e,r)=>(L(),z(A(Ex),W({"data-slot":`progress`},A(n),{class:A(J)(`bg-muted h-1 rounded-full relative flex w-full items-center overflow-x-hidden`,t.class)}),{default:j(()=>[V(A(Dx),{"data-slot":`progress-indicator`,class:`bg-primary size-full flex-1 transition-all`,style:ve(`transform: translateX(-${100-(t.modelValue??0)}%);`)},null,8,[`style`])]),_:1},16,[`class`]))}}),Cj=`archie.setup-complete.dismissed.v1`;function wj(e,t=globalThis.localStorage){if(!e?.steps?.length)return{kind:`omit`,remaining:[]};let n=e.steps.filter(e=>!e.done);return n.length?(t?.removeItem?.(Cj),{kind:`incomplete`,remaining:n}):t?.getItem?.(`archie.setup-complete.dismissed.v1`)===`1`?{kind:`dismissed`,remaining:[]}:{kind:`complete`,remaining:[]}}function Tj(e=globalThis.localStorage){e?.setItem?.(Cj,`1`)}var Ej={class:`text-lg font-semibold text-link`},Dj={class:`flex flex-col gap-3`},Oj={key:0,class:`mt-0.5 text-xs text-fg-subtle`},kj=N({__name:`SetupPanel`,setup(e){let t=k(wj(PA.value));M(PA,()=>{t.value=wj(PA.value)});let n=G(()=>PA.value?.steps??[]),r=G(()=>{let e=n.value.length;return e?Math.round((e-t.value.remaining.length)/e*100):0});function i(){Tj(),t.value=wj(PA.value)}return(e,a)=>t.value.kind===`incomplete`?(L(),z(A(_O),{key:0},{default:j(()=>[V(A(SO),null,{default:j(()=>[V(A(CO),null,{default:j(()=>[...a[0]||=[H(`Finish setting up`,-1)]]),_:1}),V(A(bO),null,{default:j(()=>[...a[1]||=[H(`Archie needs these before it can work on its own.`,-1)]]),_:1}),V(A(vO),null,{default:j(()=>[B(`span`,Ej,O(r.value)+`%`,1)]),_:1})]),_:1}),V(A(yO),null,{default:j(()=>[V(A(Sj),{"model-value":r.value,class:`mb-4`},null,8,[`model-value`]),B(`ul`,Dj,[(L(!0),R(I,null,P(n.value,(e,t)=>(L(),R(`li`,{key:t,class:`flex items-start gap-3`},[B(`span`,{class:D([`mt-px grid size-[18px] flex-none place-items-center rounded-full border-[1.5px] border-border-strong text-xs text-fg-subtle`,e.done?`border-transparent bg-ok-soft text-ok`:``])},[e.done?(L(),z(A(bd),{key:0,class:`size-3`})):U(``,!0)],2),B(`div`,null,[B(`div`,{class:D([`text-sm`,e.done?`text-fg-muted line-through`:``])},O(e.title),3),e.detail?(L(),R(`div`,Oj,O(e.detail),1)):U(``,!0)])]))),128))])]),_:1})]),_:1})):t.value.kind===`complete`?(L(),z(A(_O),{key:1},{default:j(()=>[V(A(SO),null,{default:j(()=>[V(A(CO),null,{default:j(()=>[...a[2]||=[H(`Setup complete`Line truncated
`)}),t}function iT(e){let t=String(e||``).trim();if(!t.includes(`|`))return null;let n=t.replace(/^\|/,``).replace(/\|$/,``).split(`|`).map(e=>e.trim());return n.length>1&&n.every(e=>e!==``)?n:null}function aT(e){return e.every(e=>/^:?-{3,}:?$/.test(e))}var oT={class:`[overflow-wrap:anywhere]`},sT={key:0,class:`my-2 overflow-auto rounded-md border border-border bg-background/60 p-3`},cT={class:`font-mono text-[0.85em]`},lT={key:1,class:`my-3 w-full border-collapse text-[0.92em]`},uT={key:2,class:`my-2 border-l-[3px] border-primary pl-3 text-fg-muted`},dT={key:3,class:`mt-1 mb-2 text-xl leading-tight font-semibold tracking-[-0.02em]`},fT={key:4,class:`mt-1 mb-2 text-lg leading-tight font-semibold tracking-[-0.02em]`},pT={key:5,class:`mt-1 mb-2 text-base leading-tight font-semibold tracking-[-0.02em]`},mT={key:6,class:`my-2.5 flex list-disc flex-col gap-1 pl-5`},hT={key:7,class:`my-2.5 flex list-decimal flex-col gap-1 pl-5`},gT={key:8,class:`mb-2.5 last:mb-0`},_T=N({__name:`ChatMarkdown`,props:{text:{}},setup(e){let t=e,n=G(()=>rT(t.text));return(e,t)=>(L(),R(`div`,oT,[(L(!0),R(I,null,P(n.value,(e,t)=>(L(),R(I,{key:t},[e.kind===`pre`?(L(),R(`pre`,sT,[B(`code`,cT,O(e.code),1)])):e.kind===`table`?(L(),R(`table`,lT,[B(`thead`,null,[B(`tr`,null,[(L(!0),R(I,null,P(e.head,(e,t)=>(L(),R(`th`,{key:t,class:`border border-border bg-muted px-2 py-1.5 text-left font-semibold`},[V(eT,{inline:e},null,8,[`inline`])]))),128))])]),B(`tbody`,null,[(L(!0),R(I,null,P(e.rows,(e,t)=>(L(),R(`tr`,{key:t},[(L(!0),R(I,null,P(e,(e,t)=>(L(),R(`td`,{key:t,class:`border border-border px-2 py-1.5 text-left`},[V(eT,{inline:e},null,8,[`inline`])]))),128))]))),128))])])):e.kind===`blockquote`?(L(),R(`blockquote`,uT,[V(eT,{inline:e.inline},null,8,[`inline`])])):e.kind===`h1`?(L(),R(`h1`,dT,[V(eT,{inline:e.inline},null,8,[`inline`])])):e.kind===`h2`?(L(),R(`h2`,fT,[V(eT,{inline:e.inline},null,8,[`inline`])])):e.kind===`h3`?(L(),R(`h3`,pT,[V(eT,{inline:e.inline},null,8,[`inline`])])):e.kind===`ul`?(L(),R(`ul`,mT,[(L(!0),R(I,null,P(e.items,(e,t)=>(L(),R(`li`,{key:t},[V(eT,{inline:e},null,8,[`inline`])]))),128))])):e.kind===`ol`?(L(),R(`ol`,hT,[(L(!0),R(I,null,P(e.items,(e,t)=>(L(),R(`li`,{key:t},[V(eT,{inline:e},null,8,[`inline`])]))),128))])):e.kind===`p`?(L(),R(`p`,gT,[V(eT,{inline:e.inline},null,8,[`inline`])])):U(``,!0)],64))),128))]))}}),vT={class:`truncate`},yT=N({__name:`ChatNavChip`,props:{path:{},label:{}},setup(e){return(t,n)=>{let r=ma(`RouterLink`);return L(),z(r,{to:e.path,title:`Go to ${e.label||e.path}`,class:`inline-flex max-w-full items-center gap-1.5 rounded-full border border-primary/45 bg-primary-soft px-2.5 py-1 text-xs font-semibold text-link transition-colors hover:border-primary hover:bg-primary/15 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary`},{default:j(()=>[V(A(yd),{"aria-hidden":`true`,class:`size-3.5 shrink-0`}),B(`span`,vT,O(e.label||e.path),1)]),_:1},8,[`to`,`title`])}}}),bT={key:1,class:`flex items-baseline gap-1.5 [overflow-wrap:anywhere]`},xT={class:`font-semibold text-foreground`},ST={key:0,class:`font-mono text-[0.95em] text-fg-subtle`},CT=N({__name:`ChatToolCall`,props:{tool:{},streaming:{type:Boolean}},setup(e){let t=e,n=G(()=>t.tool.name||t.tool.Name||t.tool.tool||`tool`),r=G(()=>t.tool.parameters||t.tool.Parameters||``),i=G(()=>!!(t.tool.err||t.tool.Err||t.tool.failed)),a=G(()=>t.tool.summary||t.tool.Summary||t.tool.text||t.tool.err||t.tool.Err||(t.streaming?i.value?`failed`:`running…`:`done`));return(t,o)=>e.tool.path?(L(),z(yT,{key:0,path:e.tool.path,label:e.tool.label},null,8,[`path`,`label`])):(L(),R(`div`,bT,[V(A(Kd),{"aria-hidden":`true`,class:`size-3.5 shrink-0 self-center text-fg-subtle`}),B(`span`,xT,O(n.value),1),r.value?(L(),R(`code`,ST,O(r.value),1)):U(``,!0),B(`span`,{class:D(A(J)(`text-fg-muted`,i.value&&`text-danger`))},O(a.value),3)]))}}),wT={key:0,class:`mb-2 grid gap-0.5 text-xs`},TT={key:2,class:`whitespace-pre-wrap`},ET=N({__name:`ChatBubble`,props:{text:{},tools:{default:()=>[]},assistant:{type:Boolean,default:!1},streaming:{type:Boolean,default:!1}},setup(e){return(t,n)=>(L(),R(`div`,{class:D([`flex`,e.assistant?`justify-start`:`justify-end`])},[B(`div`,{class:D(A(J)(`max-w-[min(78ch,86%)] rounded-[0.85rem] px-4 py-3 leading-normal [overflow-wrap:anywhere]`,e.assistant?`bg-muted`:`bg-primary/15`))},[e.assistant&&e.tools.length?(L(),R(`div`,wT,[(L(!0),R(I,null,P(e.tools,(t,n)=>(L(),z(CT,{key:n,tool:t,streaming:e.streaming},null,8,[`tool`,`streaming`]))),128))])):U(``,!0),e.assistant?(L(),z(_T,{key:1,text:e.text},null,8,[`text`])):(L(),R(`div`,TT,O(e.text),1)),F(t.$slots,`default`)],2)],2))}}),DT={class:`w-full self-center justify-self-center py-6 text-center`},OT={class:`grid gap-2`},kT=[`onClick`],AT=N({__name:`ChatEmptyState`,emits:[`prompt`],setup(e,{emit:t}){let n=t,r=[`Summarise active tasks`,`Show running agents`,`Check system status`];return(e,t)=>(L(),R(`div`,DT,[t[0]||=B(`span`,{"aria-hidden":`true`,class:`mx-auto mb-3 grid size-9 placLine truncated
`).map(e=>e.trim()).find(Boolean)||``,r=n.length>_j?`${n.slice(0,_j).trimEnd()}…`:n;return{text:r,full:t,truncated:r!==t}}var yj=[`title`],bj=N({__name:`ActivityRow`,props:{event:{}},emits:[`open`],setup(e,{emit:t}){let n=e,r=t,i=G(()=>HA(n.event)),a=G(()=>vj(n.event));function o(){i.value>0&&r(`open`,i.value)}let s=G(()=>n.event.at?ak(n.event.at):`—`);return(e,t)=>(L(),z(A(IO),{class:D(i.value>0?`cursor-pointer`:``),role:i.value>0?`link`:void 0,tabindex:i.value>0?0:void 0,title:i.value>0?`Open task details`:void 0,onClick:o,onKeydown:[du(lu(o,[`prevent`]),[`enter`]),du(lu(o,[`prevent`]),[`space`])]},{default:j(()=>[V(A($),{class:`font-medium`},{default:j(()=>[H(O(n.event.kind||n.event.type||`event`),1)]),_:1}),V(A($),{class:`font-mono`},{default:j(()=>[H(O(i.value>0?`#${i.value}`:`—`),1)]),_:1}),V(A($),{class:`w-[55%] max-w-0`},{default:j(()=>[B(`span`,{class:`block truncate`,title:a.value.truncated?a.value.full:void 0},O(a.value.text),9,yj)]),_:1}),V(A($),null,{default:j(()=>[H(O(s.value),1)]),_:1})]),_:1},8,[`class`,`role`,`tabindex`,`title`,`onKeydown`]))}}),xj={role:`region`,"aria-label":`Live activity`,"aria-live":`polite`},Sj=N({__name:`LiveActivityCard`,setup(e){let t=$T(),{activity:n,streamKind:r,streamState:i}=ad(JD());function a(e){t.push(`/tasks?task=${encodeURIComponent(e)}`)}return(e,t)=>(L(),z(A(_O),null,{default:j(()=>[V(A(SO),null,{default:j(()=>[V(A(CO),null,{default:j(()=>[...t[0]||=[H(`Live activity`,-1)]]),_:1}),V(A(bO),null,{default:j(()=>[...t[1]||=[H(`Last 50, newest first`,-1)]]),_:1}),V(A(vO),null,{default:j(()=>[V(A(zO),{variant:A(r)},{default:j(()=>[H(O(A(i)),1)]),_:1},8,[`variant`])]),_:1})]),_:1}),V(A(yO),null,{default:j(()=>[B(`div`,xj,[V(A(PO),null,{default:j(()=>[V(A(RO),null,{default:j(()=>[V(A(IO),null,{default:j(()=>[V(A(LO),null,{default:j(()=>[...t[2]||=[H(`Event`,-1)]]),_:1}),V(A(LO),null,{default:j(()=>[...t[3]||=[H(`Task`,-1)]]),_:1}),V(A(LO),null,{default:j(()=>[...t[4]||=[H(`Detail`,-1)]]),_:1}),V(A(LO),null,{default:j(()=>[...t[5]||=[H(`When`,-1)]]),_:1})]),_:1})]),_:1}),V(A(FO),null,{default:j(()=>[A(n).length?(L(!0),R(I,{key:1},P(A(n),(e,t)=>(L(),z(bj,{key:t,event:e,onOpen:a},null,8,[`event`]))),128)):(L(),z(A(IO),{key:0},{default:j(()=>[V(A($),{colspan:`4`},{default:j(()=>[V(A(wO),null,{default:j(()=>[V(A(DO),null,{default:j(()=>[V(A(AO),null,{default:j(()=>[...t[6]||=[H(`Waiting for activity`,-1)]]),_:1})]),_:1})]),_:1})]),_:1})]),_:1}))]),_:1})]),_:1})])]),_:1})]),_:1}))}}),Cj=N({__name:`Progress`,props:{modelValue:{default:0},max:{},getValueLabel:{},getValueText:{},asChild:{type:Boolean},as:{},class:{type:[Boolean,null,String,Object,Array]}},setup(e){let t=e,n=QS(t,`class`);return(e,r)=>(L(),z(A(Ex),W({"data-slot":`progress`},A(n),{class:A(J)(`bg-muted h-1 rounded-full relative flex w-full items-center overflow-x-hidden`,t.class)}),{default:j(()=>[V(A(Dx),{"data-slot":`progress-indicator`,class:`bg-primary size-full flex-1 transition-all`,style:ve(`transform: translateX(-${100-(t.modelValue??0)}%);`)},null,8,[`style`])]),_:1},16,[`class`]))}}),wj=`archie.setup-complete.dismissed.v1`;function Tj(e,t=globalThis.localStorage){if(!e?.steps?.length)return{kind:`omit`,remaining:[]};let n=e.steps.filter(e=>!e.done);return n.length?(t?.removeItem?.(wj),{kind:`incomplete`,remaining:n}):t?.getItem?.(`archie.setup-complete.dismissed.v1`)===`1`?{kind:`dismissed`,remaining:[]}:{kind:`complete`,remaining:[]}}function Ej(e=globalThis.localStorage){e?.setItem?.(wj,`1`)}var Dj={class:`text-lg font-semibold text-link`},Oj={class:`flex flex-col gap-3`},kj={key:0,class:`mt-0.5 text-xs text-fg-subtle`},Aj=N({__name:`SetupPanel`,setup(e){let t=k(Tj(FA.value));M(FA,()=>{t.value=Tj(FA.value)});let n=G(()=>FA.value?.steps??[]),r=G(()=>{let e=n.value.length;return e?Math.round((e-t.value.remaining.length)/e*100):0});function i(){Ej(),t.value=Tj(FA.value)}return(e,a)=>t.value.kind===`incomplete`?(L(),z(A(_O),{key:0},{default:j(()=>[V(A(SO),null,{default:j(()=>[V(A(CO),null,{default:j(()=>[...a[0]||=[H(`Finish setting up`,-1)]]),_:1}),V(A(bO),null,{default:j(()=>[...a[1]||=[H(`Archie needs these before it can work on its own.`,-1)]]),_:1}),V(A(vO),null,{default:j(()=>[B(`span`,Dj,O(r.value)+`%`,1)]),_:1})]),_:1}),V(A(yO),null,{default:j(()=>[V(A(Cj),{"model-value":r.value,class:`mb-4`},null,8,[`model-value`]),B(`ul`,Oj,[(L(!0),R(I,null,P(n.value,(e,t)=>(L(),R(`li`,{key:t,class:`flex items-start gap-3`},[B(`span`,{class:D([`mt-px grid size-[18px] flex-none place-items-center rounded-full border-[1.5px] border-border-strong text-xs text-fg-subtle`,e.done?`border-transparent bg-ok-soft text-ok`:``])},[e.done?(L(),z(A(bd),{key:0,class:`size-3`})):U(``,!0)],2),B(`div`,null,[B(`div`,{class:D([`text-sm`,e.done?`text-fg-muted line-through`:``])},O(e.title),3),e.detail?(L(),R(`div`,kj,O(e.detail),1)):U(``,!0)])]))),128))])]),_:1})]),_:1})):t.value.kind===`complete`?(L(),z(A(_O),{key:1},{default:j(()=>[V(A(SO),null,{default:j(()=>[V(A(CO),null,{default:j(()=>[...a[2]||=[H(`Setup complete`Line truncated
+43
View File
@@ -0,0 +1,43 @@
<script setup lang="ts">
import { computed } from "vue";
import { Badge } from "@/components/ui/badge";
import { useControlPlaneStore, type ApplyState } from "@/stores/control-plane";
const props = defineProps<{ kind: string }>();
const store = useControlPlaneStore();
const rows = computed(() => store.applyStatusFor(props.kind));
// A process that stopped reporting or never reported is never shown as an
// error: the setting may be fine and the process simply absent, which is a
// different thing an operator acts on differently.
const variants: Record<ApplyState, "ok" | "warn" | "danger" | "idle"> = {
running: "ok",
"pending-restart": "warn",
failed: "danger",
unknown: "warn",
"not-reporting": "idle",
};
const labels: Record<ApplyState, string> = {
running: "Running",
"pending-restart": "Restart pending",
failed: "Failed",
unknown: "Not reporting",
"not-reporting": "Never reported",
};
</script>
<template>
<div v-if="rows.length" class="flex flex-col gap-2">
<p class="text-xs font-medium text-muted-foreground">Applied by</p>
<div v-for="row in rows" :key="row.process" class="flex flex-col gap-1">
<div class="flex items-center gap-2 text-xs">
<Badge :variant="variants[row.state]">{{ labels[row.state] }}</Badge>
<span class="font-mono">{{ row.process }}</span>
<span v-if="row.state !== 'not-reporting'" class="text-muted-foreground">version {{ row.version }}</span>
</div>
<p v-if="row.error" class="text-xs text-destructive">{{ row.error }}</p>
</div>
</div>
</template>
@@ -8,6 +8,7 @@ import { Input } from "@/components/ui/input";
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { Spinner } from "@/components/ui/spinner";
import { useControlPlaneStore, type ResourceDescriptor } from "@/stores/control-plane";
import ApplyStatusRows from "./ApplyStatusRows.vue";
import ConfigCard from "./ConfigCard.vue";
import ResourceHistory from "./ResourceHistory.vue";
@@ -114,6 +115,7 @@ async function save(): Promise<void> {
</Button>
</div>
</form>
<ApplyStatusRows :kind="descriptor.kind" />
<ResourceHistory :kind="descriptor.kind" />
</ConfigCard>
</template>
+75 -1
View File
@@ -22,6 +22,55 @@ export interface ControlPlaneResource {
interface ResourceResponse { resource: ControlPlaneResource }
/** One process's report about one resource kind, as the server derives it.
* `state` is liveness only: the server knows whether a record went stale, not
* which version the page is showing. */
export interface ApplyStatusRecord {
process: string;
kind: string;
applied_version: number;
error?: string;
reported_at: string;
state: "current" | "failed" | "unknown";
}
export interface ApplyStatusResponse {
records: ApplyStatusRecord[];
processes: string[];
}
/** What the settings page says about one process for one resource. */
export type ApplyState = "running" | "pending-restart" | "failed" | "unknown" | "not-reporting";
export interface ApplyStatusRow {
process: string;
state: ApplyState;
version: number;
error: string;
}
/** applyStatusForKind reads every known process against the stored version, so
* a process that has never reported is a row saying so rather than a missing
* one. Staleness wins over the version comparison: a record that stopped being
* re-stamped describes a process that may no longer exist, so it can never
* read as running. */
export function applyStatusForKind(
records: ApplyStatusRecord[],
processes: string[],
kind: string,
storedVersion: number,
): ApplyStatusRow[] {
return processes.map((process) => {
const record = records.find((entry) => entry.process === process && entry.kind === kind);
if (!record) return { process, state: "not-reporting" as const, version: 0, error: "" };
const row = { process, version: record.applied_version, error: record.error ?? "" };
if (record.state === "unknown") return { ...row, state: "unknown" as const };
if (record.state === "failed") return { ...row, state: "failed" as const };
if (record.applied_version < storedVersion) return { ...row, state: "pending-restart" as const };
return { ...row, state: "running" as const };
});
}
/** One entry of a resource's audit trail. `value` is what that version held,
* which is also the payload a restore replays through the replace command. */
export interface ResourceRevision {
@@ -108,6 +157,7 @@ export const useControlPlaneStore = defineStore("control-plane", () => {
const catalogError = ref("");
const states = reactive<Record<string, ResourceState>>({});
const streams = new Map<string, EventSource>();
const applyStatus = ref<ApplyStatusResponse>({ records: [], processes: [] });
const genericResources = computed(() => catalog.value.filter((item) =>
item.apply_mode !== "domain-managed" && !item.query_service && item.commands.includes("replace"),
@@ -150,11 +200,31 @@ export const useControlPlaneStore = defineStore("control-plane", () => {
streams.set(kind, stream);
}
/** Re-read on every load and after each save, so the page reflects what the
* processes did with the edit rather than what was stored. A failure leaves
* the previous rows: apply status is a diagnostic, and losing it must not
* take the settings page with it. */
async function loadApplyStatus(): Promise<void> {
try {
applyStatus.value = await request<ApplyStatusResponse>("/api/control-plane/apply-status");
} catch {
// Keep whatever was last read.
}
}
/** Rows for one resource, every known process included. */
function applyStatusFor(kind: string): ApplyStatusRow[] {
return applyStatusForKind(
applyStatus.value.records, applyStatus.value.processes, kind, stateFor(kind).resource?.version ?? 0,
);
}
async function load(): Promise<void> {
try {
const response = await request<{ resources?: ResourceDescriptor[] }>("/api/control-plane/catalog");
catalog.value = response.resources ?? [];
catalogError.value = "";
await loadApplyStatus();
await Promise.all(genericResources.value.map(async ({ kind }) => {
await loadResource(kind);
watchResource(kind);
@@ -176,6 +246,7 @@ export const useControlPlaneStore = defineStore("control-plane", () => {
{ method: "POST", body: commandBody(value, state.resource.version) },
);
apply(response.resource);
await loadApplyStatus();
return true;
} catch (error) {
if (error instanceof ControlPlaneError && error.status === 409) {
@@ -207,5 +278,8 @@ export const useControlPlaneStore = defineStore("control-plane", () => {
}
}
return { catalog, catalogError, states, genericResources, history, load, replace, shippedWorkflows, stateFor };
return {
applyStatusFor, catalog, catalogError, states, genericResources,
history, load, loadApplyStatus, replace, shippedWorkflows, stateFor,
};
});
+29
View File
@@ -6,6 +6,7 @@ import {
resourcesForPage,
upsertWorkflowDefinition,
removeWorkflowDefinition,
applyStatusForKind,
} from "../src/stores/control-plane.ts";
test("control-plane commands keep the edited version and typed values", () => {
@@ -55,3 +56,31 @@ test("workflow edits replace by id without dropping sibling definitions", () =>
definitions: [{ id: "tdd", yaml: "id: tdd\nsteps: []\n" }],
});
});
test("apply status names a process behind the stored version and one that stopped reporting", () => {
const records = [
{ process: "archied", kind: "tool-settings", applied_version: 7, reported_at: "", state: "current" },
{ process: "archie-gateway", kind: "tool-settings", applied_version: 6, reported_at: "", state: "current" },
{ process: "archie-messaging", kind: "tool-settings", applied_version: 7, reported_at: "", state: "unknown" },
{ process: "archied", kind: "plugin-settings", applied_version: 2, reported_at: "", state: "current" },
];
const processes = ["archied", "archie-gateway", "archie-messaging"];
assert.deepEqual(applyStatusForKind(records, processes, "tool-settings", 7), [
{ process: "archied", state: "running", version: 7, error: "" },
{ process: "archie-gateway", state: "pending-restart", version: 6, error: "" },
{ process: "archie-messaging", state: "unknown", version: 7, error: "" },
]);
});
test("apply status shows a process that has never reported, and one that rejected the edit", () => {
const processes = ["archied", "archie-gateway"];
const records = [
{ process: "archied", kind: "tool-settings", applied_version: 6, reported_at: "", state: "failed", error: "validate database settings: bad policy" },
];
assert.deepEqual(applyStatusForKind(records, processes, "tool-settings", 7), [
{ process: "archied", state: "failed", version: 6, error: "validate database settings: bad policy" },
{ process: "archie-gateway", state: "not-reporting", version: 0, error: "" },
]);
});