Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
31 changes: 30 additions & 1 deletion go/core/cli/cmd/kagent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"os/signal"
"strconv"
"syscall"

cli "github.com/kagent-dev/kagent/go/core/cli/internal/cli/agent"
Expand All @@ -13,6 +14,8 @@ import (
"github.com/kagent-dev/kagent/go/core/cli/internal/config"
"github.com/kagent-dev/kagent/go/core/cli/internal/profiles"
"github.com/kagent-dev/kagent/go/core/cli/internal/tui"
dbcli "github.com/kagent-dev/kagent/go/core/pkg/cli/db"
"github.com/kagent-dev/kagent/go/core/pkg/migrations"
"github.com/spf13/cobra"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down Expand Up @@ -449,11 +452,37 @@ Examples:
runCmd.Flags().StringVar(&runCfg.ProjectDir, "project-dir", "", "Project directory (default: current directory)")
runCmd.Flags().BoolVar(&runCfg.Build, "build", false, "Rebuild the Docker image before running")

rootCmd.AddCommand(installCmd, uninstallCmd, invokeCmd, bugReportCmd, versionCmd, dashboardCmd, getCmd, initCmd, buildCmd, deployCmd, addMcpCmd, runCmd, mcp.NewMCPCmd(), envdoc.NewEnvCmd())
rootCmd.AddCommand(installCmd, uninstallCmd, invokeCmd, bugReportCmd, versionCmd, dashboardCmd, getCmd, initCmd, buildCmd, deployCmd, addMcpCmd, runCmd, mcp.NewMCPCmd(), envdoc.NewEnvCmd(), newDBCommand())

return rootCmd
}

// newDBCommand builds the `kagent db` command over the built-in migration
// tracks. The vector track is gated on the same DATABASE_VECTOR_ENABLED env
// var the controller reads for --database-vector-enabled, with the same
// default (enabled), so the CLI operates on the tracks the server migrates.
// An invalid value is reported only when a db subcommand actually runs, so
// unrelated commands aren't polluted by warnings during construction.
func newDBCommand() *cobra.Command {
vectorEnabled := true
var envWarning string
if v := os.Getenv("DATABASE_VECTOR_ENABLED"); v != "" {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we somehow read this from the live cluster rather than requiring information from the user. We can use this as a fallback of course

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good question, I will look into that.

@iplay88keys iplay88keys Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have a way to look up the kagent's config. The only issue is that if the kubeconfig is pointing to a Kagent which is attached to a different postgres than you are connecting to via --db-url, the looked-up value of VECTOR_ENABLED could silently differ from what's in postgres. I can't detect a mismatch, but I can print it in the cli output as stderr:

❯ go run ./core/cli/cmd/kagent db migrate status   
resolved vector track from cluster context "kind-cluster": configmap kagent/kagent-controller has DATABASE_VECTOR_ENABLED=false (set DATABASE_VECTOR_ENABLED to override)

9 migration(s) applied, 0 pending
  core: 6 applied (at v6), 0 pending
  vector: 3 applied (at v3), 0 pending

b, err := strconv.ParseBool(v)
if err != nil {
envWarning = fmt.Sprintf("warning: invalid DATABASE_VECTOR_ENABLED=%q; assuming true\n", v)
} else {
vectorEnabled = b
}
}
cmd := dbcli.NewCommand(migrations.BuiltinSources(vectorEnabled)...)
if envWarning != "" {
cmd.PersistentPreRun = func(c *cobra.Command, _ []string) {
fmt.Fprint(c.ErrOrStderr(), envWarning)
}
}
return cmd
}

func runInteractive(cmd *cobra.Command, args []string, cfg *config.Config) {
client := cfg.Client()

Expand Down
43 changes: 43 additions & 0 deletions go/core/pkg/cli/db/db.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Package db hosts the `kagent db` parent command and its subcommands.
// Currently only `migrate` is wired; future siblings attach here.
package db

import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"

"github.com/kagent-dev/kagent/go/core/pkg/cli/db/migrate"
"github.com/kagent-dev/kagent/go/core/pkg/migrations"
)

// NewCommand returns the `db` parent command with `migrate` attached. The
// given sources define the migration tracks the subcommands operate on, in
// orchestrator registration order.
func NewCommand(sources ...migrations.Source) *cobra.Command {
cmd := &cobra.Command{
Use: "db",
Short: "Database operations (migrations, inspection)",
}
cmd.AddCommand(migrate.NewCommand(sources...))

// Hide the root's API-oriented persistent flags from help across the
// entire `db` subtree. They target the kagent server / Kubernetes,
// but db commands talk to Postgres directly via --db-url.
//
// Hidden is a property of the flag itself (shared across the whole
// tree), so we can't flip it permanently. The HelpFunc override
// toggles it for the duration of the help render and restores it
// after. Children of `db` that don't set their own HelpFunc walk the
// parent chain and pick this one up.
cmd.SetHelpFunc(func(c *cobra.Command, args []string) {
for _, name := range []string{"config", "kagent-url", "namespace", "output-format", "timeout", "verbose"} {
if f := c.InheritedFlags().Lookup(name); f != nil {
f.Hidden = true
defer func(f *pflag.Flag) { f.Hidden = false }(f)
}
}
c.Root().HelpFunc()(c, args)
})

return cmd
}
Loading
Loading