Skip to content

bloom export: build a label, put a versioned file where a human works - #39

Merged
ninjudd merged 5 commits into
mainfrom
feat/export
Aug 7, 2026
Merged

ninjudd merged 5 commits into
mainfrom
feat/export

Conversation

@ninjudd

@ninjudd ninjudd commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

Same syntax as build; the result lands on ~/Desktop as a numbered
version. Captured against a clone of field (--to a scratch directory,
rewritten here to ~/Desktop):

$ bloom export creek
exported //songs/creek/mix:main → ~/Desktop/creek-mix-main-v1.wav

# nudge the keys fader
$ bloom export creek
exported //songs/creek/mix:main → ~/Desktop/creek-mix-main-v2.wav

# export again, having changed nothing
$ bloom export creek
current  //songs/creek/mix:main → ~/Desktop/creek-mix-main-v2.wav

# put the fader back where it was
$ bloom export creek
reverted //songs/creek/mix:main → ~/Desktop/creek-mix-main-v1.wav (v2 is newer and different)

--to <dir> sends them elsewhere.

Why

Outputs live under their content hash and materialize at
.bloom/out/<label>.wav. That is the right address for the engine and a
useless one in a Finder window or an email attachment — this is the one
command whose product is a file you take somewhere else.

Decisions worth reviewing

Versioned, never overwritten. Finishing something and putting it
somewhere is how people mark a version, and the previous one is often
the only copy of a decision later undone. Numbering is max + 1 over
what is already there — a gap means someone threw that version away, and
minting a second -v2 would disagree with them. Nothing in the
destination is ever removed or overwritten, including files this command
did not write (pinned by a test that puts a hand-bounced
creek-sounds-pad-normalized-v1.wav in the way and checks it survives
byte-for-byte).

Re-exporting is a no-op, against every version — not just the
newest.
The reverted line above is the case that motivates it:
export v1, change something, export v2, change it back. Those bytes are
v1 again; filing them as v3 buries that, and a silent no-op would leave
the newest file on disk not being what you just built. So the result
names the version the bytes are and the version that is still newest.

The long name, always. creek-mix-main rather than creek-main. The
short form reads better until a song has a track and a sound of the same
name — legal (the one-namespace rule covers sounds and assets, the
source: namespace) and the natural thing to do when a track plays one
sound — and then two different files want one name. Disambiguating only
on collision produced a name you could not predict without knowing the
rest of the project.

It exports what play would play, through resolvePlayables, so the
two commands cannot drift on which file a label means — and committed
sources (assets, chosen variants) export straight from the song with no
special case.

Only the labels the patterns match. A build prints its dependencies
because they are work it did; they are means, not products, and
bloom export creek scattering fifteen files across a Desktop would be
a bug that reads like a feature.

A missing destination is an error, not a mkdir. --to ~/Desktps is
a typo, and creating it would bury the mistake under something that
looks like success.

Cost

Searching every version costs a hash per candidate, so size is checked
first — a stat, not a read; a mix that differs audibly usually differs
in length. Same-size candidates are still hashed (a fader move keeps the
length), and a test pins that the filter cannot end the search early by
putting a same-size, different-content v2 in front of the real match.

Tests

18: the naming, the version scan (gaps, other labels, other extensions,
near-miss filenames), homeRelative (including that /Users/justinx is
not ~x), and the behaviours above end to end against a real built
project — each with an explicit --to so no test can write to a real
Desktop. pnpm typecheck exit 0, 282/282.

Branched off main, so it is independent of #38.

Outputs live under their content hash and materialize at
`.bloom/out/<label>.wav` — the right address for the engine and a useless
one in a Finder window or an email attachment. `bloom export` takes the
same patterns `build` takes, builds them, and copies each result to
`~/Desktop` under the name you would say out loud: `//songs/creek/mix:main`
becomes `creek-main.wav`, `//shared/assets:water` keeps `water.wav`, since
shared material has no song to name.

Three decisions worth stating.

It exports what `play` would play, through `resolvePlayables`, so the two
commands cannot drift on which file a label means — and so committed
sources (assets, chosen variants) export straight from the song, no
special case.

It exports only the labels the patterns match. A build prints its
dependencies because they are work it did; they are means, not products,
and `bloom export creek` putting fifteen files on a Desktop would be a
bug that reads as a feature.

A missing destination is an error, not a mkdir. `--to ~/Desktps` is a
typo, and creating it would bury the mistake under a directory that looks
like success.

Names need no sanitizing — labels are `[a-z0-9-]` by grammar — and
collide only where a song has two labels of the same name in different
packages. That is possible: the one-namespace rule (project-layout.md
§4.3) covers sounds and assets, the `source:` namespace, so a track may
share a sound's name. Both then take their package's scope into the name
and every other label in the run keeps its plain one.

