fractal.impl package#
Submodules#
fractal.impl.claude module#
Claude Code CLI agent implementation.
- class fractal.impl.claude.ClaudeParser(*, model=None)[source]#
Bases:
StreamParserParser for claude
--output-format stream-jsonoutput.- Parameters:
self (
ClaudeParser)model (
str|None)
Initialize
ClaudeParser.Track the last-priced message id to skip per-block repeats.
- Parameters:
self (
ClaudeParser)model (
str|None)
- feed(line)[source]#
Parse one claude stream line into normalized events.
- Parameters:
self (
ClaudeParser)line (
str)
- Return type:
list[StreamEvent]
- class fractal.impl.claude.ClaudeAgent(node, command=None, provider=None)[source]#
Bases:
AgentClaude Code CLI backend (cost-reporting, caller-minted sessions).
Initialize
Agent.- Parameters:
node (
Node) – The node this agent runs for (config dirs, worktree, ledger).command (
str|None) – Full agent command (e.g.'claude --some-flag'); defaults to the node’s configured agent. Extra words are spliced into every invocation.provider (
str|None) – Provider-route override;Nonemeans native (Node.agentthreads the node’s effective configured route).self (
Agent)
- name: str = 'claude'#
- config_file: str = 'settings.json'#
- can_fork: bool = True#
- mints_session: bool = False#
- needs_pricing: bool = False#
- cost_scope: str = 'call'#
- enforces_budget: bool = True#
- providers: tuple[str, ...] = ('openrouter',)#
- parser(*, model=None)[source]#
Return the stream parser for the bound route.
- Parameters:
self (
ClaudeAgent)model (
str|None)
- Return type:
- tracks_cost(model=None)[source]#
Return whether spend will be recorded.
Natively claude reports its own figures on the stream; through openrouter the close is chain-priced from the result usage, so only a priced model tracks.
- Parameters:
self (
ClaudeAgent)model (
str|None)
- Return type:
bool
fractal.impl.codex module#
Codex CLI agent implementation.
- class fractal.impl.codex.CodexParser(*, model=None)[source]#
Bases:
StreamParserParser for codex
exec --jsonoutput.- Parameters:
self (
CodexParser)model (
str|None)
Initialize
CodexParser.Bind the configured-model fallback and start the wall clock.
- Parameters:
self (
CodexParser)model (
str|None)
- feed(line)[source]#
Parse one codex JSONL line into normalized events.
- Parameters:
self (
CodexParser)line (
str)
- Return type:
list[StreamEvent]
- turn_usage()[source]#
Return the wire usage of the stream’s one complete turn.
- Raises:
ValueError – Unless the stream opened one thread that named its id, started one turn and completed it.
- Parameters:
self (
CodexParser)- Return type:
Any
- finish()[source]#
Close the drained stream on its settled cost and wall time.
- Parameters:
self (
CodexParser)- Return type:
list[StreamEvent]
- class fractal.impl.codex.CodexAgent(node, command=None, provider=None)[source]#
Bases:
AgentCodex CLI backend (token-priced, agent-minted threads, no fork).
Initialize
Agent.- Parameters:
node (
Node) – The node this agent runs for (config dirs, worktree, ledger).command (
str|None) – Full agent command (e.g.'claude --some-flag'); defaults to the node’s configured agent. Extra words are spliced into every invocation.provider (
str|None) – Provider-route override;Nonemeans native (Node.agentthreads the node’s effective configured route).self (
Agent)
- name: str = 'codex'#
- config_file: str = 'config.toml'#
- can_fork: bool = False#
- mints_session: bool = True#
- needs_pricing: bool = True#
- cost_scope: str = 'call'#
- enforces_budget: bool = False#
- providers: tuple[str, ...] = ('openrouter',)#
- class fractal.impl.codex.UsageWindow(home, session, existing, baseline, path=None, identity=None, prefix_sha256=None, error=None, size=0)[source]#
Bases:
objectThe session-log state captured before a codex spawn.
A codex step is priced from the per-response
token_usage_recordrows codex appends to its session log (CODEX_HOME/sessions/.../rollout-*-<thread>.jsonl) while the process runs, bound to that process by this window:captureruns before the process starts andreconcileafter it exits, so the records between the two are the invocation’s own.- Parameters:
home (
Path)session (
str|None)existing (
dict[Path,int])baseline (
dict[str,int])path (
Path|None)identity (
tuple[int,int] |None)prefix_sha256 (
str|None)error (
str|None)size (
int)
- home: Path#
- session: str | None#
- existing: dict[Path, int]#
- baseline: dict[str, int]#
- path: Path | None = None#
- identity: tuple[int, int] | None = None#
- prefix_sha256: str | None = None#
- error: str | None = None#
- size: int = 0#
- classmethod capture(invocation)[source]#
Capture the rollout state before the spawn; a failure rides
error.- Parameters:
invocation (
Invocation)- Return type:
- reconcile(session)[source]#
Return the usage and served model of the records the invocation appended.
- Raises:
ValueError – When the rollout for
sessioncannot be bound to the invocation, the invocation spawned sub-agent threads, or the records do not describe one counted turn.- Parameters:
self (
UsageWindow)session (
str)
- Return type:
tuple[dict[str,int],str]
fractal.impl.grok module#
Grok Build CLI agent implementation.
- class fractal.impl.grok.GrokParser(*, model=None)[source]#
Bases:
StreamParserParser for grok
--output-format streaming-jsonoutput.- Parameters:
self (
GrokParser)model (
str|None)
Initialize
GrokParser.Bind the configured-model fallback and start the wall clock.
- Parameters:
self (
GrokParser)model (
str|None)
- feed(line)[source]#
Parse one grok NDJSON event line into normalized events.
- Parameters:
self (
GrokParser)line (
str)
- Return type:
list[StreamEvent]
- class fractal.impl.grok.GrokAgent(node, command=None, provider=None)[source]#
Bases:
AgentGrok Build CLI backend (cost-reporting, caller-minted sessions).
Initialize
Agent.- Parameters:
node (
Node) – The node this agent runs for (config dirs, worktree, ledger).command (
str|None) – Full agent command (e.g.'claude --some-flag'); defaults to the node’s configured agent. Extra words are spliced into every invocation.provider (
str|None) – Provider-route override;Nonemeans native (Node.agentthreads the node’s effective configured route).self (
Agent)
- name: str = 'grok'#
- config_file: str = 'config.toml'#
- can_fork: bool = True#
- mints_session: bool = False#
- needs_pricing: bool = False#
- cost_scope: str = 'call'#
- enforces_budget: bool = False#
- providers: tuple[str, ...] = ()#
fractal.impl.omp module#
Oh My Pi (omp) CLI agent implementation.
- class fractal.impl.omp.OmpParser(*, model=None)[source]#
Bases:
StreamParserParser for omp
-p --mode jsonoutput.- Parameters:
self (
OmpParser)model (
str|None)
Initialize
OmpParser.Bind the configured-model fallback and start the wall clock.
- Parameters:
self (
OmpParser)model (
str|None)
- feed(line)[source]#
Parse one omp AgentSessionEvent line into normalized events.
- Parameters:
self (
OmpParser)line (
str)
- Return type:
list[StreamEvent]
- class fractal.impl.omp.OmpAgent(node, command=None, provider=None)[source]#
Bases:
AgentOh My Pi CLI backend (cost-reporting, agent-minted sessions).
Initialize
Agent.- Parameters:
node (
Node) – The node this agent runs for (config dirs, worktree, ledger).command (
str|None) – Full agent command (e.g.'claude --some-flag'); defaults to the node’s configured agent. Extra words are spliced into every invocation.provider (
str|None) – Provider-route override;Nonemeans native (Node.agentthreads the node’s effective configured route).self (
Agent)
- name: str = 'omp'#
- config_file: str = 'config.yml'#
- can_fork: bool = True#
- mints_session: bool = True#
- needs_pricing: bool = False#
- cost_scope: str = 'call'#
- enforces_budget: bool = False#
- providers: tuple[str, ...] = ()#
fractal.impl.opencode module#
opencode CLI agent implementation.
- class fractal.impl.opencode.OpencodeParser(*, model=None)[source]#
Bases:
StreamParserParser for opencode
run --format jsonoutput.- Parameters:
self (
OpencodeParser)model (
str|None)
Initialize
OpencodeParser.Bind the configured-model fallback and start the wall clock.
- Parameters:
self (
OpencodeParser)model (
str|None)
- feed(line)[source]#
Parse one opencode JSON event line into normalized events.
- Parameters:
self (
OpencodeParser)line (
str)
- Return type:
list[StreamEvent]
- class fractal.impl.opencode.OpencodeAgent(node, command=None, provider=None)[source]#
Bases:
Agentopencode CLI backend (cost-reporting, agent-minted sessions).
Initialize
Agent.- Parameters:
node (
Node) – The node this agent runs for (config dirs, worktree, ledger).command (
str|None) – Full agent command (e.g.'claude --some-flag'); defaults to the node’s configured agent. Extra words are spliced into every invocation.provider (
str|None) – Provider-route override;Nonemeans native (Node.agentthreads the node’s effective configured route).self (
Agent)
- name: str = 'opencode'#
- config_file: str = 'opencode.json'#
- can_fork: bool = True#
- mints_session: bool = True#
- needs_pricing: bool = False#
- cost_scope: str = 'call'#
- enforces_budget: bool = False#
- results_per_step: bool = True#
- providers: tuple[str, ...] = ()#
Module contents#
Implementations for fractal.