UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

717 lines • 56.2 kB
import { type DenyFace } from "./read-deny.js";
import type { RefusalEcho } from "../../core/refusal-echo.js";
import { type HomeViewSource } from "./read-deny-home.js";
import type { AssertAllKeysHandled } from "../../core/ask-origin.js";
import type { ExecutionEnv } from "../../internal/harness-types.js";
import { protectivePathTargetOf, type ToolCallLike } from "../../core/tool-registry.js";
import { familyFor, foldDriveLetter, foldRedundantPathSegments, isAbsoluteForFamily, isBareDriveSpelling, isWinFormPath, normalizeAbsPathLexically, pathFamilyOf, type PathFamily } from "../../core/unc-spelling.js";
export { familyFor, foldDriveLetter, foldRedundantPathSegments, isAbsoluteForFamily, isBareDriveSpelling, isWinFormPath, normalizeAbsPathLexically, pathFamilyOf, type PathFamily };
export { isDriveAbsoluteSpelling } from "@sema-agent/primitives";
/**
 * The WRITE TARGET of a path-confinable write call, tool-aware — single source for every gate that
 * confines a write target, same discipline as {@link fileArgPath} (core/tool-registry.ts):
 *
 *  · canonical `NotebookEdit` → `notebook_path` FIRST, `file_path`/`path` only as fallback. The tool
 *    itself writes `notebook_path`; its schema tolerates extra keys, so a stray/decoy `file_path` on a
 *    NotebookEdit call must never become the judged target while the real write lands elsewhere
 *    (a gate that read `file_path` first would confine the decoy — the hole).
 *  · every other tool → `file_path`/`path` first ({@link fileArgPath}), `notebook_path` as the
 *    historical fallback (unchanged behavior for the pre-existing gate callers).
 *
 * `canonicalName` is the tool name as mounted, raw: there is no legacy normalizer, and this module
 * stays dependency-free of the alias table — "NotebookEdit" is the canonical CC name and old→new
 * normalization is identity for it.
 */
export declare function writeTargetPath(call: ToolCallLike, pt?: ReturnType<typeof protectivePathTargetOf>): string | undefined;
/**
 * EVERY target a call names — the reader for a fence that may meet a declared read, in the read station's one reading
 * ({@link declaredReadValuesOf}): a declared read slot is every non-empty string its one reading carries (never falling back
 * to {@link writeTargetPath}); any other call is the one target {@link writeTargetPath} reads. `[]` ⇔ no resolvable path.
 */
export declare function targetPathsOf(call: ToolCallLike, pt?: ReturnType<typeof protectivePathTargetOf>): readonly string[];
/**
 * The "hand" file tools' safety invariants, ported from CC's `FileEditTool`: without these a weak
 * model blind-edits / overwrites files (a safety property, not polish). This module is the
 * pure/testable core (path resolution + the three edit invariants + content hashing); the tools in
 * this dir compose it. Per-task state and the execution env are passed in (factory-closure wiring),
 * never read from a shared/global.
 */
/** What we remember about a file the agent has read. */
export interface ReadEntry {
    /** SHA-256 of the content at read time. Staleness is detected by content hash, NOT mtime — mtime is
     *  unreliable across containers/volumes/NFS and across a suspend→resume on another replica. */
    hash: string;
    /** Total line count at read time, and whether the read was truncated (for the edit truncation hint). */
    totalLines: number;
    truncated: boolean;
    /** CC `isPartialView` parity: set ONLY when the auto-pagination branch fires — the model asked for
     *  the file by DEFAULT (no explicit offset/limit) and the token cap truncated it anyway. An EXPLICIT
     *  offset/limit slice that fits under the cap is NEVER marked this way, even though it is equally
     *  "not the whole file". Deliberately narrower than {@link truncated} above,
     *  which also fires for a fully-intentional, successful slice read (`start>1 || end<total`) — folding
     *  THIS flag into that broader one would make the Read tool's too-large refusal's documented promise
     *  ("pass an explicit offset/limit to read a slice") false: a model paging
     *  through an oversized file on purpose would never be able to satisfy {@link requireRead} again. Optional/
     *  additive: undefined on every non-Read write-back (Write/Edit re-record the file they just fully wrote)
     *  and on every seeded/attachment entry — those are never partial by construction. */
    isPartialView?: boolean;
    /** The line window actually served to the model on the last read. Optional/additive: undefined (an entry seeded
     *  from an older checkpoint, a write-back, a seed) claims the whole file. */
    view?: {
        start: number;
        end: number;
    };
    /** Millisecond timestamp of the last read/write-back that recorded this entry: the post-compaction
     *  attachment picks the most RECENTLY read files, the way CC sorts readFileState by timestamp.
     *  Optional/additive: undefined (an entry seeded from an older checkpoint) sorts last, never breaks. */
    lastReadAt?: number;
    /** TRUE when the Runner pre-seeded this entry because the file's FULL disk-verbatim text is in the
     *  system-prompt lane of this leg (the one meaning: today the memory engine's materialized index; an
     *  instruction file is never seeded — the instruction-file lane's frame records its own entry): the file passes
     *  read-before-edit. Any real
     *  Read / edit write-back records a FRESH entry without this flag. (Whether a request carries an attachment frame
     *  of the file as the "already in your context" sentence is the request projection's, against the leg's seed table;
     *  a Read of it is its contents.)
     *  Optional/additive: absent = normal entry. */
    seededFromContext?: boolean;
    /** The WITNESS SET: every transmission that still carries the body this entry stands for — each tool call whose RESULT
     *  carried it, each attachment frame that did (`attachmentTransmissionId`), oldest first. The entry retires when the
     *  last of them leaves the request (a stale-result clear, a trim, the budget arm's pointer: `applyContextShrinkToReadFileState`,
     *  `transmissions-gone` arm); one leaving while another stays leaves the entry standing. A delivery of the SAME body
     *  and window joins the set; a delivery of another body (the file changed, another window) starts it over. It is an
     *  approximation of "the model can see the body" with two error directions: a path that does not report its
     *  departure keeps a witness (the edit gate lets an edit through), a reused call id retires one entry too many (the
     *  gate asks for a fresh read). Recorded only by the deliveries that TRANSMIT a body (a Read result or a frame
     *  replayed from the transcript included) — a write-back's content is the model's own arguments and a
     *  context-seeded entry never rode a message, so neither carries a set and neither is retired by it. Optional/additive:
     *  absent (an older checkpoint's entry) never matches. */
    witnesses?: readonly string[];
}
/** The head of an attachment frame's transmission id but an instruction file's, which spells its own word (a witness in
 *  {@link ReadEntry.witnesses} for a frame's delivery; minted by `attachmentTransmissionId`; an instruction file's frame spells its origin's word in its place) — a tool call's
 *  id never starts with it. */
export declare const FRAME_TRANSMISSION_PREFIX = "attachment:";
/** Per-task record of which files have been read, keyed by canonical path: owned by prepare-task,
 *  closure-captured by the tools, and serialized into the durable checkpoint. */
export type ReadFileState = Map<string, ReadEntry>;
/** SHA-256 hex of UTF-8 content — the staleness/identity key. */
export declare function sha256(content: string): string;
/** A failed path resolution / invariant check, surfaced to the model as a self-correctable tool error. */
export interface FsViolation {
    code: "path_not_in_root" | "not_read" | "stale" | "ambiguous_edit" | "invalid" | "read_path_denied" | "write_path_denied";
    /** Set on the `not_read` violation raised by an AUTO-TRUNCATED read
     *  ({@link ReadEntry.isPartialView}) rather than by a never-read file. Both carry the same
     *  message; only this one needs {@link PARTIAL_VIEW_READ_ESCAPE_HINT} appended, because for it a plain
     *  re-read is a fixpoint. */
    partialView?: true;
    /** Set on `path_not_in_root` and `read_path_denied` — the CANONICAL key the
     *  refused path resolved to (symlinks followed, tracked cwd applied), i.e. the value the fence
     *  actually judged. Rides into the tool result's `details` (see {@link violationDetails}) so a
     *  consumer can count/aggregate boundary refusals from fields instead of regexing the prose. */
    target?: string;
    /** Set ONLY on `path_not_in_root` — the containment roots in effect (primary first,
     *  then additionalDirectories), canonical form. */
    roots?: readonly string[];
    /** Set on `read_path_denied` and `write_path_denied` — the deny-list pattern (verbatim entry text)
     *  the judged target matched. Absent on the refusal of a deny judgment that could not finish (a home view nobody could
     *  read, read-deny-home.ts `HomeView.unread`): no row matched, so none is named and no deny card is minted. */
    pattern?: string;
    /** The literals quoted by a deny refusal sentence, minted with the sentence ({@link readDenyRefusal}). */
    echoed?: readonly RefusalEcho[];
    message: string;
}
/**
 * Is a spelling relative in EVERY family — neither `/`- nor `\`-rooted and carrying no drive letter (not even the
 * drive-relative `C:x`)? The tamper check of a recorded relative key reads this (a record that is absolute, rooted or
 * drive-bearing in ANY family is refused there): the opposite stance from {@link isAbsoluteForFamily}, which answers
 * one family's question, so it is a separate, named predicate rather than a mode of that one.
 */
export declare function relativeInEveryFamily(p: string): boolean;
/** Does a spelling open with a drive letter and its colon — `C:\x`, `C:/x` and the drive-relative `C:x` alike? */
export declare function startsWithDriveLetter(p: string): boolean;
/** Does this absolute spelling name the opening process's STANDARD INPUT (`/dev/stdin`, `/dev/fd/0`, `/proc/<pid>/fd/0`),
 *  folded lexically first (`/dev/./stdin`, `/dev//fd/0`)? */
export declare function namesStandardInput(path: string): boolean;
export declare function isProcSensitiveFile(key: string): boolean;
export declare function holdsProcSensitiveFile(dir: string): boolean;
export declare function ownProcessSpelling(spelled: string): string | undefined;
export declare function belowOwnProcessLink(spelled: string, walks?: boolean): boolean;
export declare function isBareOwnDescriptorLink(spelled: string): boolean;
/**
 * Expand a LEADING `~` (bare, or followed by a separator of either family) against `home`; every other
 * spelling is returned untouched — a `~` anywhere but the front is an ordinary filename character.
 *
 * Lives here for the same reason `isWinFormPath` does: it is a path-FAMILY decision (which characters
 * end the first component), and the domain gate holds this module as the one home for those. Callers
 * that need it: the sensitive-path guard's data-root resolution, and — spelled privately for now —
 * `tool-policy.ts`'s `lexicalPath`. NOT a resolution of relative paths: a caller that also needs that
 * says so with its own `resolve`, because the two consumers of this value disagree about which cwd a
 * relative spelling belongs to and that disagreement is theirs to state, not this helper's to hide.
 */
export declare function expandHomeTilde(p: string, home: string): string;
/** True for a device/special path that must never be opened (pure path check — no I/O). The exact
 *  12-entry device blocklist and the `/proc/**\/fd/{0,1,2}` hang layer are CC's own, no sema addition;
 *  the sensitive-file layer's six FILE NAMES are CC's, its unbounded `/proc/**\/…` DEPTH is a sema
 *  widening (see {@link isProcSensitiveFile}). */
export declare function isBlockedDevicePath(key: string): boolean;
/** True if `path`'s extension is a known binary format (pure check — no I/O). Used by read_file and grep. */
export declare function hasBinaryExtension(path: string): boolean;
/** The MIME type to return an image file AS (a visual `ImageContent` block), or `undefined` if `path` is not a
 *  Read-supported image. Pure — no I/O. */
export declare function imageMimeForRead(path: string): string | undefined;
/** One contiguous byte pattern that must appear at a fixed offset for its signature to match. */
export interface BinaryMagicSegment {
    /** Byte offset the pattern starts at — 0 for a leading signature, 257 for tar's `ustar`, and so on. */
    readonly offset: number;
    /** The exact bytes that must appear there. */
    readonly bytes: readonly number[];
}
/** A file-format signature: EVERY segment must match for the format to be claimed. */
export interface BinaryMagicSignature {
    /** Human-readable format label. It lands verbatim in the Read refusal, so it names what the file IS,
     *  never the extension it happened to be carrying. */
    readonly format: string;
    /** All segments must match. A second segment exists only to disambiguate a prefix that also spells
     *  plausible text (`BM`, `RIFF`, `FORM`): the payload word at the later offset is what decides. */
    readonly segments: readonly BinaryMagicSegment[];
}
/**
 * Magic-byte criteria for the formats {@link hasBinaryExtension} names. That list carries 103
 * extensions; without this table only PDF (`pdfMagicMatches`, in the PDF lane) and the four API image
 * formats (`imageMagicMatches`, core/image-admission.ts) have a content criterion, so for every other listed format the
 * NAME is the only evidence available. Where the content IS reachable that leaves identification to
 * the statistical fallback ({@link isBinaryContent}),
 * which samples the first 8192 decoded characters and passes anything whose control-character ratio
 * stays under 10% — a short archive/executable header followed by printable payload clears that bar
 * and gets delivered as text.
 *
 * Shape: pure data, one table, `offset + bytes`. Adding a format is a row; the matcher
 * ({@link binaryMagicFormat}) never changes. Rows are grouped by family so the next diff stays readable.
 *
 * Admission rule — a row exists only where the signature is DECIDABLE. A short ASCII prefix that also
 * opens ordinary prose is admitted only with a disambiguating second segment (`BM` + the zeroed
 * reserved fields, `RIFF`/`FORM` + the payload word); formats whose only fixed marker is such a prefix
 * are deliberately absent, because a false positive here makes a real text file unreadable — the exact
 * harm the name-only refusal was retired for. Absent on that ground: DOS/PE (`MZ`, with the PE header
 * at a variable offset), SWF (`FWS`/`CWS` + a wide version byte), Blender (`BLENDER`), `.pyc` (a
 * per-release magic), and PostScript/EPS (genuinely text). They stay covered by the statistical sniff.
 *
 * Converged consumer: the WebFetch lane (`tools/web.ts`'s `sniffBinarySignature`) used to carry its own
 * private eight-format if-chain for HTTP bodies; it now reads this table via {@link binaryMagicFormat}
 * (PDF handled the same way this table's own callers handle it — via `pdfMagicMatches`, not a row here).
 */
export declare const BINARY_MAGIC_SIGNATURES: readonly BinaryMagicSignature[];
/**
 * Identify `bytes` by its file signature — the format label, or `undefined` when no row in
 * {@link BINARY_MAGIC_SIGNATURES} matches. Pure — no I/O, and name-blind by construction (nothing here
 * looks at a path), so it can be asked in either direction: a mis-named binary is caught, and a listed
 * extension holding real text is NOT claimed.
 */
export declare function binaryMagicFormat(bytes: Uint8Array): string | undefined;
/**
 * Content sniff for binary data (CC `isBinaryContent` parity): a NUL byte,
 * or more than 10% non-printable characters in the sample, means binary. Second layer behind
 * {@link hasBinaryExtension} — catches extension-less or mis-named binaries (a `Dockerfile` that is really
 * a compiled blob) that would otherwise be read as mojibake. Plain text (incl. UTF-8, tabs/newlines) passes.
 */
export declare function isBinaryContent(sample: string): boolean;
/**
 * The UNC/network-path predicate (`n.startsWith("\\\\") || n.startsWith("//")`). Pure.
 *
 * In CC this test is an EARLY ALLOW — it skips the binary-extension and device checks that follow it —
 * and CC applies it to the NORMALIZED path, not the raw argument. See {@link canonicalizeTarget} for
 * how sema mirrors that and for the two deliberate differences. This function stays a pure spelling
 * test with no verdict of its own.
 */
export declare function isUncPath(path: string): boolean;
/**
 * True when a WIN-FORM spelling carries a component Win32's own normalization would trim — a trailing dot
 * or space on anything but the `.`/`..` specials (the same client-side strip {@link uncCanonicalKey}
 * folds, stated once and read here rather than re-derived).
 *
 * Such a spelling is an ALIAS: `x. ` and `x` name ONE directory to the OS and two different strings to a
 * lexical comparator. A caller that must reason about a spelling byte-wise — a directory offered to a
 * person as the thing to declare, a common-prefix cut between two operands — cannot pick one of the two
 * readings on the person's behalf, so it withholds. POSIX paths are never aliased this way: a trailing dot
 * or space there is an ordinary filename character.
 *
 * The UNC ANCHOR is exempt for the reason the key minter states: a host's trailing dot is DNS (the FQDN
 * root) and share-name normalization is the server's business; neither is the client-side strip.
 */
export declare function hasWin32AliasedComponent(p: string): boolean;
/** The refusal words of {@link win32NamespaceScreen} — a closed set (docs/CLOSED-SETS.md). */
export declare const WIN32_NAMESPACE_REFUSALS: readonly ["device_namespace", "unmappable_namespace", "unc_on_posix_tree", "drive_relative"];
export type Win32NamespaceRefusal = (typeof WIN32_NAMESPACE_REFUSALS)[number];
/** What each refusal word says about the spelling (the message clause after `path "…" `). */
export declare const WIN32_NAMESPACE_REFUSAL_TEXT: {
    readonly device_namespace: "is a Win32 device-namespace path (\\\\.\\ names a raw device object, not a file)";
    readonly unmappable_namespace: "is a Win32 extended-length namespace path with no DOS-path equivalent (only \\\\?\\<drive>: and \\\\?\\UNC\\ forms name files)";
    readonly unc_on_posix_tree: "is a UNC (\\\\host\\share) spelling, which names no file on a POSIX tree";
    readonly drive_relative: "is drive-relative (a drive letter with no separator after the colon), a location no tree can locate";
};
/** The fence over the text table: `never` while every refusal word has a row. */
export type NamespaceRefusalTextCoversEveryWord = AssertAllKeysHandled<Exclude<Win32NamespaceRefusal, keyof typeof WIN32_NAMESPACE_REFUSAL_TEXT>>;
/**
 * The Win32 namespace screen — run on every model-spelled target BEFORE the family join, at every site
 * (the fs throat, the effective-target reader, the rule side, the glob splitter), so one spelling is
 * refused with one word everywhere. `\\.\` ⇒ `device_namespace` (every family); `\\?\` mappable ⇒ the
 * stripped spelling, which is screened ON (a `\\?\UNC\…` on a POSIX tree still refuses), unmappable ⇒
 * `unmappable_namespace` (every family); a backslash UNC ⇒ passes under `win`, `unc_on_posix_tree` under
 * `posix` (the canonicalizer's refusal boundary on POSIX trees is preserved: the family rule governs what
 * is admitted, never what was already refused); `C:rel` under `win` ⇒ `drive_relative`. A treeless call
 * passes a UNC spelling through — the identity then reads it as relative, as before.
 */
export declare function win32NamespaceScreen(spelled: string, family: PathFamily | undefined): {
    readonly ok: true;
    readonly spelled: string;
} | {
    readonly ok: false;
    readonly refuse: Win32NamespaceRefusal;
};
declare const PATH_IDENTITY: unique symbol;
/**
 * The ONE comparison form of an absolute path (upstream's normal form): posix = the lexical-normal
 * `/`-rooted path; win = `/c/rest` for a drive (letter lower-cased), `//host/share/rest` for UNC, `\`
 * folded to `/`, `.`/`..` folded with the anchor preserved. A COMPARISON form — never a path to open, never
 * compared against a native `C:\…` string. Branded: a spelling is not an identity until {@link pathIdentityOf}
 * has read it.
 */
export type PathIdentity = string & {
    readonly [PATH_IDENTITY]: true;
};
/** Why a spelling has no identity: a namespace refusal, `relative` (join it to a base first), or
 *  `unanchored` (a win `/x` with no tree root to take a drive from). */
export type PathIdentityRefusal = Win32NamespaceRefusal | "relative" | "unanchored";
export type PathIdentityReading = {
    readonly ok: true;
    readonly identity: PathIdentity;
} | {
    readonly ok: false;
    readonly reason: PathIdentityRefusal;
};
/**
 * The identity of an ABSOLUTE spelling under the family ({@link PathIdentity}). `anchor` is the tree's root
 * (or cwd) spelling: under `win` a `/`-rooted spelling whose first segment is not a drive letter
 * (`/proj/x`) anchors on the root's drive or share, as `path.win32.resolve` anchors it on the current
 * drive; `/c/x` and `/C:/x` are drive spellings (the cygdrive form and the rule grammar's `/`+body), and
 * `/\\host\share\x` is the grammar's prefix before a UNC. A relative spelling is `relative` — callers join
 * it to a base FIRST. A treeless call (`family` undefined) reads only the anchor-free `/`-rooted form, as
 * the POSIX identity; every other spelling names nothing, which is what a missing base answered before.
 */
export declare function pathIdentityOf(spelled: string, family: PathFamily | undefined, anchor?: string): PathIdentityReading;
/** Is the identity a UNC one (`//host/share/…`)? Identities compare by anchor kind first: a UNC identity is
 *  never under a rooted one and vice versa (upstream's shape parity). */
export declare function isUncIdentity(identity: PathIdentity): boolean;
/** Is `s` already an identity under the family — the identity function is the identity on it? The
 *  runtime twin of the brand for values that arrive from outside the type system. */
export declare function isPathIdentity(s: string, family: PathFamily | undefined): s is PathIdentity;
/** Is the identity a DIRECTORY a rule may speak for — anything but the tree's bare root (`/`, a drive root
 *  `/c`, a share root `//host/share`), which admits nothing? */
export declare function isIdentityDir(identity: PathIdentity, family: PathFamily | undefined): boolean;
/** A spelling of an identity that the environment resolves as a path of the family, and that reads as that family on its
 *  own ({@link isWinFormPath}) — the one way back from the comparison form: posix, the identity; a win drive identity
 *  `/c/rest` ⇒ `c:\rest`; a win UNC identity `//host/share/rest` ⇒ `\\host\share\rest`. */
export declare function spellingOfIdentity(identity: PathIdentity, family: PathFamily | undefined): string;
/** Does the spelling carry a `.` or `..` segment under the family's separators (a backslash is a name byte on
 *  POSIX)? A rule body with one admits nothing: folding it could make it name a second directory. */
export declare function carriesDotSegment(spelled: string, family: PathFamily | undefined): boolean;
/** A model-spelled path bounded for error text (the spelling is unbounded input). */
export declare function clipSpelling(spelled: string): string;
/**
 * The SHELL's spelling of a drive on a win tree. The win32 adapter runs Git for Windows bash (the MSYS line — the only
 * shells its discovery answers there), which names drive X's root `/x`, either case. A `/`-rooted spelling is read the way
 * that shell reads it: a leading run of three or more `/` is one `/` (exactly two name a UNC or a server there); a backslash
 * separates too; the first segment, ONE ASCII letter, is that drive: `/c/rest` and `/C/rest` ⇒ `C:\rest`, `/c` ⇒ `C:\`. A `..`
 * inside the drive is kept (the walk resolves a link before it steps up, as for every spelling); a `..` that climbs above the
 * drive's root reaches the emulation's own root `/`, so such a spelling is folded first, as a POSIX path (`/c/../d/f` is `/d/f`).
 * `undefined` for every other spelling — the emulation's own tree (`/etc`, `/tmp`, `/cygdrive/…`), a UNC, a backslash-rooted
 * one (Win32's current-drive form) — and on any tree that is not win, where `/c/x` is an ordinary path. The family is the
 * tree's, never the spelling's. The ONE reading of that shell's drive spelling: the shell operand resolver (with
 * {@link shellAnchoredSpellingOf}), the tracked working directory the shell reports, and {@link isShellRootedSpellingUnmapped}.
 */
export declare function shellDriveSpellingOf(family: PathFamily | undefined, spelled: string): string | undefined;
/** The SHELL's drive spelling (`/x/…`, read as {@link shellDriveSpellingOf} reads its lead) as the drive path it walks, every
 *  `..` KEPT as written — whether one climbs above the drive's root is the walk's to find (a link on the way decides it), and a
 *  reader that folds reads it as any drive path the shell anchored ({@link shellAnchoredSpellingOf}). `undefined` where the
 *  first segment is no drive letter, and on any tree that is not win. */
export declare function shellDrivePathOf(family: PathFamily | undefined, spelled: string): string | undefined;
/**
 * A ROOTED spelling on a win tree that the shell may read as a drive path although it is not the shell's drive spelling — the
 * drive path it then names and whose walk it is (`walk`): `/cygdrive/x/…` (the Cygwin drive prefix, walked by the shell as its
 * drive spelling is, `..` kept; Git Bash's mount table sets that prefix to `/`, so whether the shell still answers `/cygdrive` is
 * the shell's) and a single-backslash-rooted `\…` (Win32's current-drive form: the root of `base`'s drive or share, walked as
 * Win32 walks it — a `..` there stays at that root). Either may instead be a path of the emulation's own tree, which no reader
 * here places: the drive path is a place the word MAY lead (a stand-in), read where a reading tightens. `undefined` for every
 * other spelling, a base that is not a qualified win path, and any tree that is not win.
 */
export declare function shellDriveAliasOf(family: PathFamily | undefined, spelled: string, base: string): {
    readonly path: string;
    readonly walk: "shell" | "win32";
} | undefined;
/** The places a drive-relative spelling (`C:rest`, no separator after the colon) may be read from where `base` — the shell's
 *  working directory — is on that drive: `rest` relative to `base` (Win32's working directory of the process's current drive)
 *  and relative to the drive's root (the reading where the shell keeps no working directory per drive) — which of the two the
 *  shell takes is its own, so both are candidates, each `[base, rest]` (`rest` `.` for a bare `C:`). `undefined` for every
 *  other spelling, for a drive other than `base`'s (whose working directory only that process knows), and on any tree that is
 *  not win. */
export declare function driveRelativeReadingsOf(family: PathFamily | undefined, base: string, spelled: string): ReadonlyArray<readonly [string, string]> | undefined;
/** Does the shell's walk of a drive path it anchored ({@link shellAnchoredSpellingOf}) climb above the drive's root — a `..`
 *  counted on the text past the drive's own segments? There the shell stands in the emulation's root, not at the drive's
 *  root a Win32 fold clamps it to. `false` for any other spelling and on any tree that is not win. */
export declare function shellWalkLeavesDrive(family: PathFamily | undefined, anchored: string): boolean;
/** Where the shell's walk goes on from a spelling of the emulation's own tree (`/…`, reached by a `..` above a drive's root):
 *  the drive paths it names where the walk enters a drive — a `..` at `/` stays there; the drive's own `..` KEPT for the walk (a
 *  link below decides where they lead: `/d/deep/../../x` is walked through `D:\deep`) and folded as the shell folds a `/`-rooted
 *  path ({@link shellDriveSpellingOf}: `/d/deep/../../x` is `/x` there, `/etc/../c/x` is `C:\x`) — which of the two the shell
 *  takes is its own, so each is a landing; none where the walk stays in that tree. */
export declare function shellRootedLandingsOf(emulation: string): readonly string[];
/** A drive path the SHELL anchored itself — a relative operand joined to its working directory, a `~` word to its home — is
 *  walked in that shell's namespace: where a `..` climbs above the drive's root it reaches the emulation's root, so the path is
 *  read as {@link shellDriveSpellingOf} reads `/x/…` (`C:\proj\..\..\d\f` ⇒ `D:\f`, not the Win32 clamp's `C:\d\f`). `undefined`
 *  where no `..` climbs above the drive's root, where the climb lands in the emulation's own tree (`C:\proj\..\..\etc` is `/etc`
 *  there, a place only that shell knows — the shell operand resolver reads the clamp as a stand-in there), and for any other
 *  spelling or family. */
export declare function shellAnchoredSpellingOf(family: PathFamily | undefined, anchored: string): string | undefined;
/** A ROOTED (not qualified) spelling handed to the SHELL on a win tree (`/etc`, `/cygdrive/d/x`, `\\x`) that is not the
 *  shell's drive spelling ({@link shellDriveSpellingOf}) is the shell's to map — the win32 adapter runs Git Bash, where
 *  `/etc` is the MSYS root, not the cwd's drive root — so no lexical reader may resolve it (fail-closed: the operand is
 *  unresolvable). The ONE statement of that rule, for every shell-facing resolver. */
export declare function isShellRootedSpellingUnmapped(family: PathFamily | undefined, spelled: string): boolean;
/** The win family's native spelling of a UNC written with any leading-separator mix (`//host/share/x`, `\\/host/…`
 *  ⇒ `\\\\host\\share\\x`), for a lexical normalizer that recognises the backslash form only; every other spelling is
 *  returned as is. */
export declare function nativeUncSpellingOf(family: PathFamily | undefined, spelled: string): string;
/**
 * Fold a TRAILING separator run off a spelling that is about to become a KEY: `<dir>/adir`, `<dir>/adir/`
 * and `<dir>/adir//` name one directory and must mint one key. The existing-path arm folds them already,
 * as a side effect of asking `realpath`; the arm that mints a key for a path that does NOT exist yet
 * rejoined the model's own tail verbatim, so the same not-yet-created directory arrived under two and
 * three keys — and a byte-wise reader (the per-file read state, the write gate's per-key ledger) treats
 * two keys as two files.
 *
 * Called on the ANSWER, at the canonicalizer's single exit, and never on a spelling about to be probed.
 * Two things break if it moves earlier. A trailing separator is an ASSERTION that the target is a
 * directory and the platform enforces it (`<existing regular file>/` answers `not_directory`, reported
 * here as a refusal), so folding before the probe spends that refusal and the slash-suffixed spelling of
 * a file resolves to the file. And the ancestor walk chooses which ancestor to canonicalize by SPLITTING
 * the spelling it was handed: a leaf stripped of its separator first is skipped as though it had been
 * resolved, so `<root>/link/` — a link to a directory outside the root — comes back as the in-root
 * spelling instead of the destination. Folding the answer costs neither.
 *
 * A spelling whose remainder is the bare ANCHOR keeps the separator the platform writes on a root — `/`,
 * `C:\`, `\\host\share\`. That run IS the root's own spelling rather than a tail nobody wrote, and
 * stripping it renames the spelling to nothing, to a DRIVE-RELATIVE location, or to a share root written
 * unlike every other root. The question is asked in the module's own vocabulary ({@link pathIdentityOf} +
 * {@link isIdentityDir}: is anything left BELOW the anchor?), so the three families need no arm each.
 * Interior runs are NOT touched here: the ancestor walk folds them by probing, and a run in the middle of
 * a name is the platform's to read.
 *
 * Scanned backwards rather than matched: `/[\\/]+$/` against a model-supplied spelling is quadratic when a
 * long separator run precedes a non-separator (measured: ~5s for 32k leading slashes, on the caller's
 * thread), and a path spelling is unbounded input.
 */
export declare function foldTrailingSeparators(spelled: string, family: PathFamily): string;
/**
 * Join a RELATIVE-OR-ROOTED spelling to a base under the family, without folding (`..` across a symlinked
 * parent is the env's to resolve). win = `path.win32` semantics: `/x`/`\x` lands on the base's drive or
 * share root, anything else under the base with the base's own separator. posix = `/`-join.
 */
export declare function joinForFamily(family: PathFamily, base: string, rel: string): string;
/**
 * THE anchor step of every path reading: a spelling fully qualified under the family stands as spelled; any other is joined
 * to `base` ({@link joinForFamily}, unfolded). One definition, so "already absolute, therefore do not prepend a base" is
 * decided in one place for every reader — the path prelude (`readPath`, effective-path-target.ts), the canonicalizer, a
 * link's target against its parent, a search tool's root-relative output. Callers that need the namespace screen or an
 * identity read the prelude; this is only its anchor.
 */
export declare function anchorSpelling(family: PathFamily, base: string, spelled: string): string;
/** The family-aware LEXICAL view of a possibly-relative spelling against a resolution base (no I/O,
 *  `.`/`..` folded via {@link normalizeAbsPathLexically}): the SECOND deny-judgment view. It asks
 *  "does the NAME land on a guarded path", complementing the canonical
 *  view's "does the TARGET" — a symlink AT a guarded spelling resolves away from it canonically,
 *  and only this view still names it. */
export declare function lexicalViewOf(spelled: string, base: string): string;
/** A face's extra containment roots: a fixed list, or a getter over a run's live set (read once per resolution). */
export type RootsSeat = readonly string[] | (() => readonly string[] | undefined);
/**
 * Resolve a model-supplied path to a canonical key AND enforce rootPath containment. Existing paths
 * use `canonicalPath` (resolves symlinks, so the same file cannot get two keys). New paths
 * canonicalize the **deepest existing ancestor** then rejoin the missing tail — a symlinked parent
 * therefore cannot land the target outside root. Returns the canonical key, or a `path_not_in_root`
 * violation. Defense-in-depth at the tool layer; NOT a substitute for a sandboxed `executionEnv`.
 */
export declare function resolveKey(env: ExecutionEnv, rootCanonical: string, path: string, signal?: AbortSignal, baseCwd?: string, additionalRoots?: RootsSeat, exactFileReadExemption?: (canonicalKey: string) => boolean, readDeny?: {
    readonly face?: "write";
    readonly homeViews?: HomeViewSource;
    matchTarget(canonicalKey: string, lexicalView?: string, opts?: {
        readonly aliasResolved?: boolean;
        readonly hops?: readonly string[];
    }): {
        pattern: string;
        matchedView?: string;
    } | null;
    /** The write face's {@link import("./read-deny.js").WriteDenyMatcher.guardsReads}: the row a hit named also guards reads. */
    guardsReads?(pattern: string): boolean;
}, containmentFace?: "open" | "roots", outsideRemedy?: string): Promise<{
    ok: true;
    key: string;
} | {
    ok: false;
    violation: FsViolation;
}>;
/**
 * Canonicalize a model-supplied path to its real on-disk target (symlinks resolved; for a path that
 * doesn't exist yet, the deepest EXISTING ancestor is canonicalized then the missing tail rejoined —
 * so a symlinked parent cannot land the target elsewhere). NO containment check — this is the pure
 * canonicalization shared by `resolveKey` (which adds rootPath containment) and
 * `createSensitivePathPolicy` (which matches the real target against a guarded list).
 * A single source of truth for symlink resolution: a sensitive-path policy that matched the raw path
 * instead of the real target would compare against the spelling, not the destination.
 *
 * @contract fs.canonical_target.probed_and_bounded — every model-spelled path is resolved by asking the
 * execution environment where it really lands; no spelling shape is exempt from that, and the win-form
 * UNC spelling stopped being the one that was. The ask is bounded by the tree's shared bounded-await
 * deadline rather than by a timer of this module's own, and a wait that elapses or a probe that fails
 * comes back as a refusal carrying no key — the spelling is never handed back as a substitute for the
 * answer. What the deadline bounds is the CALLER'S wait: the underlying filesystem call is not
 * cancellable and may go on occupying the runtime's I/O capacity until the kernel gives up.
 */
export declare function canonicalizeTarget(env: ExecutionEnv, path: string, signal: AbortSignal | undefined, family: PathFamily, baseCwd?: string): Promise<{
    ok: true;
    key: string;
    aliasResolved?: true;
} | {
    ok: false;
    message: string;
    unresolvedSymlink?: true;
    refused?: Win32NamespaceRefusal;
}>;
/** Render a `FsViolation` as the model-facing tool error text (returned, never thrown — model retries). */
export declare function violationText(toolName: string, v: FsViolation): string;
/**
 * Structured `details` for a rendered violation: non-`undefined` ONLY for the two codes with
 * per-refusal coordinates worth counting (which canonical target, against which roots or which deny
 * pattern). Designed to be passed straight as `errorResult`'s second argument by every renderer of a
 * {@link resolveKey} violation — `undefined` keeps the detail-less shape for all other violation
 * codes.
 *
 * `type` is the WIRE discriminator: the card projector (`createStructuredProjector`,
 * tool-output-projection.ts) keys on `details.type`, so without it the card never reaches
 * `tool_end.structured` and the "count from fields" promise above holds for in-process readers only.
 * `code` carries the same value for consumers that read it.
 */
export declare function violationDetails(v: FsViolation): {
    type: "path_not_in_root";
    code: "path_not_in_root";
    target: string;
    roots: readonly string[];
    targets?: readonly string[];
} | ReadPathDeniedCard | undefined;
/** The read face's refusal card: which target, which deny pattern. */
export type ReadPathDeniedCard = {
    type: "read_path_denied";
    code: "read_path_denied";
    target: string;
    pattern: string;
};
/**
 * The ONE mint of the `read_path_denied` card. `type` is the CC_DETAIL_TYPES discriminator, so the refusal's
 * coordinates reach `tool_end.structured`, not just prose; `code` carries the same value for in-process readers.
 * Every site that refuses a read on a deny row — the tools' own resolution, the shell station, the gate's rule lanes —
 * mints it here.
 */
export declare function readPathDeniedCard(target: string, pattern: string): ReadPathDeniedCard;
/**
 * Where one deny row refused a call: the row's text, the view of the target it met, and the face the call is on.
 * Minted once, by the judge that found the row; every exit of the gate reads it and judges nothing again.
 */
export interface PathDenialEvidence {
    readonly rule: string;
    readonly view: string;
    readonly face: DenyFace;
}
/**
 * The card a gate-side path refusal carries: the read face's own ({@link readPathDeniedCard}); the write face has none
 * (as in the tools' own resolution, where a write refusal's `write_path_denied` code carries no card). The card's
 * presence follows the FACE, never the station that refused.
 */
export declare function pathDenialCardOf(evidence: PathDenialEvidence | undefined): ReadPathDeniedCard | undefined;
/**
 * Does `p` sit inside ANY of the canonical containment roots? Exposed for the Bash
 * tool's post-`cd` disclosure note (fs-bash.ts): the note reuses the SAME segment-aware `within`
 * the fence itself uses, so the disclosure and the fence can never disagree about what counts as
 * "inside". Pure/lexical — callers own any canonicalization of `p` (the tracked cwd stays raw by
 * design; fs-bash canonical-confirms before claiming "outside").
 */
export declare function withinAnyRoot(rootsCanonical: readonly string[], p: string): boolean;
/**
 * THE store-isolation rule, one judgment for every root admission point (the Artifact mount over the prepare-time
 * roots, an in-flight read-root grant over the granted root, a person's read directory where a run's read roots are
 * read): a root that CONTAINS the local artifact store, lies INSIDE it, or IS it hands the file tools the store's ledger
 * and stored files. Returns the first such root, or undefined.
 *
 * `storePhysical` is the store's physical path on THIS process's filesystem (`physicalPathOfExisting`, resolved
 * once per run by the Artifact phase); a root is the execution env's canonical key. The judgment touches no
 * filesystem — the grant runs after the approver's wait under the call's cut, and a synchronous lookup on a stalled
 * store mount would block the event loop past that cut. The two are compared as identities only when both spell the
 * same family (`within` reads both under the root's family); a root of the other family names a filesystem the store
 * cannot be on, and no claim is made against it.
 */
export declare function rootAdmittingArtifactStore(storePhysical: string, rootsCanonical: readonly string[]): string | undefined;
/**
 * The escape-hatch tail for the `path_not_in_root` refusal: like its three sibling hints below, it
 * names a sanctioned next step, so the model does not oscillate between "the boundary is hard" and
 * hunting for a way around it.
 *
 * The card names the SANCTIONED way out and nothing else: widening the declaration
 * (`additionalDirectories` / read-only `additionalReadDirectories`), or the deployment-level
 * `readFace: "open"` (reads) / `writeFace: "open"` (writes).
 *
 * It deliberately does NOT name the shell as unconfined by this fence, even though that is a true
 * statement rather than a recommendation. A live retest settled the question: a refused agent read
 * such a sentence as the next step, went to the shell, and rewrote through it the very file the fence
 * had just protected. A refusal card is a PROMPT surface — naming, at the moment of denial, a second
 * tool that does not enforce the boundary is a recipe whatever its grammar, and the model cannot be
 * relied on to hear "fact, not advice". The underlying fact is documented where humans read it (the
 * shell is deliberately unconfined by this fence, and every shell call still passes the deployment's
 * approval policy); it is simply not handed to the model inside a denial.
 */
export declare const PATH_NOT_IN_ROOT_ESCAPE_HINT = "(This boundary applies to the structured file tools. If you genuinely need content outside the allowed root(s), ask for the directory to be added to the deployment's additionalDirectories \u2014 or additionalReadDirectories for read-only access; a deployment that wants reads or writes open everywhere can declare readFace / writeFace: \"open\" instead of listing directories.)";
/** inv 1 (read-before-edit): a file must have been read this task before it can be edited/overwritten.
 *  Message as probed (all-tools-live-probe 2026-07-08 §2.1/§3.1/§5.1 — one message for
 *  Edit/Write/NotebookEdit: "before writing to it", not the old sema "before editing").
 *  The rule, not the decision: Edit and Write ask the run's waiver (`ReadFirstWaiverSeat`, fs-write.ts) before they refuse on
 *  it — a model the reference does not hold to read-first changes an unread file its own Read would be served for.
 *
 * CC parity (Edit and Write spell the read gate identically, `!p || p.isPartialView`): an
 * AUTO-TRUNCATED read (the model asked for the file by default, no explicit offset/limit, and the token
 * cap cut it anyway — {@link ReadEntry.isPartialView}) must NOT satisfy this gate. With `state.has(key)`
 * alone as the whole check, the model could Write (full overwrite) or Edit a file having genuinely seen
 * only its first page, silently destroying or blind-editing the unseen remainder. CC's own gate treats
 * "never read" and "auto-truncated
 * partial view" identically for BOTH tools — no softer rule for Edit (whose old_string match only touches
 * a small snippet) versus Write (which replaces everything), so this doesn't carve one out either.
 *
 * Deliberately checks `isPartialView`, NOT the broader {@link ReadEntry.truncated} (which also fires for a
 * fully-intentional, successful EXPLICIT offset/limit slice read) — CC's own `isPartialView` is scoped the
 * same narrow way (only the auto-pagination case, never an explicit range that fit), and gating on the
 * broader flag would make the Read tool's too-large refusal's documented promise ("pass an explicit offset/limit
 * to read a slice") false: a model deliberately paging through an oversized file via offset/limit would never be
 * able to satisfy this gate again. */
export declare function requireRead(state: ReadFileState, key: string): FsViolation | undefined;
/**
 * The escape-hatch parenthetical for the one shape of the read-before-edit refusal that needs one from the write
 * tool itself: the file was read, but the read was AUTO-PAGINATED by the output token cap
 * ({@link ReadEntry.isPartialView}), so only the first page was ever seen. The refusal's own advice
 * ("Read it first") is a FIXPOINT here — unlike a file Read refuses, whose refusal says its own way out: the file is UNDER the byte cap, so a default Read succeeds and
 * auto-paginates identically, and Read's unchanged-since-last-read dedup then short-circuits before the
 * state is rewritten. The gate is `isPartialView`, not the file size, so ANY explicit offset/limit slice
 * that fits clears it — stated explicitly because nothing else in the transcript says so.
 */
export declare const PARTIAL_VIEW_READ_ESCAPE_HINT = "(Your last Read of this file returned only a PARTIAL view \u2014 the output token cap paginated it, so a default Read will keep returning the same page. Re-read it with explicit offset/limit (start from the page marker's next-page hint) until you have seen the part you are about to change; an explicit slice that fits satisfies the read-first rule. Or inspect/transform it with bash (e.g. `sed -n`, `grep`) instead.)";
/**
 * The same dead end for the two files the Read tool opens by what its NAME says, not as text: a Read of an image shows
 * it as a picture, and a Read of a PDF opens it as a document (a file named like one that is not is refused as one);
 * neither leaves the text record the gate asks for, so reading it again lifts nothing, and the only way to change the file
 * is to replace it whole. They are said from the name alone — the refusal reads no byte of the file and asks the Read tool
 * nothing — so the same name gets the same sentence whatever the file holds.
 *
 * Every OTHER file the Read tool cannot take (a binary body, a notebook it cannot project, a body past a byte bound) says
 * so itself, in its own refusal, with the way out; the not-read refusal of a write tool carries no such half-sentence, because
 * naming a shell rewrite beside "read it first" was offered to files a Read takes just as well.
 */
export declare const READ_SHOWS_IMAGE_HINT = "(The Read tool opens an image file as a picture \u2014 or refuses a file named like one that is not \u2014 and records no read of it, so reading it again does not lift this rule. To change this file, replace the whole file with a shell command instead.)";
export declare const READ_SHOWS_PDF_HINT = "(The Read tool opens a PDF as a document \u2014 or refuses a file named like one that is not \u2014 and records no read of it, so reading it again does not lift this rule. To change this file, replace the whole file with a shell command instead.)";
/** The Read tool's name-only route to its PDF lane, taken before any byte is looked at. The one spelling of the test: the
 *  Read tool routes on it, and the write tools' not-read refusal reads the same answer ({@link imageMimeForRead} is the
 *  image lane's). Pure — no I/O. */
export declare function isPdfPath(path: string): boolean;
/**
 * Edit "no-op" guard (CC FileEditTool parity): refuse an edit whose `old_string`
 * equals `new_string` — without it the edit passes the match check and writes the file back unchanged (a
 * silent no-op that wastes a turn and dirties mtime). The message is worded so a CC-trained model recognizes it.
 */
export declare function checkNoChange(oldString: string, newString: string): FsViolation | undefined;
/** inv 2 (staleness): the file's current content hash must match what was recorded at read time.
 *
 *  Takes `ReadEntry | undefined` and treats an ABSENT entry as stale (fail-closed). The three
 *  write-side callers prove the entry exists with `requireRead`, then re-read the file — an `await` — and
 *  only then reach here, so each was asserting a pre-await invariant across a suspension point with `!`.
 *  Nothing deletes read state mid-turn today (the compaction sweep runs at a turn boundary), so behaviour
 *  is unchanged; if that ever stops holding, the caller gets this tool's designed "read it again" refusal
 *  instead of a TypeError thrown from inside the tool. */
export declare function checkStale(entry: ReadEntry | undefined, currentHash: string): FsViolation | undefined;
/** Count non-overlapping occurrences of `needle` in `haystack` (`needle` must be non-empty). */
export declare function countOccurrences(haystack: string, needle: string): number;
/**
 * Suggest a sibling filename for a missing path (CC `File does not exist… Did you mean X?` self-heal
 * path, bundle :335883/:478419). Honest scope (1.253 双轨终审): this is the FALLBACK tier — an
 * approximation of CC's Cxe same-directory scan plus a sema-added case-insensitive exact-name match
 * (the case-typo class CC misses). Registered delta: CC's FIRST-tier suggester is a GATED
 * sibling-tree REBASE (`join(cwd, relative(dirname(cwd), missing))`, only for a path under the cwd's
 * parent but not under the cwd), NOT the "re-resolve the filename against cwd" this comment used to
 * claim; the full geometry and the sema delta are recorded at the call site (fs-shared.ts
 * `enoentMessage`), which is where the env probing lives. This function stays pure over a listed
 * sibling set and corresponds to CC's SECOND tier (`Yrt`/findSimilarFile). (a) CC's findSimilarFile
 * rule — same stem, different extension/name in the same directory; (b) the case-insensitive
 * exact-name match (sema addition). Returns the suggested NAME (not a full path), or undefined.
 */
export declare function similarNameSuggestion(siblingNames: readonly string[], missingName: string): string | undefined;
/** Replace curly single/double quotes with their straight ASCII forms (CC qDa, 1:1 char mapping). */
export declare function normalizeQuotes(s: string): string;
/**
 * Resolve `oldString` against `content` with the CC quote-forgiveness layer: exact match first; on a
 * miss, match in the curly→straight normalized coordinate and return the ACTUAL file substring at
 * that span (CC kOe). Returns undefined when even the normalized form does not appear.
 */
export declare function resolveQuoteMatch(content: string, oldString: string): string | undefined;
/**
 * CC's forgiving-match layers 3+4: resolve `oldString` against `content` across the
 * escape/literal spelling boundary. Returns the ACTUAL span present in `content` (which is what must be
 * replaced), or `undefined` when neither spelling is present. Pure — call only after an exact match and
 * the curly-quote layer have both missed.
 */
export declare function resolveEscapeMatch(content: string, oldString: string): string | undefined;
/**
 * Rewrite `newString` into the SAME spelling the matched
 * span uses. Without this, a match found through {@link resolveEscapeMatch} would replace an escaped
 * span with a literal-character replacement (or vice versa) and silently change the file's encoding
 * convention at that spot. Hex case follows what the file itself used, per-character where known and by
 * majority vote otherwise — CC's own rule, and the reason it counts upper/lower while walking the span.
 */
export declare function adaptNewStringEscapes(oldString: string, matchedOld: string, newString: string): string;
/** CC `KZu` (@366558): the old_string shapes for which the escape layers above were even attempted —
 *  gates the explanatory note appended to a no-match refusal so it is never a false claim. */
export declare function escapeMatchWasAttempted(oldString: string): boolean;
/** The escape-match miss note. */
export declare const ESCAPE_MATCH_MISS_NOTE = "\n(note: Edit also tried swapping \\uXXXX escapes and their characters; neither form matched, so the mismatch is likely elsewhere in old_string. Re-read the file and copy the exact surrounding text.)";
/**
 * When the quote-forgiving match resolved to a curly-quoted file span, convert the straight quotes in
 * `newString` to the matching curly forms so the replacement stays style-consistent with the file
 * (CC Dmt/yPp/TPp: openers vs closers by preceding char; a letter-adjacent single quote is an
 * apostrophe U+2019). Call ONLY when the matched span differs from the model's old_string.
 */
export declare function adaptNewStringQuotes(matchedOld: string, newString: string): string;
/**
 * The effective old_string a DELETION should replace: `oldString + "\n"` when new_string is empty,
 * old_string doesn't already end with a newline, and the newline-suffixed form exists in the content;
 * otherwise old_string unchanged (CC KDa parity). SINGLE (non-replace_all) edits only: a widened
 * needle under replace_all would miss occurrences not followed by a newline and desync the
 * replacement count — the Edit tool restricts the widening to single edits (1.253 双轨终审 MED).
 */
export declare function deletionOldString(content: string, oldString: string, newString: string): string;
/**
 * inv 3 (edit uniqueness): `oldString` must match exactly once unless `replaceAll`. Zero → not found;
 * >1 without replaceAll → ambiguous. `truncated` adds a hint that unseen content may hold more matches (S2).
 * Messages as probed (all-tools-live-probe 2026-07-08 §2.1): first sentence(s) byte-exact,
 * then a `String: <needle>` echo line (CC form). The sema truncated-read hint survives as a parenthetical
 * appended to the sentence (probe verdict: "truncated 提示可并入括注保留").
 */
/** How much of the needle a failed-match refusal spells back. The echo identifies WHICH string was
 *  searched for; the caller still holds the whole thing in the tool call above, so a prefix does the job
 *  a full copy was doing at any length the caller chose. Both arms use it — the not-found arm is the more
 *  common failure, so bounding only the multi-match arm would leave the stated bound defeated where it
 *  matters most (and these refusals return as tool results, which do not pass the loop-level budget). */
export declare const EDIT_ECHO_MAX_CHARS = 200;
export declare function checkEditMatch(content: string, oldString: string, replaceAll: boolean, truncated: boolean): FsViolation | undefined;