Skip to content

feat(bin): select a Claude account per crew dispatch profile - #5444

Open
gus-fraser wants to merge 4 commits into
kunchenguid:mainfrom
gus-fraser:fm/claude-account-profiles
Open

gus-fraser wants to merge 4 commits into
kunchenguid:mainfrom
gus-fraser:fm/claude-account-profiles

Conversation

@gus-fraser

Copy link
Copy Markdown

Intent

Add account selection to crew dispatch rules so a dispatch profile can choose which Claude subscription a worker runs on.
The setup behind the ask: one Codex subscription and two Claude subscriptions.
The second Claude subscription is signed in under its own Claude config directory (for example ~/.claude-second, referred to as the account claude-second), while the first uses the default ~/.claude.
Today a dispatch profile can only choose harness, model, and effort, and bin/fm-spawn.sh forwards only firstmate's own ambient CLAUDE_CONFIG_DIR onto every Claude worker launch, so every Claude worker lands on whichever account firstmate itself runs under and there is no way to route some jobs to the second account.
Do the upstream change so that claude-second can be selected per dispatch profile for the native Claude Code runtime.
Routing through the Pi runtime is not wanted as the way to reach the second account.

What Changed

  • Adds a local, gitignored config/claude-accounts registry that maps an account name (for example claude-second) to an absolute Claude config directory. The new bin/fm-claude-accounts-lib.sh parses it and validates the whole file on every lookup. It refuses invalid or reserved names (default is reserved), unknown names, duplicate or malformed entries, and relative or missing directories.
  • Crew dispatch profiles take an optional account field, which is valid only with "harness": "claude". fm-bootstrap.sh and fm-dispatch-resolve.sh validate it and resolve its name. Two profiles that differ only by account now count as distinct candidates. The resolver passes --account <name> to fm-spawn.sh, and quota for a named account comes only from a schema 6 quota-axi row whose accountKey matches exactly. It never falls back to the default account's row, so until such a row exists, a profile that names an account is left unmeasured and unranked. Given --account, fm-spawn.sh launches the native Claude worker with that account's directory as CLAUDE_CONFIG_DIR, replacing Firstmate's own, and pre-registers workspace trust in that account's store. It records account= in the task metadata and refuses the flag for secondmates, raw launch commands, and non-Claude harnesses before any endpoint or worktree is created. With no account, launches run exactly as before.
  • fm-control.sh relaunch keeps the recorded account when the task stays on Claude and drops it when switching to another harness. It accepts --account <name> to move the task to another account, or --account default to return it to the default account. An account that doesn't resolve is refused before the running agent is stopped. Docs, skills, and AGENTS.md now describe the account axis, including that each account's Claude config directory must already have accepted Bypass Permissions mode. Tests cover bootstrap validation, resolver output and quota binding, spawn launch behavior, and relaunch.

🤖 Generated with Claude Code

Risk Assessment

✅ Low: The account axis only takes effect when a profile, spawn, or relaunch names an account, so launches without one behave as before. Every account refusal (unknown, reserved, relative or missing directory, wrong harness, secondmate) fires before any endpoint, record, or running agent is touched. Both prior-round items are in the current code as the user asked: the relaunch account override and the documented typed-resolver limitation.

Testing

I drove the change live in a throwaway Herdr lab with a scratch Firstmate home and scratch Claude config stores. Spawn routes a Claude worker onto the named account's store, confirmed from the live process env, task meta, and per-store trust registration. A spawn with no account keeps using the ambient store. Seven adversarial spawn refusals left no task record and no lab tab. Five relaunch refusals left the running worker alive. Four relaunch moves each landed on the right store and journaled from_account and to_account. A store that has not accepted Bypass Permissions visibly parks on the dialog, as the new docs state. The real resolver and bootstrap accepted valid account profiles and refused bad ones with exit 2 before any network call. Two lab setup problems were fixed and re-driven. Brand-new scratch stores stopped on Claude's first-run theme picker, so I marked onboarding complete in them. A // in the mktemp path confused teardown's exclusivity check, so I switched to canonical paths. All four targeted test files (dispatch-resolve, spawn-dispatch-profile, control-relaunch, bootstrap) passed. The lab is torn down and the worktree is clean.

  • Live validation: ✅ go - 7 of 8 scenarios driven live against the product
