Skip to content

feat(ui): add Lighthouse contextual transport core#12068

Open
alejandrobailo wants to merge 4 commits into
masterfrom
feat/lighthouse-context-core
Open

feat(ui): add Lighthouse contextual transport core#12068
alejandrobailo wants to merge 4 commits into
masterfrom
feat/lighthouse-context-core

Conversation

@alejandrobailo

@alejandrobailo alejandrobailo commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Context

Lighthouse needs a bounded UI-only context contract that preserves the text shown to the user while prioritizing the page and active side-panel detail. This is PR 1 of 2 and is the base for #12069.

Description

  • Add the versioned Lighthouse context types, validation, deterministic serialization, and a 2 KiB compiler.
  • Prioritize context as page, focused detail, explicit selections, then automatic summaries.
  • Deduplicate after priority ordering so the highest-priority representation of an entity is retained.
  • Enforce the eight-item and 2 KiB limits through progressive degradation, removing the lowest-priority items first.
  • Extend the Lighthouse v2 UI payload with text, display_text, and ui_context, while preserving non-contextual payloads, legacy { text } history, and the Lighthouse v1 flow.
  • Capture validated immutable snapshots for optimistic messages, historical badges, and retries.
  • Cover validation, transport, priority, deduplication, size limits, message normalization, payload construction, and retries.

No API, MCP Server, dependency, or visual changes are included. The approved user-visible changelog fragment ships in #12069; this foundation PR uses the no-changelog label.

Steps to review

  1. Run cd ui.
  2. Run pnpm test --run lib/lighthouse/context/context.test.ts lib/lighthouse/context/transport.test.ts 'app/(prowler)/lighthouse/_actions/lighthouse-v2.adapter.test.ts' 'app/(prowler)/lighthouse/_lib/messages.test.ts' 'app/(prowler)/lighthouse/_lib/chat-store.test.ts'.
  3. Run pnpm run healthcheck.
  4. Review compiler tests for page/focused/selection/automatic ordering, priority-aware deduplication, and progressive eight-item/2 KiB degradation.
  5. Review adapter and store tests for legacy compatibility and immutable retry snapshots.

Validation performed locally:

  • 336 test files / 2247 tests passed on this core branch.
  • pnpm run healthcheck passed TypeScript, ESLint, and Prettier.
  • The complete stacked branch passed 345 test files / 2295 tests and the UI healthcheck.

Checklist

Community Checklist
  • This feature/issue is listed in the open issues or roadmap.prowler.com
  • Is it assigned to me, if not, request it via the open issues or Prowler Community Slack
  • I have reviewed the open pull requests and found no existing PR implementing the same contextual Lighthouse outcome
  • Review if the code is being covered by tests.
  • Review if code is being documented following the applicable project conventions.
  • Review if backport is needed: not needed.
  • Review if the README needs changes: no changes needed.
  • Changelog reviewed: the user-visible fragment is intentionally included in PR 2 and this PR uses no-changelog.

SDK/CLI

  • Are there new checks included in this PR? No

UI

  • The compiler, transport, and compatibility requirements work as expected on the UI.
  • No npm dependencies are added or updated.
  • Screenshots are not applicable because this foundation PR has no visual changes.
  • Changelog handling is documented above.

API

  • No API code or API specification changes are included.

MCP Server

  • No MCP Server changes are included.

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@alejandrobailo
alejandrobailo requested a review from a team as a code owner July 21, 2026 14:31
@alejandrobailo alejandrobailo added the no-changelog Skip including change in changelog/release notes label Jul 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

No Conflicts

No conflict markers, and the branch merges cleanly into its base.

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds typed Lighthouse UI context contracts, bounded compilation and transport, context-aware chat submission and retry snapshots, and v2 adapter support for contextual or legacy text-only messages.

Changes

Lighthouse context messaging

