ACP / Codex Background Runs
When a user asks to use ACP or an external coding agent such as Codex, Claude Code, Gemini CLI, or OpenCode, do not execute the task synchronously in the current chat. Route it through the ACP runtime instead.
Default Rules
- - Prefer
sessions_spawn and set runtime: "acp" with the appropriate INLINECODE2 - Default to INLINECODE3
- Only use
thread: true or mode: "session" when the user explicitly asks for an ongoing interactive or thread-bound session - Set
cwd when the target repository or directory is known - Prefer absolute paths for
cwd; do not pass ~ directly, expand it first - Use a relaxed
runTimeoutSeconds for longer tasks; do not mechanically default to INLINECODE10 - Do not wait in the current conversation and do not poll for progress
- Reply immediately after submission that the task has been accepted and is running in the background
- Rely on
sessions_spawn completion notifications to send the final result back to the current conversation - Only add
streamTo: "parent" when the user explicitly asks for progress updates
Default Handling
If the user is simply dispatching an ACP / Codex task and does not explicitly request a persistent interactive session, treat it as a one-shot background run. Do not block the current conversation. Send the result back only when the background run completes.
Timeout Guidance
- - Quick read-only checks, short analysis, light tasks: INLINECODE13
- Normal coding tasks, project inspection, small scoped edits: INLINECODE14
- Research, code changes, file generation, test runs, longer reports: INLINECODE15
- Clearly long-running tasks: increase further to
1800-3600 as needed - Do not default to
0; only use 0 when the user explicitly wants no timeout
mode / thread Decision Rules
- - If the user only wants the external agent to finish a task in the background, use INLINECODE21
- If the user explicitly wants to continue talking to the same external-agent context afterward, use INLINECODE22
- If the user explicitly asks for a persistent session, thread session, or long-lived context, use both
thread: true and INLINECODE24 - If there is no explicit need for ongoing interaction, do not open INLINECODE25
cwd Rules
- - If the target repository, project directory, or work directory is known, set INLINECODE27
- Prefer absolute paths
- Expand
~ before passing the path into INLINECODE29 - If the user did not give a directory but the task clearly targets a known repo, resolve the actual path from context before spawning
Fallback When ACP Is Unavailable
- - Try
runtime: "acp" first - Only fall back to
runtime: "subagent" when the ACP target agentId is clearly unavailable, unconfigured, or ACP cannot be used in the current environment - When falling back, tell the user explicitly that the task is being run via
subagent, not a native ACP session - Do not silently fall back
Reply After Submission
Use this short confirmation by default:
INLINECODE34
If streamTo: "parent" is enabled, also say that key progress updates will be streamed back.
Prohibited Actions
- - Do not execute external coding-agent tasks synchronously in the current conversation when they should go through ACP
- Do not poll after submission
- Do not call
sessions_list, sessions_history, or similar tools to track child-session progress - Do not use
sleep or timer-based waiting to fake background orchestration - Rely on the
sessions_spawn completion / announce mechanism for the final result
Recommended Parameter Template
CODEBLOCK0
When To Adjust
- - Need ongoing multi-turn context: add
thread: true and, if needed, INLINECODE41 - Task may run for many minutes: increase INLINECODE42
- Task is only a quick read-only check: keep
runTimeoutSeconds small - User explicitly wants progress relayed back: add INLINECODE44
- ACP is unavailable but the task should still run in the background: explain the fallback and use INLINECODE45
技能名称: acp-background-runs
详细描述:
ACP / Codex 后台运行
当用户要求使用ACP或外部编码代理(如Codex、Claude Code、Gemini CLI或OpenCode)时,不要在当前对话中同步执行任务。应通过ACP运行时进行路由。
默认规则
- - 优先使用 sessionsspawn,并设置 runtime: acp 及相应的 agentId
- 默认使用 mode: run
- 仅当用户明确要求进行持续的交互式或线程绑定会话时,才使用 thread: true 或 mode: session
- 当已知目标仓库或目录时,设置 cwd
- cwd 优先使用绝对路径;不要直接传递 ~,先将其展开
- 对于较长的任务,使用宽松的 runTimeoutSeconds;不要机械地默认为 300
- 不要在当前对话中等待,也不要轮询进度
- 提交后立即回复任务已被接受并在后台运行
- 依赖 sessionsspawn 的完成通知将最终结果发送回当前对话
- 仅当用户明确要求进度更新时,才添加 streamTo: parent
默认处理方式
如果用户只是分派一个ACP / Codex任务,并未明确要求持久的交互式会话,则将其视为一次性后台运行。不要阻塞当前对话。仅在后台运行完成时返回结果。
超时指导
- - 快速只读检查、简短分析、轻量任务:runTimeoutSeconds: 120-300
- 普通编码任务、项目检查、小范围编辑:runTimeoutSeconds: 600
- 研究、代码更改、文件生成、测试运行、较长报告:runTimeoutSeconds: 1200
- 明显长时间运行的任务:根据需要进一步增加到 1800-3600
- 不要默认设置为 0;仅当用户明确要求无超时时才使用 0
mode / thread 决策规则
- - 如果用户只希望外部代理在后台完成一个任务,使用 mode: run
- 如果用户明确希望之后继续与同一个外部代理上下文对话,使用 thread: true
- 如果用户明确要求持久会话、线程会话或长期上下文,同时使用 thread: true 和 mode: session
- 如果没有明确的持续交互需求,不要开启 mode: session
cwd 规则
- - 如果已知目标仓库、项目目录或工作目录,设置 cwd
- 优先使用绝对路径
- 在将路径传入 sessions_spawn 之前,先展开 ~
- 如果用户未提供目录,但任务明显针对已知仓库,在生成前从上下文中解析实际路径
ACP 不可用时的回退
- - 首先尝试 runtime: acp
- 仅当ACP目标 agentId 明显不可用、未配置,或当前环境无法使用ACP时,才回退到 runtime: subagent
- 回退时,明确告知用户任务是通过 subagent 运行的,而非原生ACP会话
- 不要静默回退
提交后的回复
默认使用以下简短确认信息:
任务已接受。它正在后台运行,完成后将在此处报告结果。
如果启用了 streamTo: parent,还需说明关键进度更新将被流式传回。
禁止操作
- - 当任务应通过ACP路由时,不要在当前对话中同步执行外部编码代理任务
- 提交后不要轮询
- 不要调用 sessionslist、sessionshistory 或类似工具来跟踪子会话进度
- 不要使用 sleep 或基于定时器的等待来模拟后台编排
- 依赖 sessions_spawn 的完成/通知机制获取最终结果
推荐参数模板
json
{
task: <用户请求>,
runtime: acp,
agentId: ,
mode: run,
cwd: /绝对/路径/如果已知,
runTimeoutSeconds: 300
}
何时调整
- - 需要持续的多轮上下文:添加 thread: true,如果需要,添加 mode: session
- 任务可能运行数分钟:增加 runTimeoutSeconds
- 任务只是快速只读检查:保持 runTimeoutSeconds 较小
- 用户明确要求回传进度:添加 streamTo: parent
- ACP不可用但任务仍应在后台运行:解释回退并使用 runtime: subagent