Housekeeping: four judgement turns fit; the view is live
Paul's ruling: four turns must fit, so a judgement turn reserves its share of the day's tokens (150,000 / 4 = 37,500) rather than a fixed 40,000; the token budget stays the binding total. The Housekeeping view is a live region: nav-stream.js hears housekeeping events and work-stream.js swaps the view in place; its forms (Undo, a detector's switch) post in the background (housekeeping.js), plain posts without scripts. TestBrowserHousekeeping: a new combine, an Undo and a switch land with no reload.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
10 files changed,
+63
−19
internal/equipo/chat/housekeeping_store_test.go+9 −9internal/equipo/handlers.go+1 −0internal/equipo/housekeeping/housekeeping_test.go+3 −3internal/equipo/housekeeping/policy.go+5 −3internal/equipo/housekeeping_page.go+1 −1internal/equipo/static/housekeeping.js+27 −0internal/equipo/static/nav-stream.js+5 −0internal/equipo/templates/chrome.html+1 −1internal/equipo/templates/housekeeping.html+1 −1internal/thintest/housekeeping_browser_test.go+10 −1
diff --git a/internal/equipo/chat/housekeeping_store_test.go b/internal/equipo/chat/housekeeping_store_test.go| index d8eb3b21..e1c9576b 100644 |
| --- a/internal/equipo/chat/housekeeping_store_test.go |
| +++ b/internal/equipo/chat/housekeeping_store_test.go |
| @@ -404,20 +404,20 @@ func (r *hkRig) state(key string) hkRecord { |
| // and three retries a day per person, is reserved in the claim's |
| // transaction: exhaustion holds, two claims racing the last room cannot |
| // both pass, and a reservation counts in full until its attempt's |
| -// termination and charge are in (unknown usage charges it all). At |
| -// 40,000 tokens a judgement turn, the token limit binds at the third. |
| +// termination and charge are in (unknown usage charges it all). A |
| +// judgement turn reserves its share, 37,500, so all four fit exactly. |
| func TestHousekeepingReservation(t *testing.T) { |
| r := newHKRig(t) |
| r.task("tkone", "Crash on launch", hkOwner) |
| r.connection("cn1", "local1", wire.ConnHealthy, 0.2, r.now) |
| d := judge(housekeeping.JudgementTurn) |
| - for i := range 2 { |
| + for i := range 3 { |
| r.run(d, judgeFinding(i)) |
| - if s := r.state(judgeFinding(i).Key); s.State != wire.ActionClaimed || s.ReservedTurns != 1 || s.ReservedTokens != 40000 { |
| + if s := r.state(judgeFinding(i).Key); s.State != wire.ActionClaimed || s.ReservedTurns != 1 || s.ReservedTokens != 37500 { |
| t.Fatalf("claim %d: %+v", i, s) |
| } |
| } |
| - // Two claims race the third, the last that fits: exactly one wins. |
| + // Two claims race the fourth, the last that fits: exactly one wins. |
| var wg sync.WaitGroup |
| for _, n := range []int{10, 11} { |
| wg.Add(1) |
| @@ -438,14 +438,14 @@ func TestHousekeepingReservation(t *testing.T) { |
| if held.State != wire.ActionHeld || held.Reason != wire.ReasonHeldBudget { |
| t.Fatalf("the loser: %+v", held) |
| } |
| - // Exhausted: another is held, and the view shows three reserved. |
| + // Exhausted: a fifth is held, and the view shows the day reserved. |
| r.run(d, judgeFinding(5)) |
| if s := r.state("judge:5"); s.State != wire.ActionHeld || s.Reason != wire.ReasonHeldBudget { |
| t.Fatalf("after the last: %+v", s) |
| } |
| var view wire.Housekeeping |
| r.must(r.tx(func(t *txn) error { var e error; view, e = t.housekeepingView(hkOwner); return e })) |
| - if view.Budget.Turns != (wire.BudgetMeter{Reserved: 3, Limit: 4}) || view.Budget.Tokens != (wire.BudgetMeter{Reserved: 120000, Limit: 150000}) { |
| + if view.Budget.Turns != (wire.BudgetMeter{Reserved: 4, Limit: 4}) || view.Budget.Tokens != (wire.BudgetMeter{Reserved: 150000, Limit: 150000}) { |
| t.Fatalf("budget: %+v", view.Budget) |
| } |
| // Turns bind too: with small turns, a fifth is held on turns alone. |
| @@ -467,7 +467,7 @@ func TestHousekeepingReservation(t *testing.T) { |
| // charges the whole reservation; a complete figure charges itself. |
| first := r.state("judge:0") |
| r.must(r.tx(func(t *txn) error { return t.hkSettle(&first, nil, false, false) })) |
| - if s := r.state("judge:0"); !s.Releasing || s.ChargedTokens != 40000 || s.ChargedComplete { |
| + if s := r.state("judge:0"); !s.Releasing || s.ChargedTokens != 37500 || s.ChargedComplete { |
| t.Fatalf("unknown usage: %+v", s) |
| } |
| second := r.state("judge:1") |
| @@ -482,7 +482,7 @@ func TestHousekeepingReservation(t *testing.T) { |
| })) |
| // judge:1 is charged 12,000 but its row is still claimed, so it counts |
| // its full reservation until it moves on. |
| - if charged.Tokens != 52000 || used.Turns != 3 { |
| + if charged.Tokens != 49500 || used.Turns != 4 { |
| t.Fatalf("used %+v charged %+v", used, charged) |
| } |
diff --git a/internal/equipo/handlers.go b/internal/equipo/handlers.go| index 9dab0505..fa031385 100644 |
| --- a/internal/equipo/handlers.go |
| +++ b/internal/equipo/handlers.go |
| @@ -44,6 +44,7 @@ type pageData struct { |
| Housekeeping housekeepingView |
| // HousekeepingSettings is Settings' Housekeeping section. |
| HousekeepingSettings *hkSettingsView |
| + HousekeepingStream bool |
| Models modelsView |
| ConnectionsStream bool |
| ChatStream bool |
diff --git a/internal/equipo/housekeeping/housekeeping_test.go b/internal/equipo/housekeeping/housekeeping_test.go| index 68499934..11f868ce 100644 |
| --- a/internal/equipo/housekeeping/housekeeping_test.go |
| +++ b/internal/equipo/housekeeping/housekeeping_test.go |
| @@ -104,7 +104,7 @@ func TestRateTable(t *testing.T) { |
| t.Errorf("%s: %+v", id, d) |
| } |
| } |
| - if Limits != (Cost{Turns: 4, Tokens: 150000, Retries: 3}) || JudgementTurn != (Cost{Turns: 1, Tokens: 40000}) || AutoRetry != (Cost{Retries: 1, Tokens: 100000}) { |
| + if Limits != (Cost{Turns: 4, Tokens: 150000, Retries: 3}) || JudgementTurn != (Cost{Turns: 1, Tokens: 37500}) || AutoRetry != (Cost{Retries: 1, Tokens: 100000}) { |
| t.Fatalf("budget: %+v %+v %+v", Limits, JudgementTurn, AutoRetry) |
| } |
| if ActionsPerDay != 10 || SuggestionsPerDay != 5 || HeldPerPerson != 20 || StandDownAt != 0.8 || FailuresToDisable != 2 { |
| @@ -113,9 +113,9 @@ func TestRateTable(t *testing.T) { |
| } |
| func TestFitsAndStandDown(t *testing.T) { |
| - used := Cost{Turns: 3, Tokens: 110000} |
| + used := Cost{Turns: 3, Tokens: 112500} |
| if !Fits(used, JudgementTurn, Limits) { |
| - t.Fatal("the fourth turn with 150,000 tokens should fit") |
| + t.Fatal("the fourth turn should fit exactly") |
| } |
| if Fits(used.Add(Cost{Tokens: 1}), JudgementTurn, Limits) { |
| t.Fatal("one token over should not fit") |
diff --git a/internal/equipo/housekeeping/policy.go b/internal/equipo/housekeeping/policy.go| index 1c04efca..cfdedc1c 100644 |
| --- a/internal/equipo/housekeeping/policy.go |
| +++ b/internal/equipo/housekeeping/policy.go |
| @@ -8,10 +8,12 @@ import "time" |
| var Limits = Cost{Turns: 4, Tokens: 150_000, Retries: 3} |
| // What a spending action reserves (spec §4): a judgement turn one turn |
| -// and 40,000 tokens; an automatic retry one retry and 100,000 tokens for |
| -// the retried step and the review and checks after it. |
| +// and an equal share of the day's tokens (150,000 / 4 = 37,500, Paul's |
| +// ruling: four turns must fit; the token budget stays the binding |
| +// total); an automatic retry one retry and 100,000 tokens for the |
| +// retried step and the review and checks after it. |
| var ( |
| - JudgementTurn = Cost{Turns: 1, Tokens: 40_000} |
| + JudgementTurn = Cost{Turns: 1, Tokens: Limits.Tokens / Limits.Turns} |
| AutoRetry = Cost{Retries: 1, Tokens: 100_000} |
| ) |
diff --git a/internal/equipo/housekeeping_page.go b/internal/equipo/housekeeping_page.go| index 26829acc..691c718c 100644 |
| --- a/internal/equipo/housekeeping_page.go |
| +++ b/internal/equipo/housekeeping_page.go |
| @@ -137,7 +137,7 @@ func (a *application) housekeepingPage(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| data.Title = "housekeeping.title" |
| - data.Housekeeping = housekeepingLines(h) |
| + data.Housekeeping, data.HousekeepingStream = housekeepingLines(h), true |
| render(w, "housekeeping", data) |
| } |
diff --git a/internal/equipo/static/housekeeping.js b/internal/equipo/static/housekeeping.js| new file mode 100644 |
| index 00000000..05f5d2c5 |
| --- /dev/null |
| +++ b/internal/equipo/static/housekeeping.js |
| @@ -0,0 +1,27 @@ |
| +// The Housekeeping view without reloads. It is a live region: |
| +// nav-stream.js hears housekeeping, task and card events and |
| +// work-stream.js renders the view again and swaps it in place. Its forms |
| +// (Undo, a detector's switch) post in the background; the event their |
| +// change writes brings the new view. Without scripts they post as usual. |
| +(function () { |
| + "use strict"; |
| + if (!document.querySelector("[data-housekeeping]") || !window.fetch || !window.FormData || !window.URLSearchParams) return; |
| + function work() { |
| + document.dispatchEvent(new CustomEvent("equipo:work", { detail: { type: "housekeeping" } })); |
| + } |
| + document.addEventListener("submit", function (e) { |
| + var form = e.target; |
| + if (!form.closest || !form.closest("[data-housekeeping]")) return; |
| + e.preventDefault(); |
| + var button = form.querySelector("button"); |
| + if (button) button.disabled = true; |
| + fetch(form.action, { method: "POST", credentials: "same-origin", headers: { "Accept": "application/json" }, body: new URLSearchParams(new FormData(form)) }) |
| + .then(function (r) { if (!r.ok) throw new Error("post"); }) |
| + .then(function () { |
| + // Out of the form, so the swap is not held for it. |
| + if (document.activeElement && document.activeElement.blur) document.activeElement.blur(); |
| + work(); |
| + }) |
| + .catch(function () { form.submit(); }); |
| + }); |
| +})(); |
diff --git a/internal/equipo/static/nav-stream.js b/internal/equipo/static/nav-stream.js| index 91a4601f..0300f8f0 100644 |
| --- a/internal/equipo/static/nav-stream.js |
| +++ b/internal/equipo/static/nav-stream.js |
| @@ -144,6 +144,11 @@ |
| soon(); |
| work("card"); |
| }); |
| + // The Housekeeping view follows its own resource. |
| + source.addEventListener("housekeeping", function (event) { |
| + seen(event); |
| + work("housekeeping"); |
| + }); |
| ["message", "turn", "runner", "ping"].forEach(function (type) { |
| source.addEventListener(type, seen); |
| }); |
diff --git a/internal/equipo/templates/chrome.html b/internal/equipo/templates/chrome.html| index 210f7236..371bd8b0 100644 |
| --- a/internal/equipo/templates/chrome.html |
| +++ b/internal/equipo/templates/chrome.html |
| @@ -1,6 +1,6 @@ |
| {{define "rail-brand"}}<span hidden></span>{{end}} |
| {{define "title"}}{{copy .Title}} · {{copy "brand"}}{{end}} |
| -{{define "head"}}{{.Live.Head (T "rastrillo.ui.live.paused") (T "rastrillo.ui.live.unconfirmed")}}<link rel="stylesheet" href="{{asset "static/equipo.css"}}"><script defer src="{{asset "static/nav-stream.js"}}"></script><script defer src="{{asset "static/work-stream.js"}}"></script>{{if eq .Key "thinking"}}<script defer src="{{asset "static/stardust.js"}}"></script><script defer src="{{asset "static/thinking-preview.js"}}"></script>{{end}}{{if or .ConnectionsStream .ChatStream}}<script defer src="{{asset "static/stardust.js"}}"></script>{{end}}{{if .ConnectionsStream}}<script defer src="{{asset "static/connections.js"}}"></script>{{end}}{{if .ChatStream}}<script defer src="{{asset "static/chat-stream.js"}}"></script><script defer src="{{asset "static/chat-compose.js"}}"></script><script defer src="{{asset "static/ask-target.js"}}"></script>{{if eq .Key "conversation"}}<script defer src="{{asset "static/chat-anchor.js"}}"></script>{{end}}{{else if eq .Key "conversation"}}<script defer blocking="render" src="{{asset "static/chat-navigation.js"}}"></script><script defer src="{{asset "static/chat.js"}}"></script><script defer src="{{asset "static/chat-send.js"}}"></script>{{end}}{{end}} |
| +{{define "head"}}{{.Live.Head (T "rastrillo.ui.live.paused") (T "rastrillo.ui.live.unconfirmed")}}<link rel="stylesheet" href="{{asset "static/equipo.css"}}"><script defer src="{{asset "static/nav-stream.js"}}"></script><script defer src="{{asset "static/work-stream.js"}}"></script>{{if .HousekeepingStream}}<script defer src="{{asset "static/housekeeping.js"}}"></script>{{end}}{{if eq .Key "thinking"}}<script defer src="{{asset "static/stardust.js"}}"></script><script defer src="{{asset "static/thinking-preview.js"}}"></script>{{end}}{{if or .ConnectionsStream .ChatStream}}<script defer src="{{asset "static/stardust.js"}}"></script>{{end}}{{if .ConnectionsStream}}<script defer src="{{asset "static/connections.js"}}"></script>{{end}}{{if .ChatStream}}<script defer src="{{asset "static/chat-stream.js"}}"></script><script defer src="{{asset "static/chat-compose.js"}}"></script><script defer src="{{asset "static/ask-target.js"}}"></script>{{if eq .Key "conversation"}}<script defer src="{{asset "static/chat-anchor.js"}}"></script>{{end}}{{else if eq .Key "conversation"}}<script defer blocking="render" src="{{asset "static/chat-navigation.js"}}"></script><script defer src="{{asset "static/chat.js"}}"></script><script defer src="{{asset "static/chat-send.js"}}"></script>{{end}}{{end}} |
| {{define "up"}}/work{{if .Key}}#nav-{{.Key}}{{end}}{{end}} |
| {{define "up-label"}}{{.TeamName}}{{end}} |
| {{define "brand"}}<a rst-shell-brand href="/work">{{icon "users"}}{{.TeamName}}</a>{{end}} |
diff --git a/internal/equipo/templates/housekeeping.html b/internal/equipo/templates/housekeeping.html| index 6b8393b0..8d34a82d 100644 |
| --- a/internal/equipo/templates/housekeeping.html |
| +++ b/internal/equipo/templates/housekeeping.html |
| @@ -2,7 +2,7 @@ |
| {{define "up"}}/conversation{{end}} |
| {{define "title"}}{{copy "housekeeping.title"}}{{end}} |
| {{define "content"}}{{with .Housekeeping}} |
| -<section equipo-notebook equipo-hk data-housekeeping{{if .Paused}} data-paused{{end}}> |
| +<section equipo-notebook equipo-hk data-housekeeping data-work-live data-work-region id="housekeeping-view"{{if .Paused}} data-paused{{end}}> |
| <header equipo-notebook-head equipo-hk-head><div><h1>{{copy "housekeeping.title"}}</h1><p>{{copy "housekeeping.lede"}}</p></div> |
| <p equipo-hk-to-settings><a href="/settings#housekeeping" data-hk-settings-link>{{copy "housekeeping.settings_link"}}</a></p></header> |
| {{if .Paused}}<p equipo-hk-paused role="status">{{copy "housekeeping.paused"}}</p>{{end}} |
diff --git a/internal/thintest/housekeeping_browser_test.go b/internal/thintest/housekeeping_browser_test.go| index 93b3c118..faef4bfd 100644 |
| --- a/internal/thintest/housekeeping_browser_test.go |
| +++ b/internal/thintest/housekeeping_browser_test.go |
| @@ -79,13 +79,19 @@ func TestBrowserHousekeeping(t *testing.T) { |
| p.stop() |
| } |
| - // Undo from the view: the action reads Undone and the task is back. |
| + // Live: the view follows the stream. A new combine arrives, Undo |
| + // applies and a detector switches, all without a reload. |
| p := openInner(t, r.inst.URL, r.inst.Cookie(), 1280, 900, false, "light", "no-preference") |
| defer p.stop() |
| p.open("/housekeeping") |
| + r.pair("b2", "Compose sheet keyboard covers the send button") |
| + r.tidy() |
| + p.wait(`document.querySelectorAll('[equipo-hk-action]').length===3`, "the new action, live") |
| + p.stayed("a new action") |
| id := eval[string](p, `document.querySelector('[equipo-hk-action]').dataset.action`) |
| p.click(`[data-action="` + id + `"] [data-hk-undo]`) |
| p.wait(`document.querySelector('[data-action="`+id+`"][data-undone]')`, "the action undone") |
| + p.stayed("Undo") |
| p.check(`!document.querySelector('[data-action="`+id+`"] [data-hk-undo]')`, "no Undo after Undo") |
| p.check(`document.querySelector('[data-action="`+id+`"] [data-hk-state]').textContent==='Undone'`, "state words") |
| a := r.housekeeping() |
| @@ -96,6 +102,9 @@ func TestBrowserHousekeeping(t *testing.T) { |
| } |
| } |
| } |
| + p.click(`[data-detector="duplicate_possible"] [data-hk-detector-off]`) |
| + p.wait(`document.querySelector('[data-detector="duplicate_possible"][data-off]')`, "detector off") |
| + p.stayed("a detector switch") |
| p.shot("hk-view-undone-1280") |
| // Settings' Housekeeping section, at both sizes: Pause, quiet hours |