{"record":{"id":"ab43c454dc19fb87","repo":"siyuan-note/siyuan","slug":"registercapability-requires-3-arguments-name-con","errorCode":null,"errorMessage":"registerCapability requires 3 arguments: name, config, handler","messagePattern":"registerCapability requires 3 arguments: name, config, handler","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/plugin/api_agent.go","lineNumber":70,"sourceCode":"\n\tagentAPI := rt.NewObject()\n\n\t// siyuan.agent.registerCapability(name, config, handler) 返回 Promise<IRegisteredCapability>。\n\tlo.Must0(agentAPI.Set(\"registerCapability\", rt.ToValue(func(call goja.FunctionCall, rt *goja.Runtime) goja.Value {\n\t\tpromise, resolve, reject := rt.NewPromise()\n\n\t\tvar name string\n\t\tvar title string\n\t\tvar description string\n\t\tvar effects *tools.ToolEffects\n\t\tvar actionEffects map[string]tools.ToolEffects\n\t\tvar inputSchema *tools.ToolSchema\n\t\tvar outputSchema *tools.ToolSchema\n\t\tvar handler goja.Callable\n\n\t\targErr := func() (err error) {\n\t\t\tif len(call.Arguments) < 3 {\n\t\t\t\terr = fmt.Errorf(\"registerCapability requires 3 arguments: name, config, handler\")\n\t\t\t\treturn\n\t\t\t} else {\n\t\t\t\tif s := call.Argument(0); goja.IsString(s) {\n\t\t\t\t\tname = strings.TrimSpace(s.String())\n\t\t\t\t\tif name == \"\" {\n\t\t\t\t\t\terr = fmt.Errorf(\"capability name must not be empty\")\n\t\t\t\t\t\treturn\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\terr = fmt.Errorf(\"first argument must be a tool name string\")\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\tif c := call.Argument(1); isJsValueNotNull(c) {\n\t\t\t\t\tconfigObj := c.ToObject(rt)\n\t\t\t\t\tif configObj != nil {\n\t\t\t\t\t\tif titleValue := configObj.Get(\"title\"); goja.IsString(titleValue) {\n\t\t\t\t\t\t\ttitle = titleValue.String()","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/plugin/api_agent.go#L52-L88","documentation":"registerCapability() is the plugin API for registering an agent tool/capability with the kernel. It requires exactly three arguments: a name string, a config object, and a handler function. The runtime throws this error before doing any work when fewer than three arguments are passed, because a capability cannot be registered without all three pieces.","triggerScenarios":"Calling registerCapability(name, config) with only two arguments, registerCapability(name) with one, or registerCapability() with none — e.g. omitting the handler callback or forgetting the config object in the call.","commonSituations":"Copy-pasted plugin sample code where the handler was trimmed; refactoring that removed the config argument; dynamically-built argument lists where an optional value ended up undefined; typos in a wrapper function that forwards arguments incorrectly.","solutions":["Pass all three arguments in order: registerCapability(name, config, handler)","Define the handler function and the config object before the call site","Log typeof each argument (string, object, function) before calling to spot the missing one"],"exampleFix":"// before\nplugin.registerCapability(\"my_tool\", { description: \"...\" });\n// after\nplugin.registerCapability(\"my_tool\", { description: \"...\", inputSchema: {...} }, async (args) => { return { content: \"ok\" }; });","handlingStrategy":"validation","validationCode":"function canRegister(args) { return Array.isArray(args) && args.length >= 3; }\nif (!canRegister([name, config, handler])) throw new Error(\"registerCapability needs (name, config, handler)\");","typeGuard":"const isRegisterable = (n, c, h) => typeof n === \"string\" && n.trim() !== \"\" && c !== null && typeof c === \"object\" && typeof h === \"function\";","tryCatchPattern":"try { plugin.registerCapability(name, config, handler); } catch (e) { if (String(e).includes(\"registerCapability requires 3 arguments\")) { /* fix arg count */ } else { throw e; } }","preventionTips":["Always call with the full triple (name, config, handler)","Define config and handler above the registration call","Wrap registration in a helper that validates arity once"],"tags":["plugin-api","argument-count","agent-capability"],"backgroundTag":"missing-required-argument","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}