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
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ Global flags are defined as persistent flags in `pkg/cmd/root.go` and are availa

The `--storage` flag specifies the directory where kdn stores all its files. The default path is computed at runtime using `os.UserHomeDir()` and `filepath.Join()` to ensure cross-platform compatibility (Linux, macOS, Windows). The default is `$HOME/.kdn` with a fallback to `.kdn` in the current directory if the home directory cannot be determined.

**Environment Variable**: The `KORTEX_CLI_STORAGE` environment variable can be used to set the storage directory path. The flag `--storage` will override the environment variable if both are specified.
**Environment Variable**: The `KDN_STORAGE` environment variable can be used to set the storage directory path. The flag `--storage` will override the environment variable if both are specified.

**Priority order** (highest to lowest):
1. `--storage` flag (if specified)
2. `KORTEX_CLI_STORAGE` environment variable (if set)
2. `KDN_STORAGE` environment variable (if set)
3. Default: `$HOME/.kdn`

To access this value in any command:
Expand Down
52 changes: 26 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -958,14 +958,14 @@ fi

kdn supports environment variables for configuring default behavior.

### `KORTEX_CLI_DEFAULT_RUNTIME`
### `KDN_DEFAULT_RUNTIME`

Sets the default runtime to use when registering a workspace with the `init` command.

**Usage:**

```bash
export KORTEX_CLI_DEFAULT_RUNTIME=fake
export KDN_DEFAULT_RUNTIME=fake
kdn init /path/to/project --agent claude
```

Expand All @@ -974,14 +974,14 @@ kdn init /path/to/project --agent claude
The runtime is determined in the following order (highest to lowest priority):

1. `--runtime` flag (if specified)
2. `KORTEX_CLI_DEFAULT_RUNTIME` environment variable (if set)
2. `KDN_DEFAULT_RUNTIME` environment variable (if set)
3. Error if neither is set (runtime is required)

**Example:**

```bash
# Set the default runtime for the current shell session
export KORTEX_CLI_DEFAULT_RUNTIME=fake
export KDN_DEFAULT_RUNTIME=fake

# Register a workspace using the environment variable
kdn init /path/to/project --agent claude
Expand All @@ -997,14 +997,14 @@ kdn init /path/to/another-project --agent claude --runtime podman
- Supported runtime types depend on the available runtime implementations
- Setting this environment variable is useful for automation scripts or when you consistently use the same runtime

### `KORTEX_CLI_DEFAULT_AGENT`
### `KDN_DEFAULT_AGENT`

Sets the default agent to use when registering a workspace with the `init` command.

**Usage:**

```bash
export KORTEX_CLI_DEFAULT_AGENT=claude
export KDN_DEFAULT_AGENT=claude
kdn init /path/to/project --runtime podman
```

Expand All @@ -1013,14 +1013,14 @@ kdn init /path/to/project --runtime podman
The agent is determined in the following order (highest to lowest priority):

1. `--agent` flag (if specified)
2. `KORTEX_CLI_DEFAULT_AGENT` environment variable (if set)
2. `KDN_DEFAULT_AGENT` environment variable (if set)
3. Error if neither is set (agent is required)

**Example:**

```bash
# Set the default agent for the current shell session
export KORTEX_CLI_DEFAULT_AGENT=claude
export KDN_DEFAULT_AGENT=claude

# Register a workspace using the environment variable
kdn init /path/to/project --runtime podman
Expand All @@ -1037,14 +1037,14 @@ kdn init /path/to/another-project --runtime podman --agent goose
- Agent names must contain only alphanumeric characters or underscores (e.g., `claude`, `goose`, `my_agent`)
- Setting this environment variable is useful for automation scripts or when you consistently use the same agent

### `KORTEX_CLI_STORAGE`
### `KDN_STORAGE`

Sets the default storage directory where kdn stores its data files.

**Usage:**

```bash
export KORTEX_CLI_STORAGE=/custom/path/to/storage
export KDN_STORAGE=/custom/path/to/storage
kdn init /path/to/project --runtime podman --agent claude
```

Expand All @@ -1053,14 +1053,14 @@ kdn init /path/to/project --runtime podman --agent claude
The storage directory is determined in the following order (highest to lowest priority):

1. `--storage` flag (if specified)
2. `KORTEX_CLI_STORAGE` environment variable (if set)
2. `KDN_STORAGE` environment variable (if set)
3. Default: `$HOME/.kdn`

