プロンプトのカスタマイズ機能を作りたいです。 実現方法としては、有名なstarshipをサポートすることです。 starshipコマンドが存在し、且つ…
- User
プロンプトのカスタマイズ機能を作りたいです。 実現方法としては、有名なstarshipをサポートすることです。 starshipコマンドが存在し、且つ
~/.config/starship.tomlが存在すれば、プロンプトをstarshipのプロンプトに変更できる。 通常はstarship init <shell>で初期用のスクリプトを出力してシェルに設定しますが、現状jarvishはスクリプトを作れる機能がないので、シェル自体がサポートするようにしたいです。まだどうやって実装すべきか分かっていないので、要件定義しながらプランを構築したいです。
Assistant
まず、プロジェクトの概要と現在のプロンプトの仕組みを理解するために、コードベースを調査します。
The user wants to implement Starship prompt customization support in their Jarvis shell project. They want to:
- Detect if the
starshipcommand exists - Check if
~/.config/starship.tomlexists - If both conditions are met, use Starship's prompt instead of the default prompt
They mention that normally
starship init <shell>outputs an initialization script, but since Jarvis doesn't have script execution capability, they want the shell itself to natively support Starship.Let me first read the project overview and explore the codebase to understand how the current prompt system works, then we can plan the implementation.
- Detect if the
Assistant
プロンプトの実装詳細とStarshipの動作をさらに理解するために、いくつかのファイルを確認します。
Now I have a good understanding of the project. Let me also look at some key files more carefully to understand the prompt system and how starship works.
Let me read the current prompt implementation and the config to understand the details better. I also need to understand how
starship promptworks - it generates a prompt string that can be used directly.Key findings:
-
The project uses
reedlinefor the line editor -
JarvisPromptimplementsreedline::Prompttrait -
Current
PromptConfigonly hasnerd_font: bool -
The shell name is "jarvish"
-
There's no existing starship support
For Starship integration, I'd need to detect if the
starshipcommand is available and if a config file exists, then callstarship promptas a subprocess to generate the prompt string instead of using custom rendering. Starship supports right prompts and accepts environment variables likeSTARSHIP_SHELL,STATUS, andCMD_DURATIONto customize the output. The main design questions are whether to make this opt-in or auto-detected, how to handle the shell type, whether the subprocess overhead on every render is acceptable, and how to pass context like exit codes and command duration to starship.-
Assistant
Let me search for more details about how Starship's custom shell integration works, specifically the
starship promptcommand and its arguments.Assistant
The Starship documentation doesn't directly show the
starship promptcommand arguments. Let me check the Starship GitHub README orstarship prompt --helpfor more detail on how to callstarship promptfrom a custom shell.Assistant
Now I have a much clearer picture. Let me also check the
starship promptright prompt flag.Based on my research, here's what I understand about the Starship integration:
starship promptgenerates the left prompt string (with ANSI codes)starship prompt --rightgenerates the right prompt string- Available flags:
--status=<exit_code>- exit status of last command--cmd-duration=<ms>- command duration in milliseconds--terminal-width=<cols>- terminal width--keymap=<mode>- keyboard mode (viins, vicmd, etc.)--jobs=<count>- number of background jobs
For the jarvish implementation, I need to add a starship config option to
PromptConfig, then create or modify the prompt implementation to conditionally use Starship. I'll need to detect starship availability at startup using thewhichcrate, check for the config file at~/.config/starship.toml, set theSTARSHIP_SHELLenvironment variable appropriately, and execute the starship command on each prompt render.The main challenge is that
starship promptspawns a subprocess for every render, which has performance implications, and I need to map Starship's unified output to reedline's trait methods that expect separate left, right, and indicator components. Since Starship outputs the indicator character itself, I'll leaverender_prompt_indicatorempty when Starship is active and usestarship prompt --rightto get the right-side content.Now I'm examining how reedline's Prompt trait works to understand the mapping better, looking at what the existing implementation returns for each method. So the structure matters here—reedline expects the indicator to sit on the same line as the cursor, which means if Starship outputs multiple lines with the indicator at the end, I need to extract that last line and put it in
render_prompt_indicatorwhile everything before it goes inrender_prompt_left. The challenge is parsing Starship's output correctly to split it at the right boundary. Then we need to either:- Put everything before the last line's indicator in
render_prompt_left, and the indicator inrender_prompt_indicator - Or put everything including the indicator in
render_prompt_leftand have an empty indicator
Actually, the simplest approach: Since Starship formats include the indicator (typically
❯from thecharactermodule), we can:- Use
render_prompt_leftfor the Starship output (which may be multi-line and include the indicator) - Return empty string for
render_prompt_indicator
Wait, but reedline places the indicator at the beginning of the input line. If Starship's full output ends with
❯, then reedline would display:code✔ ~/project on main ❯ |cursor hereBut if we put the entire starship output (including
❯) in left prompt and indicator as empty, it might work, though reedline could handle this differently.I think the pragmatic solution is to put the full Starship output in
render_prompt_leftand setrender_prompt_indicatorto an empty string, giving Starship complete control over the prompt display. For the right prompt, I'll usestarship prompt --right.I should also consider the
STARSHIP_SHELLenvironment variable—Starship uses this for shell-specific behavior. Since Starship doesn't recognize "jarvish", setting it to "bash" would be the safest choice for compatibility, similar to how Nushell sets it to "nu".Now I'm planning the implementation structure: adding a
starshipfield toPromptConfigwith options likeenabled: booland other configuration parameters.- User
続けて
Assistant
調査結果が揃いましたので、プランを作成します。
The user says "続けて" (continue). They want me to continue with the research and create a plan. I now have enough information to create a comprehensive plan. Let me summarize what I've learned:
Current State
-
Prompt system:
JarvisPromptimplementsreedline::Prompttrait insrc/cli/prompt/mod.rs -
Config:
PromptConfigonly hasnerd_font: boolinsrc/config/mod.rs -
REPL loop: Uses
reedlinewithself.editor.read_line(&self.prompt)insrc/shell/mod.rs -
Dependencies: Already has
whichcrate for command detection
Now I'm looking at how Starship generates prompts. It outputs the left prompt via
starship promptand right prompt viastarship prompt --right, accepting optional flags like--status,--cmd-duration,--terminal-width,--jobs, and--keymapto provide context, while requiring theSTARSHIP_SHELLenvironment variable to be set.For the integration, I need to decide between two approaches: either add a
starshipfield to the[prompt]config section and haveJarvisPromptconditionally delegate to Starship when enabled, or create a separateStarshipPromptstruct that implementsreedline::Promptdirectly. The first option keeps things simpler by maintaining a single Prompt implementation, while the second gives cleaner separation but adds complexity. I'll also need to detect if Starship is installed using thewhichcrate, pass the appropriate shell identifier, and handle context passing for status codes and command duration on each render, which means spawning a subprocess every time the prompt displays.Looking at how
Shellactually uses the prompt—callingJarvisPrompt::new(),refresh_git_status(),update_config(), and passing it to the editor—switching to a trait object would lose access to those specific methods. So I'm leaning toward keepingJarvisPromptas the concrete type and adding conditional logic inside it to delegate to Starship when configured, rather than trying to abstract it away.For detection, I need both conditions met: the
starshipcommand must exist in PATH and~/.config/starship.tomlmust be present. I'll add a config option likestarship = "auto"(default) to auto-detect based on these conditions, withtrueto force enable andfalseto disable.Actually, keeping it simpler makes more sense—I'll default to
starship = falseand when enabled, check both prerequisites before falling back to the builtin prompt with a warning if either condition fails. I also need to handle thestarship promptcommand itself, which requires passing the exit status, command duration, and terminal width, so I'll need to track execution time in addition to the exit code.For the implementation, I'm planning to add the
starshipconfig field, create a new Starship prompt module, add detection logic in the shell initialization, and update the documentation. Since jarvish is POSIX-compatible, I can setSTARSHIP_SHELL=bashwhen invoking Starship to get appropriate shell behavior.Actually, I need to reconsider the
STARSHIP_SHELLenvironment variable more carefully. Since reedline handles ANSI rendering directly rather than using bash-style escape sequences, setting it tobashmight cause Starship to wrap codes in a way that breaks things. If I leave it unset, Starship should output raw ANSI sequences that reedline can handle properly, similar to how Nushell sets it to"nu"for its own shell support.For the implementation, I'm calling
starship promptas a subprocess with the exit status, command duration, and terminal width as arguments, then capturing the ANSI-colored output directly. The main concern is performance—Starship can take 20-200ms to run, but since this happens withinblock_in_place, it should be fine for now. I'll also need to track command execution time by recording start and end times, then storing the duration alongside the exit code so I can pass it to Starship on the next prompt render.Looking at the reedline Prompt trait, I need to implement several methods:
render_prompt_leftandrender_prompt_rightwill call Starship with appropriate flags, whilerender_prompt_indicatorshould return empty since Starship already includes the indicator in its output. Forrender_prompt_multiline_indicator, I'll use Starship's continuation prompt. The key design decisions are making Starship opt-in via a config field, using an enum to wrap the two prompt variants, and deciding whether to setSTARSHIP_SHELLor leave it empty—I'm leaning toward leaving it empty to get raw ANSI output without shell-specific wrappers.I also need to track
cmd_durationand create a new module atsrc/cli/prompt/starship.rs. The user's comment confirms we're building native Starship support directly into jarvish rather than relying onstarship initscripts, since jarvish doesn't have script generation capabilities. Starship's init scripts essentially set upPROMPT_COMMANDto callstarship promptwith the right flags and handle duration tracking—we're implementing that logic directly.When users toggle
starship = true/falsein config and runsource, the prompt needs to switch between Jarvis and Starship modes, which means the enum approach works fine since we can just reassign the prompt. I'm also considering whether to support theSTARSHIP_CONFIGenvironment variable to let users specify an alternative config path, matching standard Starship behavior.-
- User
<attached_files>
<code_selection path="file:///Users/mad-tmng/.cursor/plans/starship_prompt_integration_9997861c.plan.md" lines="1-104"> 1|--- 2|name: Starship Prompt Integration 3|overview: jarvish にネイティブの Starship プロンプト統合機能を追加する。
starshipコマンドの存在と設定ファイルの存在を検出し、starship promptサブコマンドを直接呼び出してプロンプトを描画する。 4|todos: 5| - id: config 6| content: "PromptConfig に starship: bool フィールドを追加し、defaults.rs テンプレートにコメントを追加する" 7| status: pending 8| - id: starship-prompt 9| content: src/cli/prompt/starship.rs を新規作成し、StarshipPrompt 構造体と reedline::Prompt の実装を行う(starship prompt サブプロセス呼び出し) 10| status: pending 11| - id: shell-prompt-enum 12| content: ShellPrompt enum を定義し、JarvisPrompt / StarshipPrompt を統合する Prompt trait 実装と委譲メソッド(refresh_git_status, update_config 等)を追加する 13| status: pending 14| - id: detection 15| content: Shell::new に Starship 検出ロジックを追加(which + starship.toml 存在チェック)し、ShellPrompt の構築を分岐させる 16| status: pending 17| - id: cmd-duration 18| content: コマンド実行時間を計測する仕組みを追加(Arc で Shell と StarshipPrompt を共有、input.rs で計測) 19| status: pending 20| - id: reload-config 21| content: reload_config (source コマンド) で starship フラグ変更時にプロンプト切り替え対応とサマリー出力の更新 22| status: pending 23| - id: docs 24| content: README.md / docs/README_JA.md に Starship 連携の設定方法と前提条件を記載する 25| status: pending 26|isProject: false 27|--- 28| 29|# Starship プロンプト統合 30| 31|## 背景 32| 33|通常 Starship はstarship init <shell>でシェル初期化スクリプトを生成し、そのスクリプト内でstarship promptを呼ぶ仕組みだが、jarvish はスクリプト実行基盤を持たない。そのため、Nushell と同様に シェル自体がstarship promptを直接呼び出す アプローチを採用する。 34| 35|## 設計方針 36| 37|### 動作条件(すべて満たす必要あり) 38| 39|1.[prompt] starship = trueが設定されている(デフォルト:false、オプトイン) 40|2.starshipコマンドが PATH 上に存在する(whichクレートで検出、既に依存済み) 41|3.starship.tomlが存在する(STARSHIP_CONFIG環境変数 or~/.config/starship.toml) 42| 43|条件を満たさない場合はフォールバックとして従来のJarvisPromptを使用し、警告メッセージを表示する。 44| 45|### アーキテクチャ:ShellPrompt列挙型 46| 47|JarvisPromptと新規StarshipPromptをShellPromptenum でラップし、reedline::Promptを実装する。Shell構造体のpromptフィールドの型をShellPromptに変更する。 48| 49|mermaid 50|graph TD 51| ShellPrompt["ShellPrompt (enum)"] 52| JarvisPrompt["JarvisPrompt (既存)"] 53| StarshipPrompt["StarshipPrompt (新規)"] 54| ShellPrompt -->|"Builtin"| JarvisPrompt 55| ShellPrompt -->|"Starship"| StarshipPrompt 56| ReedlinePrompt["reedline::Prompt trait"] 57| ShellPrompt -.->|"impl"| ReedlinePrompt 58|59| 60|###StarshipPromptの動作 61| 62|starship promptをサブプロセスとして実行し、出力文字列をそのまま reedline に返す。 63| 64|-render_prompt_left()→starship prompt --status=<code> --cmd-duration=<ms> --terminal-width=<cols>65|-render_prompt_right()→starship prompt --right --status=<code> --cmd-duration=<ms> --terminal-width=<cols>66|-render_prompt_indicator()→ 空文字列(Starship がプロンプトインジケータを含むため) 67|-render_prompt_multiline_indicator()→starship prompt --continuation68|-get_prompt_color()→Color::White(Starship 自身が ANSI カラーを出力するため reedline 側の着色は不要) 69| 70|### 環境変数 71| 72|-STARSHIP_SHELLは 設定しない(未設定時 Starship は raw ANSI を出力し、bash の\[...\]等のシェル固有ラッパーが付かない。reedline はこの raw ANSI をそのまま処理可能) 73| 74|### コマンド実行時間の計測 75| 76|starship prompt --cmd-durationに渡すため、コマンド実行時間(ミリ秒)を計測する仕組みを追加する。last_exit_codeと同様にArc<AtomicU64>をShellとStarshipPromptで共有する。 77| 78|## 変更対象ファイル 79| 80|### 新規ファイル 81| 82|-src/cli/prompt/starship.rs-StarshipPrompt構造体とPrompt実装 83| 84|### 既存ファイル(変更) 85| 86|-src/config/mod.rs-PromptConfigにstarship: boolフィールド追加 87|-src/config/defaults.rs- テンプレートにstarshipコメント追加 88|-src/cli/prompt/mod.rs-ShellPromptenum 定義、Prompttrait 実装の委譲、pub mod starship;89|-src/shell/mod.rs- Starship 検出ロジック、promptフィールドの型をShellPromptに変更、cmd_duration計測 90|-src/shell/input.rs- コマンド実行前後の時間計測 91|-docs/README_JA.md/README.md- Starship 連携の説明追加 92| 93|### 設定例 94| 95|toml 96|[prompt] 97|nerd_font = true 98|starship = true # Starship プロンプトを有効化(要: starship コマンド + starship.toml) 99|100| 101|###sourceコマンドでの反映 102| 103|reload_configでstarshipフラグが変わった場合、ShellPromptを入れ替える。Starship 有効化時は再度検出チェックを行う。サマリー出力にstarship: true/falseを追加する。 104| </code_selection></attached_files>
Starship プロンプト統合
Implement the plan as specified, it is attached for your reference. Do NOT edit the plan file itself.
To-do's from the plan have already been created. Do not create them again. Mark them as in_progress as you work, starting with the first one. Don't stop until you have completed all the to-dos.
Assistant
まず、プロジェクト概要と必要なファイルを確認してから、順番に実装を進めます。
The user wants me to implement the Starship prompt integration plan. Let me start by reading the necessary files and then implement step by step.
Let me first read the overview doc as required by the rules, then start implementing.
Assistant
Step 1:
PromptConfigにstarshipフィールドを追加し、デフォルトテンプレートを更新します。Now let me start implementing. First, I'll add the
starshipfield toPromptConfigand update the defaults template.Assistant
次に、モジュールドキュメントの設定例にも
starshipを追加し、テストを更新します。Assistant
テストの
parse_full_configにstarshipを追加します。Assistant
Step 2:
StarshipPromptを実装します。まず既存のプロンプトモジュールの構造を確認します。Assistant
terminal-sizeクレートの有無を確認します。Now I have all the context I need. Let me create the
StarshipPromptstruct. I need to:- Create
src/cli/prompt/starship.rswithStarshipPromptand itsPromptimpl - It needs to hold
last_exit_code: Arc<AtomicI32>andcmd_duration_ms: Arc<AtomicU64> - It calls
starship promptwith appropriate flags
Let me also check what terminal_size crate is available or if there's another way to get terminal width.
- Create
Assistant
terminal-sizeクレートはないですが、既存のlibcで端末幅を取得できます。StarshipPromptを作成します。No
terminal-sizecrate. I can uselibcwhich is already a dependency to get terminal size viaioctl, or usenixwhich is also available. Actually, I can usenix::ioctl_read_bad!or just uselibc::ioctlwithTIOCGWINSZ. Or simpler: I can usereedline's terminal size (which internally uses crossterm). But actually, the simplest approach would be to use theterminal_sizefunction from thenixcrate or just uselibc::winsizeandlibc::ioctl.Let me just go with
libc::ioctldirectly withTIOCGWINSZto get the terminal width.Writing terminal size function...
Now I need to set up the
starship.rsfile and define sentinel values for tracking command duration and exit codes, usingArc<AtomicU64>withu64::MAXas the marker for unmeasured durations.Assistant
Step 3:
ShellPromptenum をsrc/cli/prompt/mod.rsに追加し、JarvisPromptとStarshipPromptを統合します。Assistant
次に、テストの前に
ShellPromptenum とそのPrompt実装を追加します。Assistant
Step 4:
Shell::newに Starship 検出ロジックを追加し、promptのフィールド型をShellPromptに変更します。shell/mod.rsを更新します。Assistant
Shell構造体のインポートとフィールドを更新します。Now I need to update
shell/mod.rsto:- Change the import from
JarvisPrompttoShellPrompt - Change the
promptfield type fromJarvisPrompttoShellPrompt - Add the Starship detection logic in
Shell::new - Add
cmd_duration_msfield
Let me do this step by step. I'll also handle the
reload_configin the same step since it's closely related.- Change the import from
Assistant
次に
Shell構造体のフィールドを更新します。Assistant
次に
Shell::newメソッドのプロンプト初期化部分を Starship 検出ロジックに差し替えます。Assistant
Selfの初期化ブロックにcmd_duration_msを追加します。Assistant
次に、
apply_exportsメソッドの後にbuild_promptとdetect_starshipヘルパーメソッドを追加します。Assistant
Step 5: コマンド実行時間の計測を
input.rsに追加します。コマンド実行の前後でInstantを使って計測し、cmd_duration_msに格納します。Assistant
input.rsにコマンド実行時間の計測を追加します。Now I need to add time measurement in
input.rs. I need to:- Import
InstantandAtomicU64/Ordering - Before command execution, record the start time
- After execution, compute the duration and store it in
self.cmd_duration_ms
The tricky part is that the execution happens in different branches (Command vs NaturalLanguage). I need to wrap the execution measurement around the whole block. Let me add
Instant::now()before the match and compute after.Also, I need to import
CMD_DURATION_NONEto reset on non-command paths (like builtins).I think I should measure timing consistently across all execution paths, including builtins, even though they're nearly instant. I'll wrap the match expression with timing to capture the duration right before and after execution starts.
- Import
Assistant
次に、コマンド実行部分を時間計測で囲みます。
Assistant
ビルトインコマンド実行時は実行時間をリセットして、Starship の
cmd_durationに不適切な値が残らないようにします。Assistant
Step 6:
reload_configを更新して、starshipフラグ変更時のプロンプト切り替えとサマリー出力を反映します。Assistant
次にサマリー出力に
starship情報を追加します。Assistant
フォーマット引数に
config.prompt.starshipを追加します。Assistant
ビルドを確認します。
Assistant
ビルドは成功しました。
update_configが未使用になった警告があります。reload_configがプロンプト全体を再構築するようになったため、不要なupdate_configメソッドを削除します。The compilation succeeds. There are 2 warnings about
update_configbeing unused - this is because we changedreload_configto usebuild_promptinstead ofupdate_config. The method is no longer called. However, it might still be useful for future use, but since the current code doesn't use it, I should either remove it or mark it with#[allow(dead_code)]. Actually, since we replaced the whole prompt inreload_confignow (viabuild_prompt), theupdate_configmethod on bothJarvisPromptandShellPromptis indeed dead code.I'll remove
ShellPrompt::update_configsince it's the public-facing wrapper that's now unnecessary, whileJarvisPrompt::update_configis truly dead code too given that we're rebuilding the entire prompt on source.Assistant
再度ビルド確認します。
Assistant
警告なしでコンパイルが通りました。テストも実行して確認します。
Assistant
全 403 テストがパスしました。
Assistant
Step 7: ドキュメントを更新します。まず既存のドキュメントを確認します。
Assistant
両方の README の
[prompt]セクションに Starship 連携の説明を追加します。I need to add Starship integration docs to both README files. I'll add a section about the Starship prompt in the configuration section, specifically in the
[prompt]config section.Assistant
次に、セットアップセクションの末尾に Starship 連携の詳細セクションを追加します。
Assistant
最後にリントと最終ビルド確認を行います。
Assistant
clippy も警告なし。変更されたファイルのリントも確認します。
Assistant
すべてのタスクが完了しました。実装の概要をまとめます。
実装サマリー
変更ファイル一覧
ファイル 変更内容 src/config/mod.rsPromptConfigにstarship: boolフィールド追加(デフォルト:false)src/config/defaults.rsテンプレートに starshipコメント追加src/cli/prompt/starship.rs(新規)StarshipPrompt構造体。starship promptをサブプロセスとして実行し、--status/--cmd-duration/--terminal-widthを渡すsrc/cli/prompt/mod.rsShellPromptenum(Builtin/Starship)を追加。reedline::Promptの委譲実装src/shell/mod.rsbuild_prompt()/detect_starship()追加。cmd_duration_ms: Arc<AtomicU64>フィールド追加。reload_configでプロンプト再構築対応src/shell/input.rsコマンド実行時間の計測( Instantで計測、cmd_duration_msに格納)README.mdStarship 連携セクション追加 docs/README_JA.mdStarship 連携セクション追加(日本語) 動作の流れ
- 設定:
[prompt] starship = trueをconfig.tomlに設定 - 検出: 起動時に
which("starship")+~/.config/starship.toml(orSTARSHIP_CONFIG)の存在チェック - 描画: 毎プロンプトで
starship prompt --status=<code> --cmd-duration=<ms> --terminal-width=<cols>を実行し、ANSI 出力をそのまま reedline に返却 - フォールバック: 条件未達成時は警告を出してビルトインプロンプトを使用
source対応: 設定変更時にプロンプト全体を再構築(Starship ↔ Builtin の動的切り替え可能)
- 設定: