Housekeeping in Settings: Pause, quiet hours per person, activity link
Settings' Housekeeping section (a partial for UX1's Settings page, on today's /settings until it lands): Pause or Resume, the person's quiet hours (from and until in whole hours, none when equal, default 22:00 to 08:00) and the link to the activity view. The view links to Settings in place of its own Pause. Quiet hours are stored per person (0052 is not yet applied anywhere) and in the API (Housekeeping.quiet, SetHousekeeping.quiet); receipts and the digest follow the window.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
26 files changed,
+328
−51
docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md+8 −0docs/superpowers/plans/HK1-PROGRESS.md+32 −5internal/equipo/app.go+2 −1internal/equipo/chat/housekeeping.go+5 −1internal/equipo/chat/housekeeping_control.go+34 −6internal/equipo/copy.go+8 −0internal/equipo/handlers.go+10 −3internal/equipo/housekeeping/housekeeping_test.go+17 −5internal/equipo/housekeeping/policy.go+38 −9internal/equipo/housekeeping_page.go+52 −2internal/equipo/migrations/0052_thin_housekeeping.sql+1 −1internal/equipo/migrations/schema.sql+1 −1internal/equipo/render.go+1 −1internal/equipo/static/equipo.css+10 −0internal/equipo/templates/housekeeping.html+1 −1internal/equipo/templates/housekeeping_settings.html+12 −0internal/equipo/templates/settings.html+1 −0internal/thintest/client.go+5 −0internal/thintest/housekeeping_browser_test.go+34 −6internal/thintest/housekeeping_contract_test.go+35 −1internal/wire/connections_test.go+1 −1internal/wire/housekeeping.go+16 −4internal/wire/wiretest/fixtures.go+1 −1internal/wire/wiretest/testdata/api/housekeeping-paused.json+1 −1internal/wire/wiretest/testdata/api/housekeeping-quiet-request.json+1 −0internal/wire/wiretest/testdata/api/housekeeping.json+1 −1
Intent
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md| index 59f6c6de..84b3ace4 100644 |
| --- a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md |
| +++ b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md |
| @@ -5174,6 +5174,14 @@ records remain unchanged. |
| | `api.not_undoable` | This can no longer be undone. | Housekeeping slice 1 (Housekeeping view, digest, receipts) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| | `copyHousekeepingTick` | Could not run housekeeping. | Housekeeping slice 1 (Housekeeping view, digest, receipts) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| | `copyHousekeepingClaims` | Revalidated housekeeping claims. | Housekeeping slice 1 (Housekeeping view, digest, receipts) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `housekeeping.settings.lede` | Equipo tidies your work on its own. Pause it, or choose when its receipts wait. | Housekeeping slice 1 (Settings section) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `housekeeping.settings.quiet` | Quiet hours | Housekeeping slice 1 (Settings section) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `housekeeping.settings.quiet_hint` | Receipts made in these hours wait until they end, or until you next write. Times are UTC. | Housekeeping slice 1 (Settings section) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `housekeeping.settings.quiet_on` | Hold receipts during quiet hours | Housekeeping slice 1 (Settings section) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `housekeeping.settings.from` | From | Housekeeping slice 1 (Settings section) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `housekeeping.settings.until` | Until | Housekeeping slice 1 (Settings section) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `housekeeping.settings.activity` | See what Equipo did | Housekeeping slice 1 (Settings section) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| +| `housekeeping.settings_link` | Pause and quiet hours are in Settings | Housekeeping slice 1 (Settings section) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| | `chat.switched` | Switched to %s | Connections slice 1 (conversation) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| | `chat.switched_reset` | Switched to %s; %s resets %s | Connections slice 1 (conversation) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
| | `chat.no_connection` | Nothing can answer right now. %s | Connections slice 1 (conversation) | Runtime; COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) | |
diff --git a/docs/superpowers/plans/HK1-PROGRESS.md b/docs/superpowers/plans/HK1-PROGRESS.md| index 21d2ae32..027b61da 100644 |
| --- a/docs/superpowers/plans/HK1-PROGRESS.md |
| +++ b/docs/superpowers/plans/HK1-PROGRESS.md |
| @@ -114,13 +114,28 @@ suggestions (the Suggestions lane is not drawn). Conventions as in |
| fixtures. |
| 8. The Housekeeping view (`/housekeeping`, the list-checks button beside |
| - Notebook in the conversation header; scriptless): Pause and Resume, |
| - today's three budgets as quiet meters (reserved and charged), what |
| + Notebook in the conversation header; scriptless): a quiet link to |
| + Settings for Pause and quiet hours, today's three budgets as quiet meters (reserved and charged), what |
| Equipo did newest first with its evidence ("100% alike, 3 words in |
| common") and Undo while it can ("Undo until 15 Nov"), refusals and |
| failures, the detectors with On/Off and the switch. The digest line |
| in the conversation with its link. |
| +9. Settings' Housekeeping section (coordinator, 2026-11-08: Pause, the |
| + quiet-hours controls and the link to the activity view go in the |
| + Settings page's Housekeeping section; nothing in the profile menu). |
| + A partial (`templates/housekeeping_settings.html`, `{{template |
| + "housekeeping-settings" .HousekeepingSettings}}`) with Pause or |
| + Resume, quiet hours (on, from, until in whole hours, UTC until a zone |
| + is known) and "See what Equipo did"; posts to |
| + `/settings/housekeeping/pause` and `/settings/housekeeping/quiet`. It |
| + stands at the end of today's `/settings` until UX1's Settings page |
| + lands, then moves into its Housekeeping section. Quiet hours are per |
| + person now (`chat_housekeeping_settings.quiet_from`, `quiet_until`, |
| + null for 22:00 to 08:00, equal for none; `Housekeeping.quiet`, |
| + `SetHousekeeping.quiet`, fixture `housekeeping-quiet-request.json`); |
| + the digest waits for the window's end. |
| + |
| ## Tests |
| - Unit (`housekeeping`): `TestDetectorFixtures` (a fixture per |
| @@ -157,12 +172,14 @@ suggestions (the Suggestions lane is not drawn). Conventions as in |
| `TestContractHousekeepingAutoDisable` (two Undos, the digest says it |
| once, re-enable), `TestContractHousekeepingQuietHours` (02:00 action |
| on the view at once and in the conversation at 08:00; 23:00 shown by |
| - the person's message), `TestContractHousekeepingRestartWhileClaimed` |
| + the person's message; the person's own 12:00 to 14:00 window; none), `TestContractHousekeepingRestartWhileClaimed` |
| (a real restart). |
| - Browser (`-tags browser`): `TestBrowserHousekeeping` at 1280 (mouse) |
| and 390 (touch): the header link, the digest line and its link, the |
| view with evidence, three meters, detectors and Undo in reach (44 px on |
| - touch), no sideways scrolling; Undo and Pause from the view. It failed |
| + touch), no sideways scrolling; Undo from the view; Settings' section at |
| + both sizes, quiet hours saved and shown again, Pause from Settings and |
| + the view saying so. It failed |
| first: the page template was not registered (500). |
| - Mutations, each observed failing a test (script and output kept under |
| `~/.cache/tmp/equipo-hk1/` while working): the fold destination's owner |
| @@ -174,7 +191,8 @@ suggestions (the Suggestions lane is not drawn). Conventions as in |
| digest's once (AutoDisable), failures after rollback (AutoDisable, |
| store), the queue order (Preempts), the combine threshold (fixtures), |
| Undo's exact restore (UndoRoundTrips), the day's ceiling (Ledger), the |
| - refused row (Principal), and the Undo guards together (UndoRoundTrips). |
| + refused row (Principal), the Undo guards together (UndoRoundTrips), and |
| + receipts ignoring the person's own window (QuietHours). |
| The secret guard failed first on `copy_key` (allowed by name). |
| ## Decisions |
| @@ -213,6 +231,8 @@ suggestions (the Suggestions lane is not drawn). Conventions as in |
| recorded `separate` (kept apart), so the combine acts on pairs filed |
| before Equipo looked or after an Undo's pair is forgotten; the headless |
| bwrap form of H1 is not built. |
| +- Settings' section is on today's `/settings` page until UX1's Settings |
| + page is merged. |
| - Person's zone is UTC everywhere (quiet hours, the day, 03:00, 08:00). |
| - The view is not live: it re-reads on each visit and after its forms. |
| - Version skew as before: an old runner is unaffected (no new frames). |
| @@ -250,6 +270,13 @@ plan 3 inventory ("Housekeeping slice 1"): |
| duplicates", `.detector.failures` "Off after two Undos or failures this |
| week.", `.on` "On", `.off` "Off", `.turn_on` "Turn on", `.turn_off` |
| "Turn off" |
| +- Settings: `housekeeping.settings.lede` "Equipo tidies your work on |
| + its own. Pause it, or choose when its receipts wait.", `.quiet` "Quiet |
| + hours", `.quiet_hint` "Receipts made in these hours wait until they |
| + end, or until you next write. Times are UTC.", `.quiet_on` "Hold |
| + receipts during quiet hours", `.from` "From", `.until` "Until", |
| + `.activity` "See what Equipo did"; on the view |
| + `housekeeping.settings_link` "Pause and quiet hours are in Settings" |
| - API: `api.not_undoable` "This can no longer be undone." |
| - Logs: `copyHousekeepingTick` "Could not run housekeeping.", |
| `copyHousekeepingClaims` "Revalidated housekeeping claims." |
diff --git a/internal/equipo/app.go b/internal/equipo/app.go| index accde362..34978656 100644 |
| --- a/internal/equipo/app.go |
| +++ b/internal/equipo/app.go |
| @@ -231,7 +231,8 @@ func RouterWithStore(d *db.DB, cfg Config, mailer mail.Sender, logger *slog.Logg |
| r.Post("/conversation/projects/{id}/remove", a.chatProjectRemove) |
| r.Get("/conversation/notebook", a.chatNotebook) |
| r.Get("/housekeeping", a.housekeepingPage) |
| - r.Post("/housekeeping/pause", a.housekeepingPause) |
| + r.Post("/settings/housekeeping/pause", a.housekeepingPause) |
| + r.Post("/settings/housekeeping/quiet", a.housekeepingQuiet) |
| r.Post("/housekeeping/detectors/{id}", a.housekeepingDetector) |
| r.Post("/housekeeping/actions/{id}/undo", a.housekeepingUndo) |
| r.Post("/conversation/notebook/reset", a.chatNotebookReset) |
diff --git a/internal/equipo/chat/housekeeping.go b/internal/equipo/chat/housekeeping.go| index 3398ef80..c1aa0da1 100644 |
| --- a/internal/equipo/chat/housekeeping.go |
| +++ b/internal/equipo/chat/housekeeping.go |
| @@ -410,7 +410,11 @@ func hkCombine(t *txn, r *hkRecord, f housekeeping.Finding) (hkResult, error) { |
| return hkResult{}, err |
| } |
| res := hkResult{Action: f.Proposal.Action, Task: k.ID, Into: into.ID, Stage: k.Stage, DuplicateOf: k.DuplicateOf, TaskRev: k.Revision, IntoRev: into.Revision} |
| - r.VisibleAt = housekeeping.VisibleAt(t.hkNow(), t.zone(t.hk.Person)) |
| + set, err := t.hkSettings(t.hk.Person) |
| + if err != nil { |
| + return hkResult{}, err |
| + } |
| + r.VisibleAt = set.quiet().VisibleAt(t.hkNow(), t.zone(t.hk.Person)) |
| res.CardID, err = t.fold(k, into, r.ID, r.VisibleAt) |
| return res, err |
| } |
diff --git a/internal/equipo/chat/housekeeping_control.go b/internal/equipo/chat/housekeeping_control.go| index 20b239ab..aea6f3fb 100644 |
| --- a/internal/equipo/chat/housekeeping_control.go |
| +++ b/internal/equipo/chat/housekeeping_control.go |
| @@ -33,6 +33,10 @@ type hkSettingsRecord struct { |
| LastDigestAt *time.Time |
| LastSweepAt *time.Time |
| Revision int64 |
| + // QuietFrom and QuietUntil are the person's quiet hours; null is the |
| + // default, 22:00 to 08:00; equal is none. |
| + QuietFrom *int |
| + QuietUntil *int |
| } |
| func (hkSettingsRecord) TableName() string { return "chat_housekeeping_settings" } |
| @@ -56,6 +60,14 @@ type hkSettings struct { |
| func (s hkSettings) disabledFor(id string) bool { return s.disabled[id].Off } |
| +// quiet is the person's quiet hours. |
| +func (s hkSettings) quiet() housekeeping.QuietHours { |
| + if s.QuietFrom == nil || s.QuietUntil == nil { |
| + return housekeeping.DefaultQuiet |
| + } |
| + return housekeeping.QuietHours{From: *s.QuietFrom, Until: *s.QuietUntil} |
| +} |
| + |
| // SetHousekeepingClock moves the loop's clock (quiet hours, the day's |
| // budget, the digest and the sweep); nil restores the store's own. |
| func (s *Store) SetHousekeepingClock(now func() time.Time) { |
| @@ -108,7 +120,7 @@ func (t *txn) saveSettings(s *hkSettings) error { |
| if err := t.db.Create(&s.hkSettingsRecord).Error; err != nil { |
| return err |
| } |
| - } else if err := t.db.Model(&hkSettingsRecord{}).Where("person = ?", s.Person).Select("paused", "disabled", "last_digest_at", "last_sweep_at", "revision").Updates(&s.hkSettingsRecord).Error; err != nil { |
| + } else if err := t.db.Model(&hkSettingsRecord{}).Where("person = ?", s.Person).Select("paused", "disabled", "last_digest_at", "last_sweep_at", "revision", "quiet_from", "quiet_until").Updates(&s.hkSettingsRecord).Error; err != nil { |
| return err |
| } |
| sum, err := t.hkSummary(s.Person) |
| @@ -262,10 +274,15 @@ func (t *txn) hkRelease(person string, now time.Time) error { |
| // --- Pause and the switches. |
| -// SetHousekeeping is Pause: paused, no detector runs, no sweep, nothing is |
| -// posted; claims not yet dispatched go back to held and dispatched ones |
| -// keep releasing until their charge is in; existing Undo stays. |
| +// SetHousekeeping is Pause and the person's quiet hours. Paused, no |
| +// detector runs, no sweep, nothing is posted; claims not yet dispatched |
| +// go back to held and dispatched ones keep releasing until their charge |
| +// is in; existing Undo stays. Quiet hours, when given, replace the |
| +// window (From equal to Until is none). |
| func (s *Store) SetHousekeeping(ctx context.Context, person string, in wire.SetHousekeeping) (out wire.Housekeeping, err error) { |
| + if in.Quiet != nil && !(housekeeping.QuietHours{From: in.Quiet.From, Until: in.Quiet.Until}).Valid() { |
| + return out, ErrInvalid |
| + } |
| err = s.tx(ctx, func(t *txn) error { |
| if err := s.authority.CurrentPerson(ctx, t.db); err != nil { |
| return err |
| @@ -277,6 +294,16 @@ func (s *Store) SetHousekeeping(ctx context.Context, person string, in wire.SetH |
| if in.Revision != set.Revision { |
| return ErrRevision |
| } |
| + quiet := set.quiet() |
| + if in.Quiet != nil && (quiet.From != in.Quiet.From || quiet.Until != in.Quiet.Until) { |
| + from, until := in.Quiet.From, in.Quiet.Until |
| + set.QuietFrom, set.QuietUntil = &from, &until |
| + if set.Paused == in.Paused { |
| + if err := t.saveSettings(&set); err != nil { |
| + return err |
| + } |
| + } |
| + } |
| if set.Paused != in.Paused { |
| set.Paused = in.Paused |
| if err := t.saveSettings(&set); err != nil { |
| @@ -499,7 +526,7 @@ func (t *txn) digest(person string) error { |
| } |
| now := t.hkNow() |
| loc := t.zone(person) |
| - from := housekeeping.DayStart(now, loc).Add(housekeeping.QuietUntil * time.Hour) |
| + from := housekeeping.DayStart(now, loc).Add(time.Duration(set.quiet().Morning()) * time.Hour) |
| if now.Before(from) || set.LastDigestAt != nil && !set.LastDigestAt.Before(from) { |
| return nil |
| } |
| @@ -654,7 +681,8 @@ func (t *txn) housekeepingView(person string) (wire.Housekeeping, error) { |
| if err != nil { |
| return wire.Housekeeping{}, err |
| } |
| - out := wire.Housekeeping{Paused: set.Paused, Revision: set.Revision, Detectors: []wire.HousekeepingDetector{}, Actions: []wire.HousekeepingAction{}, Refusals: []wire.HousekeepingAction{}} |
| + q := set.quiet() |
| + out := wire.Housekeeping{Paused: set.Paused, Quiet: wire.QuietHours{From: q.From, Until: q.Until}, Revision: set.Revision, Detectors: []wire.HousekeepingDetector{}, Actions: []wire.HousekeepingAction{}, Refusals: []wire.HousekeepingAction{}} |
| day := housekeeping.DayStart(t.hkNow(), t.zone(person)) |
| used, charged, err := t.hkUsed(person, day) |
| if err != nil { |
diff --git a/internal/equipo/copy.go b/internal/equipo/copy.go| index aab6409c..2c94fcde 100644 |
| --- a/internal/equipo/copy.go |
| +++ b/internal/equipo/copy.go |
| @@ -593,6 +593,14 @@ var pageCopy = map[string]string{ |
| "chat.card.merge_adopt": "Merge %s?", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "chat.card.combined": "Combined “%s” into “%s”.", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "chat.card.combined_undone": "Undone: both tasks are back as they were.", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "housekeeping.settings.lede": "Equipo tidies your work on its own. Pause it, or choose when its receipts wait.", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "housekeeping.settings.quiet": "Quiet hours", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "housekeeping.settings.quiet_hint": "Receipts made in these hours wait until they end, or until you next write. Times are UTC.", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "housekeeping.settings.quiet_on": "Hold receipts during quiet hours", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "housekeeping.settings.from": "From", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "housekeeping.settings.until": "Until", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "housekeeping.settings.activity": "See what Equipo did", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| + "housekeeping.settings_link": "Pause and quiet hours are in Settings", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "chat.housekeeping.link": "Housekeeping", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "chat.housekeeping.digest_one": "Tidied 1 thing.", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
| "chat.housekeeping.digest": "Tidied %d things.", // COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context) |
diff --git a/internal/equipo/handlers.go b/internal/equipo/handlers.go| index ac4e83ef..9dab0505 100644 |
| --- a/internal/equipo/handlers.go |
| +++ b/internal/equipo/handlers.go |
| @@ -42,9 +42,11 @@ type pageData struct { |
| Thin workView |
| Notebook []notebookLine |
| Housekeeping housekeepingView |
| - Models modelsView |
| - ConnectionsStream bool |
| - ChatStream bool |
| + // HousekeepingSettings is Settings' Housekeeping section. |
| + HousekeepingSettings *hkSettingsView |
| + Models modelsView |
| + ConnectionsStream bool |
| + ChatStream bool |
| // ThinkingSet and ThinkingWords are the person's thinking words for |
| // the thinking line (thinking_words.go). |
| ThinkingSet, ThinkingWords string |
| @@ -309,6 +311,11 @@ func (a *application) settings(w http.ResponseWriter, r *http.Request) { |
| data.Key = "settings" |
| data.Title = "nav.settings" |
| data.BudgetForms = budgetForms(data.Budget, data.Groups) |
| + if ctx, address, ok := sessionContext(r); ok { |
| + if h, err := a.store.Chat().Housekeeping(ctx, address); err == nil { |
| + data.HousekeepingSettings = housekeepingSettings(h) |
| + } |
| + } |
| a.renderLive(w, r, "settings", data) |
| } |
diff --git a/internal/equipo/housekeeping/housekeeping_test.go b/internal/equipo/housekeeping/housekeeping_test.go| index e3280936..68499934 100644 |
| --- a/internal/equipo/housekeeping/housekeeping_test.go |
| +++ b/internal/equipo/housekeeping/housekeeping_test.go |
| @@ -145,19 +145,31 @@ func TestFitsAndStandDown(t *testing.T) { |
| func TestQuietHours(t *testing.T) { |
| at := func(h, m int) time.Time { return time.Date(2026, 11, 8, h, m, 0, 0, time.UTC) } |
| - eight := at(8, 0) |
| - nextEight := eight.AddDate(0, 0, 1) |
| + day := func(h int) *time.Time { v := at(h, 0); return &v } |
| + next := func(h int) *time.Time { v := at(h, 0).AddDate(0, 0, 1); return &v } |
| for _, c := range []struct { |
| + q QuietHours |
| at time.Time |
| want *time.Time |
| }{ |
| - {at(2, 0), &eight}, {at(7, 59), &eight}, {at(8, 0), nil}, {at(21, 59), nil}, {at(22, 0), &nextEight}, {at(23, 30), &nextEight}, |
| + {DefaultQuiet, at(2, 0), day(8)}, {DefaultQuiet, at(7, 59), day(8)}, {DefaultQuiet, at(8, 0), nil}, {DefaultQuiet, at(21, 59), nil}, |
| + {DefaultQuiet, at(22, 0), next(8)}, {DefaultQuiet, at(23, 30), next(8)}, |
| + // A window within one day. |
| + {QuietHours{From: 12, Until: 14}, at(13, 0), day(14)}, {QuietHours{From: 12, Until: 14}, at(14, 0), nil}, {QuietHours{From: 12, Until: 14}, at(11, 59), nil}, |
| + // None. |
| + {QuietHours{From: 9, Until: 9}, at(9, 30), nil}, {QuietHours{From: 0, Until: 0}, at(2, 0), nil}, |
| } { |
| - got := VisibleAt(c.at, time.UTC) |
| + got := c.q.VisibleAt(c.at, time.UTC) |
| if (got == nil) != (c.want == nil) || got != nil && !got.Equal(*c.want) { |
| - t.Errorf("%s: %v, want %v", c.at.Format("15:04"), got, c.want) |
| + t.Errorf("%+v at %s: %v, want %v", c.q, c.at.Format("15:04"), got, c.want) |
| } |
| } |
| + if DefaultQuiet.Morning() != 8 || (QuietHours{From: 23, Until: 7}).Morning() != 7 || (QuietHours{From: 5, Until: 5}).Morning() != 8 { |
| + t.Fatal("morning") |
| + } |
| + if (QuietHours{From: 24, Until: 3}).Valid() || !(QuietHours{From: 23, Until: 0}).Valid() { |
| + t.Fatal("valid") |
| + } |
| if !DayStart(at(23, 0), time.UTC).Equal(at(0, 0)) { |
| t.Fatal("day start") |
| } |
diff --git a/internal/equipo/housekeeping/policy.go b/internal/equipo/housekeeping/policy.go| index 89071f44..1c04efca 100644 |
| --- a/internal/equipo/housekeeping/policy.go |
| +++ b/internal/equipo/housekeeping/policy.go |
| @@ -38,7 +38,8 @@ const ( |
| FailuresToDisable = 2 |
| // VetoWindow: a dismissed key stays quiet this long, then may recur once. |
| VetoWindow = 30 * 24 * time.Hour |
| - // QuietFrom and QuietUntil: receipts made in these hours wait. |
| + // QuietFrom and QuietUntil: the default quiet hours; a person may |
| + // choose others or none. |
| QuietFrom = 22 |
| QuietUntil = 8 |
| // SweepHour: the daily sweep's hour in the person's zone. |
| @@ -85,27 +86,55 @@ func StandDown(h *Headroom, now time.Time) string { |
| return "" |
| } |
| -// Quiet reports whether at falls in quiet hours in loc. |
| -func Quiet(at time.Time, loc *time.Location) bool { |
| +// QuietHours is a person's window, in whole hours of their zone: receipts |
| +// made inside it wait until it ends. From equal to Until means none. |
| +type QuietHours struct{ From, Until int } |
| + |
| +// DefaultQuiet is 22:00 to 08:00. |
| +var DefaultQuiet = QuietHours{From: QuietFrom, Until: QuietUntil} |
| + |
| +// Off reports whether the window is empty. |
| +func (q QuietHours) Off() bool { return q.From == q.Until } |
| + |
| +// Valid reports whether both ends are hours of a day. |
| +func (q QuietHours) Valid() bool { return q.From >= 0 && q.From < 24 && q.Until >= 0 && q.Until < 24 } |
| + |
| +// Quiet reports whether at falls in the window, in loc. |
| +func (q QuietHours) Quiet(at time.Time, loc *time.Location) bool { |
| + if q.Off() { |
| + return false |
| + } |
| h := at.In(loc).Hour() |
| - return h >= QuietFrom || h < QuietUntil |
| + if q.From < q.Until { |
| + return h >= q.From && h < q.Until |
| + } |
| + return h >= q.From || h < q.Until |
| } |
| // VisibleAt is when a receipt made at at may show in the conversation: |
| -// nil outside quiet hours, else the next 08:00 in loc. |
| -func VisibleAt(at time.Time, loc *time.Location) *time.Time { |
| - if !Quiet(at, loc) { |
| +// nil outside the window, else the window's next end in loc. |
| +func (q QuietHours) VisibleAt(at time.Time, loc *time.Location) *time.Time { |
| + if !q.Quiet(at, loc) { |
| return nil |
| } |
| l := at.In(loc) |
| - v := time.Date(l.Year(), l.Month(), l.Day(), QuietUntil, 0, 0, 0, loc) |
| - if l.Hour() >= QuietFrom { |
| + v := time.Date(l.Year(), l.Month(), l.Day(), q.Until, 0, 0, 0, loc) |
| + if !v.After(l) { |
| v = v.AddDate(0, 0, 1) |
| } |
| v = v.UTC() |
| return &v |
| } |
| +// Morning is the hour the day's digest may be written from: the end of |
| +// the window, or 08:00 without one. |
| +func (q QuietHours) Morning() int { |
| + if q.Off() { |
| + return QuietUntil |
| + } |
| + return q.Until |
| +} |
| + |
| // DayStart is the start of at's day in loc, in UTC. |
| func DayStart(at time.Time, loc *time.Location) time.Time { |
| l := at.In(loc) |
diff --git a/internal/equipo/housekeeping_page.go b/internal/equipo/housekeeping_page.go| index dde02dd4..26829acc 100644 |
| --- a/internal/equipo/housekeeping_page.go |
| +++ b/internal/equipo/housekeeping_page.go |
| @@ -10,6 +10,7 @@ import ( |
| "github.com/go-chi/chi/v5" |
| "amadan.net/oficina/equipo/internal/equipo/chat" |
| + "amadan.net/oficina/equipo/internal/equipo/housekeeping" |
| "amadan.net/oficina/equipo/internal/wire" |
| ) |
| @@ -140,9 +141,58 @@ func (a *application) housekeepingPage(w http.ResponseWriter, r *http.Request) { |
| render(w, "housekeeping", data) |
| } |
| -// housekeepingPause is Pause and Resume. |
| +// hkSettingsView is Settings' Housekeeping section: Pause, the person's |
| +// quiet hours and the way to the activity view. |
| +type hkSettingsView struct { |
| + Paused, QuietOn bool |
| + Revision int64 |
| + From, Until int |
| + Hours []hkHour |
| +} |
| + |
| +type hkHour struct { |
| + Value int |
| + Label string |
| +} |
| + |
| +func housekeepingSettings(h wire.Housekeeping) *hkSettingsView { |
| + v := &hkSettingsView{Paused: h.Paused, Revision: h.Revision, QuietOn: h.Quiet.From != h.Quiet.Until, From: h.Quiet.From, Until: h.Quiet.Until} |
| + if !v.QuietOn { |
| + v.From, v.Until = housekeeping.DefaultQuiet.From, housekeeping.DefaultQuiet.Until |
| + } |
| + for i := range 24 { |
| + v.Hours = append(v.Hours, hkHour{Value: i, Label: fmt.Sprintf("%02d:00", i)}) |
| + } |
| + return v |
| +} |
| + |
| +// housekeepingQuiet saves the person's quiet hours from Settings; off is |
| +// a window of no hours. |
| +func (a *application) housekeepingQuiet(w http.ResponseWriter, r *http.Request) { |
| + a.chatActionTo(w, r, "/settings#housekeeping", func(ctx context.Context, address string) error { |
| + revision, _ := strconv.ParseInt(r.PostFormValue("revision"), 10, 64) |
| + from, err1 := strconv.Atoi(r.PostFormValue("from")) |
| + until, err2 := strconv.Atoi(r.PostFormValue("until")) |
| + if err1 != nil || err2 != nil { |
| + return ErrInvalid |
| + } |
| + if r.PostFormValue("on") != "1" { |
| + until = from |
| + } else if from == until { |
| + return ErrInvalid |
| + } |
| + h, err := a.store.Chat().Housekeeping(ctx, address) |
| + if err != nil { |
| + return err |
| + } |
| + _, err = a.store.Chat().SetHousekeeping(ctx, address, wire.SetHousekeeping{Paused: h.Paused, Quiet: &wire.QuietHours{From: from, Until: until}, Revision: revision}) |
| + return hkPageError(err) |
| + }) |
| +} |
| + |
| +// housekeepingPause is Pause and Resume, from Settings. |
| func (a *application) housekeepingPause(w http.ResponseWriter, r *http.Request) { |
| - a.chatActionTo(w, r, "/housekeeping", func(ctx context.Context, address string) error { |
| + a.chatActionTo(w, r, "/settings#housekeeping", func(ctx context.Context, address string) error { |
| revision, _ := strconv.ParseInt(r.PostFormValue("revision"), 10, 64) |
| _, err := a.store.Chat().SetHousekeeping(ctx, address, wire.SetHousekeeping{Paused: r.PostFormValue("paused") == "1", Revision: revision}) |
| return hkPageError(err) |
diff --git a/internal/equipo/migrations/0052_thin_housekeeping.sql b/internal/equipo/migrations/0052_thin_housekeeping.sql| index 63be7180..988c195c 100644 |
| --- a/internal/equipo/migrations/0052_thin_housekeeping.sql |
| +++ b/internal/equipo/migrations/0052_thin_housekeeping.sql |
| @@ -4,7 +4,7 @@ CREATE INDEX chat_housekeeping_person ON chat_housekeeping(person, at); |
| CREATE INDEX chat_housekeeping_subject ON chat_housekeeping(subject_id); |
| CREATE TABLE chat_housekeeping_failures (id integer PRIMARY KEY, person text, detector text, kind text, action_id text, at datetime); |
| CREATE INDEX chat_housekeeping_failure_person ON chat_housekeeping_failures(person, detector, at); |
| -CREATE TABLE chat_housekeeping_settings (person text PRIMARY KEY, paused numeric, disabled text, last_digest_at datetime, last_sweep_at datetime, revision integer); |
| +CREATE TABLE chat_housekeeping_settings (person text PRIMARY KEY, paused numeric, disabled text, last_digest_at datetime, last_sweep_at datetime, revision integer, quiet_from integer, quiet_until integer); |
| ALTER TABLE chat_cards ADD COLUMN action_id text; |
| ALTER TABLE chat_cards ADD COLUMN visible_at datetime; |
| ALTER TABLE chat_cards ADD COLUMN held numeric; |
diff --git a/internal/equipo/migrations/schema.sql b/internal/equipo/migrations/schema.sql| index 4271909b..7998cdad 100644 |
| --- a/internal/equipo/migrations/schema.sql |
| +++ b/internal/equipo/migrations/schema.sql |
| @@ -615,4 +615,4 @@ CREATE INDEX chat_housekeeping_person ON chat_housekeeping(person, at); |
| CREATE INDEX chat_housekeeping_subject ON chat_housekeeping(subject_id); |
| CREATE TABLE chat_housekeeping_failures (id integer PRIMARY KEY, person text, detector text, kind text, action_id text, at datetime); |
| CREATE INDEX chat_housekeeping_failure_person ON chat_housekeeping_failures(person, detector, at); |
| -CREATE TABLE chat_housekeeping_settings (person text PRIMARY KEY, paused numeric, disabled text, last_digest_at datetime, last_sweep_at datetime, revision integer); |
| +CREATE TABLE chat_housekeeping_settings (person text PRIMARY KEY, paused numeric, disabled text, last_digest_at datetime, last_sweep_at datetime, revision integer, quiet_from integer, quiet_until integer); |
diff --git a/internal/equipo/render.go b/internal/equipo/render.go| index 9ca3b945..3ca9c8c1 100644 |
| --- a/internal/equipo/render.go |
| +++ b/internal/equipo/render.go |
| @@ -51,7 +51,7 @@ func init() { |
| page = template.Must(page.ParseFS(appFS, "templates/layout.html")) |
| } |
| if name != "signin_page" && name != "errors" { |
| - page = template.Must(page.ParseFS(appFS, "templates/chrome.html", "templates/forms.html", "templates/task_card.html", "templates/conversation_card.html", "templates/work_parts.html")) |
| + page = template.Must(page.ParseFS(appFS, "templates/chrome.html", "templates/forms.html", "templates/task_card.html", "templates/conversation_card.html", "templates/work_parts.html", "templates/housekeeping_settings.html")) |
| } |
| pages[name] = template.Must(page.ParseFS(appFS, "templates/"+name+".html")) |
| } |
diff --git a/internal/equipo/static/equipo.css b/internal/equipo/static/equipo.css| index f4518930..886fa858 100644 |
| --- a/internal/equipo/static/equipo.css |
| +++ b/internal/equipo/static/equipo.css |
| @@ -943,3 +943,13 @@ a[equipo-source]:hover { color: var(--rst-text); text-decoration: underline; tex |
| [equipo-hk-empty] { margin: var(--rst-sp-3) 0; color: var(--rst-text-muted); } |
| @media (pointer: coarse) { [equipo-hk-list] [equipo-link] { min-block-size: 2.75rem; padding-inline: var(--rst-sp-2); } } |
| [equipo-card-line][data-digest] a { font-size: var(--rst-fs-sm); color: var(--rst-text-muted); text-underline-offset: 2px; } |
| +/* Housekeeping in Settings: Pause, then quiet hours on one line. */ |
| +[equipo-hk-settings] form { margin-block: var(--rst-sp-3); } |
| +[equipo-hk-settings] fieldset { border: 0; margin: 0; padding: 0; min-inline-size: 0; } |
| +[equipo-hk-settings] legend { font-weight: 500; padding: 0; } |
| +[equipo-hk-settings] label[equipo-hk-check] { display: flex; flex-direction: row; gap: var(--rst-sp-2); align-items: center; justify-content: flex-start; margin-block: var(--rst-sp-2); } |
| +[equipo-hk-settings] label[equipo-hk-check] input { inline-size: auto; margin: 0; } |
| +[equipo-hk-hours] { display: flex; flex-wrap: wrap; gap: var(--rst-sp-2) var(--rst-sp-4); margin-block-end: var(--rst-sp-3); } |
| +[equipo-hk-hours] label { display: inline-flex; align-items: center; gap: var(--rst-sp-2); } |
| +[equipo-hk-to-settings] { margin: var(--rst-sp-1) 0 0; font-size: var(--rst-fs-sm); } |
| +[equipo-hk-to-settings] a { color: var(--rst-text-muted); text-underline-offset: 2px; } |
diff --git a/internal/equipo/templates/housekeeping.html b/internal/equipo/templates/housekeeping.html| index 20022239..6b8393b0 100644 |
| --- a/internal/equipo/templates/housekeeping.html |
| +++ b/internal/equipo/templates/housekeeping.html |
| @@ -4,7 +4,7 @@ |
| {{define "content"}}{{with .Housekeeping}} |
| <section equipo-notebook equipo-hk data-housekeeping{{if .Paused}} data-paused{{end}}> |
| <header equipo-notebook-head equipo-hk-head><div><h1>{{copy "housekeeping.title"}}</h1><p>{{copy "housekeeping.lede"}}</p></div> |
| -<form method="post" action="/housekeeping/pause"><input type="hidden" name="revision" value="{{.Revision}}">{{if .Paused}}<input type="hidden" name="paused" value="0"><button rst-btn type="submit" data-hk-resume>{{copy "housekeeping.resume"}}</button>{{else}}<input type="hidden" name="paused" value="1"><button rst-btn type="submit" data-hk-pause>{{copy "housekeeping.pause"}}</button>{{end}}</form></header> |
| +<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}} |
| <section equipo-hk-part aria-labelledby="hk-today"><h2 id="hk-today">{{copy "housekeeping.today"}}</h2> |
| <ul equipo-hk-meters role="list">{{range .Meters}}<li equipo-conn-meter data-hk-meter><span>{{.Label}}</span><span equipo-conn-bar aria-hidden="true"><i style="inline-size:{{.Percent}}%"></i></span><span><b>{{.Used}}</b>{{with .Held}}, {{.}}{{end}}</span></li>{{end}}</ul></section> |
diff --git a/internal/equipo/templates/housekeeping_settings.html b/internal/equipo/templates/housekeeping_settings.html| new file mode 100644 |
| index 00000000..df681d91 |
| --- /dev/null |
| +++ b/internal/equipo/templates/housekeeping_settings.html |
| @@ -0,0 +1,12 @@ |
| +{{define "housekeeping-settings"}}<section id="housekeeping" equipo-card equipo-hk-settings data-hk-settings{{if .Paused}} data-paused{{end}} aria-labelledby="hk-settings-title"> |
| +<h2 id="hk-settings-title">{{copy "housekeeping.title"}}</h2> |
| +<p equipo-lede>{{copy "housekeeping.settings.lede"}}</p> |
| +<form method="post" action="/settings/housekeeping/pause" equipo-hk-pause-form><input type="hidden" name="revision" value="{{.Revision}}">{{if .Paused}}<p equipo-hk-paused role="status">{{copy "housekeeping.paused"}}</p><input type="hidden" name="paused" value="0"><button rst-btn type="submit" data-hk-resume>{{copy "housekeeping.resume"}}</button>{{else}}<input type="hidden" name="paused" value="1"><button rst-btn type="submit" data-hk-pause>{{copy "housekeeping.pause"}}</button>{{end}}</form> |
| +<form method="post" action="/settings/housekeeping/quiet" equipo-form equipo-hk-quiet data-hk-quiet><input type="hidden" name="revision" value="{{.Revision}}"> |
| +<fieldset><legend>{{copy "housekeeping.settings.quiet"}}</legend><p equipo-quiet>{{copy "housekeeping.settings.quiet_hint"}}</p> |
| +<label equipo-hk-check><input type="checkbox" name="on" value="1"{{if .QuietOn}} checked{{end}} data-hk-quiet-on>{{copy "housekeeping.settings.quiet_on"}}</label> |
| +<span equipo-hk-hours><label>{{copy "housekeeping.settings.from"}}<select rst-input name="from" data-hk-quiet-from>{{$f := .From}}{{range .Hours}}<option value="{{.Value}}"{{if eq .Value $f}} selected{{end}}>{{.Label}}</option>{{end}}</select></label> |
| +<label>{{copy "housekeeping.settings.until"}}<select rst-input name="until" data-hk-quiet-until>{{$u := .Until}}{{range .Hours}}<option value="{{.Value}}"{{if eq .Value $u}} selected{{end}}>{{.Label}}</option>{{end}}</select></label></span></fieldset> |
| +<button rst-btn="primary" type="submit" data-hk-quiet-save>{{copy "form.save"}}</button></form> |
| +<p><a href="/housekeeping" data-hk-activity>{{copy "housekeeping.settings.activity"}}</a></p> |
| +</section>{{end}} |
diff --git a/internal/equipo/templates/settings.html b/internal/equipo/templates/settings.html| index bde94ddb..15ef6d17 100644 |
| --- a/internal/equipo/templates/settings.html |
| +++ b/internal/equipo/templates/settings.html |
| @@ -17,4 +17,5 @@ |
| {{else}}{{template "budget-summary" .}}{{end}} |
| <h3>{{copy "budget.usage"}}</h3><p data-usage="unavailable">{{copy "usage.unknown"}}</p> |
| </section> |
| +{{with .HousekeepingSettings}}{{template "housekeeping-settings" .}}{{end}} |
| {{end}} |
diff --git a/internal/thintest/client.go b/internal/thintest/client.go| index 1a1c4662..1a38d3c3 100644 |
| --- a/internal/thintest/client.go |
| +++ b/internal/thintest/client.go |
| @@ -592,3 +592,8 @@ func (c *Client) HousekeepingActions(ctx context.Context, before string, limit i |
| func (c *Client) UndoAction(ctx context.Context, id string) (out wire.HousekeepingAction, err error) { |
| return out, c.do(ctx, "POST", "/api/v1/housekeeping/actions/"+id+"/undo", nil, &out) |
| } |
| + |
| +// SetQuiet sets the person's quiet hours, keeping Pause as it is. |
| +func (c *Client) SetQuiet(ctx context.Context, paused bool, from, until int, revision int64) (out wire.Housekeeping, err error) { |
| + return out, c.do(ctx, "PUT", "/api/v1/housekeeping", wire.SetHousekeeping{Paused: paused, Quiet: &wire.QuietHours{From: from, Until: until}, Revision: revision}, &out) |
| +} |
diff --git a/internal/thintest/housekeeping_browser_test.go b/internal/thintest/housekeeping_browser_test.go| index 26d2d833..93b3c118 100644 |
| --- a/internal/thintest/housekeeping_browser_test.go |
| +++ b/internal/thintest/housekeeping_browser_test.go |
| @@ -8,6 +8,8 @@ import ( |
| "time" |
| "github.com/chromedp/chromedp" |
| + |
| + "amadan.net/oficina/equipo/internal/wire" |
| ) |
| // click activates the element selector finds, as a tap or a click does. |
| @@ -66,7 +68,7 @@ func TestBrowserHousekeeping(t *testing.T) { |
| p.check(`[...document.querySelectorAll('[equipo-hk-action] [equipo-hk-line]')].every(e=>e.textContent.includes('Combined'))`, "action lines") |
| p.check(`[...document.querySelectorAll('[equipo-hk-action] [equipo-hk-meta]')].every(e=>/\d+% alike, \d+ words in common/.test(e.textContent))`, "evidence") |
| p.check(`document.querySelectorAll('[data-detector]').length===2 && !document.querySelector('[data-detector][data-off]')`, "detectors on") |
| - p.check(`!!document.querySelector('[data-hk-pause]')`, "Pause") |
| + p.check(`document.querySelector('[data-hk-settings-link]').getAttribute('href')==='/settings#housekeeping'`, "the way to Settings") |
| if size.touch { |
| p.check(`[...document.querySelectorAll('[data-hk-undo]')].every(b=>{const r=b.getBoundingClientRect();return r.height>=44&&r.width>0})`, "Undo within reach on touch") |
| } else { |
| @@ -96,11 +98,37 @@ func TestBrowserHousekeeping(t *testing.T) { |
| } |
| p.shot("hk-view-undone-1280") |
| - // Pause from the view. |
| - p.click(`[data-hk-pause]`) |
| - p.wait(`document.querySelector('[data-housekeeping][data-paused] [data-hk-resume]')`, "paused") |
| + // Settings' Housekeeping section, at both sizes: Pause, quiet hours |
| + // saved and shown again, and the way to the activity view. |
| + for _, size := range []struct { |
| + w, h int64 |
| + touch bool |
| + }{{1280, 900, false}, {390, 844, true}} { |
| + q := openInner(t, r.inst.URL, r.inst.Cookie(), size.w, size.h, size.touch, "light", "no-preference") |
| + q.open("/settings#housekeeping") |
| + q.check(`!!document.querySelector('[data-hk-settings] [data-hk-pause]') && document.querySelector('[data-hk-activity]').getAttribute('href')==='/housekeeping'`, "the section") |
| + q.check(`document.querySelector('[data-hk-quiet-on]').checked && document.querySelector('[data-hk-quiet-from]').value==='22' && document.querySelector('[data-hk-quiet-until]').value==='8'`, "default quiet hours") |
| + q.fits("settings") |
| + q.shot(fmt.Sprintf("hk-settings-%d", size.w)) |
| + q.stop() |
| + } |
| + q := openInner(t, r.inst.URL, r.inst.Cookie(), 1280, 900, false, "light", "no-preference") |
| + defer q.stop() |
| + q.open("/settings") |
| + q.check(`(()=>{window.__hkmark=1;document.querySelector('[data-hk-quiet-from]').value='23';document.querySelector('[data-hk-quiet-until]').value='7';return true})()`, "choose hours") |
| + q.click(`[data-hk-quiet-save]`) |
| + q.wait(`!window.__hkmark && document.querySelector('[data-hk-quiet-from]') && document.querySelector('[data-hk-quiet-from]').value==='23' && document.querySelector('[data-hk-quiet-until]').value==='7'`, "quiet hours saved") |
| + if h := r.housekeeping(); h.Quiet != (wire.QuietHours{From: 23, Until: 7}) { |
| + t.Fatalf("quiet hours from Settings: %+v", h.Quiet) |
| + } |
| + q.check(`(()=>{window.__hkmark=1;return true})()`, "mark") |
| + q.click(`[data-hk-pause]`) |
| + q.wait(`!window.__hkmark && document.querySelector('[data-hk-settings][data-paused] [data-hk-resume]')`, "paused") |
| if h := r.housekeeping(); !h.Paused { |
| - t.Fatal("Pause from the view did not take") |
| + t.Fatal("Pause from Settings did not take") |
| } |
| - p.shot("hk-view-paused-1280") |
| + q.shot("hk-settings-paused-1280") |
| + // The view says so and leads back to Settings. |
| + q.open("/housekeeping") |
| + q.check(`!!document.querySelector('[data-housekeeping][data-paused] [data-hk-settings-link]')`, "paused on the view") |
| } |
diff --git a/internal/thintest/housekeeping_contract_test.go b/internal/thintest/housekeeping_contract_test.go| index 5b59ffc7..6740b56a 100644 |
| --- a/internal/thintest/housekeeping_contract_test.go |
| +++ b/internal/thintest/housekeeping_contract_test.go |
| @@ -126,7 +126,7 @@ func TestContractHousekeepingCombine(t *testing.T) { |
| // The view beside the Notebook, scriptless: the action, its evidence |
| // and Undo; the conversation's header leads there. |
| view := r.inst.Get(t, "/housekeeping") |
| - for _, want := range []string{`data-action="` + a.ID + `"`, "data-hk-undo", "Combined “Swipe back from the edge", "words in common", "data-hk-pause", `data-detector="duplicate_same_creator"`} { |
| + for _, want := range []string{`data-action="` + a.ID + `"`, "data-hk-undo", "Combined “Swipe back from the edge", "words in common", "data-hk-settings-link", `data-detector="duplicate_same_creator"`} { |
| if !strings.Contains(view, want) { |
| t.Fatalf("view lacks %q", want) |
| } |
| @@ -134,6 +134,13 @@ func TestContractHousekeepingCombine(t *testing.T) { |
| if !strings.Contains(r.inst.Get(t, "/conversation"), "data-housekeeping-link") { |
| t.Fatal("no way from the conversation to the view") |
| } |
| + // Settings' Housekeeping section: Pause, quiet hours, the activity view. |
| + settings := r.inst.Get(t, "/settings") |
| + for _, want := range []string{`id="housekeeping"`, "data-hk-pause", "data-hk-quiet-on", `<option value="22" selected>22:00</option>`, `<option value="8" selected>08:00</option>`, `href="/housekeeping" data-hk-activity`} { |
| + if !strings.Contains(settings, want) { |
| + t.Fatalf("Settings lacks %q", want) |
| + } |
| + } |
| // A teammate sees none of it, and cannot undo it. |
| member := personToolRig(t, r, "member@example.com", equipo.RoleMember) |
| if mh, err := member.client.Housekeeping(r.ctx); err != nil || len(mh.Actions) != 0 { |
| @@ -460,6 +467,33 @@ func TestContractHousekeepingQuietHours(t *testing.T) { |
| if !found { |
| t.Fatal("the person's message did not show the receipt") |
| } |
| + |
| + // The person's own window: 12:00 to 14:00. An action at 13:00 waits |
| + // until 14:00; one at 02:00 shows at once. |
| + h := r.housekeeping() |
| + h, err := r.client.SetQuiet(r.ctx, false, 12, 14, h.Revision) |
| + if err != nil || h.Quiet != (wire.QuietHours{From: 12, Until: 14}) { |
| + t.Fatalf("quiet hours: %+v %v", h.Quiet, err) |
| + } |
| + if _, err := r.client.SetQuiet(r.ctx, false, 24, 3, h.Revision); Status(err) != 422 { |
| + t.Fatalf("an hour past 23: %v", err) |
| + } |
| + r.clock(day.Add(37 * time.Hour)) |
| + _, fold3 := r.pair("q3", "Compose sheet keyboard covers the send button") |
| + r.tidy() |
| + if a3 := r.action(fold3); a3.VisibleAt == nil || !a3.VisibleAt.Equal(day.Add(38*time.Hour)) { |
| + t.Fatalf("own window: %v", a3.VisibleAt) |
| + } |
| + // None: From equal to Until. |
| + if _, err := r.client.SetQuiet(r.ctx, false, 0, 0, r.housekeeping().Revision); err != nil { |
| + t.Fatal(err) |
| + } |
| + r.clock(day.Add(50 * time.Hour)) |
| + _, fold4 := r.pair("q4", "Crash on launch after the update") |
| + r.tidy() |
| + if a4 := r.action(fold4); a4.VisibleAt != nil { |
| + t.Fatalf("no quiet hours, still held: %v", a4.VisibleAt) |
| + } |
| } |
| // TestContractHousekeepingRestartWhileClaimed: a claim a crash left |
diff --git a/internal/wire/connections_test.go b/internal/wire/connections_test.go| index b585041d..46add40c 100644 |
| --- a/internal/wire/connections_test.go |
| +++ b/internal/wire/connections_test.go |
| @@ -95,7 +95,7 @@ func TestHousekeepingTypesCarryNoSecrets(t *testing.T) { |
| if len(names) < 30 { |
| t.Fatalf("walked only %d fields", len(names)) |
| } |
| - for _, name := range []string{"api/housekeeping.json", "api/housekeeping-paused.json", "api/action-combined.json", "api/action-undone.json", "api/action-refused.json", "api/housekeeping-actions.json", "api/action-conflict.json", "api/event-housekeeping.json", "api/event-housekeeping-summary.json", "api/card-housekeeping.json", "api/card-digest.json"} { |
| + for _, name := range []string{"api/housekeeping.json", "api/housekeeping-paused.json", "api/housekeeping-quiet-request.json", "api/action-combined.json", "api/action-undone.json", "api/action-refused.json", "api/housekeeping-actions.json", "api/action-conflict.json", "api/event-housekeeping.json", "api/event-housekeeping-summary.json", "api/card-housekeeping.json", "api/card-digest.json"} { |
| raw := strings.ReplaceAll(strings.ToLower(string(wiretest.Fixture(name))), "\"copy_key\"", "") |
| for _, bad := range []string{"token\"", "secret", "credential", "password", "sealed", "_key\"", "api_key", "access_token", "refresh"} { |
| if strings.Contains(raw, bad) { |
diff --git a/internal/wire/housekeeping.go b/internal/wire/housekeeping.go| index 0a487eec..c638cb70 100644 |
| --- a/internal/wire/housekeeping.go |
| +++ b/internal/wire/housekeeping.go |
| @@ -54,7 +54,9 @@ const ( |
| // Housekeeping is GET /api/v1/housekeeping: the person's own loop. |
| type Housekeeping struct { |
| - Paused bool `json:"paused"` |
| + Paused bool `json:"paused"` |
| + // Quiet is the person's quiet hours: receipts made in them wait. |
| + Quiet QuietHours `json:"quiet"` |
| Budget HousekeepingBudget `json:"budget"` |
| Detectors []HousekeepingDetector `json:"detectors"` |
| // Actions are the newest actions, newest first; Refusals the newest |
| @@ -127,10 +129,20 @@ type HousekeepingActions struct { |
| Before string `json:"before"` |
| } |
| -// SetHousekeeping is PUT /api/v1/housekeeping: Pause. |
| +// SetHousekeeping is PUT /api/v1/housekeeping: Pause, and quiet hours |
| +// when given. |
| type SetHousekeeping struct { |
| - Paused bool `json:"paused"` |
| - Revision int64 `json:"revision"` |
| + Paused bool `json:"paused"` |
| + Quiet *QuietHours `json:"quiet,omitempty"` |
| + Revision int64 `json:"revision"` |
| +} |
| + |
| +// QuietHours is a window in whole hours (0 to 23) of the person's zone, |
| +// UTC until a zone is known; From equal to Until is none. The default is |
| +// 22 to 8. |
| +type QuietHours struct { |
| + From int `json:"from"` |
| + Until int `json:"until"` |
| } |
| // SetDetector is PUT /api/v1/housekeeping/detectors/{id}. |
diff --git a/internal/wire/wiretest/fixtures.go b/internal/wire/wiretest/fixtures.go| index 5e63c2a2..9940ca82 100644 |
| --- a/internal/wire/wiretest/fixtures.go |
| +++ b/internal/wire/wiretest/fixtures.go |
| @@ -109,7 +109,7 @@ func APIType(name string) any { |
| return &wire.HousekeepingAction{} |
| case "housekeeping-actions.json": |
| return &wire.HousekeepingActions{} |
| - case "housekeeping-request.json": |
| + case "housekeeping-request.json", "housekeeping-quiet-request.json": |
| return &wire.SetHousekeeping{} |
| case "detector-request.json": |
| return &wire.SetDetector{} |
diff --git a/internal/wire/wiretest/testdata/api/housekeeping-paused.json b/internal/wire/wiretest/testdata/api/housekeeping-paused.json| index 2eafc182..93f29dea 100644 |
| --- a/internal/wire/wiretest/testdata/api/housekeeping-paused.json |
| +++ b/internal/wire/wiretest/testdata/api/housekeeping-paused.json |
| @@ -1 +1 @@ |
| -{"paused":true,"budget":{"turns":{"reserved":0,"charged":0,"limit":4},"tokens":{"reserved":0,"charged":0,"limit":150000},"retries":{"reserved":0,"charged":0,"limit":3}},"detectors":[{"id":"duplicate_same_creator","class":"act","enabled":false,"disabled_reason":"failures","disabled_at":"2026-11-08T09:40:00Z"},{"id":"duplicate_possible","class":"link","enabled":true,"disabled_reason":"","disabled_at":null}],"actions":[{"id":"hk_0001","revision":2,"detector":"duplicate_same_creator","class":"act","state":"undone","reason":"","subject":{"kind":"task","id":"tk0000000002"},"evidence":{"tasks":[{"id":"tk0000000002","title":"Swipe from the edge to go back doesn't work","stage":"noted","creator":"owner@example.com"},{"id":"tk0000000001","title":"Swipe back from the edge doesn't work","stage":"in_progress","creator":"owner@example.com"}],"similarity":0.75,"shared":3},"undoable":false,"undo_until":"2026-11-15T09:05:00Z","visible_at":null,"at":"2026-11-08T09:20:00Z","undone_at":"2026-11-08T09:20:00Z"}],"refusals":[],"revision":3} |
| +{"paused":true,"quiet":{"from":22,"until":8},"budget":{"turns":{"reserved":0,"charged":0,"limit":4},"tokens":{"reserved":0,"charged":0,"limit":150000},"retries":{"reserved":0,"charged":0,"limit":3}},"detectors":[{"id":"duplicate_same_creator","class":"act","enabled":false,"disabled_reason":"failures","disabled_at":"2026-11-08T09:40:00Z"},{"id":"duplicate_possible","class":"link","enabled":true,"disabled_reason":"","disabled_at":null}],"actions":[{"id":"hk_0001","revision":2,"detector":"duplicate_same_creator","class":"act","state":"undone","reason":"","subject":{"kind":"task","id":"tk0000000002"},"evidence":{"tasks":[{"id":"tk0000000002","title":"Swipe from the edge to go back doesn't work","stage":"noted","creator":"owner@example.com"},{"id":"tk0000000001","title":"Swipe back from the edge doesn't work","stage":"in_progress","creator":"owner@example.com"}],"similarity":0.75,"shared":3},"undoable":false,"undo_until":"2026-11-15T09:05:00Z","visible_at":null,"at":"2026-11-08T09:20:00Z","undone_at":"2026-11-08T09:20:00Z"}],"refusals":[],"revision":3} |
diff --git a/internal/wire/wiretest/testdata/api/housekeeping-quiet-request.json b/internal/wire/wiretest/testdata/api/housekeeping-quiet-request.json| new file mode 100644 |
| index 00000000..f8769a83 |
| --- /dev/null |
| +++ b/internal/wire/wiretest/testdata/api/housekeeping-quiet-request.json |
| @@ -0,0 +1 @@ |
| +{"paused":false,"quiet":{"from":23,"until":7},"revision":2} |
diff --git a/internal/wire/wiretest/testdata/api/housekeeping.json b/internal/wire/wiretest/testdata/api/housekeeping.json| index ba2dc733..29a6807d 100644 |
| --- a/internal/wire/wiretest/testdata/api/housekeeping.json |
| +++ b/internal/wire/wiretest/testdata/api/housekeeping.json |
| @@ -1 +1 @@ |
| -{"paused":false,"budget":{"turns":{"reserved":0,"charged":0,"limit":4},"tokens":{"reserved":0,"charged":0,"limit":150000},"retries":{"reserved":0,"charged":0,"limit":3}},"detectors":[{"id":"duplicate_same_creator","class":"act","enabled":true,"disabled_reason":"","disabled_at":null},{"id":"duplicate_possible","class":"link","enabled":true,"disabled_reason":"","disabled_at":null}],"actions":[{"id":"hk_0001","revision":1,"detector":"duplicate_same_creator","class":"act","state":"done","reason":"","subject":{"kind":"task","id":"tk0000000002"},"evidence":{"tasks":[{"id":"tk0000000002","title":"Swipe from the edge to go back doesn't work","stage":"cancelled","creator":"owner@example.com"},{"id":"tk0000000001","title":"Swipe back from the edge doesn't work","stage":"in_progress","creator":"owner@example.com"}],"similarity":0.75,"shared":3},"undoable":true,"undo_until":"2026-11-15T09:05:00Z","visible_at":null,"at":"2026-11-08T09:05:00Z","undone_at":null}],"refusals":[{"id":"hk_0003","revision":1,"detector":"duplicate_same_creator","class":"act","state":"refused","reason":"housekeeping_forbidden","subject":{"kind":"task","id":"tk0000000004"},"evidence":{"tasks":[{"id":"tk0000000004","title":"Keyboard covers the send button","stage":"noted","creator":"owner@example.com"},{"id":"tk0000000003","title":"Keyboard covers the compose send button","stage":"noted","creator":"member@example.com"}],"similarity":0.8,"shared":4},"undoable":false,"undo_until":null,"visible_at":null,"at":"2026-11-08T09:30:00Z","undone_at":null}],"revision":0} |
| +{"paused":false,"quiet":{"from":22,"until":8},"budget":{"turns":{"reserved":0,"charged":0,"limit":4},"tokens":{"reserved":0,"charged":0,"limit":150000},"retries":{"reserved":0,"charged":0,"limit":3}},"detectors":[{"id":"duplicate_same_creator","class":"act","enabled":true,"disabled_reason":"","disabled_at":null},{"id":"duplicate_possible","class":"link","enabled":true,"disabled_reason":"","disabled_at":null}],"actions":[{"id":"hk_0001","revision":1,"detector":"duplicate_same_creator","class":"act","state":"done","reason":"","subject":{"kind":"task","id":"tk0000000002"},"evidence":{"tasks":[{"id":"tk0000000002","title":"Swipe from the edge to go back doesn't work","stage":"cancelled","creator":"owner@example.com"},{"id":"tk0000000001","title":"Swipe back from the edge doesn't work","stage":"in_progress","creator":"owner@example.com"}],"similarity":0.75,"shared":3},"undoable":true,"undo_until":"2026-11-15T09:05:00Z","visible_at":null,"at":"2026-11-08T09:05:00Z","undone_at":null}],"refusals":[{"id":"hk_0003","revision":1,"detector":"duplicate_same_creator","class":"act","state":"refused","reason":"housekeeping_forbidden","subject":{"kind":"task","id":"tk0000000004"},"evidence":{"tasks":[{"id":"tk0000000004","title":"Keyboard covers the send button","stage":"noted","creator":"owner@example.com"},{"id":"tk0000000003","title":"Keyboard covers the compose send button","stage":"noted","creator":"member@example.com"}],"similarity":0.8,"shared":4},"undoable":false,"undo_until":null,"visible_at":null,"at":"2026-11-08T09:30:00Z","undone_at":null}],"revision":0} |