Repository navigation
Description
Context
Part of the epic #1777 (resolve pending media through hygiene review). Read the epic for every maintainer ruling; this task builds the one per-file media inventory that both the sync count and hygiene review use, its dispositions and the count/report changes.
Today sync lists each media path in its report (...leftovers.media.map, packages/core/src/lib/sync/report.ts:76) and noninteractive sync asks for judgment about media (needsAgent, packages/core/src/cli/commands/sync.ts:220-226). Assessment skips Git-ignored files and applies media.ignore before MEDIA/LARGE classification (assess, packages/core/src/lib/sync/assess.ts:127-155; mediaPolicyClass, packages/core/src/lib/media.ts:47-51), so an ignored file is ARTIFACT, and generated brains ignore .brain/scratch/ (template/.gitignore:24-27). Hygiene states are open | snoozed | dismissed | resolved (HygieneState, packages/core/src/lib/hygiene.ts:41), read offline by readHygieneLog (:1506).
Design: rev 4 §1, §2 and §4; rev 5 §5.7; rev 6 §1-§4; rev 6.1 in full.
Maintainer decision (2026-10-24)
A/A/A/A selected for the four inventory-policy questions:
- Add only conversation-pinned scratch MEDIA/LARGE paths to the existing assessment population, including pinned scratch paths matching media.ignore. Do not admit ignored non-scratch media or walk unpinned scratch output. Ignore-over-track precedence remains unchanged for assessment, destinations and proposed rules.
- Pinned scratch findings are review-only and do not change Media awaiting review: N. Do not add media.linked or a linked-count report suffix.
- A valid ready:false pin snapshot contributes its already-listed positive evidence, with an explicit incomplete-scan notice. Missing, malformed or unreadable snapshots admit no scratch findings and report pins-unknown. Incomplete evidence never grants deletion permission or proves an exhaustive reference scan.
- Read at most 5,000 distinct pinned paths per inventory, with a trusted-host override. Overflow explicitly reports inventory-too-large/not fully checked, without claiming exhaustive discovery; ordinary assessment remains independent.
Use read-only offline pin discovery shared by CLI and server. Apply the proposal fingerprint/invalidation rule: hash sorted session keys that list the path, so unrelated pin changes do not invalidate a disposition; missing/unpinned originals stop being findings and stale apply writes nothing. Completed kept copies remain bound to copy/copySha256. The existing effect safety gates remain unchanged.
Scope
- One inventory function, shared by offline
brain syncand server review: identity is the exact raw repo-relative path; directories expand once; MEDIA plus LARGE on one file is one finding with both provenances; symlinks are counted with no actions (rev 4 §1). - The admission path for ignored and
.brain/scratch/conversation-linked media, under the approved narrow pinned-scratch exception, including media.ignore-matching scratch pins; ignored non-scratch files stay excluded. - Severity B and ordering: MEDIA informational, LARGE warning, then the existing severity → urgency (unknown) → age → identity order of
docs/decisions/hygiene-review.md. - Fingerprints: content sha256, bytes, classes, matching track/ignore entries, the reference-inventory digest and, for scratch sources, the pin digest (rev 4 §1).
- Leave pending (A): a per-pass deferral in review operational state that survives same-pass refresh, reconnect and restart, lapses on a fingerprint change, and is reselected by a new pass; an all-deferred pass ends with truthful counts.
- Dispositions: the dedicated
keptstate incontext/hygiene/kept.md(K1 A, rev 5 §5.7, rev 6 §1), read identically offline and on the server;kept.mdis not created empty. - Count (K2 B):
Media awaiting review: Nexcludes media with a valid dismissed, snoozed or kept disposition and includes per-pass deferrals; due snoozes and invalidated dispositions return. The routine report enumerates no paths;needsAgentloses its media clause. - Compatibility per rev 6.1: existing fields keep their values, types and names; the additive fields (
copy,copySha256,keptOnwith null defaults,reconcile.kept,counts.kept,media: {awaitingReview, setAside, kept}) are always present; no-op hygiene logs and the no-media sync report text stay byte-identical.
Out of scope
- The Delete, Move, Persist here and Keep a permanent copy effects, references, config edits and Undo (Epic: resolve pending media through hygiene review #1777's effects child).
- The review UI and media preview (Epic: resolve pending media through hygiene review #1777's review child).
- Changing
media.ignore/media.tracksyntax or precedence (M1 A), or adding a second policy store.
Acceptance criteria
- A pinned scratch media file matching media.ignore is reviewable; ignored non-scratch media and unpinned scratch output stay excluded. No scratch directory walk is added.
- Valid ready:false pins are admitted with the incomplete notice; invalid/missing/unreadable snapshots admit none and report pins-unknown. A 5,001-path fixture hits the default bound and reports incomplete discovery; a trusted-host override is tested. Neither case grants deletion permission or exhaustive-scan status.
- Pin fingerprints change only for session links to the same path; unrelated pin changes preserve deferrals. Pruned/unpinned sources resolve and stale apply writes nothing; completed kept copies retain their copy-based identity.
- Scratch pins never alter the routine awaitingReview count or add media.linked/report suffixes; offline and server behavior agree for complete, incomplete, unknown and overflowing pin snapshots.
- Offline
brain syncand server review produce the same inventory, count and selection for the same tree, proven by a parity test including dismissed, snoozed, due-snooze, kept and deferred media. - Only the approved conversation-pinned scratch exception joins ordinary assessment; its findings enter review but not the routine count, with a fixture where a normally ignored, conversation-linked scratch file reaches Keep a permanent copy eligibility.
- The routine sync report shows only
Media awaiting review: Nand a route into review; no media path appears; status and exit code do not change because of media. - Leave pending survives same-pass refresh, reconnect and restart, returns on a new pass, lapses on a relevant fingerprint change and not on an unrelated one.
- The rev 6.1 G1-G6 goldens pass: file bytes, legacy JSON projection, always-present defaults, new complete goldens, report cases and no inappropriate
keptenum value; its omission, ordering, empty-file, counter and report mutations each fail their intended assertion and are restored, recorded in the PR.
Verification
bun run test packages/core packages/ui-server
bun run typecheck
bun run lintOdysseus fixture brains, real Git, offline.
Contract impact
Additive CLI --json and HTTP fields and the new kept hygiene state, per rev 6.1 §4: CONTRACT: commits, same-commit CLI and package contract updates, API reports as affected, minor core, ui-sdk and ui-server changesets. Changed human report wording is documented. No removal or retyping of an existing field.
2026-10-24 triage at main 77f35ef1ba34e4fab7092ada5362ae799852ea24: The later design supplies a concrete inventory proposal but leaves four policy choices unapproved. Folded those exact options and consequences into the body; retain needs: decision rather than treating proposed admission/count/partial-pin/bound defaults as approved. Existing epic rulings and additive compatibility commitments remain binding.
2026-10-24 maintainer ruling: selected A/A/A/A, incorporated the narrow pinned-scratch exception, review-only count, incomplete positive-evidence handling and 5,000-path bound into scope and parity proof. All four inventory-policy decisions are resolved; effect approvals and safety gates remain unchanged.
Activity
schlessera commentedon Oct 24, 2026
Needs design (2026-10-24): how ignored and
.brain/scratch/conversation-linked media enter the media inventory.Decided: one shared inventory feeds the sync count and hygiene review; Persist here must handle a conflicting
media.ignore(ignore-conflict ruling B); Keep a permanent copy exists for conversation-linked scratch media (Q2 B); the count excludes valid dismissed, snoozed and kept media (K2 B). Left open: the inherited inventory rule (rev 2 §1.1, carried through rev 4 §1) saysmedia.ignorematches are not pending, and the inventory is built from assessment, which skips every Git-ignored file, including.brain/scratch/. So the files two approved actions target never reach review. The code cannot settle this: it is a choice about which files a person is asked about and what the routine count means.schlessera commentedon Oct 24, 2026
Design brief (1/2): admitting ignored and scratch-linked media
Answers the design prompt. Read at main:
assess(sync/assess.ts:127-155),mediaPolicyClass(media.ts:47-51),template/.gitignore:24-27,scratchLinks/openScratchPins(cron/scratch-pins.ts), the epic rulings and the rollback-A ruling. The rollback-A ruling already expects review to touch ignored scratch: "Explicitly retain required media bytes even when ignored scratch would otherwise receive metadata-only observation."Summary
.brain/scratch-pins/pins.jsonthat exist under.brain/scratch/as regular files and are MEDIA or LARGE.media.ignorematches, or Git-ignored files outside scratch. An ignore rule is the user's own recorded decision that the file is disposable. Asking about it again would turn every render folder into review work.media.ignore, not when the source is ignored (§4).Media awaiting review: N, because scratch prunes itself and needs no decision to stay correct. See Decision 2.1 · Admission rule (exact)
A path enters the inventory if either condition holds:
media.ignore, MEDIA or LARGEassesswalksessions[*]ofpins.json; starts with.brain/scratch/;lstatis a regular file;isMediaPathor bytes ≥maxTrackedBytespins.jsononly. No walk of.brain/scratch/.scratchLinksalready normalizes them and refuses..,\and control characters. They are re-checked here before anylstat, and anything outside.brain/scratch/is dropped.media.ignoreis still admitted. Pins are stronger evidence ("someone linked this in a conversation") than a broad rule, and the scratch area is never tracked anyway.inventory-too-largeand is honestly marked not fully checked, in the same way as Q1 A. The assessment part is unaffected.2 · Keeping disposable output out
.brain/scratch/never becomes a finding, however large it is.media.ignorematches outside scratch stay ARTIFACT (mediaPolicyClassis unchanged; M1 A, no precedence change)..jsonor.mdunder 5 MiB stays out.3 · Count and offline/server parity
Media awaiting review: Npins.jsonis an ordinary file under the brain. The offline CLI reads it read-only, withO_NOFOLLOW, as a regular file, and the version is checked. It never writes to it, and no server state is needed. Both sides run the same pureinventory(tree, policy, pinsSnapshot), so selection is the same.media.linked(a number, default 0). That is additive.Part 2 covers eligibility, pins-unknown, fingerprints, prune, fixtures and decisions.
schlessera commentedon Oct 24, 2026
Design brief (2/2): eligibility, pins-unknown, fingerprints, fixtures, decisions
4 · Eligibility (rev 4 §4 matrix, scratch-linked rows)
Files in the scratch area can't be kept in place. Use Keep a permanent copy..brain/**is protected; scratch is never trackedLinked from N conversations; those links will stop working.Where ruling B (ignore conflict) fires:
media.ignore. Example: copying toplaces/ithaca/harbour.pngwhilemedia.ignorehas"places/**/*.png". The copy's exact track rule would lose, so the governed adjustment is proposed, with its own approval.stale, and a fresh preview offers the adjustment.5 · Pins not ready or unreadable
pins.jsonstateready: trueready: false(scan incomplete)Conversation links are still being checked; more files may appear.pins-unknown)Conversation-linked files couldn't be checked.Nothing is lost while pins are unknown: the existing pruner already suspends deletion when the snapshot is not ready.
6 · Fingerprint and invalidation
Fingerprint fields: content sha256, bytes, classes, matching track/ignore entries, and the pin digest = sha256 of the sorted session keys that list this path. The rest of the pins file is not part of it.
resolved("not detected"). A deferral drops, and an in-flight Keep-copy apply fails its source-sha premise and returnsstale, writing nothing. A completed Keep copy stays valid, becausekeptbinds tocopy+copySha256, not to the original.7 · Fixtures (Odysseus, pinned 2026-07-12, real Git, offline)
.brain/scratch/2026-07-12/ithaca-harbour.png(PNG, 1.2 MB) is listed under session["pi","voyage-home"], withready: true. It is admitted, appears in review under From conversations, and the count is unchanged. Keep a permanent copy →places/ithaca/harbour.pnggives eligibility plus a preview..brain/scratch/2026-07-12/loom-draft-03.pngis not admitted.media.ignore: ["assets/renders/"]withassets/renders/loom.png: ARTIFACT, not admitted, not counted.media.ignore: ["places/**/*.png"]gives the ruling-B adjustment proposal on the copy destination.ready: falsewith the fixture 1 listing: admitted with the "still being checked" line. A missingpins.jsongivespins-unknown, no scratch findings, and the count is unchanged.../etc/passwd-style entry is dropped.stalewith the bytes unchanged.pins.jsonon the CLI fails parity.Open decisions
media.ignorematches? (a) No; ruling B applies to destinations and rules (above). (b) Yes, review-only, in a "Set aside by your rules" group. Recommend (a): an ignore rule is a recorded decision, and (b) makes every ignored render folder review work again.media.linked, with the report lineMedia awaiting review: N (+M from conversations). Recommend (a): scratch self-prunes, and a count that grows with every illustrated chat isn't actionable.ready: false? (a) Yes, with the notice. (b) No, treat it aspins-unknown. Recommend (a): listed paths are never wrong positives for "was linked".schlessera commentedon Oct 24, 2026
2026-10-24 triage at main
77f35ef1ba34e4fab7092ada5362ae799852ea24: The later design supplies a concrete inventory proposal but leaves four policy choices unapproved. Folded those exact options and consequences into the body; retain needs: decision rather than treating proposed admission/count/partial-pin/bound defaults as approved. Existing epic rulings and additive compatibility commitments remain binding.schlessera commentedon Oct 24, 2026
Decision (maintainer, 2026-10-24): A/A/A/A. Add conversation-pinned scratch media only (including media.ignore-matching scratch pins), without admitting ignored non-scratch files or walking unpinned scratch. Scratch findings are review-only and do not change the routine media count or add media.linked. Valid ready:false snapshots admit listed positive evidence with an incomplete-scan notice; missing/malformed/unreadable snapshots admit none and report pins-unknown. Default bound: 5,000 distinct pinned paths, trusted-host configurable, with explicit incomplete reporting on overflow. This grants no deletion permission or exhaustive-scan claim; existing effect/reference safety gates remain binding. The body now selects all four branches with offline/server parity and fingerprint proof.
3 remaining items
test(core): prove sync and review agree for snoozed, due and every pi…
CONTRACT: feat(core): count media awaiting review from one inventory …
fix(ui-server): gate hygiene next --defer on the media CLI release fl…
CONTRACT: docs(api-report): record the ui-sdk review state, defer eff…
CONTRACT: feat(core): record a kept media original with brain hygiene…
test(core): prove sync and review agree for snoozed, due and every pi…
CONTRACT: feat(core): count media awaiting review from one inventory …
schlessera commentedon Nov 2, 2026
Delivered to the epic integration branch
epic/1777-media-hygieneas98a15b92avia #3288; ready-candidate proof passed against the exact epic base. This issue closes when the epic batch lands on main.CONTRACT: feat(core): fingerprint media by a bounded scan of declared…
docs: describe count-only media reporting and the five review actions…
docs: describe count-only media reporting and the five review actions…
test(core): verify media hygiene review end to end across CLI, server…