agent-exec transport 2f332e8b99c2b13e0f8734136a777328/db30d3293d24

This commit is contained in:
agent-exec-transport
2026-10-18 14:34:23 +00:00
parent f81326bd08
commit 1ff6444d33
2 changed files with 14 additions and 12 deletions
+12 -10
View File
@@ -18,13 +18,13 @@ fetch_target() {
git rev-parse --verify "refs/remotes/origin/${TARGET_BRANCH}^{commit}" >/dev/null \
|| { echo "[verdict] REMOTE_UNVERIFIED — target commit missing" >&2; return 6; }
}
target_history() { # $1=可选基线(无缓存目标时代替比较,如任务 R0)→ 输出 ok(远端不可查询/目标 ref 缺失/无缓存目标/通告提交为缓存后代)、rewound(回退或分叉)或 uncomparable(通告提交本地缺失或无法比较)
local cached advertised rc=0
target_history() { # $1=可选基线(无缓存目标时代替比较,如任务 R0)→ 输出 ok(远端不可查询/通告提交为基线后代)、rewound(回退或分叉)或 uncomparable(远端可查询但目标 ref 缺失、无基线、通告提交本地缺失或无法比较)
local cached listing advertised rc=0
cached=$(git rev-parse -q --verify "refs/remotes/origin/${TARGET_BRANCH}^{commit}" 2>/dev/null) || cached=${1:-}
[ -n "$cached" ] || { echo ok; return 0; }
advertised=$(git ls-remote origin "refs/heads/${TARGET_BRANCH}" 2>/dev/null \
| awk -v ref="refs/heads/${TARGET_BRANCH}" '$2 == ref && !seen { print $1; seen = 1 }') || { echo ok; return 0; }
[ -n "$advertised" ] || { echo ok; return 0; }
listing=$(git ls-remote origin "refs/heads/${TARGET_BRANCH}" 2>/dev/null) || { echo ok; return 0; }
advertised=$(printf '%s\n' "$listing" \
| awk -v ref="refs/heads/${TARGET_BRANCH}" '$2 == ref && !seen { print $1; seen = 1 }')
[ -n "$advertised" ] && [ -n "$cached" ] || { echo uncomparable; return 0; }
git cat-file -e "${advertised}^{commit}" 2>/dev/null || { echo uncomparable; return 0; }
git merge-base --is-ancestor "$cached" "$advertised" 2>/dev/null || rc=$?
case "$rc" in 0) echo ok ;; 1) echo rewound ;; *) echo uncomparable ;; esac
@@ -153,12 +153,13 @@ cmd_precheck() {
if [ "$mode" = local ]; then
python3 "${SCRIPT_DIR}/evidence.py" --local-context --active || return 2
if [ "$remote_fresh" -eq 0 ]; then
case "$(target_history)" in
# 无缓存目标时只以活动任务卡登记的 R0 作比较基线,不把它当作远端最新值。
case "$(target_history "$(card_r0 "$(branch_card "$branch")")")" in
rewound)
echo "[verdict] REMOTE_UNVERIFIED — origin/${TARGET_BRANCH} rewound or diverged from the cached target; preserve local work and reconcile the target history"
echo "[verdict] REMOTE_UNVERIFIED — origin/${TARGET_BRANCH} rewound or diverged from the known target; preserve local work and reconcile the target history"
return 6 ;;
uncomparable)
echo "[verdict] REMOTE_UNVERIFIED — advertised origin/${TARGET_BRANCH} commit is missing locally and cannot be compared with the cached target; preserve local work and retry the refresh"
echo "[verdict] REMOTE_UNVERIFIED — origin/${TARGET_BRANCH} is missing or its advertised commit cannot be compared with the known target; preserve local work and retry the refresh"
return 6 ;;
esac
fi
@@ -498,7 +499,7 @@ cmd_resume() {
remote_fresh=0
local r0 ls_rc=0
[ -n "$card" ] || die "no registered task card for ${branch}; receipt not imported"
r0=$(sed -n 's/^- 权威仓:.*;R0(initial_base_sha)= \([0-9a-f]\+\)[[:space:]]*$/\1/p' "$card" | head -1)
r0=$(card_r0 "$card")
[ -n "$r0" ] || die "task card has no initial baseline; receipt not imported"
git ls-remote --exit-code --heads origin "refs/heads/${TARGET_BRANCH}" >/dev/null 2>&1 || ls_rc=$?
if [ "$ls_rc" -eq 2 ]; then
@@ -604,6 +605,7 @@ card_status() { sed -n 's/^.*;状态:\([^;]*\).*/\1/p' "$1" | head -1; }
# 两级分支元数据行:'- 分支类型:<kind>;initiative_id:…;root_target:…;immediate_target:…;accepting_requirements:…'。
# 旧卡没有该行:按 standalone、root/immediate 均为目标分支、不接收新需求处理。
card_field() { sed -n "s/^- 分支类型:.*;$2:\([^;]*\).*/\1/p" "$1" 2>/dev/null | head -1; }
card_r0() { sed -n 's/^- 权威仓:.*;R0(initial_base_sha)= \([0-9a-f]\+\)[[:space:]]*$/\1/p' "$1" 2>/dev/null | head -1; }
card_branch_kind() { local v; v=$(sed -n 's/^- 分支类型:\([^;]*\).*/\1/p' "$1" 2>/dev/null | head -1); printf '%s\n' "${v:-standalone}"; }
card_initiative_id() { card_field "$1" initiative_id; }
card_root_target() { local v; v=$(card_field "$1" root_target); printf '%s\n' "${v:-${TARGET_BRANCH}}"; }