Skip to content

feat: add Claude quota recommendations and redacted chat exports - #6

Merged
earljman merged 10 commits into
mainfrom
fm/air-commits-to-fork
Oct 12, 2026
Merged

earljman merged 10 commits into
mainfrom
fm/air-commits-to-fork

Conversation

@earljman

@earljman earljman commented Oct 12, 2026 •

Copy link
Copy Markdown
Owner

Intent

Set up a PR so that firstmate commits which currently exist only on the TeohCap Air MacBook land on the earljman/firstmate fork, so all four firstmate machines (Mini, TeohCap Air, Pel Dev Crew, Pel Infra Crew) run the same code.

Context: the Air's firstmate checkout (~/Documents/firstmate, branch main, reachable over SSH as host alias macbook-firstmate) carries 8 commits that are on neither the fork nor upstream, on top of fork merge base 910889a. It has since merged the fork's main (88b956b) on top. The 8 commits:

  • 31280ed feat: add Claude account quota switching watch
  • d51d672 feat: export local agent transcripts with secret redaction
  • dac73a5 fix: tolerate repeated Claude events and isolate corrupt sessions
  • 3c3be65 fix(bin): retire pending launch-failed episodes when later owned
  • 4287197 test(bin): give older-main launch-failed coverage room to settle
  • be2811c docs: apply fork files verbatim to Group A preservation candidate
  • 6a4f73b docs: restore quota profiles and delayed launch-failure contract
  • a815c01 fix(bin): default BASHPID so bounded execution works on Bash 3.2 (an independent copy of the fork's already-merged fix(bin): default BASHPID so bounded execution works on Bash 3.2 #2 / 662d45e)

What Changed

  • Add a Claude account quota command that reads primary and fallback profiles, reports their quota status, and recommends an account for future launches.
  • Add a local chat exporter for Claude Code, Codex, Cursor, Grok CLI, and Pi logs, with secret redaction, JSONL output, and a per-machine manifest. Repeated Claude events are handled, and corrupt session files are skipped individually.
  • Delay process-event launch-failure wakes until a later failed cycle, retire pending episodes when the source becomes owned, and correct Claude trust handling for linked worktrees on case-insensitive filesystems.

Risk Assessment

🚨 High: The new export can persist unredacted session credentials in its published JSONL files, so it should be fixed before merge.

Testing

The exporter, quota selector, trust command, and real process event runner passed targeted live checks in disposable environments. An initial runner-suite attempt stopped because the host lacks setsid; the complete rerun passed with a temporary workspace-local replacement. CLI output and persisted verdict evidence were captured, the replacement was removed, and no source changes remain.

  • Live validation: ✅ go - 5 of 5 scenarios driven live against the product
Scenario Result Live Evidence
An operator exports local agent transcripts; published turns retain useful content while credential headers and secrets are redacted. ✅ pass live live-cli-export-quota.json; bash tests/fm-chat-export.test.sh
An operator exports transcripts containing duplicate Claude events and corrupt sessions; valid sessions publish and corrupt sessions are isolated. ✅ pass live bash tests/fm-chat-export.test.sh
An operator checks Claude account quota; an unchanged verdict stays quiet, a depleted primary selects the fallback, and unmeasured quota is not recommended. ✅ pass live live-cli-export-quota.json; bash tests/fm-claude-account-quota.test.sh
A Claude task trusts its legitimate worktree while out-of-scope paths are refused. ✅ pass live bash tests/fm-claude-trust.test.sh
A process event launch that remains unclaimed raises one durable wake, while a slow launch that becomes owned raises none. ✅ pass live PATH="$PWD/.test-bin:$PATH" bash tests/fm-procevent.test.sh
Evidence: Live exporter and quota CLI output

Source: Live exporter and quota CLI output

{
  "export_command": "bin/fm-chat-export.sh --source codex --root codex=<disposable fixture> --output <disposable output>",
  "exported_turn": {
    "source": "codex",
    "session_id": "sample",
    "project": "/var/folders/tq/dm9fr_l14n52q_k9mv4fqm_m0000gn/T/fm-live-cli-7oph592c/codex",
    "timestamp": "2026-01-02T12:00:00.000000Z",
    "role": "tool",
    "content": {
      "type": "function_call_output",
      "output": "visible result\nAuthorization: [REDACTED:credential]\nX-API-Key: [REDACTED:credential]\nX-Request-Id: request-42"
    },
    "tool_name": null,
    "tool_input": null,
    "tool_output": "visible result\nAuthorization: [REDACTED:credential]\nX-API-Key: [REDACTED:credential]\nX-Request-Id: request-42",
    "raw_type": "response_item:function_call_output"
  },
  "manifest_sources": {
    "codex": {
      "files": 1,
      "sessions": 1,
      "turns": 1,
      "inferred_timestamps": 0,
      "duplicate_uuids": 0,
      "duplicate_uuids_by_session": {},
      "skipped_sessions": 0,
      "skipped_session_details": [],
      "exported_sessions": 1,
      "date_range": {
        "start": "2026-01-02T12:00:00.000000Z",
        "end": "2026-01-02T12:00:00.000000Z"
      }
    }
  },
  "quota_check_initial": "SWITCH VERDICT recommendedAccount=primary CLAUDE_CONFIG_DIR=unset triggeringScope=none reason=primary_within_threshold",
  "quota_check_unchanged": "",
  "quota_check_after_primary_reaches_20_percent": "SWITCH VERDICT recommendedAccount=fallback CLAUDE_CONFIG_DIR=/var/folders/tq/dm9fr_l14n52q_k9mv4fqm_m0000gn/T/fm-live-cli-7oph592c/fallback triggeringScope=session reason=primary_threshold_reached",
  "quota_persisted_verdict": {
    "recommendedAccount": "fallback",
    "claudeConfigDir": "/var/folders/tq/dm9fr_l14n52q_k9mv4fqm_m0000gn/T/fm-live-cli-7oph592c/fallback",
    "triggeringScope": "session",
    "reason": "primary_threshold_reached"
  }
}

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 4 issues (2 errors, 2 warnings)
  • 🚨 bin/fm-chat-export.py:234 - The transcript export can publish credentials unchanged. A tool result containing Authorization: Basic dXNlcjpwYXNz or Cookie: session=abc123 passes through Scrubber.text() because neither header matches its patterns; nested Authorization and Cookie fields also pass through the key check at bin/fm-chat-export.py:293. content, tool_input, and tool_output are then written to the source JSONL and all.jsonl at bin/fm-chat-export.py:589-618. Redact these credential headers in both text and structured fields before publication.

🔧 Fix applied.
2 errors still open:

  • 🚨 bin/fm-chat-export.py:234 - The transcript export can publish credentials unchanged. A tool result containing Authorization: Basic dXNlcjpwYXNz or Cookie: session=abc123 passes through Scrubber.text() because neither header matches its patterns; nested Authorization and Cookie fields also pass through the key check at bin/fm-chat-export.py:293. content, tool_input, and tool_output are then written to the source JSONL and all.jsonl at bin/fm-chat-export.py:589-618. Redact these credential headers in both text and structured fields before publication.
  • 🚨 bin/fm-chat-export.py:250 - The round 1 credential-header fix left raw X-API-Key: and X-Auth-Token: headers unredacted. A tool result containing either header with a credential absent from scanned .env files passes through Scrubber.text() unchanged and is published in the source JSONL and all.jsonl at bin/fm-chat-export.py:594 and bin/fm-chat-export.py:615-620. Extend header redaction to these credential-bearing headers.

🔧 Fix applied.
4 issues (2 errors, 2 warnings) still open:

  • 🚨 bin/fm-chat-export.py:234 - The transcript export can publish credentials unchanged. A tool result containing Authorization: Basic dXNlcjpwYXNz or Cookie: session=abc123 passes through Scrubber.text() because neither header matches its patterns; nested Authorization and Cookie fields also pass through the key check at bin/fm-chat-export.py:293. content, tool_input, and tool_output are then written to the source JSONL and all.jsonl at bin/fm-chat-export.py:589-618. Redact these credential headers in both text and structured fields before publication.
  • 🚨 bin/fm-chat-export.py:250 - The round 1 credential-header fix left raw X-API-Key: and X-Auth-Token: headers unredacted. A tool result containing either header with a credential absent from scanned .env files passes through Scrubber.text() unchanged and is published in the source JSONL and all.jsonl at bin/fm-chat-export.py:594 and bin/fm-chat-export.py:615-620. Extend header redaction to these credential-bearing headers.
  • ⚠️ bin/fm-claude-account-quota.sh:141 - A schema-5 Claude response with numeric five_hour and seven_day windows is marked available even when quotaSemantics.status is unknown or state.status is stale. The verdict at bin/fm-claude-account-quota.sh:195 can then recommend that account with 80% remaining despite the provider saying its quota is unmeasured. Validate those status fields and both percentRemaining values before treating a profile as readable.
  • ⚠️ bin/fm-chat-export.py:525 - If a Claude file contains duplicate UUIDs and is later skipped for a corrupt record or cyclic tree, ingest rolls back its turns but still adds its duplicate count to the manifest. Move the duplicate accounting into the successful-file branch so skipped sessions cannot inflate duplicate_uuids or duplicate_uuids_by_session.

🔧 Fix applied.
4 issues (2 errors, 2 warnings) still open:

  • 🚨 bin/fm-chat-export.py:234 - The transcript export can publish credentials unchanged. A tool result containing Authorization: Basic dXNlcjpwYXNz or Cookie: session=abc123 passes through Scrubber.text() because neither header matches its patterns; nested Authorization and Cookie fields also pass through the key check at bin/fm-chat-export.py:293. content, tool_input, and tool_output are then written to the source JSONL and all.jsonl at bin/fm-chat-export.py:589-618. Redact these credential headers in both text and structured fields before publication.
  • 🚨 bin/fm-chat-export.py:250 - The round 1 credential-header fix left raw X-API-Key: and X-Auth-Token: headers unredacted. A tool result containing either header with a credential absent from scanned .env files passes through Scrubber.text() unchanged and is published in the source JSONL and all.jsonl at bin/fm-chat-export.py:594 and bin/fm-chat-export.py:615-620. Extend header redaction to these credential-bearing headers.
  • ⚠️ bin/fm-chat-export.py:525 - If a Claude file contains duplicate UUIDs and is later skipped for a corrupt record or cyclic tree, ingest rolls back its turns but still adds its duplicate count to the manifest. Move the duplicate accounting into the successful-file branch so skipped sessions cannot inflate duplicate_uuids or duplicate_uuids_by_session.
  • ⚠️ bin/fm-chat-export.py:116 - A Cursor agent-tools result containing invalid UTF-8 raises UnicodeDecodeError at line 116. The skip handler at bin/fm-chat-export.py:504 does not catch it, so one corrupt artifact aborts the entire export instead of being recorded as a skipped file. Convert decoding failures to a skippable session error at the artifact reader boundary.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 5 of 5 scenarios driven live against the product
Scenario Result Live Evidence
An operator exports local agent transcripts; published turns retain useful content while credential headers and secrets are redacted. ✅ pass live live-cli-export-quota.json; bash tests/fm-chat-export.test.sh
An operator exports transcripts containing duplicate Claude events and corrupt sessions; valid sessions publish and corrupt sessions are isolated. ✅ pass live bash tests/fm-chat-export.test.sh
An operator checks Claude account quota; an unchanged verdict stays quiet, a depleted primary selects the fallback, and unmeasured quota is not recommended. ✅ pass live live-cli-export-quota.json; bash tests/fm-claude-account-quota.test.sh
A Claude task trusts its legitimate worktree while out-of-scope paths are refused. ✅ pass live bash tests/fm-claude-trust.test.sh
A process event launch that remains unclaimed raises one durable wake, while a slow launch that becomes owned raises none. ✅ pass live PATH=&#34;$PWD/.test-bin:$PATH&#34; bash tests/fm-procevent.test.sh
  • bash tests/fm-chat-export.test.sh
  • bash tests/fm-claude-account-quota.test.sh
  • bash tests/fm-claude-trust.test.sh
  • bash tests/fm-procevent.test.sh (initial run stopped at a fixture requiring unavailable setsid)
  • PATH=&#34;$PWD/.test-bin:$PATH&#34; bash tests/fm-procevent.test.sh (workspace-local setsid shim; passed)
  • Manual disposable-home CLI export and quota checks recorded in live-cli-export-quota.json
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Air commit reconciliation

Landed unchanged in effect (cherry-picked in order, authorship preserved):

  • 31280ed feat: add Claude account quota switching watch (AGENTS.md conflict resolved by keeping the fork's operational-home-layout skill and adding the config/claude-account-profiles line there; both config sections kept in docs/configuration.md)
  • d51d672 feat: export local agent transcripts with secret redaction
  • dac73a5 fix: tolerate repeated Claude events and isolate corrupt sessions
  • 4287197 test(bin): give older-main launch-failed coverage room to settle

Adapted:

  • 3c3be65 fix(bin): retire pending launch-failed episodes when later owned. Code and tests applied cleanly; the fork had since restructured the launch-failure docs, so the delayed-announcement wording was re-applied to the fork's current text in docs/configuration.md and docs/verification/process-event-sources.md.
  • 6a4f73b docs: restore quota profiles and delayed launch-failure contract. Reduced to one docs commit that states the unreadable-profile behavior of the quota script (already true in bin/fm-claude-account-quota.sh). Its extra AGENTS.md line was dropped because the layout skill already carries that fact, and its launch-failure wording is covered by the 3c3be65 adaptation.

Dropped:

Pipeline review also fixed credential-header redaction in the transcript export (Authorization, Cookie, X-API-Key, X-Auth-Token and similar) and made the quota script refuse to recommend an account whose quota is unmeasured. Two low-severity review warnings were left unfixed: skipped sessions can inflate duplicate-UUID counts in the export manifest, and one invalid-UTF-8 Cursor artifact aborts the whole export instead of being skipped.

Known failures not caused by this PR

  • ci-1, "Behavior portable serial 2": tests/fm-calm-pi-extension.test.sh fails with grep disappeared from /export calm.html HTML while calm mode was on. CI installs the newest @earendil-works/pi-coding-agent, now 1.1.0. This PR touches no Pi or Calm code. Evidence it is pre-existing: re-running the CI run for main at 88b956b (run 36690637566, attempt 2) installed Pi 1.1.0 and failed the identical assertion in the same shard. Main's earlier green runs used Pi 0.99.1. Fixing Pi 1.1 compatibility is out of scope here.
  • Separately, main's original run for fix: bound remote supervision calls to keep the watcher responsive #3 was red on "Behavior portable serial 7" (the replacement did not finish its own TERM shutdown in the process-event tests), a different failure.
  • tests/fm-procevent.test.sh "could not read the draining holder's identity" fails on macOS because setsid is not installed. The test file calls setsid on main too (tests/fm-procevent.test.sh line 4618 at 88b956b) and this PR changes no setsid line in it, so it is pre-existing and environmental. I did not re-run that test on a clean main.

pm-justinm and others added 10 commits October 13, 2026 02:19
A slow remote-reply claim can miss the 3s confirm window and then own the
source, so announcing on the first miss re-fired every relaunch. Record the
episode first and publish the wake only if a later cycle still cannot
confirm, so a later-owned source stays silent and a dead one still alarms.
The extra pending cycle and this machine's load made the repaired confirm
and the stale-claim race miss their original short waits, so give those
two assertions the same 300-tick race bound and a bounded repair retry.

Co-authored-by: Cursor <[email protected]>
@earljman
earljman merged commit 5643c8e into main Oct 12, 2026
19 of 20 checks passed
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