/** * instances Command - Discover and manage a worktree's agent-instance roster * Issue #1000: CLI parity for the "1 agent, multiple sessions" feature (#868/#869) * * commandmate instances # list (default) * commandmate instances add --agent [--alias ] * commandmate instances remove [--kill] * commandmate instances alias * commandmate instances kill */ import { Command } from 'commander'; import { ApiClient } from '../utils/api-client'; /** * How the caller wants a roster contradiction handled (Issue #1925, DR3-015). * * `strict` is for commands with a side effect: refuse rather than pick one of * two contradicting declarations and type into whichever session that names. * `read-only` is for `capture`, which resolves in order to *look* — and which * `.claude/skills/orchestrate-monitor/scripts/monitor.sh` polls in an * unbounded loop, skipping the poll and never advancing its idle streak * whenever capture exits non-zero. A worker whose `--agent` disagrees with the * roster would leave that loop silently spinning forever. */ export type InstanceConflictMode = 'strict' | 'read-only'; /** * Resolve which CLI tool backs `instanceId`. Shared by every command that * targets an instance: `send`, `respond`, `capture` and `auto-yes`. * * Issue #1925 turned this into a thin client over the server's resolver * (`GET /api/worktrees/:id/resolve-target`). It used to resolve locally, with * two of the server's four precedence stages — no primary anchor — so the same * `--instance codex` against a roster that never registered `codex` resolved to * codex on the server and to the worktree default here. The tool id is half the * tmux session name, so two answers meant two sessions. * * The roster still wins over `--agent`: it is the user-maintained declaration * of what a named instance is. What changed is that `capture` no longer dies of * the contradiction (see {@link InstanceConflictMode}). * * @param client - API client aimed at the server * @param worktreeId - Worktree ID * @param instanceId - The `--instance` value * @param requestedAgent - The `--agent` value, if the user gave one * @param mode - What a roster contradiction means for this caller * @returns the CLI tool to send, or undefined to let an older server decide */ export declare function resolveInstanceCliTool(client: ApiClient, worktreeId: string, instanceId: string, requestedAgent: string | undefined, mode?: InstanceConflictMode): Promise; /** * Whether `value` is something the server could resolve to an instance. * * An instance id, or an alias. Issue #2376 widened `--instance` to accept the * second because it is the only name a human has for `codex-2`: the roster pane * shows `Codex 2`, `commandmate instances ` prints it in the ALIAS column, * and `--instance "Codex 2"` used to be rejected here — before any request — * with "must be an alphanumeric identifier". * * The check is deliberately loose: an alias is free text (`レビュー担当`), and * the authority on whether one EXISTS is the roster, which only the server has. * All this rules out is a value no alias can be — empty, longer than the alias * field allows, or carrying control characters. * * @param value - The `--instance` value as given */ export declare function isInstanceSelector(value: string): boolean; /** * The sentence appended to every command's `--instance` help (Issue #2376). * * Kept beside the validator that accepts the form, not in * `config/agent-target-options.ts`, so the help and the check cannot drift: the * day the alias stage is removed, both go together. */ export declare const INSTANCE_ALIAS_HELP_SUFFIX: string; /** The sentence `--instance` is rejected with. One place, five commands. */ export declare const INSTANCE_SELECTOR_ERROR: string; /** A resolved target: which agent, and which instance id to address it by. */ export interface ResolvedInstanceTarget { /** The agent to send as, or undefined to let an older server decide. */ cliToolId: string | undefined; /** * The instance id to put in the request, or undefined when the caller named * no instance at all. * * **Not the value the user typed.** `--instance "Codex 2"` resolves here to * `codex-2`, and every downstream body/query must carry the resolved id: the * alias is a label the roster holds, and no other route knows how to read one. * * Undefined for a caller that passed no selector, even though the server * answers with the worktree's default instance: a request that named no * instance must keep not naming one, or `capture --pane` would start * pinning a session it was deliberately leaving to the server. */ instanceId: string | undefined; } /** * Resolve `--instance` — id or alias — to the agent and instance id to address. * * The one resolution path, as Issue #1925 established: the server answers, * `resolveSessionTarget` asks, and this adds only what a CLI caller has to do * with the two answers it can get back that a browser does not care about — a * roster contradiction ({@link InstanceConflictMode}) and, since Issue #2376, an * alias that names more than one row. * * The ambiguity is exit 2 with every candidate printed, never a pick: two rows * called `Codex` are two different tmux sessions, and choosing one for the * operator is how a message reaches the wrong agent silently. * * @param client - API client aimed at the server * @param worktreeId - Worktree ID * @param selector - The `--instance` value (an instance id or a roster alias), * or undefined for a caller that resolves only to learn the agent * @param requestedAgent - The `--agent` value, if the user gave one * @param mode - What a roster contradiction means for this caller */ export declare function resolveInstanceTarget(client: ApiClient, worktreeId: string, selector: string | undefined, requestedAgent: string | undefined, mode?: InstanceConflictMode): Promise; export declare function createInstancesCommand(): Command; //# sourceMappingURL=instances.d.ts.map