From a60d35f9f340d64a82f3e602cedccffdc59798c7 Mon Sep 17 00:00:00 2001 From: jazz127 Date: Sat, 31 Oct 2026 09:50:29 +1000 Subject: [PATCH 1/3] fix: scope attribution to commit repository --- bin/fm-git-attribution.py | 33 ++++++++++++--- bin/fm-git-strip-ai-trailers.sh | 22 ++++++++-- bin/fm-spawn.sh | 33 ++++++--------- docs/configuration.md | 13 +++--- tests/fm-git-strip-ai-trailers.test.sh | 54 +++++++++++++++++++++++++ tests/fm-spawn-dispatch-profile.test.sh | 51 +++++++++++++++++------ 6 files changed, 160 insertions(+), 46 deletions(-) diff --git a/bin/fm-git-attribution.py b/bin/fm-git-attribution.py index ae81999df4d..85fddab502b 100755 --- a/bin/fm-git-attribution.py +++ b/bin/fm-git-attribution.py @@ -3,10 +3,11 @@ Usage: fm-git-attribution.py mode fm-git-attribution.py stamp + fm-git-attribution.py apply fm-git-attribution.py strip-fields -docs/configuration.md "Commit attribution" owns launch-repository selection -and its accepted cross-repository limitation. +docs/configuration.md "Commit attribution" owns commit-repository selection +and launch-policy fallback when the commit scope is unavailable. Stamp runs in Git's hook cwd and rechecks origin. Session references come from runtime context or existing task metadata, never a new persistent record. """ @@ -66,17 +67,26 @@ def remove_trailers(content, keys, strip_ai=False): def t27sol(project): + """Return the owner match, or None when origin scope is unavailable.""" result = subprocess.run(["git", "-C", project, "config", "--get", "remote.origin.url"], capture_output=True, text=True, check=False) + if result.returncode != 0 or not result.stdout.strip(): + return None url = result.stdout.strip() if "://" in url: - parsed = urlsplit(url) + try: + parsed = urlsplit(url) + except ValueError: + return None if parsed.scheme not in ("ssh", "https"): return False + if not parsed.hostname: + return None host, path = parsed.hostname or "", parsed.path.lstrip("/") else: match = re.fullmatch(r"(?:[^/@:]+@)?([^/:]+):([^\s]+)", url) if not match: + # A local origin identifies a repository outside the GitHub scope. return False host, path = match.groups() return host.lower() == "github.com" and bool(re.fullmatch( @@ -112,8 +122,19 @@ def session(runtime, lines, task_meta): return "" -def stamp(task_meta, runtime, model, message): - if not t27sol("."): +def apply(fallback, outside, task_meta, runtime, model, message): + scope = t27sol(".") + selected = fallback if scope is None else "add" if scope else outside + if selected == "add": + stamp(task_meta, runtime, model, message, scoped=True) + elif selected == "strip": + subprocess.run([str(Path(__file__).with_name("fm-git-strip-ai-trailers.sh")), message], check=True) + elif selected != "keep": + raise ValueError("invalid attribution policy") + + +def stamp(task_meta, runtime, model, message, scoped=False): + if not scoped and not t27sol("."): subprocess.run([str(Path(__file__).with_name("fm-git-strip-ai-trailers.sh")), message], check=True) return # Runtime/model are launch metadata, never free-form trailer contents. @@ -160,6 +181,8 @@ def stamp(task_meta, runtime, model, message): print(mode(*sys.argv[2:])) elif len(sys.argv) == 6 and sys.argv[1] == "stamp": stamp(*sys.argv[2:]) + elif len(sys.argv) == 8 and sys.argv[1] == "apply": + apply(*sys.argv[2:]) elif len(sys.argv) == 3 and sys.argv[1] == "strip-fields": message = Path(sys.argv[2]) content = remove_trailers( diff --git a/bin/fm-git-strip-ai-trailers.sh b/bin/fm-git-strip-ai-trailers.sh index b20a9e728c9..ffc39c7a996 100755 --- a/bin/fm-git-strip-ai-trailers.sh +++ b/bin/fm-git-strip-ai-trailers.sh @@ -6,7 +6,7 @@ # fm-git-strip-ai-trailers.sh # Commit-msg hook mode. Git passes the proposed message file as $1. # Rewrites that file in place, then exits 0 so the commit proceeds. -# fm-git-strip-ai-trailers.sh install [--no-strip] [--attribution ] [--push-guard ] +# fm-git-strip-ai-trailers.sh install [--no-strip] [--scoped-attribution ] [--attribution ] [--push-guard ] # Recreate as a core.hooksPath for this launch: a commit-msg # hook that runs this strip, plus one wrapper per client-side hook name # git documents except reference-transaction and post-index-change, @@ -33,6 +33,10 @@ # hook only when the guard passes (that script owns the rules). # --attribution keeps and adds scoped # attribution through fm-git-attribution.py, rechecking the commit repo. +# --scoped-attribution resolves add/keep/strip in the commit repository, +# using the legacy presence flag outside t27sol and the launch policy +# when origin cannot be resolved. The flag and fallback are captured +# at install time; task metadata supplies runtime session references. # fm-git-strip-ai-trailers.sh env-file # Write as one plain export statement that appends # core.hooksPath= after the GIT_CONFIG_COUNT entries this @@ -89,7 +93,7 @@ usage() { cat >&2 <<'EOF' usage: fm-git-strip-ai-trailers.sh - fm-git-strip-ai-trailers.sh install [--no-strip] [--attribution ] [--push-guard ] [ [...]] + fm-git-strip-ai-trailers.sh install [--no-strip] [--scoped-attribution ] [--attribution ] [--push-guard ] [ [...]] fm-git-strip-ai-trailers.sh env-file EOF exit 2 @@ -254,6 +258,12 @@ install_hooks() { if [ -n "${attribution_meta:-}" ]; then strip_line="python3 $(quote_for_hook "${SELF%/*}/fm-git-attribution.py") stamp $(quote_for_hook "$attribution_meta") $(quote_for_hook "$attribution_runtime") $(quote_for_hook "$attribution_model") \"\$1\" || exit \$?" fi + if [ -n "${attribution_config:-}" ]; then + local fallback outside=strip + fallback=$(python3 "${SELF%/*}/fm-git-attribution.py" mode "$attribution_config" "$wt") || return 1 + [ ! -e "$attribution_config" ] || outside=keep + strip_line="python3 $(quote_for_hook "${SELF%/*}/fm-git-attribution.py") apply $(quote_for_hook "$fallback") $(quote_for_hook "$outside") $(quote_for_hook "$attribution_meta") $(quote_for_hook "$attribution_runtime") $(quote_for_hook "$attribution_model") \"\$1\" || exit \$?" + fi write_executable "$hooks_dir/commit-msg" <.git-hooks as an appended GIT_CONFIG core.hooksPath entry for the pane, so git -# commit-msg strips known AI trailers at the commit object for every launched -# runtime, Claude included as defense in depth. bin/fm-git-strip-ai-trailers.sh +# commit-msg applies the commit repository attribution policy for every +# launched runtime, Claude included as defense in depth. bin/fm-git-strip-ai-trailers.sh # owns the hook install and chaining the repository git is # actually running in so a project husky hook still runs. Author identity is -# not rewritten. A forge=external ship installs that directory even under -# config/keep-ai-trailers, because its pre-push wrapper carries the push guard. +# not rewritten. A forge=external ship also installs its pre-push guard there. # T3 Code owns its provider command, so it cannot receive Claude's inline # attribution settings; the Git hook and environment overlay still apply. # Publishing the record and moving this home's backlog item to In flight are one @@ -6849,18 +6848,14 @@ EOF # rather than shipping a runtime without its required hooks. # A forge=external ship always gets this directory, because its pre-push # wrapper carries the guard that keeps task branches off the shared origin; a -# legacy keep launch gets a commit-msg wrapper that only chains. +# legacy keep launch keeps trailers outside t27sol while adding them inside it. GIT_HOOKS_DIR="$STATE_REAL/$ID.git-hooks" GIT_HOOKS_INSTALLED=0 if [ "$EXTERNAL_REVIEW" = 1 ]; then PUSH_GUARD_FILE="$STATE_REAL/$ID.push-guard" guard_args=("$PUSH_GUARD_FILE" "$WT" "$BRANCH" "$(fm_ship_branch_prefix "$BRANCH" "$ID")") [ -z "$EXTERNAL_BACKUP_REMOTE" ] || guard_args+=("$EXTERNAL_BACKUP_REMOTE" "$EXTERNAL_BACKUP_PREFIX") - strip_args=() - [ "$KEEP_AI_TRAILERS" = 0 ] || strip_args=(--no-strip) - if [ "$AI_ATTRIBUTION_MODE" = add ]; then - strip_args+=(--attribution "$STATE_REAL/$ID.meta" "$HARNESS" "${MODEL:-default}") - fi + strip_args=(--scoped-attribution "$CONFIG/keep-ai-trailers" "$STATE_REAL/$ID.meta" "$HARNESS" "${MODEL:-default}") { "$FM_ROOT/bin/fm-git-push-guard.sh" write "${guard_args[@]}" \ && "$FM_ROOT/bin/fm-git-strip-ai-trailers.sh" install "${strip_args[@]+"${strip_args[@]}"}" \ --push-guard "$PUSH_GUARD_FILE" "$GIT_HOOKS_DIR" "$WT"; } || { @@ -6868,12 +6863,10 @@ if [ "$EXTERNAL_REVIEW" = 1 ]; then exit 1 } GIT_HOOKS_INSTALLED=1 -elif [ "$KEEP_AI_TRAILERS" = 0 ] || [ "$AI_ATTRIBUTION_MODE" = add ]; then - STRIP_INSTALL=("$FM_ROOT/bin/fm-git-strip-ai-trailers.sh" install "$GIT_HOOKS_DIR" "$WT") - if [ "$AI_ATTRIBUTION_MODE" = add ]; then - STRIP_INSTALL=("$FM_ROOT/bin/fm-git-strip-ai-trailers.sh" install --attribution "$STATE_REAL/$ID.meta" "$HARNESS" "${MODEL:-default}" "$GIT_HOOKS_DIR" "$WT") - fi - if [ "$KIND" = ship ] && [ "$MODE" != local-only ]; then +else + STRIP_INSTALL=("$FM_ROOT/bin/fm-git-strip-ai-trailers.sh" install --scoped-attribution "$CONFIG/keep-ai-trailers" "$STATE_REAL/$ID.meta" "$HARNESS" "${MODEL:-default}" "$GIT_HOOKS_DIR" "$WT") + if [ "$KIND" = ship ] && [ "$MODE" != local-only ] && + { [ "$KEEP_AI_TRAILERS" = 0 ] || [ "$AI_ATTRIBUTION_MODE" = add ]; }; then STRIP_INSTALL+=("$FM_ROOT/bin/fm-upstream-push-guard.sh" "$FM_ROOT" "$TASK_TMP/prior-art.json") fi "${STRIP_INSTALL[@]}" || { @@ -7392,9 +7385,9 @@ esac LAUNCH_DIR="/tmp/fm-$ID+$LAUNCH_HOME_TOKEN" # Pane-scoped override: git in this worker reads our commit-msg strip without # rewriting the project's core.hooksPath. GIT_CONFIG_* takes precedence over -# config files and is inherited by child git processes. When the home opts in -# to keeping trailers, leave core.hooksPath alone so the repository's hooks run -# directly. An export statement inside the pane command carries the override +# config files and is inherited by child git processes. The wrappers chain +# the repository's own hooks even when keeping trailers. An export statement +# inside the pane command carries the override # across every step of a compound raw launch while firstmate's own git is unchanged. # The helper appends after the GIT_CONFIG_COUNT entries the worker actually # inherits (after any launch environment filtering), so credential.helper and diff --git a/docs/configuration.md b/docs/configuration.md index 55d3542a804..849f486afb1 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1820,8 +1820,8 @@ This applies only to agents Firstmate launches; the captain's own primary Firstm ### Commit attribution Workers in GitHub repositories owned by `t27sol` keep and receive commit attribution by default, even when `config/keep-ai-trailers` is absent. -The owner match uses the project's `origin` remote over HTTPS, SSH URL or SCP syntax, case insensitively at the owner boundary. -A matching task keeps existing AI co-authors and installs a commit hook that adds a runtime co-author when absent, `Agent-System: fac:firstmate`, and `Agent-Platform: [/]`. +The owner match uses the commit repository's `origin` remote over HTTPS, SSH URL or SCP syntax, case insensitively at the owner boundary. +For a matching commit, the hook keeps existing AI co-authors and adds a runtime co-author when absent, `Agent-System: fac:firstmate`, and `Agent-Platform: [/]`. The runtime is always included; the selected launch model reference is included only when permitted, with Claude Code model IDs and unresolved `default`/`auto` model choices omitted. Each runtime's existing selector and catalog contracts own model syntax and availability; attribution preserves safe references, including variant suffixes, while rejecting controls, whitespace, local paths, and URLs. The hook adds `Agent-Session` from a UUID `CODEX_THREAD_ID` for Codex when no native session trailer already carries the same reference. @@ -1830,16 +1830,17 @@ OpenCode passes its existing plugin session identity to shell commands in memory A session not yet available at commit time is omitted; other runtimes have no connected session source and omit it too. No additional persistent session record is created, and no local path, arbitrary hostname, credential, or guessed session is copied into the added fields. Amending a message replaces the shared fields rather than duplicating them; no trailer order is required and native runtime trailers retain their order within Git's parsed trailer block. -Hook selection is scoped to the launch repository; an attribution-enabled hook rechecks the commit repository's origin and strips attribution outside t27sol. -A worker launched outside t27sol that later commits in a t27sol submodule retains its launch repository's policy; adding attribution in that direction is an accepted limitation deferred to follow-up work. +Every fleet launch installs a commit hook that selects attribution from the repository being committed in, including submodules in either direction across the t27sol owner boundary. +If the commit repository's origin cannot be resolved, the hook uses the launch repository's policy. Focused synthetic regression coverage is in [`fm-git-strip-ai-trailers.test.sh`](../tests/fm-git-strip-ai-trailers.test.sh) and [`fm-spawn-dispatch-profile.test.sh`](../tests/fm-spawn-dispatch-profile.test.sh). Outside t27sol, the optional local, gitignored `config/keep-ai-trailers` retains its legacy home-wide presence-flag behavior; its contents do not select owners or repositories. With that flag absent outside t27sol, every Claude launch's session `--settings` value carries `"attribution":{"commit":"","pr":"","sessionUrl":false}`, every Devin worker config sets `"attribution": false`, and every fleet launch appends a worker-scoped `GIT_CONFIG` `core.hooksPath` entry pointing at `state/.git-hooks`, where git's `commit-msg` hook strips known AI trailers even when a runtime injects them after the typed message. The entry follows any `GIT_CONFIG_*` entries the worker inherits, so an inherited scoped `credential.helper` still applies to the worker and to the repository's own hooks, such as a git-lfs `pre-push`; an inherited `GIT_CONFIG_COUNT` that is not a decimal number, or that leaves no room for another entry within Git's signed int, stops the launch before the worker runs. T3 Code owns its provider command and cannot carry Claude's inline setting, but its per-worktree environment overlay selects the same Git hook; [`t3code-backend.md`](t3code-backend.md#active-limits) owns that backend limit. When the flag is present outside t27sol, Claude launches omit those attribution-off settings and Devin worker configs keep the user config's `attribution` setting (Devin's default is on). -Fleet launches then use the repository's configured hooks directly, except that a [`forge=external`](external-review-forge.md) ship still installs the wrappers for its push guard without stripping attribution. -Because the upstream prior-art push guard is installed only through those pane hooks, a non-external shipping worker in a home with the flag present outside t27sol also skips that guard. +The commit hook then preserves trailers outside t27sol and adds attribution inside t27sol; the presence flag and launch-policy fallback are captured when the hooks are installed. +The wrappers continue chaining the commit repository's own hooks and carrying the applicable shipping push guard. +A non-external shipping launch with the flag present outside t27sol still omits the upstream prior-art push guard. Cortex Code has no attribution switch and its model writes a `Generated with Snowflake CoCo` line and a `Co-authored-by: Snowflake CoCo` trailer itself, so the strip hooks are the only mechanism that removes them from a Cortex worker's commits. `bin/fm-git-attribution.py` owns message filtering and stamping; known AI co-authors are removed only from Git's parsed trailer block, preserving body examples and human co-authors. `bin/fm-git-strip-ai-trailers.sh` owns the install and chaining the hooks of whichever repository git is running in, including when `git -c core.hooksPath` supplies the pane's hook override, so a project hook such as husky still runs when stripping is enabled. diff --git a/tests/fm-git-strip-ai-trailers.test.sh b/tests/fm-git-strip-ai-trailers.test.sh index e9fac52678b..50702501522 100644 --- a/tests/fm-git-strip-ai-trailers.test.sh +++ b/tests/fm-git-strip-ai-trailers.test.sh @@ -31,6 +31,59 @@ make_repo() { fm_git_init_commit "$dir" } +# Synthetic submodules use local transport for setup, then forge-shaped origins. +# Assertions read commit objects produced by ordinary git commit. +test_commit_repository_policy() { + local launch_owner child_owner flag repo source child hooks config body sid + sid=11111111-2222-3333-4444-555555555555 + for launch_owner in another-owner t27sol; do + for flag in absent present; do + repo="$TMP_ROOT/cross-$launch_owner-$flag" + source="$TMP_ROOT/source-$launch_owner-$flag" + hooks="$TMP_ROOT/cross-hooks-$launch_owner-$flag" + config="$TMP_ROOT/cross-config-$launch_owner-$flag" + make_repo "$repo" + make_repo "$source" + git -C "$repo" remote add origin "git@github.com:$launch_owner/parent.git" + [ "$flag" != present ] || : >"$config" + for child_owner in t27sol another-owner local-file relative unknown; do + git -C "$repo" -c protocol.file.allow=always submodule add -q "$source" "$child_owner" || fail 'submodule setup failed' + child="$repo/$child_owner" + git -C "$child" remote set-url origin "https://github.com/$child_owner/child.git" + case "$child_owner" in + unknown) git -C "$child" remote remove origin ;; + local-file) git -C "$child" remote set-url origin "file://$source" ;; + relative) git -C "$child" remote set-url origin ../local-source ;; + esac + done + "$STRIP" install --scoped-attribution "$config" "$TMP_ROOT/absent.meta" codex fixture-model "$hooks" "$repo" || fail 'scoped policy install failed' + for child_owner in t27sol another-owner local-file relative unknown; do + child="$repo/$child_owner" + CODEX_THREAD_ID=$sid with_hooks_env "$hooks" git -C "$child" commit -q --allow-empty \ + -m 'fix: submodule policy' --trailer 'Co-authored-by: Claude ' \ + --trailer 'Co-authored-by: Jane Doe ' || fail 'submodule commit failed' + body=$(git -C "$child" log -1 --format=%B) + assert_contains "$body" 'Co-authored-by: Jane Doe ' 'human coauthor lost' + if [ "$child_owner" = t27sol ] || { [ "$child_owner" = unknown ] && [ "$launch_owner" = t27sol ]; }; then + assert_contains "$body" 'Co-authored-by: codex ' 'scoped runtime coauthor missing' + assert_contains "$body" 'Co-authored-by: Claude ' 'native coauthor lost' + assert_contains "$body" 'Agent-System: fac:firstmate' 'scoped system missing' + assert_contains "$body" 'Agent-Platform: codex/fixture-model' 'scoped platform missing' + assert_contains "$body" "Agent-Session: $sid" 'scoped session missing' + else + assert_not_contains "$body" 'Agent-' 'outside repository gained shared attribution' + if [ "$flag" = present ]; then + assert_contains "$body" 'Co-authored-by: Claude ' 'legacy home flag lost' + else + assert_not_contains "$body" 'noreply@anthropic.com' 'outside repository kept AI attribution' + fi + fi + done + done + done + pass 'commit repository selects attribution in both submodule directions with legacy flag and unknown-origin fallback' +} + test_scoped_keep_and_add() { local runtime repo hooks meta body session model native expected platform for runtime in codex claude pi pi-signed omp opencode grok kimi cursor agy muse gemini rovo devin commandcode polytoken cortex; do @@ -939,6 +992,7 @@ test_push_guard_install_runs_the_guard_before_chaining() { pass "install --push-guard writes a read-only pre-push that runs the guard before chaining" } +test_commit_repository_policy test_known_coauthors_respect_git_trailer_boundary test_git_trailer_removal_preserves_message_body test_strip_fields_preserves_patch_content diff --git a/tests/fm-spawn-dispatch-profile.test.sh b/tests/fm-spawn-dispatch-profile.test.sh index 93cc85f2b72..8cd129bd27c 100755 --- a/tests/fm-spawn-dispatch-profile.test.sh +++ b/tests/fm-spawn-dispatch-profile.test.sh @@ -2410,6 +2410,21 @@ test_scoped_attribution_launches() { assert_not_contains "$body" 'Agent-System:' 'unlisted owner gained shared attribution' [ "$runtime" != claude ] || assert_attribution_policy "$(cat "$LAUNCH_LOG")" 'unscoped claude' fi + if [ "$owner" = t27sol ]; then + git -C "$WT_DIR" remote set-url origin https://github.com/another-owner/example.git + else + git -C "$WT_DIR" remote set-url origin https://github.com/t27sol/example.git + fi + GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=core.hooksPath GIT_CONFIG_VALUE_0="$hooks" \ + git -C "$WT_DIR" -c user.name=Fixture -c user.email=fixture@example.invalid commit -q --allow-empty -m 'fix: changed commit scope' \ + --trailer 'Co-authored-by: Claude ' || fail 'changed-scope commit failed' + body=$(git -C "$WT_DIR" log -1 --format=%B) + if [ "$owner" = t27sol ]; then + assert_not_contains "$body" 'noreply@anthropic.com' 'changed owner kept native attribution' + assert_not_contains "$body" 'Agent-System:' 'changed owner kept shared attribution' + else + assert_contains "$body" "Agent-Platform: $runtime" 'strip launch did not add attribution in t27sol' + fi done done pass 'Codex and Claude launches add t27sol attribution without a configuration file' @@ -2489,8 +2504,8 @@ JS pass 'OpenCode 1 and 2 plugin session contexts reach actual commit trailers' } -test_keep_ai_trailers_omits_attribution_settings_and_strip_hooks() { - local rec id out status launch +test_keep_ai_trailers_omits_attribution_settings_and_keeps_scoped_hooks() { + local rec id out status launch hooks body id=profile-claude-keep-attribution-z25 rec=$(make_spawn_case profile-claude-keep-attribution claude "$id") read_case_record "$rec" @@ -2501,11 +2516,24 @@ test_keep_ai_trailers_omits_attribution_settings_and_strip_hooks() { expect_code 0 "$status" "claude spawn with keep-ai-trailers should succeed"$'\n'"$out" launch=$(cat "$LAUNCH_LOG") assert_attribution_policy_absent "$launch" "opted-in claude" - assert_not_contains "$launch" 'fm-git-strip-ai-trailers.sh' \ - "opted-in launch still overrides the repository hooksPath" - [ ! -e "$HOME_DIR/state/$id.git-hooks" ] \ - || fail "opted-in launch installed AI trailer strip hooks" - pass "keep-ai-trailers omits Claude attribution settings and the pane strip hooks" + assert_contains "$launch" 'fm-git-strip-ai-trailers.sh' \ + "opted-in launch omitted scoped hooks" + [ -e "$HOME_DIR/state/$id.git-hooks" ] || fail "opted-in launch omitted scoped hooks" + hooks="$HOME_DIR/state/$id.git-hooks" + GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=core.hooksPath GIT_CONFIG_VALUE_0="$hooks" \ + git -C "$WT_DIR" -c user.name=Fixture -c user.email=fixture@example.invalid commit -q --allow-empty \ + -m 'fix: legacy attribution' --trailer 'Co-authored-by: Claude ' || fail 'legacy keep commit failed' + body=$(git -C "$WT_DIR" log -1 --format=%B) + assert_contains "$body" 'Co-authored-by: Claude ' 'legacy flag lost native coauthor' + assert_not_contains "$body" 'Agent-System:' 'legacy keep commit gained scoped attribution' + git -C "$WT_DIR" remote set-url origin https://github.com/t27sol/example.git + GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=core.hooksPath GIT_CONFIG_VALUE_0="$hooks" \ + git -C "$WT_DIR" -c user.name=Fixture -c user.email=fixture@example.invalid commit -q --allow-empty \ + -m 'fix: t27sol attribution' || fail 'legacy launch t27sol commit failed' + body=$(git -C "$WT_DIR" log -1 --format=%B) + assert_contains "$body" 'Agent-System: fac:firstmate' 'legacy launch did not add scoped system' + assert_contains "$body" 'Agent-Platform: claude' 'legacy launch did not add scoped platform' + pass "keep-ai-trailers omits Claude attribution settings and installs scoped hooks" } test_keep_ai_trailers_reaches_secondmate_crew_launches() { @@ -2531,10 +2559,9 @@ test_keep_ai_trailers_reaches_secondmate_crew_launches() { expect_code 0 "$status" "secondmate crew spawn should succeed"$'\n'"$out" launch=$(cat "$LAUNCH_LOG") assert_attribution_policy_absent "$launch" "secondmate crew claude" - assert_not_contains "$launch" 'fm-git-strip-ai-trailers.sh' \ - "secondmate crew launch still overrides the repository hooksPath" - [ ! -e "$HOME_DIR/state/$crew_id.git-hooks" ] \ - || fail "secondmate crew launch installed AI trailer strip hooks" + assert_contains "$launch" 'fm-git-strip-ai-trailers.sh' \ + "secondmate crew launch omitted scoped hooks" + [ -e "$HOME_DIR/state/$crew_id.git-hooks" ] || fail "secondmate crew launch omitted scoped hooks" pass "keep-ai-trailers is inherited so a secondmate's crew launch keeps AI trailers" } @@ -3291,7 +3318,7 @@ test_claude_task_launch_carries_control_channel_authority test_claude_secondmate_launch_omits_task_control_channel_authority test_claude_long_launch_is_delivered_intact test_claude_crewmate_launch_carries_the_attribution_policy -test_keep_ai_trailers_omits_attribution_settings_and_strip_hooks +test_keep_ai_trailers_omits_attribution_settings_and_keeps_scoped_hooks test_keep_ai_trailers_reaches_secondmate_crew_launches test_claude_secondmate_launch_carries_the_attribution_policy test_active_dispatch_profile_does_not_block_secondmate_launch From 16427d7400e29e277d97b84a1ff3f2077df49faa Mon Sep 17 00:00:00 2001 From: jazz127 Date: Sat, 31 Oct 2026 10:00:37 +1000 Subject: [PATCH 2/3] no-mistakes(review): Remove unknown-origin attribution fallback --- bin/fm-git-attribution.py | 26 +++++++++++--------------- bin/fm-git-strip-ai-trailers.sh | 9 ++++----- docs/configuration.md | 4 ++-- tests/fm-git-strip-ai-trailers.test.sh | 12 ++++++++---- 4 files changed, 25 insertions(+), 26 deletions(-) diff --git a/bin/fm-git-attribution.py b/bin/fm-git-attribution.py index 85fddab502b..e8272bcfaf8 100755 --- a/bin/fm-git-attribution.py +++ b/bin/fm-git-attribution.py @@ -3,11 +3,10 @@ Usage: fm-git-attribution.py mode fm-git-attribution.py stamp - fm-git-attribution.py apply + fm-git-attribution.py apply fm-git-attribution.py strip-fields -docs/configuration.md "Commit attribution" owns commit-repository selection -and launch-policy fallback when the commit scope is unavailable. +docs/configuration.md "Commit attribution" owns commit-repository selection. Stamp runs in Git's hook cwd and rechecks origin. Session references come from runtime context or existing task metadata, never a new persistent record. """ @@ -67,26 +66,24 @@ def remove_trailers(content, keys, strip_ai=False): def t27sol(project): - """Return the owner match, or None when origin scope is unavailable.""" result = subprocess.run(["git", "-C", project, "config", "--get", "remote.origin.url"], capture_output=True, text=True, check=False) if result.returncode != 0 or not result.stdout.strip(): - return None + return False url = result.stdout.strip() if "://" in url: try: parsed = urlsplit(url) except ValueError: - return None + return False if parsed.scheme not in ("ssh", "https"): return False if not parsed.hostname: - return None + return False host, path = parsed.hostname or "", parsed.path.lstrip("/") else: match = re.fullmatch(r"(?:[^/@:]+@)?([^/:]+):([^\s]+)", url) if not match: - # A local origin identifies a repository outside the GitHub scope. return False host, path = match.groups() return host.lower() == "github.com" and bool(re.fullmatch( @@ -122,19 +119,18 @@ def session(runtime, lines, task_meta): return "" -def apply(fallback, outside, task_meta, runtime, model, message): - scope = t27sol(".") - selected = fallback if scope is None else "add" if scope else outside +def apply(outside, task_meta, runtime, model, message): + selected = "add" if t27sol(".") else outside if selected == "add": - stamp(task_meta, runtime, model, message, scoped=True) + stamp(task_meta, runtime, model, message) elif selected == "strip": subprocess.run([str(Path(__file__).with_name("fm-git-strip-ai-trailers.sh")), message], check=True) elif selected != "keep": raise ValueError("invalid attribution policy") -def stamp(task_meta, runtime, model, message, scoped=False): - if not scoped and not t27sol("."): +def stamp(task_meta, runtime, model, message): + if not t27sol("."): subprocess.run([str(Path(__file__).with_name("fm-git-strip-ai-trailers.sh")), message], check=True) return # Runtime/model are launch metadata, never free-form trailer contents. @@ -181,7 +177,7 @@ def stamp(task_meta, runtime, model, message, scoped=False): print(mode(*sys.argv[2:])) elif len(sys.argv) == 6 and sys.argv[1] == "stamp": stamp(*sys.argv[2:]) - elif len(sys.argv) == 8 and sys.argv[1] == "apply": + elif len(sys.argv) == 7 and sys.argv[1] == "apply": apply(*sys.argv[2:]) elif len(sys.argv) == 3 and sys.argv[1] == "strip-fields": message = Path(sys.argv[2]) diff --git a/bin/fm-git-strip-ai-trailers.sh b/bin/fm-git-strip-ai-trailers.sh index ffc39c7a996..893fbdc1aa0 100755 --- a/bin/fm-git-strip-ai-trailers.sh +++ b/bin/fm-git-strip-ai-trailers.sh @@ -34,8 +34,8 @@ # --attribution keeps and adds scoped # attribution through fm-git-attribution.py, rechecking the commit repo. # --scoped-attribution resolves add/keep/strip in the commit repository, -# using the legacy presence flag outside t27sol and the launch policy -# when origin cannot be resolved. The flag and fallback are captured +# using the legacy presence flag outside t27sol, including when origin +# cannot be resolved. The flag is captured # at install time; task metadata supplies runtime session references. # fm-git-strip-ai-trailers.sh env-file # Write as one plain export statement that appends @@ -259,10 +259,9 @@ install_hooks() { strip_line="python3 $(quote_for_hook "${SELF%/*}/fm-git-attribution.py") stamp $(quote_for_hook "$attribution_meta") $(quote_for_hook "$attribution_runtime") $(quote_for_hook "$attribution_model") \"\$1\" || exit \$?" fi if [ -n "${attribution_config:-}" ]; then - local fallback outside=strip - fallback=$(python3 "${SELF%/*}/fm-git-attribution.py" mode "$attribution_config" "$wt") || return 1 + local outside=strip [ ! -e "$attribution_config" ] || outside=keep - strip_line="python3 $(quote_for_hook "${SELF%/*}/fm-git-attribution.py") apply $(quote_for_hook "$fallback") $(quote_for_hook "$outside") $(quote_for_hook "$attribution_meta") $(quote_for_hook "$attribution_runtime") $(quote_for_hook "$attribution_model") \"\$1\" || exit \$?" + strip_line="python3 $(quote_for_hook "${SELF%/*}/fm-git-attribution.py") apply $(quote_for_hook "$outside") $(quote_for_hook "$attribution_meta") $(quote_for_hook "$attribution_runtime") $(quote_for_hook "$attribution_model") \"\$1\" || exit \$?" fi write_executable "$hooks_dir/commit-msg" <.git-hooks`, where git's `commit-msg` hook strips known AI trailers even when a runtime injects them after the typed message. The entry follows any `GIT_CONFIG_*` entries the worker inherits, so an inherited scoped `credential.helper` still applies to the worker and to the repository's own hooks, such as a git-lfs `pre-push`; an inherited `GIT_CONFIG_COUNT` that is not a decimal number, or that leaves no room for another entry within Git's signed int, stops the launch before the worker runs. T3 Code owns its provider command and cannot carry Claude's inline setting, but its per-worktree environment overlay selects the same Git hook; [`t3code-backend.md`](t3code-backend.md#active-limits) owns that backend limit. When the flag is present outside t27sol, Claude launches omit those attribution-off settings and Devin worker configs keep the user config's `attribution` setting (Devin's default is on). -The commit hook then preserves trailers outside t27sol and adds attribution inside t27sol; the presence flag and launch-policy fallback are captured when the hooks are installed. +The commit hook then preserves trailers outside t27sol and adds attribution inside t27sol; the presence flag is captured when the hooks are installed. The wrappers continue chaining the commit repository's own hooks and carrying the applicable shipping push guard. A non-external shipping launch with the flag present outside t27sol still omits the upstream prior-art push guard. Cortex Code has no attribution switch and its model writes a `Generated with Snowflake CoCo` line and a `Co-authored-by: Snowflake CoCo` trailer itself, so the strip hooks are the only mechanism that removes them from a Cortex worker's commits. diff --git a/tests/fm-git-strip-ai-trailers.test.sh b/tests/fm-git-strip-ai-trailers.test.sh index 50702501522..f8bb255f185 100644 --- a/tests/fm-git-strip-ai-trailers.test.sh +++ b/tests/fm-git-strip-ai-trailers.test.sh @@ -46,31 +46,35 @@ test_commit_repository_policy() { make_repo "$source" git -C "$repo" remote add origin "git@github.com:$launch_owner/parent.git" [ "$flag" != present ] || : >"$config" - for child_owner in t27sol another-owner local-file relative unknown; do + for child_owner in t27sol another-owner local-file relative unknown empty malformed hostless; do git -C "$repo" -c protocol.file.allow=always submodule add -q "$source" "$child_owner" || fail 'submodule setup failed' child="$repo/$child_owner" git -C "$child" remote set-url origin "https://github.com/$child_owner/child.git" case "$child_owner" in unknown) git -C "$child" remote remove origin ;; + empty) git -C "$child" remote set-url origin '' ;; + malformed) git -C "$child" remote set-url origin 'https://[github.com/t27sol/child.git' ;; + hostless) git -C "$child" remote set-url origin 'https:///t27sol/child.git' ;; local-file) git -C "$child" remote set-url origin "file://$source" ;; relative) git -C "$child" remote set-url origin ../local-source ;; esac done "$STRIP" install --scoped-attribution "$config" "$TMP_ROOT/absent.meta" codex fixture-model "$hooks" "$repo" || fail 'scoped policy install failed' - for child_owner in t27sol another-owner local-file relative unknown; do + for child_owner in t27sol another-owner local-file relative unknown empty malformed hostless; do child="$repo/$child_owner" CODEX_THREAD_ID=$sid with_hooks_env "$hooks" git -C "$child" commit -q --allow-empty \ -m 'fix: submodule policy' --trailer 'Co-authored-by: Claude ' \ --trailer 'Co-authored-by: Jane Doe ' || fail 'submodule commit failed' body=$(git -C "$child" log -1 --format=%B) assert_contains "$body" 'Co-authored-by: Jane Doe ' 'human coauthor lost' - if [ "$child_owner" = t27sol ] || { [ "$child_owner" = unknown ] && [ "$launch_owner" = t27sol ]; }; then + if [ "$child_owner" = t27sol ]; then assert_contains "$body" 'Co-authored-by: codex ' 'scoped runtime coauthor missing' assert_contains "$body" 'Co-authored-by: Claude ' 'native coauthor lost' assert_contains "$body" 'Agent-System: fac:firstmate' 'scoped system missing' assert_contains "$body" 'Agent-Platform: codex/fixture-model' 'scoped platform missing' assert_contains "$body" "Agent-Session: $sid" 'scoped session missing' else + assert_not_contains "$body" 'noreply@firstmate.invalid' 'outside repository gained runtime coauthor' assert_not_contains "$body" 'Agent-' 'outside repository gained shared attribution' if [ "$flag" = present ]; then assert_contains "$body" 'Co-authored-by: Claude ' 'legacy home flag lost' @@ -81,7 +85,7 @@ test_commit_repository_policy() { done done done - pass 'commit repository selects attribution in both submodule directions with legacy flag and unknown-origin fallback' + pass 'commit repository selects attribution in both submodule directions and preserves strip or legacy keep for unknown owners' } test_scoped_keep_and_add() { From 4d922ba18046d8eec005ff3641ed48626a0501d0 Mon Sep 17 00:00:00 2001 From: jazz127 Date: Sat, 31 Oct 2026 10:06:08 +1000 Subject: [PATCH 3/3] no-mistakes(document): Clarify commit-scoped attribution and unconditional hook installation --- docs/configuration.md | 7 +++---- docs/t3code-backend.md | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 4a7369f46db..497ec7d4fe8 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -1830,15 +1830,14 @@ OpenCode passes its existing plugin session identity to shell commands in memory A session not yet available at commit time is omitted; other runtimes have no connected session source and omit it too. No additional persistent session record is created, and no local path, arbitrary hostname, credential, or guessed session is copied into the added fields. Amending a message replaces the shared fields rather than duplicating them; no trailer order is required and native runtime trailers retain their order within Git's parsed trailer block. -Every fleet launch installs a commit hook that selects attribution from the repository being committed in, including submodules in either direction across the t27sol owner boundary. -If the commit repository's owner cannot be established, the hook strips AI trailers unless `config/keep-ai-trailers` is present, in which case it preserves them without adding attribution. +Every fleet launch appends a worker-scoped `GIT_CONFIG` `core.hooksPath` entry pointing at `state/.git-hooks`, where the commit hook selects attribution from the repository being committed in, including submodules in either direction across the t27sol owner boundary. +Outside t27sol, including when the commit repository's owner cannot be established, the hook strips known AI trailers even when a runtime injects them after the typed message, unless `config/keep-ai-trailers` was present when the hooks were installed; that flag preserves trailers without adding attribution. Focused synthetic regression coverage is in [`fm-git-strip-ai-trailers.test.sh`](../tests/fm-git-strip-ai-trailers.test.sh) and [`fm-spawn-dispatch-profile.test.sh`](../tests/fm-spawn-dispatch-profile.test.sh). Outside t27sol, the optional local, gitignored `config/keep-ai-trailers` retains its legacy home-wide presence-flag behavior; its contents do not select owners or repositories. -With that flag absent outside t27sol, every Claude launch's session `--settings` value carries `"attribution":{"commit":"","pr":"","sessionUrl":false}`, every Devin worker config sets `"attribution": false`, and every fleet launch appends a worker-scoped `GIT_CONFIG` `core.hooksPath` entry pointing at `state/.git-hooks`, where git's `commit-msg` hook strips known AI trailers even when a runtime injects them after the typed message. The entry follows any `GIT_CONFIG_*` entries the worker inherits, so an inherited scoped `credential.helper` still applies to the worker and to the repository's own hooks, such as a git-lfs `pre-push`; an inherited `GIT_CONFIG_COUNT` that is not a decimal number, or that leaves no room for another entry within Git's signed int, stops the launch before the worker runs. +With that flag absent and the launch repository outside t27sol, every Claude launch's session `--settings` value carries `"attribution":{"commit":"","pr":"","sessionUrl":false}` and every Devin worker config sets `"attribution": false`. T3 Code owns its provider command and cannot carry Claude's inline setting, but its per-worktree environment overlay selects the same Git hook; [`t3code-backend.md`](t3code-backend.md#active-limits) owns that backend limit. When the flag is present outside t27sol, Claude launches omit those attribution-off settings and Devin worker configs keep the user config's `attribution` setting (Devin's default is on). -The commit hook then preserves trailers outside t27sol and adds attribution inside t27sol; the presence flag is captured when the hooks are installed. The wrappers continue chaining the commit repository's own hooks and carrying the applicable shipping push guard. A non-external shipping launch with the flag present outside t27sol still omits the upstream prior-art push guard. Cortex Code has no attribution switch and its model writes a `Generated with Snowflake CoCo` line and a `Co-authored-by: Snowflake CoCo` trailer itself, so the strip hooks are the only mechanism that removes them from a Cortex worker's commits. diff --git a/docs/t3code-backend.md b/docs/t3code-backend.md index 9889185d5cd..65cab1fa608 100644 --- a/docs/t3code-backend.md +++ b/docs/t3code-backend.md @@ -100,7 +100,7 @@ For `claude` that is an `env` block in the directory's `.claude/settings.local.j Codex applies that file only in a project it [trusts](#setup); in an untrusted project a Codex thread runs without any of these values, so its Git hook entry, and with it the [commit attribution policy](configuration.md#commit-attribution) and a `forge=external` ship's push guard, does not apply; Firstmate warns at spawn when it cannot confirm that trust, but never grants it. The Claude `env` block keeps entries Firstmate did not write, such as a secondmate home's own, and lists the keys Firstmate wrote in `FM_T3CODE_ENV_KEYS` so a respawn replaces exactly those; a symlinked `.claude/settings.local.json` is refused. The thread's `GIT_CONFIG_*` entries are Firstmate's own `core.hooksPath` hook entry only: inherited `GIT_CONFIG_*` values, or any other inherited environment value, are never written to these files, because they can carry credentials. -That entry sets `GIT_CONFIG_COUNT=1` and index 0, so numbered `GIT_CONFIG_KEY_`/`GIT_CONFIG_VALUE_` entries in the T3 server's environment do not apply in the thread; when neither the [commit attribution policy](configuration.md#commit-attribution) nor a [`forge=external`](external-review-forge.md) push guard requires a hook entry, those inherited entries apply unchanged. +That entry sets `GIT_CONFIG_COUNT=1` and index 0, so numbered `GIT_CONFIG_KEY_`/`GIT_CONFIG_VALUE_` entries in the T3 server's environment do not apply in the thread. A T3 server whose agents need extra Git config, such as a `credential.helper`, supplies it through Git config files, which the hook entry leaves alone: for example the service user's global config, or `GIT_CONFIG_GLOBAL` in its service environment. Firstmate-created untracked environment files are git-excluded and removed at teardown; in a secondmate home, teardown removes only the keys `FM_T3CODE_ENV_KEYS` lists from the home's own `.claude/settings.local.json`. An existing untracked `.codex/config.toml` without Firstmate's marker is preserved and refused.