# Housekeeping slice 1 progress: the smallest useful loop

Branch `thin-v1-hk1` from `thin-v1-conn1` (fa3860a, then staging's line
`thin-v1-ux1` at f2602d3 merged: final Connections fixes, thinking-word
themes; no migration clash, housekeeping stays 0052;
with UX1's reversible combine cceab55), with `design-housekeeping`
merged (3aa3fb4, rev 3 accepted). Spec:
`docs/superpowers/specs/2026-11-08-equipo-housekeeping.md` §7 slice 1,
plus the controller's brief: budget reservation with Paul's defaults
(4 turns, 150,000 tokens, 3 retries per person per day, stand down at
0.8 on the selected connection, unknown is stand down) and the API v1
resources. Not in this slice: automatic retries, judgement turns,
suggestions (the Suggestions lane is not drawn). Conventions as in
`SLICE1-PROGRESS.md` to `CONN1-PROGRESS.md` and `UX1-PROGRESS.md`.

## Done

1. Registry (`internal/equipo/housekeeping`, pure): a detector declares
   id, subject kind, class (`act`, `link`, `propose`, `ask`), triggers,
   judgement, rate, cost and `Detect(View) []Finding`. `New` refuses a
   judgement detector that is not `propose`, an unknown class, a missing
   trigger or Detect, a repeated id. `Default()` is slice 1:
   `duplicate_same_creator` (act: combine) and `duplicate_possible`
   (link: "Possible duplicate of"), over record_task's similarity
   (`Significant`, `Overlap` moved here; chat uses them) and UX1's
   thresholds as constants beside the detectors. Findings carry subject,
   owner, subject revision, key (`duplicate:tkA:tkB`,
   `possible:tkB:tkA`), structured evidence and the proposal. Policy:
   `Limits`, `JudgementTurn`, `AutoRetry`, `Fits`, `StandDown`,
   `VisibleAt` (22:00 to 08:00), `DayStart`, ceilings. Team-scoped
   throughout: a team subject has no owner and keys on `(team, "",
   detector, key)`.

2. Ledger (`chat_housekeeping`, migration 0052; `chat/housekeeping.go`):
   rows only move forward (`claimed`, `held`, `done`, `undone`,
   `refused`, `failed`, `vetoed`, `expired`), unique on `(team, person,
   detector, finding_key)`. A key that exists is a no-op unless held,
   failed once, vetoed past 30 days with its one recurrence left, or
   expired because its subject moved. A free deterministic action claims
   and acts in one transaction, the action in a savepoint: a refusal or
   an error takes back everything it wrote and leaves only the row. A
   spending action commits `claimed` with its reservation first (nothing
   in slice 1 spends). Held: the day's ceiling (ten actions), the budget
   or stand-down; at most twenty held per person, the oldest expire.
   `hkSettle` keeps a reservation `releasing` until termination and the
   charge are in; no figure charges the whole reservation.

3. Principal: `Principal{Team, Person, Detector, FindingID, Reserved}`
   built from the ledger row, carried on the transaction (`txn.hk`) into
   the shared store functions, which check it inside the transaction:
   `foldable` (both tasks, the destination too, are the person's and the
   person is a current member), `saveTask` (own task, no ending, no
   merging, no `merge_eligible`, `ready_sha`, `merge_asked`, merged
   fields or cancel), `saveStep`, `dispatchStep` and turn `dispatch`
   (only within a reservation, on a selected connection that is healthy,
   reported, fresh and below 0.8), `startMerge`, `askMerge`,
   `answerMerge`, `cancelTask`, `removeProject` (split out of
   `RemoveProject`), `writeSetting`, `saveNotebook` (never another
   person's). Failure is `housekeeping_forbidden` and a `refused` row.

4. Budget reservation: the claim sums today's rows for the person in
   its own transaction (an open reservation in full, else its charge)
   and holds a claim that would exceed any limit; SQLite serialises the
   write transactions, so two claims racing the last room cannot both
   pass. Stand-down reads the connection the choice selects on the
   instance: the one that answered the person's last turn, else their
   only one; anything else is unknown and stands down, and no other
   connection is tried. A combine spends nothing and carries on.

5. Control (`chat/housekeeping_control.go`): Pause (`chat_housekeeping_
   settings`; paused: no detector runs, no sweep, no digest; undispatched
   claims go back to held, dispatched ones keep releasing; Undo stays).
   Failures (`chat_housekeeping_failures`) are written after the
   transaction ends, committed or not; two within seven days (an Undo
   counts) switch the detector off for the person, said once in the
   digest; only the person switches it back on, which clears the count.
   Quiet hours: a receipt made 22:00 to 08:00 (UTC until a zone is
   known) is held (`chat_cards.held`, `visible_at`): on the view at
   once, in the conversation at 08:00 or at the person's first message.
   The digest: one card a day from 08:00 when something happened
   ("Tidied 2 things." plus a switched-off detector or a stand-down),
   linking to the view. Recovery: at start-up, and for claims older than
   ten minutes on the minute tick, a claim with nothing dispatched goes
   to held if its subject is unchanged, else expires `subject_moved`
   with its reservation released; a dispatched one waits for sync. The
   minute tick (`HousekeepingTick`): quiet hours end, recovery, the
   03:00 sweep (and again while findings are held), the digests.

6. Duplicates through the loop: `TidyDuplicates` (start and sweep) and
   `record_task` run `housekeepingPass`, which re-reads the project
   after each action. Undo from the view, the receipt and the task page
   is one path (`unfold`): within seven days, restores the task exactly
   (stage, thread, findings, its earlier "Possible duplicate of" link
   from the action's snapshot), removes the fold from the destination,
   keeps the pair apart and makes the key a retained veto.

7. API v1 (`chat/housekeeping_http.go`): `GET /api/v1/housekeeping`,
   `PUT /api/v1/housekeeping {paused, revision}`, `PUT
   /api/v1/housekeeping/detectors/{id} {enabled, revision}`, `GET
   /api/v1/housekeeping/actions?before=&limit=`, `POST
   /api/v1/housekeeping/actions/{id}/undo` (409 `not_undoable` with the
   action). Event `housekeeping` (resource `action` or `housekeeping`).
   `Snapshot.housekeeping_summary`. `Card.action_id`, `Card.visible_at`
   (omitted when empty), card kind `housekeeping` state `digest`.
   `TurnHousekeeping` and the queue order (person, then move-in and
   explore, then housekeeping). Fixtures: `api/housekeeping.json`,
   `housekeeping-paused.json`, `action-combined.json`,
   `action-undone.json`, `action-refused.json`,
   `housekeeping-actions.json`, `housekeeping-request.json`,
   `detector-request.json`, `action-conflict.json`,
   `event-housekeeping.json`, `event-housekeeping-summary.json`,
   `card-housekeeping.json`, `card-digest.json`; `snapshot.json` gains
   the summary. The secret-shape guard covers the new types and
   fixtures.

8. The Housekeeping view (`/housekeeping`, the list-checks button beside
   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. Live (Paul dislikes reloads): the
   view is a work region, nav-stream.js hears `housekeeping` events and
   work-stream.js swaps it in place; Undo and the switches post in the
   background (`static/housekeeping.js`), plain posts without scripts.

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 in the Housekeeping section of UX1's Settings page
   (`/conversation/settings#housekeeping`, merged at 99b19e8), in its
   row style; the old section at the end of `/settings` is gone. 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
  detector, `testdata/<id>.json`, thirteen and nine cases with every
  threshold edge), `TestRegistryModelMeansPropose`, `TestRateTable`,
  `TestFitsAndStandDown`, `TestQuietHours`.
- Store (`chat/housekeeping_store_test.go`, the chat tables on a copied
  template database): `TestHousekeepingPrincipal` (a fold into another
  person's task, the other way round, a person removed from the roster,
  a link on another's task: refused, nothing changed),
  `TestHousekeepingNever` (delete, cancel, end, merge eligibility, Ready
  SHA, merge, merge card, a setting, another's notebook and task,
  dispatch without a reservation or on a limited connection; then the
  same through the ledger as refused rows), `TestHousekeepingReservation`
  (exhaustion, two claims racing the last room, tokens binding at the
  third judgement turn, turns at the fifth, settle with unknown and
  complete usage, Pause releasing), `TestHousekeepingStandsDown` (unknown,
  0.8, 16 minutes, limited, none selected; no other connection tried; a
  combine still acts), `TestHousekeepingLedger` (one transaction with
  the caller, a replayed pass, restart with nothing dispatched, moved,
  dispatched, the eleventh action held then claimed the next day, veto
  then one recurrence then none, a team key raised twice, the held cap),
  `TestHousekeepingAutoDisable` (mixed kinds, rows survive the caller's
  rollback, nothing re-enables on its own, re-enable clears the count),
  `TestHousekeepingPreempts` (queue order).
- Contract (`thintest/housekeeping_contract_test.go`): H1 as
  `TestContractHousekeepingCombine` (a recorded task's pass combines a
  pair; view, action, page and summary against the fixtures; a teammate
  sees none of it and cannot undo it, from the view or the receipt; the
  seven-day window), `TestContractHousekeepingUndoRoundTrips` (both
  tasks byte for byte after Undo, destination included; 409 with the
  action; the veto holds; the view's Undo racing the receipt's: one
  commits), `TestContractHousekeepingPause`,
  `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; 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 from the view; Settings' section at
  both sizes, quiet hours saved and shown again, Pause from Settings and
  the view saying so; live: a new combine, Undo, a switch and a change
  made from another device land with no reload (the last failed with
  nav-stream's housekeeping listener removed). 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
  check (Principal), saveTask's guard (Never), the budget fit (Reservation),
  the stand-down (StandsDown), recovery's revision compare (Restart), the
  undone veto (UndoRoundTrips), the seven-day window (Combine), Pause
  (Pause), the two-failure threshold (AutoDisable), quiet hours on the
  receipt (QuietHours), release on the person's message (QuietHours), the
  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), 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

- Thresholds are UX1's as shipped on staging (title 0.75 with three
  words, or title and brief 0.7 with five; a match at 0.6 with two, or
  0.5 with three), kept by the controller; the spec's table now says so.
  They are pinned in the fixtures.
- The combined receipt keeps its card kind `combined` (native apps and
  pages already draw it) and gains `action_id` and `visible_at`; the
  new card kind `housekeeping` is the digest line.
- `expired` with `subject_moved` is a fresh finding on the new revision
  (the spec's recovery says "re-run as a fresh finding" for unchanged
  claims; a moved subject is new facts). Refused keys never act again.
- The eleventh action of the day is `held` (§4 rate limits), not
  `refused` (§6's Never list says refused); it acts the next day.
- `checked_at` for headroom is the connection record's update time (the
  runner reports headroom at most once a minute).
- A judgement turn reserves its share of the day's tokens, 150,000 / 4
  = 37,500 (Paul: four turns must fit), derived from the limits, not a
  fixed 40,000; the token budget stays the binding total. The spec's
  §4 says so.
- `duplicate_possible` links count as actions in the ledger (class
  `link`) but not toward the ten-a-day ceiling and are not listed on the
  view; refusals are.
- A receipt held through quiet hours stands in the conversation at the
  time it showed. Undone while held, it shows at 08:00 as undone.
- Pause also suspends the digest; the view and Undo stay.
- Undo's seven-day window applies to the receipt and the task page's
  Undo too (409), for folds the ledger made; older UX1 folds keep their
  open Undo.

## Open issues

- H1 is at contract level (fake runner frames). In a real conversation a
  same-person look-alike is answered by record_task's similar result or
  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.
- Person's zone is UTC everywhere (quiet hours, the day, 03:00, 08:00).
- Version skew as before: an old runner is unaffected (no new frames).

## Round: Astra round 1 (on 220a27a), REQUEST CHANGES

Six Important and one Minor (`~/.cache/tmp/equipo/hk1rev-final.md`),
each with a test that failed first:
1. `saveTask` under the principal authorizes against the stored task's
   creator and refuses a changed creator (TestHousekeepingNever: a
   forged creator on another's task).
2. The principal never writes a notebook (its own neither cleared nor
   replaced) and never saves a card, so `withdrawMergeCards` refuses
   (TestHousekeepingNever: own notes, a merge card withdrawn or
   resolved).
3. Housekeeping dispatches nothing in slice 1: `hkSpend` refuses
   outright; the reservation boundary (live claim, person, membership,
   tier, no reuse) is slice 2's (TestHousekeepingNever: dispatch within a
   reservation on a healthy connection, a housekeeping turn).
4. The executor checks class against proposal before anything runs:
   act combines, link links, propose and ask carry out nothing yet; a
   mismatch is a refused row (TestHousekeepingClassActions).
5. Held receipts are not published for a paused person, by the tick or
   their message; Resume lets them show
   (TestContractHousekeepingPauseHoldsReceipts).
6. The digest is scheduled as receipts are: due in quiet hours, it waits
   for their end (TestContractHousekeepingDigestSchedule).
7. An empty digest does not use up the day: `LastDigestAt` moves only
   when a digest is posted or scheduled (same test).

## Copy for review

Accepted for now with the existing marker in `copy.go` and listed in the
plan 3 inventory ("Housekeeping slice 1"):
- Conversation: `chat.housekeeping.link` "Housekeeping",
  `.digest_one` "Tidied 1 thing.", `.digest` "Tidied %d things.",
  `.digest_disabled` "Stopped %s after two Undos or failures this week.",
  `.detector.duplicate_same_creator` "combining duplicate tasks",
  `.detector.duplicate_possible` "naming possible duplicates",
  `.stood_down_budget` "Housekeeping stood down: today's budget is
  used.", `.stood_down_limit` "Housekeeping stood down: the connection is
  near its limit."
- View: `housekeeping.title` "Housekeeping", `.lede` "Equipo tidies your
  work on its own. Everything it does is listed here, and you can undo
  it.", `.pause` "Pause", `.resume` "Resume", `.paused` "Paused. Nothing
  is tidied until you resume.", `.today` "Today", `.meter.turns`
  "Judgement turns", `.meter.tokens` "Tokens", `.meter.retries`
  "Automatic retries", `.meter.used` "%s of %s", `.meter.held` "%s
  held", `.actions` "What Equipo did", `.actions_empty` "Nothing yet.
  When Equipo tidies something, it shows here.", `.action.combine`
  "Combined “%s” into “%s”", `.action.link` "Named “%s” a possible
  duplicate of “%s”", `.evidence` "%d%% alike, %d words in common",
  `.state.undone` "Undone", `.state.refused` "Refused: not Equipo's to
  change", `.state.failed` "Failed", `.held.ceiling` "Waiting: ten things
  tidied today already", `.held.budget` "Waiting: today's budget is
  used", `.held.stand_down` "Waiting: the connection is near its limit",
  `.held.held_overflow` "Dropped: too many waiting", `.until` "Undo until
  %s", `.undo` "Undo", `.refusals` "Refused and failed", `.detectors`
  "What Equipo looks for", `.detector.duplicate_same_creator` "Combine
  duplicate tasks", `.detector.duplicate_possible` "Name possible
  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."

## Staging

Not restaged (the controller sequences it). No live provider runs: slice
1 spends nothing.

## Blockers

None.
