Agent CLI

让本机 Agent 通过 token 鉴权的回环接口管理提示词和分类。

先在设置中启用

Local CLI 默认关闭。打开 AI Gist 的设置,进入“本地 CLI”,启用访问并创建 token。服务只监听本机回环地址。

Agent 必须使用 token 鉴权。不要把 token 写进仓库、脚本日志或共享终端。

自动化前先检查连接

应用必须保持运行。每次自动化先执行 status;连接失败时不要继续读写。

node bin/ai-gist.js status
node bin/ai-gist.js --json status

读取提示词、分类和统计

prompt list、category list 和 stats 默认输出可读文本。把全局 --json 放在子命令前,得到机器可读的 JSON。

node bin/ai-gist.js --json prompt list
node bin/ai-gist.js prompt get 12
node bin/ai-gist.js category list
node bin/ai-gist.js --json stats

创建和更新提示词

prompt create 需要 --title,以及 --content 或 --content-file。prompt update 只修改明确提供的字段;<ref> 可以是数字 ID 或 UUID。

node bin/ai-gist.js prompt create --title "Bug report" --content "Summarize: {{topic}}"
node bin/ai-gist.js prompt update 12 --title "Release summary"
node bin/ai-gist.js prompt update 12 --content-file ./prompt.txt

定义并填写变量

先在正文中写 {{name}}。variable sync 会为未定义的占位符创建文本变量;variable add 可以指定类型、默认值和必填状态。填充时重复传入 --var name=value。

node bin/ai-gist.js prompt variable sync 12
node bin/ai-gist.js prompt variable add 12 --name tone --type select --options "formal,direct" --required
node bin/ai-gist.js prompt fill 12 --var topic="Q3 roadmap" --var tone=formal

让 AI 帮你管理提示词库

Agent 可以先用 stats 和 prompt list 了解库中内容,再用 prompt get 读取指定条目,最后通过 create、update 或 variable 命令执行小范围修改。每一步都检查 JSON 输出和返回结果,不要让 Agent 直接访问 IndexedDB。

node bin/ai-gist.js --json stats
node bin/ai-gist.js --json prompt list
node bin/ai-gist.js --json prompt get 12

失败边界

CLI 只是本机回环桥接,不是远程 API。应用未运行、CLI 未启用或 token 无效时,应停止并让用户处理。

  • 服务关闭:连接被拒绝。
  • CLI 未启用:服务端拒绝请求。
  • token 无效:返回鉴权错误。