Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .changeset/media-undo-review.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@schlessera/brain": minor
"@schlessera/brain-ui-sdk": minor
"@schlessera/brain-ui-server": minor
---

A confirmed media effect can now be undone from hygiene review (#2781). `POST /api/hygiene/review` accepts `{ "operation": "undo-media", "journalId" }`, the journal ID on the resolved card's media receipt. It runs the same checks as Undo elsewhere, so it refuses without writing anything when the saved bytes were evicted or a file changed since. The response carries the Undo's receipt as `mediaUndo`. The card keeps its resolved status and gets the Undo's receipt. The review's `fixed` or `kept` counter drops, and the finding is pending again, on a new card.

Undoing Keep a permanent copy now also removes its `kept` entry, after the copy and config are restored, so the original is pending again instead of reopening as `copy-missing`. The new `brain hygiene unkeep <id> --journal <id>` removes exactly the kept entry that journal recorded, or refuses `not-kept` and writes nothing.

The UI SDK adds `HygieneReviewMediaUndoCommand` and `HygieneReviewRequest` (either command), with `hygieneReviewMediaUndoCommandSchema` and `hygieneReviewRequestSchema`; `HygieneReviewCommand` and its schema are unchanged. `HygieneReviewRead` gains the optional `mediaUndo` receipt.
81 changes: 81 additions & 0 deletions api-report/ui-sdk.txt
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ export "." (./src/index.ts)
type HygieneMediaRefusal
type HygienePreviewRequest
type HygieneReviewCommand
type HygieneReviewMediaUndoCommand
type HygieneReviewRead
type HygieneReviewRequest
type HygieneReviewState
type HygieneWorktreeDetails
type HygieneWorktreeDetailsRead
Expand Down Expand Up @@ -637,7 +639,9 @@ export "./client" (./src/client/index.ts)
type HygieneMediaRefusal
type HygienePreviewRequest
type HygieneReviewCommand
type HygieneReviewMediaUndoCommand
type HygieneReviewRead
type HygieneReviewRequest
type HygieneReviewState
type HygieneWorktreeDetails
type HygieneWorktreeDetailsRead
Expand Down Expand Up @@ -1444,7 +1448,9 @@ export "./protocol" (./src/protocol.ts)
type HygieneMediaRefusal
type HygienePreviewRequest
type HygieneReviewCommand
type HygieneReviewMediaUndoCommand
type HygieneReviewRead
type HygieneReviewRequest
type HygieneReviewState
type HygieneWorktreeDetails
type HygieneWorktreeDetailsRead
Expand Down Expand Up @@ -1767,7 +1773,9 @@ export "./schemas" (./src/schemas.ts)
hygieneOutcomeSchema
hygienePreviewRequestSchema
hygieneReviewCommandSchema
hygieneReviewMediaUndoCommandSchema
hygieneReviewReadSchema
hygieneReviewRequestSchema
hygieneReviewStateSchema
hygieneWorktreeDetailsReadSchema
inboxActionItemSchema
Expand Down Expand Up @@ -2131,7 +2139,9 @@ export "./server" (./src/server/index.ts)
type HygieneMediaRefusal
type HygienePreviewRequest
type HygieneReviewCommand
type HygieneReviewMediaUndoCommand
type HygieneReviewRead
type HygieneReviewRequest
type HygieneReviewState
type HygieneWorktreeDetails
type HygieneWorktreeDetailsRead
Expand Down Expand Up @@ -6865,14 +6875,22 @@ signatures (every public export and the types it is made of)
export interface HygieneReviewCommand {
operation: "start" | "pause" | "resume" | "refresh";
}
HygieneReviewMediaUndoCommand (packages/ui-sdk/src/protocol.ts)
export interface HygieneReviewMediaUndoCommand {
operation: "undo-media";
journalId: string;
}
HygieneReviewRead (packages/ui-sdk/src/protocol.ts)
export interface HygieneReviewRead {
review: HygieneReviewState;
action: InboxActionItem | null;
privateDetailAccess?: {
itemId: string;
};
mediaUndo?: HygieneMediaReceipt;
}
HygieneReviewRequest (packages/ui-sdk/src/protocol.ts)
export type HygieneReviewRequest = HygieneReviewCommand | HygieneReviewMediaUndoCommand;
HygieneReviewState (packages/ui-sdk/src/protocol.ts)
export interface HygieneReviewState {
version: 1;
Expand Down Expand Up @@ -12980,6 +12998,11 @@ signatures (every public export and the types it is made of)
start: "start";
}>;
}, z.core.$strict>;
hygieneReviewMediaUndoCommandSchema (packages/ui-sdk/src/schemas.ts)
const hygieneReviewMediaUndoCommandSchema: z.ZodObject<{
journalId: z.ZodString;
operation: z.ZodLiteral<"undo-media">;
}, z.core.$strict>;
hygieneReviewReadSchema (packages/ui-sdk/src/schemas.ts)
const hygieneReviewReadSchema: z.ZodObject<{
action: z.ZodNullable<z.ZodObject<{
Expand Down Expand Up @@ -13247,6 +13270,52 @@ signatures (every public export and the types it is made of)
version: z.ZodNumber;
waitUntil: z.ZodOptional<z.ZodNumber>;
}, z.core.$loose>>;
mediaUndo: z.ZodOptional<z.ZodObject<{
action: z.ZodEnum<{
"keep-copy": "keep-copy";
delete: "delete";
move: "move";
persist: "persist";
}>;
copySha256: z.ZodOptional<z.ZodString>;
files: z.ZodArray<z.ZodObject<{
path: z.ZodString;
state: z.ZodEnum<{
"left-changed": "left-changed";
changed: "changed";
conflict: "conflict";
created: "created";
removed: "removed";
restored: "restored";
unchanged: "unchanged";
}>;
}, z.core.$strict>>;
journalId: z.ZodString;
outcome: z.ZodEnum<{
applied: "applied";
compensated: "compensated";
kept: "kept";
partial: "partial";
pending: "pending";
refused: "refused";
stale: "stale";
undone: "undone";
}>;
reason: z.ZodOptional<z.ZodString>;
refusals: z.ZodOptional<z.ZodArray<z.ZodObject<{
code: z.ZodString;
effective: z.ZodOptional<z.ZodNumber>;
limit: z.ZodOptional<z.ZodString>;
line: z.ZodOptional<z.ZodNumber>;
observed: z.ZodOptional<z.ZodNumber>;
path: z.ZodOptional<z.ZodString>;
}, z.core.$strict>>>;
undo: z.ZodObject<{
available: z.ZodBoolean;
path: z.ZodOptional<z.ZodString>;
reason: z.ZodOptional<z.ZodString>;
}, z.core.$strict>;
}, z.core.$strict>>;
privateDetailAccess: z.ZodOptional<z.ZodObject<{
itemId: z.ZodString;
}, z.core.$strict>>;
Expand Down Expand Up @@ -13292,6 +13361,18 @@ signatures (every public export and the types it is made of)
version: z.ZodLiteral<1>;
}, z.core.$strict>;
}, z.core.$strict>;
hygieneReviewRequestSchema (packages/ui-sdk/src/schemas.ts)
const hygieneReviewRequestSchema: z.ZodUnion<readonly [z.ZodObject<{
operation: z.ZodEnum<{
pause: "pause";
refresh: "refresh";
resume: "resume";
start: "start";
}>;
}, z.core.$strict>, z.ZodObject<{
journalId: z.ZodString;
operation: z.ZodLiteral<"undo-media">;
}, z.core.$strict>]>;
hygieneReviewStateSchema (packages/ui-sdk/src/schemas.ts)
const hygieneReviewStateSchema: z.ZodObject<{
blocker: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
Expand Down
20 changes: 16 additions & 4 deletions docs/decisions/hygiene-review.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ already carries category, path and stable evidence (`HygieneCandidate`,
(`hygieneId`, `packages/core/src/lib/hygiene.ts:181-184`). Those primitives do not
by themselves supply validation-to-hygiene equivalence, priority selection or
review dispositions. The CLI exposes reconciliation, listing and deterministic selection
(`hygieneCommand`, `packages/core/src/cli/commands/hygiene.ts:241-243`).
(`hygieneCommand`, `packages/core/src/cli/commands/hygiene.ts:250-252`).

## Selection: severity and known urgency, then age and identity

Expand Down Expand Up @@ -190,7 +190,7 @@ identity), the new finding carries the receipt only when the pairing is
unambiguous. In one run, exactly one disposition in force with that category
and path stops being detected, and exactly one new finding with them appears
(`if (prior.length === 1 && siblings.length === 1)`,
`packages/core/src/lib/hygiene.ts:1513`). Otherwise the new finding opens
`packages/core/src/lib/hygiene.ts:1538`). Otherwise the new finding opens
without one. Either way the old disposition does not suppress it. Entries
moved by hand carry no fingerprint, so they keep their earlier behaviour.

