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
13 changes: 13 additions & 0 deletions .changeset/media-config-broader-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"@schlessera/brain": minor
"@schlessera/brain-ui-sdk": minor
"@schlessera/brain-ui-server": minor
---

The media lists in `brain.config` can now be changed one entry at a time (#2781). `brain config media <add-track|remove-track|add-ignore|remove-ignore> <pattern> --dry-run --json` previews the change: the diff, the files sync sees now that the pattern matches (count, bytes, the five largest, which an ignore entry still wins over, which are secret-shaped), and an approval digest. Applying it with `--expect-sha <sha256>` from that preview, and optionally `--expect-approval <digest>`, splices only that entry into a literal config, without running it, and refuses `stale` or `stale-approval` with nothing written when the config or its matches changed.

Persist here can track a file by a broader rule. `brain hygiene media persist <id> --pattern <glob>` (and `keep-copy … --pattern`) adds that `media.track` rule instead of the exact path, and `--ignore-adjust <entry>` removes the one broader `media.ignore` entry that would still win. The preview adds `scope`, `pattern`, `ignoreAdjust`, `matches` and `approvalDigest`; apply needs `--expect-approval` back. Exact changes are unchanged and need no approval. Several conflicting ignore entries are still refused, now each named.

Hygiene review offers *Persist with a broader rule…* on a media card that is not in scratch or staged by a share, previewed with the rule as its input. A copy destination under one broader ignore is previewed with that ignore removed and the files it stops ignoring. Only the principal who previewed a broader change can confirm it; anyone else gets `stale-approval`.

The UI SDK adds `HygieneMediaMatches` and `hygieneMediaMatchesSchema`, the optional `scope`, `pattern`, `ignoreAdjust`, `matches` and `approvalDigest` on `HygieneMediaPlan`, and `approvedBy` on `HygieneEffect`.
638 changes: 638 additions & 0 deletions api-report/ui-sdk.txt

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,14 @@ characters, and a glob with no `/` also matches the file name alone.
media: { ignore: ["assets/renders/*"], track: ["me/*.jpg"] }
```

`brain config media <add-track|remove-track|add-ignore|remove-ignore>
<pattern>` changes one entry without running the config: it previews the
change with `--dry-run`, including the files sync sees now that the pattern
matches, then applies it with `--expect-sha` from that preview. It works only
when the lists are literal arrays in a directly exported object; anything
else is refused, for you to edit by hand
([cli.md](integration-contract/cli.md)).

## `sync`

How `brain sync` integrates remote commits and settles what git cannot: a
Expand Down
14 changes: 13 additions & 1 deletion 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:182-185`). 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:250-252`).
(`hygieneCommand`, `packages/core/src/cli/commands/hygiene.ts:257-259`).

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

Expand Down Expand Up @@ -255,6 +255,18 @@ 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`.

