Repository navigation
Go CLI: fix api commands - #16457
Go CLI: fix api commands#16457
Conversation
Signed-off-by: Jin Hai <[email protected]>
📝 WalkthroughWalkthroughCLI command handler methods across CLI Method Rename and dev_chunk Feature
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (4)
internal/cli/user_command.go (2)
4074-4103: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winPreserve the explain result in
DevChunkCommand.The
explainbranch assigns the explanation toresult.Message, but Line 4102 overwrites it with the generic success text, sodev_chunk ... explainnever returns the actual plan.Suggested fix
if explain { @@ result.Message = explanation } else { @@ for _, resultChunk := range chunkContext.ResultChunks { fmt.Printf("Chunk index: %d\n", resultChunk.Index) fmt.Printf("Chunk size: %d\n", resultChunk.Size) fmt.Printf("Chunk content: \n%s\n", resultChunk.Content) } + result.Message = fmt.Sprintf("Success to chunk %s", filename) } result.Duration = time.Since(start).Seconds() result.Code = 0 - result.Message = fmt.Sprintf("Success to chunk %s", filename) return &result, nil🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/cli/user_command.go` around lines 4074 - 4103, The explain output in DevChunkCommand is being overwritten before return, so the actual plan from engine.Explain is lost. Update the DevChunkCommand flow in user_command.go so the explain branch preserves result.Message when explain is true, and only set the generic success message for the non-explain path; use the existing result, engine.Explain, and result.Message assignment to locate the fix.
3791-3798: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
LIST INGESTION TASKS FROM ...currently drops the dataset filter.The parser still stores
dataset_idas a plainstring, but this handler now asserts*string, so theFROMclause always falls back toniland the request is sent unfiltered.Suggested fix
- datasetID, ok := cmd.Params["dataset_id"].(*string) - if !ok { - datasetID = nil - } - - payload := map[string]interface{}{ - "dataset_id": datasetID, - } + payload := map[string]interface{}{} + if datasetID, ok := cmd.Params["dataset_id"].(string); ok && datasetID != "" { + payload["dataset_id"] = datasetID + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/cli/user_command.go` around lines 3791 - 3798, The LIST INGESTION TASKS FROM handler is reading cmd.Params["dataset_id"] with the wrong type, so the dataset filter is always lost. Update the dataset_id extraction in the relevant CLI handler in user_command.go to match how the parser stores it as a plain string, then pass that value through unchanged when building the payload map. Keep the fix scoped to the LIST INGESTION TASKS flow and the datasetID/payload construction so the FROM clause is preserved.internal/cli/user_parser.go (1)
2820-2853: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winFix
EFFORT/VERBOSITYparsing inparseAPIChat.Two problems here:
VERBOSITY MEDIUMis serialized as"median", and both branchesbreak optionsLoop, so a command likeTHINK CHAT ... EFFORT high VERBOSITY highstops parsing after the first option instead of capturing both values.Suggested fix
case TokenEffort: p.nextToken() // pass Effort @@ } p.nextToken() - break optionsLoop + continue case TokenVerbosity: p.nextToken() // pass VERBOSITY switch p.curToken.Type { case TokenLow: verbosity = "low" case TokenMedium: - verbosity = "median" + verbosity = "medium" case TokenHigh: verbosity = "high" default: return nil, fmt.Errorf("invalid verbosity level") } p.nextToken() - break optionsLoop + continue🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/cli/user_parser.go` around lines 2820 - 2853, The parseAPIChat option handling has two issues: TokenVerbosity maps TokenMedium to the wrong value and both TokenEffort and TokenVerbosity exit optionsLoop too early. Update the effort/verbosity parsing in user_parser.go so TokenVerbosity assigns "medium" for TokenMedium, and change the control flow in parseAPIChat to continue parsing additional options after handling one recognized option instead of breaking out of optionsLoop; use the existing TokenEffort and TokenVerbosity branches as the fix points.internal/cli/common_command.go (1)
935-952: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winAccept
model_idinAPISetDefaultModelCommand.
parseAPISetDefaultnow emitsmodel_idfor UUID inputs, but this handler only readscomposite_model_name. As a result,SET DEFAULT ... MODEL '<uuid>'fails locally with"model_name not provided"instead of sending the PATCH.Suggested fix
func (c *CLI) APISetDefaultModelCommand(cmd *Command) (ResponseIf, error) { @@ - compositeModelName, ok := cmd.Params["composite_model_name"].(string) - if !ok { - return nil, fmt.Errorf("model_name not provided") - } - - var providerName, instanceName, modelName string - var err error - modelName, instanceName, providerName, err = common.ExtractCompositeName(compositeModelName) - if err != nil { - return nil, err - } - - payload := map[string]interface{}{ - "model_type": modelType, - "model_provider": providerName, - "model_instance": instanceName, - "model_name": modelName, - } + payload := map[string]interface{}{ + "model_type": modelType, + } + if compositeModelName, ok := cmd.Params["composite_model_name"].(string); ok { + modelName, instanceName, providerName, err := common.ExtractCompositeName(compositeModelName) + if err != nil { + return nil, err + } + payload["model_provider"] = providerName + payload["model_instance"] = instanceName + payload["model_name"] = modelName + } else if modelID, ok := cmd.Params["model_id"].(string); ok { + payload["model_id"] = modelID + } else { + return nil, fmt.Errorf("model identifier not provided") + }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/cli/common_command.go` around lines 935 - 952, APISetDefaultModelCommand currently only reads composite_model_name, so UUID-based defaults emitted as model_id by parseAPISetDefault are rejected with a misleading model_name not provided error. Update the handler in common_command.go to accept model_id as an alternate input, branch on whichever field is present, and only call common.ExtractCompositeName for composite names while allowing raw UUIDs to pass through to the PATCH payload. Keep the existing payload shape and ensure the command still sets model_type, model_provider, model_instance, and model_name appropriately for composite inputs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/cli/dev_parser.go`:
- Around line 734-743: The DSL parsing in the CHUNK/EXPLAIN CHUNK path is
checking for an optional semicolon before advancing past the quoted DSL token,
so the trailing ';' remains unconsumed. Update the parser logic in the relevant
DSL parse function (the block using parseQuotedString and p.nextToken) to
consume the DSL token first, then check for TokenSemicolon, matching the
behavior of neighboring parsers and allowing semicolon-terminated statements to
parse consistently.
In `@internal/engine/infinity/metadata.go`:
- Line 228: The inline reference in the metadata comment points to the wrong
file; update the `parseDevSetMeta` reference so it directs readers to
`internal/cli/dev_parser.go` instead of `internal/cli/user_parser.go`. Locate
the comment near the `metadata.go` change and fix the user-facing path text to
match the actual location of `parseDevSetMeta`.
---
Outside diff comments:
In `@internal/cli/common_command.go`:
- Around line 935-952: APISetDefaultModelCommand currently only reads
composite_model_name, so UUID-based defaults emitted as model_id by
parseAPISetDefault are rejected with a misleading model_name not provided error.
Update the handler in common_command.go to accept model_id as an alternate
input, branch on whichever field is present, and only call
common.ExtractCompositeName for composite names while allowing raw UUIDs to pass
through to the PATCH payload. Keep the existing payload shape and ensure the
command still sets model_type, model_provider, model_instance, and model_name
appropriately for composite inputs.
In `@internal/cli/user_command.go`:
- Around line 4074-4103: The explain output in DevChunkCommand is being
overwritten before return, so the actual plan from engine.Explain is lost.
Update the DevChunkCommand flow in user_command.go so the explain branch
preserves result.Message when explain is true, and only set the generic success
message for the non-explain path; use the existing result, engine.Explain, and
result.Message assignment to locate the fix.
- Around line 3791-3798: The LIST INGESTION TASKS FROM handler is reading
cmd.Params["dataset_id"] with the wrong type, so the dataset filter is always
lost. Update the dataset_id extraction in the relevant CLI handler in
user_command.go to match how the parser stores it as a plain string, then pass
that value through unchanged when building the payload map. Keep the fix scoped
to the LIST INGESTION TASKS flow and the datasetID/payload construction so the
FROM clause is preserved.
In `@internal/cli/user_parser.go`:
- Around line 2820-2853: The parseAPIChat option handling has two issues:
TokenVerbosity maps TokenMedium to the wrong value and both TokenEffort and
TokenVerbosity exit optionsLoop too early. Update the effort/verbosity parsing
in user_parser.go so TokenVerbosity assigns "medium" for TokenMedium, and change
the control flow in parseAPIChat to continue parsing additional options after
handling one recognized option instead of breaking out of optionsLoop; use the
existing TokenEffort and TokenVerbosity branches as the fix points.
🪄 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: 70b6b0cd-d064-43b3-87ff-f4eb29550abc
📒 Files selected for processing (8)
internal/cli/cli_http.gointernal/cli/common_command.gointernal/cli/dev_parser.gointernal/cli/parser.gointernal/cli/user_command.gointernal/cli/user_parser.gointernal/cli/user_parser_test.gointernal/engine/infinity/metadata.go
| dsl, err := p.parseQuotedString() | ||
| if err != nil { | ||
| return nil, fmt.Errorf("expected DSL: %w", err) | ||
| } | ||
|
|
||
| // Semicolon is optional | ||
| if p.curToken.Type == TokenSemicolon { | ||
| p.nextToken() | ||
| } | ||
| p.nextToken() |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Consume the token after the DSL before checking for ;.
Right now the semicolon branch is checked while p.curToken is still the quoted DSL token, so CHUNK ... WITH 'dsl'; returns with ; still unconsumed. That makes the new command inconsistent with the neighboring parsers and can break semicolon-terminated CHUNK / EXPLAIN CHUNK statements.
Proposed fix
dsl, err := p.parseQuotedString()
if err != nil {
return nil, fmt.Errorf("expected DSL: %w", err)
}
+ p.nextToken()
// Semicolon is optional
if p.curToken.Type == TokenSemicolon {
p.nextToken()
}
- p.nextToken()
cmd := NewCommand("dev_chunk")📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| dsl, err := p.parseQuotedString() | |
| if err != nil { | |
| return nil, fmt.Errorf("expected DSL: %w", err) | |
| } | |
| // Semicolon is optional | |
| if p.curToken.Type == TokenSemicolon { | |
| p.nextToken() | |
| } | |
| p.nextToken() | |
| dsl, err := p.parseQuotedString() | |
| if err != nil { | |
| return nil, fmt.Errorf("expected DSL: %w", err) | |
| } | |
| p.nextToken() | |
| // Semicolon is optional | |
| if p.curToken.Type == TokenSemicolon { | |
| p.nextToken() | |
| } | |
| cmd := NewCommand("dev_chunk") |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/cli/dev_parser.go` around lines 734 - 743, The DSL parsing in the
CHUNK/EXPLAIN CHUNK path is checking for an optional semicolon before advancing
past the quoted DSL token, so the trailing ';' remains unconsumed. Update the
parser logic in the relevant DSL parse function (the block using
parseQuotedString and p.nextToken) to consume the DSL token first, then check
for TokenSemicolon, matching the behavior of neighboring parsers and allowing
semicolon-terminated statements to parse consistently.
| // that user-driven metadata edits compose with auto-extracted fields | ||
| // produced by the LLM extraction pipeline. See the CLI parser in | ||
| // internal/cli/user_parser.go (parseSetMeta) for the user-facing | ||
| // internal/cli/user_parser.go (parseDevSetMeta) for the user-facing |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Point this reference at internal/cli/dev_parser.go.
parseDevSetMeta is defined in internal/cli/dev_parser.go in this PR, so the new comment sends readers to the wrong file.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@internal/engine/infinity/metadata.go` at line 228, The inline reference in
the metadata comment points to the wrong file; update the `parseDevSetMeta`
reference so it directs readers to `internal/cli/dev_parser.go` instead of
`internal/cli/user_parser.go`. Locate the comment near the `metadata.go` change
and fix the user-facing path text to match the actual location of
`parseDevSetMeta`.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16457 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
As title.