foreman README

项目的 README,来自 github.com/thruwire/foreman。合并为一个 markdown 文件:README.md。

Foreman

Foreman watches the software factory floor with decision models, placing a fast semantic supervisor above slower coding agents. It supports TypeSafe AI's Jev and OpenAI's Decisions API.

Give it a ticket, specification, bug report, or any free-form software job. Foreman can run Codex, OpenCode, Hermes, or LangChain's Deep Agents Code (dcode) as workers. It can also attach supervision to supported coding-agent sessions, including Pi and Pi Durable.

The coding agent does the software engineering. Foreman independently assesses completion and requirements against the original job. It also checks whether test evidence is sufficient and whether verification or human input is needed. You can configure additional checks and responsibilities for your workflow.

                         SOFTWARE FACTORY
         Coding agent     Coding agent           Tests
            worker             worker                │
               │                  │                  │
               └──────────────────┼──────────────────┘
                                  │ factory evidence
                                  ▼
                              FOREMAN
                          decision model
                                  │
                                  ▼
                    responsibilities
                      completion
                        implementation_complete  .91
                        requirements_satisfied   .79
                        ready_to_finish          .21
                      verification
                        tests_sufficient         .34
                        needs_verification       .82
                      worker health
                        worker_stuck             .02
                        work_off_track           .06
                        meaningful_progress      .94
                      repository instructions
                        agents_md_drift          .01
                      human escalation
                        needs_human              .01
                                  │
                                  ▼
                    continue / steer / stop / retry
                         verify / finish

Generative models work. Foreman watches the work.

Foreman separates software-engineering work from continuous semantic supervision. Its effectiveness depends on the quality of the configured checks, evidence, thresholds, and underlying models.

Documentation

Contributing

Contributions are welcome. See CONTRIBUTING.md for setup and pull-request guidance. Please also read the Code of Conduct and report vulnerabilities according to the Security Policy.

What is Foreman?

Foreman is a native Python asyncio runtime with two concurrent loops:

CODING AGENT LOOP                         FOREMAN LOOP
reason                                    watch
  │                                         │
  ▼                                         ▼
tool                                      assess
  │                                         │
  ▼                                         ▼
observe ───────── factory events ────────► decision model
  │                                         │
  ▼                                         ▼
edit                                      decide (Python policy)
  │                                         │
  ▼                                         ▼
test ◄──────────── intervention ────────── intervene
  │
  └── continue

Foreman does not replace a worker's reason/tool/observe loop and does not choose its individual tools or files. Missions stay broad. The important property is that the worker does not have to stop working for the factory to think: worker output and lifecycle events flow into an independent, debounced observation loop while the subprocess remains active.

Why build this?

Coding agents are relatively slow, stateful generative systems. Supervisory questions such as “is this worker stuck?” or “does this now need independent verification?” are narrower. Decision models accept evidence and typed questions and return probabilities. Foreman explores whether that interface supports frequent semantic supervision without rebuilding the coding agent itself. The provider adapter is replaceable, independently of worker backends and Python policy.

The factory floor

Foreman currently runs one coding worker at a time. By default, a real worker is a Codex App Server thread and turn launched over its JSONL protocol:

codex app-server --listen stdio://
thread/start → turn/start → turn/steer or turn/interrupt

The App Server transport keeps the active Codex thread addressable, allowing Foreman to send a supervisory update into an in-flight turn. App Server notifications and stderr are bounded in memory, persisted as factory events, and made visible to Foreman before the worker exits. A verifier is another worker using the selected backend with an independent, deterministic verification mission. The prior stable codex exec transport remains available through FOREMAN_CODEX_BACKEND=exec, but it cannot accept live steering.

The worker implementation is replaceable; the runtime depends on a small worker protocol rather than Codex-specific types.

Worker backends

The semantic-supervision loop is agent-agnostic. Select the worker backend with FOREMAN_WORKER_BACKEND (codex, the default, opencode, hermes, or deepagents):

FOREMAN_WORKER_BACKEND=opencode foreman run --repo ./my-project --job "Add request retries"

