Deduplicate Shiny and researcher-app memory/UI/sanitization code and tighten inst/shiny/ boundaries

Open
#210 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Active
Tech stack
r

Research direction

Start by mapping the duplicated memory review modules in inst/shiny/R/mod_memory.R and R/researcher-app-memory.R, then trace their callers in tempest_app() and tempest_researcher_app(). The issue also names the sanitization, rendering, worker, and asset entry points across R/ and inst/shiny/R/; tackle one scoped area at a time. Done means the acceptance criteria are met and the Shiny, researcher-app, MCP-app, and enriched-render tests pass.

Written by the indexing model from the issue text.

Description

Problem

The bundled Shiny app (inst/shiny/, ~8,945 lines), researcher app (R/researcher-app*.R, ~4,400 lines), and MCP/enriched renderers duplicate substantial UI, Graft memory, sanitization, and worker logic, embed hundreds of lines of inline JS/CSS inside R string literals, and violate the inst/shiny/ package boundary (99 calls across 61 unexported tempest::: helpers, plus direct manager$.__enclos_env__$private$sessions introspection and non-UI domain/security logic inside inst/shiny/).

Scope

  1. Unify duplicated Graft memory UI/server & remove R6 private access
    • Consolidate the ~370-line near-verbatim duplicate review module in inst/shiny/R/mod_memory.R (mod_memory_report_server, L295–664) and R/researcher-app-memory.R (tempest_researcher_memory_review_server, L166–536), plus the duplicated sidebar/config selector, into one shared Shiny module in R/.
    • Move shiny_memory_find_selection(), shiny_memory_wrap_config() (sharing tool-wrapping with R/researcher-app-tools.R), and Graft consultation extraction (eliminating manager$.__enclos_env__$private$sessions at inst/shiny/R/mod_memory.R:733–756) into R/graft-memory.R.
  2. Consolidate duplicated sanitization, rendering, URL, provider, and redaction helpers
    • Remove the 52-line verbatim duplicate sanitize_external_citation_markers() in inst/shiny/R/utils.R:77–128 in favor of tempest_shinychat_sanitize_text() (R/shinychat-adapter.R:233–284), and replace hand-rolled tempest_shinychat_escape_html() with htmltools::htmlEscape().
    • Share one Markdown → sanitized HTML allowlist pipeline across R/enriched-render.R:119–218, R/mcp-app.R:305–383, and inst/shiny/R/utils.R:29–75 / mod_report.R:158–168.
    • Share safe URL validation, search provider choices (inst/shiny/R/utils.R:11–25 -> R/config.R:595–609), topic/stream slugifiers, and credential redaction regex (3 verbatim copies inside R/researcher-app-worker.R:88,268,684 + inst/shiny/R/mod_run_review.R:732–747).
  3. Extract large inline JS/CSS literals to static assets
    • inst/shiny/R/utils.R:583–1013 (431L inline JS settings drawer) -> inst/shiny/www/settings-drawer.js.
    • R/researcher-app-ui.R:25–465 (441L inline CSS) -> static package asset (inst/).
    • R/enriched-render.R:711–877 (167L inline CSS) -> static package asset (inst/).
  4. Decompose Shiny monoliths and move non-UI domain logic into R/
    • Move ZIP archive path-traversal/quota enforcement (inst/shiny/R/mod_chat.R:2017–2136), verification threshold summary (mod_chat.R:1822–1834), trajectory authority-join filtering (mod_run_review.R:852–891), and STORM background worker NDJSON plumbing (mod_storm.R:507–796) into package R/ helpers.
    • Split inst/shiny/R/mod_chat.R (2,410L, 962L server), inst/shiny/R/utils.R (1,963L — also move mindmap_to_visnetwork() to mod_mindmap.R), and inst/shiny/R/mod_run_review.R (1,370L) into focused modules.
    • Consolidate small researcher-app UI fragments (R/researcher-app-example.R, R/researcher-app-evidence.R, R/researcher-app-briefs.R) into R/researcher-app-ui.R.

Acceptance Criteria

  • One shared Graft memory review module serves both tempest_app() and tempest_researcher_app(), with zero .__enclos_env__$private reaches from inst/shiny/.
  • Citation sanitization, HTML sanitization, search providers, and credential redaction each have a single source of truth.
  • Inline JS/CSS monoliths are served from static assets and Shiny modules are cleanly factored.
  • All Shiny, researcher-app, MCP-app, and enriched-render tests pass.
Dominant language
R
Stars
1
Forks
0
Avg merge
19h 6m
Merged PRs (30d)
12

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from JamesHWade/tempest

All issues in JamesHWade/tempest

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.