Scenario Result Live Evidence
Operator spawns a Claude crewmate with --account claude-second: the live claude process runs with CLAUDE_CONFIG_DIR=<claude-second dir>, meta records account=claude-second, and workspace trust is writ… ✅ pass live r2-02-spawn-second-and-default.txt
Spawn with no account still inherits Firstmate's ambient CLAUDE_CONFIG_DIR and records no account ✅ pass live r2-02-spawn-second-and-default.txt
Adversarial: unknown, reserved 'default', invalid-case, non-claude harness, relative dir, missing dir, and duplicate entry are each refused with exit 1 before any task record or lab tab exists ✅ pass live r2-01-spawn-refusals.txt
Relaunch --account default moves a claude-second worker to the default store; --account claude-second moves it back; a plain relaunch keeps the recorded account; a default worker moves onto claude-sec… ✅ pass live r2-04-relaunch-account-moves.txt
Adversarial: a relaunch with an unknown, invalid, relative-dir, or missing-dir account, or with codex plus an account, is refused before the running worker is stopped ✅ pass live r2-03-relaunch-refusals.txt
Crew-dispatch profile 'account' is validated: valid claude accounts pass the resolver and bootstrap; an unknown account, an account on codex, an empty account, and duplicate profiles are refused (reso… ✅ pass live r2-06-dispatch-rule-account-validation.txt
A clear typed resolution emits a profile line containing --account claude-second ⏸️ untested no A real clear answer needs a live typesafe.ai TYPESAFE_API_KEY and a schema-6 quota-axi row for the account. Neither was available, and the installed quota-axi is single-account by the documented limit…
Documented precondition: a named store that has not accepted Bypass Permissions parks the worker on the dialog with 'No, exit' selected ✅ pass live r2-05-unaccepted-store-bypass-dialog.txt
Evidence: Spawn account refusals (live lab)

Source: Spawn account refusals (live lab)

## Round-2 spawn refusals (live lab fm-lab-acct-r2-25675-6330, commit 055fed0)
$ fm-spawn.sh acct1 <proj> --mode local-only --yolo off --backend herdr --harness claude --account claude-third
error: claude account 'claude-third' is unknown: config/claude-accounts has no entry for it
exit=1
state/acct1.meta exists: no; lab tabs: []

$ fm-spawn.sh acct1 <proj> --mode local-only --yolo off --backend herdr --harness codex --account claude-second
error: --account claude-second selects a Claude account and needs the canonical claude harness, not 'codex'
exit=1
state/acct1.meta exists: no; lab tabs: []

$ fm-spawn.sh acct1 <proj> --mode local-only --yolo off --backend herdr --harness claude --account default
error: claude account name 'default' is reserved for the default Claude config directory; omit the account to use it
exit=1
state/acct1.meta exists: no; lab tabs: []

$ fm-spawn.sh acct1 <proj> --mode local-only --yolo off --backend herdr --harness claude --account Claude-Second
error: claude account 'Claude-Second' is not a valid name (lowercase letters, digits, and single hyphens)
exit=1
state/acct1.meta exists: no; lab tabs: []

(config/claude-accounts: 'claude-second relative/dir')
$ fm-spawn.sh acct1 <proj> --mode local-only --yolo off --backend herdr --harness claude --account claude-second
error: claude account 'claude-second' maps to relative directory 'relative/dir'; config/claude-accounts needs an absolute path
exit=1
state/acct1.meta exists: no; lab tabs: []

(config/claude-accounts: claude-second -> missing dir)
$ fm-spawn.sh acct1 <proj> --mode local-only --yolo off --backend herdr --harness claude --account claude-second
error: claude account 'claude-second' maps to '$SCRATCH/not-signed-in', which is not an existing directory; sign that account in under it first
exit=1
state/acct1.meta exists: no; lab tabs: []

(config/claude-accounts: duplicate claude-second entry)
$ fm-spawn.sh acct1 <proj> --mode local-only --yolo off --backend herdr --harness claude --account claude-second
error: config/claude-accounts line 2: duplicate account claude-second
exit=1
state/acct1.meta exists: no; lab tabs: []
Evidence: Spawn on claude-second vs no account: meta, process env, trust stores

Source: Spawn on claude-second vs no account: meta, process env, trust stores

## Round-2: spawn a claude worker on claude-second and one with no account (live lab fm-lab-acct-r2-25675-6330)
firstmate ambient CLAUDE_CONFIG_DIR during spawn: $SCRATCH/claude-ambient
config/claude-accounts:
  # Claude accounts (scratch)
  claude-second $SCRATCH/claude-second

$ fm-spawn.sh acct1 <proj> --mode local-only --yolo off --backend herdr --harness claude --account claude-second
spawned acct1 harness=claude kind=ship mode=local-only yolo=off window=fm-lab-acct-r2-25675-6330:w3:p2 worktree=~/.treehouse/proj-2b00f3/1/proj
exit=0

$ fm-spawn.sh acct2 <proj> --mode local-only --yolo off --backend herdr --harness claude 
spawned acct2 harness=claude kind=ship mode=local-only yolo=off window=fm-lab-acct-r2-25675-6330:w4:p2 worktree=~/.treehouse/proj-2b00f3/2/proj
exit=0

## state/acct1.meta (harness/account lines)
harness=claude
model=default
effort=default
account=claude-second
backend=herdr
herdr_pane_id=w3:p2
## live claude worker process env for acct1 (cwd = task worktree)
pid 4038: CLAUDE_CONFIG_DIR=$SCRATCH/claude-second

## state/acct2.meta (harness/account lines)
harness=claude
model=default
effort=default
backend=herdr
herdr_pane_id=w4:p2
(no account= line)
## live claude worker process env for acct2 (cwd = task worktree)
pid 7331: CLAUDE_CONFIG_DIR=$SCRATCH/claude-ambient

## workspace-trust registration per store
claude-second/.claude.json projects:
{"path":"~/.treehouse/proj-2b00f3/1/proj","hasTrustDialogAccepted":true}
{"path":"$SCRATCH/proj","hasTrustDialogAccepted":true}
claude-ambient/.claude.json projects:
{"path":"~/.treehouse/proj-2b00f3/2/proj","hasTrustDialogAccepted":true}
{"path":"$SCRATCH/proj","hasTrustDialogAccepted":true}
Evidence: Relaunch account refusals leave worker running

Source: Relaunch account refusals leave worker running

## Round-2 relaunch refusals (running claude worker pid 37511 on claude-second; live lab fm-lab-acct-r2-25675-6330)
$ fm-control.sh acct1 relaunch --account claude-third --note switch account
error: task acct1 cannot relaunch on Claude account 'claude-third', which does not resolve (claude account 'claude-third' is unknown: config/claude-accounts has no entry for it); relaunching would stop the running agent for a launch that must be refused
exit=1
worker pid 37511 still running: yes; meta: account=claude-second

$ fm-control.sh acct1 relaunch --harness codex --account claude-second --note switch account
error: --account claude-second selects a Claude account and needs the claude harness, not 'codex'; relaunching would stop the running agent for a launch that must be refused
exit=1
worker pid 37511 still running: yes; meta: account=claude-second

$ fm-control.sh acct1 relaunch --account Claude-Second --note switch account
error: task acct1 cannot relaunch on Claude account 'Claude-Second', which does not resolve (claude account 'Claude-Second' is not a valid name (lowercase letters, digits, and single hyphens)); relaunching would stop the running agent for a launch that must be refused
exit=1
worker pid 37511 still running: yes; meta: account=claude-second

(config/claude-accounts: relative dir)
$ fm-control.sh acct1 relaunch --account claude-second --note switch account
error: task acct1 cannot relaunch on Claude account 'claude-second', which does not resolve (claude account 'claude-second' maps to relative directory 'relative/dir'; config/claude-accounts needs an absolute path); relaunching would stop the running agent for a launch that must be refused
exit=1
worker pid 37511 still running: yes; meta: account=claude-second

(claude-second directory moved away)
$ fm-control.sh acct1 relaunch --note keep account
error: task acct1 cannot relaunch on Claude account 'claude-second', which does not resolve (claude account 'claude-second' maps to '$SCRATCH/claude-second', which is not an existing directory; sign that account in under it first); relaunching would stop the running agent for a launch that must be refused
exit=1
worker pid 37511 still running: yes; meta: account=claude-second
Evidence: Relaunch account moves (default, back, keep, default->second)

Source: Relaunch account moves (default, back, keep, default->second)

## Round-2 relaunch account moves (live lab fm-lab-acct-r2-25675-6330)
$ fm-control.sh acct1 relaunch --account default --note claude-second hit its usage limit; move to the default account
relaunched acct1 harness=claude from=claude model=default effort=default account=default backend=herdr endpoint=fm-lab-acct-r2-25675-6330:w3:p2 worktree=~/.treehouse/proj-2b00f3/1/proj
exit=0
meta: (no account= line: default store)
replacement claude process env: pid 19606: CLAUDE_CONFIG_DIR=$SCRATCH/claude-ambient 
journal: phase=complete from_account=claude-second to_account=default 

$ fm-control.sh acct1 relaunch --account claude-second --note move back onto claude-second
relaunched acct1 harness=claude from=claude model=default effort=default account=claude-second backend=herdr endpoint=fm-lab-acct-r2-25675-6330:w3:p2 worktree=~/.treehouse/proj-2b00f3/1/proj
exit=0
meta: account=claude-second
replacement claude process env: pid 30645: CLAUDE_CONFIG_DIR=$SCRATCH/claude-second 
journal: phase=complete from_account=default to_account=claude-second 

$ fm-control.sh acct1 relaunch --note plain relaunch keeps the recorded account
relaunched acct1 harness=claude from=claude model=default effort=default account=claude-second backend=herdr endpoint=fm-lab-acct-r2-25675-6330:w3:p2 worktree=~/.treehouse/proj-2b00f3/1/proj
exit=0
meta: account=claude-second
replacement claude process env: pid 37511: CLAUDE_CONFIG_DIR=$SCRATCH/claude-second 
journal: phase=complete from_account=claude-second to_account=claude-second 

$ fm-control.sh acct2 relaunch --account claude-second --note move the default-store worker onto claude-second
relaunched acct2 harness=claude from=claude model=default effort=default account=claude-second backend=herdr endpoint=fm-lab-acct-r2-25675-6330:w4:p2 worktree=~/.treehouse/proj-2b00f3/2/proj
exit=0
meta: account=claude-second
replacement claude process env: pid 45177: CLAUDE_CONFIG_DIR=$SCRATCH/claude-second 
journal: phase=complete from_account=default to_account=claude-second 
Evidence: Unaccepted store shows Bypass Permissions dialog (documented precondition)

Source: Unaccepted store shows Bypass Permissions dialog (documented precondition)

## Documented precondition: a named store that has not accepted Bypass Permissions mode (live lab fm-lab-acct-r2-25675-6330)
claude-third store: signed-in-shaped .claude.json, NO settings.json skipDangerousModePermissionPrompt
$ fm-spawn.sh acct3 <proj> --mode local-only --yolo off --backend herdr --harness claude --account claude-third
spawned acct3 harness=claude kind=ship mode=local-only yolo=off window=fm-lab-acct-r2-25675-6330:w5:p2 worktree=~/.treehouse/proj-2b00f3/3/proj
exit=0
worker env: pid 59083: CLAUDE_CONFIG_DIR=$SCRATCH/claude-third
## acct3 pane viewport
gusfraser@Anguss-MacBook-Pro proj % treehouse get
🌳 Setting up worktree...
🌳 Entered worktree at ~/.treehouse/proj-2b00f3/3/proj. Type 'exit' to return.
gusfraser@Anguss-MacBook-Pro proj % export GOTMPDIR=/tmp/fm-acct3/gotmp
gusfraser@Anguss-MacBook-Pro proj % export COMPACT_ADVISER_DISABLE=1
gusfraser@Anguss-MacBook-Pro proj % export FM_TASK_ID=acct3
gusfraser@Anguss-MacBook-Pro proj % . '/tmp/fm-acct3+0fe8406c3ad6c306e41badc8f342f66f0d8207fddc482c8251e63de071b16538/la
unch.s1790182614.54869.12075.sh'
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
  WARNING: Claude Code running in Bypass Permissions mode
  In Bypass Permissions mode, Claude Code will not ask for your approval before running potentially dangerous
  commands.
  This mode should only be used in a sandboxed container/VM that has restricted internet access and can easily be
  restored if damaged.
  By proceeding, you accept all responsibility for actions taken while running in Bypass Permissions mode.
  https://code.claude.com/docs/en/security
  ❯ No, exit
    Yes, I accept
  Enter to confirm · Esc to cancel
Evidence: Resolver + bootstrap crew-dispatch account validation

Source: Resolver + bootstrap crew-dispatch account validation

## Round-2: crew-dispatch profile account validation through the real resolver and bootstrap (commit 055fed0)
config/claude-accounts names: claude-second claude-third 

config/crew-dispatch.json: {"rules":[{"when":"claude-second work","use":{"harness":"claude","account":"claude-second"}}]}
  $ fm-dispatch-resolve.sh (TYPESAFE_API_KEY set, curl shimmed)
  dispatch-resolve: error (http 000 after 1000 ms: )
  dispatch-resolve:
    status: error
    reason: http 000 after 1000 ms: 
  exit=0
  $ fm-bootstrap.sh (detect) CREW_DISPATCH lines:

config/crew-dispatch.json: {"rules":[{"when":"balanced claude work","use":[{"harness":"claude","account":"claude-second"},{"harness":"claude"}]}]}
  $ fm-dispatch-resolve.sh (TYPESAFE_API_KEY set, curl shimmed)
  dispatch-resolve: error (http 000 after 0 ms: )
  dispatch-resolve:
    status: error
    reason: http 000 after 0 ms: 
  exit=0
  $ fm-bootstrap.sh (detect) CREW_DISPATCH lines:

config/crew-dispatch.json: {"rules":[{"when":"claude work","use":{"harness":"claude","account":"claude-fourth"}}]}
  $ fm-dispatch-resolve.sh (TYPESAFE_API_KEY set, curl shimmed)
  error: malformed rules file: $SCRATCH/home/config/crew-dispatch.json - claude account 'claude-fourth' is unknown: config/claude-accounts has no entry for it
  exit=2
  $ fm-bootstrap.sh (detect) CREW_DISPATCH lines:
  CREW_DISPATCH: invalid config/crew-dispatch.json - claude account 'claude-fourth' is unknown: config/claude-accounts has no entry for it

config/crew-dispatch.json: {"rules":[{"when":"codex work","use":{"harness":"codex","account":"claude-second"}}]}
  $ fm-dispatch-resolve.sh (TYPESAFE_API_KEY set, curl shimmed)
  error: malformed rules file: $SCRATCH/home/config/crew-dispatch.json - each use profile account must be a non-empty string on a claude profile
  exit=2
  $ fm-bootstrap.sh (detect) CREW_DISPATCH lines:
  CREW_DISPATCH: invalid config/crew-dispatch.json - account needs harness claude: codex:claude-second

config/crew-dispatch.json: {"rules":[{"when":"claude work","use":[{"harness":"claude","account":"claude-second"},{"harness":"claude","account":"claude-second"}]}]}
  $ fm-dispatch-resolve.sh (TYPESAFE_API_KEY set, curl shimmed)
  error: malformed rules file: $SCRATCH/home/config/crew-dispatch.json - each rule use must not contain duplicate harness, model, effort, and account profiles
  exit=2
  $ fm-bootstrap.sh (detect) CREW_DISPATCH lines:

config/crew-dispatch.json: {"rules":[],"default":{"harness":"claude","account":""}}
  $ fm-dispatch-resolve.sh (TYPESAFE_API_KEY set, curl shimmed)
  error: malformed rules file: $SCRATCH/home/config/crew-dispatch.json - each default profile account must be a non-empty string on a claude profile
  exit=2
  $ fm-bootstrap.sh (detect) CREW_DISPATCH lines:
  CREW_DISPATCH: invalid config/crew-dispatch.json - profile account must be a non-empty string when present

curl invocations total: 2
- Outcome: 🔧 1 issue found → auto-fixed ✅ across 2 runs (40m7s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 2 issues found → auto-fixed ✅
  • ⚠️ bin/fm-quota-axi-lib.sh:58 - Under typed dispatch resolution, a profile that names a Claude account can never be ranked with the quota-axi installed today. quota_bound_row binds an account only to a schema-6 row whose accountKey equals the account name, and returns null under schema 5. The installed quota-axi (quota-axi --json --provider claude) reports schemaVersion: 5 and one claude row with accountKey: null. It has no multi-Claude-account snapshot; a second store can only be read separately with CLAUDE_CONFIG_DIR=&lt;dir&gt; quota-axi --profile-only. So in the user's setup: (a) a quota-balanced array such as [{claude, account: claude-second}, {claude}] always resolves clear to the default account whenever the default row is measured, and the second subscription is never chosen, which is exactly what the new test at tests/fm-dispatch-resolve.test.sh asserts; (b) a rule whose only profile is claude@claude-second always escalates with 'no rankable eligible candidate' and falls back to manual intake. Refusing to borrow the default row is correct. The gap is that the second subscription is never measured, so quota-balanced routing across the two Claude accounts cannot work on the typed path. The remedy would be measuring each configured account, for example by running quota-axi --profile-only once per config/claude-accounts entry and merging the rows. That adds new snapshot-collection machinery beyond the stated intent, so the remedy, not the defect, is what needs authorization. Alternatively, document the limitation explicitly for the typed path.
  • ℹ️ bin/fm-spawn.sh:797 - A relaunch can keep or drop a Claude account but cannot change it. fm-spawn --relaunch refuses --account (line 797), and fm-control relaunch has no --account option. A relaunch that stays on claude always reuses the recorded account (line 2283), and fm-control refuses before the stop if that account no longer resolves (bin/fm-control.sh:851). Common case: a worker on claude-second hits that subscription's usage limit. The natural recovery, relaunching onto the default Claude account, is impossible; the only way off the account is switching to another harness entirely. The design is deliberate and the intent does not require it, so this is for the author to confirm. Remedy if wanted: let a claude relaunch take an explicit account override, including an explicit 'no account'.

🔧 Fix applied.
✅ Re-checked - no issues remain.

🔧 **Test** - 1 issue found → auto-fixed ✅
  • ⚠️ docs/configuration.md:401 - Workers launch with --dangerously-skip-permissions. If the selected account's Claude store has never accepted Bypass Permissions mode (no skipDangerousModePermissionPrompt in &lt;dir&gt;/settings.json), Claude shows the Bypass Permissions warning with the cursor on 'No, exit'. Firstmate cannot answer that dialog. Seen live in the lab: fm-spawn.sh … --account claude-second still printed 'spawned' while the worker sat on the dialog (evidence 02). A follow-up fm-control.sh relaunch --account default then failed with a misleading 'composer visibly holds pending text' error and left the task with no running agent (evidence 04a). Adding settings.json {&#34;skipDangerousModePermissionPrompt&#34;:true} to the store removed the dialog, and every later relaunch succeeded. So the cause is per-store, not machine-wide as docs/verification/runtime-backends.md:461 suggests. That doc dismissed the gate because 'a normal environment has already accepted it'; this change makes a second, separate store a normal production path. The user's real ~/.claude-second (checked read-only, key names only) is signed in (oauthAccount) but has no settings.json, so the first real dispatch onto claude-second would likely wedge. The 'Claude accounts' section of docs/configuration.md says only that the account must be signed in. Possible remedies, for the author to choose: document the precondition (run CLAUDE_CONFIG_DIR=&lt;dir&gt; claude --dangerously-skip-permissions once and accept, or set skipDangerousModePermissionPrompt in that store), and/or have bootstrap or spawn flag an account store that has not accepted it.
  • Live validation: ✅ go - 6 of 9 scenarios driven live against the product
Scenario Result Live Evidence
Operator spawns a claude worker with --account claude-second while firstmate itself runs on another store; the worker process runs with CLAUDE_CONFIG_DIR=<claude-second dir>, meta records account=clau… ✅ pass live 02-spawn-claude-second.txt
Adversarial: spawn with an unknown, invalid or reserved account name, a non-claude harness, or a relative or missing account directory is refused before any Herdr tab or task meta exists ✅ pass live 01-spawn-refusals.txt
Worker on claude-second hits its limit; fm-control relaunch --account default moves it to the default (ambient) store, drops account= from meta, and the journal records from_account=claude-second to… ✅ pass live 04-relaunch-to-default.txt
fm-control relaunch --account claude-second moves a default-store worker onto claude-second, and a plain relaunch keeps the recorded account ✅ pass live 05-relaunch-to-second-and-keep.txt
Adversarial: relaunch with an unknown or invalid account, --account on a codex target, or a recorded account whose directory vanished is refused before the running worker is stopped ✅ pass live 03-relaunch-refusals.txt
Adversarial: typed resolver rejects crew-dispatch rules with an unknown account, an account on a non-claude profile, duplicate account profiles, or an empty account, before any network call ✅ pass live 06-dispatch-resolve-account-validation.txt
Typed resolver resolves a rule and emits profile: --harness claude … --account claude-second for fm-spawn ⏸️ untested no Needs a real TYPESAFE_API_KEY and an outbound call to api.typesafe.ai (System One/Jev). Neither was available here, and sending a placeholder key to an external service was avoided. Provide the key in…
Bootstrap validates crew-dispatch.json account profiles against config/claude-accounts and prints the account in its verbose dispatch facts ⏸️ untested no Real bin/fm-bootstrap.sh performs tool installs, fleet sync and secondmate sweeps, which the workspace boundary forbids outside a fake toolchain. The hermetic test drives the real script with a faked…
A worker dispatched to a freshly signed-in second-account store reaches its brief without an unanswerable dialog ⏸️ untested no Proving this on the user's real ~/.claude-second would mean launching against production credentials, which is forbidden. With a scratch store in the same state (no skipDangerousModePermissionPrompt),…
  • bin/fm-herdr-lab.sh name acct-select + provision / teardown fm-lab-acct-select-21198-10115 (guarded lab lifecycle; the default-session tripwire matched at teardown)
  • fm-spawn.sh acct0 &lt;proj&gt; --mode local-only --yolo off --backend herdr --harness claude --account {claude-third,default,Claude-Second} and --harness codex --account claude-second, plus relative-dir and missing-dir config/claude-accounts (all refused; no tab or meta created)
  • fm-spawn.sh acct1 &lt;proj&gt; --mode local-only --yolo off --backend herdr --harness claude --account claude-second with ambient CLAUDE_CONFIG_DIR set to a different scratch store; checked the live worker's env with herdr pane process-info + ps eww, the task meta, and the .claude.json trust entries in both stores
  • fm-control.sh acct1 relaunch --account claude-third | --harness codex --account claude-second | --account Claude-Second, plus a plain relaunch after removing the account dir (all refused before the stop; worker pid still alive)
  • fm-control.sh acct1 relaunch --account default (first attempt blocked by the per-store Bypass Permissions dialog; succeeded after the store accepted bypass mode), then --account claude-second, then a plain relaunch; checked worker env, meta and the acct1.control-relaunch journal each time
  • fm-dispatch-resolve.sh &lt;brief&gt; --project proj with rules naming an unknown account, an account on codex, duplicate account profiles and an empty account (a dummy key reached only the pre-network validation; curl was shimmed and never called)
  • bash tests/fm-dispatch-resolve.test.sh, bash tests/fm-control-relaunch.test.sh, bash tests/fm-spawn-dispatch-profile.test.sh, bash tests/fm-bootstrap.test.sh (targeted to this change: 189 ok, 0 not ok)

🔧 Fix applied.
✅ Re-checked - no issues remain.

  • Live validation: ✅ go - 7 of 8 scenarios driven live against the product
Scenario Result Live Evidence
Operator spawns a Claude crewmate with --account claude-second: the live claude process runs with CLAUDE_CONFIG_DIR=<claude-second dir>, meta records account=claude-second, and workspace trust is writ… ✅ pass live r2-02-spawn-second-and-default.txt
Spawn with no account still inherits Firstmate's ambient CLAUDE_CONFIG_DIR and records no account ✅ pass live r2-02-spawn-second-and-default.txt
Adversarial: unknown, reserved 'default', invalid-case, non-claude harness, relative dir, missing dir, and duplicate entry are each refused with exit 1 before any task record or lab tab exists ✅ pass live r2-01-spawn-refusals.txt
Relaunch --account default moves a claude-second worker to the default store; --account claude-second moves it back; a plain relaunch keeps the recorded account; a default worker moves onto claude-sec… ✅ pass live r2-04-relaunch-account-moves.txt
Adversarial: a relaunch with an unknown, invalid, relative-dir, or missing-dir account, or with codex plus an account, is refused before the running worker is stopped ✅ pass live r2-03-relaunch-refusals.txt
Crew-dispatch profile 'account' is validated: valid claude accounts pass the resolver and bootstrap; an unknown account, an account on codex, an empty account, and duplicate profiles are refused (reso… ✅ pass live r2-06-dispatch-rule-account-validation.txt
A clear typed resolution emits a profile line containing --account claude-second ⏸️ untested no A real clear answer needs a live typesafe.ai TYPESAFE_API_KEY and a schema-6 quota-axi row for the account. Neither was available, and the installed quota-axi is single-account by the documented limit…
Documented precondition: a named store that has not accepted Bypass Permissions parks the worker on the dialog with 'No, exit' selected ✅ pass live r2-05-unaccepted-store-bypass-dialog.txt
  • bin/fm-herdr-lab.sh provision fm-lab-acct-r2-25675-6330 … teardown (a throwaway lab; the default session was untouched afterwards)
  • fm-spawn.sh acct1 &lt;proj&gt; --mode local-only --yolo off --backend herdr --harness claude --account &lt;claude-third|default|Claude-Second&gt;, --harness codex --account claude-second, and claude-accounts files with a relative dir, a missing dir, and a duplicate entry (7 refusals)
  • fm-spawn.sh acct1 … --harness claude --account claude-second and fm-spawn.sh acct2 … --harness claude (no account); checked task meta, ps eww CLAUDE_CONFIG_DIR of the live claude process, and each store's .claude.json trust entries
  • fm-control.sh acct1 relaunch --account &lt;claude-third|Claude-Second&gt;, --harness codex --account claude-second, a relative-dir config, and the account directory removed; checked the worker pid is still alive and meta unchanged after each
  • fm-control.sh acct1 relaunch --account default, then --account claude-second, then a plain relaunch; fm-control.sh acct2 relaunch --account claude-second; checked meta, the replacement process env, and the control-relaunch journal
  • fm-spawn.sh acct3 … --account claude-third, a store with no skipDangerousModePermissionPrompt; captured the pane viewport
  • fm-dispatch-resolve.sh &lt;brief&gt; --project proj with TYPESAFE_API_KEY set and curl shimmed, plus fm-bootstrap.sh detect, against 6 crew-dispatch.json variants
  • bash tests/fm-dispatch-resolve.test.sh (passed)
  • bash tests/fm-control-relaunch.test.sh (passed)
  • bash tests/fm-bootstrap.test.sh (passed)
  • bash tests/fm-spawn-dispatch-profile.test.sh (passed)
✅ **Document** - passed

✅ No issues found.

⚠️ **Lint** - 1 warning
  • ⚠️ linter found issues (exit code 1)
✅ **Push** - passed

✅ No issues found.

A dispatch profile can now name an account from config/claude-accounts,
and fm-spawn --account launches that Claude worker with the account's
CLAUDE_CONFIG_DIR and registers workspace trust in the same store. The
account is recorded in task meta and reused on relaunch, validated by
bootstrap and the typed resolver, and bound only to its own quota-axi
accountKey row.
@max-metaplanet

Copy link
Copy Markdown
Contributor

A design question affecting this PR's account-file inheritance has been opened: #5481

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants