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
1 change: 1 addition & 0 deletions .agents/skills/secondmate-provisioning/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ SSH exit 255 preserves the route and reports unknown completion; it never trigge
The same placement-specific launch and deferred bootstrap sweep also propagate the primary's declared inherited local material: `config/crew-dispatch.json`, `config/crew-harness`, `config/backlog-backend`, `config/backend`, `config/herdr-presentation-spaces`, `config/startup-memory-budget`, and the one shared captain-preference file `data/captain-shared.md`.
Because these paths are gitignored, that propagation is a separate, primary-authoritative copy independent of the tracked-files fast-forward: it re-converges every live home whether or not its tracked files advanced, and it touches only the declared items.
Propagation failures warn without blocking secondmate launch or session-start continuation, and the destination keeps whatever safely validated state the helper left behind.
A remote launch also rsyncs the engineer's `~/.claude/skills/` into the route at this same convergence point, a separate best-effort step outside this allowlist; see [Remote secondmate skill sync](../../../docs/configuration.md#remote-secondmate-skill-sync-configskill-sync-exclude) for its contract.
Inheritance copies the literal `config/crew-harness` file, so a secondmate's own crewmates use the primary's crewmate harness only when it names a concrete adapter such as `codex`; an unset or `default` value has nothing concrete to inherit, and the secondmate's own crewmates fall back to the secondmate's own or detected harness instead.
Inherited `config/backend` becomes that secondmate home's local runtime-backend default for future spawns only; it never retargets, rewrites, migrates, stops, or restarts an already-live worker endpoint.
A present primary value always converges byte-exact into validated secondmate homes, and primary absence removes the destination so those homes keep runtime auto-detection.
Expand Down
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ config/herdr-presentation-spaces optional "off" opt-out from, or "on" opt-in to
config/trace-context optional presence flag enabling default-off native W3C trace-context propagation to spawned agents; LOCAL, gitignored; inherited by secondmate homes; see docs/configuration.md "Trace context propagation" and docs/trace-context.md
config/cmux-socket-password optional cmux control-socket password; LOCAL, gitignored; read fresh on every cmux CLI call and passed through without ever overriding an operator's own ambient CMUX_SOCKET_PASSWORD when absent (docs/cmux-backend.md "Setup")
config/wedge-alarm optional away-mode wedge-alarm active-alert directives; LOCAL, gitignored; absent means auto (macOS Notification Center when available); see docs/wedge-alarm.md
config/skill-sync-exclude optional rsync --exclude patterns for the remote secondmate skill sync, one per non-empty, non-comment line; LOCAL, gitignored; absent uses the built-in default set; a remote-launch-only best-effort step outside the FM_INHERITABLE_CONFIG allowlist, NOT inherited by secondmate homes; see docs/configuration.md "Remote secondmate skill sync (config/skill-sync-exclude)"
config/watched-tools.json optional list of the tools this home depends on, read by the update check armed with bin/fm-tool-update-check.sh; LOCAL, gitignored, firstmate-maintained but human-editable, and NOT inherited by secondmate homes; see docs/configuration.md "Watched tool updates"
config/x-mode.env generated Relay watcher cadence; LOCAL, gitignored; source before arming watcher when present
data/ personal fleet records; LOCAL, gitignored as a whole
Expand Down
121 changes: 121 additions & 0 deletions bin/fm-remote-skill-sync.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#!/usr/bin/env bash
# Rsync the engineer's local ~/.claude/skills/ into a remote secondmate's home,
# so that secondmate's own crewmates and skill loads always see the captain's
# current skill set. A skill set loads only at session start, so this only
# matters at launch; it has no effect on an already-running secondmate.
#
# Usage: fm-remote-skill-sync.sh <secondmate-id>
#
# This is adjacent to, and independent of, the FM_INHERITABLE_CONFIG allowlist
# (bin/fm-config-inherit-lib.sh): that contract carries single small files
# inside FM_HOME with sha256 transfer and generation records. Skills are a
# directory tree outside FM_HOME, so this uses plain rsync instead and does not
# read or write anything that contract owns.
#
# Remote routes only: a local secondmate is the same user on the same machine
# already reading this same directory, so a local route is a no-op here.
# Never passes --delete: the remote host may legitimately hold skills the
# local machine does not (no-mistakes, installed there by its own installer,
# is the standing example), and deleting host-only content would break it.
#
# The destination is the plain relative path .claude/skills/, which an
# interactive-less ssh command resolves against the remote login shell's own
# home directory, so no extra remote-home field is required beyond the
# existing SSH alias.
#
# Exclusions come from the gitignored config/skill-sync-exclude (one rsync
# --exclude pattern per non-empty, non-comment line); an absent file uses the
# DEFAULT_EXCLUDES below verbatim (no merge). docs/configuration.md owns this
# schema.
#
# A caller must treat any nonzero exit as warn-only and never let it block a
# secondmate launch. Exit 0 means a route was actually not remote (silent
# no-op) or a confirmed rsync transfer, including one that moved nothing.
# Exit 1 means misuse (bad arguments or registry lookup failure). Exit 2 means
# rsync could not be trusted to have run: missing rsync, a failed SSH/rsync
# invocation, or output that carries no recognizable rsync --stats block. That
# last case matters concretely: a shipped rsync that rejects an unsupported
# flag can print its usage banner and still exit 0, so exit status alone is
# never proof a transfer happened here - only a genuine --stats block is.
set -eu

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
FM_ROOT="${FM_ROOT_OVERRIDE:-$(cd "$SCRIPT_DIR/.." && pwd)}"
FM_HOME="${FM_HOME:-${FM_ROOT_OVERRIDE:-$FM_ROOT}}"
CONFIG="${FM_CONFIG_OVERRIDE:-$FM_HOME/config}"
DATA="${FM_DATA_OVERRIDE:-$FM_HOME/data}"

