Skip to content

async prompt updating - #18660

Merged
fdncred merged 15 commits into
nushell:mainfrom
philocalyst:async-prompt
Aug 5, 2026
Merged

fdncred merged 15 commits into
nushell:mainfrom
philocalyst:async-prompt

Conversation

@philocalyst

@philocalyst philocalyst commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Description

I added support for async/streaming prompts. Background jobs now have the capabilitiy of pushing segments of the prompt to a live state in an in-place fashion. This will not disturb the line being edited.

The interactive prompt resided fully as owned state within the REPL loop. This prevented interaction with components who lived outside of that loop. I reworked this configuration to be built around a separate state mechanism -- PromptState -- which all prompt updates flow through in a thread-safe way. EngineState now owns it, encapsulated in an arc shared between jobs. Leaving NushellPrompt as a READ-ONLY view, rendering the current state of it on every redraw.

Upon new prompt, PROMPT_COMMAND is re-evaled (rather than keeping the pushed/edited async state, which I'm open to alternative approaches on).

The actual prompt is interacted with through commandline set-prompt that takes these parts (left/right/indicator) as flag arguments, and pushes them as overrides. This keeps PROMPT_COMMAND in place as the fallback/static mechanism, and effectively acts as the "ad-hoc" path. I purposefully didn't include things like vim or completion indicators, but those would be trivial to add.

User-facing changes (Release notes)

Added commandline set-prompt for async prompt updates

  • Added the commandline set-prompt command for ad-hoc updates to a rendered prompt.

Examples:

Stand-in values, with background job spawn:

$env.PROMPT_COMMAND = { $"(ansi green)~(ansi reset)> " }

$env.PROMPT_COMMAND_RIGHT = {
    job spawn {
        let branch = (git branch --show-current | complete | get stdout | str trim)
        commandline set-prompt --right $"(ansi yellow)($branch)(ansi reset)"
    }

    ""  # show nothing on the right until the background job fills it in
}
  Replace the left prompt with a freshly rendered string.
  > job spawn { sleep 1sec; commandline set-prompt $"(ansi green)me> (ansi reset)" }

  Replace the right prompt.
  > job spawn { sleep 1sec; commandline set-prompt --right $"right (date now | format date '%H:%M:%S')" }

  Replace the default/emacs indicator.
  > job spawn { sleep 1sec; commandline set-prompt --indicator $" (char prompt)" }

  Replace the vi insert and normal mode indicators independently.
  > job spawn { sleep 1sec; commandline set-prompt --vi-insert ": " --vi-normal "n " }

  Replace the multiline continuation indicator.
  > job spawn { sleep 1sec; commandline set-prompt --multiline "... " }

  Replace multiple prompt segments in one call.
  > job spawn { sleep 1sec; commandline set-prompt --right "67" --indicator "69" }

  Stream a slow prompt segment in from a background job.
  > job spawn { sleep 1sec; commandline set-prompt $"(git branch --show-current) > " }

Additional notes

closes #18613

  • The alternative to this approach, which I'm kind of foggy on how this could be implemented, but maybe poll the env variable and re-render? I do find this to be more flexible, but that way is more streamlined, and perhaps more consistent if similar mechanisms are pursued.

@philocalyst philocalyst changed the title add is_empty method to Jobs struct async promptin Jul 18, 2026
@github-actions

Copy link
Copy Markdown

Hey, just a bot checking in! You edited files related to the configuration.
If you changed any of the default values or added a new config option, don't forget to update the doc_config.nu which documents the options for our users including the defaults provided by the Rust implementation.
If you didn't make a change here, you can just ignore me.

@fdncred
fdncred marked this pull request as ready for review July 29, 2026 13:02
@github-actions github-actions Bot added A:parser Issues related to parsing A:LSP Language Server Protocol (nu-lsp) labels Jul 29, 2026
@fdncred
fdncred marked this pull request as draft July 29, 2026 13:37
@fdncred fdncred changed the title async promptin async prompt updating Jul 30, 2026
@fdncred
fdncred marked this pull request as ready for review August 1, 2026 00:22
fdncred added a commit that referenced this pull request Aug 2, 2026
Requires nushell/reedline#1136
Related PR (Builds ontop of):
#18660

## Description

This is a follow-up to #18334 (non-blocking completions, merged) and
#18671 (test-infra sync, merged). Those landed the async worker model
(`CompletionResult` Fresh/Stale/Pending) but left... several issues
unresolved. Sorry to all the folks who put up with that on the nightlies
:(

Overarching changes:
- Across prompts we're using a LRU cache for storing and managing the
caches. This is configurable, and default bounded to 100. For many
completions nothing is loaded onto the LRU cache, only the intensive
operations (git checkout, carapace stuff, etc.). Open to dramatically
reducing this number, but it *sure* feels nice when it works.
- Cache work is a lot more robust, we do narrowing and carry always an
"env" for the completor environment, so we have a *rough* idea of when
to complete for the sources that are mostly pure.
- Added completionengine for the death of hardcoded dispatch with a
routing enum. This allowed me to rewrite the completor trait around the
context and fetched types, wiring a lot more logic directly through it.
- Added completionsite and sitekind models for a catch-all way for
resolving the facts of what is under the cursor, which kills maybe fifty
sites of span math (what caused the super annoying completion
duplication)
- *commandline complete --type` now type-checks its argument (previously
accepted any string and could silently no-op) and clamps the cursor to a
valid boundary instead of indexing out of range.
- complete paths is shared between file and directory completions, which
eliminates a panic risk and more manual span constructions.
- 
- **Flag/span plumbing.** `FlagRef` and `Flag::long_name` are adopted
across `nu-parser`/`nu-engine`/`nu-cmd-lang` so flag identity survives
through parsing and into completion and help-text rendering, which
eliminated a lot of re-derive logic.

## User-facing changes (Release notes)

- Added `$env.config.completions.cache_size` (default: `100`) to control
that cap.
- Completion results now persist across prompts instead of being
discarded on every new prompt,.
- Fixed a potential panic when narrowing file/directory completions on a
path containing multi-byte (non-ASCII) characters.
- `commandline complete --type` now validates its `--type` argument and
no longer panics on an out-of-range cursor.
- `use`, `overlay use`, `export use`, `source-env`, `hide-env`, `attr
complete`, and `which` now go through the same completion dispatch as
other builtins, fixing inconsistent/missing completions in a few of them

## Additional Notes
- Can't promise that this eliminates all bugs, just most of them. The
bigger thing it gives us is a more robust framework to fix bugs, going
forward. Will be responsive to anything related to completions, and am
okay with a longer review period before merge. The big things are
covered now, however, with the added tests in this PR.
-

fixes #11211

---------

Co-authored-by: Darren Schroeder <[email protected]>
@philocalyst
philocalyst force-pushed the async-prompt branch 2 times, most recently from e5752c3 to 2242316 Compare August 2, 2026 23:00
@philocalyst

Copy link
Copy Markdown
Contributor Author

@fdncred This is now unblocked!

@fdncred

fdncred commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

@philocalyst not quite. ci is still angry.

@philocalyst

Copy link
Copy Markdown
Contributor Author

Fixed it up, one moment :)

@philocalyst

Copy link
Copy Markdown
Contributor Author

ay there :)

@fdncred

fdncred commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

I wonder if all the prompts should be included? Maybe some can't be? Here's the list. I think it's complete?

  • PROMPT_COMMAND
  • PROMPT_COMMAND_RIGHT
  • PROMPT_INDICATOR
  • PROMPT_INDICATOR_VI_NORMAL
  • PROMPT_INDICATOR_VI_INSERT
  • PROMPT_MULTILINE_INDICATOR
  • TRANSIENT_PROMPT_COMMAND
  • TRANSIENT_PROMPT_COMMAND_RIGHT
  • TRANSIENT_PROMPT_INDICATOR
  • TRANSIENT_PROMPT_INDICATOR_VI_INSERT
  • TRANSIENT_PROMPT_INDICATOR_VI_NORMAL
  • TRANSIENT_PROMPT_MULTILINE_INDICATOR

@fdncred

fdncred commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

The other thing that concerns me about this PR is how it affects OSC133, if at all. I worked on that for a week or so to get right and I don't want to break it and have to figure out how to fix it. We need to keep the semantic prompt working nushell/reedline#1019. I'll try to test with ghostty when the CI is green.

@philocalyst

ghost commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

Let me check, didn't know about that.

@philocalyst

ghost commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

It does look like it's okay with semantic prompts, at least under my testing

@philocalyst

ghost commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

And I'm adding dynmism to the VI indicators, it's not very diffuclt yay

@philocalyst

ghost commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

Okay, so as of now, everything is configurable, including multiline

@fdncred

ghost commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

It would be good to include an example using job spawn in the user-facing changes section for the release notes. Can you do that @philocalyst ?

Also, You might have missed my comment here #18660 (comment)

@philocalyst

ghost commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

Everything should be at least responded to

@philocalyst

ghost commented Aug 3, 2026

Copy link
Copy Markdown
Contributor Author

One thing I will add is that I saw some changes will add a visual mode. I don't know if more modes will come, but right now these changes are sort of out of sync with those modes being added.

@philocalyst

ghost commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Resolved :)

@fdncred

ghost commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

not quite

@fdncred

ghost commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Well, it's mostly green but reverting shell_integration.rs after piepmatz just updated those tests probably isn't ideal. https://github.com/nushell/nushell/pull/18776/changes#diff-75255f62eeca5ecfd74c9e5e5a3b44d2abd71e6cc9b3905f5a3b79e10caeb89e

@philocalyst

ghost commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

oh...

@philocalyst

ghost commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Yeah, I don't think it's reverted? I mean it's different because I changed the signature, but it all checks out to me, what exactly was reverted?

@fdncred

ghost commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Did you look at this PR https://github.com/nushell/nushell/pull/18776/changes#diff-75255f62eeca5ecfd74c9e5e5a3b44d2abd71e6cc9b3905f5a3b79e10caeb89e, specifically shell_integration.rs? It looks like he removed create_test_engine() and you added it back amongst other things.

@philocalyst

ghost commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Ahhh great, they actually caught a bug, too! initially assumed that was a fault of the rebase so accidentally removed some of your changes, my fault @cptpiepmatz :)

@fdncred

ghost commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

I think the OSC133 looks right.
Screenshot 2026-08-04 at 10-56-20

@philocalyst

ghost commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

Good! Yeah I didn't change the output mechanism, just how nu handles state and updates

@fdncred

ghost commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

We need to take a look at performance next. This is the feeback we got. Any ideas @philocalyst ?

his works, I'm just having another issue. Not sure why but nushell appears quite a bit slower to render the prompt compared to other shells. I'll try to launch an investigation of what happens, but at least this is functional with my custom build and adjusted script.

@fdncred
fdncred merged commit 9734414 into nushell:main Aug 5, 2026
@github-actions github-actions Bot added this to the v0.115.0 milestone Aug 5, 2026
@fdncred

ghost commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Landing because we can work on performance separately.

@fdncred fdncred added notes:ready Indicates Ready for Release notes notes:additions Noted in "Additions" section and removed A:LSP Language Server Protocol (nu-lsp) labels Aug 5, 2026
@philocalyst

ghost commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

We need to take a look at performance next. This is the feeback we got. Any ideas @philocalyst ?

his works, I'm just having another issue. Not sure why but nushell appears quite a bit slower to render the prompt compared to other shells. I'll try to launch an investigation of what happens, but at least this is functional with my custom build and adjusted script.

Hm, didn't notice this, but I'm back on a fancy laptop; actually very interesting, if there are any performance cliffs you would still expect them to be small enough to be imperceptible (not that it's okay)...

@fdncred

ghost commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Let's wait for a repro from Jan

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

Labels

A:parser Issues related to parsing notes:additions Noted in "Additions" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow a background job to update the prompt while the line editor is active

2 participants