API Reference
Namespaces
Modules
Classes
Events
Global
Externals

Class: Cmux

Cmux ()


new Cmux()

Cmux — chart multiplexer and supervisor for multi-chart command orchestration.

Modeled after a process supervisor / PID 1: owns a table of registered chart "processes" ({ pid, stx, executor }), allocates pids, computes a foreground pid on demand, and routes @-addressed command strings to the correct Executor(s). It never constructs or touches an Executor it did not itself register — standalone executors built directly via stx.getExecutor() (e.g. headless consumers) are invisible to it.

Since:
  • 10.6.0

Methods


deregister(stx)

Deregisters a chart, looked up by its CIQ.ChartEngine instance rather than by pid, since that's what callers (e.g. Multichart.removeChart()) have on hand.

Parameters:
Name Type Description
stx object

The chart's CIQ.ChartEngine instance.

Returns:

The pid that was removed, or null if stx was never registered.

Type
number | null

<async> exec(input)

Dispatches a command line, resolving any @-target prefix.

  • No target: runs against the current foreground pid.
  • @N: runs against pid N only; unknown pid is a plain error, no Executor is invoked. Side-effect-free — never changes foreground.
  • @all: broadcasts to every registered pid concurrently. Targets are independent siblings: one's failure never cancels the others. Result is a pid-keyed status map, not a single collapsed status.
Parameters:
Name Type Description
input string

The raw command line, with optional @-target.

Returns:

The Executor status for a single target, or a pid-keyed status map for @all.

Type
Promise.<(number|Record.<number, number>)>

get(pid)

Looks up a registered chart by pid, e.g. for callers (like the mc registry command) that need the underlying CIQ.ChartEngine to act on a specific chart rather than merely dispatching a command to it.

Parameters:
Name Type Description
pid number

The pid to look up.

Returns:

The entry for pid, or null if it isn't registered.

Type
Cmux~Entry | null

list()

Lists the currently addressable pids, in ascending (registration) order, along with which one is currently the foreground target. A minimal stand-in for a future ps/jobs-style introspection command

Returns:

The addressable pids and current foreground pid.

Type
Cmux~List

register(stx, terminal)

Registers a chart, constructing its Executor and composing its echo/log as an attribution-prefixed wrapper around the terminal's own echo/log. The prefix is only added while more than one chart is registered — checked at call time, not registration time, so a chart registered while alone (single-chart, or the only survivor after siblings are reaped) produces unprefixed output identical to a standalone Executor, and only gains attribution once a second chart actually makes output ambiguous.

Parameters:
Name Type Description
stx object

The chart's CIQ.ChartEngine instance.

terminal object

The one shared terminal (<cq-cli> instance) whose echo/log attributed output is ultimately relayed to.

Returns:

The pid assigned to this chart.

Type
number

parse(input)

Parses a raw command line for a leading @-target, without resolving it against any process table. This is the single authoritative parser for the @-addressing grammar: both Cmux#exec (which resolves target into real pids) and external callers that merely need the command text (e.g. cli.js's command-validity check) parse through here, so the syntax is defined in exactly one place.

Parameters:
Name Type Description
input string

The raw command line, with optional @-target.

Returns:

The parsed target and command.

Type
Cmux~ParseResult

Type Definitions


Entry

A registered chart, as returned by Cmux#get.

Type:
  • object
Properties:
Name Type Description
pid number

The pid assigned to this chart.

stx object

The chart's CIQ.ChartEngine instance.


List

The currently addressable pids and foreground target, as returned by Cmux#list.

Type:
  • object
Properties:
Name Type Description
pids Array.<number>

The currently addressable pids, in registration order.

foreground number | null

The current foreground pid, or null if nothing is registered.


ParseResult

The result of parsing a raw command line for a leading @-target.

Type:
  • object
Properties:
Name Type Description
target null | "all" | number

null when untargeted (the command should run against whatever the caller considers current/foreground), "all" for a broadcast, or a pid number for a single target.

command string

The input with any target prefix stripped.