Skip to content

feat(formula): add format command for readable TOML diffs#576

Closed
easel wants to merge 38 commits intogastownhall:mainfrom
easel:polecat/formula-format
Closed

feat(formula): add format command for readable TOML diffs#576
easel wants to merge 38 commits intogastownhall:mainfrom
easel:polecat/formula-format

Conversation

@easel
Copy link
Copy Markdown
Contributor

@easel easel commented Jan 16, 2026

Summary

  • Add gt formula format command that converts single-line strings with \n escapes to proper TOML multi-line strings
  • Makes PR diffs for formula files readable (addresses the issue seen in PR fix(formulas): witness patrol deacon check for town-level service #561)
  • Includes --check, --write, and --diff flags
  • Property-based testing with pgregory.net/rapid ensures 100% round-trip accuracy
  • PostToolUse hook auto-formats .formula.toml files after Edit/Write operations

Test plan

  • All unit tests pass
  • Property-based tests pass (100 iterations for round-trip, idempotency, non-string preservation)
  • gofmt and go vet pass
  • Manual test: gt formula format internal/formula/formulas/mol-witness-patrol.formula.toml produces valid TOML
  • Test hook by editing a .formula.toml file in Claude Code

🤖 Generated with Claude Code

@easel easel marked this pull request as ready for review January 16, 2026 03:34
@easel easel force-pushed the polecat/formula-format branch 6 times, most recently from 2b03840 to 3c4d50c Compare January 26, 2026 05:09
@easel easel force-pushed the polecat/formula-format branch 5 times, most recently from 863ad94 to 9d5ec65 Compare February 1, 2026 03:41
easel and others added 18 commits February 1, 2026 14:10
1. Fix mol-witness-patrol.formula.toml TOML syntax error
   - Convert multi-line descriptions to use triple-quoted strings
   - Fixes TestParallelReadySteps test failure

2. Add Windows build support for tmux package
   - Extract syscall.Kill calls to platform-specific signal_unix.go
   - Add no-op signal_windows.go stub (tmux not available on Windows)
   - Fixes Windows CI build failure

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Explicitly ignore error returns from logFile.Close() calls
- Add nolint directive for stopLocked's always-nil error return
- Regenerate embedded formula files to match source

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Fix lint errors: errcheck for Sscanf, gosec for Close/Remove
- Add nolint:unparam for parseValue (error kept for future)
- Add BuiltProperly ldflags to test helper
- Skip Windows tests for process groups and concurrent atomic writes
- Regenerate formula files to sync with .beads/formulas

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Update role_e2e_test.go for compound GT_ROLE format
- Add normalizeRuntimeConfig call for built-in presets in lookupAgentConfig
- Fix dog_test.go to use filepath.FromSlash for cross-platform paths
- Skip Windows tests with file I/O timing issues

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1. Fix mol-witness-patrol.formula.toml TOML syntax error
   - Convert multi-line descriptions to use triple-quoted strings
   - Fixes TestParallelReadySteps test failure

2. Add Windows build support for tmux package
   - Extract syscall.Kill calls to platform-specific signal_unix.go
   - Add no-op signal_windows.go stub (tmux not available on Windows)
   - Fixes Windows CI build failure

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add e2e tests that verify gt install creates a functional system:
- TestInstallDoctorClean: verifies structure, rig/crew add, commands
- TestInstallWithDaemon: extends above with daemon lifecycle testing

Tests run in isolated Docker container for reproducibility.

Includes:
- Dockerfile.e2e for test container
- Makefile targets: test-e2e, test-e2e-container
- GitHub Actions workflow for CI

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Implements two new commands for managing Gas Town processes:

1. gt ps - List all tmux sessions with process information
   - Shows session names, status (alive/dead), commands, PIDs
   - Displays work-on-hook status for polecats
   - Supports --json and --verbose flags
   - Highlights Gas Town sessions

2. gt cleanup - Manage orphaned processes and sessions
   - cleanup orphans: Find work assigned to dead agents
   - cleanup sessions: Clean up dead/zombie tmux sessions
   - cleanup stale: Clean up stale polecats (wraps gt polecat stale)
   - Supports --dry-run flag for safe inspection

Both commands integrate with existing daemon orphan detection logic
and provide manual inspection/triggering of cleanup operations.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Remove --force flag from cleanup sessions command that was declared but never used
- Fix extractRigFromAgentID to handle rig names with hyphens by finding the "-polecat-" delimiter
- Fix extractPolecatNameFromAgentID to handle polecat names with hyphens by taking everything after "-polecat-"

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Revert beads_test.go changes from contrib/process-management that
removed t.Skip() from tests documenting a bd CLI 0.47.2 bug. The
tests cannot pass until the bd CLI issue is resolved, so they need
to remain skipped.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
These tests require tmux and bd which are not available on Windows CI.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Instead of skipping tests on Windows, provide Windows batch script
equivalents for the mock tmux, bd, pgrep, and gt commands.

Update writeScript() helper to accept both Unix and Windows scripts
and write the appropriate one based on runtime.GOOS.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The TestRunPSJSONIncludesAgentDetails and TestCleanupOrphansDryRunReports
tests require complex tmux mocking with argument parsing and loops that
don't translate well to Windows batch scripts. Skip these on Windows
while keeping simpler tests cross-platform.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
easel and others added 20 commits February 1, 2026 14:10
Add `gt formula format` command that converts single-line strings with
\n escapes to proper TOML multi-line strings, making PR diffs readable.

Features:
- --check: Exit 1 if formatting needed (for CI)
- --write: Modify files in-place
- --diff: Show unified diff of changes

Includes property-based testing with pgregory.net/rapid for 100%
round-trip accuracy on arbitrary valid strings.

Also adds PostToolUse hook to auto-format .formula.toml files after
Edit/Write operations.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add WorkDir field to AgentEnvConfig that enables automatic detection of
beads redirects. When a redirect file exists in WorkDir/.beads/redirect,
BEADS_SYNC_BRANCH is set to "" to suppress the "Redirect active...
skipping sync-branch operations" warning.

This consolidates redirect detection into internal/config/env.go,
eliminating the need for callers to import the beads package or
manually check for redirects. Callsites simply pass their working
directory and the config package handles the rest.

The fix only activates when a redirect is actually present, avoiding
false positives for standalone crew/polecat workspaces without redirects.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add `gt epic` command for managing upstream contributions with:

- Epic lifecycle: start → ready → sling → review → submit
- CONTRIBUTING.md discovery and context injection
- Plan parsing using molecule step format
- Subtask creation with dependency tracking
- Stacked PR creation with dependency-aware base targeting
- PR lifecycle management (status, check, sync, respond, resolve)
- Crew member onboarding for planning sessions
- Worker dispatch with --workers flag support

New files:
- internal/epic/contributing.go - CONTRIBUTING.md discovery
- internal/epic/upstream.go - PR types and dependency graph
- internal/epic/sync.go - Rebase and conflict detection
- internal/beads/beads_epic.go - Epic state helpers
- internal/cmd/epic*.go - All epic subcommands

Also modifies:
- sling.go: Add --workers flag for batch dispatch
- prime_output.go: Inject CONTRIBUTING.md for epics
- mayor.md.tmpl: Add epic detection guidance

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add comprehensive test infrastructure for the refinery's DAG-based
branch management workflow. Includes:

- BranchDAG and BranchNode data structures for tracking dependencies
- TopologicalOrder for cascade rebase ordering
- AgentSignaler interface for mocking agent notifications
- TestRepo helpers for creating isolated git repositories in tests
- 37 unit tests and 8 integration tests covering:
  - Linear stack rebases
  - Conflict detection
  - Diamond dependencies
  - Fork workflow (upstream + local PRs)
  - Full workflow orchestration

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add 93 tests covering epic upstream workflow functionality:

- internal/epic/sync_test.go (39 tests):
  - Git operations: FetchUpstream, CheckConflicts, RebaseBranch
  - Force push, conflict file detection
  - Helper functions: getCurrentBranch, countCommits
  - CI/PR status structures

- internal/cmd/epic_test.go (54 tests):
  - Helper functions: sanitizeForBranch, extractStepRef, detectRole
  - State transitions validation
  - PR URL parsing, dependency graph building
  - Crew member detection and listing
  - Plan parsing integration

Bug fix:
- extractStepRef: Fix case-insensitive step prefix extraction

Coverage improvements:
- internal/epic: 36.3% → 79.2%
- Added tests for previously untested sync.go operations

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add interface-based dependency injection for gh CLI operations:
- GHClient interface with GetPRChecks and GetPRReviews methods
- RealGHClient implementation using actual gh CLI
- StubGHClient for testing with configurable responses
- Comprehensive tests achieving 92% coverage

This enables testing CI status and review status logic without
requiring actual GitHub API calls.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add CLI commands to manage stacked PR dependencies:
- gt stack set <base-branch>: Register current branch as depending on another
- gt stack list: Show the PR dependency DAG with status
- gt stack sync: Rebase all dependent PRs when base updates
- gt stack clear: Remove dependency tracking for current branch

Changes:
- Add DependsOn field to MRFields for tracking PR dependencies
- Create internal/cmd/pr_stack.go with stack subcommands
- Wire up DAGOrchestrator for automated rebase coordination

This enables proper stacked PR workflows where:
1. PRs can declare dependencies on other PRs
2. The refinery can merge in correct order
3. Rebases cascade automatically when base branches update

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Engineer now initializes DAGOrchestrator and loads DAG state
- ListReadyMRs filters out MRs whose dependencies haven't merged
- HandleMRInfoSuccess notifies DAG when branch merges, retargeting dependents
- mq_submit auto-registers branches in DAG with target-based dependencies
- TestRepo now uses 'main' as default branch for consistent testing

Adds comprehensive tests for:
- Dependency filtering logic (blocks MRs with unmerged deps)
- Merge notification cascade (retargets and signals dependents)
- Auto-registration logic (target determines dependency)
- MRFields DependsOn parsing integration

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add .gt/rig.toml manifest file support for standardizing rig setup:

- Parse and apply manifest defaults during gt rig add
- Fork detection and upstream/origin remote configuration
- Crew presets with agent, model, and account support
- gt rig update command for checking/pulling updates
- Setup command execution from manifest

The manifest enables one-liner rig installation with automatic
crew workspace creation and proper remote configuration.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Run go generate ./... to synchronize embedded formulas with source.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Remove unused error return from runAllowFailure, getConflictFiles,
  AbortRebase, and AbortMerge (unparam lint)
- Explicitly ignore os.RemoveAll errors in test helpers (errcheck lint)
- Update GitOperations interface to match implementation

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@easel easel force-pushed the polecat/formula-format branch from 9d5ec65 to 75ce1fb Compare February 1, 2026 19:20
@julianknutsen
Copy link
Copy Markdown
Collaborator

Thanks for the extensive work here, @easel! There's clearly a lot of thought and effort in this branch — the formula format command, epic workflow, stack management, DAG tracking, and more.

Unfortunately this PR has accumulated many unrelated features onto a single branch (37 commits across 114 files covering 7+ distinct features), which makes it very difficult to review, test, or merge safely. The codebase has also evolved significantly since January, so most of these changes would have substantial merge conflicts with current main.

We're closing this for now, but if you feel any of these features are still relevant, we'd welcome them as individual, focused PRs against the latest main:

  • gt formula format — the core feature described in this PR. Could be a clean, self-contained PR.
  • gt ps / gt cleanup — some of this functionality now exists upstream (cleanup.go), but there may be gaps worth filling.
  • gt epic — interesting concept that would benefit from an issue discussion first to align on the design.
  • gt stack / Refinery DAG tracking — significant architectural additions that would need design discussion.
  • Rig manifest support — would also benefit from an issue to discuss the design.

Each of these would be much easier to review and land as a separate, rebased PR. The CONTRIBUTING.md guide recommends dedicated branches per PR rather than working from a shared branch, which helps avoid this accumulation pattern.

Thanks again for the contributions — hope to see some of these come back as focused PRs!

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