Skip to content

Build graph: labels, action cache, build/query/explain, normalize rule - #6

Merged
ninjudd merged 2 commits into
mainfrom
feat/build-graph
Aug 5, 2026
Merged

ninjudd merged 2 commits into
mainfrom
feat/build-graph

Conversation

@ninjudd

@ninjudd ninjudd commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Chunk 3 of 3 for project-core — the phase's §4 definition of done now runs end to end:

bloom init && bloom song create opener
bloom import hello.wav --song opener --name hello
# declare a normalize target in songs/opener/targets.yaml
bloom build //songs/opener/targets:hello-96k   # built  → .bloom/out/…/hello-96k.wav
bloom build //songs/opener/targets:hello-96k   # cached (action-cache hit, nothing executed)
bloom query 'deps(//songs/opener/targets:hello-96k)'
bloom explain //songs/opener/targets:hello-96k # rule, inputs, action key, cache status

(afinfo confirms the materialized output really is 96 kHz / 24-bit.)

Design, per the settled decisions

  • Labels (§3.4): targets derive from the model by convention — entity files (tracks/drums.yaml → //songs/creek/tracks:drums) take their directory as package; collection files (assets.yaml, new targets.yaml) take dir + stem, so entries become //songs/creek/assets:pad / //songs/creek/targets:pad-96k. Grammar: //pkg:name, //pkg:all, //pkg/..., absolute-only. No BUILD files.
  • Action cache (§3.5): CAS at .bloom/cache/cas/<sha256>, action index keyed by sha256 of canonical JSON {rule, rule_version, inputs, parameters, project_sample_rate}. The action entry is written last (crash window re-runs, never corrupts — the lesson from Asset store: assets.yaml, bloom import, content verification in check #5 applied from the start). Cache hits require CAS presence, so a wiped CAS re-runs cleanly.
  • First rule: normalize via afconvert, rule_version: 1, runner injectable so tests count executions.
  • §7 deferral lands: validate now requires asset file paths in normalized form, closing the ./audio/x.wav spelling class entirely.
  • Rule targets declared in songs/<song>/targets.yaml — the seed of the future mix file, not a BUILD file: it declares renders, structure stays derived.

Tests

64 passing (13 new): label grammar (incl. //songs//creek rejection), cache-hit/param-change/rebuild against a counting runner, wildcard expansion, invalid-project refusal, unmatched patterns, deps ordering, explain before/after build, and one real-afconvert integration test (CI is macos-latest, so afconvert exists there).

Scope note

bloom test and bloom prepare from the brief remain out of scope for project-core, as does building anything audible beyond format conversion — that's mix-assembly after sc-render. With this PR, sc-render only has to add a build rule.


Note

Medium Risk
New build pipeline writes cache artifacts and shells out to afconvert on macOS; invalid projects are blocked before build, but cache/CAS correctness affects reproducibility of outputs.

Overview
Completes project-core chunk 3: a real dependency graph with caching and CLI surface, so later phases only add rules—not a build system.

Labels & graph — //pkg:name grammar with //pkg:all and //pkg/... wildcards; assets and targets.yaml entries become graph nodes with asset→rule edges. bloom build, bloom query (patterns or deps(...)), and bloom explain refuse invalid projects (same gate as bloom check).

Action cache — Outputs in .bloom/cache/cas/<sha256>; keys from canonical JSON of rule version, input hashes, parameters, and project sample rate. Hits materialize to .bloom/out/...; action index written last so partial crashes re-run safely.

Normalize rule — First executable rule via afconvert, with injectable runner for tests. targets.yaml schema (discriminated normalize targets) plus validation for duplicate names and asset references.

Validation — Asset file paths must be POSIX-normalized (closes deferred §7 tightening from #5).

Reviewed by Cursor Bugbot for commit b08f138. Configure here.

The final project-core chunk. Targets derive from the project model by
convention (§3.4): assets.yaml entries are //songs/<song>/assets:<name>,
and a new songs/<song>/targets.yaml declares rule targets as
//songs/<song>/targets:<name>. Label grammar supports //pkg:name,
//pkg:all, and //pkg/... wildcards, absolute-only.

The action cache implements §3.5: outputs in .bloom/cache/cas/<sha256>,
an action index keyed by the hash of canonical JSON {rule, rule_version,
input hashes, parameters, project sample rate}, and the action entry
written last so a crash window re-runs rather than corrupts. Outputs
materialize under .bloom/out/<pkg>/<name>.wav for human ears.

First real rule: normalize (afconvert, sample-rate/bit-depth conversion),
with the runner injectable for tests. bloom build expands patterns and
builds in dependency order; bloom query handles patterns and deps();
bloom explain shows rule, inputs, parameters, action key, and cache
status. Also lands §7's deferred normalized-form requirement for asset
file paths.

64 tests passing (13 new). The §4 definition-of-done flow verified end to
end: build, cache hit on rebuild, rebuild on parameter change, honest
query/explain.

@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 high 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 b08f138. Configure here.

Comment thread src/graph/build.ts Resolved

@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 head b08f138 (local checkout matches). Typecheck clean, all 64 tests pass on Node 24 including the real-afconvert integration test; CI's test job is green. The architecture is faithful to the settled decisions: labels derive from the model with no BUILD files (§3.4), the action key is canonical JSON of exactly the §3.5 tuple, the CAS write goes through tmp+rename with the action entry last (the #5 lesson applied), the runner injection makes cache behavior properly testable, and canonicalJson is genuinely deterministic. §7's normalization requirement landing here closes that thread, and the docs status update is accurate.

Four findings, each confirmed by executing a repro against this head — one P2 and three P3s, inline:

  1. P2 — the action cache can be silently poisoned: build keys actions by the declared input hash but feeds the rule the actual file bytes. A transient tamper before first build leaves a permanently wrong cache entry that survives restoring the file — check goes green, build reports cached, explain vouches for it. Inline on src/graph/build.ts.
  2. P3 — a corrupt action entry (e.g. a crash mid-writeFileSync, which is not atomic) crashes every subsequent build with a JSON parse error instead of re-running. Inline on src/graph/build.ts.
  3. P3 — the everything-pattern spelling is inverted: //... errors while ///... works (and the test enshrines the latter). Inline on src/labels.ts.
  4. P3 — an asset or target named all passes check but is shadowed by the :all wildcard: unaddressable individually, silently swept into package expansion. Inline on src/model/project.ts.

With the P2 fixed this completes the phase's §4 definition of done honestly — the whole point of explain is that its answers can be trusted, which is exactly what finding 1 breaks. Merging is Justin's checkpoint as always.

Comment thread src/graph/build.ts Resolved
Comment thread src/graph/build.ts Resolved
Comment thread src/labels.ts Resolved
Comment thread src/model/project.ts Resolved
- build now verifies consumed input bytes against their declaration (size,
  then hash) before executing a rule, refusing with a pointer to bloom
  check on mismatch — the action key is the declared hash, so executing on
  disagreeing bytes would cache a poisoned output under the clean key
- a corrupt action entry (crash mid-write) is a cache miss that removes
  itself and re-runs, not a wedged cache; entries are now written
  tmp+rename so they appear atomically
- //... is the everything pattern; ///... is now an invalid package
- "all" is reserved wherever a name becomes addressable: schema-level
  (assets, targets, tracks) plus early rejection in import and track
  create

67 tests passing (3 new, 2 extended).

@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.

Verified e4973d3 (local checkout matches; typecheck clean, all 67 tests pass on Node 24; CI test job green on this head; all 5 threads resolved). I re-ran every repro from the review against this head:

  • Cache poisoning: closed in both variants — a different-size tamper is refused with the size message, a same-size tamper with the sha256 message, the counting runner stays at 0 executions (nothing poisoned), and the clean rebuild after restore produces the right bytes. Verifying only consumed inputs, only on the execute path, is exactly the right cost placement.
  • Corrupt action entry: now a self-repairing miss — the truncated entry is removed, the rule re-runs once, and the rewritten entry serves a hit on the next build. writeAction's tmp+rename makes the commit-message claim true this time.
  • //...: works as the everything pattern; ///... is now an invalid package, and the test asserts the correct spelling.
  • all reserved: rejected at all three layers — import --name all, track create all, and a hand-written name: all in assets.yaml gets a schema diagnostic with the path. Owning the constant in the label-grammar module is the right dependency direction.

Nothing further from my side. With this, project-core's §4 definition of done stands honestly end to end — PR #6 and the phase are ready for Justin's merge.

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