Skip to content

fix(bin): keep inherited Git config entries when installing the trailer-strip hooks path - #6341

Merged
kunchenguid merged 10 commits into
kunchenguid:mainfrom
andrewli8:fm/fm-upstream-contrib
Oct 14, 2026
Merged

kunchenguid merged 10 commits into
kunchenguid:mainfrom
andrewli8:fm/fm-upstream-contrib

Conversation

@andrewli8

@andrewli8 andrewli8 commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

What Changed

  • The launch command in bin/fm-spawn.sh no longer overwrites the pane's GIT_CONFIG_COUNT/KEY_0/VALUE_0 with a single core.hooksPath entry. It now runs a new fm-git-strip-ai-trailers.sh env-file <hooks-dir> <out-file> subcommand inside the pane and sources the result. That subcommand writes one plain export line into the private launch directory, adding the canonicalized core.hooksPath entry after whatever GIT_CONFIG_* entries the worker inherited. Inherited settings such as a scoped credential.helper therefore still apply, and the pane shell (fish included) only has to parse a simple command, &&, ||, and the export list. The LAUNCH_DIR derivation moved earlier in the script so the env file can be placed there.
  • If the inherited GIT_CONFIG_COUNT is not a decimal number, or is too large to add another entry within Git's signed int, env-file exits with an error and the launch stops before the worker starts.
  • The generated hook wrappers no longer unset all GIT_CONFIG_*. They remove only the entries whose core.hooksPath names their own hooks directory, shift the remaining entries down, and then chain to the repository's own hook, so hooks like a git-lfs pre-push still see inherited config. docs/configuration.md describes this behavior and the count refusal. Spawn, Claude-trust, and Kimi test suites now share a launch-command parser in tests/lib.sh that understands the new prefix, and new tests cover env-file output, entry preservation in the wrappers, and refused counts.

🤖 Generated with Claude Code

Risk Assessment

⚠️ Medium: The change rewrites the launch prefix for every worker spawn and the body of every chained Git hook wrapper; traced paths look correct. Those paths are: inherited GIT_CONFIG_* entries kept after env -i filtering, the wrapper dropping only its own canonical hooksPath entries, a bad or overflowing count refused before the worker starts, and env-file output that fish can parse. Prior rounds settled the design, but the change sits on a hot launch path.

Testing

Built throwaway lab homes (bin/fm-lab-home.sh create, the committed tree checked out, a private tmux socket, TREEHOUSE_ROOT inside the lab, a local bare origin). Real fm-spawn.sh launched a raw-command probe worker into a real treehouse worktree. Ran it with a zsh pane at the target, with a zsh pane at the base commit (the bug reproduced), and with a fish 4.9.3 pane at the target; all target runs passed. The invalid and overflow count guard was exercised by sourcing a line in the same shape as the emitted launch prefix inside the live spawned zsh and fish worker panes. Setting a bad count for the whole pane makes git itself fail before treehouse get, so fm-spawn never reaches its own guard in that setup, and the worker never starts either way. Ran tests/fm-spawn-dispatch-profile.test.sh with fish on PATH; its fish-inclusive Git-config case passed. Ran tests/fm-git-strip-ai-trailers.test.sh: its two new regressions passed. Two earlier tests in that suite (unresolvable and valueless core.hooksPath) fail the same way at base 8c9c67de with the local git 2.46.2, so they predate this change. The suite stops at the first failure, so the new regressions ran with those two excluded. All labs, /tmp/fm-<id> dirs and the downloaded fish were removed. No UI surface is involved.

  • Live validation: ✅ go - 5 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Spawned worker in a pane that inherits scoped credential.helper GIT_CONFIG entries keeps both entries, gets core.hooksPath appended as entry 2, and its commit has the AI trailer stripped (zsh pane) ✅ pass live target-zsh-inherited-credentials.txt
Repository's own pre-push hook, run through the strip wrapper on git push, resolves the inherited scoped credential helper (git-lfs-style git credential fill returns the scoped token, not osxkeychai… ✅ pass live target-zsh-inherited-credentials.txt (push section)
The same lab at base 8c9c67d reproduces the original bug: inherited helpers replaced, COUNT=1, credential fill falls back to osxkeychain and fails ✅ pass live base-zsh-inherited-credentials-dropped.txt
Fish pane shell sources the staged launch, the worker starts, and inherited credentials and the appended hooksPath are kept ✅ pass live target-fish-inherited-credentials.txt
Invalid (bad) or overflowing (2147483647) inherited GIT_CONFIG_COUNT: the guard was exercised by sourcing a line in the emitted launch-prefix shape in the live spawned zsh and fish worker panes. Each… ✅ pass live target-zsh-pane-count-refusal.txt, target-fish-inherited-credentials.txt (refusal section), target-zsh-count-bad-refused.txt, target-zsh-count-overflow-refused.txt
Automated regressions: dispatch-profile fish-inclusive launch case, repository hook keeps inherited GIT_CONFIG, env-file canonicalizes the hooks dir ⏸️ untested no The prior payload recorded only an automated test-suite run (tests/fm-spawn-dispatch-profile.test.sh, tests/fm-git-strip-ai-trailers.test.sh) for this scenario, with live=false, so it did not establis…
Evidence: Target zsh pane: inherited credentials kept, hooksPath appended, trailer stripped, pre-push credential fill uses the scoped helper

