Skip to content

[Bug]: pi-fff registers tools before startup mode is known #792

Description

@XWIlluDelu

What happens

pi-fff resolves its startup options and registers its tools while the extension is loading. At that point Pi has registered the extension flags, but has not populated their values yet. Saved fff-mode entries arrive later, in session_start, after the tool names have already been chosen.

On current main (be2dd8d), an isolated Pi session shows both sides of the problem:

$ pi --fff-mode override
/fff-mode
Current mode: 'tools-and-ui' (flag: override)

The active extension tools are still ffgrep and fffind, rather than the expected grep and find overrides.

A session with a saved override selection has the opposite mismatch:

Current mode: 'override' (flag: unset)
Active extension tools: ffgrep, fffind

This is the mismatch noted in the review of #790: #790 (comment)

The timing also affects the other public CLI flags. The database paths and scan options call the same getConfigValue() helper before Pi makes flag values available, so their CLI values are skipped during initial construction.

Suggested fix

Keep flag registration where it is, but defer startup resolution and tool registration until session_start:

  1. Resolve the five startup options after Pi has populated the flags.
  2. Restore the saved session mode, preserving the current session-persistence behavior.
  3. Create the finder factories and register the tools from that final state.
  4. Explicitly activate the dynamically registered tool names.

For /fff-mode, switches between tools-and-ui and tools-only can remain immediate because their tool names are identical. A switch to or from override should save the selection but leave the reported active mode unchanged until /reload; that avoids another transient mismatch.

I have a focused patch ready on a fork. It keeps the tool definitions in place, queues only their final registration, and covers CLI precedence, saved-mode restoration, tool names, prompt guidelines, and the reload boundary. It passes the 74 pi-fff tests, type checking, formatting, and isolated Pi RPC checks. Happy to open the PR if this direction looks right.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions