UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

31 lines (30 loc) • 1.82 kB
/** * The `Tool(content)` rule SYNTAX — the one reader every rule face shares, as a LEAF module. * * Two modules read this grammar and, until this file existed, one imported it from the other: the rule * DSL compiler (`permission-rules.ts`) declared the parser and the persisted-rule model * (`permission-rule-model.ts`) imported it. The model's command/path grammars are now consumed by the * compiler too (a content-form `deny`/`ask` rule compiles through the model's own validator and * matcher), which would have closed a value-import cycle between the two. The syntax layer has no * dependency of its own, so it lives here and both read DOWN. * * Upstream parity: `Lh` (the split), `Dju`/`Pju` (the escape-aware paren search), `Hju` (the three * unescapes) — INCLUDING the lenient downgrades (malformed parens / trailing garbage ⇒ the WHOLE string * becomes the bare tool name). The strict complement that refuses the downgrades is the compiler's * validator, not this reader. */ /** Parse result — the tool name and, for a `Tool(content)` spelling, its unescaped content. */ export interface ParsedPermissionRule { toolName: string; ruleContent?: string; } /** First index of `ch` preceded by an EVEN number of backslashes. */ export declare function indexOfUnescaped(s: string, ch: string): number; /** Last index of `ch` preceded by an EVEN number of backslashes. */ export declare function lastIndexOfUnescaped(s: string, ch: string): number; /** * Parse one rule string, including the lenient downgrades (malformed parens / trailing garbage ⇒ the * WHOLE string becomes the bare tool name). Use the compiler's `validatePermissionRules` (or the policy * factory) to refuse the downgrades. */ export declare function parsePermissionRule(rule: string): ParsedPermissionRule;