Source: Target zsh pane: inherited credentials kept, hooksPath appended, trailer stripped, pre-push credential fill uses the scoped helper

# target 633c3adf: real fm-spawn.sh, tmux lab socket, zsh pane, inherited GIT_CONFIG_COUNT=2 (credential.helper='' + scoped helper)
## spawn.log
spawned gc4987428518 harness=sh kind=ship mode=local-only yolo=on window=firstmate:fm-gc4987428518 worktree=/private/tmp/fmgc.FkV989/treehouse/.treehouse/notes-9588ba/1/notes
## probe output (worker process inside the spawned pane)
WORKER-RAN
GIT_CONFIG_COUNT=3
  0: credential.helper=
  1: credential.helper=!f() { echo username=scoped-bot; echo password=scoped-token-from-inherited-helper; }; f
  2: core.hooksPath=/private/tmp/fmgc.FkV989/home/state/gc4987428518.git-hooks
credential.helper list:
  [osxkeychain]
  []
  [!f() { echo username=scoped-bot; echo password=scoped-token-from-inherited-helper; }; f]
core.hooksPath=/private/tmp/fmgc.FkV989/home/state/gc4987428518.git-hooks
commit message after strip hook:
  | probe commit
  | 
push:
  repo pre-push hook ran (lfs-style credential fill):
    protocol=https
    host=lfs.example.com
    username=scoped-bot
    password=scoped-token-from-inherited-helper
PROBE-DONE
## env-file the pane wrote
export GIT_CONFIG_KEY_2=core.hooksPath GIT_CONFIG_VALUE_2='/private/tmp/fmgc.FkV989/home/state/gc4987428518.git-hooks' GIT_CONFIG_COUNT=3
Evidence: Base 8c9c67d: inherited credential helpers dropped (regression reproduced)

Source: Base 8c9c67de: inherited credential helpers dropped (regression reproduced)

# BASE 8c9c67de (before fix): same lab, same inherited GIT_CONFIG_COUNT=2
spawned gc4992225527 harness=sh kind=ship mode=local-only yolo=on window=firstmate:fm-gc4992225527 worktree=/private/tmp/fmgc.XruQge/treehouse/.treehouse/notes-ab51f3/1/notes
## probe output
WORKER-RAN
GIT_CONFIG_COUNT=1
  0: core.hooksPath=/private/tmp/fmgc.XruQge/home/state/gc4992225527.git-hooks
credential.helper list:
  [osxkeychain]
core.hooksPath=/private/tmp/fmgc.XruQge/home/state/gc4992225527.git-hooks
commit message after strip hook:
  | probe commit
  | 
push:
  repo pre-push hook ran (lfs-style credential fill):
    fatal: could not read Username for 'https://lfs.example.com': terminal prompts disabled
PROBE-DONE
Evidence: Target fish pane: spawn and credential preservation, plus live refusal of a bad or overflowing count

Source: Target fish pane: spawn and credential preservation, plus live refusal of a bad or overflowing count

# target 633c3adf: real fm-spawn.sh, tmux lab socket, FISH 4.9.3 pane shell (workspace-local, from the official .pkg payload), inherited GIT_CONFIG_COUNT=2
spawned gc5027916355 harness=sh kind=ship mode=local-only yolo=on window=firstmate:fm-gc5027916355 worktree=/private/tmp/fmgc.X1Ta6S/treehouse/.treehouse/notes-5e5991/1/notes
## probe output
WORKER-RAN
GIT_CONFIG_COUNT=3
  0: credential.helper=
  1: credential.helper=!f() { echo username=scoped-bot; echo password=scoped-token-from-inherited-helper; }; f
  2: core.hooksPath=/private/tmp/fmgc.X1Ta6S/home/state/gc5027916355.git-hooks
credential.helper list:
  [osxkeychain]
  []
  [!f() { echo username=scoped-bot; echo password=scoped-token-from-inherited-helper; }; f]
core.hooksPath=/private/tmp/fmgc.X1Ta6S/home/state/gc5027916355.git-hooks
commit message after strip hook:
  | probe commit
  | 
push:
  repo pre-push hook ran (lfs-style credential fill):
    protocol=https
    host=lfs.example.com
    username=scoped-bot
    password=scoped-token-from-inherited-helper
PROBE-DONE