**Example:**

```bash
# Set a custom storage directory
export KORTEX_CLI_STORAGE=/var/lib/kortex
export KDN_STORAGE=/var/lib/kortex

# All commands will use this storage directory
kdn init /path/to/project --runtime podman --agent claude
Expand All @@ -1070,14 +1070,14 @@ kdn list
kdn list --storage /tmp/kortex-storage
```

### `KORTEX_CLI_INIT_AUTO_START`
### `KDN_INIT_AUTO_START`

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

**Usage:**

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

Expand All @@ -1086,7 +1086,7 @@ kdn init /path/to/project --runtime podman --agent claude
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)
2. `KDN_INIT_AUTO_START` environment variable (if set to a truthy value)
3. Default: workspace is not started automatically

**Supported Values:**
Expand All @@ -1102,14 +1102,14 @@ Any other value (including `0`, `false`, `no`, or empty string) will not trigger

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

# Register and start a workspace automatically
kdn 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
export KDN_INIT_AUTO_START=0
kdn init /path/to/another-project --runtime podman --agent claude --start
# Workspace is started despite env var being 0
```
Expand Down Expand Up @@ -1645,7 +1645,7 @@ When registering a workspace, configurations are merged in this order (later con
User-specific configurations are stored in the kdn storage directory:

- **Default location**: `~/.kdn/config/`
- **Custom location**: Set via `--storage` flag or `KORTEX_CLI_STORAGE` environment variable
- **Custom location**: Set via `--storage` flag or `KDN_STORAGE` environment variable

The storage directory contains:
- `config/agents.json` - Agent-specific environment variables and mounts
Expand Down Expand Up @@ -1781,7 +1781,7 @@ kdn init --runtime podman --agent claude
kdn init --runtime podman --project my-custom-project --agent goose
```

**Note:** The `--agent` flag is required (or set `KORTEX_CLI_DEFAULT_AGENT` environment variable) when registering a workspace.
**Note:** The `--agent` flag is required (or set `KDN_DEFAULT_AGENT` environment variable) when registering a workspace.

### Merging Behavior

Expand Down Expand Up @@ -1928,13 +1928,13 @@ kdn init [sources-directory] [flags]

#### Flags

