Hide /jail when sandbox is already jailed
/jail and /unjail are mutually exclusive actions, so only show the one that actually applies in the current state.
- commit
- 1030ae584dd090f76e8de9a8ef58c54ee2e5c1cb
- author
- patriceckhart · · 2026-05-11 16:11 UTC
- parent
- 21b88f6
- signature
- unsigned
- refs
- tag: v0.1.76
2 files · +9 -2
M internal/agent/modes/slash_suggest.go +3 -2
| @@ -121,12 +121,13 @@ func (s *slashSuggester) allCatalog() []slashCommand { | |||
| 121 | 121 | // baseCatalog returns the built-in commands visible for the current | |
| 122 | 122 | // interactive state. | |
| 123 | 123 | func (s *slashSuggester) baseCatalog() []slashCommand { | |
| 124 | + | hide := "/unjail" | |
| 124 | 125 | if s.jailed { | |
| 125 | - | return slashCatalog | |
| 126 | + | hide = "/jail" | |
| 126 | 127 | } | |
| 127 | 128 | out := make([]slashCommand, 0, len(slashCatalog)-1) | |
| 128 | 129 | for _, c := range slashCatalog { | |
| 129 | - | if c.Name == "/unjail" { | |
| 130 | + | if c.Name == hide { | |
| 130 | 131 | continue | |
| 131 | 132 | } | |
| 132 | 133 | out = append(out, c) | |
| @@ -121,12 +121,13 @@ func (s *slashSuggester) allCatalog() []slashCommand { | |||||
| 121 | // baseCatalog returns the built-in commands visible for the current | 121 | // baseCatalog returns the built-in commands visible for the current | ||
| 122 | // interactive state. | 122 | // interactive state. | ||
| 123 | func (s *slashSuggester) baseCatalog() []slashCommand { | 123 | func (s *slashSuggester) baseCatalog() []slashCommand { | ||
| 124 | + | hide := "/unjail" | |||
| 124 | if s.jailed { | 125 | if s.jailed { | ||
| 125 | - | return slashCatalog | 126 | + | hide = "/jail" |
| 126 | } | 127 | } | ||
| 127 | out := make([]slashCommand, 0, len(slashCatalog)-1) | 128 | out := make([]slashCommand, 0, len(slashCatalog)-1) | ||
| 128 | for _, c := range slashCatalog { | 129 | for _, c := range slashCatalog { | ||
| 129 | - | if c.Name == "/unjail" { | 130 | + | if c.Name == hide { |
| 130 | continue | 131 | continue | ||
| 131 | } | 132 | } | ||
| 132 | out = append(out, c) | 133 | out = append(out, c) | ||
M internal/agent/modes/slash_suggest_test.go +6 -0
| @@ -8,11 +8,17 @@ func TestSlashSuggesterHidesUnjailUntilJailed(t *testing.T) { | |||
| 8 | 8 | if got := commandNames(s.matches("/unj")); contains(got, "/unjail") { | |
| 9 | 9 | t.Fatalf("/unjail should be hidden while not jailed, got %v", got) | |
| 10 | 10 | } | |
| 11 | + | if got := commandNames(s.matches("/ja")); !contains(got, "/jail") { | |
| 12 | + | t.Fatalf("/jail should be visible while not jailed, got %v", got) | |
| 13 | + | } | |
| 11 | 14 | ||
| 12 | 15 | s.SetJailed(true) | |
| 13 | 16 | if got := commandNames(s.matches("/unj")); !contains(got, "/unjail") { | |
| 14 | 17 | t.Fatalf("/unjail should be visible while jailed, got %v", got) | |
| 15 | 18 | } | |
| 19 | + | if got := commandNames(s.matches("/ja")); contains(got, "/jail") { | |
| 20 | + | t.Fatalf("/jail should be hidden while jailed, got %v", got) | |
| 21 | + | } | |
| 16 | 22 | } | |
| 17 | 23 | ||
| 18 | 24 | func commandNames(cmds []slashCommand) []string { | |
| @@ -8,11 +8,17 @@ func TestSlashSuggesterHidesUnjailUntilJailed(t *testing.T) { | |||||
| 8 | if got := commandNames(s.matches("/unj")); contains(got, "/unjail") { | 8 | if got := commandNames(s.matches("/unj")); contains(got, "/unjail") { | ||
| 9 | t.Fatalf("/unjail should be hidden while not jailed, got %v", got) | 9 | t.Fatalf("/unjail should be hidden while not jailed, got %v", got) | ||
| 10 | } | 10 | } | ||
| 11 | + | if got := commandNames(s.matches("/ja")); !contains(got, "/jail") { | |||
| 12 | + | t.Fatalf("/jail should be visible while not jailed, got %v", got) | |||
| 13 | + | } | |||
| 11 | 14 | ||||
| 12 | s.SetJailed(true) | 15 | s.SetJailed(true) | ||
| 13 | if got := commandNames(s.matches("/unj")); !contains(got, "/unjail") { | 16 | if got := commandNames(s.matches("/unj")); !contains(got, "/unjail") { | ||
| 14 | t.Fatalf("/unjail should be visible while jailed, got %v", got) | 17 | t.Fatalf("/unjail should be visible while jailed, got %v", got) | ||
| 15 | } | 18 | } | ||
| 19 | + | if got := commandNames(s.matches("/ja")); contains(got, "/jail") { | |||
| 20 | + | t.Fatalf("/jail should be hidden while jailed, got %v", got) | |||
| 21 | + | } | |||
| 16 | } | 22 | } | ||
| 17 | 23 | ||||
| 18 | func commandNames(cmds []slashCommand) []string { | 24 | func commandNames(cmds []slashCommand) []string { | ||