| new file mode 100644 |
| index 00000000..697cce94 |
| --- /dev/null |
| +++ b/docs/superpowers/plans/HK1-PROGRESS.md |
| @@ -0,0 +1,262 @@ |
| +# Housekeeping slice 1 progress: the smallest useful loop |
| + |
| +Branch `thin-v1-hk1` from `thin-v1-conn1` (fa3860a, what staging runs, |
| +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): Pause and Resume, |
| + 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. |
| + |
| +## 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), `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 |
| + 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), and the Undo guards together (UndoRoundTrips). |
| + 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), not the spec table's rounded "0.8": 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). |
| +- With Paul's defaults the token limit binds before the turn limit for |
| + judgement turns: 40,000 each, so three fit in 150,000. Recorded in |
| + `TestHousekeepingReservation`; for Paul if four is meant. |
| +- `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). |
| +- 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). |
| + |
| +## 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" |
| +- 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. |