Skip to content

feat: Add Suggestions tab to the agent rule creation flow#95875

Open
samranahm wants to merge 28 commits into
Expensify:mainfrom
samranahm:95742/agent-rule-suggestions
Open

feat: Add Suggestions tab to the agent rule creation flow#95875
samranahm wants to merge 28 commits into
Expensify:mainfrom
samranahm:95742/agent-rule-suggestions

Conversation

@samranahm

@samranahm samranahm commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Explanation of Change

Fixed Issues

$ #95742
PROPOSAL: #95742 (comment)

Tests

  1. Open workspaces tab and choose a workspace
  2. Open Rules page and press "Add agent rule" in Agent rules section
  3. Verify suggested tab open with some suggestions to create new rule
  4. Select any suggested rule and press Next and verify the same rule open in edit tab and user can edit it
  5. Press Save again on edit page and verify rule is added.
  • Verify that no errors appear in the JS console

Offline tests

  1. While online, open Rules page and press "Add agent rule"
  2. Verify Suggested tab open with multiple suggestions
  3. Go back to "Rules" page and turn on "Force offline" and press "Add agent rule" again and verify suggestions list appear
  4. Select a suggestion and press Next to go to edit page, make any changes and press Save.
  5. On Rules page verify the new rules is available as gray under "Agent rules"
  6. Open Account tab > Troubleshoot and turn off "Force offline" and clear cache by pressing "Clear cache and restart"
  7. Turn on "Force offline" again open Workspaces tab > select a workspace and press "Add agent rule"
  8. Verify Blocking view open with "No suggestions available" title and "You appear to be offline." subtitle
  9. Turn off "Force offline" with Troubleshoot menu and verify suggestions list appear without going back and come to this page again

QA Steps

Same as test

// TODO: These must be filled out, or the issue title must include "[No QA]."

  • Verify that no errors appear in the JS console

PR Author Checklist

  • I linked the correct issue in the ### Fixed Issues section above
  • I wrote clear testing steps that cover the changes made in this PR
    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms
  • I ran the tests on all platforms & verified they passed on:
    • Android: Native
    • Android: mWeb Chrome
    • iOS: Native
    • iOS: mWeb Safari
    • MacOS: Chrome / Safari
  • I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
  • I followed proper code patterns (see Reviewing the code)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text that was added to the app is grammatically correct in English. It adheres to proper capitalization guidelines (note: only the first word of header/labels should be capitalized), and is either coming verbatim from figma or has been approved by marketing (in order to get marketing approval, ask the Bug Zero team member to add the Waiting for copy label to the issue)
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I followed the guidelines as stated in the Review Guidelines
  • I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar are working as expected)
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))
  • If new assets were added or existing ones were modified, I verified that:
    • The assets are optimized and compressed (for SVG files, run npm run compress-svg)
    • The assets load correctly across all supported platforms.
  • If the PR modifies code that runs when editing or sending messages, I tested and verified there is no unexpected behavior for all supported markdown - URLs, single line code, code blocks, quotes, headings, bold, strikethrough, and italic.
  • If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like Avatar is modified, I verified that Avatar is working as expected in all cases)
  • If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
  • If the PR modifies a component or page that can be accessed by a direct deeplink, I verified that the code functions as expected when the deeplink is used - from a logged in and logged out account.
  • If the PR modifies the UI (e.g. new buttons, new UI components, changing the padding/spacing/sizing, moving components, etc) or modifies the form input styles:
    • I verified that all the inputs inside a form are aligned with each other.
    • I added Design label and/or tagged @Expensify/design so the design team can review the changes.
  • I added unit tests for any new feature or bug fix in this PR to help automatically prevent regressions in this user flow.
  • If the main branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to the Test steps.

Screenshots/Videos

Android: Native
Android.Native.mp4
Android: mWeb Chrome
Android.mWeb.Chrome.mp4
iOS: Native
IOS.Native.mp4
iOS: mWeb Safari
IOS.mWeb.safari.mp4
MacOS: Chrome / Safari
macOS.Chrome.mp4

@samranahm
samranahm requested a review from a team as a code owner July 11, 2026 00:03
Copilot AI review requested due to automatic review settings July 11, 2026 00:03
@samranahm
samranahm requested a review from a team as a code owner July 11, 2026 00:03
@melvin-bot
melvin-bot Bot requested a review from joekaufmanexpensify July 11, 2026 00:03
@melvin-bot

melvin-bot Bot commented Jul 11, 2026

Copy link
Copy Markdown

Hey, I noticed you changed src/languages/en.ts in a PR from a fork. For security reasons, translations are not generated automatically for PRs from forks.

If you want to automatically generate translations for other locales, an Expensify employee will have to:

  1. Look at the code and make sure there are no malicious changes.
  2. Run the Generate static translations GitHub workflow. If you have write access and the K2 extension, you can simply click: [this button]

