Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
fix(skill): 解析 stringified JSON 数组形式的 args
养乐多13abc41b0d39
diff --git a/internal/agent/tools/skill_execute.go b/internal/agent/tools/skill_execute.goindex 24e5fcfd5..0caf01b40 100644--- a/internal/agent/tools/skill_execute.go+++ b/internal/agent/tools/skill_execute.go@@ -108,9 +108,18 @@ func (i *ExecuteSkillScriptInput) UnmarshalJSON(data []byte) error {return fmt.Errorf("args must be a string or an array of strings: %w", err)}- // A string is interpreted as a conventional space-separated command line.- // The tool schema continues to advertise []string, so well-formed calls are- // unaffected; this is only a compatibility fallback for model output.+ // Some providers emit the array as a stringified JSON payload+ // (e.g. "[\"--project-name\",\"X\"]"). Treat that as an array first so the+ // model's intent is preserved; strings.Fields would otherwise split the+ // brackets/quotes into garbage tokens and the script would see nonsense argv.+ if err := json.Unmarshal([]byte(argsString), &i.Args); err == nil {+ return nil+ }++ // A plain string is interpreted as a conventional space-separated command+ // line. The tool schema continues to advertise []string, so well-formed+ // calls are unaffected; this is only a compatibility fallback for model+ // output.i.Args = strings.Fields(argsString)return nil}diff --git a/internal/agent/tools/skill_execute_test.go b/internal/agent/tools/skill_execute_test.goindex 2b38fa13b..1c67ead57 100644--- a/internal/agent/tools/skill_execute_test.go+++ b/internal/agent/tools/skill_execute_test.go@@ -1,6 +1,7 @@package toolsimport (+ "encoding/json""testing""github.com/stretchr/testify/assert"@@ -33,3 +34,55 @@ func TestExecuteSkillScriptDescriptionAcceptsWorkspacePaths(t *testing.T) {assert.Contains(t, executeSkillScriptTool.Description(), "install_deps.py")assert.Contains(t, executeSkillScriptTool.Description(), ".skill-packages")}++// TestExecuteSkillScriptInputUnmarshalJSON covers the model-emitted shapes the+// UnmarshalJSON fallback must tolerate. The provider does not always honor the+// []string schema: it sometimes emits a stringified JSON array or a single+// command-line string. Each must round-trip to the intended argv.+func TestExecuteSkillScriptInputUnmarshalJSON(t *testing.T) {+ t.Run("real array", func(t *testing.T) {+ var in ExecuteSkillScriptInput+ require.NoError(t, json.Unmarshal([]byte(`{+ "skill_name": "s", "script_path": "p",+ "args": ["--project-name", "X", "--creator", "admin"]+ }`), &in))+ require.Equal(t, []string{"--project-name", "X", "--creator", "admin"}, in.Args)+ })++ t.Run("stringified json array", func(t *testing.T) {+ // Some providers emit args as a JSON string whose content is itself a+ // JSON array. strings.Fields would mangle the brackets/quotes into+ // one garbage token; the array must be recovered instead.+ var in ExecuteSkillScriptInput+ require.NoError(t, json.Unmarshal([]byte(`{+ "skill_name": "s", "script_path": "p",+ "args": "[\"--project-name\", \"X\", \"--creator\", \"admin\"]"+ }`), &in))+ require.Equal(t, []string{"--project-name", "X", "--creator", "admin"}, in.Args)+ })++ t.Run("single command line string", func(t *testing.T) {+ var in ExecuteSkillScriptInput+ require.NoError(t, json.Unmarshal([]byte(`{+ "skill_name": "s", "script_path": "p",+ "args": "ls --workspace /workspace/output"+ }`), &in))+ require.Equal(t, []string{"ls", "--workspace", "/workspace/output"}, in.Args)+ })++ t.Run("absent args", func(t *testing.T) {+ var in ExecuteSkillScriptInput+ require.NoError(t, json.Unmarshal([]byte(`{+ "skill_name": "s", "script_path": "p"+ }`), &in))+ require.Empty(t, in.Args)+ })++ t.Run("null args", func(t *testing.T) {+ var in ExecuteSkillScriptInput+ require.NoError(t, json.Unmarshal([]byte(`{+ "skill_name": "s", "script_path": "p", "args": null+ }`), &in))+ require.Empty(t, in.Args)+ })+}