Skip to content

CLI agent: scope @-mention autocomplete to the active site path#3338

Open
lezama wants to merge 3 commits intotrunkfrom
cli-autocomplete-basepath-tracks-active-site
Open

CLI agent: scope @-mention autocomplete to the active site path#3338
lezama wants to merge 3 commits intotrunkfrom
cli-autocomplete-basepath-tracks-active-site

Conversation

@lezama
Copy link
Copy Markdown
Contributor

@lezama lezama commented May 4, 2026

Related issues

Follow-up to #3336.

Proposed Changes

When the user picks a different site mid-session via the site picker, the chat editor's @-mention file completion now follows. Today, the CombinedAutocompleteProvider is constructed once at AiChatUI startup with process.cwd() and is never updated, so completion stays anchored to the launch directory regardless of which site is active.

  • New private updateAutocompleteBasePath() on AiChatUI. Picks _activeSite.path for local sites, falls back to a captured initialCwd (the launch cwd) for no-site and remote-site cases — remote sites have no local files to complete against.
  • pi-tui's CombinedAutocompleteProvider exposes basePath only via the constructor — there's no public setter — so the helper replaces the whole provider on each call. The provider has no observable state beyond config, so reconstruction is cheap.
  • Hook into the three site-mutation paths: the activeSite setter, setActiveSite, and clearActiveSite. The constructor also now goes through the helper instead of an inline new CombinedAutocompleteProvider(…, process.cwd()).

Testing Instructions

  1. npm install
  2. npm run typecheck — passes.
  3. npm test -- apps/cli/ai/tests/ui.test.ts — 18 tests pass, including 4 new ones covering the basePath logic.
  4. Build the CLI and exercise the chat:
    npm run cli:build
    cd ~                             # launch from somewhere that is NOT a Studio site
    node /path/to/apps/cli/dist/cli/main.mjs
    
    • Type @ → fuzzy completion is scoped to ~ (the launch cwd). Cancel with Esc.
    • Open the site picker, pick a local site (my-site).
    • Type @ → fuzzy completion is now scoped to ~/Studio/my-site/ and lists files inside the site.
    • Open the picker again, pick a different local site (other-site).
    • Type @ → fuzzy completion now lists files in ~/Studio/other-site/.
    • Open the picker, pick a remote (WordPress.com) site.
    • Type @ → fuzzy completion falls back to ~, since remote sites have no local files.

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?
  • Tests run and pass locally.

Comment thread apps/cli/ai/ui.ts
const { announce = true, emitEvent = true } = options;
this._activeSite = site;
this.editor.activeSiteName = site.name;
this.activeSite = site;
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.

Is this like an unrelated cleanup or something?

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.

Adjacent dedup, not random — it's part of "funnel site mutations through the activeSite setter" in this commit. The setter already does _activeSite = site + editor.activeSiteName = … + updateAutocompleteBasePath(), so setActiveSite/clearActiveSite were duplicating the first two and the original PR added the third in three places. Routing them through the setter means a single source of truth for "what happens when activeSite changes" — future code paths that mutate it can't forget to update the basePath. Happy to split into its own commit if you'd rather.

@lezama lezama marked this pull request as ready for review May 5, 2026 13:29
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.

2 participants