Skip to content

fix(guard): add insights.share scope, overviewStats, miniHeatmap, and reauth CTA to share#703

Open
kantorcodes wants to merge 1 commit into
mainfrom
fix/guard-insights-share-p0
Open

fix(guard): add insights.share scope, overviewStats, miniHeatmap, and reauth CTA to share#703
kantorcodes wants to merge 1 commit into
mainfrom
fix/guard-insights-share-p0

Conversation

@kantorcodes

Copy link
Copy Markdown
Member

Summary

  • Add guard:insights.share to DEFAULT_GUARD_DEVICE_SCOPES so daemon can publish insights shares without incremental reauth.
  • Extend build_insights_share_payload with overviewStats (pending/apps/recorded) and miniHeatmap (last 5 days) matching home card.
  • Update dashboard share modal: overview stats + mini heatmap preview, re-auth CTA for scope errors.

Testing

  • python -m pytest tests/test_guard_connect_flow.py tests/test_insights_share.py -q
  • cd dashboard && pnpm run typecheck

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces a mini 5-day activity heatmap component (EvidenceActivityHeatmapMini) and integrates it into the home preview and share modal. It also adds overview stats to the share payload, handles re-authorization for scope/unauthorized errors, and updates the backend and tests accordingly. The review feedback suggests centralizing the heatmap level calculation logic into a shared helper function (getHeatmapLevel) to prevent potential TypeScript null-pointer compilation errors and ensure visual consistency with the backend's thresholds across all previews.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread dashboard/src/evidence/evidence-activity-heatmap-mini.tsx
Comment thread dashboard/src/evidence/evidence-insights-home-preview.tsx Outdated
Comment thread dashboard/src/evidence/evidence-insights-home-preview.tsx
Comment thread dashboard/src/evidence/evidence-insights-share-modal.tsx Outdated
Comment thread dashboard/src/evidence/evidence-insights-share-modal.tsx
@greptile-apps

greptile-apps Bot commented Jun 8, 2026

Copy link
Copy Markdown

Greptile Summary

This PR adds guard:insights.share to the default device OAuth scope list, extends build_insights_share_payload with overviewStats and miniHeatmap, and wires the share modal to show a live preview plus a re-auth CTA when a scope or auth error occurs.

  • Python backend: build_insights_share_payload now accepts overview_stats and emits overviewStats unconditionally plus miniHeatmap (last-5-days, conditional on data). publish_insights_share resolves stats from the live store before building the payload.
  • TypeScript dashboard: New EvidenceActivityHeatmapMini component and getHeatmapLevel helper use the same thresholds as the Python backend, replacing the mismatched inline formula. The share modal now stores the raw error alongside the formatted one so isInsightsShareScopeError is applied to the unformatted string — fixing the previously broken re-auth CTA. Both insufficient scope / insufficient_scope variants are checked.

Confidence Score: 5/5

Safe to merge — the re-auth CTA path is now correctly wired to the raw error, and the heatmap level logic matches the backend exactly.

All three previously broken paths (re-auth CTA swallowed, level formula divergence, scope-pattern mismatch) are addressed. The new overviewStats and miniHeatmap fields have test coverage, the scope list change is straightforward, and the TypeScript compiles cleanly. Only a minor redundant expression remains.

No files require special attention.

Important Files Changed

Filename Overview
dashboard/src/evidence/evidence-activity-heatmap-mini.tsx New component with getHeatmapLevel matching Python thresholds (0.85/0.6/0.35); correctly pads missing cells and renders 5 fixed cells.
dashboard/src/evidence/evidence-insights-share-modal.tsx Re-auth CTA fixed: rawError stored and checked with isInsightsShareScopeError before formatting; preview extended with overview stats and mini heatmap.
dashboard/src/evidence/evidence-insights-share-errors.ts isInsightsShareScopeError added; checks both underscore and space variants plus "unauthorized" to correctly gate the re-auth CTA.
src/codex_plugin_scanner/guard/insights_share.py Adds overviewStats (always present) and miniHeatmap (conditional on data) to payload; days field correctly tracks actual cell count.
src/codex_plugin_scanner/guard/cli/connect_flow.py guard:insights.share added to DEFAULT_GUARD_DEVICE_SCOPES in correct position (before guard:offline_access).
dashboard/src/guard-types.ts GuardInsightsShareHeatmapCell added and used; GuardInsightsShareOverviewStats added but not imported by any component (dead type).
dashboard/src/evidence/evidence-insights-home-preview.tsx Migrated from old EvidenceActivityHeatmapMini to new one; miniHeatmapDays computed inline with correct optional chaining; label updated to "Last 5 days".
tests/test_insights_share.py New assertions verify overviewStats defaults, miniHeatmap.days === len(cells), and that cell count matches input data length.

Sequence Diagram

sequenceDiagram
    participant Modal as Share Modal (TS)
    participant API as guard-api
    participant Daemon as Python Daemon
    participant Store as GuardStore
    participant Cloud as Guard Cloud

    Modal->>Modal: render preview (runtime stats + analytics heatmap)
    Modal->>API: publishInsightsShare(opts)
    API->>Daemon: POST /insights/shares
    Daemon->>Store: receipt_analytics()
    Daemon->>Store: count_approval_requests()
    Daemon->>Store: list_managed_installs()
    Daemon->>Store: count_receipts()
    Daemon->>Daemon: build_insights_share_payload() overviewStats + miniHeatmap
    Daemon->>Cloud: POST payload (guard:insights.share scope)
    alt success
        Cloud-->>Daemon: slug, publicUrl
        Daemon-->>API: share result
        API-->>Modal: GuardInsightsShareResult
        Modal->>Modal: show EvidenceInsightsShareSheet
    else scope / auth error
        Cloud-->>Daemon: 403 / 401
        Daemon-->>API: error
        API-->>Modal: Error(rawMessage)
        Modal->>Modal: setRawError → isInsightsShareScopeError → show Reconnect CTA
    end
Loading

Reviews (6): Last reviewed commit: "fix(insights): add overviewStats and min..." | Re-trigger Greptile

Comment thread dashboard/src/evidence/evidence-insights-share-modal.tsx Outdated
Comment thread src/codex_plugin_scanner/guard/insights_share.py Outdated
Comment thread dashboard/src/evidence/evidence-insights-share-modal.tsx
Comment thread dashboard/src/guard-types.ts
@kantorcodes kantorcodes force-pushed the fix/guard-insights-share-p0 branch 2 times, most recently from b0e364b to bb76d54 Compare June 9, 2026 01:30
Comment thread dashboard/src/evidence/evidence-insights-share-errors.ts
@kantorcodes kantorcodes force-pushed the fix/guard-insights-share-p0 branch 2 times, most recently from f581aa7 to 4e7a29e Compare June 9, 2026 01:54
…ors reauth CTA

Signed-off-by: Michael Kantor <6068672+kantorcodes@users.noreply.github.com>
@kantorcodes kantorcodes force-pushed the fix/guard-insights-share-p0 branch from 4e7a29e to d05380b Compare June 9, 2026 02:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant