Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions .agents/skills/tui-development/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,16 @@ fn draw_detail_popup(frame: &mut Frame<'_>, data: &MyData, area: Rect, theme: &T
Always show a y/n confirm dialog before delete, stop, or other irreversible operations.

```
Delete sandbox 'my-sandbox'? [y] Confirm [Esc] Cancel
Delete sandbox 'my-sandbox'?
Workspace: team-a
Sandbox ID: my-sandbox-id

[y] Confirm [Esc] Cancel
```

The `confirm_delete` flag in `App` gates destructive key handling — while true, only `y`, `n`, and `Esc` are processed.
Pressing `d` captures the sandbox name, workspace, and ID shown in the dialog.
Background refreshes do not change what `y` confirms. Press `n` or `Esc` to
cancel. The TUI refuses to open confirmation when the sandbox ID is missing.

### CLI parity

Expand All @@ -320,7 +326,7 @@ TUI actions should parallel `openshell` CLI commands so users have familiar ment
| CLI Command | TUI Equivalent |
| --- | --- |
| `openshell sandbox list` | Sandbox table on Dashboard |
| `openshell sandbox delete <name>` | `[d]` on sandbox detail, then `[y]` to confirm |
| `openshell sandbox delete --id <id>` | `[d]` on sandbox detail, then `[y]` to confirm. A gateway that supports conditional deletion refuses to delete a same-name replacement; older gateways ignore the ID condition. |
| `openshell sandbox create` | `[c]` on sandbox panel to open create form |
| `openshell sandbox connect` | `[s]` on sandbox policy view to launch SSH shell |
| `openshell logs <name>` | `[l]` on sandbox detail to open log viewer |
Expand Down Expand Up @@ -488,6 +494,7 @@ use openshell_core::proto::{
name: sandbox_name,
workspace_scope: Some(workspace_selector(workspace)),
allow_missing: true,
expected_sandbox_id: Some(sandbox_id),
..Default::default()
};
```
Expand Down
117 changes: 105 additions & 12 deletions crates/openshell-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1780,12 +1780,21 @@ enum SandboxCommands {
#[command(help_template = LEAF_HELP_TEMPLATE, next_help_heading = "FLAGS")]
Delete {
/// Sandbox names.
#[arg(required_unless_present = "all", num_args = 1.., value_name = "NAME", add = ArgValueCompleter::new(completers::complete_sandbox_names))]
#[arg(required_unless_present_any = ["all", "id"], num_args = 1.., value_name = "NAME", add = ArgValueCompleter::new(completers::complete_sandbox_names))]
names: Vec<String>,

/// Delete all sandboxes.
#[arg(long, conflicts_with = "names")]
all: bool,

/// Delete only if the name still resolves to this sandbox ID. Fails
/// instead of deleting a same-name replacement. Requires one NAME.
#[arg(long = "expected-id", value_name = "ID", conflicts_with = "all")]
expected_id: Option<String>,

/// Delete the sandbox with this ID, never a same-name replacement.
#[arg(long, value_name = "ID", conflicts_with_all = ["names", "all", "expected_id"])]
id: Option<String>,
},

/// Stop a sandbox while preserving its workspace.
Expand Down Expand Up @@ -3071,7 +3080,7 @@ async fn run_async() -> Result<()> {
}
}
};
if run::stop_forward(&workspace, &name, port)? {
if run::stop_forward(&workspace, &name, port, None)? {
eprintln!(
"{} Stopped forward of port {port} for sandbox {name}",
"✓".green().bold(),
Expand Down Expand Up @@ -3854,16 +3863,33 @@ async fn run_async() -> Result<()> {
)
.await?;
}
SandboxCommands::Delete { names, all } => {
run::sandbox_delete(
endpoint,
&names,
all,
&cli.workspace,
&tls,
&ctx.name,
)
.await?;
SandboxCommands::Delete {
names,
all,
expected_id,
id,
} => {
if let Some(id) = id {
run::sandbox_delete_by_id(
endpoint,
&id,
&cli.workspace,
&tls,
&ctx.name,
)
.await?;
} else {
run::sandbox_delete(
endpoint,
&names,
all,
expected_id.as_deref(),
&cli.workspace,
&tls,
&ctx.name,
)
.await?;
}
}
SandboxCommands::Stop { name } => {
let name = resolve_sandbox_name(name, &ctx.name, &cli.workspace)?;
Expand Down Expand Up @@ -6017,6 +6043,73 @@ mod tests {
));
}

#[test]
fn sandbox_delete_accepts_expected_id_but_not_with_all() {
let cli = Cli::try_parse_from([
"openshell",
"sandbox",
"delete",
"my-box",
"--expected-id",
"sandbox-observed",
])
.expect("sandbox delete --expected-id should parse");
assert!(matches!(
cli.command,
Some(Commands::Sandbox {
command: Some(SandboxCommands::Delete {
expected_id: Some(ref id),
..
})
}) if id == "sandbox-observed"
));

let result = Cli::try_parse_from([
"openshell",
"sandbox",
"delete",
"--all",
"--expected-id",
"sandbox-observed",
]);
assert!(result.is_err(), "--expected-id and --all should conflict");
}

#[test]
fn sandbox_delete_accepts_id_without_names() {
let cli =
Cli::try_parse_from(["openshell", "sandbox", "delete", "--id", "sandbox-observed"])
.expect("sandbox delete --id should parse without a name");
assert!(matches!(
cli.command,
Some(Commands::Sandbox {
command: Some(SandboxCommands::Delete {
id: Some(ref id),
..
})
}) if id == "sandbox-observed"
));

for conflicting in [
vec!["openshell", "sandbox", "delete", "my-box", "--id", "x"],
vec!["openshell", "sandbox", "delete", "--all", "--id", "x"],
vec![
"openshell",
"sandbox",
"delete",
"--id",
"x",
"--expected-id",
"y",
],
] {
assert!(
Cli::try_parse_from(&conflicting).is_err(),
"{conflicting:?} should conflict"
);
}
}

#[test]
fn sandbox_list_json_conflicts_with_ids() {
let result = Cli::try_parse_from(["openshell", "sandbox", "list", "-o", "json", "--ids"]);
Expand Down
Loading