@compilr-dev/agents 0.0.1

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 (160) hide show
  1. package/README.md +1277 -0
  2. package/dist/agent.d.ts +1272 -0
  3. package/dist/agent.js +1912 -0
  4. package/dist/anchors/builtin.d.ts +24 -0
  5. package/dist/anchors/builtin.js +61 -0
  6. package/dist/anchors/index.d.ts +6 -0
  7. package/dist/anchors/index.js +5 -0
  8. package/dist/anchors/manager.d.ts +115 -0
  9. package/dist/anchors/manager.js +412 -0
  10. package/dist/anchors/types.d.ts +168 -0
  11. package/dist/anchors/types.js +10 -0
  12. package/dist/context/index.d.ts +12 -0
  13. package/dist/context/index.js +10 -0
  14. package/dist/context/manager.d.ts +224 -0
  15. package/dist/context/manager.js +770 -0
  16. package/dist/context/types.d.ts +377 -0
  17. package/dist/context/types.js +7 -0
  18. package/dist/costs/index.d.ts +8 -0
  19. package/dist/costs/index.js +7 -0
  20. package/dist/costs/tracker.d.ts +121 -0
  21. package/dist/costs/tracker.js +295 -0
  22. package/dist/costs/types.d.ts +157 -0
  23. package/dist/costs/types.js +8 -0
  24. package/dist/errors.d.ts +178 -0
  25. package/dist/errors.js +249 -0
  26. package/dist/guardrails/builtin.d.ts +27 -0
  27. package/dist/guardrails/builtin.js +223 -0
  28. package/dist/guardrails/index.d.ts +6 -0
  29. package/dist/guardrails/index.js +5 -0
  30. package/dist/guardrails/manager.d.ts +117 -0
  31. package/dist/guardrails/manager.js +288 -0
  32. package/dist/guardrails/types.d.ts +159 -0
  33. package/dist/guardrails/types.js +7 -0
  34. package/dist/hooks/index.d.ts +31 -0
  35. package/dist/hooks/index.js +29 -0
  36. package/dist/hooks/manager.d.ts +147 -0
  37. package/dist/hooks/manager.js +600 -0
  38. package/dist/hooks/types.d.ts +368 -0
  39. package/dist/hooks/types.js +12 -0
  40. package/dist/index.d.ts +45 -0
  41. package/dist/index.js +73 -0
  42. package/dist/mcp/client.d.ts +93 -0
  43. package/dist/mcp/client.js +287 -0
  44. package/dist/mcp/errors.d.ts +60 -0
  45. package/dist/mcp/errors.js +78 -0
  46. package/dist/mcp/index.d.ts +43 -0
  47. package/dist/mcp/index.js +45 -0
  48. package/dist/mcp/manager.d.ts +120 -0
  49. package/dist/mcp/manager.js +276 -0
  50. package/dist/mcp/tools.d.ts +54 -0
  51. package/dist/mcp/tools.js +99 -0
  52. package/dist/mcp/types.d.ts +150 -0
  53. package/dist/mcp/types.js +40 -0
  54. package/dist/memory/index.d.ts +8 -0
  55. package/dist/memory/index.js +7 -0
  56. package/dist/memory/loader.d.ts +114 -0
  57. package/dist/memory/loader.js +463 -0
  58. package/dist/memory/types.d.ts +182 -0
  59. package/dist/memory/types.js +8 -0
  60. package/dist/messages/index.d.ts +82 -0
  61. package/dist/messages/index.js +155 -0
  62. package/dist/permissions/index.d.ts +5 -0
  63. package/dist/permissions/index.js +4 -0
  64. package/dist/permissions/manager.d.ts +125 -0
  65. package/dist/permissions/manager.js +379 -0
  66. package/dist/permissions/types.d.ts +162 -0
  67. package/dist/permissions/types.js +7 -0
  68. package/dist/providers/claude.d.ts +90 -0
  69. package/dist/providers/claude.js +348 -0
  70. package/dist/providers/index.d.ts +8 -0
  71. package/dist/providers/index.js +11 -0
  72. package/dist/providers/mock.d.ts +133 -0
  73. package/dist/providers/mock.js +204 -0
  74. package/dist/providers/types.d.ts +168 -0
  75. package/dist/providers/types.js +4 -0
  76. package/dist/rate-limit/index.d.ts +45 -0
  77. package/dist/rate-limit/index.js +47 -0
  78. package/dist/rate-limit/limiter.d.ts +104 -0
  79. package/dist/rate-limit/limiter.js +326 -0
  80. package/dist/rate-limit/provider-wrapper.d.ts +112 -0
  81. package/dist/rate-limit/provider-wrapper.js +201 -0
  82. package/dist/rate-limit/retry.d.ts +108 -0
  83. package/dist/rate-limit/retry.js +287 -0
  84. package/dist/rate-limit/types.d.ts +181 -0
  85. package/dist/rate-limit/types.js +22 -0
  86. package/dist/rehearsal/file-analyzer.d.ts +22 -0
  87. package/dist/rehearsal/file-analyzer.js +351 -0
  88. package/dist/rehearsal/git-analyzer.d.ts +22 -0
  89. package/dist/rehearsal/git-analyzer.js +472 -0
  90. package/dist/rehearsal/index.d.ts +35 -0
  91. package/dist/rehearsal/index.js +36 -0
  92. package/dist/rehearsal/manager.d.ts +100 -0
  93. package/dist/rehearsal/manager.js +290 -0
  94. package/dist/rehearsal/types.d.ts +235 -0
  95. package/dist/rehearsal/types.js +8 -0
  96. package/dist/skills/index.d.ts +160 -0
  97. package/dist/skills/index.js +282 -0
  98. package/dist/state/agent-state.d.ts +41 -0
  99. package/dist/state/agent-state.js +88 -0
  100. package/dist/state/checkpointer.d.ts +110 -0
  101. package/dist/state/checkpointer.js +362 -0
  102. package/dist/state/errors.d.ts +66 -0
  103. package/dist/state/errors.js +88 -0
  104. package/dist/state/index.d.ts +35 -0
  105. package/dist/state/index.js +37 -0
  106. package/dist/state/serializer.d.ts +55 -0
  107. package/dist/state/serializer.js +172 -0
  108. package/dist/state/types.d.ts +312 -0
  109. package/dist/state/types.js +14 -0
  110. package/dist/tools/builtin/bash-output.d.ts +61 -0
  111. package/dist/tools/builtin/bash-output.js +90 -0
  112. package/dist/tools/builtin/bash.d.ts +150 -0
  113. package/dist/tools/builtin/bash.js +354 -0
  114. package/dist/tools/builtin/edit.d.ts +50 -0
  115. package/dist/tools/builtin/edit.js +215 -0
  116. package/dist/tools/builtin/glob.d.ts +62 -0
  117. package/dist/tools/builtin/glob.js +244 -0
  118. package/dist/tools/builtin/grep.d.ts +74 -0
  119. package/dist/tools/builtin/grep.js +363 -0
  120. package/dist/tools/builtin/index.d.ts +44 -0
  121. package/dist/tools/builtin/index.js +69 -0
  122. package/dist/tools/builtin/kill-shell.d.ts +44 -0
  123. package/dist/tools/builtin/kill-shell.js +80 -0
  124. package/dist/tools/builtin/read-file.d.ts +57 -0
  125. package/dist/tools/builtin/read-file.js +184 -0
  126. package/dist/tools/builtin/shell-manager.d.ts +176 -0
  127. package/dist/tools/builtin/shell-manager.js +337 -0
  128. package/dist/tools/builtin/task.d.ts +202 -0
  129. package/dist/tools/builtin/task.js +350 -0
  130. package/dist/tools/builtin/todo.d.ts +207 -0
  131. package/dist/tools/builtin/todo.js +453 -0
  132. package/dist/tools/builtin/utils.d.ts +27 -0
  133. package/dist/tools/builtin/utils.js +70 -0
  134. package/dist/tools/builtin/web-fetch.d.ts +96 -0
  135. package/dist/tools/builtin/web-fetch.js +290 -0
  136. package/dist/tools/builtin/write-file.d.ts +54 -0
  137. package/dist/tools/builtin/write-file.js +147 -0
  138. package/dist/tools/define.d.ts +60 -0
  139. package/dist/tools/define.js +65 -0
  140. package/dist/tools/index.d.ts +10 -0
  141. package/dist/tools/index.js +37 -0
  142. package/dist/tools/registry.d.ts +79 -0
  143. package/dist/tools/registry.js +151 -0
  144. package/dist/tools/types.d.ts +59 -0
  145. package/dist/tools/types.js +4 -0
  146. package/dist/tracing/hooks.d.ts +58 -0
  147. package/dist/tracing/hooks.js +377 -0
  148. package/dist/tracing/index.d.ts +51 -0
  149. package/dist/tracing/index.js +55 -0
  150. package/dist/tracing/logging.d.ts +78 -0
  151. package/dist/tracing/logging.js +310 -0
  152. package/dist/tracing/manager.d.ts +160 -0
  153. package/dist/tracing/manager.js +468 -0
  154. package/dist/tracing/otel.d.ts +102 -0
  155. package/dist/tracing/otel.js +246 -0
  156. package/dist/tracing/types.d.ts +346 -0
  157. package/dist/tracing/types.js +38 -0
  158. package/dist/utils/index.d.ts +23 -0
  159. package/dist/utils/index.js +44 -0
  160. package/package.json +79 -0
