cmd

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   "oni3 [directory]",
	Short: "Oni3 — AI agent CLI",
	Long: `Oni3 is a command line interface for AI agents.

Optionally pass a working directory; tools resolve relative paths against it.
The same directory can be given with --cwd/-C.`,
	Version: version.Version,
	Args:    cobra.MaximumNArgs(1),

	RunE: func(cmd *cobra.Command, args []string) error {
		cfg := config.GetConfig()
		name, err := resolveDefaultAgent(cfg)
		if err != nil {
			return err
		}
		return startAgentSession(name)
	},
	PersistentPreRunE: func(cmd *cobra.Command, args []string) error {

		dir := workDir
		if cmd.Name() != "run" {
			d, err := workDirFromArgs(args, workDir)
			if err != nil {
				return err
			}
			dir = d
		}
		if err := enterWorkDir(dir); err != nil {
			return err
		}

		created, err := config.EnsureConfigFile(configPath)
		if err != nil {
			return fmt.Errorf("failed to prepare configuration file: %w", err)
		}
		if created {
			fmt.Fprintf(os.Stderr, "Created a starter configuration at %s\n", configPath)
			fmt.Fprintln(os.Stderr, "Oni3 ships built-in providers: pick one in the provider list to enter an API key and import models. Edit the file only for custom endpoints.")
		}

		cfg, err := config.LoadConfig(configPath)
		if err != nil {
			return fmt.Errorf("failed to load configuration file: %w", err)
		}

		if _, err := ensureBuiltinAgent(cfg); err != nil {
			fmt.Fprintf(os.Stderr, "Note: built-in agent unavailable: %v\n", err)
		}

		go func() {

			ctx := cmd.Context()
			if ctx == nil {
				ctx = context.Background()
			}
			if err := mcp.InitializeGlobalManager(ctx, cfg); err != nil {
				fmt.Fprintf(os.Stderr, "Failed to initialize MCP manager asynchronously: %v\n", err)
			}
		}()

		return nil
	},
}

RootCmd represents the base command when called without any subcommands

Functions

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

func Main

func Main()

Main is the shared entry point for the `oni3` binary. It initializes logging, handles signals and executes the root command.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL