Repository navigation
refactor: template laid out by app in three crates [ORB-27923] - #23
Open
danieljhkim wants to merge 1 commit into
Open
danieljhkim wants to merge 1 commit into
danieljhkim wants to merge 1 commit into
Conversation
Split the template into tmpl-cli -> tmpl-cli-core -> tmpl-cli-store, following the layout approved for scribe. - tmpl-cli: argument declarations, mapping to the app's Command, rendering. main captures the environment into the core's Env once. - tmpl-cli-core: apps/note (Command, Outcome, Error, exec, run, one flow per command, pure rules: next id, list selection), runtime (Ctx, the audit guard, shared errors), composition.rs (Env, data directory, store, clock), and a test-support feature exposing Ctx and run. - tmpl-cli-store: db/ (fsio, persisted format and upgrades, audit line, locks), repository/ (notes, audit), contracts/ (note and audit record shapes). No rule of the note app. No change to the CLI, help, goldens, exit codes, messages or on-disk format. Tests moved with their code; call sites changed where the API they called moved. The guard script, ARCHITECTURE.md and the design docs describe the new layout, with a decision superseding the two-crate and store-module decisions. The one wall-clock test runs alone under nextest. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Restructures the template into three crates laid out by app:
tmpl-cli -> tmpl-cli-core -> tmpl-cli-store, following the layout approved for scribe on 2026-11-24. Daniel's words: "can you also update rust-cli-template similarly? separate create for store. runtime, composition, apps in core."Behaviour is unchanged: the CLI, help, output goldens, exit codes, error messages and codes, the order on stderr, and the on-disk format are all the same. No golden changed.
What moved where
tmpl-cli(binary)app.rs->tmpl-cli-core/src/composition.rs(AppEnvis nowEnv, and holds--rootas well).audit_middleware.rs->tmpl-cli-core/src/runtime/audit.rs.commands/note.rsnow only maps arguments toapps::note::Command, callsapps::note::exec, and turns theOutcomeinto a payload (list_noticestays here).main.rscapturesEnv::from_process()once and passes it torun.CliError::CoreandCliError::NoDataDirbecomeCliError::Note(apps::note::Error), still through a single#[from].tmpl_cli_core: record shapes come fromtmpl_cli_core::contracts.tmpl-cli-coreapps/note/:mod.rs:Command,Outcome,Error(NotFound,IdExhausted,Runtime),exec,run, and the audited-command tableCommand::audit.add.rs,list.rs,show.rs: one flow per command.rules.rs: the oldquery.rsplusnext_id(wasNoteId::next_after) andNewNote::into_note.runtime/:Runtime,Ctx;errors.rs, the sharedError(NoDataDir,Store).composition.rs:Env, the data directory, theStore, the actor and the clock. It is the only place in the core that reads the environment.test_support.rs(featuretest-support): exposesCtxandnote_run.tmpl-cli-store(new)store.rs:Store::open,read() -> Snapshot,write(label, |tx| …),audit()(wasstore/mod.rs, minusadd/list/show).db/:fsio.rs,format.rs(the notes document andUPGRADES),audit.rs(the persisted audit line and its upgrades), and the file-name constants.repository/:Snapshot/Tx,notes(all,get,bad_records,bad_record,put),audit(append, wasStore::record_audit).contracts/:note.rs(was corenote.rs, withoutnext_afterandNewNote) andaudit.rs(AuditEvent,AuditStatus).error.rs: the storeError(minusNotFoundandIdExhausted, which moved to the note app) andBadRecord.Guards and docs
scripts/check-dependency-direction.sh:tmpl-cli-store;db/does I/O,db/fsioknows no records, andcontracts/has no db/repository imports, nocheck_*functions and no clock;std::envonly incomposition.rs,runtime/imports no app, noapps/common|shared|util, andrulesare pure;commands/reads no environment and opens no store;ARCHITECTURE.mdis rewritten.4_decisions.mdgains "The template is laid out by app in three crates". It marks "A domain library crate and a CLI crate" and "Persistence is one module inside the core crate" superseded, and updates the code anchors and adds update notes in the live decisions it touches.1_overview.md,2_design.md,specs/store.md,AGENTS.mdcode rules (the standards block is untouched), README/about ("three crates"), the Makefile doctest comment and therename-template.shheader are updated.CHANGELOG.mdis untouched (compiled at release).Departures from the target
exectakes afinishcallback:exec(env, command, finish)instead ofexec(env, command) -> Result<Outcome, Error>. The audit line has to be written after the payload or JSON error object is flushed.json_error_object_precedes_audit_failure_warning_on_stderrpins that order, and a plain return would drop the guard before rendering. This is recorded in the new decision.test-support. The core dev-depends on itself withfeatures = ["test-support"]sotests/note.rscan pin the clock and the lock wait. The binary's integration tests did not needrun/Ctx.Store::add/list/show,Context::with_store,commands::run_with,AuditGuard::mark_result(&Result<Output, CliError>)). Test names and assertions are kept:crates/tmpl-cli-core/tests/note.rs(wastests/store.rs): every test body is byte-identical. The header adds a smallNoteAppadapter trait onStorethat runs the app's commands throughnote_run. Fourmatches!patterns now unwrap the store error throughstore_error(&err), since store errors reach the app wrapped.the_next_id_is_one_past_the_highest_whatever_the_ordercallsnext_id(..)instead ofNoteId::next_after(..).only_note_add_is_auditedand the lock-timeout chokepoint test moved from the binary tocore/src/apps/note/tests/note.rs. They buildCommandvalues instead of parsing argv, and callrun_with(&ctx, …)with aCtx.runtime/tests/audit.rs) produce the outcome throughnote::runand passOk(target)/Err(code)tomark_result.tmpl-cli-store/src/tests/store.rs) write throughstore.writeandstore.audit().append.addflow refuses on its own read before any side effect (the STD-02 R34 ordering, and the same error precedence as before).Store::writerefuses again under the lock, since a rewrite would drop the bad records. I treat the second check as a store integrity guard, not a note rule.Outcome::Listedechoes theListFilter, so the binary can build the empty-result notice without keeping its own copy.Titledoctest moved withTitleto the store crate, so the core crate has no doctest now. The Makefile comment says so. No test was added..config/nextest.toml:lock_timeout_audited_command_waits_one_deadline…now runs alone (threads-required = "num-cpus"). It asserts wall time (under two 80 ms deadlines, including an fsync'd audit append). In its new test binary, nextest schedules it alongside the process-spawningscripts/rename_templatetests: it failed 8 of 10 full runs at 160–168 ms, whileagent-mainpassed 10 of 10 with the test scheduled earlier. Its bound is unchanged. With the override it passed 10 of 10.output/still readsTMPL_CLI_FORMAT,TMPL_CLI_LOG,NO_COLORand the rest. Onlymaincaptures the core'sEnv.No
toolscrate and noproviders, as the brief said.Validation
make ciin the worktree, withoutCI=true: passed.-D warnings: passed.agent-main.cargo deny: not run, because cargo-deny is not installed locally, somake ciskipped it with a warning. CI runs it. No external dependency changed; the new crate is MIT vialicense.workspace.STANDARDS_STRICT=1 make standards-check: passed.cargo clippy --workspace -- -D warnings(non-test build, withouttest-support): passed.scripts/rename-template.sh demo-clion a full copy of the tree: it produceddemo-cli,demo-cli-coreanddemo-cli-store. In the renamed copy,cargo clippy --workspace --all-targets --offline -- -D warnings,check-dependency-direction.shandcargo fmt --checkall passed. Therename_templateintegration test also passed.🤖 Generated with Claude Code