[{"data":1,"prerenderedAt":539},["ShallowReactive",2],{"navigation_docs":3,"-hosts-opencode":60,"-hosts-opencode-surround":465,"host-views":468},[4,32],{"title":5,"path":6,"stem":7,"children":8,"icon":31},"Guide","\u002Fguide","1.guide\u002F01.index",[9,11,15,19,23,27],{"title":10,"path":6,"stem":7},"Getting Started",{"title":12,"path":13,"stem":14},"Defining Tools","\u002Fguide\u002Fdefining-tools","1.guide\u002F02.defining-tools",{"title":16,"path":17,"stem":18},"Validation and Errors","\u002Fguide\u002Fvalidation","1.guide\u002F03.validation",{"title":20,"path":21,"stem":22},"CLI","\u002Fguide\u002Fcli","1.guide\u002F04.cli",{"title":24,"path":25,"stem":26},"HTTP","\u002Fguide\u002Fhttp","1.guide\u002F05.http",{"title":28,"path":29,"stem":30},"Moving a Package Over","\u002Fguide\u002Fmigrating","1.guide\u002F06.migrating","i-lucide-book-open",{"title":33,"path":34,"stem":35,"children":36,"icon":59},"Hosts","\u002Fhosts","2.hosts\u002F00.index",[37,39,43,47,51,55],{"title":38,"path":34,"stem":35},"Every host",{"title":40,"path":41,"stem":42},"MCP","\u002Fhosts\u002Fmcp","2.hosts\u002F01.mcp",{"title":44,"path":45,"stem":46},"Pi","\u002Fhosts\u002Fpi","2.hosts\u002F02.pi",{"title":48,"path":49,"stem":50},"OMP","\u002Fhosts\u002Fomp","2.hosts\u002F03.omp",{"title":52,"path":53,"stem":54},"AI SDK","\u002Fhosts\u002Fai-sdk","2.hosts\u002F04.ai-sdk",{"title":56,"path":57,"stem":58},"OpenCode","\u002Fhosts\u002Fopencode","2.hosts\u002F05.opencode","i-lucide-table",{"id":61,"title":56,"body":62,"description":459,"extension":460,"links":461,"meta":462,"navigation":147,"path":57,"seo":463,"stem":58,"__hash__":464},"docs\u002F2.hosts\u002F05.opencode.md",{"type":63,"value":64,"toc":452},"minimark",[65,69,94,210,215,218,229,285,295,305,313,320,324,335,339,346,349,368,372,379,390,399,403,418,434,448],[66,67],"host-facts",{"name":68},"opencode",[70,71,72,73,77,78,81,82,85,86,89,90,93],"p",{},"Call ",[74,75,76],"code",{},"registerOpencodeTools(ctx, tools)"," from ",[74,79,80],{},"@agntn\u002Ftools\u002Fopencode"," inside your plugin's ",[74,83,84],{},"setup",", and await it there. The plugin's default export is ",[74,87,88],{},"{ id, setup }",". ",[74,91,92],{},"@opencode\u002Fplugin"," is only needed for its types. OpenCode hands over everything else at runtime.",[95,96,102],"pre",{"className":97,"code":98,"filename":99,"language":100,"meta":101,"style":101},"language-js shiki shiki-themes tools tools tools","import { registerOpencodeTools } from \"@agntn\u002Ftools\u002Fopencode\";\nimport { tools } from \".\u002Fdist\u002Ftools.mjs\";\n\nexport default {\n  id: \"mypackage\",\n  async setup(ctx) {\n    await registerOpencodeTools(ctx, tools);\n  },\n};\n","server.mjs","js","",[74,103,104,127,142,149,161,173,186,198,204],{"__ignoreMap":101},[105,106,109,113,117,120,124],"span",{"class":107,"line":108},"line",1,[105,110,112],{"class":111},"skH_V","import",[105,114,116],{"class":115},"s38Sx"," { registerOpencodeTools } ",[105,118,119],{"class":111},"from",[105,121,123],{"class":122},"shU9J"," \"@agntn\u002Ftools\u002Fopencode\"",[105,125,126],{"class":115},";\n",[105,128,130,132,135,137,140],{"class":107,"line":129},2,[105,131,112],{"class":111},[105,133,134],{"class":115}," { tools } ",[105,136,119],{"class":111},[105,138,139],{"class":122}," \".\u002Fdist\u002Ftools.mjs\"",[105,141,126],{"class":115},[105,143,145],{"class":107,"line":144},3,[105,146,148],{"emptyLinePlaceholder":147},true,"\n",[105,150,152,155,158],{"class":107,"line":151},4,[105,153,154],{"class":111},"export",[105,156,157],{"class":111}," default",[105,159,160],{"class":115}," {\n",[105,162,164,167,170],{"class":107,"line":163},5,[105,165,166],{"class":115},"  id: ",[105,168,169],{"class":122},"\"mypackage\"",[105,171,172],{"class":115},",\n",[105,174,176,179,183],{"class":107,"line":175},6,[105,177,178],{"class":111},"  async",[105,180,182],{"class":181},"sK71F"," setup",[105,184,185],{"class":115},"(ctx) {\n",[105,187,189,192,195],{"class":107,"line":188},7,[105,190,191],{"class":111},"    await",[105,193,194],{"class":181}," registerOpencodeTools",[105,196,197],{"class":115},"(ctx, tools);\n",[105,199,201],{"class":107,"line":200},8,[105,202,203],{"class":115},"  },\n",[105,205,207],{"class":107,"line":206},9,[105,208,209],{"class":115},"};\n",[211,212,214],"h2",{"id":213},"writes-dont-ask-by-default","Writes don't ask by default",[70,216,217],{},"A write doesn't mean a question. In OpenCode 2.3.2, the default rules let it run without asking anybody. That's a reckless default for a tool that writes.",[70,219,220,221,224,225,228],{},"Any tool whose effect isn't ",[74,222,223],{},"read"," meets the permission rules under its own name, just like an MCP tool. Want OpenCode to ask every time? Add an ",[74,226,227],{},"ask"," rule for that name:",[95,230,235],{"className":231,"code":232,"filename":233,"language":234,"meta":101,"style":101},"language-json shiki shiki-themes tools tools tools","{\n  \"plugin\": [\"\u002Fpath\u002Fto\u002Fmypackage\"],\n  \"permission\": {\n    \"notes_write\": \"ask\"\n  }\n}\n","opencode.json","json",[74,236,237,242,256,264,275,280],{"__ignoreMap":101},[105,238,239],{"class":107,"line":108},[105,240,241],{"class":115},"{\n",[105,243,244,247,250,253],{"class":107,"line":129},[105,245,246],{"class":181},"  \"plugin\"",[105,248,249],{"class":115},": [",[105,251,252],{"class":122},"\"\u002Fpath\u002Fto\u002Fmypackage\"",[105,254,255],{"class":115},"],\n",[105,257,258,261],{"class":107,"line":144},[105,259,260],{"class":181},"  \"permission\"",[105,262,263],{"class":115},": {\n",[105,265,266,269,272],{"class":107,"line":151},[105,267,268],{"class":181},"    \"notes_write\"",[105,270,271],{"class":115},": ",[105,273,274],{"class":122},"\"ask\"\n",[105,276,277],{"class":107,"line":163},[105,278,279],{"class":115},"  }\n",[105,281,282],{"class":107,"line":175},[105,283,284],{"class":115},"}\n",[70,286,287,288,290,291,294],{},"A ",[74,289,223],{}," never asks. And ",[74,292,293],{},"deny"," removes the tool from what the model can see.",[70,296,297,298,301,302,304],{},"In a non-interactive ",[74,299,300],{},"opencode run",", ",[74,303,227],{}," means rejection:",[95,306,311],{"className":307,"code":309,"language":310,"meta":101},[308],"language-text","permission requested: notes_write (*); auto-rejecting\n","text",[74,312,309],{"__ignoreMap":101},[70,314,315,316,319],{},"With ",[74,317,318],{},"--auto",", the call is approved instead.",[211,321,323],{"id":322},"tools-live-in-code-mode","Tools live in Code Mode",[70,325,326,327,330,331,334],{},"In OpenCode 2.3.2, plugin tools land in Code Mode by default. They aren't separate tools in the model's view. The model calls them as ",[74,328,329],{},"tools.\u003Cname>(...)"," from OpenCode's own ",[74,332,333],{},"execute"," tool.",[211,336,338],{"id":337},"failures-dont-look-like-success","Failures don't look like success",[70,340,341,342,345],{},"Duplicate names aren't welcome. Two tools with the same name throw a ",[74,343,344],{},"ToolDefinitionError"," at registration.",[70,347,348],{},"Arguments are checked against the schema before the permission question. Nobody has to approve a typo. Bad input throws the same lines as every host.",[70,350,351,352,354,355,358,359,362,363,367],{},"When ",[74,353,333],{}," returns ",[74,356,357],{},"isError: true",", its text is thrown. OpenCode records a failed call. Thrown errors also carry the same ",[74,360,361],{},"caused by:"," lines as ",[364,365,40],"a",{"href":366},"\u002Fhosts\u002Fmcp#when-the-error-has-a-cause"," in their message.",[211,369,371],{"id":370},"what-the-model-reads","What the model reads",[70,373,374,375,378],{},"Text stays text. Images go out as file parts with a ",[74,376,377],{},"data:"," URI.",[70,380,381,382,385,386,389],{},"An empty result needs a little help. With no content blocks, the result is an empty string ",[74,383,384],{},"\"\"",". Otherwise OpenCode shows the model an empty list as ",[74,387,388],{},"\"undefined\"",". That's not much of an answer.",[70,391,392,395,396,398],{},[74,393,394],{},"details"," becomes the call's metadata. An object goes as is. Anything else, including an array or string, goes under a ",[74,397,394],{}," key.",[211,400,402],{"id":401},"progress-cancellation-and-questions","Progress, cancellation and questions",[70,404,405,406,409,410,413,414,417],{},"Progress goes where OpenCode expects it. ",[74,407,408],{},"progress?.(message, { progress, total })"," reaches OpenCode's ",[74,411,412],{},"context.progress",". OpenCode's call signal becomes the tool's ",[74,415,416],{},"signal",".",[70,419,420,423,424,301,427,430,431,417],{},[74,421,422],{},"host"," is OpenCode's own call context, handed over untouched. It contains ",[74,425,426],{},"sessionID",[74,428,429],{},"agent"," and ",[74,432,433],{},"messageID",[70,435,436,437,439,440,443,444,447],{},"There's no ",[74,438,227],{}," on OpenCode. It's ",[74,441,442],{},"undefined",", just like on the CLI and AI SDK. See ",[364,445,227],{"href":446},"\u002Fguide\u002Fdefining-tools#ask-the-person-not-the-model"," for the tool's question interface. OpenCode's permission question is a separate thing.",[449,450,451],"style",{},"html pre.shiki code .s38Sx, html code.shiki .s38Sx{--shiki-light:var(--ui-text-highlighted);--shiki-default:var(--ui-text-highlighted);--shiki-dark:var(--ui-text-highlighted)}html pre.shiki code .sK71F, html code.shiki .sK71F{--shiki-light:var(--shiki-token-function);--shiki-default:var(--shiki-token-function);--shiki-dark:var(--shiki-token-function)}html pre.shiki code .shU9J, html code.shiki .shU9J{--shiki-light:var(--shiki-token-string);--shiki-default:var(--shiki-token-string);--shiki-dark:var(--shiki-token-string)}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .skH_V, html code.shiki .skH_V{--shiki-light:var(--shiki-token-keyword);--shiki-default:var(--shiki-token-keyword);--shiki-dark:var(--shiki-token-keyword)}",{"title":101,"searchDepth":129,"depth":129,"links":453},[454,455,456,457,458],{"id":213,"depth":129,"text":214},{"id":322,"depth":129,"text":323},{"id":337,"depth":129,"text":338},{"id":370,"depth":129,"text":371},{"id":401,"depth":129,"text":402},"registerOpencodeTools puts every tool in an OpenCode plugin. Writes meet the permission rules, and with no rule they run unasked","md",null,{},{"title":56,"description":459},"sS_jmYegSZVgZpUNgX9Ng5yV6z6e6AjHS-npf8gTRT8",[466,461],{"title":52,"path":53,"stem":54,"description":467,"children":-1},"toAiTool turns a definition into an AI SDK tool. The TypeBox schema goes in as it is and nobody writes it again in Zod",[469,487,502,514,527],{"key":470,"rows":471,"registration":483,"fields":484},"mcp",[472,475,478,481],{"label":473,"value":474},"title","Text Slug",{"label":476,"value":477,"accent":147},"hints","readOnly, idempotent",{"label":479,"value":480},"inputSchema","text, separator",{"label":482,"value":357},"failure","{\n  \"name\": \"text_slug\",\n  \"title\": \"Text Slug\",\n  \"description\": \"Turn a title into a lowercase URL slug. Letters and digits stay, accents lose their marks, the rest becomes the separator.\",\n  \"inputSchema\": {\n    \"type\": \"object\",\n    \"properties\": {\n      \"text\": {\n        \"type\": \"string\",\n        \"minLength\": 1,\n        \"maxLength\": 200,\n        \"pattern\": \"\\\\S\",\n        \"description\": \"Title to slug\"\n      },\n      \"separator\": {\n        \"enum\": [\n          \"-\",\n          \"_\",\n          \".\"\n        ],\n        \"description\": \"Joins the words. '-' when omitted\"\n      }\n    },\n    \"required\": [\n      \"text\"\n    ],\n    \"additionalProperties\": false\n  },\n  \"annotations\": {\n    \"title\": \"Text Slug\",\n    \"readOnlyHint\": true,\n    \"destructiveHint\": false,\n    \"idempotentHint\": true,\n    \"openWorldHint\": false\n  }\n}",{"name":485,"label":473,"schema":479,"effect":486,"prompt":461,"run":461},"name","annotations",{"key":488,"rows":489,"registration":499,"fields":500},"pi",[490,492,495,497],{"label":491,"value":474},"label",{"label":493,"value":494,"accent":147},"prompt","snippet, 1 rule",{"label":496,"value":480},"parameters",{"label":482,"value":498},"thrown","{\n  \"prepareArguments\": \"[function]\",\n  \"name\": \"text_slug\",\n  \"label\": \"Text Slug\",\n  \"description\": \"Turn a title into a lowercase URL slug. Letters and digits stay, accents lose their marks, the rest becomes the separator.\",\n  \"promptSnippet\": \"Use text_slug to turn a title into a URL slug.\",\n  \"promptGuidelines\": [\n    \"Pass separator '_' for identifiers. The default '-' is for URLs.\"\n  ],\n  \"parameters\": {\n    \"type\": \"object\",\n    \"required\": [\n      \"text\"\n    ],\n    \"properties\": {\n      \"text\": {\n        \"type\": \"string\",\n        \"minLength\": 1,\n        \"maxLength\": 200,\n        \"pattern\": \"\\\\S\",\n        \"description\": \"Title to slug\"\n      },\n      \"separator\": {\n        \"enum\": [\n          \"-\",\n          \"_\",\n          \".\"\n        ],\n        \"description\": \"Joins the words. '-' when omitted\"\n      }\n    },\n    \"additionalProperties\": false\n  },\n  \"annotations\": {\n    \"readOnlyHint\": true,\n    \"destructiveHint\": false,\n    \"idempotentHint\": true,\n    \"openWorldHint\": false\n  },\n  \"execute\": \"[function]\"\n}",{"name":485,"label":491,"schema":496,"effect":486,"prompt":501,"run":333},"promptSnippet",{"key":503,"rows":504,"registration":512,"fields":513},"omp",[505,506,508,510],{"label":491,"value":474},{"label":507,"value":223,"accent":147},"approval",{"label":496,"value":509},"Type.Unsafe(json)",{"label":482,"value":511},"isError or thrown","{\n  \"name\": \"text_slug\",\n  \"label\": \"Text Slug\",\n  \"description\": \"Turn a title into a lowercase URL slug. Letters and digits stay, accents lose their marks, the rest becomes the separator.\",\n  \"parameters\": {\n    \"unsafe\": {\n      \"type\": \"object\",\n      \"required\": [\n        \"text\"\n      ],\n      \"properties\": {\n        \"text\": {\n          \"type\": \"string\",\n          \"minLength\": 1,\n          \"maxLength\": 200,\n          \"pattern\": \"\\\\S\",\n          \"description\": \"Title to slug\"\n        },\n        \"separator\": {\n          \"enum\": [\n            \"-\",\n            \"_\",\n            \".\"\n          ],\n          \"description\": \"Joins the words. '-' when omitted\"\n        }\n      },\n      \"additionalProperties\": false\n    }\n  },\n  \"approval\": \"read\",\n  \"strict\": false,\n  \"execute\": \"[function]\",\n  \"renderCall\": \"[function]\",\n  \"renderResult\": \"[function]\"\n}",{"name":485,"label":491,"schema":496,"effect":507,"prompt":461,"run":333},{"key":515,"rows":516,"registration":524,"fields":525},"ai",[517,518,520,523],{"label":473,"value":474},{"label":479,"value":519,"accent":147},"jsonSchema()",{"label":521,"value":522},"output","details + text",{"label":482,"value":498},"{\n  \"title\": \"Text Slug\",\n  \"description\": \"Turn a title into a lowercase URL slug. Letters and digits stay, accents lose their marks, the rest becomes the separator.\",\n  \"needsApproval\": false,\n  \"inputSchema\": {\n    \"type\": \"object\",\n    \"required\": [\n      \"text\"\n    ],\n    \"properties\": {\n      \"text\": {\n        \"type\": \"string\",\n        \"minLength\": 1,\n        \"maxLength\": 200,\n        \"pattern\": \"\\\\S\",\n        \"description\": \"Title to slug\"\n      },\n      \"separator\": {\n        \"enum\": [\n          \"-\",\n          \"_\",\n          \".\"\n        ],\n        \"description\": \"Joins the words. '-' when omitted\"\n      }\n    },\n    \"additionalProperties\": false\n  },\n  \"execute\": \"[function]\",\n  \"toModelOutput\": \"[function]\"\n}",{"name":461,"label":473,"schema":479,"effect":526,"prompt":461,"run":333},"needsApproval",{"key":68,"rows":528,"registration":537,"fields":538},[529,531,534,536],{"label":485,"value":530},"text_slug",{"label":532,"value":533,"accent":147},"permission","none, it's a read",{"label":535,"value":480},"input",{"label":482,"value":498},"{\n  \"name\": \"text_slug\",\n  \"description\": \"Turn a title into a lowercase URL slug. Letters and digits stay, accents lose their marks, the rest becomes the separator.\",\n  \"input\": {\n    \"type\": \"object\",\n    \"required\": [\n      \"text\"\n    ],\n    \"properties\": {\n      \"text\": {\n        \"type\": \"string\",\n        \"minLength\": 1,\n        \"maxLength\": 200,\n        \"pattern\": \"\\\\S\",\n        \"description\": \"Title to slug\"\n      },\n      \"separator\": {\n        \"enum\": [\n          \"-\",\n          \"_\",\n          \".\"\n        ],\n        \"description\": \"Joins the words. '-' when omitted\"\n      }\n    },\n    \"additionalProperties\": false\n  },\n  \"execute\": \"[function]\"\n}",{"name":485,"label":461,"schema":535,"effect":461,"prompt":461,"run":333},1796479391695]