Skip to content

feat(cmd): add --model flag to init command (#188)#190

Open
feloy wants to merge 2 commits intokortex-hub:mainfrom
feloy:model
Open

feat(cmd): add --model flag to init command (#188)#190
feloy wants to merge 2 commits intokortex-hub:mainfrom
feloy:model

Conversation

@feloy
Copy link
Copy Markdown
Contributor

@feloy feloy commented Apr 4, 2026

Add optional --model/-m flag to specify a model ID for the agent during workspace initialization. The flag takes precedence over any model defined in the agent's default settings files.

  • Add SetModel method to Agent interface
  • Implement SetModel for Claude (sets model in .claude.json)
  • Implement SetModel for Goose (sets GOOSE_MODEL in config.yaml)
  • Implement SetModel for Cursor (set model in .cursor/cli-config.json)
  • Call SetModel in manager.Add when model is specified
  • Update README and skills documentation

Closes #188

Add optional --model/-m flag to specify a model ID for the agent during
workspace initialization. The flag takes precedence over any model
defined in the agent's default settings files.

- Add SetModel method to Agent interface
- Implement SetModel for Claude (sets model in .claude.json)
- Implement SetModel for Goose (sets GOOSE_MODEL in config.yaml)
- Implement SetModel for Cursor (set model in .cursor/cli-config.json)
- Call SetModel in manager.Add when model is specified
- Update README and skills documentation

Made-with: Cursor

Co-Authored-By: Claude Code (Claude Sonnet 4.5) <noreply@anthropic.com>
Signed-off-by: Philippe Martin <phmartin@redhat.com>
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 4, 2026

Codecov Report

❌ Patch coverage is 87.69231% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/agent/cursor.go 83.33% 2 Missing and 2 partials ⚠️
pkg/agent/claude.go 88.88% 1 Missing and 1 partial ⚠️
pkg/agent/goose.go 86.66% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 4, 2026

📝 Walkthrough

Walkthrough

Adds a model-override path to instance creation: a new --model/-m init flag is passed into instances.Add, which calls agent implementations' new SetModel method to persist the provided model ID into agent-specific config files (Claude, Goose, Cursor), taking precedence over existing settings.

Changes

Cohort / File(s) Summary
Agent interface
pkg/agent/agent.go
Added SetModel(settings map[string][]byte, modelID string) (map[string][]byte, error) to the Agent interface.
Claude agent
pkg/agent/claude.go, pkg/agent/claude_test.go
New ClaudeJSONPath (.claude.json); ClaudeSettingsPath moved to .claude/settings.json. Implemented SetModel to set model in Claude JSON while preserving unknown fields. Tests added/updated for onboarding and SetModel.
Cursor agent
pkg/agent/cursor.go, pkg/agent/cursor_test.go
Added CursorCLIConfigPath (.cursor/cli-config.json). Implemented SetModel to update the model object and hasChangedDefaultModel flag; preserves other settings. Added tests for nil/empty/preexisting JSON and invalid JSON error.
Goose agent
pkg/agent/goose.go, pkg/agent/goose_test.go
Added gooseModelKey = "GOOSE_MODEL". Implemented SetModel to set GOOSE_MODEL in .config/goose/config.yaml, preserving other fields; tests for creation, preservation, invalid YAML, and overwrite.
Manager / instances
pkg/instances/manager.go, pkg/instances/manager_test.go
Added Model string to AddOptions. Manager.Add now calls agentImpl.SetModel(agentSettings, opts.Model) when opts.Model != ""; added test doubles and tests covering call/no-call, error propagation, and preservation.
CLI init
pkg/cmd/init.go, pkg/cmd/init_test.go
Added --model/-m flag to kortex-cli init, plumbed into AddOptions.Model. E2E tests for both flag forms added; examples count updated.
Registry & test doubles
pkg/agent/registry_test.go
Updated fakeAgent to implement SetModel and return settings unchanged to satisfy interface in tests.
Docs / README / SKILLs
README.md, skills/.../SKILL.md
Documented --model precedence and updated guidance for Claude/Goose/Cursor model configuration and Cursor defaults; added --model examples and notes that --model during init takes precedence.

Sequence Diagram(s)

sequenceDiagram
    participant User as User
    participant CLI as "kortex-cli init"
    participant Manager as "instances.Manager"
    participant Registry as "Agent Registry"
    participant Agent as "Agent Implementation"
    participant Settings as "Settings File"

    User->>CLI: init --model claude-sonnet
    CLI->>Manager: Add(AddOptions{Model: "claude-sonnet"})
    Manager->>Registry: Get(agentName)
    Registry-->>Manager: agentImpl
    Manager->>Agent: SkipOnboarding(settings)
    Agent->>Settings: read settings
    Settings-->>Agent: config data
    Agent-->>Manager: updated settings
    Manager->>Agent: SetModel(settings, "claude-sonnet")
    Agent->>Settings: unmarshal existing config
    Settings-->>Agent: config data
    Agent->>Agent: set model field to "claude-sonnet"
    Agent->>Settings: marshal & write config
    Agent-->>Manager: settings w/ model
    Manager-->>CLI: instance registered
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 2.94% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding an optional --model flag to the init command for specifying agent model IDs.
Description check ✅ Passed The PR description clearly outlines the changes: adding a --model flag to init, implementing SetModel for Claude/Goose/Cursor agents, and updating documentation. It directly relates to all the file changes summarized.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/agent/claude.go (1)

64-70: ⚠️ Potential issue | 🟠 Major

Initialize config after unmarshalling Claude JSON to handle null values.

When a settings file contains the valid JSON literal null, unmarshalling into a nil-initialized map[string]interface{} leaves the map nil. Lines 70 and 131 then panic on map assignment instead of returning an error.

🛠️ Suggested fix
 	var config map[string]interface{}
 	if err := json.Unmarshal(existingContent, &config); err != nil {
 		return nil, fmt.Errorf("failed to parse existing %s: %w", ClaudeJSONPath, err)
 	}
+	if config == nil {
+		config = make(map[string]interface{})
+	}
 
 	// Set hasCompletedOnboarding
 	config["hasCompletedOnboarding"] = true
 	var config map[string]interface{}
 	if err := json.Unmarshal(existingContent, &config); err != nil {
 		return nil, fmt.Errorf("failed to parse existing %s: %w", ClaudeSettingsPath, err)
 	}
+	if config == nil {
+		config = make(map[string]interface{})
+	}
 
 	config["model"] = modelID

Also applies to: Line 131

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/agent/claude.go` around lines 64 - 70, After json.Unmarshal into the
local variable config in pkg/agent/claude.go, guard against the JSON literal
null by initializing the map when it's nil (e.g., if config == nil then config =
make(map[string]interface{})); apply the same nil-check/initialization before
any map assignment sites (the subsequent assignment to
config["hasCompletedOnboarding"] and the other assignment around the later
unmarshal at the second location) so assignments won't panic and existing
behavior continues.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pkg/agent/cursor.go`:
- Around line 86-99: When json.Unmarshal into the local variable config may
produce a nil map (e.g., when the file contains the JSON literal null), guard
against a nil config before assigning keys: after the Unmarshal in
pkg/agent/cursor.go, check if config == nil and if so set config =
make(map[string]interface{}) so subsequent assignments like config["model"] =
... and config["hasChangedDefaultModel"] = true (which reference modelID and
CursorCLIConfigPath in the error message) won’t panic; update the block around
the Unmarshal and the config population to ensure config is always an
initialized map before use.

---

Outside diff comments:
In `@pkg/agent/claude.go`:
- Around line 64-70: After json.Unmarshal into the local variable config in
pkg/agent/claude.go, guard against the JSON literal null by initializing the map
when it's nil (e.g., if config == nil then config =
make(map[string]interface{})); apply the same nil-check/initialization before
any map assignment sites (the subsequent assignment to
config["hasCompletedOnboarding"] and the other assignment around the later
unmarshal at the second location) so assignments won't panic and existing
behavior continues.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 35de5905-924b-4f51-966d-934dd726199f

📥 Commits

Reviewing files that changed from the base of the PR and between e968352 and 0d5989c.

📒 Files selected for processing (15)
  • README.md
  • pkg/agent/agent.go
  • pkg/agent/claude.go
  • pkg/agent/claude_test.go
  • pkg/agent/cursor.go
  • pkg/agent/cursor_test.go
  • pkg/agent/goose.go
  • pkg/agent/goose_test.go
  • pkg/agent/registry_test.go
  • pkg/cmd/init.go
  • pkg/cmd/init_test.go
  • pkg/instances/manager.go
  • pkg/instances/manager_test.go
  • skills/working-with-config-system/SKILL.md
  • skills/working-with-instances-manager/SKILL.md

Signed-off-by: Philippe Martin <phmartin@redhat.com>

Co-Authored-By: Claude Code (Claude Sonnet 4.5) <noreply@anthropic.com>
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.

Model flag for init

2 participants