cli_core library
Portable Ball CLI verbs — the single source of truth for the report text
produced by ball info, ball validate, ball tree, ball audit, and
ball version.
Every function here is a pure Program/Module-IR → report-String
transform with no dart:io: the native CLI shells own argv and stream
I/O, and this library owns the report text. Because it depends only on the
generated proto types (plus the equally-portable capability/termination
analyzers), it round-trips through DartEncoder into
dart/self_host/cli.ball.json and executes on the Ball engine, so the CLI
verbs run identically whether invoked natively or self-hosted (see the
parity gate in dart/cli/test/cli_core_parity_test.dart).
Engine-safe authoring rules (this file is round-tripped and executed by
the tree-walking engine over proto3-JSON maps, per .claude/rules/dart.md):
- Prefer explicit
forloops over.every/.fold/.where/.firstOrNull. - Never mutate a collection via
.addAll(mis-routed tolist_concat); append per-item with.add. - Access a presence-sensitive message/oneof field only after a
hasX()/whichX()guard (these route to theball_protomodule).
Functions
-
analyzeCapabilities(
Program program) → Map< String, Object?> - Analyze a Ball program and return a structured capability report Map. Every function is analyzed (whole-program view).
-
analyzeCapabilitiesReachable(
Program program) → Map< String, Object?> -
Reachability-scoped capability analysis: analyze only the transitive closure
of the program's entry function. Native-only (
ball audit --reachable-only). -
analyzeModuleCapabilities(
Module module, {Iterable< Module> imports = const []}) → Map<String, Object?> -
Analyze a library
module(e.g.ball_protobuf) plus any inlineimportsand return its capability report Map. A library has no entry point, so reachability does not apply and every function is analyzed. Native-only (the self-hostedauditReportnever audits a bare Module). -
analyzeModuleTermination(
Module module, {Iterable< Module> imports = const []}) → List<Object?> -
Analyze a library
module(and any inlineimports) for termination and control-flow issues — audited as the Module it is. Native-only. -
analyzeTermination(
Program program) → List< Object?> - Analyze a Ball program for termination and control-flow issues. Returns the list of warning Maps (empty ⇒ no issues).
-
auditReport(
Program program) → String -
The report printed by
ball audit <input.ball.json>for aprogramwith default options (all functions analyzed, termination check on). Reuses the shared capability + termination analyzers so the native verb and this function are a single implementation. -
buildCapabilityTable(
) → Map< String, String> -
Build the
"module.function" -> capability-nametable. Provably complete: every base function that can perform a side effect appears here. -
capabilityModuleNames(
) → List< String> -
The base module names keyed in buildCapabilityTable, in scan order. The
audit's bare-name fallback (lookupCapabilityByName) walks these prefixes,
so this list MUST stay in sync with the modules present in the table — the
capability_tablegroup incapability_analyzer_test.dartguards against drift and against any bare-name collision that would make the fallback ambiguous. -
capabilityNames(
) → List< String> -
The capability category names, in report-iteration order. Each program
function is tagged with a subset of these;
'pure'means no side effects. -
capabilityRisk(
String capability) → String -
Risk level associated with a capability name (
'none'for'pure'). -
checkPolicy(
Map report, {Set< String> deny = const {}}) → List<String> -
Check a report Map against a
denylist of capability names. Returns the list of violation strings (empty = pass). Native-friendly wrapper over the engine-safe checkPolicyViolations. -
checkPolicyViolations(
Map ctx) → List< String> -
Engine-safe policy check:
ctx={report, deny(List<String>)}. Returns a list of violation strings, one per denied call site. -
formatCapabilityReport(
Map report) → String -
Format a capability report Map as human-readable text (byte-identical to
the legacy proto-report renderer). Built from a line list joined with
\nplus a trailing newline — reproducingStringBuffer.writelnsemantics — so it self-hosts on the compiled TS/C++/Rust CLIs (which have no StringBuffer). -
formatTerminationReport(
List warnings) → String -
Format a termination warning List as human-readable text. Built from a
line list joined with
\nplus a trailing newline (reproducingStringBuffer.writeln) so it self-hosts on the StringBuffer-less compiled TS/C++/Rust CLIs. -
infoReport(
Program program) → String -
The report printed by
ball info <input.ball.json>(no trailing newline). -
lookupBaseModuleByName(
Map table, String function) → String -
The base module that declares bare
function, or''if none does. Companion to lookupCapabilityByName (same globally-unique-bare-name guarantee, so at most one module matches) — resolves the owning module so the audit can name the shadowed base function in full, e.g.std_concurrency.mutex_create(issue #420). -
lookupCapability(
Map table, String module, String function) → String -
The capability of a base function call, or
''for non-base / user-defined functions (which are pure by construction — they can only call other functions in this table).tableis abuildCapabilityTable()result. -
lookupCapabilityByName(
Map table, String function) → String -
Resolve a base-function capability by BARE function name alone, ignoring the
(attacker-controllable) call-site module. Scans the known base modules in
capabilityModuleNames and returns the capability of the single base
function named
function, or''when no base function has that name. -
terminationHasErrors(
List warnings) → bool -
Whether every warning has
severity == 'error'in the list (helper for the native--exit-codegate). -
treeReport(
Program program) → String -
The report printed by
ball tree <input.ball.json>(no trailing newline). -
validateOk(
Program program) → bool -
Whether
programis valid (no validation errors) — drives the native verb's exit code and stream selection. -
validateReport(
Program program) → String -
The report printed by
ball validate <input.ball.json>(no trailing newline). On the valid path this is theValid: …block; on the invalid path theInvalid: …block. The native verb routes it to stdout/stderr and picks the exit code via validateOk. -
validationErrors(
Program program) → List< String> -
The validation errors for
program(empty ⇒ valid). Mirrors the checks the nativeball validateverb historically inlined. -
versionLine(
String version) → String -
The line printed by
ball version:ball <version>.