@codedir/mimir-code 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,754 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * Core type definitions for Mimir
5
+ */
6
+ interface Message {
7
+ role: 'system' | 'user' | 'assistant';
8
+ content: string;
9
+ name?: string;
10
+ toolCalls?: ToolCall[];
11
+ metadata?: MessageMetadata;
12
+ }
13
+ interface MessageMetadata {
14
+ timestamp?: number;
15
+ duration?: number;
16
+ usage?: {
17
+ inputTokens: number;
18
+ outputTokens: number;
19
+ totalTokens: number;
20
+ };
21
+ cost?: number;
22
+ model?: string;
23
+ provider?: string;
24
+ }
25
+ interface ToolCall {
26
+ id: string;
27
+ name: string;
28
+ arguments: Record<string, unknown>;
29
+ }
30
+ interface ToolResult {
31
+ success: boolean;
32
+ data?: unknown;
33
+ error?: string;
34
+ }
35
+ interface ChatResponse {
36
+ content: string;
37
+ toolCalls?: ToolCall[];
38
+ finishReason: 'stop' | 'tool_calls' | 'length' | 'error';
39
+ usage: {
40
+ inputTokens: number;
41
+ outputTokens: number;
42
+ totalTokens: number;
43
+ };
44
+ }
45
+ interface ChatChunk {
46
+ content: string;
47
+ done: boolean;
48
+ }
49
+ type RiskLevel = 'low' | 'medium' | 'high' | 'critical';
50
+ interface PermissionDecision {
51
+ command: string;
52
+ riskLevel: RiskLevel;
53
+ decision: 'allow' | 'deny' | 'always' | 'never';
54
+ timestamp: number;
55
+ }
56
+ interface Action {
57
+ type: 'tool_call' | 'finish';
58
+ toolName?: string;
59
+ arguments?: Record<string, unknown>;
60
+ result?: unknown;
61
+ }
62
+ interface Observation {
63
+ type: 'tool_result' | 'permission_denied' | 'error';
64
+ data?: unknown;
65
+ error?: string;
66
+ }
67
+ interface LLMConfig {
68
+ provider: string;
69
+ model: string;
70
+ apiKey?: string;
71
+ baseURL?: string;
72
+ temperature: number;
73
+ maxTokens: number;
74
+ }
75
+ interface PermissionsConfig {
76
+ autoAccept: boolean;
77
+ acceptRiskLevel: RiskLevel;
78
+ alwaysAcceptCommands: string[];
79
+ }
80
+ interface DockerConfig {
81
+ enabled: boolean;
82
+ baseImage: string;
83
+ cpuLimit?: number;
84
+ memoryLimit?: string;
85
+ }
86
+ type Result<T, E = Error> = {
87
+ ok: true;
88
+ value: T;
89
+ } | {
90
+ ok: false;
91
+ error: E;
92
+ };
93
+ declare const createOk: <T>(value: T) => Result<T>;
94
+ declare const createErr: <E = Error>(error: E) => Result<never, E>;
95
+
96
+ /**
97
+ * LLM Provider abstraction interface
98
+ * All providers (DeepSeek, Anthropic, OpenAI, etc.) implement this interface
99
+ */
100
+
101
+ interface LLMTool {
102
+ name: string;
103
+ description: string;
104
+ schema: Record<string, unknown>;
105
+ }
106
+ interface ILLMProvider {
107
+ /**
108
+ * Send chat completion request
109
+ */
110
+ chat(messages: Message[], tools?: LLMTool[]): Promise<ChatResponse>;
111
+ /**
112
+ * Stream chat completion response
113
+ */
114
+ streamChat(messages: Message[], tools?: LLMTool[]): AsyncGenerator<ChatChunk>;
115
+ /**
116
+ * Count tokens in text
117
+ */
118
+ countTokens(text: string): number;
119
+ /**
120
+ * Calculate cost based on token usage
121
+ */
122
+ calculateCost(inputTokens: number, outputTokens: number): number;
123
+ /**
124
+ * Get provider name
125
+ */
126
+ getProviderName(): string;
127
+ /**
128
+ * Get model name
129
+ */
130
+ getModelName(): string;
131
+ }
132
+
133
+ /**
134
+ * Tool interface and registry
135
+ */
136
+
137
+ interface Tool {
138
+ name: string;
139
+ description: string;
140
+ schema: z.ZodObject<never>;
141
+ execute(args: unknown): Promise<ToolResult>;
142
+ }
143
+ declare class ToolRegistry {
144
+ private tools;
145
+ register(tool: Tool): void;
146
+ unregister(toolName: string): void;
147
+ get(toolName: string): Tool | undefined;
148
+ getAll(): Tool[];
149
+ has(toolName: string): boolean;
150
+ execute(toolName: string, args: unknown): Promise<ToolResult>;
151
+ }
152
+
153
+ /**
154
+ * Core Agent implementation (ReAct loop)
155
+ */
156
+
157
+ interface AgentConfig {
158
+ maxIterations: number;
159
+ budgetLimit?: number;
160
+ }
161
+ declare class Agent {
162
+ private toolRegistry;
163
+ private config;
164
+ private conversationHistory;
165
+ private currentIteration;
166
+ constructor(_provider: ILLMProvider, toolRegistry: ToolRegistry, config: AgentConfig);
167
+ run(task: string): Promise<Result<unknown>>;
168
+ private reason;
169
+ private act;
170
+ private observe;
171
+ }
172
+
173
+ /**
174
+ * Risk assessment for commands with detailed explanations
175
+ */
176
+
177
+ interface RiskAssessment {
178
+ level: RiskLevel;
179
+ reasons: string[];
180
+ score: number;
181
+ }
182
+
183
+ /**
184
+ * Permission system for command execution
185
+ */
186
+
187
+ declare class PermissionManager {
188
+ private riskAssessor;
189
+ private allowlist;
190
+ private blocklist;
191
+ private auditLog;
192
+ constructor();
193
+ checkPermission(command: string): Promise<{
194
+ allowed: boolean;
195
+ assessment: RiskAssessment;
196
+ }>;
197
+ addToAllowlist(pattern: string): void;
198
+ addToBlocklist(pattern: string): void;
199
+ private logDecision;
200
+ getAuditLog(): PermissionDecision[];
201
+ }
202
+
203
+ /**
204
+ * Base LLM Provider implementation
205
+ * Contains common logic for retry, error handling, etc.
206
+ */
207
+
208
+ interface RetryConfig {
209
+ maxRetries: number;
210
+ retryDelay: number;
211
+ backoffMultiplier: number;
212
+ }
213
+ declare abstract class BaseLLMProvider implements ILLMProvider {
214
+ protected config: LLMConfig;
215
+ protected retryConfig: RetryConfig;
216
+ constructor(config: LLMConfig, retryConfig?: RetryConfig);
217
+ abstract chat(messages: Message[], tools?: LLMTool[]): Promise<ChatResponse>;
218
+ abstract streamChat(messages: Message[], tools?: LLMTool[]): AsyncGenerator<ChatChunk>;
219
+ abstract countTokens(text: string): number;
220
+ abstract calculateCost(inputTokens: number, outputTokens: number): number;
221
+ getProviderName(): string;
222
+ getModelName(): string;
223
+ /**
224
+ * Retry wrapper for API calls
225
+ * Only retries on NetworkError (5xx server errors)
226
+ * Does NOT retry on auth errors, rate limits, or client errors
227
+ */
228
+ protected withRetry<T>(fn: () => Promise<T>): Promise<T>;
229
+ private sleep;
230
+ }
231
+
232
+ /**
233
+ * Factory for creating LLM provider instances
234
+ */
235
+
236
+ declare class ProviderFactory {
237
+ static create(config: LLMConfig): ILLMProvider;
238
+ }
239
+
240
+ /**
241
+ * Configuration schemas with Zod validation
242
+ */
243
+
244
+ declare const ConfigSchema: z.ZodObject<{
245
+ llm: z.ZodObject<{
246
+ provider: z.ZodEnum<["deepseek", "anthropic", "openai", "google", "gemini", "qwen", "ollama"]>;
247
+ model: z.ZodString;
248
+ apiKey: z.ZodOptional<z.ZodString>;
249
+ baseURL: z.ZodOptional<z.ZodString>;
250
+ temperature: z.ZodDefault<z.ZodNumber>;
251
+ maxTokens: z.ZodDefault<z.ZodNumber>;
252
+ }, "strip", z.ZodTypeAny, {
253
+ provider: "deepseek" | "anthropic" | "openai" | "google" | "gemini" | "qwen" | "ollama";
254
+ model: string;
255
+ temperature: number;
256
+ maxTokens: number;
257
+ apiKey?: string | undefined;
258
+ baseURL?: string | undefined;
259
+ }, {
260
+ provider: "deepseek" | "anthropic" | "openai" | "google" | "gemini" | "qwen" | "ollama";
261
+ model: string;
262
+ apiKey?: string | undefined;
263
+ baseURL?: string | undefined;
264
+ temperature?: number | undefined;
265
+ maxTokens?: number | undefined;
266
+ }>;
267
+ permissions: z.ZodObject<{
268
+ autoAccept: z.ZodDefault<z.ZodBoolean>;
269
+ acceptRiskLevel: z.ZodDefault<z.ZodEnum<["low", "medium", "high", "critical"]>>;
270
+ alwaysAcceptCommands: z.ZodEffects<z.ZodDefault<z.ZodNullable<z.ZodArray<z.ZodString, "many">>>, string[], string[] | null | undefined>;
271
+ }, "strip", z.ZodTypeAny, {
272
+ autoAccept: boolean;
273
+ acceptRiskLevel: "low" | "medium" | "high" | "critical";
274
+ alwaysAcceptCommands: string[];
275
+ }, {
276
+ autoAccept?: boolean | undefined;
277
+ acceptRiskLevel?: "low" | "medium" | "high" | "critical" | undefined;
278
+ alwaysAcceptCommands?: string[] | null | undefined;
279
+ }>;
280
+ keyBindings: z.ZodObject<{
281
+ interrupt: z.ZodDefault<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, string[], string | string[]>>;
282
+ accept: z.ZodDefault<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, string[], string | string[]>>;
283
+ modeSwitch: z.ZodDefault<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, string[], string | string[]>>;
284
+ editCommand: z.ZodDefault<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, string[], string | string[]>>;
285
+ showTooltip: z.ZodDefault<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, string[], string | string[]>>;
286
+ navigateUp: z.ZodDefault<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, string[], string | string[]>>;
287
+ navigateDown: z.ZodDefault<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, string[], string | string[]>>;
288
+ help: z.ZodDefault<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, string[], string | string[]>>;
289
+ clearScreen: z.ZodDefault<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, string[], string | string[]>>;
290
+ undo: z.ZodDefault<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, string[], string | string[]>>;
291
+ redo: z.ZodDefault<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, string[], string | string[]>>;
292
+ reject: z.ZodOptional<z.ZodDefault<z.ZodEffects<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>, string[], string | string[]>>>;
293
+ }, "strip", z.ZodTypeAny, {
294
+ interrupt: string[];
295
+ accept: string[];
296
+ modeSwitch: string[];
297
+ editCommand: string[];
298
+ showTooltip: string[];
299
+ navigateUp: string[];
300
+ navigateDown: string[];
301
+ help: string[];
302
+ clearScreen: string[];
303
+ undo: string[];
304
+ redo: string[];
305
+ reject?: string[] | undefined;
306
+ }, {
307
+ interrupt?: string | string[] | undefined;
308
+ accept?: string | string[] | undefined;
309
+ modeSwitch?: string | string[] | undefined;
310
+ editCommand?: string | string[] | undefined;
311
+ showTooltip?: string | string[] | undefined;
312
+ navigateUp?: string | string[] | undefined;
313
+ navigateDown?: string | string[] | undefined;
314
+ help?: string | string[] | undefined;
315
+ clearScreen?: string | string[] | undefined;
316
+ undo?: string | string[] | undefined;
317
+ redo?: string | string[] | undefined;
318
+ reject?: string | string[] | undefined;
319
+ }>;
320
+ docker: z.ZodObject<{
321
+ enabled: z.ZodDefault<z.ZodBoolean>;
322
+ baseImage: z.ZodDefault<z.ZodString>;
323
+ cpuLimit: z.ZodOptional<z.ZodNumber>;
324
+ memoryLimit: z.ZodOptional<z.ZodString>;
325
+ }, "strip", z.ZodTypeAny, {
326
+ enabled: boolean;
327
+ baseImage: string;
328
+ cpuLimit?: number | undefined;
329
+ memoryLimit?: string | undefined;
330
+ }, {
331
+ enabled?: boolean | undefined;
332
+ baseImage?: string | undefined;
333
+ cpuLimit?: number | undefined;
334
+ memoryLimit?: string | undefined;
335
+ }>;
336
+ ui: z.ZodObject<{
337
+ theme: z.ZodDefault<z.ZodEnum<["mimir", "dark", "light", "dark-colorblind", "light-colorblind", "dark-ansi", "light-ansi"]>>;
338
+ syntaxHighlighting: z.ZodDefault<z.ZodBoolean>;
339
+ showLineNumbers: z.ZodDefault<z.ZodBoolean>;
340
+ compactMode: z.ZodDefault<z.ZodBoolean>;
341
+ autocompleteAutoShow: z.ZodDefault<z.ZodBoolean>;
342
+ autocompleteExecuteOnSelect: z.ZodDefault<z.ZodBoolean>;
343
+ }, "strip", z.ZodTypeAny, {
344
+ theme: "mimir" | "dark" | "light" | "dark-colorblind" | "light-colorblind" | "dark-ansi" | "light-ansi";
345
+ syntaxHighlighting: boolean;
346
+ showLineNumbers: boolean;
347
+ compactMode: boolean;
348
+ autocompleteAutoShow: boolean;
349
+ autocompleteExecuteOnSelect: boolean;
350
+ }, {
351
+ theme?: "mimir" | "dark" | "light" | "dark-colorblind" | "light-colorblind" | "dark-ansi" | "light-ansi" | undefined;
352
+ syntaxHighlighting?: boolean | undefined;
353
+ showLineNumbers?: boolean | undefined;
354
+ compactMode?: boolean | undefined;
355
+ autocompleteAutoShow?: boolean | undefined;
356
+ autocompleteExecuteOnSelect?: boolean | undefined;
357
+ }>;
358
+ monitoring: z.ZodObject<{
359
+ metricsRetentionDays: z.ZodDefault<z.ZodNumber>;
360
+ enableHealthChecks: z.ZodDefault<z.ZodBoolean>;
361
+ healthCheckIntervalSeconds: z.ZodDefault<z.ZodNumber>;
362
+ slowOperationThresholdMs: z.ZodDefault<z.ZodNumber>;
363
+ batchWriteIntervalSeconds: z.ZodDefault<z.ZodNumber>;
364
+ }, "strip", z.ZodTypeAny, {
365
+ metricsRetentionDays: number;
366
+ enableHealthChecks: boolean;
367
+ healthCheckIntervalSeconds: number;
368
+ slowOperationThresholdMs: number;
369
+ batchWriteIntervalSeconds: number;
370
+ }, {
371
+ metricsRetentionDays?: number | undefined;
372
+ enableHealthChecks?: boolean | undefined;
373
+ healthCheckIntervalSeconds?: number | undefined;
374
+ slowOperationThresholdMs?: number | undefined;
375
+ batchWriteIntervalSeconds?: number | undefined;
376
+ }>;
377
+ budget: z.ZodObject<{
378
+ enabled: z.ZodDefault<z.ZodBoolean>;
379
+ dailyLimit: z.ZodOptional<z.ZodNumber>;
380
+ weeklyLimit: z.ZodOptional<z.ZodNumber>;
381
+ monthlyLimit: z.ZodOptional<z.ZodNumber>;
382
+ warningThreshold: z.ZodDefault<z.ZodNumber>;
383
+ }, "strip", z.ZodTypeAny, {
384
+ enabled: boolean;
385
+ warningThreshold: number;
386
+ dailyLimit?: number | undefined;
387
+ weeklyLimit?: number | undefined;
388
+ monthlyLimit?: number | undefined;
389
+ }, {
390
+ enabled?: boolean | undefined;
391
+ dailyLimit?: number | undefined;
392
+ weeklyLimit?: number | undefined;
393
+ monthlyLimit?: number | undefined;
394
+ warningThreshold?: number | undefined;
395
+ }>;
396
+ rateLimit: z.ZodObject<{
397
+ enabled: z.ZodDefault<z.ZodBoolean>;
398
+ commandsPerMinute: z.ZodDefault<z.ZodNumber>;
399
+ toolExecutionsPerMinute: z.ZodDefault<z.ZodNumber>;
400
+ llmCallsPerMinute: z.ZodDefault<z.ZodNumber>;
401
+ maxFileSizeMB: z.ZodDefault<z.ZodNumber>;
402
+ }, "strip", z.ZodTypeAny, {
403
+ enabled: boolean;
404
+ commandsPerMinute: number;
405
+ toolExecutionsPerMinute: number;
406
+ llmCallsPerMinute: number;
407
+ maxFileSizeMB: number;
408
+ }, {
409
+ enabled?: boolean | undefined;
410
+ commandsPerMinute?: number | undefined;
411
+ toolExecutionsPerMinute?: number | undefined;
412
+ llmCallsPerMinute?: number | undefined;
413
+ maxFileSizeMB?: number | undefined;
414
+ }>;
415
+ }, "strip", z.ZodTypeAny, {
416
+ permissions: {
417
+ autoAccept: boolean;
418
+ acceptRiskLevel: "low" | "medium" | "high" | "critical";
419
+ alwaysAcceptCommands: string[];
420
+ };
421
+ llm: {
422
+ provider: "deepseek" | "anthropic" | "openai" | "google" | "gemini" | "qwen" | "ollama";
423
+ model: string;
424
+ temperature: number;
425
+ maxTokens: number;
426
+ apiKey?: string | undefined;
427
+ baseURL?: string | undefined;
428
+ };
429
+ keyBindings: {
430
+ interrupt: string[];
431
+ accept: string[];
432
+ modeSwitch: string[];
433
+ editCommand: string[];
434
+ showTooltip: string[];
435
+ navigateUp: string[];
436
+ navigateDown: string[];
437
+ help: string[];
438
+ clearScreen: string[];
439
+ undo: string[];
440
+ redo: string[];
441
+ reject?: string[] | undefined;
442
+ };
443
+ docker: {
444
+ enabled: boolean;
445
+ baseImage: string;
446
+ cpuLimit?: number | undefined;
447
+ memoryLimit?: string | undefined;
448
+ };
449
+ ui: {
450
+ theme: "mimir" | "dark" | "light" | "dark-colorblind" | "light-colorblind" | "dark-ansi" | "light-ansi";
451
+ syntaxHighlighting: boolean;
452
+ showLineNumbers: boolean;
453
+ compactMode: boolean;
454
+ autocompleteAutoShow: boolean;
455
+ autocompleteExecuteOnSelect: boolean;
456
+ };
457
+ monitoring: {
458
+ metricsRetentionDays: number;
459
+ enableHealthChecks: boolean;
460
+ healthCheckIntervalSeconds: number;
461
+ slowOperationThresholdMs: number;
462
+ batchWriteIntervalSeconds: number;
463
+ };
464
+ budget: {
465
+ enabled: boolean;
466
+ warningThreshold: number;
467
+ dailyLimit?: number | undefined;
468
+ weeklyLimit?: number | undefined;
469
+ monthlyLimit?: number | undefined;
470
+ };
471
+ rateLimit: {
472
+ enabled: boolean;
473
+ commandsPerMinute: number;
474
+ toolExecutionsPerMinute: number;
475
+ llmCallsPerMinute: number;
476
+ maxFileSizeMB: number;
477
+ };
478
+ }, {
479
+ permissions: {
480
+ autoAccept?: boolean | undefined;
481
+ acceptRiskLevel?: "low" | "medium" | "high" | "critical" | undefined;
482
+ alwaysAcceptCommands?: string[] | null | undefined;
483
+ };
484
+ llm: {
485
+ provider: "deepseek" | "anthropic" | "openai" | "google" | "gemini" | "qwen" | "ollama";
486
+ model: string;
487
+ apiKey?: string | undefined;
488
+ baseURL?: string | undefined;
489
+ temperature?: number | undefined;
490
+ maxTokens?: number | undefined;
491
+ };
492
+ keyBindings: {
493
+ interrupt?: string | string[] | undefined;
494
+ accept?: string | string[] | undefined;
495
+ modeSwitch?: string | string[] | undefined;
496
+ editCommand?: string | string[] | undefined;
497
+ showTooltip?: string | string[] | undefined;
498
+ navigateUp?: string | string[] | undefined;
499
+ navigateDown?: string | string[] | undefined;
500
+ help?: string | string[] | undefined;
501
+ clearScreen?: string | string[] | undefined;
502
+ undo?: string | string[] | undefined;
503
+ redo?: string | string[] | undefined;
504
+ reject?: string | string[] | undefined;
505
+ };
506
+ docker: {
507
+ enabled?: boolean | undefined;
508
+ baseImage?: string | undefined;
509
+ cpuLimit?: number | undefined;
510
+ memoryLimit?: string | undefined;
511
+ };
512
+ ui: {
513
+ theme?: "mimir" | "dark" | "light" | "dark-colorblind" | "light-colorblind" | "dark-ansi" | "light-ansi" | undefined;
514
+ syntaxHighlighting?: boolean | undefined;
515
+ showLineNumbers?: boolean | undefined;
516
+ compactMode?: boolean | undefined;
517
+ autocompleteAutoShow?: boolean | undefined;
518
+ autocompleteExecuteOnSelect?: boolean | undefined;
519
+ };
520
+ monitoring: {
521
+ metricsRetentionDays?: number | undefined;
522
+ enableHealthChecks?: boolean | undefined;
523
+ healthCheckIntervalSeconds?: number | undefined;
524
+ slowOperationThresholdMs?: number | undefined;
525
+ batchWriteIntervalSeconds?: number | undefined;
526
+ };
527
+ budget: {
528
+ enabled?: boolean | undefined;
529
+ dailyLimit?: number | undefined;
530
+ weeklyLimit?: number | undefined;
531
+ monthlyLimit?: number | undefined;
532
+ warningThreshold?: number | undefined;
533
+ };
534
+ rateLimit: {
535
+ enabled?: boolean | undefined;
536
+ commandsPerMinute?: number | undefined;
537
+ toolExecutionsPerMinute?: number | undefined;
538
+ llmCallsPerMinute?: number | undefined;
539
+ maxFileSizeMB?: number | undefined;
540
+ };
541
+ }>;
542
+ type Config = z.infer<typeof ConfigSchema>;
543
+
544
+ /**
545
+ * Platform-agnostic file system interface
546
+ * Implementation will use fs/promises + globby
547
+ */
548
+ interface Stats {
549
+ isFile(): boolean;
550
+ isDirectory(): boolean;
551
+ size: number;
552
+ mtime: Date;
553
+ }
554
+ interface IFileSystem {
555
+ /**
556
+ * Read file contents as string
557
+ */
558
+ readFile(path: string, encoding?: BufferEncoding): Promise<string>;
559
+ /**
560
+ * Write content to file
561
+ */
562
+ writeFile(path: string, content: string, encoding?: BufferEncoding): Promise<void>;
563
+ /**
564
+ * Check if file or directory exists
565
+ */
566
+ exists(path: string): Promise<boolean>;
567
+ /**
568
+ * Create directory (recursive)
569
+ */
570
+ mkdir(path: string, options?: {
571
+ recursive?: boolean;
572
+ }): Promise<void>;
573
+ /**
574
+ * Read directory contents
575
+ */
576
+ readdir(path: string): Promise<string[]>;
577
+ /**
578
+ * Get file/directory stats
579
+ */
580
+ stat(path: string): Promise<Stats>;
581
+ /**
582
+ * Delete file
583
+ */
584
+ unlink(path: string): Promise<void>;
585
+ /**
586
+ * Remove directory (recursive)
587
+ */
588
+ rmdir(path: string, options?: {
589
+ recursive?: boolean;
590
+ }): Promise<void>;
591
+ /**
592
+ * Copy file
593
+ */
594
+ copyFile(src: string, dest: string): Promise<void>;
595
+ /**
596
+ * Find files matching glob pattern
597
+ */
598
+ glob(pattern: string, options?: {
599
+ cwd?: string;
600
+ ignore?: string[];
601
+ }): Promise<string[]>;
602
+ }
603
+
604
+ /**
605
+ * Allowlist loader for team-shared command permissions
606
+ * Loads from .mimir/allowlist.yml
607
+ */
608
+
609
+ /**
610
+ * Allowlist schema
611
+ */
612
+ declare const AllowlistSchema: z.ZodObject<{
613
+ commands: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
614
+ files: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
615
+ urls: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
616
+ envVars: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
617
+ bashCommands: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
618
+ }, "strip", z.ZodTypeAny, {
619
+ commands: string[];
620
+ files: string[];
621
+ urls: string[];
622
+ envVars: string[];
623
+ bashCommands: string[];
624
+ }, {
625
+ commands?: string[] | undefined;
626
+ files?: string[] | undefined;
627
+ urls?: string[] | undefined;
628
+ envVars?: string[] | undefined;
629
+ bashCommands?: string[] | undefined;
630
+ }>;
631
+ type Allowlist = z.infer<typeof AllowlistSchema>;
632
+
633
+ /**
634
+ * Configuration loader with hierarchy support
635
+ * Priority: CLI flags > env vars > project config > global config > defaults
636
+ */
637
+
638
+ interface ConfigLoadOptions {
639
+ projectRoot?: string;
640
+ cliFlags?: Partial<Config>;
641
+ }
642
+ interface ConfigLoadResult {
643
+ config: Config;
644
+ allowlist: Allowlist;
645
+ }
646
+ declare class ConfigLoader {
647
+ private fs;
648
+ private allowlistLoader;
649
+ constructor(fs: IFileSystem);
650
+ /**
651
+ * Load configuration with full hierarchy:
652
+ * 1. Default config
653
+ * 2. Global (~/.mimir/config.yml)
654
+ * 3. Project (.mimir/config.yml)
655
+ * 4. Environment variables (.env)
656
+ * 5. CLI flags
657
+ *
658
+ * Also loads allowlist from:
659
+ * 1. Global (~/.mimir/allowlist.yml)
660
+ * 2. Project (.mimir/allowlist.yml)
661
+ */
662
+ load(options?: ConfigLoadOptions): Promise<ConfigLoadResult>;
663
+ private getDefaults;
664
+ private loadGlobalConfig;
665
+ private loadProjectConfig;
666
+ private loadEnvConfig;
667
+ private merge;
668
+ save(config: Partial<Config>, scope: 'global' | 'project', projectRoot?: string): Promise<void>;
669
+ validate(config: unknown): Config;
670
+ }
671
+
672
+ /**
673
+ * FileSystemAdapter - Cross-platform file system implementation
674
+ * Uses Node.js fs/promises + globby for file operations
675
+ */
676
+
677
+ declare class FileSystemAdapter implements IFileSystem {
678
+ readFile(path: string, encoding?: BufferEncoding): Promise<string>;
679
+ writeFile(path: string, content: string, encoding?: BufferEncoding): Promise<void>;
680
+ exists(path: string): Promise<boolean>;
681
+ mkdir(path: string, options?: {
682
+ recursive?: boolean;
683
+ }): Promise<void>;
684
+ readdir(path: string): Promise<string[]>;
685
+ stat(path: string): Promise<Stats>;
686
+ unlink(path: string): Promise<void>;
687
+ rmdir(path: string, options?: {
688
+ recursive?: boolean;
689
+ }): Promise<void>;
690
+ copyFile(src: string, dest: string): Promise<void>;
691
+ glob(pattern: string, options?: {
692
+ cwd?: string;
693
+ ignore?: string[];
694
+ }): Promise<string[]>;
695
+ }
696
+
697
+ /**
698
+ * Logging utility using winston
699
+ */
700
+ type LogLevel = 'error' | 'warn' | 'info' | 'debug';
701
+ declare class Logger {
702
+ private logger;
703
+ private fileLoggingEnabled;
704
+ private consoleTransport;
705
+ constructor(logDir?: string);
706
+ error(message: string, meta?: Record<string, unknown>): void;
707
+ warn(message: string, meta?: Record<string, unknown>): void;
708
+ info(message: string, meta?: Record<string, unknown>): void;
709
+ debug(message: string, meta?: Record<string, unknown>): void;
710
+ /**
711
+ * Disable console logging (useful when Ink UI is active)
712
+ */
713
+ disableConsole(): void;
714
+ /**
715
+ * Enable console logging
716
+ */
717
+ enableConsole(): void;
718
+ }
719
+ declare const logger: Logger;
720
+
721
+ /**
722
+ * Custom error classes
723
+ */
724
+ declare class MimirError extends Error {
725
+ constructor(message: string);
726
+ }
727
+ declare class ConfigurationError extends MimirError {
728
+ constructor(message: string);
729
+ }
730
+ declare class ProviderError extends MimirError {
731
+ readonly provider?: string | undefined;
732
+ constructor(message: string, provider?: string | undefined);
733
+ }
734
+ declare class ToolExecutionError extends MimirError {
735
+ readonly toolName?: string | undefined;
736
+ constructor(message: string, toolName?: string | undefined);
737
+ }
738
+ declare class PermissionDeniedError extends MimirError {
739
+ readonly command?: string | undefined;
740
+ constructor(message: string, command?: string | undefined);
741
+ }
742
+ declare class DockerError extends MimirError {
743
+ constructor(message: string);
744
+ }
745
+ declare class NetworkError extends MimirError {
746
+ readonly statusCode?: number | undefined;
747
+ constructor(message: string, statusCode?: number | undefined);
748
+ }
749
+ declare class RateLimitError extends MimirError {
750
+ readonly retryAfter?: number | undefined;
751
+ constructor(message: string, retryAfter?: number | undefined);
752
+ }
753
+
754
+ export { type Action, Agent, type AgentConfig, BaseLLMProvider, type ChatChunk, type ChatResponse, type ConfigLoadOptions, type ConfigLoadResult, ConfigLoader, ConfigurationError, type DockerConfig, DockerError, FileSystemAdapter, type IFileSystem, type ILLMProvider, type LLMConfig, type LLMTool, type LogLevel, Logger, type Message, type MessageMetadata, MimirError, NetworkError, type Observation, type PermissionDecision, PermissionDeniedError, PermissionManager, type PermissionsConfig, ProviderError, ProviderFactory, RateLimitError, type Result, type RetryConfig, type RiskLevel, type Tool, type ToolCall, ToolExecutionError, ToolRegistry, type ToolResult, createErr, createOk, logger };