octobot/skills/engineering/bdd/deep-modules-r.md
Lukasz Boryn 277ec801de refactor(skills): convert cross-skill links to /skill-name references
- implements blueprint 028
- rewrite 290 cross-skill markdown links across 59 files to unchecked
  backtick-wrapped /skill-name prose (R-023), so skill content resolves
  under any install depth — symlinked, flat-copied, or whole-tree
- add skills/productivity/conjure-a-skill/scripts/skill-ref-check —
  validates every /skill-name mention resolves to a real skill folder,
  the replacement coverage link-check lost on these references
- add scripts/link-skills.sh, mirroring mattpocock/skills, symlinking
  every skill into ~/.claude/skills and ~/.agents/skills
- docs(readme): point Install at link-skills.sh and npx skills@latest
  add for non-Claude-Code harnesses
2026-09-23 11:03:25 +02:00

76 lines
2.3 KiB
Markdown

# Deep modules in R
Vocabulary and principles in `/design-codebase`.
This file shows what deep / shallow look like with `box::use` — the R lever
for controlling the interface.
In R you control the interface with `box::use` (or NAMESPACE/`@export` in a
package). The interface is whatever a caller writes after `box::use(...)`.
## Shallow — bad
```r
# R/modb/client.R — exports eight thin helpers
box::export(
build_url, build_headers, parse_token, refresh_token,
page_request, paged_collect, validate_dataset_id, query_dataset
)
```
A caller writes:
```r
box::use(R/modb/client[
build_url, build_headers, parse_token, refresh_token,
page_request, paged_collect, validate_dataset_id, query_dataset
])
tok <- refresh_token(parse_token(Sys.getenv("MODB_TOKEN")))
url <- build_url("DS001")
hdr <- build_headers(tok)
rows <- paged_collect(page_request(url, hdr))
```
Every refactor that splits, renames, or merges a helper breaks every caller
and every test. The tests reach into internals because the internals *are*
the interface.
## Deep — good
```r
# R/modb/client.R — one exported entry point, everything else internal
box::export(query_dataset)
```
A caller writes:
```r
box::use(R/modb/client[query_dataset])
rows <- query_dataset("DS001")
```
`query_dataset()` handles tokens, paging, retries, and validation
internally. Tests target the contract ("returns a tibble of expected rows
for DS001"; "raises `modb_auth_error` on bad token"). Internal helpers can
be renamed or replaced freely.
## Design questions before exporting
For every name you are about to `box::export()` or `@export`:
1. **Does a caller need this?** If only other internals call it, keep it
unexported.
2. **Could two of these collapse?** `build_url` + `build_headers` may want
to become an internal `prepare_request()`.
3. **Could a parameter swallow a helper?** A `paginate = TRUE` argument on
`query_dataset()` can remove `page_request` + `paged_collect` from the
surface.
4. **Is this a leaky abstraction?** Returning a `httr2::request` object
forces every caller (and test) to know `httr2`. Return a tibble or a
typed result instead.
## Heuristic
If the count of exports from a module changes every PR, the module is
shallow. Deep modules export one or two names and stay stable for months.