Run xAI Grok locally via bundled scripts (search + chat + model listing). Default output for search is pretty JSON (agent-friendly) with citations.
API key
The script looks for an xAI API key in this order:
- -
XAI_API_KEY env var - INLINECODE1 → INLINECODE2
- INLINECODE3 → INLINECODE4
- fallback:
skills.entries["search-x"].apiKey or INLINECODE6
Run
Use {baseDir} so the command works regardless of workspace layout.
Search
- INLINECODE8
- - X/Twitter search (JSON):
- INLINECODE9
Chat
- INLINECODE10
- INLINECODE11
Models
- INLINECODE12
Useful flags
Output:
- -
--links-only print just citation URLs - INLINECODE14 hide the citations section in pretty output
- INLINECODE15 include the raw Responses API payload on stderr (debug)
Common:
- -
--max <n> limit results (default 8) - INLINECODE17 (default
grok-4-1-fast)
X-only filters (server-side via x_search tool params):
- -
--days <n> (e.g. 7) - INLINECODE20 / INLINECODE21
- INLINECODE22 (limit to these handles)
- INLINECODE23 (exclude handles)
Output shape (JSON)
CODEBLOCK0
Notes
- -
citations are merged/validated from xAI response annotations where possible (more reliable than trusting the model’s JSON blindly). - Prefer
--x for tweets/threads, --web for general research.
技能名称: grok-search
详细描述:
通过捆绑脚本本地运行xAI Grok(搜索+聊天+模型列表)。搜索默认输出为美观JSON(对代理友好)并附带引用来源。
API密钥
脚本按以下顺序查找xAI API密钥:
- - XAIAPIKEY 环境变量
- ~/.clawdbot/clawdbot.json → env.XAIAPIKEY
- ~/.clawdbot/clawdbot.json → skills.entries[grok-search].apiKey
- 回退方案:skills.entries[search-x].apiKey 或 skills.entries.xai.apiKey
运行
使用 {baseDir} 确保命令不受工作区布局影响。
搜索
- node {baseDir}/scripts/grok_search.mjs <查询词> --web
- node {baseDir}/scripts/grok_search.mjs <查询词> --x
聊天
- node {baseDir}/scripts/chat.mjs <提示词>
- node {baseDir}/scripts/chat.mjs --image /path/to/image.jpg <提示词>
模型
- node {baseDir}/scripts/models.mjs
实用标志
输出控制:
- - --links-only 仅打印引用URL
- --text 在美观输出中隐藏引用部分
- --raw 在stderr中包含原始Responses API负载(调试用)
通用参数:
- - --max 限制结果数量(默认8)
- --model (默认grok-4-1-fast)
X专用过滤器(通过x_search工具参数在服务端生效):
- - --days (例如7)
- --from YYYY-MM-DD / --to YYYY-MM-DD
- --handles @a,@b(限定特定用户)
- --exclude @bots,@spam(排除特定用户)
输出格式(JSON)
json
{
query: ...,
mode: web | x,
results: [
{
title: ...,
url: ...,
snippet: ...,
author: ...,
posted_at: ...
}
],
citations: [https://...]
}
注意事项
- - citations 尽可能从xAI响应注释中合并/验证(比盲目信任模型的JSON更可靠)。
- 推文/帖子搜索优先使用 --x,通用研究搜索优先使用 --web。