@brainforge/core 3.0.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.
Files changed (3) hide show
  1. package/dist/index.d.ts +393 -0
  2. package/dist/index.js +3556 -0
  3. package/package.json +54 -0
@@ -0,0 +1,393 @@
1
+ import { EventEmitter } from 'events';
2
+
3
+ type ProjectType = 'student' | 'junior' | 'solo';
4
+ type StudentLevel = 'beginner' | 'intermediate' | 'advanced';
5
+ type Language = 'typescript' | 'javascript' | 'python' | 'java' | 'go' | 'php';
6
+ type PhaseStatus = 'pending' | 'active' | 'completed' | 'blocked';
7
+ type TaskStatus = 'todo' | 'in-progress' | 'done' | 'skipped';
8
+ interface ProjectConfig {
9
+ name: string;
10
+ description: string;
11
+ type: ProjectType;
12
+ language: Language;
13
+ framework?: string;
14
+ studentLevel?: StudentLevel;
15
+ }
16
+ interface Task {
17
+ id: string;
18
+ phaseId: string;
19
+ title: string;
20
+ description: string;
21
+ status: TaskStatus;
22
+ files?: string[];
23
+ context?: Record<string, unknown>;
24
+ createdAt: string;
25
+ updatedAt: string;
26
+ }
27
+ interface Phase {
28
+ id: string;
29
+ name: string;
30
+ description: string;
31
+ status: PhaseStatus;
32
+ tasks: Task[];
33
+ startedAt?: string;
34
+ completedAt?: string;
35
+ }
36
+ type AIProvider = 'claude' | 'openai' | 'gemini' | 'deepseek';
37
+ interface AIConfig {
38
+ provider: AIProvider;
39
+ model?: string;
40
+ apiKeyEnv: string;
41
+ }
42
+ interface BrainforgeState {
43
+ version: string;
44
+ project: ProjectConfig;
45
+ phases: Phase[];
46
+ activePhaseId?: string;
47
+ context: Record<string, unknown>;
48
+ aiConfig?: AIConfig;
49
+ metadata: {
50
+ createdAt: string;
51
+ updatedAt: string;
52
+ workingDirectory: string;
53
+ };
54
+ }
55
+
56
+ declare class StateManager {
57
+ private readonly workingDir;
58
+ private statePath;
59
+ private state;
60
+ constructor(workingDir: string);
61
+ load(): Promise<BrainforgeState>;
62
+ save(): Promise<void>;
63
+ init(project: ProjectConfig): Promise<BrainforgeState>;
64
+ get(): BrainforgeState;
65
+ set(updater: (state: BrainforgeState) => void): void;
66
+ configureAI(config: AIConfig): Promise<void>;
67
+ addPhase(phase: Omit<Phase, 'tasks'>): Promise<Phase>;
68
+ addTask(task: Task): Promise<void>;
69
+ updateTaskStatus(taskId: string, status: Task['status']): Promise<void>;
70
+ private writeDerivedViews;
71
+ private writeProjectMd;
72
+ private writeStateMd;
73
+ }
74
+
75
+ type StateAction = {
76
+ type: 'SET_ACTIVE_PHASE';
77
+ phaseId: string;
78
+ } | {
79
+ type: 'COMPLETE_PHASE';
80
+ phaseId: string;
81
+ } | {
82
+ type: 'UPDATE_TASK';
83
+ taskId: string;
84
+ updates: Partial<Task>;
85
+ } | {
86
+ type: 'SET_CONTEXT';
87
+ key: string;
88
+ value: unknown;
89
+ };
90
+ declare function reduce(state: BrainforgeState, action: StateAction): BrainforgeState;
91
+
92
+ interface FileChangeEvent {
93
+ type: 'add' | 'change' | 'unlink';
94
+ path: string;
95
+ timestamp: string;
96
+ }
97
+ declare class FileWatcher extends EventEmitter {
98
+ private watcher;
99
+ watch(rootDir: string, patterns?: string[]): void;
100
+ stop(): Promise<void>;
101
+ }
102
+
103
+ declare class PromptEngine {
104
+ private compiled;
105
+ constructor();
106
+ render(templateName: string, context: Record<string, unknown>): string;
107
+ registerTemplate(name: string, source: string): void;
108
+ listTemplates(): string[];
109
+ }
110
+
111
+ interface FunctionInfo {
112
+ name: string;
113
+ line: number;
114
+ isExported: boolean;
115
+ isAsync: boolean;
116
+ }
117
+ interface ClassInfo {
118
+ name: string;
119
+ line: number;
120
+ isExported: boolean;
121
+ methods: string[];
122
+ }
123
+ interface FileNode {
124
+ path: string;
125
+ language: Language;
126
+ functions: FunctionInfo[];
127
+ classes: ClassInfo[];
128
+ imports: string[];
129
+ exports: string[];
130
+ lastScanned: string;
131
+ }
132
+ interface CodebaseMap {
133
+ version: string;
134
+ scannedAt: string;
135
+ rootDir: string;
136
+ files: FileNode[];
137
+ stats: {
138
+ totalFiles: number;
139
+ totalFunctions: number;
140
+ totalClasses: number;
141
+ };
142
+ }
143
+
144
+ declare class CodebaseMapper {
145
+ private readonly workingDir;
146
+ constructor(workingDir: string);
147
+ scan(language: Language): Promise<CodebaseMap>;
148
+ load(): Promise<CodebaseMap>;
149
+ findRelevantFiles(map: CodebaseMap, query: string): FileNode[];
150
+ private findFiles;
151
+ private walk;
152
+ private saveMap;
153
+ }
154
+
155
+ type PlanAction = 'create' | 'modify' | 'delete' | 'review';
156
+ interface PlanStep {
157
+ id: string;
158
+ order: number;
159
+ action: PlanAction;
160
+ file: string;
161
+ description: string;
162
+ targetFunctions?: string[];
163
+ }
164
+ interface TaskPlan {
165
+ id: string;
166
+ title: string;
167
+ description: string;
168
+ impactedFiles: string[];
169
+ impactedFunctions: string[];
170
+ steps: PlanStep[];
171
+ estimatedComplexity: number;
172
+ risks: string[];
173
+ agentPrompt: string;
174
+ createdAt: string;
175
+ }
176
+
177
+ declare class TaskPlanner {
178
+ plan(title: string, description: string, map: CodebaseMap, relevantFiles: FileNode[], project: ProjectConfig): TaskPlan;
179
+ private buildSteps;
180
+ private inferAction;
181
+ private detectRisks;
182
+ private estimateComplexity;
183
+ private buildAgentPrompt;
184
+ }
185
+
186
+ type Severity = 'warn' | 'error';
187
+ interface HeuristicPattern {
188
+ id: string;
189
+ name: string;
190
+ explanation: string;
191
+ regex: RegExp;
192
+ languages: Language[];
193
+ flagForLevels: StudentLevel[];
194
+ severity: Severity;
195
+ }
196
+
197
+ interface PatternMatch {
198
+ patternId: string;
199
+ name: string;
200
+ explanation: string;
201
+ severity: Severity;
202
+ file: string;
203
+ line: number;
204
+ snippet: string;
205
+ }
206
+ interface ScanReport {
207
+ scannedAt: string;
208
+ language: Language;
209
+ studentLevel: StudentLevel;
210
+ totalFilesScanned: number;
211
+ matches: PatternMatch[];
212
+ summary: {
213
+ errors: number;
214
+ warnings: number;
215
+ clean: boolean;
216
+ };
217
+ }
218
+ declare class ProfessorScanner {
219
+ private readonly workingDir;
220
+ constructor(workingDir: string);
221
+ scan(language: Language, studentLevel: StudentLevel): Promise<ScanReport>;
222
+ private findFiles;
223
+ private walk;
224
+ private writeReport;
225
+ }
226
+
227
+ declare class BrainForgeServer {
228
+ private readonly workingDir;
229
+ readonly port: number;
230
+ private httpServer;
231
+ private wss;
232
+ private clients;
233
+ private readonly dashboardDir;
234
+ private boundPort;
235
+ constructor(workingDir: string, port?: number, dashboardDir?: string);
236
+ start(): Promise<void>;
237
+ stop(): void;
238
+ broadcast(type: string, payload: unknown): void;
239
+ get url(): string;
240
+ private handle;
241
+ private json;
242
+ private fileJson;
243
+ private fileText;
244
+ private static;
245
+ }
246
+
247
+ interface Question {
248
+ id: string;
249
+ text: string;
250
+ modelAnswer: string;
251
+ difficulty: 'easy' | 'medium' | 'hard';
252
+ languages: Language[];
253
+ levels: StudentLevel[];
254
+ patternId?: string;
255
+ }
256
+ interface DynamicQuestion {
257
+ text: string;
258
+ modelAnswer: string;
259
+ difficulty: 'easy' | 'medium' | 'hard';
260
+ }
261
+ declare function buildQuestionSet(project: {
262
+ language: Language;
263
+ studentLevel?: StudentLevel;
264
+ }, map: CodebaseMap, report: ScanReport | null, maxQuestions?: number): DynamicQuestion[];
265
+
266
+ interface DefenseAnswer {
267
+ question: string;
268
+ answer: string;
269
+ modelAnswer: string;
270
+ confidence: 1 | 2 | 3 | 4 | 5;
271
+ }
272
+ interface DefenseSession {
273
+ projectName: string;
274
+ language: string;
275
+ studentLevel: string;
276
+ completedAt: string;
277
+ questions: DefenseAnswer[];
278
+ averageConfidence: number;
279
+ }
280
+ declare class MockDefense {
281
+ private readonly workingDir;
282
+ constructor(workingDir: string);
283
+ selectQuestions(project: ProjectConfig, map: CodebaseMap, report: ScanReport | null, count?: number): DynamicQuestion[];
284
+ saveSession(session: DefenseSession): Promise<void>;
285
+ }
286
+
287
+ type SkillCategory = 'backend' | 'frontend' | 'database' | 'testing' | 'devops' | 'academic' | 'review' | 'general';
288
+ type ContextFieldType = 'text' | 'boolean' | 'select';
289
+ interface ContextField {
290
+ key: string;
291
+ label: string;
292
+ type: ContextFieldType;
293
+ placeholder?: string;
294
+ options?: string[];
295
+ default?: string | boolean;
296
+ }
297
+ interface Skill {
298
+ id: string;
299
+ name: string;
300
+ category: SkillCategory;
301
+ description: string;
302
+ template: string;
303
+ contextSchema: ContextField[];
304
+ tags: string[];
305
+ version: string;
306
+ }
307
+ interface SkillContext {
308
+ project: {
309
+ name: string;
310
+ language: string;
311
+ framework?: string;
312
+ type: string;
313
+ studentLevel?: string;
314
+ };
315
+ [key: string]: unknown;
316
+ }
317
+
318
+ declare class SkillRegistry {
319
+ private skills;
320
+ private compiled;
321
+ constructor();
322
+ register(skill: Skill): void;
323
+ loadUserSkills(skillsDir: string): Promise<void>;
324
+ get(id: string): Skill | undefined;
325
+ list(filter?: {
326
+ category?: SkillCategory;
327
+ tag?: string;
328
+ }): Skill[];
329
+ listByCategory(): Map<SkillCategory, Skill[]>;
330
+ render(id: string, context: SkillContext): string;
331
+ count(): {
332
+ builtin: number;
333
+ custom: number;
334
+ };
335
+ search(query: string): Skill[];
336
+ }
337
+
338
+ declare const BUILT_IN_SKILLS: Skill[];
339
+
340
+ interface CompletionOptions {
341
+ system?: string;
342
+ maxTokens?: number;
343
+ temperature?: number;
344
+ }
345
+ interface AIAdapter {
346
+ readonly provider: AIProvider;
347
+ readonly model: string;
348
+ complete(prompt: string, options?: CompletionOptions): Promise<string>;
349
+ isConfigured(): boolean;
350
+ }
351
+
352
+ declare class AdapterManager {
353
+ static create(config: AIConfig): AIAdapter;
354
+ static fromState(state: BrainforgeState): AIAdapter | null;
355
+ }
356
+
357
+ declare class ClaudeAdapter implements AIAdapter {
358
+ readonly provider: "claude";
359
+ readonly model: string;
360
+ private readonly apiKeyEnv;
361
+ constructor(config: AIConfig);
362
+ isConfigured(): boolean;
363
+ complete(prompt: string, options?: CompletionOptions): Promise<string>;
364
+ }
365
+
366
+ declare class OpenAIAdapter implements AIAdapter {
367
+ readonly provider: "openai";
368
+ readonly model: string;
369
+ private readonly apiKeyEnv;
370
+ constructor(config: AIConfig);
371
+ isConfigured(): boolean;
372
+ complete(prompt: string, options?: CompletionOptions): Promise<string>;
373
+ }
374
+
375
+ declare class GeminiAdapter implements AIAdapter {
376
+ readonly provider: "gemini";
377
+ readonly model: string;
378
+ private readonly apiKeyEnv;
379
+ constructor(config: AIConfig);
380
+ isConfigured(): boolean;
381
+ complete(prompt: string, options?: CompletionOptions): Promise<string>;
382
+ }
383
+
384
+ declare class DeepSeekAdapter implements AIAdapter {
385
+ readonly provider: "deepseek";
386
+ readonly model: string;
387
+ private readonly apiKeyEnv;
388
+ constructor(config: AIConfig);
389
+ isConfigured(): boolean;
390
+ complete(prompt: string, options?: CompletionOptions): Promise<string>;
391
+ }
392
+
393
+ export { type AIAdapter, type AIConfig, type AIProvider, AdapterManager, BUILT_IN_SKILLS, BrainForgeServer, type BrainforgeState, type ClassInfo, ClaudeAdapter, type CodebaseMap, CodebaseMapper, type CompletionOptions, type ContextField, DeepSeekAdapter, type DefenseAnswer, type DefenseSession, type DynamicQuestion, type FileChangeEvent, type FileNode, FileWatcher, type FunctionInfo, GeminiAdapter, type HeuristicPattern, type Language, MockDefense, OpenAIAdapter, type PatternMatch, type Phase, type PhaseStatus, type PlanAction, type PlanStep, ProfessorScanner, type ProjectConfig, type ProjectType, PromptEngine, type Question, type ScanReport, type Severity, type Skill, type SkillCategory, type SkillContext, SkillRegistry, type StateAction, StateManager, type StudentLevel, type Task, type TaskPlan, TaskPlanner, type TaskStatus, buildQuestionSet, reduce };