## fish refusal in the live pane
count=bad probe: no probe output: worker never ran
count=2147483647 probe: no probe output: worker never ran
andrew@MacBook-Air /p/t/f/t/.t/n/1/notes ((a27f8847))> set -gx GIT_CONFIG_COUNT bad; source /private/tmp/fmgc.X1Ta6S/relaunch-bad.sh; echo source-status=$status; echo SHELL-STILL-ALIVE; set -gx GIT_CONFIG_COUNT 2
error: invalid inherited GIT_CONFIG_COUNT
source-status=1
SHELL-STILL-ALIVE
andrew@MacBook-Air /p/t/f/t/.t/n/1/notes ((a27f8847))> set -gx GIT_CONFIG_COUNT 2147483647; source /private/tmp/fmgc.X1Ta6S/relaunch-2147483647.sh; echo source-status=$status; echo SHELL-STILL-ALIVE; set -gx GIT_CONFIG_COUNT 2
error: inherited GIT_CONFIG_COUNT cannot be extended
source-status=1
SHELL-STILL-ALIVE
pane_dead=0 cmd=fish
Evidence: Target zsh pane: refusal of a bad or overflowing count, pane survives, worker never runs

Source: Target zsh pane: refusal of a bad or overflowing count, pane survives, worker never runs

# target 633c3adf: invalid/overflow inherited GIT_CONFIG_COUNT sourced through the launch-prefix shape in the live spawned zsh worker pane
# (setting a bad count tmux-wide breaks git itself, so treehouse get fails before the launch; see target-zsh-count-*-refused.txt)
--- count=bad: launch file
/private/tmp/fmgc.Rit5KL/home/bin/fm-git-strip-ai-trailers.sh env-file /private/tmp/fmgc.Rit5KL/home/state/gc5019628611.git-hooks /private/tmp/fmgc.Rit5KL/env-bad.sh && . /private/tmp/fmgc.Rit5KL/env-bad.sh || return 1 2>/dev/null || exit 1; /bin/sh /private/tmp/fmgc.Rit5KL/probe.sh
--- probe ran?
(no probe output: worker never ran)
--- env-file exists?
ls: /private/tmp/fmgc.Rit5KL/env-bad.sh: No such file or directory
--- count=2147483647: launch file
/private/tmp/fmgc.Rit5KL/home/bin/fm-git-strip-ai-trailers.sh env-file /private/tmp/fmgc.Rit5KL/home/state/gc5019628611.git-hooks /private/tmp/fmgc.Rit5KL/env-2147483647.sh && . /private/tmp/fmgc.Rit5KL/env-2147483647.sh || return 1 2>/dev/null || exit 1; /bin/sh /private/tmp/fmgc.Rit5KL/probe.sh
--- probe ran?
(no probe output: worker never ran)
--- env-file exists?
ls: /private/tmp/fmgc.Rit5KL/env-2147483647.sh: No such file or directory
source-status=1
SHELL-STILL-ALIVE
/private/tmp/fmgc.Rit5KL/treehouse/.treehouse/notes-17f1bd/1/notes @2a851e78 ❯ export GIT_CONFIG_COUNT=2147483647; . /private/tmp/fmgc.Rit5KL/relaunch-2147483647.sh; echo source-status=$?; echo SHELL-
STILL-ALIVE; export GIT_CONFIG_COUNT=2
error: inherited GIT_CONFIG_COUNT cannot be extended
source-status=1
SHELL-STILL-ALIVE
/private/tmp/fmgc.Rit5KL/treehouse/.treehouse/notes-17f1bd/1/notes @2a851e78 ❯                                                                                                              11:56:54 PM
pane_dead=0 cmd=zsh
== pane lines ==
/private/tmp/fmgc.Rit5KL/treehouse/.treehouse/notes-17f1bd/1/notes @2a851e78 ❯ export GIT_CONFIG_COUNT=bad; . /private/tmp/fmgc.Rit5KL/relaunch-bad.sh; echo source-status=$?; echo SHELL-STILL-ALIVE; export GIT_CONFIG_COUNT=2
error: invalid inherited GIT_CONFIG_COUNT
source-status=1
SHELL-STILL-ALIVE
/private/tmp/fmgc.Rit5KL/treehouse/.treehouse/notes-17f1bd/1/notes @2a851e78 ❯ export GIT_CONFIG_COUNT=2147483647; . /private/tmp/fmgc.Rit5KL/relaunch-2147483647.sh; echo source-status=$?; echo SHELL-
STILL-ALIVE; export GIT_CONFIG_COUNT=2
error: inherited GIT_CONFIG_COUNT cannot be extended
source-status=1
SHELL-STILL-ALIVE
Evidence: Lab-wide bad count: git fails before launch, worker never runs

Source: Lab-wide bad count: git fails before launch, worker never runs

