@runhalo/engine 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,154 @@
1
+ /**
2
+ * Halo COPPA Rule Engine
3
+ * Core scanning logic for child safety compliance detection
4
+ *
5
+ * Sprint 2: Added rules 6-20 (coppa-sec-006 through coppa-default-020)
6
+ * Sprint 2: Added suppression system for // halo-ignore comments
7
+ * Sprint 1 Fixes: Added tree-sitter for AST analysis, YAML rule loading
8
+ */
9
+ import Parser from 'tree-sitter';
10
+ export type Severity = 'critical' | 'high' | 'medium' | 'low';
11
+ export interface Violation {
12
+ ruleId: string;
13
+ ruleName: string;
14
+ severity: Severity;
15
+ filePath: string;
16
+ line: number;
17
+ column: number;
18
+ message: string;
19
+ codeSnippet: string;
20
+ fixSuggestion: string;
21
+ penalty?: string;
22
+ suppressed?: boolean;
23
+ suppressionComment?: string;
24
+ }
25
+ export interface Rule {
26
+ id: string;
27
+ name: string;
28
+ severity: Severity;
29
+ description: string;
30
+ patterns: RegExp[];
31
+ fixSuggestion: string;
32
+ penalty: string;
33
+ languages: string[];
34
+ }
35
+ export interface SuppressionConfig {
36
+ enabled: boolean;
37
+ commentPattern: string;
38
+ }
39
+ export declare function loadRulesFromYAML(yamlPath: string): Rule[];
40
+ export declare class TreeSitterParser {
41
+ private parser;
42
+ constructor();
43
+ /**
44
+ * Initialize parser with language
45
+ */
46
+ initialize(language: 'typescript' | 'javascript'): void;
47
+ /**
48
+ * Parse code and return AST
49
+ */
50
+ parse(code: string, language?: 'typescript' | 'javascript'): Parser.Tree;
51
+ /**
52
+ * Find all function calls matching a name pattern
53
+ */
54
+ findFunctionCalls(code: string, functionName: string): Array<{
55
+ line: number;
56
+ column: number;
57
+ }>;
58
+ /**
59
+ * Extract all identifiers from code (for pattern matching)
60
+ */
61
+ extractIdentifiers(code: string): string[];
62
+ }
63
+ export declare const treeSitterParser: TreeSitterParser;
64
+ export declare const COPPA_RULES: Rule[];
65
+ export declare const ETHICAL_RULES: Rule[];
66
+ export interface IgnoreConfig {
67
+ /** File glob patterns to ignore entirely */
68
+ ignoredFiles: string[];
69
+ /** Global rule suppressions (rule ID → true) */
70
+ globalRuleSuppressions: Set<string>;
71
+ /** Per-file rule suppressions (filePath → Set of rule IDs) */
72
+ fileRuleSuppressions: Map<string, Set<string>>;
73
+ }
74
+ /**
75
+ * Parse a .haloignore file content
76
+ *
77
+ * Format:
78
+ * # comment
79
+ * path/to/file.ts — ignore entire file
80
+ * **\/*.test.ts — glob pattern to ignore files
81
+ * rule:coppa-auth-001 — globally suppress a rule
82
+ * src/auth.ts:coppa-auth-001 — suppress rule in specific file
83
+ */
84
+ export declare function parseHaloignore(content: string): IgnoreConfig;
85
+ /**
86
+ * Check if a file should be ignored based on .haloignore config
87
+ */
88
+ export declare function shouldIgnoreFile(filePath: string, config: IgnoreConfig): boolean;
89
+ /**
90
+ * Check if a violation should be ignored based on .haloignore config
91
+ */
92
+ export declare function shouldIgnoreViolation(violation: Violation, config: IgnoreConfig): boolean;
93
+ export interface EngineConfig {
94
+ includePatterns?: string[];
95
+ excludePatterns?: string[];
96
+ rules?: string[];
97
+ severityFilter?: Severity[];
98
+ suppressions?: {
99
+ enabled: boolean;
100
+ commentPattern?: string;
101
+ };
102
+ includeSuppressed?: boolean;
103
+ rulesPath?: string;
104
+ ignoreConfig?: IgnoreConfig;
105
+ projectDomains?: string[];
106
+ ethical?: boolean;
107
+ }
108
+ export interface ScanResult {
109
+ filePath: string;
110
+ violations: Violation[];
111
+ suppressedViolations?: Violation[];
112
+ scannedAt: string;
113
+ totalViolations: number;
114
+ suppressedCount: number;
115
+ }
116
+ export declare class HaloEngine {
117
+ private config;
118
+ private rules;
119
+ private treeSitter;
120
+ constructor(config?: EngineConfig);
121
+ /**
122
+ * Get the tree-sitter parser for advanced AST analysis
123
+ */
124
+ getParser(): TreeSitterParser;
125
+ /**
126
+ * Scan using tree-sitter AST analysis (advanced mode)
127
+ */
128
+ scanFileWithAST(filePath: string, content: string, language?: 'typescript' | 'javascript'): Violation[];
129
+ /**
130
+ * Get the ignore config (if any)
131
+ */
132
+ getIgnoreConfig(): IgnoreConfig | undefined;
133
+ /**
134
+ * Scan a single file for violations
135
+ */
136
+ scanFile(filePath: string, content: string): Violation[];
137
+ /**
138
+ * Get all rules
139
+ */
140
+ getRules(): Rule[];
141
+ /**
142
+ * Get rule by ID
143
+ */
144
+ getRule(ruleId: string): Rule | undefined;
145
+ /**
146
+ * Explain a rule (for MCP)
147
+ */
148
+ explainRule(ruleId: string): string;
149
+ /**
150
+ * Get fix suggestion for a rule (for MCP)
151
+ */
152
+ getFixSuggestion(ruleId: string): string;
153
+ }
154
+ export default HaloEngine;