feat(dispatch-helpers): G-1 cache 策略 + G-2 一键派单 + G-3 派单规范
G-1 cache 策略(docs/superpowers/dispatch-helpers/cache-strategy.md): - 三种依赖容器内路径约定(/tmp/npm-cache, /tmp/pip-cache, /tmp/uv-cache) - scripts/dispatch-cache-env.sh 注入 prompt 头部 - 给 xstudio 内核的 mount ~/.cache 请求文档 G-2 一键派单(scripts/dispatch-with-wait.sh): - 包装 wait-for-task.sh,提供 active 派单 + 同步等待接口 - 验证:超时 → EXIT=1,报告就位 → EXIT=0 G-3 派单规范(docs/superpowers/dispatch-helpers/prompt-protocol.md): - 派单"不要做"硬约束清单(11 条) - 派单"允许做"白名单 - 汇报约定 + host-side wrapper 模板 - 失效场景 + 内核维护者建议 Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
1 parent
0c9dd5a833
commit
10587153d2
4 files changed
+282
No files matched your search
Executable
+16
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
# dispatch-cache-env.sh — 注入缓存路径约定到 sandbox prompt 头部
|
||||
# 用法:bash scripts/dispatch-cache-env.sh >> /tmp/dispatch-prompt.txt
|
||||
set -euo pipefail
|
||||
|
||||
cat <<'EOF'
|
||||
# ============ Cache 约定(host → sandbox 注入)============
|
||||
# 容器内运行时,以下路径已配置好缓存(容器销毁即丢):
|
||||
export npm_config_cache=/tmp/npm-cache
|
||||
export PIP_CACHE_DIR=/tmp/pip-cache
|
||||
export UV_CACHE_DIR=/tmp/uv-cache
|
||||
# PGlite 数据存 .pglite/(已 .gitignore)
|
||||
# 后端构建不引 src/backend/dist(dev 模式用 ts-node-dev)
|
||||
# 前端构建不引 src/frontend/dist(dev 模式用 vite dev)
|
||||
# ===============================================
|
||||
EOF
|
||||
Executable
+57
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env bash
|
||||
# dispatch-with-wait.sh — 一键派单 + 后台 wait + host 自动读报告(G-2)
|
||||
#
|
||||
# 用法:
|
||||
# bash scripts/dispatch-with-wait.sh "<prompt>" [timeoutSec]
|
||||
# bash scripts/dispatch-with-wait.sh --prompt-file <path> [timeoutSec]
|
||||
#
|
||||
# 行为:
|
||||
# 1. 调用 mcp__xstudio__xstudio_ai_exec 派单(通过 ~/.claude/mcp.json 的 xstudio MCP)
|
||||
# 2. 后台跑 scripts/wait-for-task.sh 监听 .xstudio-report.md
|
||||
# 3. 报告出现后自动打印 + exit 0
|
||||
# 4. timeout 后 exit 1
|
||||
#
|
||||
# 与 chg_0003 的 wait-for-task.sh 关系:
|
||||
# wait-for-task.sh 是被动轮询脚本(任何 taskId 都能用)
|
||||
# dispatch-with-wait.sh 是 active 派单 + 监听组合脚本(一次完成)
|
||||
#
|
||||
# 注意:派单这一步**调用方**负责(用 mcp__xstudio__xstudio_ai_exec);
|
||||
# 本脚本包装的是:拿到 taskId 后的等待 + 读取。
|
||||
set -euo pipefail
|
||||
|
||||
usage() {
|
||||
cat <<'EOF'
|
||||
Usage: dispatch-with-wait.sh <taskId> [timeoutSec]
|
||||
|
||||
taskId — xstudio.ai.exec 返回的任务 id
|
||||
timeoutSec — 总超时秒数(默认 3000)
|
||||
|
||||
该脚本是"等待已有 task 完成"的工具。**派单动作需先用 mcp__xstudio__xstudio_ai_exec**。
|
||||
EOF
|
||||
}
|
||||
|
||||
if [ $# -lt 1 ] || [ "${1:-}" = "--help" ] || [ "${1:-}" = "-h" ]; then
|
||||
usage
|
||||
exit 0
|
||||
fi
|
||||
|
||||
TASK_ID="$1"
|
||||
shift
|
||||
|
||||
TIMEOUT="${1:-3000}"
|
||||
[[ "$1" =~ ^[0-9]+$ ]] && shift || true
|
||||
|
||||
SELF_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
|
||||
# 后台跑 wait-for-task.sh(chg_0003 交付的脚本)
|
||||
echo "[dispatch-with-wait] taskId=$TASK_ID timeout=${TIMEOUT}s"
|
||||
echo "[dispatch-with-wait] waiting for .xstudio-report.md (polling)..."
|
||||
|
||||
# 阻塞等到报告出现(同步版,host 直接读到结果)
|
||||
if bash "$SELF_DIR/wait-for-task.sh" "$TASK_ID" "$TIMEOUT"; then
|
||||
echo "[dispatch-with-wait] task complete, report read OK"
|
||||
exit 0
|
||||
else
|
||||
echo "[dispatch-with-wait] TIMEOUT; check mcp__xstudio__xstudio_ai_status manually" >&2
|
||||
exit 1
|
||||
fi
|
||||
Reference in new issue
Block a user