root=/private/tmp/fmgc.aEWCfp id=gc4995129814 ref=HEAD mode=bad shell=/bin/zsh
spawn exit=1
error: treehouse get did not enter an isolated worktree within 60s (last seen '/private/tmp/fmgc.aEWCfp/home/projects/notes': it is the spawning project itself; spawning project '/private/tmp/fmgc.aEWCfp/home/projects/notes'); inspect window firstmate:fm-gc4995129814
===== probe output (target-bad) =====
(no probe output: worker never ran)
===== worker pane (target-bad) =====
@0 lab
@1 fm-gc4995129814
treehouse get
/private/tmp/fmgc.aEWCfp/home/projects/notes main ❯ treehouse get                                                                                                                           11:52:43 PM
A new version of treehouse is available: v2.3.0 → v3.1.3
Run "treehouse update" to update
not in a git or jj repository: git rev-parse --show-toplevel: error: bogus count in GIT_CONFIG_COUNT
fatal: unable to parse command-line config
/private/tmp/fmgc.aEWCfp/home/projects/notes main ❯                                                                                                                                         11:52:44 PM
== full pane after wait ==
== pane process ==
Evidence: Lab-wide overflow count: git fails before launch, worker never runs

Source: Lab-wide overflow count: git fails before launch, worker never runs

root=/private/tmp/fmgc.nz4ogk id=gc5006317934 ref=HEAD mode=overflow shell=/bin/zsh
spawn exit=1
error: treehouse get did not enter an isolated worktree within 60s (last seen '/private/tmp/fmgc.nz4ogk/home/projects/notes': it is the spawning project itself; spawning project '/private/tmp/fmgc.nz4ogk/home/projects/notes'); inspect window firstmate:fm-gc5006317934
===== probe output (target-overflow) =====
(no probe output: worker never ran)
===== worker pane (target-overflow) =====
@0 lab
@1 fm-gc5006317934
treehouse get
/private/tmp/fmgc.nz4ogk/home/projects/notes main ❯ treehouse get                                                                                                                           11:54:29 PM
A new version of treehouse is available: v2.3.0 → v3.1.3
Run "treehouse update" to update
not in a git or jj repository: git rev-parse --show-toplevel: error: missing config key GIT_CONFIG_KEY_2
fatal: unable to parse command-line config
/private/tmp/fmgc.nz4ogk/home/projects/notes main ❯                                                                                                                                         11:54:29 PM
== full pane after wait ==
== pane process ==
Evidence: Lab driver script used for all runs

Source: Lab driver script used for all runs

#!/usr/bin/env bash
# lab.sh <ref> <label> <count-mode: good|bad|overflow> [shell]
set -u
SRC=~/.no-mistakes/worktrees/12f15a3b55da/01M4W89X8GV39D047914YF2JZ8
REF=$1 LABEL=$2 MODE=$3 PSHELL=${4:-/bin/zsh}
ROOT=$(mktemp -d /tmp/fmgc.XXXXXX); ROOT=$(cd "$ROOT" && pwd -P)
LAB=$ROOT/home; ID="gc$(date +%s | tail -c 6)$RANDOM"
echo "root=$ROOT id=$ID ref=$REF mode=$MODE shell=$PSHELL"
"$SRC/bin/fm-lab-home.sh" create "$LAB" >/dev/null || exit 1
git -C "$LAB" init -q -b main; git -C "$LAB" fetch -q "$SRC" "$REF"; git -C "$LAB" checkout -q -f -B main FETCH_HEAD
git -C "$LAB" config user.name lab; git -C "$LAB" config user.email [email protected]
mkdir -p "$LAB/state" "$LAB/data" "$LAB/config" "$LAB/projects" "$ROOT/treehouse"
printf 'tmux\n' > "$LAB/config/backend"; printf 'codex\n' > "$LAB/config/crew-harness"
TMUX_DIR=$("$LAB/bin/fm-lab-home.sh" tmux-dir "$LAB")
# project
seed=$ROOT/seed; mkdir -p "$seed"; git init -q -b main "$seed"; echo hi > "$seed/README.md"
git -C "$seed" add -A; git -C "$seed" -c user.name=lab -c [email protected] commit -q -m seed
git clone -q --bare "$seed" "$ROOT/notes.git"; git clone -q --bare "$seed" "$ROOT/probe-remote.git"
git clone -q "$ROOT/notes.git" "$LAB/projects/notes"
printf '# Projects\n\n- notes [local-only +yolo] - lab notes\n' > "$LAB/data/projects.md"
OUT=$ROOT/probe.out
cat > "$ROOT/probe.sh" <<P
#!/bin/sh
exec >"$OUT" 2>&1
echo WORKER-RAN
echo "GIT_CONFIG_COUNT=\$GIT_CONFIG_COUNT"
i=0; while [ "\$i" -lt "\${GIT_CONFIG_COUNT:-0}" ]; do eval "echo \"  \$i: \\\$GIT_CONFIG_KEY_\$i=\\\$GIT_CONFIG_VALUE_\$i\""; i=\$((i+1)); done
echo "credential.helper list:"; git config --get-all credential.helper | sed 's/^/  [/; s/\$/]/'
echo "core.hooksPath=\$(git config --get core.hooksPath)"
hooks=\$(git rev-parse --path-format=absolute --git-common-dir)/hooks; mkdir -p "\$hooks"
cat > "\$hooks/pre-push" <<'H'
#!/bin/sh
echo "repo pre-push hook ran (lfs-style credential fill):"
printf 'protocol=https\nhost=lfs.example.com\n\n' | GIT_TERMINAL_PROMPT=0 git credential fill 2>&1 | sed 's/^/  /'
H
chmod +x "\$hooks/pre-push"
echo x >> README.md; git add README.md
git -c user.name=w -c [email protected] commit -q -m "probe commit

Co-Authored-By: Claude <[email protected]>"
echo "commit message after strip hook:"; git log -1 --format=%B | sed 's/^/  | /'
echo "push:"; git push -q "$ROOT/probe-remote.git" HEAD:refs/heads/probe 2>&1 | sed 's/^/  /'
echo PROBE-DONE
P
chmod +x "$ROOT/probe.sh"
HELPER='!f() { echo username=scoped-bot; echo password=scoped-token-from-inherited-helper; }; f'
case $MODE in good) CNT=2 ;; bad) CNT=bad ;; overflow) CNT=2147483647 ;; esac
base=(HOME=$HOME USER=$USER LOGNAME=$USER PATH=$PATH SHELL=$PSHELL TERM=xterm-256color LANG=en_US.UTF-8
  TMUX_TMPDIR=$TMUX_DIR TREEHOUSE_ROOT=$ROOT/treehouse FM_BACKEND=tmux DISABLE_AUTOUPDATER=1
  GIT_CONFIG_COUNT=$CNT GIT_CONFIG_KEY_0=credential.helper GIT_CONFIG_VALUE_0=
  GIT_CONFIG_KEY_1=credential.helper "GIT_CONFIG_VALUE_1=$HELPER")
env -i "${base[@]}" tmux -f /dev/null new-session -d -s firstmate -n lab -x 200 -y 50 -c "$ROOT" || exit 1
echo "$ROOT" > /tmp/fmgc-scripts/last-root
(cd "$LAB" && env -i "${base[@]}" FM_HOME="$LAB" "$LAB/bin/fm-brief.sh" "$ID" notes --mode local-only >/dev/null)
python3 - "$LAB/data/$ID/brief.md" <<'PY'
import sys; p=sys.argv[1]; t=open(p).read()
t=t.replace("{TASK}","Lab probe of inherited git config.",1).replace("{FIRSTMATE_SPEC}","Run the probe.",1); open(p,"w").write(t)
PY
(cd "$LAB" && env -i "${base[@]}" FM_HOME="$LAB" "$LAB/bin/fm-tasks-axi.sh" add "$ID" "lab probe" --kind ship --repo notes >/dev/null)
# spawn from inside the lab tmux (so TMUX names the lab socket); the spawner's own env has no GIT_CONFIG override
(cd "$LAB" && env -i "${base[@]:0:11}" TMUX="$(env -i "${base[@]}" tmux display -p '#{socket_path},1,0')" FM_HOME="$LAB" \
  timeout 240 "$LAB/bin/fm-spawn.sh" "$ID" "$LAB/projects/notes" --mode local-only --yolo on --harness "/bin/sh $ROOT/probe.sh") > "$ROOT/spawn.log" 2>&1
echo "spawn exit=$?"; tail -5 "$ROOT/spawn.log"
for i in $(seq 1 30); do grep -q PROBE-DONE "$OUT" 2>/dev/null && break; sleep 1; done
echo "===== probe output ($LABEL) ====="; cat "$OUT" 2>/dev/null || echo "(no probe output: worker never ran)"
echo "===== worker pane ($LABEL) ====="
env -i "${base[@]}" tmux list-windows -a -F '#{window_id} #{window_name}' 
w=$(env -i "${base[@]}" tmux list-windows -a -F '#{window_id} #{window_name}' | awk -v id="$ID" '$2 ~ id {print $1}' | head -1)
[ -n "$w" ] && env -i "${base[@]}" tmux capture-pane -p -J -t "$w" -S -40 | sed '/^$/d' | tail -25
Evidence: Target worker probe (zsh and fish identical)
GIT_CONFIG_COUNT=3
0: credential.helper=
1: credential.helper=!f() { echo username=scoped-bot; echo password=scoped-token-from-inherited-helper; }; f
2: core.hooksPath=.../home/state/<id>.git-hooks
commit message after strip hook:
| probe commit
push:
repo pre-push hook ran (lfs-style credential fill):
username=scoped-bot
password=scoped-token-from-inherited-helper
Evidence: Base worker probe (before fix)
GIT_CONFIG_COUNT=1
0: core.hooksPath=.../home/state/<id>.git-hooks
credential.helper list:
[osxkeychain]
push:
repo pre-push hook ran (lfs-style credential fill):
fatal: could not read Username for 'https://lfs.example.com': terminal prompts disabled
- Outcome: ⚠️ 1 info across 1 run (22m53s)

Pipeline

Updates from git push no-mistakes

⏭️ **intent** - skipped

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - medium risk

✅ No issues found.

