Skip to content

Commit 1acf3ee

Browse files
authored
refactor: rename binary vp to vt and make program name configurable (#228)
- Rename binary from `vp` to `vt` in Cargo.toml - Support both `vp` and `vt` (and `vpr` shorthand) in nested scripts. ## Details - Rename `SessionCallbacks` → `SessionConfig` with a `program_name: Str` field, making all libraries agnostic about the program name - Add `program_name` to `LabeledReporterBuilder`/`LabeledGraphReporter` and thread it through to `format_compact_summary` so summary output shows the correct binary name - Rename `OwnedSessionCallbacks` → `OwnedSessionConfig` and `as_callbacks()` → `as_config()` - Update all test fixtures, snapshots, and [CLAUDE.md](http://CLAUDE.md) to use `vt`
1 parent 042ab37 commit 1acf3ee

File tree

255 files changed

+720
-710
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

255 files changed

+720
-710
lines changed

CLAUDE.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,19 +74,19 @@ Test fixtures and snapshots:
7474

7575
```bash
7676
# Run a task defined in vite-task.json
77-
vp run <task> # run task in current package
78-
vp run <package>#<task> # run task in specific package
79-
vp run <task> -r # run task in all packages (recursive)
80-
vp run <task> -t # run task in current package + transitive deps
81-
vp run <task> -- --extra --args # pass extra args to the task command
82-
vp run # interactive task selector (fuzzy search)
77+
vt run <task> # run task in current package
78+
vt run <package>#<task> # run task in specific package
79+
vt run <task> -r # run task in all packages (recursive)
80+
vt run <task> -t # run task in current package + transitive deps
81+
vt run <task> -- --extra --args # pass extra args to the task command
82+
vt run # interactive task selector (fuzzy search)
8383

8484
# Built-in commands (run tools from node_modules/.bin)
85-
vp test [args...] # run vitest
86-
vp lint [args...] # run oxlint
85+
vt test [args...] # run vitest
86+
vt lint [args...] # run oxlint
8787

8888
# Cache management
89-
vp cache clean # remove the cache database
89+
vt cache clean # remove the cache database
9090

9191
# Package selection flags
9292
-r, --recursive # select all packages in the workspace
@@ -113,7 +113,7 @@ vp cache clean # remove the cache database
113113
## Key Architecture
114114

115115
- **vite_task** - Main task runner with caching and session management
116-
- **vite_task_bin** - CLI binary (`vp` command) and task synthesizer
116+
- **vite_task_bin** - CLI binary (`vt` command) and task synthesizer
117117
- **vite_task_graph** - Task dependency graph construction and config loading
118118
- **vite_task_plan** - Execution planning (resolves env vars, working dirs, commands)
119119
- **vite_workspace** - Workspace detection and package dependency graph

crates/vite_task/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub mod session;
55

66
// Public exports for vite_task_bin
77
pub use cli::{CacheSubcommand, Command, RunCommand, RunFlags};
8-
pub use session::{CommandHandler, ExitStatus, HandledCommand, Session, SessionCallbacks};
8+
pub use session::{CommandHandler, ExitStatus, HandledCommand, Session, SessionConfig};
99
pub use vite_task_graph::{
1010
config::{
1111
self,

crates/vite_task/src/session/mod.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,10 @@ impl TaskGraphLoader for LazyTaskGraph<'_> {
7979
}
8080
}
8181

82-
pub struct SessionCallbacks<'a> {
82+
pub struct SessionConfig<'a> {
8383
pub command_handler: &'a mut (dyn CommandHandler + 'a),
8484
pub user_config_loader: &'a mut (dyn UserConfigLoader + 'a),
85+
pub program_name: Str,
8586
}
8687

8788
/// The result of a [`CommandHandler::handle_command`] call.
@@ -162,8 +163,10 @@ pub struct Session<'a> {
162163

163164
plan_request_parser: PlanRequestParser<'a>,
164165

166+
program_name: Str,
167+
165168
/// Cache is lazily initialized to avoid `SQLite` race conditions when multiple
166-
/// processes (e.g., parallel `vp lib` commands) start simultaneously.
169+
/// processes (e.g., parallel `vt lib` commands) start simultaneously.
167170
cache: OnceCell<ExecutionCache>,
168171
cache_path: AbsolutePathBuf,
169172
}
@@ -185,11 +188,11 @@ impl<'a> Session<'a> {
185188
/// Returns an error if the current directory cannot be determined or
186189
/// if workspace initialization fails.
187190
#[tracing::instrument(level = "debug", skip_all)]
188-
pub fn init(callbacks: SessionCallbacks<'a>) -> anyhow::Result<Self> {
191+
pub fn init(config: SessionConfig<'a>) -> anyhow::Result<Self> {
189192
let envs = std::env::vars_os()
190193
.map(|(k, v)| (Arc::<OsStr>::from(k.as_os_str()), Arc::<OsStr>::from(v.as_os_str())))
191194
.collect();
192-
Self::init_with(envs, vite_path::current_dir()?.into(), callbacks)
195+
Self::init_with(envs, vite_path::current_dir()?.into(), config)
193196
}
194197

195198
/// Ensures the task graph is loaded, loading it if necessary.
@@ -214,14 +217,10 @@ impl<'a> Session<'a> {
214217
///
215218
/// Returns an error if workspace root cannot be found or PATH env cannot be prepended.
216219
#[tracing::instrument(level = "debug", skip_all)]
217-
#[expect(
218-
clippy::needless_pass_by_value,
219-
reason = "cwd is an Arc that gets cloned internally, pass by value is intentional"
220-
)]
221220
pub fn init_with(
222221
mut envs: FxHashMap<Arc<OsStr>, Arc<OsStr>>,
223222
cwd: Arc<AbsolutePath>,
224-
callbacks: SessionCallbacks<'a>,
223+
config: SessionConfig<'a>,
225224
) -> anyhow::Result<Self> {
226225
let (workspace_root, _) = find_workspace_root(&cwd)?;
227226
let cache_path = get_cache_path_of_workspace(&workspace_root.path);
@@ -235,11 +234,12 @@ impl<'a> Session<'a> {
235234
workspace_path: Arc::clone(&workspace_root.path),
236235
lazy_task_graph: LazyTaskGraph::Uninitialized {
237236
workspace_root,
238-
config_loader: callbacks.user_config_loader,
237+
config_loader: config.user_config_loader,
239238
},
240239
envs: Arc::new(envs),
241240
cwd,
242-
plan_request_parser: PlanRequestParser { command_handler: callbacks.command_handler },
241+
plan_request_parser: PlanRequestParser { command_handler: config.command_handler },
242+
program_name: config.program_name,
243243
cache: OnceCell::new(),
244244
cache_path,
245245
})
@@ -317,6 +317,7 @@ impl<'a> Session<'a> {
317317
Box::new(tokio::io::stdout()),
318318
run_command.flags.verbose,
319319
Some(self.make_summary_writer()),
320+
self.program_name.clone(),
320321
);
321322
self.execute_graph(graph, Box::new(builder)).await.map_err(SessionError::EarlyExit)
322323
}
@@ -688,7 +689,7 @@ impl<'a> Session<'a> {
688689
Err(error) => {
689690
return Err(vite_task_plan::Error::ParsePlanRequest {
690691
error: error.into(),
691-
program: Str::from("vp"),
692+
program: self.program_name.clone(),
692693
args: Arc::default(),
693694
cwd: Arc::clone(&cwd),
694695
});

crates/vite_task/src/session/reporter/labeled.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ pub struct LabeledReporterBuilder {
5959
/// Callback to persist the summary (e.g., write `last-summary.json`).
6060
/// `None` when persistence is not needed (e.g., nested script execution, tests).
6161
write_summary: Option<WriteSummaryFn>,
62+
program_name: Str,
6263
}
6364

6465
impl LabeledReporterBuilder {
@@ -68,13 +69,15 @@ impl LabeledReporterBuilder {
6869
/// - `writer`: Async writer for reporter display output.
6970
/// - `show_details`: Whether to render the full detailed summary.
7071
/// - `write_summary`: Callback to persist the summary, or `None` to skip.
72+
/// - `program_name`: The CLI binary name (e.g. `"vt"`) used in summary output.
7173
pub fn new(
7274
workspace_path: Arc<AbsolutePath>,
7375
writer: Box<dyn AsyncWrite + Unpin>,
7476
show_details: bool,
7577
write_summary: Option<WriteSummaryFn>,
78+
program_name: Str,
7679
) -> Self {
77-
Self { workspace_path, writer, show_details, write_summary }
80+
Self { workspace_path, writer, show_details, write_summary, program_name }
7881
}
7982
}
8083

@@ -87,6 +90,7 @@ impl GraphExecutionReporterBuilder for LabeledReporterBuilder {
8790
workspace_path: self.workspace_path,
8891
show_details: self.show_details,
8992
write_summary: self.write_summary,
93+
program_name: self.program_name,
9094
})
9195
}
9296
}
@@ -101,6 +105,7 @@ pub struct LabeledGraphReporter {
101105
workspace_path: Arc<AbsolutePath>,
102106
show_details: bool,
103107
write_summary: Option<WriteSummaryFn>,
108+
program_name: Str,
104109
}
105110

106111
#[async_trait::async_trait(?Send)]
@@ -177,7 +182,7 @@ impl GraphExecutionReporter for LabeledGraphReporter {
177182
let summary_buf = if self.show_details {
178183
format_full_summary(&summary)
179184
} else {
180-
format_compact_summary(&summary)
185+
format_compact_summary(&summary, &self.program_name)
181186
};
182187

183188
// Persist summary via callback (best-effort, callback handles errors).
@@ -331,6 +336,7 @@ mod tests {
331336
Box::new(tokio::io::sink()),
332337
false,
333338
None,
339+
Str::from("vt"),
334340
));
335341
let mut reporter = builder.build();
336342
reporter.new_leaf_execution(display, leaf_kind, all_ancestors_single_node)

crates/vite_task/src/session/reporter/summary.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ pub fn format_full_summary(summary: &LastRunSummary) -> Vec<u8> {
666666
/// - Single task + cache hit → thin line + "vp run: cache hit, {duration} saved."
667667
/// - Multi-task → thin line + "vp run: {hits}/{total} cache hit ({rate}%), {duration} saved."
668668
/// with optional failure count and `--verbose` hint.
669-
pub fn format_compact_summary(summary: &LastRunSummary) -> Vec<u8> {
669+
pub fn format_compact_summary(summary: &LastRunSummary, program_name: &str) -> Vec<u8> {
670670
let stats = SummaryStats::compute(&summary.tasks);
671671

672672
let is_single_task = summary.tasks.len() == 1;
@@ -681,13 +681,14 @@ pub fn format_compact_summary(summary: &LastRunSummary) -> Vec<u8> {
681681
// Thin line separator
682682
let _ = writeln!(buf, "{}", "---".style(Style::new().bright_black()));
683683

684+
let run_label = vite_str::format!("{program_name} run:");
684685
if is_single_task {
685686
// Single task cache hit
686687
let formatted_total_saved = format_summary_duration(stats.total_saved);
687688
let _ = writeln!(
688689
buf,
689690
"{} cache hit, {} saved.",
690-
"vp run:".style(Style::new().blue().bold()),
691+
run_label.as_str().style(Style::new().blue().bold()),
691692
formatted_total_saved.style(Style::new().green().bold()),
692693
);
693694
} else {
@@ -709,7 +710,7 @@ pub fn format_compact_summary(summary: &LastRunSummary) -> Vec<u8> {
709710
let _ = write!(
710711
buf,
711712
"{} {hits}/{total} cache hit ({rate}%)",
712-
"vp run:".style(Style::new().blue().bold()),
713+
run_label.as_str().style(Style::new().blue().bold()),
713714
);
714715

715716
if stats.total_saved > Duration::ZERO {
@@ -726,8 +727,9 @@ pub fn format_compact_summary(summary: &LastRunSummary) -> Vec<u8> {
726727
let _ = write!(buf, ", {} failed", n.style(Style::new().red()));
727728
}
728729

730+
let last_details_cmd = vite_str::format!("`{program_name} run --last-details`");
729731
let _ = write!(buf, ". {}", "(Run ".style(Style::new().bright_black()));
730-
let _ = write!(buf, "{}", "`vp run --last-details`".style(COMMAND_STYLE));
732+
let _ = write!(buf, "{}", last_details_cmd.as_str().style(COMMAND_STYLE));
731733
let _ = write!(buf, "{}", " for full details)".style(Style::new().bright_black()));
732734
let _ = writeln!(buf);
733735
}

crates/vite_task_bin/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ license.workspace = true
77
rust-version.workspace = true
88

99
[[bin]]
10-
name = "vp"
10+
name = "vt"
1111
path = "src/main.rs"
1212

1313
[dependencies]

crates/vite_task_bin/src/lib.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_hash::FxHashMap;
1010
use vite_path::AbsolutePath;
1111
use vite_str::Str;
1212
use vite_task::{
13-
Command, EnabledCacheConfig, HandledCommand, ScriptCommand, SessionCallbacks, UserCacheConfig,
13+
Command, EnabledCacheConfig, HandledCommand, ScriptCommand, SessionConfig, UserCacheConfig,
1414
get_path_env, plan_request::SyntheticPlanRequest,
1515
};
1616

@@ -71,7 +71,7 @@ fn synthesize_node_modules_bin_task(
7171
}
7272

7373
#[derive(Debug, Parser)]
74-
#[command(name = "vp", version)]
74+
#[command(name = "vt", version)]
7575
pub enum Args {
7676
Lint {
7777
#[clap(trailing_var_arg = true, allow_hyphen_values = true)]
@@ -96,10 +96,10 @@ impl vite_task::CommandHandler for CommandHandler {
9696
command: &mut ScriptCommand,
9797
) -> anyhow::Result<HandledCommand> {
9898
match command.program.as_str() {
99-
"vp" => {}
100-
// `vpr <args>` is shorthand for `vp run <args>`
99+
"vt" | "vp" => {}
100+
// `vpr <args>` is shorthand for `vt run <args>`
101101
"vpr" => {
102-
command.program = Str::from("vp");
102+
command.program = Str::from("vt");
103103
command.args =
104104
iter::once(Str::from("run")).chain(command.args.iter().cloned()).collect();
105105
}
@@ -171,16 +171,17 @@ impl vite_task::loader::UserConfigLoader for JsonUserConfigLoader {
171171
}
172172

173173
#[derive(Default)]
174-
pub struct OwnedSessionCallbacks {
174+
pub struct OwnedSessionConfig {
175175
command_handler: CommandHandler,
176176
user_config_loader: JsonUserConfigLoader,
177177
}
178178

179-
impl OwnedSessionCallbacks {
180-
pub fn as_callbacks(&mut self) -> SessionCallbacks<'_> {
181-
SessionCallbacks {
179+
impl OwnedSessionConfig {
180+
pub fn as_config(&mut self) -> SessionConfig<'_> {
181+
SessionConfig {
182182
command_handler: &mut self.command_handler,
183183
user_config_loader: &mut self.user_config_loader,
184+
program_name: Str::from("vt"),
184185
}
185186
}
186187
}

crates/vite_task_bin/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use vite_task::{
66
EnabledCacheConfig, ExitStatus, Session, UserCacheConfig, get_path_env,
77
plan_request::SyntheticPlanRequest,
88
};
9-
use vite_task_bin::{Args, OwnedSessionCallbacks, find_executable};
9+
use vite_task_bin::{Args, OwnedSessionConfig, find_executable};
1010

1111
#[tokio::main]
1212
async fn main() -> anyhow::Result<ExitCode> {
@@ -18,8 +18,8 @@ async fn main() -> anyhow::Result<ExitCode> {
1818
#[expect(clippy::future_not_send, reason = "Session contains !Send types; single-threaded runtime")]
1919
async fn run() -> anyhow::Result<ExitStatus> {
2020
let args = Args::parse();
21-
let mut owned_callbacks = OwnedSessionCallbacks::default();
22-
let session = Session::init(owned_callbacks.as_callbacks())?;
21+
let mut owned_config = OwnedSessionConfig::default();
22+
let session = Session::init(owned_config.as_config())?;
2323
match args {
2424
Args::Task(parsed) => session.main(parsed).await,
2525
args => {

crates/vite_task_bin/tests/e2e_snapshots/fixtures/associate-existing-cache/snapshots.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
[[e2e]]
44
name = "associate existing cache"
55
steps = [
6-
"vp run script1 # cache miss",
7-
"vp run script2 # cache hit, same command as script1",
6+
"vt run script1 # cache miss",
7+
"vt run script2 # cache hit, same command as script1",
88
"json-edit package.json '_.scripts.script2 = \"print world\"' # change script2",
9-
"vp run script2 # cache miss",
9+
"vt run script2 # cache miss",
1010
]

crates/vite_task_bin/tests/e2e_snapshots/fixtures/associate-existing-cache/snapshots/associate existing cache.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
source: crates/vite_task_bin/tests/e2e_snapshots/main.rs
33
expression: e2e_outputs
44
---
5-
> vp run script1 # cache miss
5+
> vt run script1 # cache miss
66
$ print hello
77
hello
8-
> vp run script2 # cache hit, same command as script1
8+
> vt run script2 # cache hit, same command as script1
99
$ print hellocache hit, replaying
1010
hello
1111

1212
---
13-
vp run: cache hit, <duration> saved.
13+
vt run: cache hit, <duration> saved.
1414
> json-edit package.json '_.scripts.script2 = "print world"' # change script2
1515

16-
> vp run script2 # cache miss
16+
> vt run script2 # cache miss
1717
$ print world ✗ cache miss: args changed, executing
1818
world

0 commit comments

Comments
 (0)