Alternatively, if you are an external contributor, you can run the translation script locally with your own OpenAI API key. To learn more, try running:

npx ts-node ./scripts/generateTranslations.ts --help

Typically, you'd want to translate only what you changed by running npx ts-node ./scripts/generateTranslations.ts --compare-ref main

@melvin-bot
melvin-bot Bot requested a review from mananjadhav July 11, 2026 00:03
@melvin-bot

melvin-bot Bot commented Jul 11, 2026

Copy link
Copy Markdown

@mananjadhav Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button]

@codecov

codecov Bot commented Jul 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Looks like you've decreased code coverage for some files. Please write tests to increase, or at least maintain, the existing level of code coverage. See our documentation here for how to interpret this table.

Files with missing lines Coverage Δ
src/CONST/index.ts 94.81% <ø> (ø)
src/ONYXKEYS.ts 100.00% <ø> (ø)
src/libs/API/types.ts 100.00% <ø> (ø)
src/libs/ExportOnyxState/common.ts 80.35% <ø> (ø)
src/libs/PolicyRulesUtils.ts 77.77% <100.00%> (+77.77%) ⬆️
...ce/rules/AgentRules/AddAgentRuleSuggestionsTab.tsx 98.14% <98.14%> (ø)
...s/workspace/rules/AgentRules/EditAgentRulePage.tsx 0.00% <0.00%> (ø)
src/hooks/useSuggestedAgentRules.ts 0.00% <0.00%> (ø)
src/libs/actions/Policy/Rules.ts 29.92% <0.00%> (-2.11%) ⬇️
...orkspace/rules/AgentRules/AddAgentRuleWriteTab.tsx 0.00% <0.00%> (ø)
... and 1 more
... and 6 files with indirect coverage changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a “Suggestions” tab to the workspace agent-rule creation flow, allowing admins to pick a backend-provided suggested rule, prefill the prompt, edit it, and then save via the existing addPolicyAgentRule path.

Changes:

  • Introduces a tabbed add-agent-rule page (Suggestions + Write/Edit), with selection → draft prefill → save.
  • Adds Onyx plumbing (key, type, hook) for backend-served suggested rules plus icon-derivation utility.
  • Adds translations and unit/UI tests for the suggestions experience.

Reviewed changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/unit/getSuggestedAgentRuleIconTest.ts Unit tests for suggestion → icon mapping helper.
tests/ui/AddAgentRuleSuggestionsTabTest.tsx UI tests covering rendering, selection, filtering, and empty state.
src/types/onyx/SuggestedAgentRule.ts Defines SuggestedAgentRule Onyx type shape {id,title,prompt}.
src/types/onyx/index.ts Exposes SuggestedAgentRule from the central Onyx types barrel.
src/pages/workspace/rules/AgentRules/AddAgentRuleWriteTab.tsx New “Write/Edit” tab owning the prompt form + submit.
src/pages/workspace/rules/AgentRules/AddAgentRuleSuggestionsTab.tsx New “Suggestions” tab UI: search, select card, concierge/help, next.
src/pages/workspace/rules/AgentRules/AddAgentRulePage.tsx Converts the add rule page to a tabbed flow + draft prefill wiring.
src/ONYXKEYS.ts Adds SUGGESTED_AGENT_RULES Onyx key + type mapping.
src/libs/PolicyRulesUtils.ts Adds getSuggestedAgentRuleIcon() and icon rule constants.
src/languages/zh-hans.ts Adds/updates copy for the new tabbed flow.
src/languages/pt-BR.ts Adds/updates copy for the new tabbed flow.
src/languages/pl.ts Adds/updates copy for the new tabbed flow.
src/languages/nl.ts Adds/updates copy for the new tabbed flow.
src/languages/ja.ts Adds/updates copy for the new tabbed flow.
src/languages/it.ts Adds/updates copy for the new tabbed flow.
src/languages/fr.ts Adds/updates copy for the new tabbed flow.
src/languages/es.ts Adds/updates copy for the new tabbed flow.
src/languages/en.ts Adds/updates copy for the new tabbed flow.
src/languages/de.ts Adds/updates copy for the new tabbed flow.
src/hooks/useSuggestedAgentRules.ts Hook to read suggested rules + loading state from Onyx.
src/CONST/index.ts Adds agent-rule tab constants + Sentry label for suggested-rule cards.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/pages/workspace/rules/AgentRules/AddAgentRuleSuggestionsTab.tsx Outdated
Comment thread src/pages/workspace/rules/AgentRules/AddAgentRuleSuggestionsTab.tsx Outdated
Comment thread src/languages/en.ts
Comment thread tests/unit/getSuggestedAgentRuleIconTest.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8a845696ee

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/pages/workspace/rules/AgentRules/AddAgentRuleSuggestionsTab.tsx Outdated
Comment thread src/pages/workspace/rules/AgentRules/AddAgentRuleSuggestionsTab.tsx
Comment thread src/pages/workspace/rules/AgentRules/AddAgentRuleWriteTab.tsx
Comment thread src/pages/workspace/rules/AgentRules/AddAgentRuleSuggestionsTab.tsx Outdated
@samranahm

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cb4cd9b0bb

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/hooks/useSuggestedAgentRules.ts

