/**
 * Classification and filtering of team-spawned sessions.
 *
 * Sessions launched by `agents teams` carry an 'sdk-cli' entrypoint and
 * optionally have a meta.json with handle/mode info. This module determines
 * whether a session is team-origin and splits session lists into visible
 * and hidden groups for the picker UI.
 */
import type { SessionMeta, TeamOrigin } from './types.js';
/**
 * Determine whether `session` was spawned by `agents teams`.
 *
 * Primary signal is `session.isTeamOrigin`, captured at scan time from the
 * JSONL `entrypoint` field ('sdk-cli' for team spawns, 'cli' for real CLI).
 * When a team meta.json exists we additionally enrich with handle/mode/team and
 * the orchestrator that spawned it — but its absence no longer demotes a
 * session: older team runs whose meta dir was cleaned up still get recognized
 * via the entrypoint flag.
 *
 * Returns the TeamOrigin metadata when the session is team-origin, or null
 * when it is a normal interactive session.
 */
export declare function classifyTeamSession(session: SessionMeta): TeamOrigin | null;
/**
 * A team name / handle as it is safe to render: a real string, terminal escapes
 * stripped, or undefined.
 *
 * These values reach the row and the preview pane, and for a peer's row they are
 * whatever JSON that machine sent — `parseRemoteList` copies the object through
 * without inspecting its fields, so neither the type nor the content is ours to
 * assume. A non-string `spawnedTeam` used to throw out of `teamBadge`, which runs
 * on every row, taking down the whole listing rather than one entry.
 */
export declare function safeTeamText(value: unknown): string | undefined;
/** Drop the cached teammate index — for tests that rewrite AGENTS_TEAMS_DIR. */
export declare function _resetTeamOriginIndex(): void;
/**
 * Attach `teamOrigin` to every team-spawned row in `sessions`, from the shared
 * teammate index rather than a stat per row.
 */
export declare function enrichTeamOrigins(sessions: SessionMeta[]): SessionMeta[];
/** Result of splitting sessions into visible and hidden (team-origin) groups. */
export interface FilterResult {
    visible: SessionMeta[];
    hiddenCount: number;
}
/**
 * Whether a listing scope must retain team-origin sessions.
 *
 * A routine owns every session produced during its run, including teammates and
 * SDK-launched children. Requiring callers to add `--teams` would make a routine
 * catalog incomplete and can make team-heavy routines appear to have no runs.
 */
export declare function shouldShowTeamSessions(filters: {
    teams?: boolean;
    routine?: boolean | string;
}): boolean;
/**
 * Split `sessions` into visible and hidden (team-origin) groups.
 * When `showTeams` is true every session is visible and `teamOrigin` is
 * populated on team sessions for display. When false, team sessions are
 * excluded and counted in `hiddenCount`.
 */
export declare function filterTeamSessions(sessions: SessionMeta[], showTeams: boolean): FilterResult;
/**
 * Whether a team-origin session is a real `agents teams` teammate or a bare SDK
 * spawn with no teammate record. The two share the `sdk-cli` entrypoint that
 * sets `isTeamOrigin`, so they are told apart by whether a `meta.json` teammate
 * record backs the origin ({@link TeamOrigin.source} === `'meta'`).
 *
 * `source` is newer than the rest of {@link TeamOrigin}, so a row that arrived
 * from a pre-`source` peer over the `--device` fan-out carries none. There the
 * meta-only fields settle it: the entrypoint fallback is a bare `{ handle }`, so
 * any `team` / `mode` / `parentSessionId` / `startedAt` means a real teammate
 * record produced it — otherwise a genuine teammate from an unupgraded peer
 * would be misfiled into the no-team bucket, the exact conflation this splits.
 */
export declare function teamRowKind(origin: TeamOrigin | undefined): 'teammate' | 'subagent';
/** A team-origin session with its resolved {@link TeamOrigin} guaranteed present. */
type TeamSession = SessionMeta & {
    teamOrigin: TeamOrigin;
};
/**
 * Key/label for the residual bucket — sessions flagged `isTeamOrigin` (an SDK /
 * `sdk-cli` entrypoint) that carry no teammate `meta.json`. In practice this is
 * headless `agents run` spawns and teammates whose team record aged out; a true
 * `Task` sub-agent's transcript is never indexed, so it cannot land here. Named
 * "(no team)" rather than "(sub-agents)" so the label matches what it holds.
 */
export declare const NO_TEAM_GROUP_KEY = "(no team)";
/** Key/label for teammates whose record carries no team name (`task_name`). */
export declare const UNNAMED_TEAM_KEY = "(unnamed team)";
/** One team's sessions, grouped for the `agents sessions --teams` view. */
export interface TeamSessionGroup {
    /**
     * The grouping key: the team name, {@link UNNAMED_TEAM_KEY} for teammates that
     * carry no `task_name`, or {@link NO_TEAM_GROUP_KEY} for the residual bucket.
     */
    key: string;
    /** A named team of `agents teams` teammates vs the catch-all no-team bucket. */
    kind: 'team' | 'noTeam';
    /** Team name when this is a named team, else undefined. */
    team?: string;
    /**
     * The orchestrator session id that spawned this team (`parent_session_id`),
     * when every teammate agrees on one. Undefined for the no-team bucket, an
     * unparented team, or a group whose teammates disagree.
     */
    spawnerSessionId?: string;
    /** The team's rows, newest-active first. */
    sessions: TeamSession[];
    /** Most-recent activity across the group, for ordering groups. */
    maxTs: string;
    /** Earliest spawn time across the group (`started_at`, else `timestamp`). */
    firstSpawnTs: string;
}
/**
 * Group team-origin sessions for the `--teams` view: each named team becomes one
 * group of its teammates, and every bare SDK spawn with no teammate record falls
 * into a single trailing {@link NO_TEAM_GROUP_KEY} bucket, so a real teammate and
 * a bare spawn are never shown as the same thing.
 *
 * Only rows with a resolved {@link TeamOrigin} participate (the caller has
 * already run {@link filterTeamSessions}); any non-team session is ignored.
 * Groups are ordered newest-active first; sub-agents always sort last. Pure —
 * unit-tested.
 */
export declare function groupSessionsByTeam(sessions: SessionMeta[]): TeamSessionGroup[];
export {};