⚠️ **Test** - 1 info
  • ℹ️ tests/fm-git-strip-ai-trailers.test.sh:454 - test_unresolvable_project_hookspath_still_refuses and test_valueless_project_hookspath_still_refuses fail locally with git 2.46.2, and fail the same way at base 8c9c67d, so this change did not cause them. Because the suite stops at the first failure, the new regressions only ran locally with those two excluded. CI's git version decides whether they pass there.
  • Live validation: ✅ go - 5 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Spawned worker in a pane that inherits scoped credential.helper GIT_CONFIG entries keeps both entries, gets core.hooksPath appended as entry 2, and its commit has the AI trailer stripped (zsh pane) ✅ pass live target-zsh-inherited-credentials.txt
Repository's own pre-push hook, run through the strip wrapper on git push, resolves the inherited scoped credential helper (git-lfs-style git credential fill returns the scoped token, not osxkeychai… ✅ pass live target-zsh-inherited-credentials.txt (push section)
The same lab at base 8c9c67d reproduces the original bug: inherited helpers replaced, COUNT=1, credential fill falls back to osxkeychain and fails ✅ pass live base-zsh-inherited-credentials-dropped.txt
Fish pane shell sources the staged launch, the worker starts, and inherited credentials and the appended hooksPath are kept ✅ pass live target-fish-inherited-credentials.txt
Invalid (bad) or overflowing (2147483647) inherited GIT_CONFIG_COUNT: the guard was exercised by sourcing a line in the emitted launch-prefix shape in the live spawned zsh and fish worker panes. Each… ✅ pass live target-zsh-pane-count-refusal.txt, target-fish-inherited-credentials.txt (refusal section), target-zsh-count-bad-refused.txt, target-zsh-count-overflow-refused.txt
Automated regressions: dispatch-profile fish-inclusive launch case, repository hook keeps inherited GIT_CONFIG, env-file canonicalizes the hooks dir ⏸️ untested no The prior payload recorded only an automated test-suite run (tests/fm-spawn-dispatch-profile.test.sh, tests/fm-git-strip-ai-trailers.test.sh) for this scenario, with live=false, so it did not establis…
  • Lab spawn at target 633c3adf: bin/fm-lab-home.sh create + private tmux socket + real fm-spawn.sh &lt;id&gt; projects/notes --mode local-only --yolo on --harness &#39;/bin/sh probe.sh&#39; with tmux server env GIT_CONFIG_COUNT=2 (credential.helper='' + scoped helper), zsh pane
  • Same lab at base 8c9c67de for comparison (bug reproduced)
  • Same lab at target with fish 4.9.3 as the pane shell. fish came from the official release .pkg payload (pkgutil --expand-full), ran from a temp dir only, and was deleted afterwards. No system install.
  • Probe in the worker: dumped GIT_CONFIG_*, git config --get-all credential.helper, committed a message with a Co-Authored-By trailer, then git push to a local bare remote with a repo pre-push hook running git credential fill
  • Live refusal: in the spawned zsh and fish worker panes, set GIT_CONFIG_COUNT=bad and 2147483647, sourced a fm-git-strip-ai-trailers.sh env-file ... &amp;&amp; . &lt;file&gt; || return 1 2&gt;/dev/null || exit 1; /bin/sh probe.sh line, and checked the error, source status 1, that the shell is still alive, and that the probe never ran
  • Lab-wide GIT_CONFIG_COUNT=bad and 2147483647 spawns: git fails in treehouse get before the launch and the worker never runs
  • PATH=&lt;temp fish&gt;:$PATH bash tests/fm-spawn-dispatch-profile.test.sh (test_launch_preserves_inherited_git_config, fish included)
  • bash tests/fm-git-strip-ai-trailers.test.sh (new regressions run with the two git-2.46-incompatible earlier tests excluded; both of those also fail at base)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[High risk] Changes how Git configuration is passed to spawned processes.

The PR appears safe to merge, though the fish refusal test remains an unreliable regression check.

Reviews (6) · Last reviewed commit: "no-mistakes(document): Document GIT_CONF..."

Comment thread tests/fm-spawn-dispatch-profile.test.sh Resolved
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

