import type { ProbedRecord } from "../../logsViewer/session/registry.js"; import type { FocusReply } from "../../logsViewer/session/protocol.js"; import type { SessionRecord } from "../../logsViewer/session/record.js"; import type { CommentAuthor } from "../../runDirectory/comments.js"; import type { CommentsStore } from "../../runDirectory/commentsStore.js"; export type TargetArgs = { /** `--log`: the statelog to act on, which also picks the viewer on it. */ log?: string; /** `--trace`, a full id or unique prefix; resolved by the command. */ traceId?: string; /** A row argument: a full address, or a bare row id. */ row?: string; }; export type LiveSession = { record: SessionRecord; focus: FocusReply; socketPath: string; }; export type Target = { kind: "session"; session: LiveSession; /** Undefined when the viewer has no comments file (stdin). */ store: CommentsStore | undefined; /** `--trace`, else the viewer's current trace. A full address wins * over both once the command reads the log. */ traceId: string; /** The row argument as given: an address or a bare row id. Which it * is can only be told against the log's trace ids, so the command * decides (`locate` in commands.ts). */ rowRef: string | undefined; } | { kind: "files"; logPath: string; store: CommentsStore; traceId: string | undefined; rowRef: string | undefined; } | { kind: "refused"; reason: string; }; export type LogDeps = { cwd: string; /** What `--log` names on disk, so a run directory can stand for its * statelog and a typo is refused before anything reads it. */ pathKind(absolutePath: string): "file" | "directory" | "missing"; /** The run directories inside a directory that is not one itself, so a * directory of runs is refused with a pointer to the explorer. */ childRunDirectories(dir: string): string[]; /** `log.logFile` from `agency.json`, read only when `--log` is absent, * so a broken config cannot stop a command that named its log. An * empty string counts as unset: `--log stdout` writes `""` there on * purpose to cancel a configured file. */ configuredLog(): string | undefined; }; export type TargetDeps = LogDeps & { socketPathFor(record: SessionRecord): string; openStore(commentsPath: string, author: CommentAuthor): CommentsStore; author: CommentAuthor; }; export type LogChoice = { kind: "session"; session: LiveSession; } | { kind: "files"; logPath: string; } | { kind: "refused"; reason: string; }; export declare const NO_LOG_GIVEN = "No log given. Pass --log , set log.logFile in agency.json, or open a viewer with `agency logs `."; export declare function resolveTarget(args: TargetArgs, probed: readonly ProbedRecord[], deps: TargetDeps): Target; /** The viewers that answered the probe. */ export declare function liveSessions(probed: readonly ProbedRecord[], socketPathFor: (record: SessionRecord) => string): LiveSession[]; /** * The log a command acts on, in this order: * * 1. `--log`, which also picks the viewer that has that log open. * 2. The one open viewer. Several open viewers are refused with "say * which", and the configured log never overrides that. * 3. The log `agency.json` names, when no viewer is open. * 4. A refusal that says all three ways forward. * * A path is what `agency logs` takes: a statelog file or a run directory, * which stands for the `statelog.jsonl` inside it. A directory of run * directories is refused with a pointer to the runs explorer, and a path * that is not there is refused, so no command reads a log that does not * exist. */ export declare function chooseLog(log: string | undefined, live: LiveSession[], deps: LogDeps): LogChoice;