@@ -0,0 +1,290 @@
1
+ /**
2
+ * Rehearsal Manager
3
+ *
4
+ * Coordinates rehearsal analyzers to provide impact analysis
5
+ * for destructive operations before they are executed.
6
+ */
7
+ import { GitRehearsalAnalyzer } from './git-analyzer.js';
8
+ import { FileRehearsalAnalyzer } from './file-analyzer.js';
9
+ /**
10
+ * Severity level ordering for comparison
11
+ */
12
+ const SEVERITY_ORDER = {
13
+ low: 0,
14
+ medium: 1,
15
+ high: 2,
16
+ critical: 3,
17
+ };
18
+ /**
19
+ * Compare severity levels
20
+ */
21
+ function compareSeverity(a, b) {
22
+ return SEVERITY_ORDER[a] - SEVERITY_ORDER[b];
23
+ }
24
+ /**
25
+ * RehearsalManager - Coordinates impact analysis for destructive operations
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * const manager = new RehearsalManager({
30
+ * workingDirectory: '/path/to/project',
31
+ * });
32
+ *
33
+ * // Analyze before executing
34
+ * const result = await manager.rehearse('rm -rf node_modules');
35
+ *
36
+ * if (result.recommendation === 'abort') {
37
+ * console.log('Operation too dangerous:', result.warnings);
38
+ * } else if (result.recommendation === 'confirm') {
39
+ * const confirmed = await askUser(result.impact.summary);
40
+ * if (confirmed) {
41
+ * // Execute the operation
42
+ * }
43
+ * }
44
+ * ```
45
+ */
46
+ export class RehearsalManager {
47
+ analyzers = new Map();
48
+ workingDirectory;
49
+ warningThreshold;
50
+ sessionStartTime;
51
+ sessionModifiedFiles = new Set();
52
+ trackSessionFiles;
53
+ eventHandler;
54
+ constructor(options = {}) {
55
+ this.workingDirectory = options.workingDirectory ?? process.cwd();
56
+ this.warningThreshold = options.warningThreshold ?? 'medium';
57
+ this.sessionStartTime = options.sessionStartTime ?? new Date();
58
+ this.trackSessionFiles = options.trackSessionFiles ?? true;
59
+ // Add built-in analyzers if requested (default: true)
60
+ if (options.includeBuiltinAnalyzers !== false) {
61
+ this.registerAnalyzer(new GitRehearsalAnalyzer());
62
+ this.registerAnalyzer(new FileRehearsalAnalyzer());
63
+ }
64
+ // Add custom analyzers
65
+ if (options.analyzers) {
66
+ for (const analyzer of options.analyzers) {
67
+ this.registerAnalyzer(analyzer);
68
+ }
69
+ }
70
+ // Set up callbacks
71
+ if (options.onRehearsal) {
72
+ const rehearsalCallback = options.onRehearsal;
73
+ this.onEvent((event) => {
74
+ if (event.type === 'rehearsal_complete' && event.result) {
75
+ rehearsalCallback(event.result);
76
+ }
77
+ });
78
+ }
79
+ }
80
+ /**
81
+ * Register an analyzer
82
+ */
83
+ registerAnalyzer(analyzer) {
84
+ this.analyzers.set(analyzer.id, analyzer);
85
+ return this;
86
+ }
87
+ /**
88
+ * Unregister an analyzer
89
+ */
90
+ unregisterAnalyzer(id) {
91
+ return this.analyzers.delete(id);
92
+ }
93
+ /**
94
+ * Get all registered analyzers
95
+ */
96
+ getAnalyzers() {
97
+ return Array.from(this.analyzers.values());
98
+ }
99
+ /**
100
+ * Set event handler
101
+ */
102
+ onEvent(handler) {
103
+ this.eventHandler = handler;
104
+ return this;
105
+ }
106
+ /**
107
+ * Emit an event
108
+ */
109
+ emit(event) {
110
+ if (this.eventHandler) {
111
+ this.eventHandler(event);
112
+ }
113
+ }
114
+ /**
115
+ * Track a file as modified in this session
116
+ */
117
+ trackFileModification(filePath) {
118
+ if (this.trackSessionFiles) {
119
+ this.sessionModifiedFiles.add(filePath);
120
+ }
121
+ }
122
+ /**
123
+ * Get files modified in this session
124
+ */
125
+ getSessionModifiedFiles() {
126
+ return Array.from(this.sessionModifiedFiles);
127
+ }
128
+ /**
129
+ * Check if an operation is potentially destructive
130
+ */
131
+ isDestructive(operation) {
132
+ for (const analyzer of this.analyzers.values()) {
133
+ if (analyzer.canAnalyze(operation)) {
134
+ return true;
135
+ }
136
+ }
137
+ return false;
138
+ }
139
+ /**
140
+ * Find the appropriate analyzer for an operation
141
+ */
142
+ findAnalyzer(operation) {
143
+ for (const analyzer of this.analyzers.values()) {
144
+ if (analyzer.canAnalyze(operation)) {
145
+ return analyzer;
146
+ }
147
+ }
148
+ return undefined;
149
+ }
150
+ /**
151
+ * Rehearse an operation - analyze its impact before execution
152
+ *
153
+ * @param operation - The command or operation to analyze
154
+ * @returns Impact analysis result
155
+ */
156
+ async rehearse(operation) {
157
+ this.emit({
158
+ type: 'rehearsal_start',
159
+ operation,
160
+ timestamp: new Date(),
161
+ });
162
+ const context = {
163
+ workingDirectory: this.workingDirectory,
164
+ sessionModifiedFiles: this.getSessionModifiedFiles(),
165
+ sessionStartTime: this.sessionStartTime,
166
+ };
167
+ // Find appropriate analyzer
168
+ const analyzer = this.findAnalyzer(operation);
169
+ let result;
170
+ if (analyzer) {
171
+ result = await analyzer.analyze(operation, context);
172
+ }
173
+ else {
174
+ // No specific analyzer - return generic result
175
+ result = {
176
+ operation,
177
+ category: 'unknown',
178
+ isDestructive: false,
179
+ isReversible: true,
180
+ impact: {
181
+ filesAffected: 0,
182
+ linesAffected: 0,
183
+ affectedFiles: [],
184
+ summary: 'No specific analysis available for this operation',
185
+ },
186
+ severity: 'low',
187
+ warnings: [],
188
+ recommendation: 'proceed',
189
+ analysisTimeMs: 0,
190
+ };
191
+ }
192
+ // Emit warning if severity exceeds threshold
193
+ if (compareSeverity(result.severity, this.warningThreshold) >= 0) {
194
+ this.emit({
195
+ type: 'warning_triggered',
196
+ operation,
197
+ result,
198
+ timestamp: new Date(),
199
+ });
200
+ }
201
+ this.emit({
202
+ type: 'rehearsal_complete',
203
+ operation,
204
+ result,
205
+ timestamp: new Date(),
206
+ });
207
+ return result;
208
+ }
209
+ /**
210
+ * Rehearse multiple operations
211
+ */
212
+ async rehearseAll(operations) {
213
+ const results = [];
214
+ for (const operation of operations) {
215
+ const result = await this.rehearse(operation);
216
+ results.push(result);
217
+ }
218
+ return results;
219
+ }
220
+ /**
221
+ * Check if an operation should proceed based on rehearsal
222
+ *
223
+ * @returns true if safe to proceed, false if should abort
224
+ */
225
+ async shouldProceed(operation) {
226
+ const result = await this.rehearse(operation);
227
+ return result.recommendation === 'proceed' || result.recommendation === 'caution';
228
+ }
229
+ /**
230
+ * Get a formatted summary of a rehearsal result
231
+ */
232
+ formatResult(result) {
233
+ const lines = [];
234
+ // Header
235
+ lines.push(`=== Rehearsal Analysis ===`);
236
+ lines.push(`Operation: ${result.operation}`);
237
+ lines.push(`Category: ${result.category}`);
238
+ lines.push(`Severity: ${result.severity.toUpperCase()}`);
239
+ lines.push(`Recommendation: ${result.recommendation.toUpperCase()}`);
240
+ lines.push('');
241
+ // Impact summary
242
+ lines.push(`--- Impact ---`);
243
+ lines.push(result.impact.summary);
244
+ if (result.impact.filesAffected > 0) {
245
+ lines.push(`Files affected: ${String(result.impact.filesAffected)}`);
246
+ }
247
+ if (result.impact.linesAffected > 0) {
248
+ lines.push(`Lines affected: ${String(result.impact.linesAffected)}`);
249
+ }
250
+ if (result.impact.timeInvestment) {
251
+ lines.push(`Time investment: ${result.impact.timeInvestment}`);
252
+ }
253
+ lines.push('');
254
+ // Warnings
255
+ if (result.warnings.length > 0) {
256
+ lines.push(`--- Warnings ---`);
257
+ for (const warning of result.warnings) {
258
+ lines.push(`⚠️ ${warning}`);
259
+ }
260
+ lines.push('');
261
+ }
262
+ // Alternatives
263
+ if (result.alternatives && result.alternatives.length > 0) {
264
+ lines.push(`--- Safer Alternatives ---`);
265
+ for (const alt of result.alternatives) {
266
+ lines.push(`• ${alt}`);
267
+ }
268
+ lines.push('');
269
+ }
270
+ // Affected files (limited)
271
+ if (result.impact.affectedFiles.length > 0) {
272
+ lines.push(`--- Affected Files (first 10) ---`);
273
+ const filesToShow = result.impact.affectedFiles.slice(0, 10);
274
+ for (const file of filesToShow) {
275
+ const info = file.linesAffected ? ` (${String(file.linesAffected)} lines)` : '';
276
+ lines.push(`• ${file.path}${info}`);
277
+ }
278
+ if (result.impact.affectedFiles.length > 10) {
279
+ lines.push(`... and ${String(result.impact.affectedFiles.length - 10)} more files`);
280
+ }
281
+ }
282
+ return lines.join('\n');
283
+ }
284
+ }
285
+ /**
286
+ * Create a RehearsalManager with default configuration
287
+ */
288
+ export function createRehearsalManager(options) {
289
+ return new RehearsalManager(options);
290
+ }
@@ -0,0 +1,235 @@
1
+ /**
2
+ * Rehearsal System Types
3
+ *
4
+ * The Rehearsal system provides impact analysis for destructive operations
5
+ * before they are executed. This is a novel safety feature that goes beyond
6
+ * simple dry-run by actually analyzing what would be affected.
7
+ */
8
+ /**
9
+ * Severity level of the operation's potential impact
10
+ */
11
+ export type ImpactSeverity = 'low' | 'medium' | 'high' | 'critical';
12
+ /**
13
+ * Recommendation based on impact analysis
14
+ */
15
+ export type RehearsalRecommendation = 'proceed' | 'caution' | 'confirm' | 'abort';
16
+ /**
17
+ * Category of destructive operation
18
+ */
19
+ export type OperationCategory = 'git' | 'file' | 'database' | 'network' | 'system' | 'unknown';
20
+ /**
21
+ * Information about a file that would be affected
22
+ */
23
+ export interface AffectedFile {
24
+ /**
25
+ * Path to the file
26
+ */
27
+ path: string;
28
+ /**
29
+ * Type of change that would occur
30
+ */
31
+ changeType: 'delete' | 'overwrite' | 'reset' | 'modify';
32
+ /**
33
+ * Number of lines that would be affected (if applicable)
34
+ */
35
+ linesAffected?: number;
36
+ /**
37
+ * When the file was last modified
38
+ */
39
+ lastModified?: Date;
40
+ /**
41
+ * Size of the file in bytes
42
+ */
43
+ size?: number;
44
+ /**
45
+ * Whether this file has uncommitted changes (for git operations)
46
+ */
47
+ hasUncommittedChanges?: boolean;
48
+ }
49
+ /**
50
+ * Detailed impact analysis of a destructive operation
51
+ */
52
+ export interface RehearsalImpact {
53
+ /**
54
+ * Total number of files that would be affected
55
+ */
56
+ filesAffected: number;
57
+ /**
58
+ * Total lines of code that would be changed/lost
59
+ */
60
+ linesAffected: number;
61
+ /**
62
+ * List of affected files with details
63
+ */
64
+ affectedFiles: AffectedFile[];
65
+ /**
66
+ * Human-readable time investment summary
67
+ * e.g., "Files modified in the last 2 hours"
68
+ */
69
+ timeInvestment?: string;
70
+ /**
71
+ * Estimated hours of work that could be lost
72
+ */
73
+ estimatedWorkHours?: number;
74
+ /**
75
+ * Size of data that would be affected (in bytes)
76
+ */
77
+ dataSize?: number;
78
+ /**
79
+ * Human-readable summary of the impact
80
+ */
81
+ summary: string;
82
+ }
83
+ /**
84
+ * Result of rehearsing a destructive operation
85
+ */
86
+ export interface RehearsalResult {
87
+ /**
88
+ * The original operation/command being rehearsed
89
+ */
90
+ operation: string;
91
+ /**
92
+ * Category of the operation
93
+ */
94
+ category: OperationCategory;
95
+ /**
96
+ * Whether this operation is considered destructive
97
+ */
98
+ isDestructive: boolean;
99
+ /**
100
+ * Whether the operation can be reversed/undone
101
+ */
102
+ isReversible: boolean;
103
+ /**
104
+ * Detailed impact analysis
105
+ */
106
+ impact: RehearsalImpact;
107
+ /**
108
+ * Severity of the potential impact
109
+ */
110
+ severity: ImpactSeverity;
111
+ /**
112
+ * Warning messages about potential issues
113
+ */
114
+ warnings: string[];
115
+ /**
116
+ * Recommendation on how to proceed
117
+ */
118
+ recommendation: RehearsalRecommendation;
119
+ /**
120
+ * Suggested safer alternatives (if any)
121
+ */
122
+ alternatives?: string[];
123
+ /**
124
+ * Time taken to perform the analysis (ms)
125
+ */
126
+ analysisTimeMs: number;
127
+ }
128
+ /**
129
+ * Context provided to analyzers for better impact assessment
130
+ */
131
+ export interface RehearsalContext {
132
+ /**
133
+ * Working directory for the operation
134
+ */
135
+ workingDirectory: string;
136
+ /**
137
+ * Whether we're in a git repository
138
+ */
139
+ isGitRepo?: boolean;
140
+ /**
141
+ * Current git branch (if in a git repo)
142
+ */
143
+ currentBranch?: string;
144
+ /**
145
+ * Files that have been modified in this session
146
+ */
147
+ sessionModifiedFiles?: string[];
148
+ /**
149
+ * Start time of the current session (for time investment calculation)
150
+ */
151
+ sessionStartTime?: Date;
152
+ /**
153
+ * Additional context from the agent
154
+ */
155
+ agentContext?: Record<string, unknown>;
156
+ }
157
+ /**
158
+ * Interface for operation-specific analyzers
159
+ */
160
+ export interface RehearsalAnalyzer {
161
+ /**
162
+ * Unique identifier for this analyzer
163
+ */
164
+ readonly id: string;
165
+ /**
166
+ * Human-readable name
167
+ */
168
+ readonly name: string;
169
+ /**
170
+ * Category of operations this analyzer handles
171
+ */
172
+ readonly category: OperationCategory;
173
+ /**
174
+ * Patterns that this analyzer can handle
175
+ */
176
+ readonly patterns: RegExp[];
177
+ /**
178
+ * Check if this analyzer can handle the given operation
179
+ */
180
+ canAnalyze(operation: string): boolean;
181
+ /**
182
+ * Analyze the operation and return impact assessment
183
+ */
184
+ analyze(operation: string, context: RehearsalContext): Promise<RehearsalResult>;
185
+ }
186
+ /**
187
+ * Options for the RehearsalManager
188
+ */
189
+ export interface RehearsalManagerOptions {
190
+ /**
191
+ * Working directory (defaults to process.cwd())
192
+ */
193
+ workingDirectory?: string;
194
+ /**
195
+ * Custom analyzers to add
196
+ */
197
+ analyzers?: RehearsalAnalyzer[];
198
+ /**
199
+ * Whether to include built-in analyzers (default: true)
200
+ */
201
+ includeBuiltinAnalyzers?: boolean;
202
+ /**
203
+ * Minimum severity to trigger warnings (default: 'medium')
204
+ */
205
+ warningThreshold?: ImpactSeverity;
206
+ /**
207
+ * Callback when a rehearsal is performed
208
+ */
209
+ onRehearsal?: (result: RehearsalResult) => void;
210
+ /**
211
+ * Session start time for time investment calculations
212
+ */
213
+ sessionStartTime?: Date;
214
+ /**
215
+ * Track files modified during session
216
+ */
217
+ trackSessionFiles?: boolean;
218
+ }
219
+ /**
220
+ * Event types emitted by RehearsalManager
221
+ */
222
+ export type RehearsalEventType = 'rehearsal_start' | 'rehearsal_complete' | 'warning_triggered';
223
+ /**
224
+ * Events emitted during rehearsal
225
+ */
226
+ export interface RehearsalEvent {
227
+ type: RehearsalEventType;
228
+ operation: string;
229
+ result?: RehearsalResult;
230
+ timestamp: Date;
231
+ }
232
+ /**
233
+ * Handler for rehearsal events
234
+ */
235
+ export type RehearsalEventHandler = (event: RehearsalEvent) => void;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Rehearsal System Types
3
+ *
4
+ * The Rehearsal system provides impact analysis for destructive operations
5
+ * before they are executed. This is a novel safety feature that goes beyond
6
+ * simple dry-run by actually analyzing what would be affected.
7
+ */
8
+ export {};
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Skills System - Prompt expansions for specialized agent behavior
3
+ *
4
+ * Skills are reusable prompt templates that can be invoked to provide
5
+ * specialized capabilities to agents. They allow you to define
6
+ * domain-specific instructions that can be dynamically added to conversations.
7
+ */
8
+ /**
9
+ * Skill definition
10
+ */
11
+ export interface Skill {
12
+ /**
13
+ * Unique identifier for the skill
14
+ */
15
+ name: string;
16
+ /**
17
+ * Human-readable description of what the skill does
18
+ */
19
+ description: string;
20
+ /**
21
+ * The prompt content that will be expanded when the skill is invoked
22
+ */
23
+ prompt: string;
24
+ /**
25
+ * Optional tags for categorization
26
+ */
27
+ tags?: string[];
28
+ /**
29
+ * Optional version string
30
+ */
31
+ version?: string;
32
+ /**
33
+ * Whether this skill is enabled (default: true)
34
+ */
35
+ enabled?: boolean;
36
+ }
37
+ /**
38
+ * Result of invoking a skill
39
+ */
40
+ export interface SkillInvocationResult {
41
+ /**
42
+ * The skill that was invoked
43
+ */
44
+ skill: Skill;
45
+ /**
46
+ * The expanded prompt content
47
+ */
48
+ prompt: string;
49
+ /**
50
+ * Whether the invocation was successful
51
+ */
52
+ success: boolean;
53
+ /**
54
+ * Error message if invocation failed
55
+ */
56
+ error?: string;
57
+ }
58
+ /**
59
+ * Options for skill invocation
60
+ */
61
+ export interface SkillInvokeOptions {
62
+ /**
63
+ * Variables to interpolate into the skill prompt
64
+ * Use {{variable}} syntax in the prompt template
65
+ */
66
+ variables?: Record<string, string>;
67
+ /**
68
+ * Additional context to prepend to the prompt
69
+ */
70
+ context?: string;
71
+ }
72
+ /**
73
+ * Skill Registry - Manages skill registration and invocation
74
+ */
75
+ export declare class SkillRegistry {
76
+ private readonly skills;
77
+ /**
78
+ * Register a new skill
79
+ */
80
+ register(skill: Skill): void;
81
+ /**
82
+ * Register multiple skills at once
83
+ */
84
+ registerAll(skills: Skill[]): void;
85
+ /**
86
+ * Get a skill by name
87
+ */
88
+ get(name: string): Skill | undefined;
89
+ /**
90
+ * Check if a skill exists
91
+ */
92
+ has(name: string): boolean;
93
+ /**
94
+ * Get all registered skills
95
+ */
96
+ getAll(): Skill[];
97
+ /**
98
+ * Get all enabled skills
99
+ */
100
+ getEnabled(): Skill[];
101
+ /**
102
+ * Get skills by tag
103
+ */
104
+ getByTag(tag: string): Skill[];
105
+ /**
106
+ * Get skill names
107
+ */
108
+ getNames(): string[];
109
+ /**
110
+ * Remove a skill
111
+ */
112
+ remove(name: string): boolean;
113
+ /**
114
+ * Clear all skills
115
+ */
116
+ clear(): void;
117
+ /**
118
+ * Enable a skill
119
+ */
120
+ enable(name: string): boolean;
121
+ /**
122
+ * Disable a skill
123
+ */
124
+ disable(name: string): boolean;
125
+ /**
126
+ * Invoke a skill by name
127
+ */
128
+ invoke(name: string, options?: SkillInvokeOptions): SkillInvocationResult;
129
+ /**
130
+ * Get skill count
131
+ */
132
+ get size(): number;
133
+ }
134
+ /**
135
+ * Helper function to define a skill
136
+ */
137
+ export declare function defineSkill(options: {
138
+ name: string;
139
+ description: string;
140
+ prompt: string;
141
+ tags?: string[];
142
+ version?: string;
143
+ enabled?: boolean;
144
+ }): Skill;
145
+ /**
146
+ * Create a new skill registry
147
+ */
148
+ export declare function createSkillRegistry(): SkillRegistry;
149
+ /**
150
+ * Built-in skills that are commonly useful
151
+ */
152
+ export declare const builtinSkills: Skill[];
153
+ /**
154
+ * Get the default skill registry
155
+ */
156
+ export declare function getDefaultSkillRegistry(): SkillRegistry;
157
+ /**
158
+ * Reset the default registry to built-in skills only
159
+ */
160
+ export declare function resetDefaultSkillRegistry(): void;