The OpenCode backend runs opencode run non-interactively and streams its output like the Codex exec backend. The Hermes backend runs hermes chat in headless single-query mode and decodes its newline-delimited JSON events into tool-activity summaries. The Deep Agents backend runs the separately installed dcode CLI headlessly with bounded output and turn/time budgets. Live steering into an active turn is only available with the Codex App Server backend; other backends degrade to stop/retry. See Worker backends for the Worker protocol and how to add your own.

Deep Agents also supports interactive attached supervision through native hooks. Install foreman-deepagents@thruwire from our marketplace, or use the core foreman deepagents setup command to merge hooks into native configuration. Choose one installation method to avoid duplicate assessments. See the Deep Agents setup guide for installation, credentials, and both supervision paths.

What Foreman watches

Each observation is compact and bounded. It contains:

Foreman never dumps the repository into the decision model. Repository instructions are read for each observation and included only in the transient decision model request; their contents are not persisted in factory state. Defaults are a 20,000-character diff, 12,000 characters per captured output tail, 30 recent events, and 10 workers of history. The limits live in FactoryConfig and can be changed for experiments.

Responsibilities and checks

Foreman's semantic supervision is split into pluggable responsibilities. A responsibility owns one or more decision model checks and deterministic logic that may propose directives. Checks have results; responsibilities do not have aggregate scores. All active responsibilities can match at once. Checks sharing an evidence selection are batched into one decision model request; different selections use separate, filtered requests.

The built-in completion responsibility owns:

Verification owns tests_sufficient and needs_verification. Worker health owns:

Repository instructions owns:

Human escalation owns:

Documentation quality is conditional. When incoming work explicitly requires repository documentation, it owns documentation_sufficient and can request another worker pass when that check remains below its TOML-defined minimum.

Every dimension is a predicate whose result is the probability of “yes.” The Jev adapter uses Noul; the OpenAI adapter uses native predicate questions. The ten global checks—and the documentation check when routed—share one request under the default evidence configuration. A ForemanResult groups check outputs by responsibility, records every proposed directive, and identifies the one selected directive. It is stored in state.json and the event timeline. The runtime accepts a ResponsibilityRegistry, so another responsibility can add checks and directives without changing the decision model adapter or runtime loop.

For real runs, Foreman ships one TOML file per built-in responsibility under src/foreman/responsibilities/definitions/. Each file owns its global-or-routed behavior, decision model routing instructions, recurring decision model check IDs and instructions, thresholds, and responsibility-specific settings. The Python class retains directive logic and any observation or integration behavior, and declares the check IDs that behavior requires. An optional central directory selected with --responsibilities-dir or FOREMAN_RESPONSIBILITIES_DIR can override those files for the whole Foreman installation. Target repositories never supply responsibility configuration. Foreman evaluates all non-global candidates in one decision model request and activates every match; there is no separate routes file. See Responsibility configuration and routing.

What Foreman can do

The decision model only evaluates checks. Responsibilities propose directives, and a deterministic Python arbiter selects the one action that is permitted:

The ordering is safety-first: human need, iteration bounds, AGENTS.md drift, off-track/stuck workers, retry handling, completion, verification, then continued work. A worker that crosses one of those drift, stuck, or off-track thresholds is steered once by default. It receives a grace period before a repeated high score causes Foreman to stop it. State tracks steering and verification so policy does not oscillate. Transient decision model failures are tolerated up to FOREMAN_MAX_CONSECUTIVE_ASSESSMENT_FAILURES consecutive misses — the workers keep running while the assessment is retried — and only then does the run escalate.

Default policy thresholds are:

Decision input Threshold
needs human 0.80
off track 0.80
AGENTS.md drift 0.80
worker stuck 0.80
needs verification 0.65
implementation before verification 0.75
ready to finish 0.75
requirements satisfied 0.75
tests sufficient 0.75
documentation sufficient, when routed 0.75

These values are declared as min_threshold beside their checks in the responsibility TOMLs; the table is only a consolidated view.

Decision models

