Skip to content
Merged
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
80 changes: 80 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,20 @@ $ kortex-cli init /path/to/another-project --runtime fake --agent claude -o json

Exit code: `0` (success)

**Step 3a: Register and start immediately with auto-start flag**

```bash
$ kortex-cli init /path/to/third-project --runtime podman --agent claude -o json --start
```

```json
{
"id": "3c4d5e6f7a8b9098765432109876543210987654321098765432109876543210b"
}
```

Exit code: `0` (success, workspace is running)

**Step 4: List all workspaces**

```bash
Expand Down Expand Up @@ -737,6 +751,57 @@ kortex-cli list
kortex-cli list --storage /tmp/kortex-storage
```

### `KORTEX_CLI_INIT_AUTO_START`

Automatically starts a workspace after registration when using the `init` command.

**Usage:**

```bash
export KORTEX_CLI_INIT_AUTO_START=1
kortex-cli init /path/to/project --runtime podman --agent claude
```

**Priority:**

The auto-start behavior is determined in the following order (highest to lowest priority):

1. `--start` flag (if specified)
2. `KORTEX_CLI_INIT_AUTO_START` environment variable (if set to a truthy value)
3. Default: workspace is not started automatically

**Supported Values:**

The environment variable accepts the following truthy values (case-insensitive):
- `1`
- `true`, `True`, `TRUE`
- `yes`, `Yes`, `YES`

Any other value (including `0`, `false`, `no`, or empty string) will not trigger auto-start.

**Example:**

```bash
# Set auto-start for the current shell session
export KORTEX_CLI_INIT_AUTO_START=1

# Register and start a workspace automatically
kortex-cli init /path/to/project --runtime podman --agent claude
# Workspace is now running

# Override the environment variable with the flag
export KORTEX_CLI_INIT_AUTO_START=0
kortex-cli init /path/to/another-project --runtime podman --agent claude --start
# Workspace is started despite env var being 0
```

**Notes:**

- Auto-starting combines the `init` and `start` commands into a single operation
- Useful for automation scripts where you want workspaces ready to use immediately
- If the workspace fails to start, the registration still succeeds, but an error is returned
- The `--start` flag always takes precedence over the environment variable

## Podman Runtime

The Podman runtime provides a container-based development environment for workspaces. It creates an isolated environment with all necessary tools pre-installed and configured.
Expand Down Expand Up @@ -1491,6 +1556,7 @@ kortex-cli init [sources-directory] [flags]
- `--workspace-configuration <path>` - Directory for workspace configuration files (default: `<sources-directory>/.kortex`)
- `--name, -n <name>` - Human-readable name for the workspace (default: generated from sources directory)
- `--project, -p <identifier>` - Custom project identifier to override auto-detection (default: auto-detected from git repository or source directory)
- `--start` - Start the workspace after registration (can also be set via `KORTEX_CLI_INIT_AUTO_START` environment variable)
- `--verbose, -v` - Show detailed output including all workspace information
- `--output, -o <format>` - Output format (supported: `json`)
- `--show-logs` - Show stdout and stderr from runtime commands (cannot be combined with `--output json`)
Expand Down Expand Up @@ -1524,6 +1590,19 @@ kortex-cli init /path/to/myproject --runtime fake --agent claude --project "my p
kortex-cli init /path/to/myproject --runtime fake --agent claude --workspace-configuration /path/to/config
```

**Register and start immediately:**
```bash
kortex-cli init /path/to/myproject --runtime podman --agent claude --start
```
Output: `a1b2c3d4e5f6...` (workspace ID, workspace is now running)

**Register and start using environment variable:**
```bash
export KORTEX_CLI_INIT_AUTO_START=1
kortex-cli init /path/to/myproject --runtime podman --agent claude
```
Output: `a1b2c3d4e5f6...` (workspace ID, workspace is now running)

**View detailed output:**
```bash
kortex-cli init --runtime fake --agent claude --verbose
Expand Down Expand Up @@ -1676,6 +1755,7 @@ kortex-cli init /tmp/workspace --runtime fake --agent claude
- **Runtime is required**: You must specify a runtime using either the `--runtime` flag or the `KORTEX_CLI_DEFAULT_RUNTIME` environment variable
- **Agent is required**: You must specify an agent using either the `--agent` flag or the `KORTEX_CLI_DEFAULT_AGENT` environment variable
- **Project auto-detection**: The project identifier is automatically detected from git repository information or source directory path. Use `--project` flag to override with a custom identifier
- **Auto-start**: Use the `--start` flag or set `KORTEX_CLI_INIT_AUTO_START=1` to automatically start the workspace after registration, combining `init` and `start` into a single operation
- All directory paths are converted to absolute paths for consistency
- The workspace ID is a unique identifier generated automatically
- Workspaces can be listed using the `workspace list` command
Expand Down
27 changes: 27 additions & 0 deletions pkg/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type initCmd struct {
verbose bool
output string
showLogs bool
start bool
}

// preRun validates the parameters and flags
Expand Down Expand Up @@ -115,6 +116,18 @@ func (i *initCmd) preRun(cmd *cobra.Command, args []string) error {
}
}

// Determine start behavior: if flag is not set to true, check environment variable
if !i.start {
// Check environment variable
if envStart := os.Getenv("KORTEX_CLI_INIT_AUTO_START"); envStart != "" {
// Accept "1", "true", "yes" as truthy values (case-insensitive)
switch envStart {
case "1", "true", "True", "TRUE", "yes", "Yes", "YES":
i.start = true
}
}
}

// Get sources directory (default to current directory)
i.sourcesDir = "."
if len(args) > 0 {
Expand Down Expand Up @@ -215,6 +228,14 @@ func (i *initCmd) run(cmd *cobra.Command, args []string) error {
return outputErrorIfJSON(cmd, i.output, err)
}

// Start the workspace if auto-start is enabled
if i.start {
err = i.manager.Start(ctx, addedInstance.GetID())
if err != nil {
return outputErrorIfJSON(cmd, i.output, err)
}
}

// Handle JSON output
if i.output == "json" {
return i.outputJSON(cmd, addedInstance)
Expand Down Expand Up @@ -283,6 +304,9 @@ kortex-cli init --runtime fake --agent claude --name my-project
# Register with custom project identifier
kortex-cli init --runtime fake --agent goose --project my-custom-project

# Register and start workspace
kortex-cli init --runtime podman --agent claude --start

# Show detailed output
kortex-cli init --runtime fake --agent claude --verbose

Expand All @@ -309,6 +333,9 @@ kortex-cli init --runtime fake --agent claude --show-logs`,
// Add agent flag
cmd.Flags().StringVarP(&c.agent, "agent", "a", "", "Agent name for loading agent-specific configuration (required if KORTEX_CLI_DEFAULT_AGENT is not set)")

// Add start flag
cmd.Flags().BoolVar(&c.start, "start", false, "Start the workspace after registration (can also be set via KORTEX_CLI_INIT_AUTO_START environment variable)")

// Add verbose flag
cmd.Flags().BoolVarP(&c.verbose, "verbose", "v", false, "Show detailed output")

Expand Down
Loading
Loading