aiwf 0.3.15 → 0.3.17

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 (45) hide show
  1. package/README.ko.md +4 -5
  2. package/README.md +90 -196
  3. package/docs/ADR_MANAGEMENT_GUIDE.ko.md +602 -0
  4. package/docs/ADR_MANAGEMENT_GUIDE.md +602 -0
  5. package/docs/API_REFERENCE_FULL.ko.md +1135 -0
  6. package/docs/API_REFERENCE_FULL.md +1135 -0
  7. package/docs/ARCHITECTURE.ko.md +314 -0
  8. package/docs/ARCHITECTURE.md +314 -0
  9. package/docs/EXAMPLES.ko.md +695 -0
  10. package/docs/EXAMPLES.md +12 -12
  11. package/docs/GETTING_STARTED.ko.md +219 -0
  12. package/docs/GETTING_STARTED.md +19 -26
  13. package/docs/MODULE_MANAGEMENT_GUIDE.ko.md +289 -0
  14. package/docs/MODULE_MANAGEMENT_GUIDE.md +289 -0
  15. package/docs/PERFORMANCE_GUIDELINES.ko.md +388 -0
  16. package/docs/PRD.ko.md +2 -2
  17. package/docs/PRD.md +2 -2
  18. package/docs/TROUBLESHOOTING.ko.md +366 -0
  19. package/docs/YOLO_SYSTEM_GUIDE.ko.md +542 -0
  20. package/docs/YOLO_SYSTEM_GUIDE.md +542 -0
  21. package/package.json +50 -2
  22. package/src/DEPENDENCY_MAP.md +90 -0
  23. package/src/lib/installer.js +1 -0
  24. package/src/lib/resources/templates/api-server/template/src/controllers/aiwfController.ts +0 -14
  25. package/src/lib/resources/templates/api-server/template/src/routes/aiwf.ts +0 -11
  26. package/src/lib/resources/templates/web-app/template/src/pages/AiwfDashboard.tsx +2 -5
  27. package/src/lib/resources/utils/token-reporter.js +2 -3
  28. package/src/utils/checkpoint-manager.js +11 -1
  29. package/src/utils/engineering-guard.js +11 -1
  30. package/templates/api-server/template/src/controllers/aiwfController.ts +0 -14
  31. package/templates/api-server/template/src/routes/aiwf.ts +0 -11
  32. package/templates/web-app/template/src/pages/AiwfDashboard.tsx +2 -5
  33. package/docs/guides/feature-git-integration-guide-ko.md +0 -481
  34. package/docs/guides/feature-git-integration-guide.md +0 -481
  35. package/src/commands/cache-templates.js +0 -209
  36. package/src/commands/create-offline.js +0 -86
  37. package/src/commands/state-refactored.js +0 -419
  38. package/src/lib/resources/commands/feature-ledger.js +0 -565
  39. package/src/lib/resources/commands/feature_commit_report.js +0 -370
  40. package/src/lib/resources/commands/scan_git_history.js +0 -234
  41. package/src/lib/resources/commands/sync_feature_commits.js +0 -154
  42. package/src/lib/resources/templates/web-app/template/src/components/aiwf/FeatureLedger.tsx +0 -93
  43. package/src/lib/resources/utils/feature-updater.js +0 -271
  44. package/src/utils/git-integration.js +0 -173
  45. package/templates/web-app/template/src/components/aiwf/FeatureLedger.tsx +0 -93