Re-exporting overwrites and says `replaced` rather than accumulating
`creek-main-2.wav`; the two status words are the same width, so the
labels line up.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit cb93ffc. Configure here.

Comment thread src/commands/export.ts Resolved
Two changes from review of the first cut.

**Always the long name.** `//songs/creek/mix:main` exports as
`creek-mix-main-v1.wav`, not `creek-main.wav`, and shared material keeps
its shelf. The short form read better right up until a song has a track
and a sound of the same name — legal, since the one-namespace rule
covers sounds and assets, and the natural thing to do when a track plays
one sound — and then two different files want one name. Disambiguating
only on collision meant a name you could not predict without knowing the
rest of the project; a name that is always scoped is worth the extra
word.

**Exports are versioned, never overwritten.** Finishing something and
putting it somewhere is how people mark a version, and the previous one
is often the only copy of a decision later undone. A second export is
`-v2`, numbered from the highest already present — a gap means someone
threw that version away, and minting a second `-v2` would disagree with
them. Nothing in the destination is ever removed or overwritten,
including files this command did not write.

Re-exporting compares bytes against *every* existing version, newest
first, and writes nothing when one matches:

    exported //songs/creek/mix:main → ~/Desktop/creek-mix-main-v1.wav
    exported //songs/creek/mix:main → ~/Desktop/creek-mix-main-v2.wav
    current  //songs/creek/mix:main → ~/Desktop/creek-mix-main-v2.wav
    reverted //songs/creek/mix:main → ~/Desktop/creek-mix-main-v1.wav (v2 is newer and different)

The last line is the case worth the machinery: export v1, change
something, export v2, change it back. Those bytes are v1 again. Filing
them as v3 would bury that, and a silent no-op would leave the newest
file on disk not being what you just built — so it names the version the
bytes are and the version that is still newest.

Searching every version rather than just the newest costs a hash per
candidate, so size is checked first (a stat, not a read): a mix that
differs audibly usually differs in length. Same-size candidates are
still hashed — a fader move keeps the length — and a test pins that the
filter cannot end the search early.
@ninjudd ninjudd changed the title bloom export: build a label, put the file somewhere a human works bloom export: build a label, put a versioned file where a human works Aug 7, 2026

@ninjudd ninjudd left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 930108c. Design reads well and the reasoning in the PR body holds up — versioning over overwriting, the long name, matching against every version rather than the newest, refusing to mkdir a typo'd destination. I verified the 18 tests and the full suite green on Node 24 (259 passed | 23 skipped, tsc --noEmit exit 0) in a scratch clone.

Two findings break invariants this PR states explicitly, and both are confirmed by running the code rather than reading it. Details inline; summary here.

P1 — a file differing only in case is silently overwritten. existingVersions matches case-sensitively; copyFileSync overwrites case-insensitively. On APFS (default, and the default destination is ~/Desktop) a hand-bounced Creek-Assets-Pad-v1.wav is destroyed in place — the directory listing still shows their filename, holding our bytes. This is exactly the scenario "never touches a file it did not write" pins; that test passes only because its fixture happens to use the same case.

P2 — a committed source that drifted from its declared hash exports as current. For asset and generation targets item.sha256 is the declared hash, which the build trusts without checking (src/graph/build.ts:153-155 — "check verifies content, the build system trusts the declaration"). Export compares candidates' real bytes against that declaration, so a bounced-over pad.wav reports current → creek-assets-pad-v1.wav while v1 holds different audio. Note the asymmetry: the same drift makes bloom build refuse when the asset is an input (build.ts:230-234), and this is the command whose product leaves the system.

P2 — the copy is not atomic. copyFileSync writes in place at the final name. Ctrl-C or ENOSPC mid-copy leaves a truncated -vN.wav that, because nothing is ever overwritten, is permanent — and poisons the family forever after: it is "newest and different", so every later export of matching bytes reports reverted (vN is newer and different). materialize already established copy-to-temp + rename for the analogous hazard (build.ts:194-204).

