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.ChartEngineinstance rather than by pid, since that's what callers (e.g.Multichart.removeChart()) have on hand.Parameters:
Name Type Description stxobject The chart's
CIQ.ChartEngineinstance.Returns:
The pid that was removed, or null if
stxwas 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 inputstring 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
mcregistry command) that need the underlyingCIQ.ChartEngineto act on a specific chart rather than merely dispatching a command to it.Parameters:
Name Type Description pidnumber 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 commandReturns:
The addressable pids and current foreground pid.
- Type
- Cmux~List
-
register(stx, terminal)
-
Registers a chart, constructing its Executor and composing its
echo/logas an attribution-prefixed wrapper around the terminal's ownecho/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 stxobject The chart's
CIQ.ChartEngineinstance.terminalobject The one shared terminal (
<cq-cli>instance) whoseecho/logattributed 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: bothCmux#exec(which resolvestargetinto 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 inputstring 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 pidnumber The pid assigned to this chart.
stxobject The chart's
CIQ.ChartEngineinstance. -
List
-
The currently addressable pids and foreground target, as returned by
Cmux#list.Type:
- object
Properties:
Name Type Description pidsArray.<number> The currently addressable pids, in registration order.
foregroundnumber | 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 targetnull | "all" | number nullwhen untargeted (the command should run against whatever the caller considers current/foreground),"all"for a broadcast, or a pid number for a single target.commandstring The input with any target prefix stripped.
