跳至内容

运行

在文件上运行脚本,并将LLM输出流式传输到标准输出或工作区根目录下的文件夹。

终端窗口
npx genaiscript run <script> "<files...>"

其中

文件也可以包含glob模式。

终端窗口
npx genaiscript run code-annotator "src/*.ts"

如果指定了多个文件,所有文件都会被包含在env.files中。

终端窗口
npx genaiscript run <script> "src/*.bicep" "src/*.ts"

文件

run 接受一个或多个 glob 模式来匹配工作区中的文件。

终端窗口
npx genaiscript run <script> "**/*.md" "**/*.ts"

管道操作

run 接收标准输入内容并将其转换为 stdin 文件。 大语言模型的输出会发送到 stdout,而其余的日志信息则发送到 stderr

终端窗口
cat README.md | genaiscript run summarize > summary.md

—excluded-files <文件…>

从文件集中排除指定的文件。

终端窗口
npx genaiscript run <script> <files> --excluded-files <excluded-files...>

—排除-git-忽略

排除工作区根目录下.gitignore文件所忽略的文件。

终端窗口
npx genaiscript run <script> <files> --exclude-git-ignore

配置

—model …

配置默认或large模型别名。使用echo进行试运行并返回消息,而不是调用LLM提供商。

—provider …

为给定的LLM提供商加载一组模型别名。

—变量 名称=值 名称2=值2 …

填充env.vars映射中的值,这些值可以在运行提示时使用。

输出

—输出 <文件|目录>

将结果保存为JSON文件,同时包含输出的markdown文件和跟踪记录。

终端窗口
npx genaiscript run <script> <files> --out out/res.json

如果 file 不以 .json 结尾,则该路径将被视为目录路径。

终端窗口
npx genaiscript run <script> <files> --out tmp

—json

将整个响应以JSON格式输出到标准输出(stdout)。

—yaml

将整个响应以YAML格式输出到标准输出(stdout)。

—out-trace <文件>

将markdown跟踪信息保存到指定文件。

终端窗口
npx genaiscript run <script> <files> --out-trace &lt;file&gt;

在GitHub Actions工作流中,您可以使用此功能将跟踪保存为步骤摘要(GITHUB_STEP_SUMMARY):

.github/workflows/genaiscript.yml
- name: Run GenAIScript tool on spec
run: |
genaiscript run <script> <files> --out-trace $GITHUB_STEP_SUMMARY

在Azure Dev Ops中,您可以在流水线中使用task.uploadSummary将跟踪记录作为摘要上传。

genaiscript.pipeline.yml
- script: npx --yes genaiscript run poem --out-trace $(System.DefaultWorkingDirectory)/trace.md
displayName: "Run GenAIScript tool"
continueOnError: true
- script: echo "##vso[task.uploadsummary]$(System.DefaultWorkingDirectory)/trace.md"
displayName: "append readme to pipeline report"

—输出注释文件

将指定文件中的注释以JSON数组、JSON Lines、SARIF格式输出,如果文件以.csv结尾则输出为CSV文件。

终端窗口
npx genaiscript run <script> <files> --out-annotations diags.csv

使用JSON行格式(.jsonl)将多次运行的注释汇总到单个文件中。

终端窗口
npx genaiscript run <script> <files> --out-annotations diags.jsonl

—out-data <文件>

将解析后的数据以JSON、YAML或JSONL格式输出。如果指定了JSON模式且可用,还会存储JSON验证结果。

终端窗口
npx genaiscript run <script> <files> --out-data data.jsonl

—out-changelogs <文件>

将变更日志以文本形式输出到指定文件中。

终端窗口
npx genaiscript run <script> <files> --out-changelogs changelogs.txt

拉取请求和问题

CLI可以在GitHub Action或Azure DevOps流水线中运行时更新拉取请求/问题描述和评论。

GitHub Action 工作流配置

更新您的工作流配置以包含以下内容:

  • 在工作流/步骤中添加pull-requests: write权限
permissions:
pull-requests: write
  • 在运行cli时,在env中设置GITHUB_TOKEN密钥
- run: npx --yes genaiscript run ... -prc --out-trace $GITHUB_STEP_SUMMARY
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
... # LLM secrets

Azure DevOps 配置

  • 在仓库的协作者角色中添加 Build Service
  • 向脚本传递密钥,包括 System.AccessToken
- script: npx genaiscript run ... -prd
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)
... # LLM secrets

—pull-request-description [标签]

当在GitHub Action或Azure DevOps流水线中针对拉取请求运行时,CLI会将LLM输出插入到拉取请求的描述中(示例)

终端窗口
npx genaiscript run ... -prd

tag 参数是一个唯一标识符,用于区分不同运行生成的描述。默认为脚本ID。

—pull-request-comment [标签];

在拉取请求/问题上插入一条包含LLM输出的评论(示例)

终端窗口
npx genaiscript run ... -prc

tag 参数是一个唯一标识符,用于区分不同运行生成的描述。默认值为脚本ID。

—拉取请求审查

从每个annotations创建拉取请求审查评论 (example)。

终端窗口
npx genaiscript run ... -prr

了解更多

完整选项列表可在CLI参考文档中查看。