**Broader config changes (#2781, rev 3 §5.2-§5.4, rev 4 §7).** Persist here
tracks one exact path by default. A broader `media.track` rule, or removing
the one broader `media.ignore` entry that would still win (M1 A), changes how
sync treats other files too, now and later. So its preview lists the files
sync sees now that it matches, and the approval binds the config's bytes, the
exact diff and a digest of those matches. A config edited, or a file that
starts or stops matching, before apply makes the approval `stale-approval`.
The host binds the principal: only the person who previewed a broader change
can confirm it. Several conflicting ignore entries are never adjusted; they
are named, for the owner to edit. `brain config media` is the same edit
outside review, previewed and applied against the config's SHA-256.

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

Dismiss and Snooze do not change the document, acknowledge a successful repair
Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/managed-worktrees.md
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ selects undone copy.
Markdown findings and the host's by core's ordinal rules (severity, known
urgency, age, identity), and every operation that names a host finding goes to
the host, never to the CLI
(`async function cli(args`, `packages/ui-server/src/inbox/hygiene-review.ts:45-57`).
(`async function cli(args`, `packages/ui-server/src/inbox/hygiene-review.ts:46-58`).
A retained or failed worktree offers one repair, `delete-worktree`; an unknown
one offers none and stays kept and charged, and "check again" assesses it
afresh, after a failed removal too. Selection assesses its winner again before
Expand Down
3 changes: 2 additions & 1 deletion docs/integration-contract/cli.md

Large diffs are not rendered by default.

19 changes: 15 additions & 4 deletions docs/integration-contract/package-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1966,18 +1966,29 @@ Additive shapes in `@schlessera/brain-ui-sdk`:

| Surface | Change |
| --- | --- |
| `HygieneEffect.operation` | gains `media-delete`, `media-move`, `media-persist`, `media-keep-copy`; the effect may carry `destination` and `premiseDigest` |
| `InboxOption.media` | `HygieneMediaPlan`: the CLI plan (`action`, `premiseDigest`, `destination`, `files`, `captureBytes`, `links`, `references`, `rewrites`, `blockers`, `configDiff`, `copy`, `resultClass`, `refusals`) |
| `HygieneEffect.operation` | gains `media-delete`, `media-move`, `media-persist`, `media-keep-copy`; the effect may carry `destination`, `premiseDigest` and `approvedBy` (the principal who previewed a broader config change, below) |
| `InboxOption.media` | `HygieneMediaPlan`: the CLI plan (`action`, `premiseDigest`, `destination`, `files`, `captureBytes`, `links`, `references`, `rewrites`, `blockers`, `configDiff`, `copy`, `resultClass`, `refusals`), and optionally `scope` (`exact`\|`pattern`\|null), `pattern`, `ignoreAdjust`, `matches` (`{ track, ignore }` of `HygieneMediaMatches`) and `approvalDigest`, which a CLI before them omits |
| `HygieneMediaMatches`, `hygieneMediaMatchesSchema` | new (0.45.0): `{ pattern, anyFolder, count, bytes, changed, ignoredStill, sensitive, largest: [{ path, bytes, before, after }] (at most 5), digest }`, a list pattern's current matches among the files sync sees, with the class (`TRACK`\|`ARTIFACT`\|`SENSITIVE`\|null) the lists give each before and after |
| `HygieneAction.outcome.status` | gains `kept`, a confirmed Keep a permanent copy |
| `HygieneReviewMediaUndoCommand`, `HygieneReviewRequest` | new (0.45.0): `{ operation: "undo-media", journalId }`, Undo of a confirmed media effect from review (below); `HygieneReviewRequest` is it or the unchanged `HygieneReviewCommand`, parsed by the new `hygieneReviewMediaUndoCommandSchema` and `hygieneReviewRequestSchema`; `hygieneReviewCommandSchema` is unchanged |
| `HygieneReviewRead.mediaUndo` | `HygieneMediaReceipt`, on the `undo-media` response only (0.45.0) |
| `HygieneAction.outcome.media` | `HygieneMediaReceipt`: `{ journalId, action, outcome: "pending"\|"applied"\|"kept"\|"compensated"\|"partial"\|"refused"\|"stale"\|"undone", reason?, refusals?, files: [{ path, state: "created"\|"changed"\|"removed"\|"restored"\|"unchanged"\|"left-changed"\|"conflict" }], copySha256?, undo: { available, reason?, path? } }` |

A media finding's card offers Persist here, Move to a final location…, Keep a
A media finding's card offers Persist here, Persist with a broader rule…
(not for scratch or share-staged files), Move to a final location…, Keep a
permanent copy… (scratch only) and Delete…, before Leave pending. Persist and
Delete are planned when the card is prepared; Move and Keep a copy when a
destination is previewed (`POST /hygiene/review/preview` with the path as
`input`). A plan with refusals keeps them on the option and has no
`input`), and the broader rule (option `media-persist-rule`, effect
`media-persist`) when its `media.track` pattern is previewed as `input`.
When a previewed track entry would still lose to exactly one broader
`media.ignore` entry, the preview plans that ignore's removal too
(`ignoreAdjust`), with the files it stops ignoring in `matches.ignore`;
several such entries stay refused as `ignore-adjustment-required`. A plan
with an `approvalDigest` (a broader rule or ignore adjustment) records the
previewing principal as `effect.approvedBy`; confirming it as anyone else is
`stale` with reason `stale-approval`, and the CLI refuses the same reason
when the config, the diff or any match changed since. A plan with refusals keeps them on the option and has no
`premiseDigest`, so it cannot be confirmed. Confirming applies exactly the
previewed plan: an applied effect resolves the card as `fixed`, a kept copy
as `kept` (the review's `kept` counter); `stale` and `refused` leave it
Expand Down
6 changes: 3 additions & 3 deletions docs/integration-contract/wire.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ states that overlapping writable windows share observations. `observedAt`
names the retained window observation, not a guessed receipt time.
The type is defined by (`TurnJournalSummary`,
`packages/ui-sdk/src/turn-journal.ts:2-29`); validation uses
(`turnJournalSummarySchema`, `packages/ui-sdk/src/schemas.ts:1084-1102`).
(`turnJournalSummarySchema`, `packages/ui-sdk/src/schemas.ts:1097-1115`).
`actor` additionally accepts `user` for a server-recorded history operation.
Optional `kind` is `turn` or `revert`; a revert may name its original
`sourceTurnId`. These facts do not create an assistant message or an inference
Expand Down Expand Up @@ -131,8 +131,8 @@ previous observation rather than adding it. The frame never opens a message,
reopens run state or moves focus. Older clients may ignore it. The same optional
`budget` is retained on `TurnJournalSummary` and replayed with the existing
single below-turn disclosure. The additive types and validation are
(`ServerUsage`, `packages/ui-sdk/src/protocol.ts:4000-4006`) and
(`serverUsageSchema`, `packages/ui-sdk/src/schemas.ts:1938-1940`).
(`ServerUsage`, `packages/ui-sdk/src/protocol.ts:4200-4206`) and
(`serverUsageSchema`, `packages/ui-sdk/src/schemas.ts:1973-1975`).

Budget list-price inference cost is separate from the journal's billing-aware
`costUsd`. Unpriced totals remain null; known lower bounds, estimated rates,
Expand Down
7 changes: 7 additions & 0 deletions docs/media.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ A brain usually hits the pain well before those limits.
the file name alone. `ignore` wins over `track`, and a secret-shaped name is
never tracked, whatever `track` says. See
[configuration.md](configuration.md#media).

`brain config media add-track "me/*.jpg" --dry-run` previews one change to
these lists: the files it affects now, the largest first, and which an
`ignore` entry still wins over. Applying it with the preview's
`--expect-sha` edits only that entry and leaves every other byte of the
config as it was. In hygiene review, *Persist with a broader rule…* does the
same for one media file, and asks you to approve the rule with its matches.
- **The template's `.gitignore`** has a commented media section to start from.

## Git LFS for large masters
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/cli/brain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ function beforeTerminator(args: string[]): string[] {
// reports, and rewrites frontmatter only with --apply and no --dry-run;
// `brain hygiene` writes under `reconcile` without --dry-run, and under
// `dismiss` and `snooze`;
// `brain registry` rewrites index tables unless --check.
// `brain registry` rewrites index tables unless --check;
// `brain config media` edits the config unless --dry-run.
const MUTATING_WITH_FLAGS: Record<string, (args: string[]) => boolean> = {
config: (args) => args[0] === "media" && !args.includes("--dry-run"),
geo: (args) => args[0] === "map",
tags: (args) => args.includes("--apply") && !args.includes("--dry-run"),
hygiene: (args) => (args[0] === "reconcile" && !args.includes("--dry-run")) || args[0] === "dismiss" || args[0] === "snooze",
Expand Down
52 changes: 48 additions & 4 deletions packages/core/src/cli/commands/config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
import { relative, sep } from "path";

import type { CoreCommand, CliContext } from "../types.js";
import { emit, parseArgs, UsageError } from "../io.js";
import { mediaPolicy } from "../../lib/media.js";

const HELP = `brain config <check|get>
const HELP = `brain config <check|get|media>

check Validate the config and print the effective taxonomy summary
get <dotted.path> Print a resolved config value as JSON (used by skills)`;
get <dotted.path> Print a resolved config value as JSON (used by skills)
media <add-track|remove-track|add-ignore|remove-ignore> <pattern>
[--dry-run | --expect-sha <sha256> [--expect-approval <digest>]]
Change one media.track or media.ignore entry by a minimal
splice; the config is edited as syntax and never evaluated.
--dry-run previews: { "status": "preview", "op", "pattern",
"scope": "exact"|"pattern", "config": { "path", "sha256" },
"configDiff", "matches": { "pattern", "anyFolder", "count",
"bytes", "changed", "ignoredStill", "sensitive", "largest",
"digest" }, "approvalDigest", "refusals" }. Apply needs the
preview's config sha256, and with --expect-approval its
approvalDigest: { "status": "applied", "op", "pattern",
"config": { "path", "before", "after" }, "configDiff" }.
Otherwise { "status": "refused"|"stale", "op", "pattern",
"reason", "refusals" } and nothing is written; reasons are
stale, stale-approval, already-listed, not-listed,
not-expressible, invalid-pattern, config-not-literal and
config-invalid.`;

/** Effective-taxonomy summary for `config check`. */
function taxonomySummary(cli: CliContext): Record<string, unknown> {
Expand Down Expand Up @@ -62,7 +82,7 @@ export const configCommand: CoreCommand = {
summary: "Validate config / read effective taxonomy and config values",
helpBlock: HELP,
async run(args, cli): Promise<number | void> {
const { args: pos } = parseArgs(args);
const { args: pos, flags } = parseArgs(args);
const sub = pos[0];

if (sub === "check") {
Expand Down Expand Up @@ -102,6 +122,30 @@ export const configCommand: CoreCommand = {
return;
}

throw new UsageError("Usage: brain config <check|get>");
if (sub === "media") {
// Loaded only for this verb: the edit's dependencies stay out of every other one.
const { applyMediaConfigChange, MEDIA_CONFIG_OPS, planMediaConfigChange } = await import("../../lib/media-config.js");
const op = pos[1], pattern = pos[2];
if (!MEDIA_CONFIG_OPS.includes(op as (typeof MEDIA_CONFIG_OPS)[number]) || pattern === undefined || pos.length !== 3) {
throw new UsageError("Usage: brain config media <add-track|remove-track|add-ignore|remove-ignore> <pattern> [--dry-run | --expect-sha <sha256> [--expect-approval <digest>]]");
}
if (cli.configError) throw new UsageError(`Invalid brain.config: ${cli.configError}; no changes made`);
const configPath = cli.brain.configPath === null ? null : relative(cli.brain.root, cli.brain.configPath).split(sep).join("/");
const ctx = { root: cli.brain.root, policy: mediaPolicy(cli.brain.config), configPath };
const kind = op as (typeof MEDIA_CONFIG_OPS)[number];
let result;
if (flags["dry-run"] === true) result = planMediaConfigChange(ctx, kind, pattern);
else {
const sha = flags["expect-sha"], approval = flags["expect-approval"];
if (typeof sha !== "string" || (approval !== undefined && typeof approval !== "string")) {
throw new UsageError("Preview with --dry-run first, then apply with --expect-sha <config sha256> [--expect-approval <approvalDigest>]");
}
result = applyMediaConfigChange(ctx, kind, pattern, { sha256: sha, ...(typeof approval === "string" ? { approval } : {}) });
}
emit(cli.json, result, () => console.log(JSON.stringify(result, null, 2)));
return ["preview", "applied"].includes(result.status) ? 0 : 1;
}

throw new UsageError("Usage: brain config <check|get|media>");
},
};
Loading
Loading