Jev remains the default, using the official typesafe-sdk, TYPESAFE_API_KEY, and system_one with Noul questions. Its existing OpenRouter configuration continues to work.

To use OpenAI's native Decisions API, install the optional adapter and configure its credentials:

pip install 'foreman-core[openai]'
FOREMAN_DECISION_PROVIDER=openai
FOREMAN_DECISION_MODEL=gpt-6-luna
FOREMAN_OPENAI_API_KEY=your-key

Save these settings in ${FOREMAN_DATA_DIR:-~/.foreman}/.env for managed runs and attached hooks. OPENAI_API_KEY is also accepted; the dedicated Foreman key takes precedence and is removed from launched workers. A worker's own OPENAI_API_KEY remains available to its coding model.

Both adapters serve routing and recurring assessments. Thresholds, evidence selection, lifecycle limits, and policy remain in shared Foreman code. Refusals and malformed answers are assessment errors. See decision models for architecture, supported semantics, configuration compatibility, and API references.

Requirements

Installation

Install the published package:

python -m pip install foreman-core

The distribution is named foreman-core; it installs the foreman command and the foreman Python package.

Pi and Pi Durable supervision also requires the separate TypeScript bridge. Follow the Pi installation guide; installing foreman-core alone does not register an extension with Pi.

For development, install from a fresh checkout:

python3.12 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install '.[dev]'
cp .env.example .env

Put the key in .env:

TYPESAFE_API_KEY=your-key-here

.env is ignored by Git. Foreman never writes the key into logs, observations, state, or events.

OpenRouter users can use the same SDK without a separate TypeSafe account. Follow the OpenRouter setup guide to configure both the key and the base URL.

Running Foreman

foreman run \
  --repo ./my-project \
  --job "Add rate limiting to the API and make sure it is properly tested."

Checks normally receive Foreman's built-in evidence providers. A check can instead name an exact provider list, including trusted external CLI tools. Define the command in Foreman's central config:

[[evidence.commands]]
id = "pytest"
command = ["python", "-m", "pytest", "-q"]
timeout_seconds = 120

Then pair it with a decision model check in a central responsibility definition:

[checks.tests_sufficient]
instructions = """
Does the selected evidence show sufficient relevant coverage and passing verification?
"""
min_threshold = 0.75
evidence = ["worker", "git.diff", "command.pytest"]

The command runs after a coding worker completes, before the check's next assessment. Foreman adds its bounded output, exit status, and timing to that check's evidence; the check's decision model instructions interpret the result through the existing responsibility and policy mechanism. See evidence providers.

The terminal shows worker lifecycle messages and grouped job/factory-floor assessments. It makes explicit when the coding agent is working and Foreman is independently watching, without animated noise.

Deterministic demo

The simulation exercises the same runtime, policy, persistence, event stream, and UI with deterministic model and worker implementations:

foreman demo --repo .

It needs no API key, network, coding-agent CLI, or external repository. The sequence progresses from continued implementation, through independent verification, to FINISH.

Attached coding-assistant workers

foreman hook accepts one lifecycle event as JSON on stdin and writes the selected assistant's hook JSON to stdout. It lets Foreman supervise an interactive session that a human started, rather than only workers launched by foreman run:

printf '%s\n' '{"session_id":"thr_123","cwd":"/workspace/project","hook_event_name":"SessionStart","source":"startup"}' \
  | foreman hook --client codex

The explicit --client selects codex, deepagents, pi, or pi-durable; codex remains the compatibility default. Foreman does not infer a client from arbitrary JSON, and unknown clients fail closed. The adapter normalizes events before they reach the shared attached-worker runtime and translates semantic outcomes back into client-specific hook JSON.

Hook sessions are keyed by client plus its native session_id and stored globally under ~/.foreman/sessions/, not in the target repository. Hooks compose built-in definitions with any configured extensions from validated local snapshots; they never authenticate or synchronize on the hook path. The installable Codex adapter is maintained in the ThruWire marketplace and is published as foreman@thruwire:

codex plugin marketplace add thruwire/marketplace
codex plugin add foreman@thruwire

