oficina / equipo Public

specs: Equipo housekeeping loop, detectors, policy and budget

Design spec for proactive tidying that stays under control: a registry of
deterministic detectors, four action classes (act and tell, propose, ask
once, never) enforced server side, a per-person daily budget drawn from
the cheapest healthy connection with a stand-down rule, event-driven
cadence plus a daily sweep, idempotency through a housekeeping ledger,
quiet hours, one Pause switch, a daily digest line and a Housekeeping
view with Undo. Suggestions live in a folded lane, decay and are capped.
Scoped to a team with subjects so the same loop can later serve a
business or a family. Four slices; two decisions for Paul.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
claude cc6ca419f36494ba0a73e9757d2dd45455614d68 parent 7946111
1 file changed, +388 −0
  • docs/superpowers/specs/2026-11-08-equipo-housekeeping.md +388 −0

CI passed — run details

diff --git a/docs/superpowers/specs/2026-11-08-equipo-housekeeping.md b/docs/superpowers/specs/2026-11-08-equipo-housekeeping.md
new file mode 100644
index 00000000..32cf84ab
--- /dev/null
+++ b/docs/superpowers/specs/2026-11-08-equipo-housekeeping.md
@@ -0,0 +1,388 @@
+# Equipo housekeeping: a tidying loop that stays under control
+
+Status: design for Paul's review, 2026-11-08. Drafted by Claude (Fable
+5.1) on `design-housekeeping` from `thin-v1-conn1` (7946111). Builds on
+thin v1 (`2026-11-06-equipo-thin-v1.md`), Connections rev 3
+(`2026-11-08-equipo-connections.md`, §§3, 6) and the progress logs for
+slices 2b, 3, 4, 4c, CONN1 and UX1. Not implemented.
+
+## 0. Why, and the shape of the answer
+
+Paul, on the duplicate tasks the coordinator kept filing: "Can Equipo
+itself tidy up the duplicates? This is where I guess we need to start
+thinking about loops where it pro-actively tries to keep everything tidy
+and to spot things to improve (whilst not going out of control)." And
+later: the loop is the basis of continual improvement that Equipo should
+suggest and manage "across the whole business / organisation / family".
+
+Equipo already has the pieces of a loop without the loop. Move-in and
+explore turns run with no person message and only read and note tools.
+The notebook holds what the coordinator has learned. The runner checks
+reach every minute and watches merged branches. The merge policy is
+deterministic and runs in `advance`. Duplicate detection is being built:
+same-creator, high-similarity pairs are combined with an Undo receipt
+(`Task.folded`, `CardCombined`, `POST /tasks/{id}/uncombine`), weaker
+matches get a "Possible duplicate of" link. The mutation ledger makes
+writes idempotent across attempts. Usage records every attempt.
+
+Housekeeping is the rule that joins them: **deterministic detectors
+notice things; a policy table says what each class of thing may become;
+a budget, a ledger and one Pause switch keep it bounded; everything it
+does leaves a receipt with Undo; everything it only thinks of becomes a
+suggestion, never a task, until a person taps.** A model is consulted
+only when a detector has already fired and the question is one of
+judgement, and that consultation is a cheap read-only turn like explore.
+No setup: the loop is on from the first message, with defaults, and the
+only control a person needs is Pause.
+
+## 1. Scope: teams, subjects, who sees what
+
+Everything in this spec belongs to a **team**: the roster that shares a
+conversation server today, which in time may be a business, an
+organisation or a family. Within a team, every detector finding, action
+and suggestion has a **subject**: `{kind, id}` where kind is `task`,
+`project`, `connection`, `notebook_entry`, `person` (a person's own area)
+or `team`. The subject decides authority and visibility by one rule:
+**a subject owned by one person is that person's business; a subject
+owned by the team is everyone's to see and the owner's to act on.**
+
+Concretely, a task's subject owner is its creator ("only a task's
+creator acts on it" stands). A connection's owner is its person. A
+notebook entry's owner is the coordinator's person. A project and the
+team itself are team subjects. The loop runs **per person**: each
+person's coordinator keeps that person's own subjects tidy, draws on
+that person's connections and budget, and posts receipts into that
+person's conversation. Team subjects produce suggestions visible to the
+whole roster, and in v1 nothing more; acting on a team subject is slice
+4 and needs the owner's say. A person sees a suggestion if its audience
+is them or the team; a person may accept a suggestion if they could
+create the task it describes (any member for team subjects, the owner
+for personal ones); dismissing is per person for team suggestions and
+final for personal ones. Budgets are per person in slices 1 to 3; a team
+budget, spent by the owner's housekeeping on team subjects, arrives with
+slice 4.
+
+## 2. Detectors: a registry of small declared units
+
+A **detector** is a declared, data-driven unit in a registry
+(`internal/equipo/housekeeping`), never free code in a handler. Each
+declares: `id`; subject kind; `class` (the action class of §3);
+`triggers` (event types from the stream, plus `sweep`); `judgement`
+(`none` or `model`); `rate` (at most N findings per subject and per team
+per period); `undo` (whether its action can be reversed); and `Detect`, a
+pure function from a read-only view of the store to zero or more
+**findings** `{detector, subject, key, evidence, proposal}`. The `key` is
+the finding's identity (`duplicate:tkA:tkB`, `retry:tkA:attempt3`): the
+same key never acts twice (§4). Evidence is structured fields the receipt
+and the page can render, never model prose. Adding a detector is a
+registry entry and a fixture; nothing else changes, which is what lets
+the non-code detectors of §8 arrive later.
+
+Deterministic first. Every detector in v1 fires on data the instance
+already holds or the runner already reports; a model is called only when
+`judgement: model`, and only to answer "should this finding become a
+suggestion, and in what words" with a verdict tool, never to decide an
+action. The candidate detectors, with the class each lands in:
+
+| Detector | Fires on | Class | Judgement |
+|---|---|---|---|
+| `duplicate_same_creator` | `record_task` by the same creator, title overlap at or above 0.8 with three shared words, both open, neither started | Act and tell: combine, receipt with Undo (the work being built) | none |
+| `duplicate_possible` | overlap at or above 0.6 or a different creator | Link "Possible duplicate of"; different creators: Ask once, to the newer task's creator | none |
+| `retry_transient` | a step stopped with `runner_restarted`, `provider_failed`, `interrupted`, `checks_timeout`, `candidate_unavailable`, `clone_failed`, `push_failed` (republish), `no_runner` once a runner is back | Act and tell: one retry per task per day, receipt with Undo | none |
+| `ready_waiting` | a task at Ready to merge with an open card or no card for over 24 h | Digest mention only ("2 ready tasks are waiting on you"), never a new card | none |
+| `merged_outside` | the merge watch sees the candidate on the default branch without a merge step, or a `branch_gone` report with no merge | Act and tell: mark Done "Merged on Amadan" (reversible); a branch gone unmerged: Needs you `branch_moved` as today | none |
+| `stale_project` | no task, message or push in 60 days | Propose: "Archive <project>?" (team subject) | none |
+| `flaky_check` | the same gate fails then passes on the same SHA (a Retry of checks), twice in 30 days | Propose: "Checks flaked twice on <gate>" with the tails | model, to name the test |
+| `findings_unaddressed` | Review findings on a merged task whose files were not touched by the fix rounds | Propose: "Review raised N points that were not addressed" | model |
+| `notebook_stale` | an entry whose `repo` source file changed, or an `own` entry older than 90 days contradicted by a newer one | Act and tell: mark the entry stale (hidden from context, kept, Undo) | model for "contradicted" |
+| `repo_reach` | hello catalog gains or loses a repository | Quiet line in the digest; a lost repo with open tasks: Needs you (exists) | none |
+| `connection_health` | `limited` with a reset over 48 h away, `sign_in_again`, a key whose `expires_at` is within 7 days | Needs you (exists) once; digest line otherwise | none |
+| `improvement_noticed` | a specialist calls `note_improvement{text, repo, path}` during a step (bounded, pinned) | Propose: one suggestion per note, deduplicated | model, to merge near-identical notes |
+
+The thresholds are constants beside the detector and appear in its
+fixture; the similarity function is `record_task`'s existing one.
+
+## 3. Action classes and the policy table
+
+Four classes, decided by the registry entry, enforced by the instance in
+the write transaction, never by the detector's own code or a model.
+
+**Act and tell.** Reversible, within the person's own subjects, no model
+spend beyond the person's cheap tier, and undoable for seven days or
+until a later change makes the undo impossible (409 with the reason, as
+the home card's Undo today). The action is written, its receipt card
+posted in the person's conversation ("Combined [A] into [B] · Undo",
+"Retried Engineering on [A] after the runner restarted · Undo", "Marked
+a note stale · Undo") and the `housekeeping` event emitted, in one
+transaction. Undo restores the exact prior state through the same
+resource APIs a person would use (`uncombine`, cancel of the retried
+attempt plus the step's prior reason, the entry's prior state) and marks
+the key `undone`, which vetoes it: the detector never fires that key
+again, and the person's veto is the containment signal of §4.
+
+**Propose.** Creates a **suggestion**, not a task (§5). Costs nothing
+unless `judgement: model`, in which case one housekeeping turn from the
+budget. A suggestion never changes a task, a branch, a project or a
+note. Examples: flaky checks, unaddressed findings, improvements noticed,
+stale projects.
+
+**Ask once.** Shared, irreversible or costly, and the question is a
+**Needs you** card with one tap, asked once per key and never repeated:
+a cross-creator duplicate ("Is [A] the same as Nora's [B]? Fold into it
+/ Keep separate"), a retry that would run a `strong` tier step, a stale
+project's archive. "Ask once" reuses the card kinds and the creator-only
+answer path from slice 4c.
+
+**Never.** Delete data (tasks, projects, branches, notes, usage rows);
+merge without checks, or merge at all outside the slice 4c policy; act
+on another person's task or notebook; create or start a task from a
+suggestion without a tap; spend past the budget or on a `limited`
+connection; post more than receipts and one digest line a day; change a
+setting. These are refused **server side** by a `housekeeping` principal
+check in the handlers, so a detector or a judgement turn that tries gets
+403 `housekeeping_forbidden` and the refusal is logged on the view.
+
+| Class | Needs | Costs | Reversal | Tells the person |
+|---|---|---|---|---|
+| Act and tell | own subject, reversible, no model | 0 or one cheap step | Undo, 7 days | receipt card, digest |
+| Propose | any subject | 0 or one cheap turn | dismiss | Suggestions lane, digest |
+| Ask once | shared, irreversible or strong tier | 0 | the answer | one Needs you card |
+| Never | | | | refused, shown on the view |
+
+## 4. Control
+
+**Budget.** Per person per day: `judgement_turns` (default 4) and
+`tokens` (default 150,000) for housekeeping turns, and `retries`
+(default 3) for act-and-tell steps. Spent rows are ordinary `usage` rows
+with role `housekeeping`, so the budget is computed, not stored, and
+shows on the Usage page like any role. Housekeeping runs on the
+**cheapest healthy connection**: the choice function of Connections §3
+with the tier floor `cheap` and role `housekeeping`, never a `limited`
+connection, and it **stands down** when every healthy connection reports
+utilization at or above 0.8 or when only limited connections remain, so
+Paul's week-limited Claude is never nudged over by a tidy-up. A
+housekeeping turn is dispatched after every person turn, as move-in is,
+and yields to a person's message exactly as move-in yields. Deterministic
+detectors cost no budget and keep running when the budget is spent; only
+judgement turns and retries stop, and the digest says so ("Housekeeping
+paused until tomorrow: today's budget is used").
+
+**Cadence.** Event-driven first: each detector lists the event types it
+cares about (`task`, `step`, `card`, `connection`, `project`,
+`notebook`), and `advance` runs the registry for the affected subject
+in the same transaction that wrote the event, so a duplicate is noticed
+as the second task is recorded and a transient stop as its report lands.
+Plus one **daily sweep** per person over all their subjects, at 03:00 in
+the person's zone (UTC until the zone is known), for the detectors that
+depend on time (`ready_waiting`, `stale_project`, `notebook_stale`,
+`connection_health`). The sweep is a single pass; it never loops.
+
+**Rate limits** are in the registry: `retry_transient` once per task per
+day; `duplicate_same_creator` unbounded (free and undoable);
+`flaky_check` once per gate per week; `improvement_noticed` five per
+task; a hard ceiling of **ten actions and five suggestions per person
+per day** across all detectors, after which findings are held for the
+next day.
+
+**Idempotency.** `chat_housekeeping` (§6) is the loop's ledger, keyed
+`(team, person, detector, key)`; a finding whose key exists in any state
+is a no-op, so a replayed event, a restart or a second sweep cannot act
+twice. Actions that run through the coordinator's tools also enter the
+turn's mutation ledger as today.
+
+**Quiet hours.** Between 22:00 and 08:00 in the person's zone the loop
+may act (a retry at 02:00 is welcome) but posts nothing; receipts and
+the digest wait for 08:00 or the person's first message, whichever comes
+first.
+
+**Pause.** One switch, `PUT /api/v1/housekeeping {paused}`, on the
+Housekeeping view and in Settings. Paused: no detector runs, no sweep,
+nothing posted; existing receipts keep their Undo. Nothing else to set.
+
+**The digest.** Once a day, only when something happened, one line in
+the conversation written by the instance (no model): "Tidied 2 things,
+suggested 1. [Housekeeping]" linking to the view. Receipts posted during
+the day are not repeated in it.
+
+**The Housekeeping view** (`/housekeeping`, linked from the conversation
+header beside Notebook and from the digest): Pause; today's budget as
+three quiet meters; actions newest first, each with its evidence and
+Undo while possible; suggestions; refusals; and the detector list with
+its state and reason when disabled.
+
+**Failure containment.** A detector is **auto-disabled for that person**
+when, within seven days, two of its actions are undone, or two of its
+runs error, or two of its judgement turns end `failed`. It says so once
+in the digest ("Stopped combining duplicates after two undos. Turn it
+back on in Housekeeping.") and the view offers the switch
+(`PUT /housekeeping/detectors/{id} {enabled}`). Disabling is per person
+and per detector; the rest of the loop goes on.
+
+## 5. Suggestions
+
+A suggestion is a row (§6) with a title, a short text, structured
+evidence, a subject and an audience. It lives in two places: the
+**Housekeeping view**, in full; and a **folded "Suggestions (3)" group at
+the bottom of the Tasks page**, collapsed by default, with the same row
+shape as a task but muted and with no track. The sidebar shows no count
+for suggestions; only Needs you carries a number.
+
+Each row has two quiet actions. **Make it a task** calls `record_task`
+with the suggestion as brief, the tapper as creator and the suggestion's
+project, through the ordinary path (duplicate check included), then marks
+the suggestion `accepted` with the task id; the task is then just a task.
+**Dismiss** marks it `dismissed` and vetoes its key for 30 days.
+
+Suggestions **decay**: 14 days open becomes `expired`; expired and
+dismissed rows are kept 30 days for the view and then deleted by the
+retention sweep that already trims usage rows. A key may be raised again
+after its veto if the evidence recurs, at most once.
+
+**De-duplication**, in order: against open and recently closed
+suggestions by key; against open tasks in the same project by
+`record_task`'s similarity, in which case the suggestion is dropped and
+the task gets the evidence as a thread entry; against each other within
+a judgement turn, where the model may merge near-identical notes into
+one. **At most five open suggestions per person** (ten team-wide); a
+sixth is `held` and surfaces when one closes, so the lane never becomes
+a backlog.
+
+## 6. Data model, API v1, wire, tests
+
+**Tables** (migration 0050):
+
+- `chat_housekeeping`: `id`, `team`, `person`, `detector`,
+ `subject_kind`, `subject_id`, `key`, `class`, `state` (`done`,
+ `undone`, `refused`, `failed`, `held`), `evidence` (JSON), `result`
+ (JSON: what changed, enough to undo), `undo_until`, `at`, `undone_at`,
+ `revision`; unique `(team, person, detector, key)`.
+- `chat_suggestions`: `id`, `team`, `audience_person` (null for team),
+ `detector`, `subject_kind`, `subject_id`, `project`, `key`, `title`,
+ `text`, `evidence`, `state` (`open`, `held`, `accepted`, `dismissed`,
+ `expired`), `task_id`, `created_at`, `expires_at`, `revision`;
+ `chat_suggestion_dismissals (suggestion, person)` for per-person
+ dismissal of team suggestions.
+- `chat_housekeeping_settings`: `person`, `paused`, `disabled` (JSON
+ map detector to reason and time), `last_digest_at`, `revision`.
+- `chat_turns.kind` gains `housekeeping` beside `move_in` and
+ `explore`; `chat_usage.role` gains `housekeeping`.
+
+**Resources.** `GET /api/v1/housekeeping` returns `Housekeeping {paused,
+budget {turns_used, turns, tokens_used, tokens, retries_used, retries},
+detectors[{id, class, enabled, disabled_reason}], actions[], refusals[],
+revision}`; `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 with the current
+action when no longer undoable); `GET /api/v1/suggestions`;
+`POST /api/v1/suggestions/{id}/accept` returns `TaskAccepted`;
+`POST /api/v1/suggestions/{id}/dismiss`. Events: `housekeeping` (one per
+action state change) and `suggestion`. `Snapshot` gains `suggestions`
+and `housekeeping_summary {open_suggestions, paused, disabled}`.
+`Card` gains kind `housekeeping` with `action_id` and `ChoiceUndo`, the
+combined card being its first instance.
+
+**Wire.** Instance to runner: `message{kind: housekeeping}` for a
+judgement turn, with the tool set `status`, `read_task`, `find`,
+`search_code`, `read_file`, `read_notes` plus `housekeeping_verdict
+{key, verdict: suggest | drop, title, text}`, mounted by the proxy for
+this kind only, 24 calls as explore. Runner to instance: `step` reports
+gain `noticed[{text, repo, path}]` from the pinned `note_improvement`
+tool (five per step, 280 bytes each, text only); the merge watch gains
+`branch_gone{task, branch}`. Retries and combines need no new frame:
+they are the existing retry and fold paths called by the housekeeping
+principal. Fixtures under `internal/wire/wiretest/testdata`:
+`api/housekeeping.json`, `api/housekeeping-paused.json`,
+`api/action-combined.json`, `api/action-retry.json`,
+`api/action-undone.json`, `api/suggestions.json`,
+`api/suggestion-accepted.json`, `api/event-housekeeping.json`,
+`api/event-suggestion.json`, `api/card-housekeeping.json`,
+`frames/message-housekeeping.json`, `frames/step-noticed.json`,
+`frames/branch-gone.json`. The secret-shape guard covers the new types.
+
+**Tests.** Unit: every detector has a **deterministic fixture** (a store
+snapshot in, the exact findings out, including the no-finding cases at
+the threshold edges) and a rate-limit table. Contract: `TestHousekeepingBudget`
+(the fifth judgement turn in a day is held, the digest says so,
+deterministic detectors still act); `TestHousekeepingStandsDown` (every
+connection at 0.8 or limited: no turn, no retry, duplicates still
+combined); `TestHousekeepingUndoRoundTrips` (each act-and-tell detector:
+act, undo, the resource equals its prior fixture byte for byte, the key
+vetoed, a second finding a no-op); `TestHousekeepingNeverRefused` (the
+housekeeping principal attempting delete, merge, another person's task,
+a `limited` connection, a sixth action past budget: 403 or 409 at the
+handler, a `refused` row, nothing changed); `TestHousekeepingIdempotent`
+(the same event replayed and a restart mid-action: one row);
+`TestHousekeepingAutoDisable` (two undos: disabled, one digest line, the
+switch re-enables); `TestSuggestionsLane` (five open, the sixth held,
+accept makes a task through `record_task`, dismiss vetoes, decay at 14
+days); `TestHousekeepingQuietHours` (an action at 02:00 posts at 08:00).
+Headless: `H1` two similar tasks in one message, combined, Undo from the
+receipt restores both; `H2` the runner killed mid-step, restarted, the
+step retried once with a receipt, a second kill is Needs you; `H3` a
+judgement turn with the fake CLI produces one suggestion and spends one
+budget turn. Browser: the view and the lane at 1280 and 390.
+
+## 7. Slices
+
+| Slice | Content | Size |
+|---|---|---|
+| 1 The smallest useful loop | Registry and `chat_housekeeping`; `duplicate_same_creator` wrapped as the first detector (the combine being built becomes its action); `retry_transient` once per task per day; the budget with stand-down; Pause; the digest line; the Housekeeping view with Undo and refusals; auto-disable; the `housekeeping` principal and its server-side refusals. No model turns, no suggestions. Headless H1, H2 | 3 days |
+| 2 Suggestions | `chat_suggestions`, the lane, accept and dismiss, decay, de-duplication and the cap; detectors `merged_outside`, `ready_waiting`, `repo_reach`, `connection_health` (digest lines) and `flaky_check` without the model naming the test | 2 days |
+| 3 Judgement | turn kind `housekeeping`, role and tier, `housekeeping_verdict`, quiet hours and the sweep; `note_improvement` on steps and `improvement_noticed`; `findings_unaddressed`; `notebook_stale`; `duplicate_possible` ask-once across creators; headless H3 | 2 days |
+| 4 Team scope | team suggestions with per-person dismissal, `stale_project`, the owner's team budget and team Pause, acting on team subjects by the owner | 1.5 days |
+
+Each slice lands headless first, then staging with the real CLI, then
+UI, as thin v1 §8. Slice 1 ships behind nothing: it is on by default
+with Pause as the exit.
+
+## 8. Beyond code
+
+The same loop serves a business or a family when three things change
+and nothing in §§3 to 5 does. **Subjects** widen: a person's area, a
+shared responsibility, a recurring obligation, a decision. **Detectors**
+are added to the registry over new facts: a recurring chore that has no
+completion since its period (`chore_overdue`, propose a reminder), a
+decision recorded in the notebook with a review date that has passed
+(`decision_stale`, propose revisiting it), a question or follow-up with
+no owner after N days (`unowned_followup`, ask once who takes it), spend
+drifting from its usual level on a connected ledger (`spending_drift`,
+propose a look), a document or list nobody has touched that a current
+task depends on. **Data sources** become connections of new kinds
+(a calendar, a shared list, a bank or accounts export, a mailbox) with
+the same consent model as model connections: added by the person who
+owns them, readable by that person's housekeeping, shared with the team
+only by an explicit grant, never a secret on the instance. For a family
+the owner role matters more than it does for a one-person team: the
+owner sets the team Pause and the team budget, and personal subjects
+stay personal even from the owner. What this needs before any of it is
+built: a typed fact store the detectors read instead of the chat tables,
+a consent record per source and per audience, and copy that a
+non-developer reads without flinching. None of that is designed here.
+
+## 9. Decisions for Paul
+
+1. **Budget defaults and the stand-down rule.** Four judgement turns,
+ 150,000 tokens and three retries per person per day, on the cheap
+ tier only, and the loop stands down whenever every healthy connection
+ is at 80% utilization or only limited connections remain. Confirm, or
+ name other numbers.
+2. **Where suggestions show.** A folded Suggestions group at the bottom
+ of Tasks plus the Housekeeping view, capped at five open per person,
+ with no sidebar count. The alternative is the view alone with a quiet
+ dot on Tasks. Confirm the first, or choose the second.
+
+## 10. Risks
+
+Headroom is best effort (Claude reports one figure, endpoints none), so
+the stand-down rule may let a judgement turn run on a connection closer
+to its limit than it looks; the daily turn cap bounds the damage. A
+detector that is deterministic but wrong on real data will act before it
+is undone twice; the seven-day Undo and the per-key veto bound that too.
+`merged_outside` depends on the merge watch's squash heuristic, which
+already serves people's merges. The judgement turn is a model reading
+code and findings, so its verdict tool must stay the only effect it can
+have, as `write_note` is for move-in; the proxy mounts nothing else.
+Team scope waits for slice 4, so until then a shared project tidied by
+two people's loops could raise the same team suggestion twice; the key
+is team-scoped to prevent it.