Prompt file imported from D3V0N5H1R3/luma (
.github/prompts/new-stdlib-module.prompt.md). Copyright stays with the author.
New Standard Library Module
Add a new standard library module to Luma. Follow the existing module patterns.
This prompt covers creating the module skeleton and wiring it into the runtime, catalog, type checker, build, and docs. For the per-item work inside the module, follow:
- new-stdlib-function.prompt.md for each function or named constant.
- new-stdlib-type.prompt.md for each record or choice type.
Steps
- Read Luma_Software_Architecture.md Section 11 for stdlib architecture.
- Read Luma_Standard_Library_Reference.md for existing standard library modules.
- Read Luma_Coding_Guidelines.md for Luma coding style conventions.
- Read Luma_Error_Handling.md for error handling conventions — especially §6 (Standard Library Conventions) and §8 (Anti-Patterns).
- Implement the module across the runtime, catalog, type checker, and build layers, following the existing patterns:
- Study the existing pattern. Read STDLIB_MODULE_REGISTRATION_GUIDE.md and an existing module in
core/runtime/stdlib/(e.g.string_module.cpp) to learn the registration patterns and file-naming conventions. - Create the module (runtime). Add
core/runtime/stdlib/<category>/<module_lower>_module.hppand<module_lower>_module.cpp(in the category subdirectory that matches the module's domain —common,types,collections,text,math,io,system, orconcurrency) with one top-levelregister_<module_lower>_ns(const EnvPtr& env)(sandbox-aware modules take an extrabool sandbox). Register functions via the fluent DSL —ModuleBuilderfor standard modules,ContainerModuleBuilderfor collection types, ordefine_nativefor special cases (global names, blocking lifecycle, conditional compilation) — using.func("name", arity)then.extract_body(...)/.raw_body(...)(name and arity only; types live in the catalog). Validate arguments, emit clear error messages, use the pipe-first calling convention (first argument is the receiver), and split large modules across_module.cpp+_search.cpp/_transform.cpp/_parser.cpp/_serializer.cppwith a_internal.hppfor shared helpers. - Register the module at runtime. Include the new
<module_lower>_module.hppincore/runtime/stdlib/common/stdlib_registry.hppand add an entry to itskModulestable, alphabetically within its group, with the correctos_only/sandbox_awareflags. The lazy registry and stdlib namespace list derive from this table automatically. - Add catalog metadata (single source of truth). Create
shared/stdlib/stdlib_catalog_<topic>.cpp(or extend an existing topic file) with aregister_<module_lower>_functions(specs, m, p)function that adds each function viam.fn(name, arity, params, return_type, {param_types}). Declare it inshared/stdlib/stdlib_catalog_internal.hppand add it to thek_registrationstable inshared/stdlib/stdlib_catalog.cppwith the module name andCapability. The catalog drives arity, return types, completions, hover, and signature help automatically. - Add type refinement only if generic. Most modules need nothing further — the type checker derives signatures from the catalog. Only add manual logic to
refine_return_type()incore/analysis/types/stdlib_type_signatures.cppif a return type depends on call-site argument types (e.g.array<U>). - Wire the build. Add the runtime source(s) to
core/runtime/CMakeLists.txtand the catalog source toshared/CMakeLists.txt(sources are listed explicitly — no globbing).
- Study the existing pattern. Read STDLIB_MODULE_REGISTRATION_GUIDE.md and an existing module in
- Add C++ unit tests in a
tests/runtime/stdlib_test_<module_lower>.cppfile and wire it into CMake. - Add a Luma feature test at
tests/features/stdlib/<module_lower>_functions.luma. - When warranted, add fuzz and/or benchmark coverage. Add a fuzz target in
fuzz/only if the module parses or decodes untrusted input (a new parser/decoder/codec entry point). Addtime_itcases to abench_<topic>.lumainbenchmarks/only if the module is performance-sensitive. Skip both for pure-logic modules. - Document the module in
Luma_Standard_Library_Reference.mdunder the standard library section. If the module is large enough to warrant its own guide, add one. - Build and verify:
cmake --build --preset default, thenctest --preset defaultfor the C++ tests andbuild/Release/luma --test tests/features/stdlib/<module_lower>_functions.lumafor the Luma test. Confirm everything passes before finishing.
Verification Tiers
A new module involves many files. Verify incrementally rather than waiting until step 10.
| After… | Run | Why |
|---|---|---|
| Creating the module source + registry entry (step 5) | cmake --build --preset default (compile only) |
Catches includes, linker errors, registration typos early |
| Compiling cleanly | ctest -R stdlib_test_<module> (targeted test) |
Confirms the module registers and its functions work |
| Adding catalog metadata | ctest -R stdlib_catalog_conformance |
Catches arity/name mismatches between runtime and catalog |
| All C++ tests pass | build/Release/luma --strict --test tests/features/stdlib/<module>_functions.luma |
Validates Luma-level behaviour and catches lint warnings |
If a tier fails, fix the failure before advancing to the next tier. If a fix introduces a new failure you can't resolve in two attempts, revert to your last green state (git stash or git checkout -- <files>) and try a different approach.
