跳至正文
Taku Docs

版本 1.4.0(当前)

开发你的第一个插件

创建一个返回真实问候的 Skill/MCP 插件,安装后由 Agent 调用,再卸载。

本教程使用社区 Skill/MCP 格式,与 God Mode 的 manifest.json 格式不同。需要已提供 taku-plugin 的 Taku 开发版本;Agent 调用还需要连接模型。

完整文件和安装包都在公开社区仓库:源码、ZIP、SHA-256。也可以直接复制下面四个文件。

验证范围

示例已通过主机上的 MCP 协议和包校验。创建、打包、试装与经电脑提交社区 PR 的既有流程在专用开发模拟器验证过;本例在发行 ROM 上的 Agent/UI 调用仍需按下方步骤实际检查。

创建文件

新建 taku-hello-world/ 目录,文件路径如下。只放本插件需要的内容,不放账号或个人资料。

.codex-plugin/plugin.json

{
  "name": "taku-hello-world",
  "version": "1.0.1",
  "description": "Return a local greeting through the Agent. No network or personal data.",
  "author": {
    "name": "Taku OS"
  },
  "license": "Apache-2.0",
  "skills": "./skills/",
  "mcpServers": "./.mcp.json",
  "taku": {
    "capabilities": [
      "return a local greeting"
    ],
    "permissions": []
  }
}

.mcp.json

{
  "mcpServers": {
    "hello-world": {
      "command": "/system/bin/sh",
      "args": [
        "./server.sh"
      ],
      "cwd": "."
    }
  }
}

server.sh

#!/system/bin/sh

while IFS= read -r line; do
  id=$(printf '%s' "$line" | sed -n 's/.*"id"[[:space:]]*:[[:space:]]*\([0-9][0-9]*\).*/\1/p')
  [ -n "$id" ] || continue

  case "$line" in
    *'"initialize"'*)
      printf '{"jsonrpc":"2.0","id":%s,"result":{"protocolVersion":"2024-11-05","capabilities":{"tools":{}},"serverInfo":{"name":"taku-hello-world","version":"1.0.1"}}}\n' "$id"
      ;;
    *'"tools/list"'*)
      printf '{"jsonrpc":"2.0","id":%s,"result":{"tools":[{"name":"hello_world","description":"Return the first Taku OS plugin greeting","inputSchema":{"type":"object","properties":{},"additionalProperties":false}}]}}\n' "$id"
      ;;
    *'"tools/call"'*)
      printf '{"jsonrpc":"2.0","id":%s,"result":{"content":[{"type":"text","text":"Hello from Taku!"}],"structuredContent":{"message":"Hello from Taku!","runtime":"on-device","plugin":"taku-hello-world"}}}\n' "$id"
      ;;
    *)
      printf '{"jsonrpc":"2.0","id":%s,"error":{"code":-32601,"message":"Method not found"}}\n' "$id"
      ;;
  esac
done

skills/hello-world/SKILL.md

---
name: hello-world
description: Call the local hello_world tool when the user asks for the Taku plugin greeting.
---

Call `hello_world` and relay its actual result. Do not invent a successful call. The expected result is `Hello from Taku!`.

校验、安装与调用

从电脑把目录放到自己的设备,SERIAL 替换为 adb devices -l 中的设备:

这条电脑安装路径需要支持 root ADB 的 Taku userdebug 开发镜像,工作目录由 root 持有。若 adb root 被拒绝就停止,不要在原厂生产系统上继续。id 应显示 uid=0(root)。

adb -s SERIAL root
adb -s SERIAL wait-for-device
adb -s SERIAL shell id
adb -s SERIAL push taku-hello-world /data/local/agentos/work/
adb -s SERIAL shell

然后在设备 shell 执行:

taku-plugin validate /data/local/agentos/work/taku-hello-world
taku-plugin pack /data/local/agentos/work/taku-hello-world /data/local/agentos/work/hello-world-package
taku-plugin catalog-add /data/local/agentos/work/hello-world-package

把返回的 marketplace 路径用于安装:

taku-plugin install MARKETPLACE_PATH taku-hello-world
taku-plugin list
taku-plugin status

对已连接的 Agent 说:调用 Hello World 插件,把它实际返回的问候给我。

成功时,执行记录应出现 hello_world 工具调用,结果为 Hello from Taku!。只有聊天文字而没有工具调用,不算完成。没有调用时,先查模型连接、taku-plugin status 和 MCP 加载结果。

停用测试与卸载

使用 taku-plugin list 返回的完整插件 ID:

taku-plugin uninstall PLUGIN_ID

退出码 2 表示安装或卸载已完成,但 MCP 重新加载失败。先读状态,再决定是否重试。

分享插件

可以让 Agent 打包已经跑通的任务,也可以执行 taku-plugin publish DIR OUTPUT_DIR。提交社区 PR 需要已登录的 gh 和 git;Android 缺少这些工具时使用已授权电脑上的发布辅助程序。拿到 PR URL 才表示已提交;只返回本地包路径不表示发布成功。从公开社区仓库获取电脑端发布脚本,在连接设备且已登录自己 GitHub 账号的电脑上运行:

这段命令使用 Bash(macOS/Linux;Windows 可用 WSL)和 Python 3。请先查看上面固定版本的脚本内容;它只使用 Python 标准库。校验与执行在同一 Python 进程中完成,哈希不符、下载失败或文件过大时直接退出;-I 避免当前目录中的模块影响校验。

python3 -I - SERIAL OUTPUT_DIR <<'PY_HELPER'
import hashlib
import sys
import urllib.request

if len(sys.argv) != 3:
    raise SystemExit("Provide your device serial and packed output directory")
url = "https://raw.githubusercontent.com/Taku-OS/taku-os-plugins/b783b226424217ceca700f3444e64a26ef8149d3/scripts/publish-from-device.py"
expected = "a566dcca0fa39f7fc5f851d0e1b47a7980b8b06abd737c451d37a3ff881a120f"
with urllib.request.urlopen(url, timeout=30) as response:
    source = response.read(65537)
if len(source) > 65536 or hashlib.sha256(source).hexdigest() != expected:
    raise SystemExit("Helper verification failed; nothing was executed")
sys.argv = ["publish-from-device.py", "--serial", sys.argv[1], "--packed", sys.argv[2]]
exec(compile(source, "<verified Taku publishing helper>", "exec"), {"__name__": "__main__"})
PY_HELPER

它只传输插件包,不复制电脑凭据到手机。流程见社区插件格式与分享。

插件以 Agent 的权限运行,capabilities 和 permissions 是声明,不是沙箱。示例不联网、不读取用户数据;安装其他插件前按其实际行为核对权限与来源。

Research preview · 查看当前可用范围

文档检索

搜索本站公开文档,返回原文摘录与引用。当前使用全文检索,不由大模型生成答案。

每个结果都能回到文档原文。研究设想与已跑通的能力分开阅读。

查看帮助与排错 →
这篇文档有帮助吗?
纠错或反馈

送达维护队列不代表已处理。反馈保留 90 天。

基于 Fumadocs

本页目录