# shellcheck source=bin/fm-secondmate-registry-lib.sh
. "$SCRIPT_DIR/fm-secondmate-registry-lib.sh"

DEFAULT_EXCLUDES='notebooklm/
notebooklm-to-skill/
notebooklm-to-skill-workspace/
skill-creator/
no-mistakes/
__pycache__
.venv
node_modules'

die() { printf 'error: %s\n' "$1" >&2; exit 1; }
fail_transfer() { printf '%s\n' "$1" >&2; exit 2; }

[ "$#" -eq 1 ] || die "usage: fm-remote-skill-sync.sh <secondmate-id>"
ID=$1
case "$ID" in ''|*[!A-Za-z0-9._-]*) die "invalid secondmate id: $ID" ;; esac

REMOTE=$(secondmate_registry_field "$DATA/secondmates.md" "$ID" remote 2>/dev/null || true)
if [ "$REMOTE" != 1 ]; then
echo "skip: secondmate $ID is not a remote route"
exit 0
fi
HOST=$(secondmate_registry_field "$DATA/secondmates.md" "$ID" host)
case "$HOST" in ''|-*|*[!A-Za-z0-9._-]*) die "configured SSH alias is unsafe: $HOST" ;; esac

SOURCE="${FM_SKILLS_SOURCE_OVERRIDE:-$HOME/.claude/skills}"
if [ ! -d "$SOURCE" ]; then
echo "skip: no local skills directory at $SOURCE"
exit 0
fi

EXCLUDE_FILE="$CONFIG/skill-sync-exclude"
if [ -f "$EXCLUDE_FILE" ]; then
PATTERNS=$(grep -v '^[[:space:]]*#' "$EXCLUDE_FILE" | grep -v '^[[:space:]]*$' || true)
else
PATTERNS=$DEFAULT_EXCLUDES
fi

RSYNC_BIN=${FM_RSYNC_BIN:-rsync}
SSH_BIN=${FM_SSH_BIN:-ssh}
command -v "$RSYNC_BIN" >/dev/null 2>&1 || fail_transfer "rsync is not available"

RSYNC_ARGS=(-az --stats)
while IFS= read -r pattern; do
[ -n "$pattern" ] || continue
RSYNC_ARGS+=(--exclude="$pattern")
done <<EOF
$PATTERNS
EOF

ALIVE_INTERVAL=${FM_SSH_ALIVE_INTERVAL:-15}
ALIVE_COUNT_MAX=${FM_SSH_ALIVE_COUNT_MAX:-3}
RSYNC_SSH="$SSH_BIN -o BatchMode=yes -o ConnectTimeout=10 -o ServerAliveInterval=$ALIVE_INTERVAL -o ServerAliveCountMax=$ALIVE_COUNT_MAX"

if OUT=$("$RSYNC_BIN" "${RSYNC_ARGS[@]}" -e "$RSYNC_SSH" "$SOURCE/" "$HOST:.claude/skills/" 2>&1); then
:
else
fail_transfer "rsync to $HOST failed: $(printf '%s' "$OUT" | tail -1)"
fi

