← 返回官网首页

Extension Guide

用一个 manifest.json,把高频操作变成燕子扩展。

扩展的核心是一个标准 JSON 文件。简单动作直接声明目标,复杂动作使用 C# 或 PowerShell,快捷面板会把选中的文本或文件路径传入动作上下文。

如何选择扩展类型

打开文件、目录、网页 使用 openTarget,最稳定,适合常用目录、系统设置和固定网页。
搜索类命令 使用 queryPrefixesqueryTargetTemplate,把用户输入替换到 {query}
处理选中文本/文件 优先使用 C#,读取 context.InputText,适合文本处理、API 调用和复杂逻辑。
Windows 自动化 使用 PowerShell,适合剪贴板、进程、文件系统和系统命令。

打开目录、网页或系统位置

这是最简单的扩展形式,只需要声明 openTarget

{
  "id": "open-downloads",
  "name": "打开下载目录",
  "version": "0.1.0",
  "category": "目录",
  "description": "打开当前用户的下载目录。",
  "keywords": ["downloads", "下载", "xiazai"],
  "icon": "mdi:folder",
  "openTarget": "C:\\Users\\你的用户名\\Downloads"
}

带参数网页搜索

当用户输入 谷歌 Yanzigg Yanzi 时,剩余文本会替换到模板中的 {query}

{
  "id": "google-search",
  "name": "谷歌搜索",
  "version": "0.1.0",
  "category": "搜索",
  "description": "用默认浏览器打开 Google 搜索。",
  "keywords": ["google", "谷歌", "gg", "guge"],
  "icon": "mdi:search",
  "queryPrefixes": ["谷歌", "google", "gg", "guge"],
  "queryTargetTemplate": "https://www.google.com/search?q={query}"
}

C# 动作:处理选中文本

快捷面板执行扩展时,燕子会在点击扩展后抓取当前选中的文本或文件路径,并写入 context.InputText

{
  "id": "csharp-selection-summary",
  "name": "选中内容摘要",
  "version": "0.1.0",
  "category": "C#",
  "description": "读取快捷面板传入的选中文本。",
  "keywords": ["csharp", "selection", "选中", "摘要"],
  "icon": "mdi:code",
  "runtime": "csharp",
  "entryMode": "inline",
  "permissions": ["context.read"],
  "script": {
    "source": "using OpenQuickHost.CSharpRuntime;\\n\\npublic static class YanziAction\\n{\\n    public static Task<string> RunAsync(YanziActionContext context)\\n    {\\n        var text = string.IsNullOrWhiteSpace(context.InputText) ? \\\"没有收到选中内容。\\\" : context.InputText.Trim();\\n        return Task.FromResult($\\\"来源: {context.LaunchSource}\\\\n长度: {text.Length}\\\\n\\\\n{text}\\\");\\n    }\\n}"
  }
}

C# 入口要求

using OpenQuickHost.CSharpRuntime;

public static class YanziAction
{
    public static Task<string> RunAsync(YanziActionContext context)
    {
        return Task.FromResult(context.InputText);
    }
}

PowerShell 自动化

PowerShell 适合调用系统命令、读取剪贴板、操作进程和文件。

{
  "id": "clipboard-read",
  "name": "读取剪贴板",
  "version": "0.1.0",
  "category": "脚本",
  "description": "读取当前剪贴板文本。",
  "keywords": ["clipboard", "剪贴板"],
  "icon": "mdi:clipboard",
  "runtime": "powershell",
  "entryMode": "inline",
  "permissions": ["clipboard.read"],
  "script": {
    "source": "param([string]$InputText = \\\"\\\", [string]$ContextPath = \\\"\\\")\\n[Console]::OutputEncoding = [System.Text.Encoding]::UTF8\\n$text = Get-Clipboard -Raw\\nif ([string]::IsNullOrWhiteSpace($text)) { Write-Output \\\"当前剪贴板为空。\\\" } else { Write-Output $text.Trim() }"
  }
}

需要界面的扩展

使用 hostedView 可以让扩展在主窗口中展示输入区、输出区和执行按钮,适合翻译、文本处理和查询类工具。

{
  "id": "text-workbench",
  "name": "文本处理台",
  "version": "0.1.0",
  "category": "工具",
  "description": "在宿主窗口中输入文本并执行 C# 动作。",
  "keywords": ["text", "文本", "workbench"],
  "icon": "mdi:terminal",
  "runtime": "csharp",
  "entryMode": "inline",
  "hostedView": {
    "type": "split-workbench",
    "title": "文本处理台",
    "description": "左侧输入文本,右侧显示执行结果。",
    "inputLabel": "输入",
    "inputPlaceholder": "输入要处理的文本...",
    "outputLabel": "结果",
    "actionButtonText": "执行",
    "actionType": "script",
    "emptyState": "结果会显示在这里。"
  },
  "script": {
    "source": "using OpenQuickHost.CSharpRuntime;\\n\\npublic static class YanziAction\\n{\\n    public static Task<string> RunAsync(YanziActionContext context)\\n    {\\n        return Task.FromResult(context.InputText.ToUpperInvariant());\\n    }\\n}"
  }
}

图标写法

  • 内置图标:mdi:searchmdi:translatemdi:foldermdi:clipboardmdi:code
  • 应用别名:app:wechatapp:qqapp:googleapp:selection
  • 图片路径:扩展目录下相对路径,例如 icons/logo.png,也支持绝对路径和 HTTPS 图片地址

给 AI 的提示词

复制这段给 AI,可以让它生成能直接导入燕子的扩展 JSON。

请为燕子 Yanzi 生成一个单文件 manifest.json 扩展。

要求:
1. 只输出合法 JSON,不要 Markdown 代码块。
2. 优先使用 runtime = "csharp"、entryMode = "inline"、script.source。
3. C# 源码必须包含 public static class YanziAction,并实现 public static Task<string> RunAsync(YanziActionContext context)。
4. 如果只是打开文件、目录、网页或系统协议,使用 openTarget,不要写脚本。
5. 如果是搜索类命令,使用 queryPrefixes 和 queryTargetTemplate,模板里用 {query}。
6. 如果需要宿主界面,使用 hostedView,actionType 优先使用 script。
7. 必须包含 id、name、version、category、description、keywords。
8. icon 优先使用内置值,例如 mdi:search、mdi:folder、mdi:clipboard、mdi:code、mdi:translate。
9. 不要写 null 字段,不要补充燕子未支持的字段。
10. 输出的 JSON 要能直接保存为 manifest.json。

我要的扩展功能是:
在这里描述你的需求。