@sema-agent/core
Version:
Stateless, task-oriented AI agent core
40 lines (39 loc) • 2.89 kB
TypeScript
import type { ReadNote } from "../../tools/fs/fs-read.js";
/** The smallest per-file cap, in characters (the reference's floor). */
export declare const INSTRUCTION_FILE_MIN_CHARS = 40000;
/** The share of the model's window one instruction file may fill. */
export declare const INSTRUCTION_FILE_WINDOW_SHARE = 0.05;
/** The deepest `@` include followed from a file (the file itself is depth 0; an include at this depth is not followed). */
export declare const INSTRUCTION_INCLUDE_MAX_DEPTH = 5;
/** The largest file read at all, in bytes: a file past it is not an instruction file this lane loads. */
export declare const INSTRUCTION_FILE_MAX_BYTES: number;
/** One file's cap: max(40 000, window × 0.05 × characters per token, to the nearest whole character). */
export declare function instructionFileCap(contextWindow: number, charsPerToken: number): number;
/** A file as the lane shows it. `content` is the text after the frontmatter and the comments; `globs` is present only on a
* file whose frontmatter names paths it applies to; `noLimit` is present (true) when the frontmatter names `paths:` and
* nothing in it limits the file — the key is there and reads as no glob (nothing under it, an empty list, only `**`, a value
* that is not a string, a mapping); `spansLines` is present (true) when one glob of it was written over several lines — globs
* on lines of their own with no comma between them read as one text, which matches no file; `includes` are the include paths
* as written (relative ones unresolved). */
export interface InstructionText {
readonly content: string;
readonly globs?: readonly string[];
readonly noLimit?: true;
readonly spansLines?: true;
readonly includes: readonly string[];
}
/** Read one instruction file's text (already in the decoded coordinate). `withIncludes`: extract the `@` include paths. */
export declare function processInstructionText(text: string, withIncludes: boolean): InstructionText;
/** Does a conditional rule apply to a path (relative to the rule's level directory, `/`-separated)? gitignore anchoring: a
* glob with a `/` matches from the level directory, a bare one matches a name at any depth; `{a,b}` is alternation. */
export declare function ruleGlobsMatch(globs: readonly string[], rel: string): boolean;
/** May an include name this path (by its extension)? */
export declare function isTextIncludeTarget(path: string): boolean;
/** A text cut to `cap` characters: at its last line break within the cap, or — a text with none there — at the cap itself.
* `note` is the frame's statement of the cut (the Read layer's own partial-view words); absent ⇒ the whole text. */
export declare function cutInstructionText(text: string, cap: number, charsPerToken: number): {
text: string;
note?: Extract<ReadNote, {
kind: "partial_page" | "partial_chars";
}>;
};