@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
102 lines • 4.77 kB
TypeScript
import type { FindAction } from '../commands/builtin/types.ts';
import { UsageError } from '../commands/errors.ts';
import type { PredNode } from '../core/generic/types.ts';
import type { JsonValue } from '../types.ts';
export declare const OPERAND = "";
export declare const DAY = 86400;
type Bounds = readonly [number | null, number | null];
type Obj = Readonly<Record<string, JsonValue>>;
/**
* One parsed find expression: the predicate tree plus everything the flat
* window lifts out of it. The tests a backend can answer per entry stay in
* `tree`; the windows (depth, size, mtime) and the actions are global to
* the expression, because a native find op evaluates the tree and the
* executor applies the actions to what came back. A time test also sits in
* the tree as an `mtime` node, for its position alone: a `-prune` after it
* fires only where the test holds. `newer` holds `-newer` reference
* operands as typed, which the executor resolves against the dispatcher
* before it binds the expression. `actions` are in the order written, since
* GNU runs actions per position; `depthFirst` is GNU's `-depth`, which
* `-delete` turns on; `predicates` is every predicate word typed, in order;
* `warnings` the lines GNU prints while it parses; `start` where the
* expression begins among the words typed. Mirrors Python's `FindExpr`.
*/
export interface FindExpr {
tree: PredNode;
maxDepth: number | null;
minDepth: number | null;
minSize: number | null;
maxSize: number | null;
mtimeMin: number | null;
mtimeMax: number | null;
usesEmpty: boolean;
actions: FindAction[];
newer: string[];
depthFirst: boolean;
predicates: string[];
warnings: string[];
start: number;
}
/** Where find's expression begins among the words typed, and which words an `-exec` owns. */
export interface FindLayout {
readonly start: number;
readonly spans: readonly (readonly [number, number])[];
}
/**
* Where the expression begins in the words typed after `find`, and which
* words an `-exec` owns, read by mirage-rs without parsing the expression,
* so a line that will be refused still classifies. Mirrors Python's
* `find_layout`.
*/
export declare function findLayout(argv: readonly string[]): FindLayout;
/**
* The inclusive lower bound that means "later than `timestamp`". `-newer`
* and `-newermt` are strict (GNU: modified *more recently than*), and the
* window is inclusive, so the bound is the next representable float: exact,
* where adding an epsilon would either miss a timestamp or admit the
* reference itself.
*/
export declare function strictlyAfter(timestamp: number): number;
/** One `-newermt` argument as a GNU date expression; naive times are UTC. */
export declare function parseNewermt(value: string): number;
/** One `-mtime` as inclusive epoch-second bounds: `cmp` is `+`, `-` or `=`. */
export declare function mtimeBounds(cmp: string, days: number, now: number): Bounds;
/**
* What mirage-rs read of a find line, before any time test is resolved.
* Mirrors Python's `FindParse`.
*/
export declare class FindParse {
readonly values: Obj;
constructor(values: Obj);
/** Where the expression begins among the words typed. */
get start(): number;
/** The `-newer` references, as typed, in expression order. */
get newer(): string[];
/**
* The first `-newermt` text that is no date, in expression order, with
* how many `-newer` references precede it; null when every date reads.
* GNU reads `-newer` and `-newermt` left to right, so the references
* typed before that date are statted first and their error, if any, is
* the one reported.
*/
dateRefusal(): [number, UsageError] | null;
/**
* The expression with its time tests resolved. `newerTimes` is each
* `-newer` reference's mtime in epoch seconds, in order; empty leaves
* every `-newer` a test that always holds, as one the executor could not
* resolve. `now` is the clock `-mtime` counts from, the current time by
* default. Throws UsageError for a `-newermt` text that is no date.
*/
bind(newerTimes?: readonly number[], now?: number): FindExpr;
}
/**
* find's words read once by mirage-rs: the start points end where the
* expression begins, and the expression becomes a tree. Throws UsageError
* for the first word the grammar refuses, in GNU's words and with its exit
* status. Mirrors Python's `parse_find`.
*/
export declare function parseFind(argv: readonly string[]): FindParse;
/** `parseFind` and `bind` with no reference resolved, for a caller holding only the words. */
export declare function parseFindExpression(argv: readonly string[]): FindExpr;
export {};
//# sourceMappingURL=find.d.ts.map