See coding-assistant hooks and attached workers for the process protocol and the Codex plugin README for installation, trust, and diagnostics.

The Pi and Pi Durable bridges forward native extension events and task hooks to the same runtime. They include prompt routing, tool supervision, completion continuations, and a Durable replay contract. Pi supervision requires both foreman-core and the separate TypeScript bridge; installing the Python core alone does not load the Pi extension. Install the published bridge with pi install npm:@thruwire/foreman-pi. See the bridge guide for Pi Durable setup and building from source.

Persistence and inspection

Each repository gets local, ignored state:

.foreman/runs/<run-id>/
├── state.json
└── events.jsonl

state.json is atomically replaced and contains enough typed state to recover a run. events.jsonl is an append-only timeline. Inspect either through the CLI:

foreman runs --repo ./my-project
foreman inspect <run-id> --repo ./my-project

The target repository's entire .foreman/ directory is locally ignored because it contains run state, not factory configuration.

Runtime configuration

The most useful environment overrides are:

Variable Default Meaning
FOREMAN_ASSESSMENT_MIN_INTERVAL_SECONDS 5 Debounce/coalescing floor
FOREMAN_PERIODIC_ASSESSMENT_SECONDS 30 Assessment during quiet work
FOREMAN_DECISION_PROVIDER jev jev or openai decision adapter
FOREMAN_DECISION_MODEL provider default jev-latest or gpt-6-luna; override explicitly
FOREMAN_DECISION_TIMEOUT_SECONDS 10 Semantic assessment timeout
FOREMAN_WORKER_TIMEOUT_SECONDS 3600 Per-worker timeout
FOREMAN_OVERALL_TIMEOUT_SECONDS 7200 Whole-run timeout
FOREMAN_MAX_WORKERS 3 Total workers, including verifier
FOREMAN_MAX_RETRIES 1 Fresh attempts after a stop
FOREMAN_MAX_ITERATIONS 20 Semantic decision ceiling
FOREMAN_MAX_CONSECUTIVE_ASSESSMENT_FAILURES 3 Tolerated supervisor failures before escalation
FOREMAN_CODEX_BACKEND app-server app-server for steering or exec fallback
FOREMAN_CODEX_EXECUTABLE codex Codex CLI executable or absolute path
FOREMAN_CODEX_MODEL unset Explicit Codex worker model; otherwise use native Codex configuration
FOREMAN_WORKER_BACKEND codex codex, opencode, hermes, or deepagents worker backend
FOREMAN_DEEPAGENTS_EXECUTABLE dcode Installed Deep Agents Code executable
FOREMAN_DEEPAGENTS_MODEL unset Native provider/model identifier
FOREMAN_DEEPAGENTS_MAX_TURNS 200 Headless agentic turn limit
FOREMAN_DEEPAGENTS_SHELL_ALLOW_LIST recommended Native shell preset or command allow-list
FOREMAN_STEERING_ENABLED true Allow decision model active-turn guidance
FOREMAN_MAX_STEERS_PER_WORKER 1 Steering attempts before stop/retry
FOREMAN_STEERING_GRACE_SECONDS 30 Time to recover before another intervention
FOREMAN_RESPONSIBILITIES_DIR unset Optional Foreman-wide responsibility overrides
FOREMAN_DATA_DIR ~/.foreman Global configuration, extension, and session data
FOREMAN_CONFIG ~/.foreman/config.toml Central evidence-provider and extension configuration
FOREMAN_HOOK_SESSION_TTL_SECONDS 604800 Inactive attached-session lifetime

Observation bounds and runtime limits remain typed FactoryConfig fields. Semantic minimums live beside their checks in the central responsibility TOMLs. Other central settings can configure only the responsibility that owns them.

Tests

python -m pytest

The suite is offline: no credentials, network, Codex process, or external repository is required. It covers models, serialization, persistence/recovery, decision adapter translation and failure handling, every policy branch, subprocess streaming/termination, concurrent assessments, intervention delivery, the complete simulated factory, and a stuck-worker recovery scenario.

Process safety and security