@mananjadhav mananjadhav left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@samranahm I've reviewed the PR thoroughly. I've marked some important comments that should be addressed for sure.

Comment thread src/hooks/useSuggestedAgentRules.ts Outdated
Comment thread src/languages/de.ts
Comment thread src/languages/en.ts
*/
function getAgentRuleSuggestions(policyID: string | undefined) {
if (!policyID) {
Log.warn('Invalid params for getAgentRuleSuggestions', {policyID});

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nab: Do we need to clear the key on this invalid case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nope, we only set IS_LOADING_AGENT_RULE_SUGGESTIONS after the policyID check, so the invalid case never turns loading spinner on. So nothing to clear there.

{
onyxMethod: Onyx.METHOD.MERGE,
key: ONYXKEYS.IS_LOADING_AGENT_RULE_SUGGESTIONS,
value: true,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

important: Will this cause any infinite spinner when the user goes offline?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

IS_LOADING_AGENT_RULE_SUGGESTIONS flag is cleared via successData/failureData when the request completes, but I think we shouldn’t fire the fetch while offline in the first place. So we can follow the same pattern as PreviewMatchesPage skip getAgentRuleSuggestions() when isOffline. wyt

Screenshot 2026-07-13 at 8 39 57 AM

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yes I think that would be better. @yuwenmemon wdyt?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@yuwenmemon We have two options here

  1. Always use FullPageOfflineBlockingView (“You appear to be offline.” / “This feature requires an active internet connection.”), even if suggestions are already cached in Onyx, same behaviour as PreviewMatchesPage.

  2. Only show the offline empty state when there’s no cached data and we need to call getAgentRuleSuggestions. If suggestions are already loaded, keep the list usable offline. (our current approach) Here's how it looks like

Screenshot 2026-07-13 at 9 12 10 AM

Which one do you prefer?

Comment thread src/pages/workspace/rules/AgentRules/AddAgentRuleWriteTab.tsx Outdated
Comment thread tests/unit/getSuggestedAgentRuleIconTest.ts Outdated
Comment thread tests/unit/getSuggestedAgentRuleIconTest.ts
Comment thread tests/ui/AddAgentRuleSuggestionsTabTest.tsx Outdated
Comment thread tests/ui/AddAgentRuleSuggestionsTabTest.tsx
@mananjadhav

mananjadhav commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator

UI Testing:

  1. The cursor seems to be touching the edge of the border of TextInput and no placeholder text?
image
  1. There should be some padding between the pills.
image
  1. Comment may be for @Expensify/design. Should the second tab name be Edit?

  2. Should there be more padding for the no results content?

image
  1. As I mentioned in the review as well. This disclaimer is missing in the new flow. It exists in the Edit flow as well as the old Add flow.
image
  1. The length of the text input is not covering full height. Question for @Expensify/design too as the original video matches the PR body.
image image
  1. The scroll position and the selected item is lost when we switch to Edit tab without clicking next.
web-list-scroll-back.mov
  1. The button should be Save in the second tab Edit.
web-button-save.mov
  1. Similar to point no. 7, we're losing the filters on tab change too. Need to confirm with @Expensify/design.
web-no-filter.mov
  1. Switching from offline mode to online mode with the Add Rules screen open, doesn't load the suggestions. We need to reopen the tab/refresh.
web-offline-to-online.mov

@yuwenmemon

Copy link
Copy Markdown
Contributor

@samranahm you have some tests failing

@samranahm

Copy link
Copy Markdown
Contributor Author

Looking into this.

@samranahm

Copy link
Copy Markdown
Contributor Author

@yuwenmemon @mananjadhav PR ready for review.

@github-actions

Copy link
Copy Markdown
Contributor

🚧 yuwenmemon has triggered a test Expensify/App build. You can view the workflow run here.

@mananjadhav

Copy link
Copy Markdown
Collaborator

Reviewing this now.

@shawnborton

Copy link
Copy Markdown
Contributor

Yup, agree with Danny's suggestion to use the super simple text under the input for no search results. Thanks for moving the Concierge icon up to the header as well.

@mananjadhav

Copy link
Copy Markdown
Collaborator

@samranahm Is this handled? and can we please resolve the conflicts?

@samranahm

Copy link
Copy Markdown
Contributor Author

@mananjadhav Yes it has been resolved, resolving merge conflicts.

@samranahm

Copy link
Copy Markdown
Contributor Author

Adding offline test to match the current offline behaviour.

@samranahm

Copy link
Copy Markdown
Contributor Author

@mananjadhav PR ready for review, please take a look.

@samranahm

Copy link
Copy Markdown
Contributor Author

The scroll position and the selected item is lost when we switch to Edit tab without clicking next.

@mananjadhav We actually need to fix this because even if we click the next button and switch back to Suggested tab via tab selector we lost the selected item anyway, fixing it asap.

… to preserve selection and scroll state during tab switches.
@samranahm

Copy link
Copy Markdown
Contributor Author

@mananjadhav All yours.

@mananjadhav

mananjadhav commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

@samranahm I think we have 2 bugs. One of them I am able to reproducible every time and second unreliably but I think it exists.

useEffect(() => {
    Tab.setSelectedTab(CONST.TAB.AGENT_RULE_TAB_TYPE, CONST.TAB.AGENT_RULE.SUGGESTIONS);
    if (!isOffline) {
        getAgentRuleSuggestions(policyID);
    }
    return () => clearDraftValues(ONYXKEYS.FORMS.ADD_AGENT_RULE_FORM);
}, [policyID, isOffline]);

  1. isOffline is now in the deps, and the cleanup clears the form draft. Effect cleanups run on every dep change, so if connectivity flips, while the user is typing, the draft is cleared mid-edit. I am unable to reproduce this reliably.

  2. There's a double discard modal. clearDraftValues is async (Onyx), but goBack() dispatches immediately`

const leavePage = () => {
    clearDraftValues(ONYXKEYS.FORMS.ADD_AGENT_RULE_FORM);
    Navigation.goBack();
web-discard-modal.mov

if (!isOffline) {
getAgentRuleSuggestions(policyID);
}
return () => clearDraftValues(ONYXKEYS.FORMS.ADD_AGENT_RULE_FORM);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

important: Raised a bug question here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, cleanup is tied to isOffline, so network connectivity flips clears the draft mid-edit. Let me impliment draft cleanup on unmount only.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can reliably produce this bug,

  1. Select a suggestion from list and press Next
  2. On edit tab flip the network state (turn on/off "Force offline")
  3. Switch to suggested tab via tab selector
  4. Switch back to Edit tab > Draft gone

Fixed this

};

const leavePage = () => {
clearDraftValues(ONYXKEYS.FORMS.ADD_AGENT_RULE_FORM);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

important: Raised a bug here. Discard shows twice.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agree, the manual leave modal conflict with useDiscardChangesConfirmation because clearDraftValues is async and goBack() ran immediately. Back now just calls Navigation.goBack() so the hook owns a single discard prompt.

const handleKeyPress = (e: TextInputKeyPressEvent | KeyboardEvent) => {
if (!('key' in e)) {
useEffect(() => {
Tab.setSelectedTab(CONST.TAB.AGENT_RULE_TAB_TYPE, CONST.TAB.AGENT_RULE.SUGGESTIONS);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

question: activeTab is local state now, and nothing reads SELECTED_TAB + AGENT_RULE_TAB_TYPE anymore, right?. These Tab.setSelectedTab writes, are these needed or can be removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, activeTab is local now and nothing reads SELECTED_TAB + AGENT_RULE_TAB_TYPE, so those writes are not required, removing them.

…ggestions

# Conflicts:
#	src/languages/de.ts
#	src/languages/en.ts
#	src/languages/es.ts
#	src/languages/fr.ts
#	src/languages/it.ts
#	src/languages/ja.ts
#	src/languages/nl.ts
#	src/languages/pl.ts
#	src/languages/pt-BR.ts
#	src/languages/zh-hans.ts
#	src/pages/workspace/rules/AgentRules/AddAgentRulePage.tsx
@samranahm

Copy link
Copy Markdown
Contributor Author

@mananjadhav All yours.

Comment thread src/languages/ja.ts
agentCreatedTitle: 'RuleBot がワークスペースに追加されました!',
agentCreatedDescription: (agentsRoute: string) =>
`<muted-text>エージェント ルールを適用するために、エージェントを作成し、ワークスペースの管理者として追加しました。<br><br>エージェントの詳細は <a href="${agentsRoute}">「アカウント」&gt;「エージェント」</a> で編集できます。</muted-text>`,
suggestionsTab: 'おすすめ',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

question: Are we sure the translation is correct?

/** Higher priority wins when multiple rules match the same suggestion. */
priority: number;

/** keywords matched against suggestion id + title */

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/** keywords matched against suggestion id + title */
/** Keywords matched against suggestion id + title */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants