67120478d8
- Extended file-display resolution to accept an immutable flag and suppress hashline anchors when immutable sources are requested. - Plumbed immutable propagation through ReadTool and SearchTool so internal URL reads and searches pass that context. - Added a regression test confirming artifact:// search output no longer includes hashline anchors.
46 lines
1.6 KiB
TypeScript
46 lines
1.6 KiB
TypeScript
/**
|
|
* Resolve line-display mode for file-like outputs (read, grep, @file mentions).
|
|
*/
|
|
|
|
import { resolveEditMode } from "./edit-mode";
|
|
|
|
export interface FileDisplayMode {
|
|
lineNumbers: boolean;
|
|
hashLines: boolean;
|
|
}
|
|
|
|
/** Session-like object providing settings and tool availability for display mode resolution. */
|
|
export interface FileDisplayModeSession {
|
|
/** Whether the edit tool is available. Hashlines are suppressed without it. */
|
|
hasEditTool?: boolean;
|
|
settings: {
|
|
get(key: "readLineNumbers" | "readHashLines" | "edit.mode"): unknown;
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Computes effective line display mode from session settings/env.
|
|
* Hashline mode takes precedence and implies line-addressed output everywhere.
|
|
* Hashlines are suppressed when the edit tool is not available (e.g. explore agents),
|
|
* when the caller signals a `raw` read, and when the source is `immutable`
|
|
* (e.g. internal URLs like artifact://, agent://, memory:// — there is no edit
|
|
* path that could consume the anchors). Raw output is returned as-is.
|
|
*/
|
|
export function resolveFileDisplayMode(
|
|
session: FileDisplayModeSession,
|
|
options?: { raw?: boolean; immutable?: boolean },
|
|
): FileDisplayMode {
|
|
const { settings } = session;
|
|
const hasEditTool = session.hasEditTool ?? true;
|
|
const editMode = resolveEditMode(session);
|
|
const usesHashLineAnchors = editMode === "hashline";
|
|
const raw = options?.raw === true;
|
|
const immutable = options?.immutable === true;
|
|
const hashLines =
|
|
!raw && !immutable && hasEditTool && usesHashLineAnchors && settings.get("readHashLines") !== false;
|
|
return {
|
|
hashLines,
|
|
lineNumbers: !raw && (hashLines || settings.get("readLineNumbers") === true),
|
|
};
|
|
}
|