# openrsync (the shipped macOS rsync) and GNU rsync label their --stats block
# differently ("Total sent:" vs "Total bytes sent:"), so match either. Both
# require this pair to appear together only on a genuine stats block, never on
# a usage/error banner, which is what makes a confirmed zero-file resync
# distinguishable from a transfer that never actually ran.
if ! printf '%s\n' "$OUT" | grep -Eq '^Number of files: [0-9]' \
|| ! printf '%s\n' "$OUT" | grep -Eq '^Total (bytes )?sent: [0-9]'; then
fail_transfer "rsync to $HOST produced no recognizable transfer summary: $(printf '%s' "$OUT" | tail -1)"
fi

printf '%s\n' "$OUT"
exit 0
10 changes: 9 additions & 1 deletion bin/fm-spawn.sh
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ fi
spawn_remote_secondmate() {
local id=$1 remote host root home harness positional model effort backend out rc meta tmp
local remote_backend remote_target remote_harness remote_herdr_session registry_lock remote_lock remote_generation
local remote_traceparent remote_recorded_traceparent
local remote_traceparent remote_recorded_traceparent skill_sync_out
local -a launch_args
id=${POS[0]:-}
fm_task_id_creation_valid "$id" || { echo "error: invalid task id" >&2; return 2; }
Expand Down Expand Up @@ -544,6 +544,14 @@ spawn_remote_secondmate() {
fi
return "$rc"
fi
# Adjacent to the inheritance push above, not part of its contract: a
# skill-tree rsync outside FM_HOME, best-effort. A failure here warns and
# the launch continues, matching the propagation-failure contract for every
# other piece of inherited local material.
skill_sync_out=
if ! skill_sync_out=$("$SCRIPT_DIR/fm-remote-skill-sync.sh" "$id" 2>&1); then
echo "SECONDMATE_SYNC: secondmate $id: skipped: skill sync failed on $host: $(printf '%s\n' "$skill_sync_out" | tail -1)" >&2
fi
# This parent home owns the remote secondmate's task identity because it holds
# the task metadata an observer reads, exactly as for a local spawn: the
# carrier is resolved against THIS task's own meta (reused verbatim on
Expand Down
10 changes: 10 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ This does not relax protection for any other untracked file.
An existing linked-worktree home that predates this rule advances through its marker-only state during its next bootstrap or spawn local sync, after which Git ignores the marker normally.
A standalone-clone home cannot receive a primary-local commit through that no-fetch sync, so it receives the rule through `/updatefirstmate`'s origin refresh instead.

## Remote secondmate skill sync (config/skill-sync-exclude)

At every remote secondmate launch, `bin/fm-remote-skill-sync.sh` rsyncs the engineer's local `~/.claude/skills/` into `.claude/skills/` under that route's remote login home, so the secondmate always launches against the captain's current skill set; a running secondmate does not see a mid-session sync because skills load only at session start.
This is a plain rsync step at the same launch convergence point as [inherited local-material propagation](../.agents/skills/secondmate-provisioning/SKILL.md#charter-and-seed), not an extension of it: `FM_INHERITABLE_CONFIG` (`bin/fm-config-inherit-lib.sh`) stays the single owner of single small files inside `FM_HOME`, while skills are a directory tree outside it.
It is remote-route only, never passes `--delete` (a host may legitimately hold skills the local machine does not, `no-mistakes` installed there by its own installer being the standing example), and a failure warns on `SECONDMATE_SYNC:` without blocking the launch, matching every other inherited-material propagation failure.
`config/skill-sync-exclude` (local, gitignored) lists rsync `--exclude` patterns, one per non-empty, non-comment line, and fully replaces the built-in default set when present.
An absent file uses this default: `notebooklm/`, `notebooklm-to-skill/`, `notebooklm-to-skill-workspace/`, and `skill-creator/` (authoring/local-cache tools a worker host does not need), `no-mistakes/` (installed on a remote host by its own installer; overwriting it would break a working install), and the build-residue patterns `__pycache__`, `.venv`, `node_modules`.
See [`docs/examples/skill-sync-exclude`](examples/skill-sync-exclude) for a copyable starting point.
The script's own header owns exact rsync flags, the destination-path resolution, and how it tells a confirmed no-op transfer apart from a transfer that never ran.

## FM_HOME

`FM_HOME` selects the operational home for one firstmate instance.
Expand Down
4 changes: 4 additions & 0 deletions docs/documentation-audiences.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@
"path": "docs/examples/crew-dispatch.json",
"audience": "operator-example"
},
{
"path": "docs/examples/skill-sync-exclude",
"audience": "operator-example"
},
{
"path": "docs/examples/watched-tools.json",
"audience": "operator-example"
Expand Down
19 changes: 19 additions & 0 deletions docs/examples/skill-sync-exclude
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# config/skill-sync-exclude - rsync --exclude patterns for the remote
# secondmate skill sync (bin/fm-remote-skill-sync.sh). Copy this into a local,
# gitignored config/skill-sync-exclude and edit. One pattern per non-empty,
# non-comment line. Presence fully replaces the script's built-in default set
# below, it does not merge with it.
#
# no-mistakes is excluded because a remote host installs it itself; overwriting
# it with the local copy could break a working install. notebooklm is a large
# local data cache. skill-creator, notebooklm-to-skill, and
# notebooklm-to-skill-workspace are authoring tools a worker host does not run.
# The rest is ordinary build residue.
notebooklm/
notebooklm-to-skill/
notebooklm-to-skill-workspace/
skill-creator/
no-mistakes/
__pycache__
.venv
node_modules
2 changes: 1 addition & 1 deletion docs/remote-secondmates.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Launch or recover the remote second mate with the same command used for a local
bin/fm-spawn.sh <id> --secondmate
```

The primary resolves the verified secondmate harness and optional model and effort, runs the same readiness gate the seed runs, transfers the inherited-material allowlist, and asks the remote host to launch on Herdr in `fm-remote`.
The primary resolves the verified secondmate harness and optional model and effort, runs the same readiness gate the seed runs, transfers the inherited-material allowlist, best-effort rsyncs the engineer's skills (see [Remote secondmate skill sync](configuration.md#remote-secondmate-skill-sync-configskill-sync-exclude)), and asks the remote host to launch on Herdr in `fm-remote`.
All remote secondmates on one host share `fm-remote` and retain separate `2ndmate-<id>` workspaces inside it.
An explicit request for any other backend is refused rather than honored, and the remote host refuses one too.
An existing remote endpoint recorded in another Herdr session, including `default`, is classified as unverified and left untouched; launch, liveness recovery, control, and retirement refuse it until an operator explicitly migrates it instead of attempting a live cutover.
Expand Down
5 changes: 5 additions & 0 deletions tests/fm-remote-secondmate-lifecycle-e2e.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,13 @@ publish_healthy_watcher_identity() { # <state> <home> <watch-script>
touch "$state/.last-watcher-beat"
}

# Points fm-remote-skill-sync.sh at a source that does not exist, so the launch
# convergence point's skill sync no-ops instead of attempting a real rsync;
# tests/fm-remote-skill-sync.test.sh and
# tests/fm-remote-secondmate-skill-sync.test.sh own that step's own behavior.
remote_env() {
FM_HOME="$PARENT" \
FM_SKILLS_SOURCE_OVERRIDE="$TMP_ROOT/no-skills-source" \
FM_ROOT_OVERRIDE="$REMOTE_ROOT" \
FM_PROCEVENT_CLAIM_ROOT="$CLAIMS" \
FM_SSH_BIN="$FAKEBIN/fake-ssh" \
Expand Down
5 changes: 5 additions & 0 deletions tests/fm-remote-secondmate-parent-binding.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,13 @@ exec "$FM_FAKE_REMOTE_ENTRYPOINT" "$@"
SH
chmod +x "$FAKEBIN/fake-ssh"

# Points fm-remote-skill-sync.sh at a source that does not exist, so the launch
# convergence point's skill sync no-ops instead of attempting a real rsync;
# tests/fm-remote-skill-sync.test.sh and
# tests/fm-remote-secondmate-skill-sync.test.sh own that step's own behavior.
remote_env() {
FM_HOME="$PARENT" \
FM_SKILLS_SOURCE_OVERRIDE="$TMP_ROOT/no-skills-source" \
FM_ROOT_OVERRIDE="$REMOTE_ROOT" \
FM_PROCEVENT_CLAIM_ROOT="$CLAIMS" \
FM_SSH_BIN="$FAKEBIN/fake-ssh" \
Expand Down
Loading
Loading