Skip to content

Conversation

@toolmantim
Copy link
Contributor

@toolmantim toolmantim commented Jul 16, 2025

Update BK CLI to improve agent use cases, as well as help and examples for human users too.

  • Migrated from Cobra to Kong framework
  • Improved help text for better readability by humans and LLMs
  • Dynamic shell completions with comprehensive flag and subcommand suggestions
  • Better error messages
  • Various improvements to make things more LLM friendly:
    • Non-interactive modes for bk build watch
    • Add bk job logs <job-id> command for viewing individual job logs
    • Add --logs and --failed-only flags to bk build download command
  • New --output flag for all data query commands (deprecated --json)

See UPGRADING.md for upgrade instructions.

Replaces #478

@toolmantim toolmantim requested a review from a team as a code owner July 16, 2025 13:46
@toolmantim toolmantim changed the title Switch CLI from Cobra to Kong framework Improve CLI usability and improve automation cases (e.g. LLMs) Jul 16, 2025
@toolmantim toolmantim changed the title Improve CLI usability and improve automation cases (e.g. LLMs) Improve CLI usability and improve automation cases (e.g. agents/LLMs) Jul 16, 2025
@mcncl
Copy link
Contributor

mcncl commented Jul 16, 2025

@toolmantim that diff 😂 I'll look at this one file at a time, but I'm very excited if this does what it says on the tin

@toolmantim toolmantim force-pushed the kong branch 5 times, most recently from 943ee03 to 27555fb Compare July 16, 2025 23:59
}
req.Header.Set("Accept", "application/json")

// Set custom headers (these can override common headers)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

custom headers support regressed in #447, this includes a fix for that

@toolmantim
Copy link
Contributor Author

@mcncl thanks! Lol yeah, no avoiding the big diff sadly. I just pushed a few final things, including a fix to custom headers. Feel free to update this branch yourself now.

Copy link
Contributor

@scadu scadu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still reading through the PR, but left some initial feedback.

@toolmantim toolmantim force-pushed the kong branch 2 times, most recently from 2dd1052 to 72c2a3e Compare July 18, 2025 11:08
@toolmantim
Copy link
Contributor Author

Related musings that I saw posted today: https://www.notcheckmark.com/2025/07/rethinking-cli-interfaces-for-ai/

I'll give this a really good manual test this week. If you can assist with code reviews, and someone can also give it a quick manual test, we should be good.

@luispadron
Copy link

Was just about to open up an issue to allow --json output when possible (for use in scripts, etc). Would love to see this supported for commands like bk build view and bk artifacts list

toolmantim and others added 11 commits July 24, 2025 22:35
- Migrated from Cobra to Kong framework
- Improved help text for better readability by humans and LLMs
- Dynamic shell completions with comprehensive flag and subcommand suggestions
- Better error messages
- Various improvements to make things more LLM friendly:
  - Non-interactive modes for `bk build watch`
  - Add `bk job logs <job-id>`` command for viewing individual job logs
  - Add `--logs` and `--failed-only` flags to `bk build download` command
- New `--output` flag for all data query commands (deprecated `--json`)

See UPGRADING.md for breaking changes and upgrade instructions.
- Add Bubble Tea TUI support for agent list command (default behavior)
- Add TUI progress bars for agent stop when stopping multiple agents
- Add live refresh mode for build watch command (default behavior)
- Match Cobra's default TUI behavior exactly
- Add basic tests for help text validation

The TUI features now have full parity with the Cobra implementation,
using the same default behavior without requiring additional flags.

Amp-Thread: https://ampcode.com/threads/T-ba73c50b-9366-47dd-8be7-1fbfeb5106a1
Co-authored-by: Amp <[email protected]>
- Agent list: Only show TUI when stdout is a TTY, otherwise show table
- Agent stop: Only show progress bars for multiple agents when TTY available
- Build watch: Only use clear screen refresh when TTY available
- Add fallback behavior for non-TTY environments (CI/CD compatibility)
- Add tests documenting TTY detection behavior

This ensures commands work properly in non-interactive environments
while preserving the rich TUI experience for terminal users.

Amp-Thread: https://ampcode.com/threads/T-ba73c50b-9366-47dd-8be7-1fbfeb5106a1
Co-authored-by: Amp <[email protected]>
- Convert whoami from Cobra to Kong CLI framework
- Add structured output support (JSON, YAML, table)
- Include help text and examples
- Preserve original functionality from main branch

Co-authored-by: Amp <[email protected]>
Amp-Thread-ID: https://ampcode.com/threads/T-9b44beb4-1b27-47f7-b450-8b0b97694529
Co-authored-by: Amp <[email protected]>
Amp-Thread-ID: https://ampcode.com/threads/T-9b44beb4-1b27-47f7-b450-8b0b97694529
Copy link
Contributor

@scadu scadu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few more comments, mostly around possible race conditions and validation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Binary should be removed from the repo.

key := fmt.Sprintf("organizations.%s.api_token", slug)

// Check for deprecated BK_ACCESS_TOKEN and warn if used
legacyToken := os.Getenv("BK_ACCESS_TOKEN")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it lead to a race condition when sync.One is a global, but warning logic depends on env variables that can change between calls?

return m.loadAgents(true)
}

func (m *AgentListModel) loadAgents(isRefresh bool) tea.Cmd {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it could append indefinitely in long-running sessions? Is there a limit or pagination somewhere?

_, err = f.RestAPIClient.Agents.Stop(ctx, org, agentID, a.Force)
})
if spinErr != nil {
errChan <- spinErr
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be another race condition when multiple goroutines write to errChan and reading from shared state? Might be worth looking into https://pkg.go.dev/golang.org/x/sync/errgroup which provides a friendly abstraction over goroutines handling.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have equivalent of that in Kong version?

@mcncl
Copy link
Contributor

mcncl commented Jul 30, 2025

Taking a little tour through this and I can see that there are at least some helpers missing, like bk build new without a default branch just returns a 402, rather than a helpful error re: missing default branch and to use --branch.

I think it's heading down the right path; basic functionality seems to persist, but I think we'd need to fine tooth-comb it.

@toolmantim
Copy link
Contributor Author

thanks @scadu & @mcncl — will update this shortly

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants