Skip to content

Commit 57dbd30

Browse files
committed
docs(ai): 补充 agent runner 使用说明
1 parent 1100106 commit 57dbd30

4 files changed

Lines changed: 128 additions & 0 deletions

File tree

bin/Invoke-AiAgent.ps1

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env -S pwsh -NoProfile
2+
3+
# Auto-generated shim by Manage-BinScripts.ps1
4+
# Source: /Users/mudssky/projects/powershellScripts/scripts/pwsh/ai/agent-runner/main.ps1
5+
6+
<#
7+
.SYNOPSIS
8+
通过本机 coding agent 执行 prompt 或内置 preset。
9+
10+
.DESCRIPTION
11+
支持 `codex`、`claude`、`opencode` 三个 agent,并通过 Markdown preset 管理常用任务。
12+
13+
.PARAMETER CommandName
14+
顶层命令,支持 `run`、`commit`、`help`。
15+
16+
.PARAMETER Prompt
17+
直接执行的 prompt 文本。
18+
19+
.PARAMETER PromptFile
20+
prompt 文件路径。
21+
22+
.PARAMETER Preset
23+
prompt preset 名称。
24+
#>
25+
26+
[CmdletBinding(PositionalBinding = $false)]
27+
param(
28+
[Parameter(Position = 0)]
29+
[string]$CommandName,
30+
31+
[Parameter(Position = 1)]
32+
[string]$Prompt,
33+
34+
[string]$PromptFile,
35+
[string]$Preset,
36+
37+
[ValidateSet('codex', 'claude', 'opencode')]
38+
[string]$Agent,
39+
40+
[string]$Model,
41+
42+
[ValidateSet('minimal', 'low', 'medium', 'high', 'xhigh')]
43+
[string]$ReasoningEffort,
44+
45+
[string]$WorkDir,
46+
[switch]$Json,
47+
[switch]$DryRun,
48+
[string[]]$ExtraArgs
49+
)
50+
51+
$SourcePath = Join-Path $PSScriptRoot '../scripts/pwsh/ai/agent-runner/main.ps1'
52+
if (-not (Test-Path $SourcePath)) {
53+
Write-Error "Cannot find source script at $SourcePath"
54+
exit 1
55+
}
56+
& $SourcePath @PSBoundParameters
57+
exit $LASTEXITCODE
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# AI Agent Runner
2+
3+
`agent-runner` 是一个跨平台 PowerShell CLI,用来通过本机 coding agent 执行一次性 prompt。
4+
5+
安装 bin shim:
6+
7+
```powershell
8+
pwsh -NoProfile -File ./Manage-BinScripts.ps1 -Action sync -Force
9+
```
10+
11+
常用命令:
12+
13+
```powershell
14+
./bin/Invoke-AiAgent.ps1 commit
15+
./bin/Invoke-AiAgent.ps1 commit -ReasoningEffort high
16+
./bin/Invoke-AiAgent.ps1 run "修复 failing tests,并执行 pnpm qa"
17+
./bin/Invoke-AiAgent.ps1 run -PromptFile ./task.md -Agent claude
18+
./bin/Invoke-AiAgent.ps1 run -Preset commit -Agent codex
19+
```
20+
21+
## Prompt preset
22+
23+
内置 preset 位于 `prompts/*.md`,文件开头可以声明 frontmatter:
24+
25+
```markdown
26+
---
27+
agent: codex
28+
reasoning_effort: medium
29+
---
30+
31+
检查当前 Git 变更并提交 commit。
32+
```
33+
34+
优先级从低到高:
35+
36+
1. 工具默认值
37+
2. preset frontmatter
38+
3. CLI 显式参数
39+
40+
## Agent 支持
41+
42+
- `codex`:支持 `model``reasoning_effort``json``work_dir`
43+
- `claude`:支持 `model``json``work_dir`,不映射 `reasoning_effort`
44+
- `opencode`:支持 `model``work_dir`,不映射 `reasoning_effort`
45+
46+
`commit` preset 会让 agent 执行本地 `git commit`,不会执行 `git push`
47+
48+
## 常见问题
49+
50+
- 未找到 CLI:先安装对应的 `codex``claude``opencode` 并完成登录。
51+
- 没有 Git 变更:`commit` preset 应以非零退出码结束。
52+
- 验证失败:修复验证命令报告的问题后重新运行。
53+
- 需要透传 agent 私有参数:使用 `-ExtraArgs`
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@{
2+
BinName = 'Invoke-AiAgent.ps1'
3+
Entry = 'main.ps1'
4+
}

tests/AiAgentRunner.Tests.ps1

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,17 @@ Describe 'AI agent runner prompt and config' {
147147
$request.Preset | Should -Be 'commit'
148148
}
149149
}
150+
151+
Describe 'AI agent runner public script' {
152+
It 'prints a safe dry-run preview for commit' {
153+
$scriptPath = Join-Path $script:RunnerRoot 'main.ps1'
154+
$pwshPath = (Get-Command pwsh -ErrorAction Stop).Source
155+
$output = & $pwshPath -NoProfile -File $scriptPath commit -DryRun -ReasoningEffort high 2>&1
156+
157+
$LASTEXITCODE | Should -Be 0
158+
($output -join "`n") | Should -Match 'codex exec'
159+
($output -join "`n") | Should -Match 'model_reasoning_effort="high"'
160+
($output -join "`n") | Should -Match '<PROMPT>'
161+
($output -join "`n") | Should -Not -Match '检查当前 Git 变更'
162+
}
163+
}

0 commit comments

Comments
 (0)