UNPKG

agentfootprint

Version:

The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.

52 lines (51 loc) • 3.52 kB
/** * matcher — the prose grammar's machinery: a reply's tokens with their offsets, and the phrase * matcher over them. It owns NO spelling rule: every token is spelled by the library's one * spelling leaf (`lib/normalize.ts` · `foldCase`), and names compare by its `sameName`. * * Pattern: pure functions, linear in the text. A token is a run of letters, digits and marks, * with `- _ . / : @ #` kept INSIDE an identifier (`host-07.dc1.example.com`, `eth1/3`) * and an apostrophe kept inside a word (`doesn't`); every step of the one tokenizer * regex consumes a character, so no input backtracks. Spans are offsets into the text * as given; only each token's own text is spelled. * Role: integrity/ layer (L3), read by `units.ts`, `detect.ts`, `language.ts`, * `resolve.ts` and `containment.ts`. */ import type { ClaimPhrase } from './phrases.js'; import type { ProseWorkBudget } from './work.js'; /** One token: its normalized text and where it sits in the text as given. */ export interface Token { readonly text: string; readonly start: number; readonly end: number; } /** One token as the grammar compares it: the leaf's case fold, a curly apostrophe straightened. */ export declare function spellToken(raw: string): string; /** The tokens of `text[from, to)`, with offsets into `text`. */ export declare function tokensOf(text: string, from?: number, to?: number): Token[]; /** A phrase's or a said word's tokens, as text. */ export declare function spell(phrase: string, work?: ProseWorkBudget): string[]; /** Whether `tokens` hold `words` as consecutive tokens, anywhere. */ export declare function holdsWords(tokens: readonly Token[], words: readonly string[], work?: ProseWorkBudget): boolean; /** The first index at which `tokens` hold `words` consecutively, or -1. */ export declare function findWords(tokens: readonly Token[], words: readonly string[], from?: number, work?: ProseWorkBudget): number; /** Whether any of the said phrases is held by `tokens`. */ export declare function holdsAnySaid(tokens: readonly Token[], said: readonly string[] | undefined, work?: ProseWorkBudget): boolean; /** Whether the unit holds `name` as one of its token runs, by the leaf's name rule (`sameName`). */ export declare function holdsName(text: string, tokens: readonly Token[], name: string, work?: ProseWorkBudget): boolean; /** The first token index at which the unit holds `name` (by `sameName`), from `from`; or -1. */ export declare function nameAt(text: string, tokens: readonly Token[], name: string, from: number, work?: ProseWorkBudget): number; /** A number word's value, or a digit string's. */ export declare function numberOf(token: string): number | undefined; /** One match: the phrase and the token range it covers. */ export interface PhraseHit { readonly phrase: ClaimPhrase; readonly first: number; readonly last: number; } /** The first hit of `phrase` in a unit's tokens, or undefined. */ export declare function matchPhrase(text: string, tokens: readonly Token[], phrase: ClaimPhrase): PhraseHit | undefined; /** The earliest hit of any phrase of a pack (ties go to pack order), or undefined. */ export declare function firstHit(text: string, tokens: readonly Token[], pack: readonly ClaimPhrase[]): PhraseHit | undefined; /** Every phrase of a pack that matches somewhere in the unit. */ export declare function allHits(text: string, tokens: readonly Token[], pack: readonly ClaimPhrase[]): PhraseHit[];