fractal.cli package#
Subpackages#
- fractal.cli.cmd package
- Submodules
- fractal.cli.cmd.channel module
- fractal.cli.cmd.config module
- fractal.cli.cmd.cost module
- fractal.cli.cmd.db module
- fractal.cli.cmd.event module
- fractal.cli.cmd.fractal module
- fractal.cli.cmd.node module
- fractal.cli.cmd.plan module
- fractal.cli.cmd.radio module
- fractal.cli.cmd.time module
- Module contents
Submodules#
fractal.cli.main module#
Command-line interface for fractal.
fractal.cli.utils module#
Shared helpers for fractal CLI commands.
- fractal.cli.utils.command(app, name, **kwargs)[source]#
Register a CLI command on
appwith error wrapping.- Parameters:
app (
Typer)name (
str)kwargs (
Any)
- Return type:
Callable
- fractal.cli.utils.require_non_negative(**limits)[source]#
Reject negative numeric CLI options as
BadParameter.Each keyword maps a limit option’s name to its value (
Noneis skipped); the first negative raises with that option’s flag spelling. Centralizes the>= 0guard so every numeric--max-*cap is validated uniformly at the CLI boundary – unbounded is expressed by omitting the flag, never by a negative sentinel.- Parameters:
**limits (
float|None) – Option name mapped to its value (e.g.max_depth=max_depth).- Raises:
typer.BadParameter – If any value is negative.
- Return type:
None
- fractal.cli.utils.parse_reserve_budget(value, max_cost, *, default='10%')[source]#
Resolve
--reserve-budgetto a USD amount.The value is a USD number or
N%ofmax_cost; when omitted it falls back todefault(10%ofmax_cost), so a budget reserves a cleanup buffer by default, and with nomax_costthere is no reserve. The reserve is not enforced – it only moves when the node enters reserve mode (the budget is treated as drainedreserve_budgetUSD beforemax_costis reached).- Parameters:
value (
str|None) – The raw--reserve-budgetstring (USD orN%), orNoneto takedefault.max_cost (
float|None) – The node’s--max-costin USD; required whenvalueis an explicit reserve.default (
str) – Reserve applied whenvalueisNone(USD orN%).
- Return type:
float|None- Returns:
The reserve in USD –
defaultapplied tomax_costwhenvalueisNone, orNonewhen neithervaluenormax_costis set.- Raises:
typer.BadParameter – If an explicit value is given without
max_cost, is not a number, is negative, or is >= 99% ofmax_cost.
- class fractal.cli.utils.StreamRenderer[source]#
Bases:
objectANSI terminal renderer for parsed agent stream events.
The single CLI renderer over the seam’s normalized events – one instance per stream, passed as the
rendercallback toAgent.stream(the loop’s pane rendering) andNode.chatso core never prints. Branches onkindonly, never on the provider; session and cost facts render nothing (they are recorded, not displayed). Tracks the open text run (a delta without a trailing newline) so tool headers and closing summaries start below it, andclose()ends a truncated stream on a fresh line with the-- $?placeholder summary. Every write flushes: piped stdout is block-buffered while the driving command’s stderr echoes are write-through, so an unflushed line would land out of order in a merged capture.- Parameters:
self (
StreamRenderer)
Initialize
StreamRenderer.- Parameters:
self (
StreamRenderer)
- close()[source]#
End the stream on a fresh line, settling the closing summary.
Called by the driving command after the stream drains – a truncated stream (killed before its result frame) otherwise leaves the cursor mid-line and shows no closing summary, so the
-- $?placeholder marks the unaccounted turn. Idempotent, and resets for the next stream (the loop reuses one renderer across steps).- Parameters:
self (
StreamRenderer)- Return type:
None
- fractal.cli.utils.print_rows(rows, *, csv=False, columns=None)[source]#
Print rows as a formatted table or CSV.
Uses
sys.stdout.isatty()to auto-detect format: formatted text table for terminals, CSV for pipes. Thecsvparameter enables CSV output.- Parameters:
rows (
list[dict[str,Any]]) – List of row dicts.csv (
bool) – Output as CSV.columns (
list[str] |None) – Column names for the empty-result header (emitted in both formats so empty output is never ambiguous).
- Return type:
None
- fractal.cli.utils.print_json(rows, *, columns=None)[source]#
Print rows as a JSON array of objects.
The machine-readable counterpart to
print_rows: one object per row, keys incolumnsorder, and an empty result prints[](never nothing), so parsers see one shape per listing.- Parameters:
rows (
list[dict[str,Any]]) – List of row dicts.columns (
list[str] |None) – Key order for the row objects (default: each row’s own key order).
- Return type:
None
- fractal.cli.utils.init_node(path)[source]#
Resolve a
Nodefor init (accepts repo root as-is).When an agent runs init from inside its own worktree (
_NODEset) with the default path, resolve to the caller’s repo root so the new node nests under the main repo rather than the worktree (the parent is resolved from_NODEinNode.init).- Parameters:
path (
str|PathLike)- Return type:
- fractal.cli.utils.resolve_init_target(path)[source]#
Resolve the git-root-anchored node and project path for an init target.
fractal init/node initaccept a repo root or a sub-project folder aspath. The user node and every child must be anchored at the git root –Node.node_dirderives the<project>/prefix from the.worktrees/.projectcache, so anchoring at a sub-project folder would double the prefix. This resolves the target, then returns aNodeat its git root plus the target’s project-relative path.- Parameters:
path (
str|PathLike) – Repo root or sub-project folder (absolute or relative).- Return type:
tuple[Node,Path]- Returns:
(node, path)– aNodeat the git root and the target’s path relative to it (.for the repo root).- Raises:
typer.BadParameter – If the target is a linked git worktree (outside the main repo root, so never a sub-project path).
- fractal.cli.utils.resolve_node(path, *, check=True)[source]#
Resolve a
Nodeinstance from a path argument.- Parameters:
path (
str|PathLike) – Worktree directory (absolute or relative).check (
bool) – Require an initialized node at the resolved path (mirrorsresolve_target), so a user-facing command run outside a node fails cleanly instead of leaking a raw internal error. The pre-init private setter (config _set, which writes the veryconfig.jsonthis checks) passescheck=False.
- Return type:
- Returns:
Node bound to the resolved path.
- Raises:
typer.BadParameter – If
pathis a repo root with active worktrees (should use the worktree path), or (whencheck) the resolved path is not an initialized node.
- fractal.cli.utils.resolve_user_node(path)[source]#
Resolve the tree’s user (root) node from any checkout, by config not branch.
The tree-wide brake (
pause/resume) must always anchor on the user node, butresolve_node()keys on the repo’s current branch – so on a non-init checkout (the user on their own branch while nodes run) it silently mis-scopes to a lone child or dies on two.Node.resolve_user()finds theconfig.jsonmarkeduser: trueand pins aNodeto that branch, independent of the git checkout; this wrapper turns its no-fractalNoneinto the CLI refusal.- Parameters:
path (
str|PathLike) – Any path inside the repo.- Return type:
- Returns:
The user (root) node, branch-pinned.
- Raises:
typer.BadParameter – If the repo has no user node (no fractal).
- fractal.cli.utils.resolve_target(path, node=None)[source]#
Resolve the node to act on, anchored at the caller’s worktree.
pathidentifies the caller’s own worktree (default cwd);node, when given, selects another node by branch name within the same repo. Omittingnodetargets the caller’s own node.- Parameters:
path (
str|PathLike) – Caller’s worktree directory (absolute or relative).node (
str|None) – Target node’s branch name, orNonefor the caller.
- Return type:
- Returns:
Node bound to the resolved target worktree.
- Raises:
typer.BadParameter – If
nodenames a branch with no worktree, or the resolved target is not an initialized node.
- fractal.cli.utils.resolve_ledger_target(path, node)[source]#
Resolve a cost-ledger target, answering for deleted branches.
A live target resolves normally as
(node, None, None). A deleted branch fails resolution while its recorded history persists in the shared db, so it resolves through the caller as(caller, branch, latest_run)– how the fallback applies stays per command (remainingreportsno budgetwithout delegating;spent/breakdownsubstitutelatest_runfor an absent scope). The fallback accepts the same unique short names live resolution does: the registry rows that expansion consults die with the node, so the trailing segment expands against the recorded runs instead.- Parameters:
path (
str|PathLike) – Caller’s worktree directory (absolute or relative).node (
str|None) – Target node’s branch name, orNonefor the caller.
- Return type:
tuple[Node,str|None,int|None]- Returns:
(node, deleted, latest_run)– the resolved target, the deleted branch name (Nonefor a live target), and the deleted branch’s latest recorded run id.- Raises:
typer.BadParameter – If resolution fails and the branch never recorded a run (there is no history to answer from), or a short name matches several live or recorded branches.
Module contents#
Command-line interface for fractal.