- `--runtime, -r <type>` - Runtime to use for the workspace (required if `KORTEX_CLI_DEFAULT_RUNTIME` is not set)
- `--agent, -a <name>` - Agent to use for the workspace (required if `KORTEX_CLI_DEFAULT_AGENT` is not set)
- `--runtime, -r <type>` - Runtime to use for the workspace (required if `KDN_DEFAULT_RUNTIME` is not set)
- `--agent, -a <name>` - Agent to use for the workspace (required if `KDN_DEFAULT_AGENT` is not set)
- `--model, -m <id>` - Model ID to configure for the agent (optional, uses agent's default if not specified)
- `--workspace-configuration <path>` - Directory for workspace configuration files (default: `<sources-directory>/.kaiden`)
- `--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)
- `--start` - Start the workspace after registration (can also be set via `KDN_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 @@ -1981,7 +1981,7 @@ Output: `a1b2c3d4e5f6...` (workspace ID, workspace is now running)

**Register and start using environment variable:**
```bash
export KORTEX_CLI_INIT_AUTO_START=1
export KDN_INIT_AUTO_START=1
kdn init /path/to/myproject --runtime podman --agent claude
```
Output: `a1b2c3d4e5f6...` (workspace ID, workspace is now running)
Expand Down Expand Up @@ -2135,11 +2135,11 @@ kdn init /tmp/workspace --runtime podman --agent claude

#### Notes

- **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
- **Runtime is required**: You must specify a runtime using either the `--runtime` flag or the `KDN_DEFAULT_RUNTIME` environment variable
- **Agent is required**: You must specify an agent using either the `--agent` flag or the `KDN_DEFAULT_AGENT` environment variable
- **Model is optional**: Use `--model` to specify a model ID for the agent. The flag takes precedence over any model defined in the agent's default settings files (`~/.kdn/config/<agent>/`). If not provided, the agent uses its default model or the one configured in settings. All agents support model configuration: Claude (via `.claude/settings.json`), Goose (via `config.yaml`), and Cursor (via `.cursor/cli-config.json`)
- **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
- **Auto-start**: Use the `--start` flag or set `KDN_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
16 changes: 8 additions & 8 deletions pkg/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,29 +104,29 @@ func (i *initCmd) preRun(cmd *cobra.Command, args []string) error {
// Determine runtime: flag takes precedence over environment variable
if i.runtime == "" {
// Check environment variable
if envRuntime := os.Getenv("KORTEX_CLI_DEFAULT_RUNTIME"); envRuntime != "" {
if envRuntime := os.Getenv("KDN_DEFAULT_RUNTIME"); envRuntime != "" {
i.runtime = envRuntime
} else {
// Neither flag nor environment variable is set
return outputErrorIfJSON(cmd, i.output, fmt.Errorf("runtime is required: use --runtime flag or set KORTEX_CLI_DEFAULT_RUNTIME environment variable"))
return outputErrorIfJSON(cmd, i.output, fmt.Errorf("runtime is required: use --runtime flag or set KDN_DEFAULT_RUNTIME environment variable"))
}
}

// Determine agent: flag takes precedence over environment variable
if i.agent == "" {
// Check environment variable
if envAgent := os.Getenv("KORTEX_CLI_DEFAULT_AGENT"); envAgent != "" {
if envAgent := os.Getenv("KDN_DEFAULT_AGENT"); envAgent != "" {
i.agent = envAgent
} else {
// Neither flag nor environment variable is set
return outputErrorIfJSON(cmd, i.output, fmt.Errorf("agent is required: use --agent flag or set KORTEX_CLI_DEFAULT_AGENT environment variable"))
return outputErrorIfJSON(cmd, i.output, fmt.Errorf("agent is required: use --agent flag or set KDN_DEFAULT_AGENT environment variable"))
}
}

// 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 != "" {
if envStart := os.Getenv("KDN_INIT_AUTO_START"); envStart != "" {
// Accept "1", "true", "yes" as truthy values (case-insensitive)
switch envStart {
case "1", "true", "True", "TRUE", "yes", "Yes", "YES":
Expand Down Expand Up @@ -335,20 +335,20 @@ kdn init --runtime podman --agent claude --show-logs`,
cmd.Flags().StringVarP(&c.name, "name", "n", "", "Name for the workspace (default: generated from sources directory)")

// Add runtime flag
cmd.Flags().StringVarP(&c.runtime, "runtime", "r", "", "Runtime to use for the workspace (required if KORTEX_CLI_DEFAULT_RUNTIME is not set)")
cmd.Flags().StringVarP(&c.runtime, "runtime", "r", "", "Runtime to use for the workspace (required if KDN_DEFAULT_RUNTIME is not set)")
cmd.RegisterFlagCompletionFunc("runtime", completeRuntimeFlag)

// Add project flag
cmd.Flags().StringVarP(&c.project, "project", "p", "", "Custom project identifier (default: auto-detected from git repository or source directory)")

// 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)")
cmd.Flags().StringVarP(&c.agent, "agent", "a", "", "Agent name for loading agent-specific configuration (required if KDN_DEFAULT_AGENT is not set)")

// Add model flag
cmd.Flags().StringVarP(&c.model, "model", "m", "", "Model ID to configure for the agent (optional)")

// 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)")
cmd.Flags().BoolVar(&c.start, "start", false, "Start the workspace after registration (can also be set via KDN_INIT_AUTO_START environment variable)")

// Add verbose flag
cmd.Flags().BoolVarP(&c.verbose, "verbose", "v", false, "Show detailed output")
Expand Down
38 changes: 19 additions & 19 deletions pkg/cmd/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ func TestInitCmd_PreRun(t *testing.T) {
// Note: Cannot use t.Parallel() when using t.Setenv()

t.Run("with valid runtime from env", func(t *testing.T) {
t.Setenv("KORTEX_CLI_DEFAULT_RUNTIME", "fake")
t.Setenv("KDN_DEFAULT_RUNTIME", "fake")

tempDir := t.TempDir()

Expand Down Expand Up @@ -559,7 +559,7 @@ func TestInitCmd_PreRun(t *testing.T) {
// Note: Cannot use t.Parallel() when using t.Setenv()

t.Run("with valid agent from env", func(t *testing.T) {
t.Setenv("KORTEX_CLI_DEFAULT_AGENT", "test-agent")
t.Setenv("KDN_DEFAULT_AGENT", "test-agent")

tempDir := t.TempDir()

Expand Down Expand Up @@ -588,7 +588,7 @@ func TestInitCmd_PreRun(t *testing.T) {
// Note: Cannot use t.Parallel() when using t.Setenv()

t.Run("flag overrides env", func(t *testing.T) {
t.Setenv("KORTEX_CLI_DEFAULT_RUNTIME", "env-runtime")
t.Setenv("KDN_DEFAULT_RUNTIME", "env-runtime")

tempDir := t.TempDir()

Expand Down Expand Up @@ -617,7 +617,7 @@ func TestInitCmd_PreRun(t *testing.T) {
// Note: Cannot use t.Parallel() when using t.Setenv()

t.Run("flag overrides env", func(t *testing.T) {
t.Setenv("KORTEX_CLI_DEFAULT_AGENT", "env-agent")
t.Setenv("KDN_DEFAULT_AGENT", "env-agent")

tempDir := t.TempDir()

Expand Down Expand Up @@ -821,22 +821,22 @@ func TestInitCmd_PreRun(t *testing.T) {
envValue string
expected bool
}{
{"KORTEX_CLI_INIT_AUTO_START=1", "1", true},
{"KORTEX_CLI_INIT_AUTO_START=true", "true", true},
{"KORTEX_CLI_INIT_AUTO_START=True", "True", true},
{"KORTEX_CLI_INIT_AUTO_START=TRUE", "TRUE", true},
{"KORTEX_CLI_INIT_AUTO_START=yes", "yes", true},
{"KORTEX_CLI_INIT_AUTO_START=Yes", "Yes", true},
{"KORTEX_CLI_INIT_AUTO_START=YES", "YES", true},
{"KORTEX_CLI_INIT_AUTO_START=0", "0", false},
{"KORTEX_CLI_INIT_AUTO_START=false", "false", false},
{"KORTEX_CLI_INIT_AUTO_START=no", "no", false},
{"KORTEX_CLI_INIT_AUTO_START=empty", "", false},
{"KDN_INIT_AUTO_START=1", "1", true},
{"KDN_INIT_AUTO_START=true", "true", true},
{"KDN_INIT_AUTO_START=True", "True", true},
{"KDN_INIT_AUTO_START=TRUE", "TRUE", true},
{"KDN_INIT_AUTO_START=yes", "yes", true},
{"KDN_INIT_AUTO_START=Yes", "Yes", true},
{"KDN_INIT_AUTO_START=YES", "YES", true},
{"KDN_INIT_AUTO_START=0", "0", false},
{"KDN_INIT_AUTO_START=false", "false", false},
{"KDN_INIT_AUTO_START=no", "no", false},
{"KDN_INIT_AUTO_START=empty", "", false},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Setenv("KORTEX_CLI_INIT_AUTO_START", tt.envValue)
t.Setenv("KDN_INIT_AUTO_START", tt.envValue)

tempDir := t.TempDir()

Expand Down Expand Up @@ -867,7 +867,7 @@ func TestInitCmd_PreRun(t *testing.T) {
// Note: Cannot use t.Parallel() when using t.Setenv()

t.Run("flag true overrides env", func(t *testing.T) {
t.Setenv("KORTEX_CLI_INIT_AUTO_START", "0")
t.Setenv("KDN_INIT_AUTO_START", "0")

tempDir := t.TempDir()

Expand Down Expand Up @@ -1989,9 +1989,9 @@ func TestInitCmd_E2E(t *testing.T) {
func TestInitCmd_E2E_AutoStartWithEnv(t *testing.T) {
// Note: This test function cannot use t.Parallel() because subtests use t.Setenv()

t.Run("registers and starts workspace with KORTEX_CLI_INIT_AUTO_START environment variable", func(t *testing.T) {
t.Run("registers and starts workspace with KDN_INIT_AUTO_START environment variable", func(t *testing.T) {
t.Run("with env var set to 1", func(t *testing.T) {
t.Setenv("KORTEX_CLI_INIT_AUTO_START", "1")
t.Setenv("KDN_INIT_AUTO_START", "1")

storageDir := t.TempDir()
sourcesDir := t.TempDir()
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func NewRootCmd() *cobra.Command {
}

// Check for environment variable
if envStorage := os.Getenv("KORTEX_CLI_STORAGE"); envStorage != "" {
if envStorage := os.Getenv("KDN_STORAGE"); envStorage != "" {
defaultStoragePath = envStorage
}

Expand Down
Loading
Loading