Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions bin/fm-git-attribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

Usage: fm-git-attribution.py mode <config> <project>
fm-git-attribution.py stamp <task-meta> <runtime> <model> <message>
fm-git-attribution.py apply <outside> <task-meta> <runtime> <model> <message>
fm-git-attribution.py strip-fields <message>

docs/configuration.md "Commit attribution" owns launch-repository selection
and its accepted cross-repository limitation.
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.
"""
Expand Down Expand Up @@ -68,11 +68,18 @@ def remove_trailers(content, keys, strip_ai=False):
def t27sol(project):
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 False
url = result.stdout.strip()
if "://" in url:
parsed = urlsplit(url)
try:
parsed = urlsplit(url)
except ValueError:
return False
if parsed.scheme not in ("ssh", "https"):
return False
if not parsed.hostname:
return False
host, path = parsed.hostname or "", parsed.path.lstrip("/")
else:
match = re.fullmatch(r"(?:[^/@:]+@)?([^/:]+):([^\s]+)", url)
Expand Down Expand Up @@ -112,6 +119,16 @@ def session(runtime, lines, task_meta):
return ""


def apply(outside, task_meta, runtime, model, message):
selected = "add" if t27sol(".") else outside
if selected == "add":
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):
if not t27sol("."):
subprocess.run([str(Path(__file__).with_name("fm-git-strip-ai-trailers.sh")), message], check=True)
Expand Down Expand Up @@ -160,6 +177,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) == 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])
content = remove_trailers(
Expand Down
21 changes: 18 additions & 3 deletions bin/fm-git-strip-ai-trailers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# fm-git-strip-ai-trailers.sh <msgfile>
# 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 <task-meta> <runtime> <model>] [--push-guard <guard-file>] <hooks-dir> <worktree>
# fm-git-strip-ai-trailers.sh install [--no-strip] [--scoped-attribution <config> <task-meta> <runtime> <model>] [--attribution <task-meta> <runtime> <model>] [--push-guard <guard-file>] <hooks-dir> <worktree>
# Recreate <hooks-dir> 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,
Expand All @@ -33,6 +33,10 @@
# hook only when the guard passes (that script owns the rules).
# --attribution <task-meta> <runtime> <model> 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, 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 <hooks-dir> <out-file>
# Write <out-file> as one plain export statement that appends
# core.hooksPath=<hooks-dir> after the GIT_CONFIG_COUNT entries this
Expand Down Expand Up @@ -89,7 +93,7 @@ usage() {
cat >&2 <<'EOF'
usage:
fm-git-strip-ai-trailers.sh <msgfile>
fm-git-strip-ai-trailers.sh install [--no-strip] [--attribution <task-meta> <runtime> <model>] [--push-guard <guard-file>] <hooks-dir> <worktree> [<pre-push-guard> [<arg>...]]
fm-git-strip-ai-trailers.sh install [--no-strip] [--scoped-attribution <config> <task-meta> <runtime> <model>] [--attribution <task-meta> <runtime> <model>] [--push-guard <guard-file>] <hooks-dir> <worktree> [<pre-push-guard> [<arg>...]]
fm-git-strip-ai-trailers.sh env-file <hooks-dir> <out-file>
EOF
exit 2
Expand Down Expand Up @@ -254,6 +258,11 @@ 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 outside=strip
[ ! -e "$attribution_config" ] || outside=keep
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" <<EOF
#!/usr/bin/env bash
set -u
Expand Down Expand Up @@ -310,9 +319,15 @@ CMD=${1:-}
case "$CMD" in
install)
shift
strip=1 guard='' attribution_meta='' attribution_runtime='' attribution_model=''
strip=1 guard='' attribution_meta='' attribution_runtime='' attribution_model='' attribution_config=''
while [ "$#" -gt 0 ]; do
case "$1" in
--scoped-attribution)
[ "$#" -ge 7 ] || usage
attribution_config=$2 attribution_meta=$3 attribution_runtime=$4 attribution_model=$5
strip=0
shift 5
;;
--attribution)
[ "$#" -ge 6 ] || usage
attribution_meta=$2 attribution_runtime=$3 attribution_model=$4
Expand Down
33 changes: 13 additions & 20 deletions bin/fm-spawn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -660,14 +660,13 @@
# ~/.cursor/cli-config.json attribution-off is not durable (it does not travel
# with this repo, defaults back to on when unset, and only feeds the CLI's
# request to the server, so it suppresses the trailer rather than preventing
# it). When stripping is selected, the spawn installs
# it). Every spawn installs
# state/<id>.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
Expand Down Expand Up @@ -6849,31 +6848,25 @@ 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"; } || {
echo "error: could not install the external-review push guard hooks for $ID" >&2
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[@]}" || {
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: <runtime>[/<model>]`.
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: <runtime>[/<model>]`.
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.
Expand All @@ -1830,16 +1830,16 @@ 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 appends a worker-scoped `GIT_CONFIG` `core.hooksPath` entry pointing at `state/<id>.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/<id>.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).
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 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.
Expand Down
2 changes: 1 addition & 1 deletion docs/t3code-backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_<n>`/`GIT_CONFIG_VALUE_<n>` 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_<n>`/`GIT_CONFIG_VALUE_<n>` 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.
Expand Down
Loading
Loading