refactor(agentic): clarify local agent command quoting
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
7389b2f801
commit
a18723d564
2 changed files with 21 additions and 4 deletions
|
|
@ -134,16 +134,28 @@ func agentCommandResult(agent, prompt string) core.Result {
|
|||
if localModel == "" {
|
||||
localModel = "devstral-24b"
|
||||
}
|
||||
script := core.Sprintf(
|
||||
`socat TCP-LISTEN:11434,fork,reuseaddr TCP:host.docker.internal:11434 & sleep 0.5 && codex exec --dangerously-bypass-approvals-and-sandbox --oss --local-provider ollama -m %s -o ../.meta/agent-codex.log %q`,
|
||||
localModel, prompt,
|
||||
)
|
||||
script := localAgentCommandScript(localModel, prompt)
|
||||
return core.Result{Value: agentCommandResultValue{command: "sh", args: []string{"-c", script}}, OK: true}
|
||||
default:
|
||||
return core.Result{Value: core.E("agentCommand", core.Concat("unknown agent: ", agent), nil), OK: false}
|
||||
}
|
||||
}
|
||||
|
||||
// localAgentCommandScript("devstral-24b", "Review the last 2 commits")
|
||||
func localAgentCommandScript(model, prompt string) string {
|
||||
builder := core.NewBuilder()
|
||||
builder.WriteString("socat TCP-LISTEN:11434,fork,reuseaddr TCP:host.docker.internal:11434 & sleep 0.5")
|
||||
builder.WriteString(" && codex exec --dangerously-bypass-approvals-and-sandbox --oss --local-provider ollama -m ")
|
||||
builder.WriteString(shellQuote(model))
|
||||
builder.WriteString(" -o ../.meta/agent-codex.log ")
|
||||
builder.WriteString(shellQuote(prompt))
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
func shellQuote(value string) string {
|
||||
return core.Concat("'", core.Replace(value, "'", "'\\''"), "'")
|
||||
}
|
||||
|
||||
const defaultDockerImage = "core-dev"
|
||||
|
||||
// command, args := containerCommand("codex", []string{"exec", "--model", "gpt-5.4"}, "/srv/.core/workspace/core/go-io/task-5", "/srv/.core/workspace/core/go-io/task-5/.meta")
|
||||
|
|
|
|||
|
|
@ -101,6 +101,11 @@ func TestDispatch_AgentCommand_Good_LocalWithModel(t *testing.T) {
|
|||
assert.Contains(t, args[1], "mistral-nemo")
|
||||
}
|
||||
|
||||
func TestDispatch_LocalAgentCommandScript_Good_ShellQuoting(t *testing.T) {
|
||||
script := localAgentCommandScript("devstral-24b", "can't break quoting")
|
||||
assert.Contains(t, script, "'can'\\''t break quoting'")
|
||||
}
|
||||
|
||||
func TestDispatch_AgentCommand_Bad_Unknown(t *testing.T) {
|
||||
cmd, args, err := agentCommand("robot-from-the-future", "take over")
|
||||
assert.Error(t, err)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue