Skip to content

feat: add re:factory persistent supervisor agent (#728)#754

Open
xukai92 wants to merge 10 commits into
mainfrom
factory/run-82141037
Open

feat: add re:factory persistent supervisor agent (#728)#754
xukai92 wants to merge 10 commits into
mainfrom
factory/run-82141037

Conversation

@xukai92

@xukai92 xukai92 commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • New re:factory agent — a persistent Claude Code supervisor that manages CEO agent lifecycles, context/compaction, and playbook evolution
  • Bare factory command (no subcommand) now launches the refactory agent instead of the welcome wizard
  • 4 slash command skills: /factory-run (dispatch), /sessions (tracking), /compaction (context preservation), /playbook (ACE evolution)
  • 13 new tests covering workspace setup, session management, role registration, and CLI integration

Files changed

  • factory/agents/prompts/refactory.md — agent system prompt (149 lines)
  • factory/refactory.py — workspace setup + session management module
  • factory/agents/skills/ — 4 skill files (factory-run, sessions, compaction, playbook)
  • factory/agents/runner.py — added "refactory" to AgentRole
  • factory/agents/agents.yml — added refactory role config
  • factory/cli.py — added cmd_refactory + wired bare factory to launch it
  • tests/test_refactory.py — 13 test cases

Test plan

  • uv run pytest tests/test_refactory.py -v — 13/13 pass
  • uv run pytest tests/test_prompts.py -v — 71/71 pass (no regressions)
  • ruff check factory/refactory.py factory/agents/runner.py — clean
  • Full test suite (366 tests in affected files) — all pass

Closes #728

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Jun 24, 2026

Copy link
Copy Markdown

Sentrux Quality Report

Absolute

Scanning ....
[scan] git ls-files: 312 total, 300 kept, 12 dropped (ext:12, meta:0, big:0)
[build_project_map] 300 files, 54 unique dirs, 50 cache misses, 2.3ms
[resolve] 444 resolved, 786 unresolved (of 1230 total specs)
[resolve_imports] project_map 2.4ms, suffix_idx 0.6ms, suffix_resolve 10.4ms, total 13.4ms
[build_graphs] 300 files | maps 0.9ms, imports 13.5ms, calls+inherit 3.1ms, total 17.4ms | 443 import, 4416 call, 0 inherit edges
sentrux check — 2 rules checked

Quality: 4705

✗ [Error] max_cc: 5 function(s) exceed max cyclomatic complexity of 30
    factory/cli.py:cmd_ceo (cc=79)
    factory/study.py:study_project_local (cc=43)
    factory/cli.py:_welcome_wizard (cc=39)
    factory/cli.py:cmd_run (cc=37)
    factory/workflow/validation.py:validate_workflow (cc=31)

✗ 1 violation(s) found

Diff (vs base branch)

Scanning ....
[scan] git ls-files: 312 total, 300 kept, 12 dropped (ext:12, meta:0, big:0)
[build_project_map] 300 files, 54 unique dirs, 50 cache misses, 2.4ms
[resolve] 444 resolved, 786 unresolved (of 1230 total specs)
[resolve_imports] project_map 2.5ms, suffix_idx 1.0ms, suffix_resolve 9.9ms, total 13.4ms
[build_graphs] 300 files | maps 0.8ms, imports 13.4ms, calls+inherit 3.1ms, total 17.4ms | 443 import, 4416 call, 0 inherit edges
sentrux gate — structural regression check

Quality:      4705 -> 4705
Coupling:     0.75 → 0.75
Cycles:       4 → 4
God files:    0 → 0

Distance from Main Sequence: 0.35

✓ No degradation detected

@xukai92 xukai92 changed the title test: add tests for re:factory agent module feat: add re:factory persistent supervisor agent (#728) Jun 24, 2026
@codecov

codecov Bot commented Jun 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.32394% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.86%. Comparing base (3baba8c) to head (ac90ffe).
⚠️ Report is 37 commits behind head on main.

Files with missing lines Patch % Lines
factory/cli.py 67.85% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #754      +/-   ##
==========================================
+ Coverage   86.75%   86.86%   +0.11%     
==========================================
  Files          79       81       +2     
  Lines       11881    12203     +322     
==========================================
+ Hits        10307    10600     +293     
- Misses       1574     1603      +29     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@xukai92

xukai92 commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator Author

@ceo-review

github-actions[bot]
github-actions Bot previously approved these changes Jun 25, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Factory Review: KEEP

Verdict: KEEP
Reason: Persistent refactory supervisor agent with full session management, context/compaction skills, and playbook evolution. All tests pass (2597/2597) including 19 new tests. 2 LOW severity issues are acceptable patterns. All acceptance criteria verified.

Score Comparison

Metric Value
Before 0.4282
After 0.4282
Delta +0.0000
Threshold 0.8000

Code Review Notes

  • qa_verdict=ISSUES_FOUND
  • qa_issues_count=2
  • qa_issues_severity=LOW
  • tests_pass=2597/2597
  • lint_pass=yes
  • acceptance_criteria=4/4
  • issues=unreachable_wizard_code+temp_file_leak_with_execvp
  • smoke_test=PASS
  • edge_cases=9/9_PASS

Posted by Factory CEO

xukai92 and others added 10 commits June 26, 2026 03:58
Introduces the re:factory persistent supervisor agent — a layer above
the CEO that manages CEO lifecycles, context/compaction, and playbooks.

Phase 1: Agent prompt (refactory.md), workspace module (refactory.py),
AgentRole registration, agents.yml config, CLI subcommand + bare
`factory` entry point.

Phase 2-3: Four slash-command skill files (factory-run, sessions,
compaction, playbook) copied to workspace on setup, giving the agent
dispatch, monitoring, context preservation, and ACE evolution abilities.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
13 test cases covering setup_workspace (directories, settings.json,
CLAUDE.md, skill copying, idempotency), session ID lifecycle (create,
existing, reset, roundtrip), agent role registration (AgentRole type,
agents.yml), and CLI integration (subcommand parsing, prompt resolution).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add "refactory" to _WORKSPACE_WRITE_ROLES in plugin.py so Codex
  sandbox mode handles the new role
- Update test_tty_launches_wizard to mock cmd_refactory instead of
  _welcome_wizard, matching the new bare `factory` behavior

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Claude Code's --session-id flag requires standard UUID format
(with dashes), not hex-only. Found during E2E testing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add TestCmdRefactory: no_claude error, new/existing session resume
  flag, reset flag, model forwarding (all mock os.execvp)
- Add test_corrupt_json_generates_new for the except branch
- factory/refactory.py now at 100% coverage

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Claude Code CLI doesn't support --cwd. Change to os.chdir(workspace)
before os.execvp instead.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Claude Code doesn't allow --session-id combined with --resume.
New sessions: --session-id <uuid> (sets the ID).
Existing sessions: --resume <uuid> (resumes by ID).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Move refactory workspace from global ~/.factory/refactory/ to per-project
.refactory/ so each project gets its own session and config. Add sop-compact
PreCompact and SessionStart hooks so the agent survives context compaction.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Bare `factory` now checks for .git/ — launches refactory in git repos,
wizard otherwise. Split test into two: git repo and non-git-repo cases.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The refactory agent is fully trusted within its project workspace,
same as the board agent in refactory-server.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@xukai92 xukai92 force-pushed the factory/run-82141037 branch from 732a492 to fab6b4d Compare June 26, 2026 04:28
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.

re:factory agent

1 participant