refactor: move renderer-independent logic to berhtjan-core (order + lang) #3

Closed
opened 2026-05-07 12:20:52 +02:00 by michael · 0 comments
Owner

Goal

Move all UI-renderer-independent logic into berhtjan-core so it is
shared by cli, web, api and any future renderer without duplication.
Includes subcommand ordering and multilingual label support.

Current problem

adapters/ui is copy-pasted per host program (stapul, steurjan, ...).
parse_scan_roots, load_contributions, build_index live in
berhtjan-cli/dispatch.lua but belong in core since web and api need
the same logic. Language resolution and subcommand ordering are missing.

What moves to berhtjan-core

Contribution scanning:

  • parse_scan_roots(raw) -- parses cfg.ui.scan string into list
  • load_contributions(roots) -- scans module.conf + contribution.json
  • build_index(contributions) -- builds command/subcommand index

Ordering:

  • order field added to subcommands in contribution.json (optional int)
  • build_index sorts subcommands by order, fallback: alphabetical

Language resolution:

  • resolve_lang(ctx) -- priority chain:
    1. ctx.user_locale (auth user locale if available)
    2. os.getenv("LANG") / LC_ALL (e.g. "de_DE.UTF-8" -> "de")
    3. ctx.lang (from cfg.ui.lang, passed via adapters/ui)
    4. "en" (hardcoded default)
  • resolve_label(label, lang) -- picks correct label string for lang

What stays in berhtjan-cli

  • dispatch(args, roots, ctx) -- uses berhtjan-core
  • build_usage(roots, ctx) -- uses berhtjan-core, respects lang
  • print_subcommands -- respects lang + order
  • render, prompt, confirm -- CLI-specific

What stays in adapters/ui (host)

  • build_ctx(cfg) -- host-specific: reads registry, paths, project,
    lang from cfg
  • Thin wrappers calling berhtjan-core + berhtjan-cli/web/api

contribution.json additions

"subcommands": {
  "list":         { "order": 1, "label": { "en": "...", "de": "..." }, ... },
  "install":      { "order": 2, "label": { "en": "...", "de": "..." }, ... },
  "update-index": { "order": 3, "label": { "en": "...", "de": "..." }, ... }
}

Acceptance criteria

  • berhtjan-core: parse_scan_roots, load_contributions, build_index,
    resolve_lang, resolve_label implemented and tested
  • berhtjan-core/build_index: subcommands sorted by order field
  • berhtjan-cli/dispatch.lua: uses berhtjan-core, respects lang + order
  • adapters/ui in stapul + steurjan: simplified to build_ctx + calls
  • daw-module-manager/src/ui/contribution.json: order + en/de labels
  • cfg.ui.lang optional in stapul.conf + steurjan.conf
  • All existing tests pass, new tests for resolve_lang + ordering

References

  • DAW/daw-modul-berhtjan-cli (dispatch.lua)
  • DAW/daw-module-manager (contribution.json)
  • DAW/stapul (adapters/ui)
  • DAW/steurjan (adapters/ui)
## Goal Move all UI-renderer-independent logic into `berhtjan-core` so it is shared by cli, web, api and any future renderer without duplication. Includes subcommand ordering and multilingual label support. ## Current problem `adapters/ui` is copy-pasted per host program (stapul, steurjan, ...). `parse_scan_roots`, `load_contributions`, `build_index` live in `berhtjan-cli/dispatch.lua` but belong in core since web and api need the same logic. Language resolution and subcommand ordering are missing. ## What moves to berhtjan-core **Contribution scanning:** - `parse_scan_roots(raw)` -- parses cfg.ui.scan string into list - `load_contributions(roots)` -- scans module.conf + contribution.json - `build_index(contributions)` -- builds command/subcommand index **Ordering:** - `order` field added to subcommands in contribution.json (optional int) - `build_index` sorts subcommands by `order`, fallback: alphabetical **Language resolution:** - `resolve_lang(ctx)` -- priority chain: 1. ctx.user_locale (auth user locale if available) 2. os.getenv("LANG") / LC_ALL (e.g. "de_DE.UTF-8" -> "de") 3. ctx.lang (from cfg.ui.lang, passed via adapters/ui) 4. "en" (hardcoded default) - `resolve_label(label, lang)` -- picks correct label string for lang ## What stays in berhtjan-cli - `dispatch(args, roots, ctx)` -- uses berhtjan-core - `build_usage(roots, ctx)` -- uses berhtjan-core, respects lang - `print_subcommands` -- respects lang + order - `render`, `prompt`, `confirm` -- CLI-specific ## What stays in adapters/ui (host) - `build_ctx(cfg)` -- host-specific: reads registry, paths, project, lang from cfg - Thin wrappers calling berhtjan-core + berhtjan-cli/web/api ## contribution.json additions ```json "subcommands": { "list": { "order": 1, "label": { "en": "...", "de": "..." }, ... }, "install": { "order": 2, "label": { "en": "...", "de": "..." }, ... }, "update-index": { "order": 3, "label": { "en": "...", "de": "..." }, ... } } ``` ## Acceptance criteria - [ ] `berhtjan-core`: parse_scan_roots, load_contributions, build_index, resolve_lang, resolve_label implemented and tested - [ ] `berhtjan-core/build_index`: subcommands sorted by order field - [ ] `berhtjan-cli/dispatch.lua`: uses berhtjan-core, respects lang + order - [ ] `adapters/ui` in stapul + steurjan: simplified to build_ctx + calls - [ ] `daw-module-manager/src/ui/contribution.json`: order + en/de labels - [ ] cfg.ui.lang optional in stapul.conf + steurjan.conf - [ ] All existing tests pass, new tests for resolve_lang + ordering ## References - DAW/daw-modul-berhtjan-cli (dispatch.lua) - DAW/daw-module-manager (contribution.json) - DAW/stapul (adapters/ui) - DAW/steurjan (adapters/ui)
michael 2026-05-08 11:47:54 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
DAW/daw-modul-berhtjan-core#3
No description provided.