One fix covers the first and third: copy to ${to}.tmp-${process.pid} in the destination, then linkSync(tmp, to) and unlink the temp. linkSync is atomic and fails EEXIST on an existing destination, including a case-differing one — I checked both on APFS. (copyFileSync(..., constants.COPYFILE_EXCL) also refuses the case-differing name, if you'd rather not carry a temp file, but it leaves the atomicity gap.)

P3 — the doc paragraph describes different behaviour than the code. Non-blocking; noted inline.

Nothing else to flag. The bases collision guard is right to be an error, the size pre-filter is correctly pinned as unable to end the search early, and homeRelative's /Users/justinx case is a nice catch to have tested.

Comment thread src/commands/export.ts Resolved
Comment thread src/commands/export.ts Resolved
Comment thread docs/build-graph.md Resolved
Three findings from the #39 review, all reproduced before fixing.

**A file differing only in case was silently destroyed.** The version
scan matched case-sensitively while APFS resolves case-insensitively, so
someone's `Creek-Mix-Main-v1.wav` was invisible to the scan and then
became our bytes *under their filename* — a directory listing does not
even change. Confirmed on this machine: copyFileSync onto the lowercase
name left one file, holding our content, still called theirs.

Writes now go to a temp name in the destination and `link` into place.
`link` fails EEXIST rather than truncating, including on a name that
differs only in case, and the next version number is taken. The scan is
also case-insensitive now — not for safety, which the link already
gives, but for truthfulness: their v5 must count as 5, or our next
export writes a "v1" that is newer in time than a v5 sitting beside it.

**The same change makes a version complete or absent.** An interrupted
copy left a truncated `-vN.wav`, and since nothing is ever overwritten
that file was permanent: forever "newest and different", so every later
matching export would report `reverted`. Now an interrupt leaves debris
under a dotted `.part-<pid>` name that no scan matches.

**A drifted committed source exported as `current`.** For assets and
chosen variants the recorded hash is the *declared* one, which the build
deliberately trusts and only verifies when consuming the file as an
input. So a bounce written over pad.wav without re-importing compared
equal to the previous export, and the command said `current` while the
exported file was different audio from the project's. Export now hashes
what it is about to copy and refuses when a committed source disagrees
with its declaration — the guard build applies to inputs, on the command
whose product leaves the machine. Playable gained `committed` to say
which items carry a declared hash; typecheck caught the one hand-built
Playable in click.test.ts, as it did in #35.

Each fix has a test that fails without it, checked by reverting them one
at a time. The case test alone did not isolate the scan (the link guard
also saves the file), so there is a second test for the numbering.

Docs: the paragraph said bytes are compared against the newest version
when the code compares every version, and never mentioned `reverted`.
Rewritten, including the two new guarantees. A citation I had drafted
for project-core.md §3.5 turned out to be the cache-key decision, not
the tamper guard, so it is described rather than cited.
Comment thread src/commands/export.ts Resolved
@ninjudd

ninjudd commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Re-reviewed at f66756b. All three fixes verified against the running code, not just read — and the reasoning you added is sound in the places it corrects my framing.

P1, case-clobber — fixed and confirmed. Copy-to-dotted-temp plus linkSync gives both properties, and the temp name (.<base>-v<n>.wav.part-<pid>) is unmatched by the version scan, so abandoned debris cannot be mistaken for a version. MAX_VERSION_PROBES bounding the probe loop is a good call.

Your A/B on the scan reverts correctly, and I confirmed it. Reverting the 'i' flag alone leaves never writes through a name that differs only in case passing — the link guard does carry it — and fails counts case-differing versions when numbering with expected 1 to be 6. The truthfulness argument is the right justification: a v1 written beside a Creek-…-v5.wav makes the family read backwards. Better than the reason either of us started with.

P2, drift — fixed, and refusing is the right call. Exporting drifted bytes as a new version would have put a file on someone's Desktop that nothing in the project describes, which is the failure this command can least afford. The committed flag is the right shape: it marks declared vs measured, so the distinction lives on the type rather than in a comment someone has to remember. Docs sentence "the same guard build applies before consuming an asset as an input" checks out against build.ts:230-234.

Citation call was right. I verified project-core.md §3.5 — it is "Cache key definition (DECIDED)", the SHA-256/action-key decision, with no tamper guard in it. Describing rather than citing was correct.

Verified locally on Node 24: tsc --noEmit clean, 265 passed | 23 skipped (288), and each of the three new behaviours fails without its fix.

One new finding inline: the drift refusal fires inside the export loop, so a multi-label run can leave a correct file on the Desktop and print only an error. P3, and single-label export is unaffected.


Two things blocking this that are not about the code

This PR now conflicts with main, and that is why CI has not run. #38 landed on main (3403bbc) at 02:41; f66756b was pushed at 03:24. GitHub reports mergeable: CONFLICTING, and there are zero workflow runs for f66756b — check-runs total 0, statusCheckRollup empty, no run in gh run list. The workflow is pull_request-triggered, and a conflicting PR has no merge ref to build, so it was never scheduled. The last green CI on this branch is 930108c — the pre-fix head. So CI is not running, and nothing has validated this commit on CI.

Resolving the conflict textually is not enough — it leaves a type error. The conflict is in click.test.ts, the same hand-built Playable call site you mentioned. #38 added a second one in its new re-hashes: sha256 describes the clicked file, not the source test, and that literal has no committed:

src/commands/click.test.ts(87,44): error TS2345:
  Property 'committed' is missing in type '{ label; pkg; path; sha256 }'
  but required in type 'Playable'.

I merged realmain into f66756b in a throwaway clone to check. Adding committed: false to that second literal as well is the whole fix — with both, the merge is clean: typecheck silent, 277 passed | 23 skipped (300).

Worth noting the pattern: this call site has now broken in #35, in this PR, and again on the merge. A Playable factory for tests, or defaulting committed to false, would stop it being a recurring merge hazard — though not something this PR needs to take on.

Nothing else outstanding from my side. Still yours to merge.

ninjudd added 2 commits August 6, 2026 20:35
The drift check ran per item inside the write loop while the name-
collision guard was hoisted above it, so a multi-label run could land a
correct file and then throw — a file on the Desktop with only an error
on screen, which is worse than either outcome alone: the thing you can
see disagrees with the thing you were told (#39 review P3).

Both checks now run in one pass before anything is written. They reject
the request, not one item of it, so that is where they belong. The hash
each item is verified with is carried forward to the write loop, so this
is a reordering rather than extra work.

The test exports a clean asset and a drifted one in the same run and
asserts the destination is untouched; it fails with the check back
inside the write loop.
One conflict, in the hand-built Playables in click.test.ts. #38 taught
withClick to re-hash, dropping the stale "carries it through untouched"
comment; this branch made `committed` required. The resolution takes
both, and adds the field to the re-hashes test #38 introduced — which
the merge would otherwise have left as a type error the branch's own CI
never saw, because a conflicting PR has no merge ref to build.

That call site has now needed the same edit three times (#35, this PR,
this merge). A test Playable factory would end it; noted for a follow-up
rather than smuggled in here.
@ninjudd

ninjudd commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

Verified at d2a04dd. Nothing outstanding from my side.

P3 fixed and confirmed. b1ff2d9 hoists both refusals into one pre-flight pass, collecting verified before the write loop starts — so the collision guard and the drift guard now share the property, rather than one having it and one not. Re-ran my reproduction from the last round (two assets, only the second drifted, one recursive pattern): the destination that previously held creek-assets-aaa-first-v1.wav is now [].

The merge resolution is right. Both hand-built Playable literals in click.test.ts carry committed: false (lines 74 and 92), including the one #38 added.

CI genuinely ran this time. check-runs total 1, test: success at d2a04dd — the rollup confirms it positively rather than by absence, which is the distinction that mattered. Branch contains current main, and mergeable: MERGEABLE.

Independent verification on Node 24 at this head: tsc --noEmit clean, 278 passed | 23 skipped (301).

All five threads resolved. Ready for you.

@ninjudd
ninjudd merged commit 5c4ddde into main Aug 7, 2026
1 check passed
ninjudd added a commit that referenced this pull request Aug 7, 2026
…it (#40)

Hand-built `Playable` literals in tests have broken three times running,
each time in a way the usual signals missed:

- `sha256` in #35 — invisible to vitest (which does not typecheck) and
  to `pnpm build` (which excludes tests), so every signal was green.
- `committed` in #39.
- Again merging #38 into #39: the re-hashes test #38 added needed the
  field too, a type error neither branch's own CI could see, because a
  conflicting pull request has no merge ref to build.

`playable({ path })` fills every required field. The two call sites in
`click.test.ts` use it.

### The property, verified rather than assumed

I added a temporary required field to `Playable` and checked who breaks:

```
before updating the factory:   src/commands/play.ts, src/testing/playable.ts
after updating only the factory: src/commands/play.ts
```

`play.ts` is real code and has to change anyway. No test file does.

### Two small decisions

`path` has no default. A Playable's job is to name a file, and
defaulting it would turn a missing fixture into an ENOENT somewhere far
away instead of a compile error at the call site.

The helper lives in `src/testing/` and is excluded from
`tsconfig.build.json`, so it does not ship in `dist`. `*.test.ts` was
the only exclusion before; a helper that is not itself a test needed its
own.

`pnpm typecheck` exit 0, 301/301. Built in a git worktree off `main`, so
the shared checkout — whose `dist` the global `bloom` symlinks into —
was never switched or rebuilt.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> Test-only helper and test refactors; no production runtime behavior
changes.
> 
> **Overview**
> Adds **`playable()`** in `src/testing/playable.ts` so tests can build
a full **`Playable`** with defaults for `label`, `pkg`, `sha256`, and
`committed`, while **`path` stays required** at the call site.
> 
> **`click.test.ts`** now uses `playable({ path: src })` (and overrides
`sha256` in the re-hash test) instead of hand-written literals.
> 
> **`tsconfig.build.json`** excludes **`src/testing/**`** so the helper
is not emitted to **`dist`** alongside test files.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
f3a353e. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
@ninjudd
ninjudd deleted the feat/export branch September 28, 2026 04:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant