Documentation
¶
Overview ¶
Package cli adapts typed daemon contracts and local workflows into Canary commands, machine-readable output, and terminal rendering. Broker-connected for broker state, policy decisions, and gated broker writes.
Index ¶
- func DetectWriteOrigin(stdin io.Reader) string
- func HelpInvocation(cmd string, rest []string) bool
- func IsKnown(name string) bool
- func PolicyLocalSubcommand(args []string) bool
- func PrintUsage(w io.Writer)
- func PushDeliveryLine(p rpc.PushDeliveryProof, now time.Time) (string, bool)
- func Run(ctx context.Context, env *Env, cmd string, args []string) int
- func RunPolicyLocal(ctx context.Context, env *Env, args []string) int
- func RunRestart(ctx context.Context, args []string, stdout, stderr io.Writer) int
- func RunStop(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io.Writer) int
- func RunUpdate(ctx context.Context, args []string, version string, stdin io.Reader, ...) int
- func ShouldColor(w io.Writer) bool
- type Command
- type CommandFunc
- type CommandSpec
- type DaemonConn
- type Env
- type FlagSpec
- type GuardClass
- type HelpGroup
- type HelpGroupSpec
- type SubcommandSpec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DetectWriteOrigin ¶
DetectWriteOrigin classifies this process for broker-write authorization. Any agent marker or a non-TTY stdin classifies as agent; nothing can force a human classification. The daemon treats unknown origins as agent for audit and any origin-specific policy, while broker-write readiness still comes from trading mode, pins, preview tokens, freeze state, and broker checks.
func HelpInvocation ¶
HelpInvocation reports whether rest asks cmd for help in a form its handler answers without the daemon: a help flag anywhere, `help` alone, or `help ACTION` where the usage offers it (`canary policy help override`). cmd/canary checks it before dialling, so asking for help never starts the daemon.
func IsKnown ¶
IsKnown reports whether name is a registered subcommand. Used by cmd/canary to skip the daemon autospawn for typos and unknown commands — otherwise `canary nonsense` would spawn the daemon just to fail with "unknown subcommand", which is wasteful and confusing if it tips a dormant install into a long startup.
func PolicyLocalSubcommand ¶
PolicyLocalSubcommand reports whether args name a policy subcommand that runs without the daemon: default, ensure, and check --offline.
func PrintUsage ¶
PrintUsage writes the top-level help text. Commands are listed under their catalog group, in registry order inside each one, so `status` stays the first line. The listing shows the catalog's short form and the full summary stays in `canary <subcommand> --help` — a flat list of 36 long summaries wraps into a wall on an 80-column terminal.
func PushDeliveryLine ¶
PushDeliveryLine renders the one-line phone push verdict shared by `canary status` and `canary app status`: how long alert pushes have been silent, whether a device ever witnessed a push, and what blocks delivery. ok is true only when a paired device has reported a push displayed or opened and nothing currently blocks delivery. Push-service acceptance is never a witness.
func Run ¶
Run dispatches the subcommand named by cmd. Returns the process exit code. flag package stops at the first non-flag token, but users naturally write
func RunPolicyLocal ¶
RunPolicyLocal runs the policy subcommands that need no daemon: default (print a template), ensure (write missing files, review/apply conversions) and check --offline (the file-only plausibility read). The install path runs `canary policy ensure` before any daemon exists.
func RunRestart ¶
RunRestart is the top-level `canary restart` entrypoint. It intentionally does not take an Env: restart is local process management and must run before the normal autospawn+dial path in cmd/canary/main.go.
func RunStop ¶
RunStop is the top-level `canary stop` entrypoint. Like RunRestart it takes no Env: stopping is local process management and must run before the autospawn path in cmd/canary/main.go, which would otherwise start the very daemon this command exists to stop.
func RunUpdate ¶
func RunUpdate(ctx context.Context, args []string, version string, stdin io.Reader, stdout, stderr io.Writer) int
RunUpdate is the entrypoint cmd/canary/main.go dispatches to. It does not match the CommandFunc signature because update has no Env (no daemon connection) — `update` is registered in cli.commands with Fn=nil and the binary's main.go calls this function directly, the same pattern `setup` uses.
args are the raw CLI args after `canary update`. version is the installed binary's version string (cmd/canary stamps it at build). stdin / stdout / stderr are the process I/O streams.
Returns the process exit code.
func ShouldColor ¶
ShouldColor reports whether ANSI color escapes should be emitted to w. Policy, in order:
- CANARY_COLOR=always → on (overrides TTY check)
- CANARY_COLOR=never → off
- NO_COLOR set (any) → off (https://no-color.org)
- w is an interactive terminal → on
- otherwise → off (pipes, file redirects, bytes.Buffer in tests)
Computed once per process and cached on Env.Color so colored renderers don't re-syscall on every value.
Types ¶
type Command ¶
type Command struct {
Name string
Summary string
Usage string // optional one-line usage example shown in `canary X --help`
Fn CommandFunc
}
Command bundles a subcommand's name, one-line summary, optional usage
type CommandFunc ¶
CommandFunc is the signature implemented by every subcommand handler.
type CommandSpec ¶
type CommandSpec struct {
Name string
Summary string
// Brief is the listing line for commands whose Summary is too long for
// a terminal row. `canary <command> --help` and the generated CLI
// reference always render Summary, so the detail is moved, not lost.
Brief string
Usage string
Flags []FlagSpec
Subcommands []SubcommandSpec
Guard GuardClass
Group HelpGroup
}
CommandSpec is the user-facing command catalog. Name/Summary/Usage are copied from Commands() at runtime so the help table and catalog cannot silently drift.
func Catalog ¶
func Catalog() []CommandSpec
Catalog returns the registered commands with shared metadata for the help listing, generated reference, guard descriptions, and flag-value handling.
type DaemonConn ¶
type DaemonConn interface {
Call(context.Context, string, any, any) error
Stream(context.Context, string, any, func(json.RawMessage) error) error
}
DaemonConn is the CLI's typed daemon-call surface. *dial.Conn implements
type Env ¶
type Env struct {
// HelpOnly parses offline; it must never execute a normal command.
HelpOnly bool
Stdout io.Writer
Stderr io.Writer
// Stdin is the interactive input used for live-write confirmation
Stdin io.Reader
Conn DaemonConn
// Origin is this process's broker-write origin classification
// Empty classifies as agent at the daemon (fail closed).
Origin string
// Version is the running CLI version stamped by cmd/canary. Empty in
// renderer tests and local-only helper paths that do not need parity
// checks against the daemon.
Version string
// Color is true when ANSI color escapes should be emitted on Stdout.
Color bool
}
Env is the per-invocation context shared by every subcommand.
type FlagSpec ¶
FlagSpec is the shared flag metadata used by command-line flag hoisting and generated reference documentation. Values is intentionally small and enum-like.
type GuardClass ¶
type GuardClass string
GuardClass describes whether a command is read-only, changes local state, or needs a human confirmation. It is metadata only; existing CLI gates still enforce the real safety policy.
const ( GuardReadOnly GuardClass = "read-only" GuardLocal GuardClass = "local" GuardConfirm GuardClass = "confirm" )
Guard classifications used by the command catalog.
type HelpGroup ¶
type HelpGroup string
HelpGroup buckets commands in the top-level help listing. It is a reading aid for the command registry and carries no policy; guard classes remain the only statement about what a command may do.
type HelpGroupSpec ¶
HelpGroupSpec is one heading in the top-level help listing.
func HelpGroups ¶
func HelpGroups() []HelpGroupSpec
HelpGroups returns the listing groups in render order. Commands keep registry order inside their group, so `status` stays the first line of the first group.
type SubcommandSpec ¶
type SubcommandSpec struct {
Name string
Guard GuardClass
}
SubcommandSpec captures nested command words that are useful for completion and guard classification. The existing handlers remain authoritative for parsing and validation.
Source Files
¶
- account.go
- brief.go
- calendar.go
- catalog.go
- chains.go
- cli.go
- color.go
- core.go
- data.go
- display.go
- edge.go
- edge_brief.go
- edge_levels.go
- edge_replay.go
- edge_tests.go
- feedback.go
- help.go
- lending.go
- lending_rates.go
- locks.go
- macro.go
- mandate.go
- market.go
- market_bond.go
- market_read.go
- market_tape.go
- market_tape_history.go
- opportunities.go
- opportunities_exercises.go
- order.go
- order_tws.go
- orders.go
- origin.go
- policy.go
- policy_check.go
- policy_default.go
- policy_effective.go
- policy_ensure.go
- portfolio_plan.go
- positions.go
- positions_bonds.go
- process_scope.go
- proposals.go
- proposals_budget.go
- proposals_bundle.go
- proposals_cash_sweep.go
- proposals_currency_leveling.go
- proposals_display.go
- proposals_prepared.go
- proposals_queue.go
- push_delivery.go
- recon.go
- regime_stress.go
- reporting.go
- reporting_costs.go
- reporting_fx.go
- restart.go
- restart_launchd.go
- restart_quiesce.go
- risk_display.go
- rules.go
- rules_policy.go
- scorecard.go
- settings.go
- setups.go
- setups_display.go
- short_interest.go
- status.go
- status_opend.go
- stock_add.go
- stop.go
- strategies.go
- strategy_one.go
- technical.go
- terminal_linux.go
- trading.go
- update.go
- update_standard.go
- watchlist.go