Verdict: Tip vs main 6af83310535b3d48b1d35bcc1597a0b7b98902d7. No closing issue. Tip vs main: fm-spawn no longer overwrites inherited GIT_CONFIG_* with GIT_CONFIG_COUNT=1 hooksPath; appends via fm-git-strip-ai-trailers.sh env-file and keeps inherited helpers in hook wrappers — concrete broken path for scoped credential.helper (also called out from #6339).

contract-class: restore

VISION.md (each rule)

  • One captain, one interface: aligns.
  • Authority is explicit and never inferred: aligns — scoped credentials survive launch.
  • Scripts own the mechanics, agents own the judgment: aligns.
  • A restart is a non-event: aligns.
  • Delegation with a spine: aligns — worker env contract kept.
  • The fleet outlives any vendor: aligns.
  • Scope: aligns — spawn/hooks only.

Greptile: FAILURE with non-blocking P2 (fish launch verification gap) — not a merge blocker once CI green; no P1.
Attestation: MATCH. CI/NM: approved this pass (36928570948 CI, 36928571046 Require no-mistakes) — queued. Firstmate flag: no. Security tip: none (strengthens scoped helpers).

Comment on lines +523 to +528
result=$(isolated_pane_env GIT_CONFIG_COUNT="$count" fish -i -c \
"source '$launch_file'; and exit 2; printf '\nSHELL-STILL-ALIVE\n'" 2>&1)
status=$?
expect_code 0 "$status" "invalid count must preserve the interactive fish pane"
assert_contains "$result" 'error: ' "count refusal must remain visible in fish"
assert_contains "$result" SHELL-STILL-ALIVE "count refusal killed the interactive fish pane"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Refusal test can miss launch

The fish invalid-count check can pass even if the worker starts. The env-file helper supplies the expected error: text, and the worker probe’s final git config command can fail under the invalid count. That leaves source with a nonzero status, skips and exit 2, and satisfies the remaining assertions. The test therefore does not reliably catch a worker starting after a refused launch; it needs to check that the worker command was not reached.

@andrewli8
andrewli8 force-pushed the fm/fm-upstream-contrib branch from 7097fd2 to 2349ac4 Compare October 2, 2026 02:47
@andrewli8 andrewli8 changed the title fix(bin): keep inherited Git config when installing the trailer hooks path fix(bin): keep inherited Git config when adding the AI-trailer hooks path Oct 2, 2026
andrewli8 and others added 10 commits October 13, 2026 23:46
…railer hooks path

Problem:
Every fleet launch prefixed the worker command with `export GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=core.hooksPath GIT_CONFIG_VALUE_0=...`.
That replaced any `GIT_CONFIG_*` entries the pane already carried, so a scoped HTTPS credential setup such as `credential.helper=` followed by `credential.helper=!gh auth git-credential` was silently dropped.
Git then fell back to the system or global helper (for example `osxkeychain` from the system gitconfig on macOS), so a worker meant to use a scoped token pushed with the user's personal credentials.

Reproduction on main:
GIT_CONFIG_COUNT=2 GIT_CONFIG_KEY_0=credential.helper GIT_CONFIG_VALUE_0= GIT_CONFIG_KEY_1=credential.helper GIT_CONFIG_VALUE_1='!gh auth git-credential' sh -c "<emitted launch>; git config --get-all credential.helper" prints none of the inherited entries, only the system helper (`osxkeychain` from Homebrew's system gitconfig on the reporting machine).

Fix:
The launch prefix now appends `core.hooksPath` at index `GIT_CONFIG_COUNT` and increments the count, resolved in the destination shell after any `config/launch-env-allowlist` filtering.
The inherited count is validated as decimal before shell arithmetic, leading zeros are normalized (Git accepts `02`), and a count that cannot be extended within Git's signed int refuses.
A refusal uses `return 1 2>/dev/null || exit 1`, so when the pane sources the launch file the error stays visible and the interactive shell survives instead of the pane dying with the message.

Tests:
`tests/fm-spawn-dispatch-profile.test.sh` gains a behavior test that runs the real emitted launch under sh, bash, and zsh with inherited credential-helper entries and counts `2` and `02`, then asks Git for `credential.helper` and `core.hooksPath`.
The same test checks that an invalid or overflowing count refuses, and that sourcing the launch file from an interactive shell keeps that shell alive with the error visible.
The exact-launch assertions in the dispatch-profile and Kimi suites now extract the emitted prefix through one `fm_test_launch_git_prefix` helper in `tests/lib.sh` instead of two hand-copied strings, whose content the behavior test covers.

Risk:
Top-level `return` outside a sourced file is unspecified by POSIX; verified on macOS sh (bash 3.2 in POSIX mode), bash, and zsh, and every path still ends nonzero before the worker command runs.
The hook wrapper still unsets only `GIT_CONFIG_COUNT` and index 0, which is sufficient because Git ignores indexed entries once the count is unset.
A launch that forwards `GIT_CONFIG_COUNT` without all of its indexed keys now fails in Git instead of being masked by the overwrite.
Install fish in the portable serial lane and run the credential-append
and invalid-count refusal cases under fish. Under CI the spawn test
fails instead of falling back to the static syntax check.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…orbell

The trust suite evaluated the whole launch command to find the final prompt
argument, so it now also sourced the per-spawn git-config env file that the
fake pane never writes. Drop that prefix the same way the dispatch suite does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The trust suite failed in CI because its copy of the launch parser missed
the Git configuration prefix the dispatch suite's copies already stripped.
Move the prefix and export stripping into tests/lib.sh next to
fm_test_launch_git_prefix so the three parsers cannot drift again.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tests

env-file now writes the canonical (pwd -P) spelling of the hooks directory, matching what install records, so a symlinked path no longer makes the hook wrapper miss its own entry and silently skip the repository's hook.
A new strip test passes a symlinked hooks path through env-file and fails without this change.

The launch-env-allowlist test now also asserts the appended core.hooksPath, so a regression that drops the strip-hook entry only on the env -i path is caught.

Without fish installed locally, the launch test now prints an explicit fish skip line and limits its pass message to sh, bash and zsh, instead of claiming every pane shell after only a static token check.
The invalid-count refusal checks only asserted a nonzero status and the helper's own error text.
If the launch line kept going after the refusal, the worker probe's final `git config` also failed under the bad count, so the checks still passed.
The probe now prints a marker on stderr, and every refusal case in sh, bash, zsh and fish asserts the marker never appears.
Dropping the `|| return 1 2>/dev/null || exit 1` guard from the launch line now fails the test.
andrewli8 added a commit to andrewli8/firstmate that referenced this pull request Oct 14, 2026
Fixes kunchenguid#6339

On the Orca backend, `config/launch-env-allowlist` expands each allowlisted name in the destination pane, and that pane is an Orca terminal whose environment comes from the Orca app and the user's shell startup files.
Allowlisted credentials therefore resolve to the user's personal values or to nothing, with no warning, while the same allowlist scopes tmux workers correctly.

Add an opt-in `config/launch-env-tmux-session` naming one tmux session.
On a fresh Orca spawn, before the worktree or terminal is allocated, fm-spawn reads each allowlisted name from that session's local environment with `tmux -u show-environment -t =<session> <name>`.
The worker launches with the existing `env -i` boundary and operational floor, the snapshotted values in place of destination expansion, and `GIT_CONFIG_NOSYSTEM=1` so a system credential helper cannot answer for the worker.
The source requires an allowlist, so tmux's automatic update-environment names such as `SSH_AUTH_SOCK` are never forwarded unless listed.
A listed name missing from the session, an unreadable session, or a malformed selector refuses before allocation; an explicit `-NAME` record stays a deliberate unset.
Values are shell-quoted only in the existing owner-only staged launch file, never terminal input, and the pane deletes that file as sourcing starts; a deletion failure refuses the worker launch and keeps the interactive shell.
`-u` is required because tmux's non-UTF-8 client output replaces newlines and non-ASCII bytes in values with underscores.

The source is opt-in and nothing changes for homes that do not create the file.
When `config/backend` is orca, the allowlist is nonempty, and no source is configured, fm-spawn now prints a stderr warning that allowlisted names resolve from the Orca terminal, so the mismatch is no longer silent.
It warns rather than refuses because refusing would stop every existing Orca home that uses an allowlist, which the triage asked not to assume.
Other backends, relaunch (already refused on Orca), and secondmate inheritance are unchanged; the selector is not in the inherited configuration list.

The scoped Git credential helper case also needs kunchenguid#6341, which stops fm-spawn's `core.hooksPath` entry from overwriting inherited `GIT_CONFIG_*` entries; this change does not depend on it.

Tests in `tests/fm-spawn-orca-worktree.test.sh`:

- A real-tmux regression on a private socket checks exact multiline UTF-8 values under absent and C locales through sh, Bash, and zsh, refusal of names that exist only server-globally or only inside another value, and exclusion of the automatic `SSH_AUTH_SOCK`.
- Fake-Orca spawns execute the real staged launch file under synthetic personal credentials and cover the configured source, an empty allowlist, refusal before allocation for each invalid setting, file privacy and deletion before the worker runs, and the deletion-failure path.
- The warning appears for a nonempty allowlist without a source and not for an empty allowlist or a configured source.

Risk: the source keeps tmux and the named session as dependencies of Orca spawns, and secret values sit in a 0600 file under a 0700 directory until the pane sources it.
It is not a filesystem sandbox; a worker can still read the user's credential files unless the harness restricts that.
The hardened path was verified with the regressions above, not with a live Orca spawn.
@andrewli8
andrewli8 force-pushed the fm/fm-upstream-contrib branch from 8d119fa to 633c3ad Compare October 14, 2026 04:11
@andrewli8 andrewli8 changed the title fix(bin): keep inherited Git config when adding the AI-trailer hooks path fix(bin): keep inherited Git config entries when installing the trailer-strip hooks path Oct 14, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate:

Verdict: Tip 633c3adf vs main 2911a3bb (GREEN). Tip is 1 behind (#6608 docs/AGENTS/stow only); GitHub mergeable CLEAN. Tip vs main: fm-spawn no longer overwrites inherited GIT_CONFIG_* with GIT_CONFIG_COUNT=1 hooksPath; appends via fm-git-strip-ai-trailers.sh env-file and wrappers keep inherited helpers — restores scoped credential.helper on the existing default spawn path.

contract-class: restore

VISION.md (each rule): One captain / Authority / Scripts / Restart / Delegation / Vendor / Scope — all align.

Attestation: MATCH at tip. Live validation go (5/6). All required checks SUCCESS. Greptile P2 fish notes declined by author for scope (no workflow change) — non-blocking. Security tip: none (strengthens scoped helpers). Merging now.

@kunchenguid
kunchenguid merged commit 0397cb2 into kunchenguid:main Oct 14, 2026
20 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @andrewli8 — really appreciate you taking the time on this.