Layer / File(s) Summary
Context contracts and validation
ui/types/lighthouse-context.ts, ui/lib/lighthouse/context/schema.ts, ui/lib/lighthouse/context/context.test.ts
Defines supported context item types and validates envelope, field, item-count, filter, and schema constraints.
Context compilation and transport
ui/lib/lighthouse/context/compiler.ts, ui/lib/lighthouse/context/transport.ts, ui/lib/lighthouse/context/*test.ts
Filters stale scopes, deduplicates and orders items, degrades oversized context, and serializes validated context into deterministic API metadata blocks.
Chat context lifecycle
ui/app/(prowler)/lighthouse/_lib/chat-store.ts, ui/app/(prowler)/lighthouse/_lib/messages.ts, ui/app/(prowler)/lighthouse/_lib/*test.ts
Submissions and optimistic messages carry compiled context; retries reuse snapshots, while context disable and session reset behavior are covered.
Message API integration
ui/app/(prowler)/lighthouse/_types/sessions.ts, ui/app/(prowler)/lighthouse/_actions/lighthouse-v2.adapter.ts, ui/app/(prowler)/lighthouse/_actions/lighthouse-v2.adapter.test.ts, ui/app/(prowler)/lighthouse/_components/chat/lighthouse-v2-chat-page.test.tsx
Renames the payload field to displayText and adds optional context serialization, preserving text-only payloads when context is absent.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant ChatStore
  participant ContextCompiler
  participant LighthouseAdapter
  participant LighthouseAPI
  User->>ChatStore: submitMessage(displayText, context)
  ChatStore->>ContextCompiler: prepareLighthouseContext(context)
  ContextCompiler-->>ChatStore: compiled context snapshot
  ChatStore->>LighthouseAdapter: send displayText and context
  LighthouseAdapter->>LighthouseAPI: send contextual message payload
  LighthouseAPI-->>LighthouseAdapter: response
  LighthouseAdapter-->>ChatStore: message result
Loading

Possibly related PRs

Suggested reviewers: pfe-nazaries

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and accurately summarizes the main change: adding the Lighthouse contextual transport core.
Description check ✅ Passed The description follows the template closely and includes context, summary, review steps, checklist items, and scope notes.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/lighthouse-context-core

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

🔒 Container Security Scan

Image: prowler-ui:4fd0160
Last scan: 2026-07-22 15:21:54 UTC

✅ No Vulnerabilities Detected

The container image passed all security checks. No known CVEs were found.

📋 Resources:

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ui/app/`(prowler)/lighthouse/_actions/lighthouse-v2.adapter.ts:
- Around line 264-274: Update buildAgentText in the lighthouse context transport
module to accept and reuse the already-validated apiContext, then pass that
value from the adapter’s contextual message branch instead of having
buildAgentText revalidate input.context. Preserve the existing text output and
non-context path while ensuring each context envelope is parsed only once per
send.

In `@ui/app/`(prowler)/lighthouse/_lib/chat-store.ts:
- Around line 131-134: The retry context bypass currently relies on mutable
closure state and call ordering. Remove retryContextOverride and update
submitMessage to accept an explicit internal option indicating whether to bypass
the context gate; have retryLastMessage pass that option while normal callers
retain the default behavior, preserving reuse of the original validated
snapshot.

In `@ui/lib/lighthouse/context/compiler.ts`:
- Around line 29-65: Update the candidate loop in compileLighthouseContext to
ignore schema-parse failures rather than returning undefined, while continuing
to collect valid same-scope items. Preserve the existing scope filtering,
deduplication, ordering, and size-based fallback behavior for the successfully
parsed candidates.

In `@ui/lib/lighthouse/context/transport.ts`:
- Around line 69-146: Update toApiContextItem with an explicit return type and
an exhaustive default branch that assigns the unhandled item to never and
returns or throws through the established guard pattern. Ensure any future
LIGHTHOUSE_CONTEXT_KIND addition causes a compile-time failure instead of
silently returning undefined, while preserving all existing serialization cases.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d97d4258-b973-4193-aa2f-549724356012

📥 Commits

Reviewing files that changed from the base of the PR and between e943ded and fde3e8d.

📒 Files selected for processing (13)
  • ui/app/(prowler)/lighthouse/_actions/lighthouse-v2.adapter.test.ts
  • ui/app/(prowler)/lighthouse/_actions/lighthouse-v2.adapter.ts
  • ui/app/(prowler)/lighthouse/_lib/chat-store.test.ts
  • ui/app/(prowler)/lighthouse/_lib/chat-store.ts
  • ui/app/(prowler)/lighthouse/_lib/messages.test.ts
  • ui/app/(prowler)/lighthouse/_lib/messages.ts
  • ui/app/(prowler)/lighthouse/_types/sessions.ts
  • ui/lib/lighthouse/context/compiler.ts
  • ui/lib/lighthouse/context/context.test.ts
  • ui/lib/lighthouse/context/schema.ts
  • ui/lib/lighthouse/context/transport.test.ts
  • ui/lib/lighthouse/context/transport.ts
  • ui/types/lighthouse-context.ts

Comment thread ui/app/(prowler)/lighthouse/_actions/lighthouse-v2.adapter.ts Outdated
Comment thread ui/app/(prowler)/lighthouse/_lib/chat-store.ts Outdated
Comment thread ui/lib/lighthouse/context/compiler.ts
Comment thread ui/lib/lighthouse/context/transport.ts Outdated
@alejandrobailo alejandrobailo self-assigned this Jul 21, 2026
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/ui no-changelog Skip including change in changelog/release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant