Files
oh-my-pi/packages/coding-agent/src/capability/rule.ts
T
can1357 13f3eae8c0 feat: introduced TTSR for real-time pattern matching during streaming
- Added Time Traveling Streamed Rules (TTSR) feature for real-time pattern matching and rule injection during streaming.
- Added TtsrManager with configurable settings for context mode, repeat mode, and repeat gap.
- Added TTSR trigger support across all rule discovery sources (builtin, cline, cursor, windsurf).
- Added abort signal handling in agent loop to support stream interruption for TTSR.
- Added TtsrNotificationComponent for displaying rule violation notifications in interactive mode.
2026-01-03 19:43:17 +01:00

57 lines
1.6 KiB
TypeScript

/**
* Rules Capability
*
* Project-specific rules from Cursor (.mdc), Windsurf (.md), and Cline formats.
* Translated to a canonical shape regardless of source format.
*/
import { defineCapability } from "./index";
import type { SourceMeta } from "./types";
/**
* Parsed frontmatter from MDC rule files (Cursor format).
*/
export interface RuleFrontmatter {
description?: string;
globs?: string[];
alwaysApply?: boolean;
/** Regex pattern that triggers time-traveling rule injection */
ttsr_trigger?: string;
[key: string]: unknown;
}
/**
* A rule providing project-specific guidance and constraints.
*/
export interface Rule {
/** Rule name (derived from filename) */
name: string;
/** Absolute path to rule file */
path: string;
/** Rule content (after frontmatter stripped) */
content: string;
/** Globs this rule applies to (if any) */
globs?: string[];
/** Whether to always include this rule */
alwaysApply?: boolean;
/** Description (for agent-requested rules) */
description?: string;
/** Regex pattern that triggers time-traveling rule injection */
ttsrTrigger?: string;
/** Source metadata */
_source: SourceMeta;
}
export const ruleCapability = defineCapability<Rule>({
id: "rules",
displayName: "Rules",
description: "Project-specific rules and constraints (Cursor MDC, Windsurf, Cline formats)",
key: (rule) => rule.name,
validate: (rule) => {
if (!rule.name) return "Missing rule name";
if (!rule.path) return "Missing rule path";
if (!rule.content || typeof rule.content !== "string") return "Rule must have content";
return undefined;
},
});