Expand All @@ -213,7 +213,7 @@ receipt (`keptInvalidity`, `packages/core/src/lib/hygiene.ts:998-1008`).

Sync's count and review use one read-only function that applies these
predicates to the log as it stands rather than trusting the file an entry sits
in (K2 B; `mediaReviewCounts`, `packages/core/src/lib/hygiene.ts:1753-1768`).
in (K2 B; `mediaReviewCounts`, `packages/core/src/lib/hygiene.ts:1778-1793`).
Leave pending is a per-pass deferral in review state, never a log state: it
skips the finding while its fingerprint holds, and the finding still counts.

Expand Down Expand Up @@ -243,6 +243,18 @@ what the effect wrote, so a later edit is never overwritten and the outcome is
No all-file atomicity is claimed. The contract is in
[media review effects](../integration-contract/package-api.md#media-review-effects-additive-2781).

**Undo from review (#2781, maintainer ruling 2026-11-03).** A confirmed media
effect resolves its card, and a resolved card takes no option. So review
reaches Undo through a review command, `{ operation: "undo-media", journalId }`,
instead of keeping the card open ("applied · Undo available") until the next
selection. That keeps the resolved lifecycle, and the Undo stays bound to the
receipt's journal. It runs the CLI Undo's preflights. The card keeps its
resolved status and gets the Undo's receipt, and the restored finding returns
on a new card, never the old one. Undoing Keep a permanent copy also removes
its `kept` entry after the copy and config are restored (rev 5 §5.7,
`brain hygiene unkeep`), so the original is pending again rather than
reopened as `copy-missing`.

## A disposition is not a repair or an authority grant

Dismiss and Snooze do not change the document, acknowledge a successful repair
Expand All @@ -253,7 +265,7 @@ permission, premise revalidation and a real post-apply check before success.

Do not implement dismissal by marking a still-detected finding resolved: existing
reconciliation reopens such an entry (`const prev = field(entry, "resolved-by")`,
`packages/core/src/lib/hygiene.ts:1487-1490`). Keep review disposition distinct from
`packages/core/src/lib/hygiene.ts:1512-1515`). Keep review disposition distinct from
actual check success and from notification acknowledgement.

Markdown remains authoritative for findings, dispositions and confirmed content
Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/mechanical-hygiene.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ one explicit providerless CLI planner/apply operation
for this supported grammar, with `--json` and dry-run output, followed by the
existing reconciliation. Re-read every consulted input and use the existing
unchanged-source writer (`replaceIfUnchanged`,
`packages/core/src/lib/hygiene.ts:1236-1246`) before application. Keep registry
`packages/core/src/lib/hygiene.ts:1246-1256`) before application. Keep registry
ownership, inbox/archive exclusions and all unhandled cases visible as log-only.
The skill delegates these two mechanical operations; canonical judgment remains
with it. That follow-up needs the additive contract documentation and normal
Expand Down
1 change: 1 addition & 0 deletions docs/integration-contract/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ resumption. The host must retain a successful complete export at least every
| `brain hygiene dismiss <id> --expect-fingerprint <fp> [--reason <text>] [--extra <file.json>] --json` | `{ "status": "dismissed", "id", "fingerprint", "until": null, "reason", "changedFiles" }`. Reconciles, then moves the finding to `context/hygiene/dismissed.md` with the date and the fingerprint it applies to; it stays out of review until its evidence fingerprint changes. Refused with exit `1` and nothing written when the finding is not detected now or its fingerprint is not `<fp>`: `{ "status": "refused", "reason": "not-detected"\|"stale-fingerprint", "id", "expectedFingerprint", "currentFingerprint" }`. A finding reported through `reconcile --extra` is detected only when the same `--extra` file is given. A malformed argument exits `1` as a usage error (additive in 0.41.0) |
| `brain hygiene snooze <id> --until <date\|date-time> --expect-fingerprint <fp> [--reason <text>] [--extra <file.json>] --json` | As `dismiss`, with `"status": "snoozed"` and `"until"` as given, into `context/hygiene/snoozed.md`. `--until` is an ISO date (due at the start of that UTC day) or a date-time with `Z` or an offset (due at that instant), and must be in the future. The finding returns when due, or before then as soon as its fingerprint changes (additive in 0.41.0) |
| `brain hygiene keep-copy <id> --expect-fingerprint <fp> --copy <path> --copy-sha256 <sha256> --journal <id> [--reason <text>] --json` | Additive in 0.45.0 (#2780). As `dismiss`, with `"status": "kept"` and `"copy"`, `"copySha256"` and `"journal"` appended, into `context/hygiene/kept.md` (created by its first entry) with `kept-on:`, `copy:`, `copy-sha256:`, `journal:` and `disposition-fingerprint:`. Keep a permanent copy runs it after making and verifying the copy. Refused with exit `1` and nothing written, besides `dismiss`'s reasons, as `"not-media"` (not a `media` finding), `"copy-missing"` (not a contained regular file outside `.brain/` and `workspaces/`), `"copy-untracked"` (`media.track` does not keep it) or `"copy-changed"` (its bytes are not `<sha256>`) |
| `brain hygiene unkeep <id> --journal <id> --json` | Additive in 0.45.0 (#2781). Reconcile, then remove the `kept` entry that `keep-copy` recorded for `<id>` under that journal ID: Undo of Keep a permanent copy runs it after the copy and config are restored. The original returns to `open.md` without its disposition fields and without an `invalidated:` receipt (or to `resolved.md` as `original-pruned` when it is no longer detected). `{ "status": "unkept", "id", "journal", "changedFiles" }`. Refused with exit `1` and nothing written as `{ "status": "refused", "reason": "not-kept", "id", "journal" }` when no kept entry for `<id>` carries that journal |
| `brain hygiene media <delete\|move\|persist\|keep-copy> <id> --expect-fingerprint <fp> [--to <path>] (--dry-run \| --expect-premise <digest> --journal <id>) --json` | Additive in 0.45.0 (#2781). A media finding's effect. `--dry-run` plans it and writes nothing: `{ "status": "preview", "id", "action", "fingerprint", "source": { "path", "sha256", "bytes", "kind": "content"\|"scratch"\|"share-staged" }, "destination", "links": { "state": "linked"\|"unlinked"\|"unknown", "conversations" }, "references": { "complete", "count" }, "rewrites": [{ "note", "line", "kind", "before", "after" }], "blockers": [{ "note", "line", "kind", "target" }], "configDiff": { "path", "track": { "before", "after" }, "ignore": { "before", "after" } }\|null, "captureBytes", "copy": { "bytes", "sha256", "diskFreeAdvisory" }\|null, "resultClass": "TRACK"\|"ARTIFACT"\|null, "files": [{ "path", "role": "source"\|"destination"\|"note"\|"config"\|"directory", "before", "after", "bytes" }], "premiseDigest", "refusals": [{ "code", "path"?, "line"?, "limit"?, "effective"?, "observed"? }] }`. `files` is every file the effect writes, in apply order, with its expected SHA-256 before and after (`null` absent, `"directory"` for a created folder); it is empty when anything refuses. `move` and `keep-copy` need `--to`. A named refusal is a result, never an error: `share-staged`, `not-final-location` (scratch for `persist`, or a destination under `.brain/`, `workspaces/`, `.git/` or `context/hygiene/`), `pinned-scratch`, `pins-unknown`, `not-linked-scratch`, `destination-required`, `not-contained`, `exists`, `name-collision` (a sibling equal under NFC and case folding), `secret-name`, `ref-unsupported` (a frontmatter or HTML reference a Move cannot rewrite), `not-expressible` (no exact `media.track` form: a root-level name or a `*`), `ignore-adjustment-required` (an ignore entry other than this exact path matches), `config-not-literal`, `config-invalid`, `inventory-too-large` (with `limit` `rewrittenNotes` or `preview`, or the scan's own) and `inventory-unscannable`. A finding not detected now exits `1` with `{ "status": "refused", "reason": "not-detected" }`, one whose fingerprint is not `<fp>` with `"status": "stale"`. Apply recomputes the plan and writes only when its `premiseDigest` equals `<digest>`, otherwise `"status": "stale"` with nothing written; it returns `{ "status": "applied"\|"stale"\|"refused"\|"interrupted", "id", "action", "journal", "reason"?, "refusals"?, "files": [{ ...file, "state": "created"\|"changed"\|"removed"\|"unchanged" }], "copySha256"? }`. The caller (`--journal`) must retain every listed pre-image first and compensates from it: this command never compensates, and `interrupted` names what it wrote before a step failed. Move is `link` then `unlink` and never overwrites; across file systems it refuses `exdev`. A copy streams into a private `.part` beside the destination and publishes it with `link`. `persist` and `keep-copy` splice the exact `media.track` entry (removing an exact `media.ignore` of the same path) into a literal `brain.config`, parsed as syntax and never evaluated, then verify the written lists and that the file classes `TRACK`. `keep-copy` does not record the kept entry; `brain hygiene keep-copy` does, after the caller verifies the copy. Linux only for apply (`platform-unsupported`) |
| `brain travel validate --json` | `{ "validation": { "valid": boolean, "files": number, "issues": [{ "file", "level": "error", "message" }] } }` — read-only canonical format, reference and asset checks. `files` counts successfully parsed travel/trip/place documents. Exit `0` when valid, `1` on domain errors. File paths are root-relative; messages are prose |
| `brain travel migrate [--dry-run] --json` | `{ "migration": { "path", "changed": boolean, "dry_run": boolean } }` — `path` is `brain.config.ts` or `brain.config.json`; `changed` reports the proposed edit even during dry run. Reapplication reports false without a write. Refusals exit `1` with actionable stderr and no success envelope |
Expand Down
Loading
Loading