@@ -0,0 +1,1135 @@
1
+ # AIWF Complete API Reference
2
+
3
+ [한국어로 보기](API_REFERENCE_FULL.ko.md)
4
+
5
+ ## Table of Contents
6
+
7
+ 1. [Core APIs](#core-apis)
8
+ - [Resource Loader](#resource-loader)
9
+ - [State Management](#state-management)
10
+ - [Template System](#template-system)
11
+ 2. [Command APIs](#command-apis)
12
+ - [AI Tool Command](#ai-tool-command)
13
+ - [Compress Command](#compress-command)
14
+ - [Create Project](#create-project)
15
+ - [Evaluate Command](#evaluate-command)
16
+ - [Feature Command](#feature-command)
17
+ - [Persona Command](#persona-command)
18
+ - [State Command](#state-command)
19
+ - [Token Command](#token-command)
20
+ - [YOLO Config](#yolo-config)
21
+ 3. [Utility APIs](#utility-apis)
22
+ - [Checkpoint Manager](#checkpoint-manager)
23
+ - [Git Utilities](#git-utilities)
24
+ - [Token Counter](#token-counter)
25
+ - [Text Processors](#text-processors)
26
+ 4. [Plugin APIs](#plugin-apis)
27
+ - [Plugin Interface](#plugin-interface)
28
+ - [Hook System](#hook-system)
29
+ 5. [AI Integration APIs](#ai-integration-apis)
30
+ - [Persona Manager](#persona-manager)
31
+ - [Compression Engine](#compression-engine)
32
+ - [Evaluation System](#evaluation-system)
33
+
34
+ ---
35
+
36
+ ## Core APIs
37
+
38
+ ### Resource Loader
39
+
40
+ The Resource Loader manages all framework resources, providing a unified interface for accessing bundled and user resources.
41
+
42
+ #### Class: `ResourceLoader`
43
+
44
+ ```javascript
45
+ import { ResourceLoader } from 'aiwf/lib/resource-loader';
46
+ ```
47
+
48
+ ##### Constructor
49
+
50
+ ```javascript
51
+ new ResourceLoader(options?: ResourceLoaderOptions)
52
+ ```
53
+
54
+ **Options:**
55
+ ```typescript
56
+ interface ResourceLoaderOptions {
57
+ bundledPath?: string; // Path to bundled resources
58
+ userPath?: string; // Path to user resources
59
+ preferUserResources?: boolean; // Prefer user over bundled (default: true)
60
+ }
61
+ ```
62
+
63
+ ##### Methods
64
+
65
+ ###### `resolvePath(resourceType, resourceName)`
66
+
67
+ Resolves the path to a resource, checking user directory first, then bundled resources.
68
+
69
+ ```javascript
70
+ async resolvePath(resourceType: string, resourceName: string): Promise<string>
71
+ ```
72
+
73
+ **Example:**
74
+ ```javascript
75
+ const loader = new ResourceLoader();
76
+ const personaPath = await loader.resolvePath('personas', 'analyst.json');
77
+ ```
78
+
79
+ ###### `loadResource(resourceType, resourceName)`
80
+
81
+ Loads and parses a resource file.
82
+
83
+ ```javascript
84
+ async loadResource(resourceType: string, resourceName: string): Promise<any>
85
+ ```
86
+
87
+ **Supported formats:**
88
+ - JSON (`.json`)
89
+ - YAML (`.yaml`, `.yml`)
90
+ - JavaScript modules (`.js`)
91
+ - Markdown (`.md`)
92
+
93
+ ###### `listResources(resourceType)`
94
+
95
+ Lists all available resources of a given type.
96
+
97
+ ```javascript
98
+ async listResources(resourceType: string): Promise<string[]>
99
+ ```
100
+
101
+ ###### `copyResource(resourceType, resourceName, destination)`
102
+
103
+ Copies a resource to a specified location.
104
+
105
+ ```javascript
106
+ async copyResource(
107
+ resourceType: string,
108
+ resourceName: string,
109
+ destination: string
110
+ ): Promise<void>
111
+ ```
112
+
113
+ ### State Management
114
+
115
+ Manages application and project state with support for checkpoints and atomic updates.
116
+
117
+ #### Class: `StateIndexManager`
118
+
119
+ ```javascript
120
+ import { StateIndexManager } from 'aiwf/lib/state/state-index';
121
+ ```
122
+
123
+ ##### Constructor
124
+
125
+ ```javascript
126
+ new StateIndexManager(aiwfPath: string)
127
+ ```
128
+
129
+ ##### Methods
130
+
131
+ ###### `loadState()`
132
+
133
+ Loads the current state from disk.
134
+
135
+ ```javascript
136
+ async loadState(): Promise<StateIndex>
137
+ ```
138
+
139
+ **Returns:**
140
+ ```typescript
141
+ interface StateIndex {
142
+ version: string;
143
+ last_updated: string;
144
+ last_updated_by: string;
145
+ project_info: ProjectInfo;
146
+ milestones: Milestone[];
147
+ sprints: Sprint[];
148
+ tasks: Task[];
149
+ workflow_mode: WorkflowMode;
150
+ }
151
+ ```
152
+
153
+ ###### `saveState(state)`
154
+
155
+ Saves state to disk with automatic backup.
156
+
157
+ ```javascript
158
+ async saveState(state: StateIndex): Promise<void>
159
+ ```
160
+
161
+ ###### `updateProjectInfo(updates)`
162
+
163
+ Updates project information.
164
+
165
+ ```javascript
166
+ async updateProjectInfo(updates: Partial<ProjectInfo>): Promise<void>
167
+ ```
168
+
169
+ ###### `addMilestone(milestone)`
170
+
171
+ Adds a new milestone to the project.
172
+
173
+ ```javascript
174
+ async addMilestone(milestone: Milestone): Promise<void>
175
+ ```
176
+
177
+ ### Template System
178
+
179
+ Manages project templates and code generation.
180
+
181
+ #### Class: `TemplateEngine`
182
+
183
+ ```javascript
184
+ import { TemplateEngine } from 'aiwf/lib/template-engine';
185
+ ```
186
+
187
+ ##### Methods
188
+
189
+ ###### `listTemplates()`
190
+
191
+ Lists all available project templates.
192
+
193
+ ```javascript
194
+ async listTemplates(): Promise<TemplateInfo[]>
195
+ ```
196
+
197
+ ###### `createFromTemplate(templateName, targetPath, variables)`
198
+
199
+ Creates a new project from a template.
200
+
201
+ ```javascript
202
+ async createFromTemplate(
203
+ templateName: string,
204
+ targetPath: string,
205
+ variables: Record<string, string>
206
+ ): Promise<void>
207
+ ```
208
+
209
+ **Example:**
210
+ ```javascript
211
+ const engine = new TemplateEngine();
212
+ await engine.createFromTemplate('api-server', './my-api', {
213
+ projectName: 'My API',
214
+ author: 'John Doe',
215
+ description: 'My awesome API server'
216
+ });
217
+ ```
218
+
219
+ ---
220
+
221
+ ## Command APIs
222
+
223
+ ### AI Tool Command
224
+
225
+ Manages AI tool integrations and configurations.
226
+
227
+ #### Class: `AIToolCommand`
228
+
229
+ ```javascript
230
+ import AIToolCommand from 'aiwf/commands/ai-tool';
231
+ ```
232
+
233
+ ##### Methods
234
+
235
+ ###### `execute(args)`
236
+
237
+ Executes AI tool commands.
238
+
239
+ ```javascript
240
+ async execute(args: string[]): Promise<void>
241
+ ```
242
+
243
+ **Subcommands:**
244
+ - `list` - List all available AI tools
245
+ - `activate <tool>` - Activate an AI tool
246
+ - `configure <tool>` - Configure an AI tool
247
+ - `status` - Show current AI tool status
248
+
249
+ ### Compress Command
250
+
251
+ Provides various compression strategies for optimizing context.
252
+
253
+ #### Functions
254
+
255
+ ###### `compress(mode, content, options)`
256
+
257
+ Compresses content using specified strategy.
258
+
259
+ ```javascript
260
+ async compress(
261
+ mode: CompressionMode,
262
+ content: string,
263
+ options?: CompressionOptions
264
+ ): Promise<string>
265
+ ```
266
+
267
+ **Compression Modes:**
268
+ - `simple` - Basic whitespace and comment removal
269
+ - `moderate` - Balanced compression
270
+ - `aggressive` - Maximum compression
271
+ - `custom` - User-defined rules
272
+
273
+ **Options:**
274
+ ```typescript
275
+ interface CompressionOptions {
276
+ preserveComments?: boolean;
277
+ preserveWhitespace?: boolean;
278
+ maxLineLength?: number;
279
+ customRules?: CompressionRule[];
280
+ }
281
+ ```
282
+
283
+ ### Create Project
284
+
285
+ Creates new AIWF projects from templates.
286
+
287
+ #### Function: `createProject`
288
+
289
+ ```javascript
290
+ async createProject(options: CreateProjectOptions): Promise<void>
291
+ ```
292
+
293
+ **Options:**
294
+ ```typescript
295
+ interface CreateProjectOptions {
296
+ template: string;
297
+ name: string;
298
+ path?: string;
299
+ variables?: Record<string, string>;
300
+ skipInstall?: boolean;
301
+ gitInit?: boolean;
302
+ }
303
+ ```
304
+
305
+ ### Evaluate Command
306
+
307
+ Evaluates AI responses and code quality.
308
+
309
+ #### Class: `EvaluateCommand`
310
+
311
+ ##### Methods
312
+
313
+ ###### `evaluateResponse(file, options)`
314
+
315
+ Evaluates the quality of an AI response.
316
+
317
+ ```javascript
318
+ async evaluateResponse(
319
+ file: string,
320
+ options?: EvaluationOptions
321
+ ): Promise<EvaluationResult>
322
+ ```
323
+
324
+ ###### `evaluateCode(file, options)`
325
+
326
+ Evaluates code quality and best practices.
327
+
328
+ ```javascript
329
+ async evaluateCode(
330
+ file: string,
331
+ options?: CodeEvaluationOptions
332
+ ): Promise<CodeEvaluationResult>
333
+ ```
334
+
335
+ ### Feature Command
336
+
337
+ Manages feature tracking and development workflow.
338
+
339
+ #### Functions
340
+
341
+ ###### `createFeature(name, description)`
342
+
343
+ Creates a new feature entry.
344
+
345
+ ```javascript
346
+ async createFeature(
347
+ name: string,
348
+ description?: string
349
+ ): Promise<FeatureEntry>
350
+ ```
351
+
352
+ ###### `updateFeatureStatus(id, status)`
353
+
354
+ Updates the status of a feature.
355
+
356
+ ```javascript
357
+ async updateFeatureStatus(
358
+ id: string,
359
+ status: FeatureStatus
360
+ ): Promise<void>
361
+ ```
362
+
363
+ **Feature Statuses:**
364
+ - `planned`
365
+ - `in-progress`
366
+ - `testing`
367
+ - `completed`
368
+ - `deployed`
369
+
370
+ ### Persona Command
371
+
372
+ Manages AI personas and their configurations.
373
+
374
+ #### Class: `PersonaCommand`
375
+
376
+ ##### Methods
377
+
378
+ ###### `listPersonas()`
379
+
380
+ Lists all available personas.
381
+
382
+ ```javascript
383
+ async listPersonas(): Promise<PersonaInfo[]>
384
+ ```
385
+
386
+ ###### `activatePersona(name)`
387
+
388
+ Activates a specific persona.
389
+
390
+ ```javascript
391
+ async activatePersona(name: string): Promise<void>
392
+ ```
393
+
394
+ ###### `createPersona(name, config)`
395
+
396
+ Creates a custom persona.
397
+
398
+ ```javascript
399
+ async createPersona(
400
+ name: string,
401
+ config: PersonaConfig
402
+ ): Promise<void>
403
+ ```
404
+
405
+ ### State Command
406
+
407
+ Manages project state and workflow transitions.
408
+
409
+ #### Class: `StateCommand`
410
+
411
+ ##### Methods
412
+
413
+ ###### `showStatus()`
414
+
415
+ Displays current project state.
416
+
417
+ ```javascript
418
+ async showStatus(): Promise<StateStatus>
419
+ ```
420
+
421
+ ###### `checkpoint(name, description)`
422
+
423
+ Creates a state checkpoint.
424
+
425
+ ```javascript
426
+ async checkpoint(
427
+ name: string,
428
+ description?: string
429
+ ): Promise<CheckpointInfo>
430
+ ```
431
+
432
+ ###### `restore(checkpointId)`
433
+
434
+ Restores from a checkpoint.
435
+
436
+ ```javascript
437
+ async restore(checkpointId: string): Promise<void>
438
+ ```
439
+
440
+ ### Token Command
441
+
442
+ Monitors and manages AI token usage.
443
+
444
+ #### Functions
445
+
446
+ ###### `trackUsage(input, output, model)`
447
+
448
+ Records token usage.
449
+
450
+ ```javascript
451
+ async trackUsage(
452
+ input: string,
453
+ output: string,
454
+ model?: string
455
+ ): Promise<UsageRecord>
456
+ ```
457
+
458
+ ###### `getUsageReport(period)`
459
+
460
+ Generates usage report.
461
+
462
+ ```javascript
463
+ async getUsageReport(
464
+ period?: 'day' | 'week' | 'month'
465
+ ): Promise<UsageReport>
466
+ ```
467
+
468
+ ### YOLO Config
469
+
470
+ Manages YOLO mode configuration.
471
+
472
+ #### Functions
473
+
474
+ ###### `createYoloConfig(options)`
475
+
476
+ Creates YOLO configuration file.
477
+
478
+ ```javascript
479
+ async createYoloConfig(options?: YoloOptions): Promise<void>
480
+ ```
481
+
482
+ ###### `createInteractiveYoloConfig()`
483
+
484
+ Creates configuration through interactive prompts.
485
+
486
+ ```javascript
487
+ async createInteractiveYoloConfig(): Promise<void>
488
+ ```
489
+
490
+ ---
491
+
492
+ ## Utility APIs
493
+
494
+ ### Engineering Guard
495
+
496
+ Prevents over-engineering and maintains code quality during autonomous execution.
497
+
498
+ #### Class: `EngineeringGuard`
499
+
500
+ ```javascript
501
+ import { EngineeringGuard } from 'aiwf/utils/engineering-guard';
502
+ ```
503
+
504
+ ##### Constructor
505
+
506
+ ```javascript
507
+ new EngineeringGuard(configPath?: string)
508
+ ```
509
+
510
+ ##### Methods
511
+
512
+ ###### `checkFileComplexity(filePath)`
513
+
514
+ Checks a single file for complexity violations.
515
+
516
+ ```javascript
517
+ async checkFileComplexity(filePath: string): Promise<void>
518
+ ```
519
+
520
+ ###### `checkProject(projectPath, filePatterns)`
521
+
522
+ Performs comprehensive project-wide complexity analysis.
523
+
524
+ ```javascript
525
+ async checkProject(
526
+ projectPath: string,
527
+ filePatterns?: string[]
528
+ ): Promise<GuardReport>
529
+ ```
530
+
531
+ **Returns:**
532
+ ```typescript
533
+ interface GuardReport {
534
+ passed: boolean;
535
+ violations: Violation[];
536
+ warnings: Warning[];
537
+ summary: {
538
+ total_violations: number;
539
+ high_severity: number;
540
+ medium_severity: number;
541
+ warnings: number;
542
+ };
543
+ recommendations: string[];
544
+ }
545
+ ```
546
+
547
+ ###### `provideFeedback(filePath, content)`
548
+
549
+ Provides real-time feedback during development.
550
+
551
+ ```javascript
552
+ async provideFeedback(
553
+ filePath: string,
554
+ content?: string
555
+ ): Promise<Feedback[]>
556
+ ```
557
+
558
+ ###### `generateReport()`
559
+
560
+ Generates comprehensive analysis report.
561
+
562
+ ```javascript
563
+ generateReport(): GuardReport
564
+ ```
565
+
566
+ ### Checkpoint Manager
567
+
568
+ Manages state checkpoints and recovery.
569
+
570
+ #### Class: `CheckpointManager`
571
+
572
+ ```javascript
573
+ import { CheckpointManager } from 'aiwf/utils/checkpoint-manager';
574
+ ```
575
+
576
+ ##### Constructor
577
+
578
+ ```javascript
579
+ new CheckpointManager(projectRoot: string)
580
+ ```
581
+
582
+ ##### Methods
583
+
584
+ ###### `startSession(sprintId, mode)`
585
+
586
+ Starts a new YOLO session with tracking.
587
+
588
+ ```javascript
589
+ async startSession(sprintId: string, mode?: string): Promise<void>
590
+ ```
591
+
592
+ ###### `startTask(taskId, taskInfo)`
593
+
594
+ Begins tracking a specific task.
595
+
596
+ ```javascript
597
+ async startTask(taskId: string, taskInfo?: any): Promise<void>
598
+ ```
599
+
600
+ ###### `completeTask(taskId, result)`
601
+
602
+ Marks a task as completed with results.
603
+
604
+ ```javascript
605
+ async completeTask(taskId: string, result?: any): Promise<void>
606
+ ```
607
+
608
+ ###### `createCheckpoint(type, metadata)`
609
+
610
+ Creates a new checkpoint.
611
+
612
+ ```javascript
613
+ async createCheckpoint(
614
+ type?: string,
615
+ metadata?: CheckpointMetadata
616
+ ): Promise<string>
617
+ ```
618
+
619
+ ###### `listCheckpoints()`
620
+
621
+ Lists all available checkpoints.
622
+
623
+ ```javascript
624
+ async listCheckpoints(): Promise<CheckpointInfo[]>
625
+ ```
626
+
627
+ ###### `restoreFromCheckpoint(checkpointId)`
628
+
629
+ Restores from a specific checkpoint.
630
+
631
+ ```javascript
632
+ async restoreFromCheckpoint(checkpointId: string): Promise<RestoreResult>
633
+ ```
634
+
635
+ **Returns:**
636
+ ```typescript
637
+ interface RestoreResult {
638
+ success: boolean;
639
+ checkpoint: Checkpoint;
640
+ tasks_to_resume: {
641
+ completed: string[];
642
+ current: string | null;
643
+ next_task_hint: string;
644
+ };
645
+ }
646
+ ```
647
+
648
+ ###### `generateProgressReport()`
649
+
650
+ Generates comprehensive progress report.
651
+
652
+ ```javascript
653
+ async generateProgressReport(): Promise<ProgressReport>
654
+ ```
655
+
656
+ **Returns:**
657
+ ```typescript
658
+ interface ProgressReport {
659
+ session: {
660
+ id: string;
661
+ started: string;
662
+ sprint: string;
663
+ mode: string;
664
+ };
665
+ progress: {
666
+ completed: number;
667
+ failed: number;
668
+ skipped: number;
669
+ current: string;
670
+ };
671
+ performance: {
672
+ total_time: string;
673
+ avg_task_time: string;
674
+ success_rate: string;
675
+ };
676
+ checkpoints: CheckpointInfo[];
677
+ recommendations: string[];
678
+ }
679
+ ```
680
+
681
+ ###### `endSession(summary)`
682
+
683
+ Ends the current session and generates final report.
684
+
685
+ ```javascript
686
+ async endSession(summary?: any): Promise<ProgressReport>
687
+ ```
688
+
689
+ ### Git Utilities
690
+
691
+ Provides Git integration utilities.
692
+
693
+ #### Functions
694
+
695
+ ###### `parseCommitMessage(message)`
696
+
697
+ Parses structured commit messages.
698
+
699
+ ```javascript
700
+ parseCommitMessage(message: string): ParsedCommit
701
+ ```
702
+
703
+ **Returns:**
704
+ ```typescript
705
+ interface ParsedCommit {
706
+ type: string;
707
+ scope?: string;
708
+ subject: string;
709
+ body?: string;
710
+ features?: string[];
711
+ tasks?: string[];
712
+ }
713
+ ```
714
+
715
+ ###### `getRecentCommits(limit)`
716
+
717
+ Gets recent commit history.
718
+
719
+ ```javascript
720
+ async getRecentCommits(limit?: number): Promise<Commit[]>
721
+ ```
722
+
723
+ ### Token Counter
724
+
725
+ Counts tokens for various AI models.
726
+
727
+ #### Functions
728
+
729
+ ###### `countTokens(text, model)`
730
+
731
+ Counts tokens in text.
732
+
733
+ ```javascript
734
+ countTokens(text: string, model?: string): number
735
+ ```
736
+
737
+ **Supported models:**
738
+ - `gpt-3.5-turbo`
739
+ - `gpt-4`
740
+ - `claude`
741
+ - `claude-instant`
742
+
743
+ ###### `estimateCost(tokens, model)`
744
+
745
+ Estimates cost based on token count.
746
+
747
+ ```javascript
748
+ estimateCost(tokens: number, model: string): number
749
+ ```
750
+
751
+ ### Text Processors
752
+
753
+ Various text processing utilities.
754
+
755
+ #### Functions
756
+
757
+ ###### `summarizeText(text, maxLength)`
758
+
759
+ Creates a summary of text.
760
+
761
+ ```javascript
762
+ async summarizeText(
763
+ text: string,
764
+ maxLength?: number
765
+ ): Promise<string>
766
+ ```
767
+
768
+ ###### `extractKeywords(text)`
769
+
770
+ Extracts keywords from text.
771
+
772
+ ```javascript
773
+ extractKeywords(text: string): string[]
774
+ ```
775
+
776
+ ###### `normalizeWhitespace(text)`
777
+
778
+ Normalizes whitespace in text.
779
+
780
+ ```javascript
781
+ normalizeWhitespace(text: string): string
782
+ ```
783
+
784
+ ---
785
+
786
+ ## Plugin APIs
787
+
788
+ ### Plugin Interface
789
+
790
+ Standard interface for AIWF plugins.
791
+
792
+ #### Interface: `AIWFPlugin`
793
+
794
+ ```typescript
795
+ interface AIWFPlugin {
796
+ name: string;
797
+ version: string;
798
+ description?: string;
799
+
800
+ // Lifecycle hooks
801
+ init?(context: PluginContext): Promise<void>;
802
+ destroy?(): Promise<void>;
803
+
804
+ // Command hooks
805
+ commands?: Record<string, CommandHandler>;
806
+
807
+ // Event hooks
808
+ hooks?: Record<string, HookHandler>;
809
+ }
810
+ ```
811
+
812
+ #### Plugin Context
813
+
814
+ ```typescript
815
+ interface PluginContext {
816
+ aiwfPath: string;
817
+ projectRoot: string;
818
+ config: AIWFConfig;
819
+ logger: Logger;
820
+
821
+ // Core services
822
+ resourceLoader: ResourceLoader;
823
+ stateManager: StateIndexManager;
824
+ templateEngine: TemplateEngine;
825
+ }
826
+ ```
827
+
828
+ ### Hook System
829
+
830
+ Event-driven extension system.
831
+
832
+ #### Available Hooks
833
+
834
+ ##### Command Lifecycle
835
+
836
+ ```javascript
837
+ hooks: {
838
+ 'before-command': async (command, args) => { /* ... */ },
839
+ 'after-command': async (command, result) => { /* ... */ },
840
+ 'command-error': async (command, error) => { /* ... */ }
841
+ }
842
+ ```
843
+
844
+ ##### State Management
845
+
846
+ ```javascript
847
+ hooks: {
848
+ 'before-state-change': async (oldState, newState) => { /* ... */ },
849
+ 'after-state-change': async (oldState, newState) => { /* ... */ },
850
+ 'state-checkpoint': async (checkpoint) => { /* ... */ }
851
+ }
852
+ ```
853
+
854
+ ##### Resource Loading
855
+
856
+ ```javascript
857
+ hooks: {
858
+ 'before-resource-load': async (type, name) => { /* ... */ },
859
+ 'after-resource-load': async (type, name, content) => { /* ... */ },
860
+ 'resource-not-found': async (type, name) => { /* ... */ }
861
+ }
862
+ ```
863
+
864
+ ---
865
+
866
+ ## AI Integration APIs
867
+
868
+ ### Persona Manager
869
+
870
+ Manages AI persona configurations and contexts.
871
+
872
+ #### Class: `AIPersonaManager`
873
+
874
+ ```javascript
875
+ import { AIPersonaManager } from 'aiwf/lib/ai-persona-manager';
876
+ ```
877
+
878
+ ##### Methods
879
+
880
+ ###### `loadPersona(name)`
881
+
882
+ Loads a persona configuration.
883
+
884
+ ```javascript
885
+ async loadPersona(name: string): Promise<Persona>
886
+ ```
887
+
888
+ ###### `applyPersona(content, persona)`
889
+
890
+ Applies persona context to content.
891
+
892
+ ```javascript
893
+ applyPersona(content: string, persona: Persona): string
894
+ ```
895
+
896
+ ###### `validatePersona(persona)`
897
+
898
+ Validates persona configuration.
899
+
900
+ ```javascript
901
+ validatePersona(persona: Persona): ValidationResult
902
+ ```
903
+
904
+ ### Compression Engine
905
+
906
+ Provides intelligent content compression.
907
+
908
+ #### Class: `CompressionEngine`
909
+
910
+ ##### Methods
911
+
912
+ ###### `compress(content, strategy)`
913
+
914
+ Compresses content using specified strategy.
915
+
916
+ ```javascript
917
+ async compress(
918
+ content: string,
919
+ strategy: CompressionStrategy
920
+ ): Promise<CompressedContent>
921
+ ```
922
+
923
+ ###### `decompress(compressed)`
924
+
925
+ Decompresses content.
926
+
927
+ ```javascript
928
+ async decompress(compressed: CompressedContent): Promise<string>
929
+ ```
930
+
931
+ ###### `analyzeCompression(content)`
932
+
933
+ Analyzes potential compression savings.
934
+
935
+ ```javascript
936
+ analyzeCompression(content: string): CompressionAnalysis
937
+ ```
938
+
939
+ ### Evaluation System
940
+
941
+ Evaluates AI responses and code quality.
942
+
943
+ #### Class: `EvaluationSystem`
944
+
945
+ ##### Methods
946
+
947
+ ###### `evaluateQuality(content, criteria)`
948
+
949
+ Evaluates content quality.
950
+
951
+ ```javascript
952
+ async evaluateQuality(
953
+ content: string,
954
+ criteria?: EvaluationCriteria
955
+ ): Promise<QualityScore>
956
+ ```
957
+
958
+ ###### `compareResponses(responses)`
959
+
960
+ Compares multiple AI responses.
961
+
962
+ ```javascript
963
+ compareResponses(responses: string[]): ComparisonResult
964
+ ```
965
+
966
+ ###### `generateReport(evaluations)`
967
+
968
+ Generates evaluation report.
969
+
970
+ ```javascript
971
+ generateReport(evaluations: Evaluation[]): EvaluationReport
972
+ ```
973
+
974
+ ---
975
+
976
+ ## Error Handling
977
+
978
+ All AIWF APIs follow consistent error handling patterns:
979
+
980
+ ```javascript
981
+ try {
982
+ const result = await aiwfApi.someMethod();
983
+ } catch (error) {
984
+ if (error.code === 'RESOURCE_NOT_FOUND') {
985
+ // Handle missing resource
986
+ } else if (error.code === 'VALIDATION_ERROR') {
987
+ // Handle validation error
988
+ console.error(error.details);
989
+ } else {
990
+ // Handle unexpected error
991
+ throw error;
992
+ }
993
+ }
994
+ ```
995
+
996
+ ### Error Codes
997
+
998
+ - `RESOURCE_NOT_FOUND` - Requested resource not found
999
+ - `VALIDATION_ERROR` - Input validation failed
1000
+ - `STATE_CONFLICT` - State operation conflict
1001
+ - `PERMISSION_DENIED` - Insufficient permissions
1002
+ - `NETWORK_ERROR` - Network operation failed
1003
+ - `TIMEOUT` - Operation timed out
1004
+
1005
+ ---
1006
+
1007
+ ## Best Practices
1008
+
1009
+ ### Resource Management
1010
+
1011
+ 1. Always use ResourceLoader for accessing framework resources
1012
+ 2. Prefer async methods for I/O operations
1013
+ 3. Handle resource not found errors gracefully
1014
+ 4. Cache expensive operations when possible
1015
+
1016
+ ### State Management
1017
+
1018
+ 1. Use atomic state updates to prevent conflicts
1019
+ 2. Create checkpoints before major operations
1020
+ 3. Validate state transitions
1021
+ 4. Handle concurrent modifications
1022
+
1023
+ ### Error Handling
1024
+
1025
+ 1. Use specific error codes for different scenarios
1026
+ 2. Provide meaningful error messages
1027
+ 3. Include context in error details
1028
+ 4. Log errors appropriately
1029
+
1030
+ ### Performance
1031
+
1032
+ 1. Use streaming for large files
1033
+ 2. Implement pagination for lists
1034
+ 3. Cache frequently accessed data
1035
+ 4. Monitor memory usage
1036
+
1037
+ ---
1038
+
1039
+ ## Examples
1040
+
1041
+ ### Creating a Custom Command
1042
+
1043
+ ```javascript
1044
+ import { ResourceLoader } from 'aiwf/lib/resource-loader';
1045
+ import { StateIndexManager } from 'aiwf/lib/state/state-index';
1046
+
1047
+ export default class CustomCommand {
1048
+ constructor() {
1049
+ this.loader = new ResourceLoader();
1050
+ this.stateManager = new StateIndexManager('.aiwf');
1051
+ }
1052
+
1053
+ async execute(args) {
1054
+ // Load current state
1055
+ const state = await this.stateManager.loadState();
1056
+
1057
+ // Perform operations
1058
+ // ...
1059
+
1060
+ // Save updated state
1061
+ await this.stateManager.saveState(state);
1062
+ }
1063
+ }
1064
+ ```
1065
+
1066
+ ### Creating a Plugin
1067
+
1068
+ ```javascript
1069
+ export default {
1070
+ name: 'my-plugin',
1071
+ version: '1.0.0',
1072
+
1073
+ async init(context) {
1074
+ this.logger = context.logger;
1075
+ this.logger.info('My plugin initialized');
1076
+ },
1077
+
1078
+ commands: {
1079
+ 'my-command': {
1080
+ description: 'My custom command',
1081
+ handler: async (args, options) => {
1082
+ // Command implementation
1083
+ }
1084
+ }
1085
+ },
1086
+
1087
+ hooks: {
1088
+ 'after-state-change': async (oldState, newState) => {
1089
+ this.logger.info('State changed', {
1090
+ from: oldState.workflow_mode,
1091
+ to: newState.workflow_mode
1092
+ });
1093
+ }
1094
+ }
1095
+ };
1096
+ ```
1097
+
1098
+ ### Using the Compression Engine
1099
+
1100
+ ```javascript
1101
+ import { CompressionEngine } from 'aiwf/utils/compression-engine';
1102
+
1103
+ const engine = new CompressionEngine();
1104
+
1105
+ // Analyze before compression
1106
+ const analysis = engine.analyzeCompression(largeContent);
1107
+ console.log(`Potential savings: ${analysis.savingsPercent}%`);
1108
+
1109
+ // Compress with specific strategy
1110
+ const compressed = await engine.compress(largeContent, {
1111
+ strategy: 'aggressive',
1112
+ preserveStructure: true
1113
+ });
1114
+
1115
+ // Later, decompress
1116
+ const original = await engine.decompress(compressed);
1117
+ ```
1118
+
1119
+ ---
1120
+
1121
+ ## Version History
1122
+
1123
+ - **v0.3.x** - Current stable release
1124
+ - Complete API redesign
1125
+ - Plugin system introduction
1126
+ - Enhanced state management
1127
+
1128
+ - **v0.2.x** - Legacy version
1129
+ - Basic command structure
1130
+ - Initial resource loader
1131
+
1132
+ - **v0.1.x** - Initial release
1133
+ - Core framework setup
1134
+
1135
+ For detailed changelog, see [CHANGELOG.md](../CHANGELOG.md).