Foreman enforces steering, worker, retry, iteration, worker-timeout, overall-timeout, and concurrency limits. Workers receive only the supplied repository as their working root. Stop requests first interrupt the active App Server turn, then terminate the process after a bounded grace period. Ctrl-C cancels the run, terminates active workers, and persists a final cancelled state.

Workers still run with the permissions of the local environment. Codex requests its workspace-write sandbox. OpenCode runs with --auto, which approves permission requests that are not explicitly denied; Foreman does not add a sandbox around it. Configure restrictive OpenCode permission rules before use. Foreman does not make untrusted repositories or jobs safe, so review the worker configuration and repository before running either backend.

Configured command evidence providers also run with the user's local permissions and inherit Foreman's environment. They are loaded only from trusted central configuration, invoked directly without a shell, bounded by a timeout and retained-output limit, and terminated as a process group on timeout. Treat provider commands as trusted local code and avoid putting credentials in command arguments or printing secrets to their output.

Limitations

Roadmap

Natural next steps include simultaneous workers, per-worker and factory-wide assessments, alternate coding agents or fast decision models, dynamic assessment frequency, calibrated policies, durable execution, and isolated worker environments. They are outside the current scope.

foreman (thruwire/foreman)

正在搜索数据库…

这是什么?Foreman 是一个监督程序,在编码代理(如 Codex 或 OpenCode)处理工单或缺陷报告时进行监视,并使用一个名为 Jev 的快速决策模型来独立判断实现是已完成、需要验证,还是需要人工介入。
Foreman 本身是一个编码代理,还是架在编码代理之上的东西?它不是编码代理。它是一个原生 Python asyncio 运行时,带两个并发循环,观察一个单独的 worker(Codex、OpenCode 或 Hermes)完成实际的工程工作,从不直接触碰它的工具或文件。
怎么安装和运行 Foreman?克隆仓库,从全新的检出安装,把 TypeSafe API 密钥放进 .env 文件,然后针对一个任务运行 Foreman。还有一个确定性的演示模式,不需要任何真实的 worker 或 API 密钥就能运行。
在用 Foreman 跑真实任务之前我需要准备什么?Python 3.11+、一个 TypeSafe API 密钥,以及你所选 worker 后端的 CLI:默认后端需要支持 'codex app-server' 的 Codex CLI 并已完成 codex login,opencode 后端需要 OpenCode CLI,hermes 后端需要 Hermes Agent CLI。
所有 worker 后端都支持相同的功能吗?不是。对进行中的回合做实时转向只在 Codex App Server 后端可用;OpenCode 和 Hermes 后端只能退化为停止/重试模式,无法在回合中途引导。
我的 TypeSafe API 密钥会被安全处理吗?密钥只保存在本地 .env 文件中(已被 git 忽略),而且 Foreman 明确绝不把它写入日志、观察记录、状态或持久化的事件。
Jev 到底为 Foreman 做什么?Jev 接受结构化状态和带类型的“是/否”(Noul)问题,并在一次并行请求中返回相互独立的概率答案,这让 Foreman 能以很低的成本询问诸如“worker 卡住了吗?”之类的问题,而不会拖慢编码代理。
Foreman 对运行中的任务实际能采取哪些行动?一个确定性仲裁器会从 CONTINUE、STARTWORKER、STARTVERIFIER、STEERWORKER、STOPWORKER、RETRYWORKER、FINISH 或 ESCALATE 中选择一个,依据是 Jev 为完成度、偏移、worker 卡住等检查返回的概率。
没有 API 密钥或真实的编码代理也能试用 Foreman 吗?可以。内置的确定性演示用模拟的模型和 worker 实现运行同样的运行时、策略、持久化和 UI,不需要 API 密钥、网络或外部仓库。
Foreman 能监督我自己启动的交互式会话,而不只是它自己启动的任务吗?可以,通过 'foreman hook',它会从接入的编码助手会话(目前是 Codex 适配器)读取 JSON 格式的生命周期事件,让 Foreman 用与自己启动的 worker 相同的方式来监督它。
作者
thruwire
大小
1.4 MB
星标
828
时长
2个月
提交 · 90 天