watchfix 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.
Files changed (91) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +99 -0
  3. package/dist/agents/base.d.ts +19 -0
  4. package/dist/agents/base.js +140 -0
  5. package/dist/agents/claude.d.ts +11 -0
  6. package/dist/agents/claude.js +6 -0
  7. package/dist/agents/codex.d.ts +11 -0
  8. package/dist/agents/codex.js +6 -0
  9. package/dist/agents/defaults.d.ts +21 -0
  10. package/dist/agents/defaults.js +21 -0
  11. package/dist/agents/gemini.d.ts +11 -0
  12. package/dist/agents/gemini.js +6 -0
  13. package/dist/agents/index.d.ts +19 -0
  14. package/dist/agents/index.js +63 -0
  15. package/dist/agents/types.d.ts +22 -0
  16. package/dist/agents/types.js +1 -0
  17. package/dist/cli/commands/clean.d.ts +9 -0
  18. package/dist/cli/commands/clean.js +173 -0
  19. package/dist/cli/commands/config.d.ts +7 -0
  20. package/dist/cli/commands/config.js +134 -0
  21. package/dist/cli/commands/fix.d.ts +12 -0
  22. package/dist/cli/commands/fix.js +391 -0
  23. package/dist/cli/commands/ignore.d.ts +7 -0
  24. package/dist/cli/commands/ignore.js +74 -0
  25. package/dist/cli/commands/init.d.ts +5 -0
  26. package/dist/cli/commands/init.js +115 -0
  27. package/dist/cli/commands/logs.d.ts +9 -0
  28. package/dist/cli/commands/logs.js +106 -0
  29. package/dist/cli/commands/show.d.ts +8 -0
  30. package/dist/cli/commands/show.js +165 -0
  31. package/dist/cli/commands/status.d.ts +7 -0
  32. package/dist/cli/commands/status.js +110 -0
  33. package/dist/cli/commands/stop.d.ts +7 -0
  34. package/dist/cli/commands/stop.js +106 -0
  35. package/dist/cli/commands/version.d.ts +7 -0
  36. package/dist/cli/commands/version.js +36 -0
  37. package/dist/cli/commands/watch.d.ts +10 -0
  38. package/dist/cli/commands/watch.js +204 -0
  39. package/dist/cli/index.d.ts +2 -0
  40. package/dist/cli/index.js +152 -0
  41. package/dist/config/loader.d.ts +4 -0
  42. package/dist/config/loader.js +96 -0
  43. package/dist/config/schema.d.ts +375 -0
  44. package/dist/config/schema.js +99 -0
  45. package/dist/db/index.d.ts +15 -0
  46. package/dist/db/index.js +71 -0
  47. package/dist/db/queries.d.ts +45 -0
  48. package/dist/db/queries.js +111 -0
  49. package/dist/db/schema.d.ts +4 -0
  50. package/dist/db/schema.js +84 -0
  51. package/dist/fixer/context.d.ts +9 -0
  52. package/dist/fixer/context.js +361 -0
  53. package/dist/fixer/index.d.ts +37 -0
  54. package/dist/fixer/index.js +398 -0
  55. package/dist/fixer/lock.d.ts +7 -0
  56. package/dist/fixer/lock.js +49 -0
  57. package/dist/fixer/output.d.ts +21 -0
  58. package/dist/fixer/output.js +108 -0
  59. package/dist/fixer/queue.d.ts +15 -0
  60. package/dist/fixer/queue.js +53 -0
  61. package/dist/fixer/verifier.d.ts +44 -0
  62. package/dist/fixer/verifier.js +133 -0
  63. package/dist/utils/daemon.d.ts +22 -0
  64. package/dist/utils/daemon.js +143 -0
  65. package/dist/utils/duration.d.ts +2 -0
  66. package/dist/utils/duration.js +31 -0
  67. package/dist/utils/errors.d.ts +17 -0
  68. package/dist/utils/errors.js +20 -0
  69. package/dist/utils/hash.d.ts +2 -0
  70. package/dist/utils/hash.js +18 -0
  71. package/dist/utils/http.d.ts +6 -0
  72. package/dist/utils/http.js +61 -0
  73. package/dist/utils/logger.d.ts +25 -0
  74. package/dist/utils/logger.js +85 -0
  75. package/dist/utils/process.d.ts +16 -0
  76. package/dist/utils/process.js +146 -0
  77. package/dist/watcher/index.d.ts +55 -0
  78. package/dist/watcher/index.js +234 -0
  79. package/dist/watcher/parser.d.ts +42 -0
  80. package/dist/watcher/parser.js +162 -0
  81. package/dist/watcher/patterns.d.ts +5 -0
  82. package/dist/watcher/patterns.js +92 -0
  83. package/dist/watcher/sources/command.d.ts +27 -0
  84. package/dist/watcher/sources/command.js +143 -0
  85. package/dist/watcher/sources/docker.d.ts +28 -0
  86. package/dist/watcher/sources/docker.js +183 -0
  87. package/dist/watcher/sources/file.d.ts +30 -0
  88. package/dist/watcher/sources/file.js +177 -0
  89. package/dist/watcher/sources/types.d.ts +27 -0
  90. package/dist/watcher/sources/types.js +1 -0
  91. package/package.json +38 -0
@@ -0,0 +1,375 @@
1
+ import { z } from 'zod';
2
+ declare const durationSchema: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
3
+ declare const fileSourceSchema: z.ZodObject<{
4
+ name: z.ZodString;
5
+ type: z.ZodLiteral<"file">;
6
+ path: z.ZodString;
7
+ }, "strip", z.ZodTypeAny, {
8
+ path: string;
9
+ name: string;
10
+ type: "file";
11
+ }, {
12
+ path: string;
13
+ name: string;
14
+ type: "file";
15
+ }>;
16
+ declare const dockerSourceSchema: z.ZodObject<{
17
+ name: z.ZodString;
18
+ type: z.ZodLiteral<"docker">;
19
+ container: z.ZodString;
20
+ }, "strip", z.ZodTypeAny, {
21
+ name: string;
22
+ type: "docker";
23
+ container: string;
24
+ }, {
25
+ name: string;
26
+ type: "docker";
27
+ container: string;
28
+ }>;
29
+ declare const commandSourceSchema: z.ZodObject<{
30
+ name: z.ZodString;
31
+ type: z.ZodLiteral<"command">;
32
+ run: z.ZodString;
33
+ interval: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
34
+ }, "strip", z.ZodTypeAny, {
35
+ name: string;
36
+ type: "command";
37
+ run: string;
38
+ interval: string;
39
+ }, {
40
+ name: string;
41
+ type: "command";
42
+ run: string;
43
+ interval: string;
44
+ }>;
45
+ declare const logSourceSchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
46
+ name: z.ZodString;
47
+ type: z.ZodLiteral<"file">;
48
+ path: z.ZodString;
49
+ }, "strip", z.ZodTypeAny, {
50
+ path: string;
51
+ name: string;
52
+ type: "file";
53
+ }, {
54
+ path: string;
55
+ name: string;
56
+ type: "file";
57
+ }>, z.ZodObject<{
58
+ name: z.ZodString;
59
+ type: z.ZodLiteral<"docker">;
60
+ container: z.ZodString;
61
+ }, "strip", z.ZodTypeAny, {
62
+ name: string;
63
+ type: "docker";
64
+ container: string;
65
+ }, {
66
+ name: string;
67
+ type: "docker";
68
+ container: string;
69
+ }>, z.ZodObject<{
70
+ name: z.ZodString;
71
+ type: z.ZodLiteral<"command">;
72
+ run: z.ZodString;
73
+ interval: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
74
+ }, "strip", z.ZodTypeAny, {
75
+ name: string;
76
+ type: "command";
77
+ run: string;
78
+ interval: string;
79
+ }, {
80
+ name: string;
81
+ type: "command";
82
+ run: string;
83
+ interval: string;
84
+ }>]>;
85
+ declare const patternSchema: z.ZodString;
86
+ declare const configSchema: z.ZodObject<{
87
+ project: z.ZodObject<{
88
+ name: z.ZodString;
89
+ root: z.ZodDefault<z.ZodString>;
90
+ }, "strip", z.ZodTypeAny, {
91
+ name: string;
92
+ root: string;
93
+ }, {
94
+ name: string;
95
+ root?: string | undefined;
96
+ }>;
97
+ agent: z.ZodObject<{
98
+ provider: z.ZodEnum<["claude", "gemini", "codex"]>;
99
+ timeout: z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
100
+ retries: z.ZodDefault<z.ZodNumber>;
101
+ command: z.ZodOptional<z.ZodString>;
102
+ args: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
103
+ stderr_is_progress: z.ZodOptional<z.ZodBoolean>;
104
+ }, "strip", z.ZodTypeAny, {
105
+ provider: "claude" | "gemini" | "codex";
106
+ timeout: string;
107
+ retries: number;
108
+ command?: string | undefined;
109
+ args?: string[] | undefined;
110
+ stderr_is_progress?: boolean | undefined;
111
+ }, {
112
+ provider: "claude" | "gemini" | "codex";
113
+ command?: string | undefined;
114
+ args?: string[] | undefined;
115
+ timeout?: string | undefined;
116
+ retries?: number | undefined;
117
+ stderr_is_progress?: boolean | undefined;
118
+ }>;
119
+ logs: z.ZodObject<{
120
+ sources: z.ZodEffects<z.ZodArray<z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
121
+ name: z.ZodString;
122
+ type: z.ZodLiteral<"file">;
123
+ path: z.ZodString;
124
+ }, "strip", z.ZodTypeAny, {
125
+ path: string;
126
+ name: string;
127
+ type: "file";
128
+ }, {
129
+ path: string;
130
+ name: string;
131
+ type: "file";
132
+ }>, z.ZodObject<{
133
+ name: z.ZodString;
134
+ type: z.ZodLiteral<"docker">;
135
+ container: z.ZodString;
136
+ }, "strip", z.ZodTypeAny, {
137
+ name: string;
138
+ type: "docker";
139
+ container: string;
140
+ }, {
141
+ name: string;
142
+ type: "docker";
143
+ container: string;
144
+ }>, z.ZodObject<{
145
+ name: z.ZodString;
146
+ type: z.ZodLiteral<"command">;
147
+ run: z.ZodString;
148
+ interval: z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
149
+ }, "strip", z.ZodTypeAny, {
150
+ name: string;
151
+ type: "command";
152
+ run: string;
153
+ interval: string;
154
+ }, {
155
+ name: string;
156
+ type: "command";
157
+ run: string;
158
+ interval: string;
159
+ }>]>, "many">, ({
160
+ path: string;
161
+ name: string;
162
+ type: "file";
163
+ } | {
164
+ name: string;
165
+ type: "docker";
166
+ container: string;
167
+ } | {
168
+ name: string;
169
+ type: "command";
170
+ run: string;
171
+ interval: string;
172
+ })[], ({
173
+ path: string;
174
+ name: string;
175
+ type: "file";
176
+ } | {
177
+ name: string;
178
+ type: "docker";
179
+ container: string;
180
+ } | {
181
+ name: string;
182
+ type: "command";
183
+ run: string;
184
+ interval: string;
185
+ })[]>;
186
+ context_lines_before: z.ZodDefault<z.ZodNumber>;
187
+ context_lines_after: z.ZodDefault<z.ZodNumber>;
188
+ max_line_buffer: z.ZodDefault<z.ZodNumber>;
189
+ }, "strip", z.ZodTypeAny, {
190
+ sources: ({
191
+ path: string;
192
+ name: string;
193
+ type: "file";
194
+ } | {
195
+ name: string;
196
+ type: "docker";
197
+ container: string;
198
+ } | {
199
+ name: string;
200
+ type: "command";
201
+ run: string;
202
+ interval: string;
203
+ })[];
204
+ context_lines_before: number;
205
+ context_lines_after: number;
206
+ max_line_buffer: number;
207
+ }, {
208
+ sources: ({
209
+ path: string;
210
+ name: string;
211
+ type: "file";
212
+ } | {
213
+ name: string;
214
+ type: "docker";
215
+ container: string;
216
+ } | {
217
+ name: string;
218
+ type: "command";
219
+ run: string;
220
+ interval: string;
221
+ })[];
222
+ context_lines_before?: number | undefined;
223
+ context_lines_after?: number | undefined;
224
+ max_line_buffer?: number | undefined;
225
+ }>;
226
+ verification: z.ZodDefault<z.ZodObject<{
227
+ test_commands: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
228
+ test_command_timeout: z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
229
+ health_checks: z.ZodDefault<z.ZodArray<z.ZodEffects<z.ZodString, string, string>, "many">>;
230
+ health_check_timeout: z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
231
+ wait_after_fix: z.ZodDefault<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
232
+ }, "strip", z.ZodTypeAny, {
233
+ test_commands: string[];
234
+ test_command_timeout: string;
235
+ health_checks: string[];
236
+ health_check_timeout: string;
237
+ wait_after_fix: string;
238
+ }, {
239
+ test_commands?: string[] | undefined;
240
+ test_command_timeout?: string | undefined;
241
+ health_checks?: string[] | undefined;
242
+ health_check_timeout?: string | undefined;
243
+ wait_after_fix?: string | undefined;
244
+ }>>;
245
+ limits: z.ZodDefault<z.ZodObject<{
246
+ max_attempts_per_error: z.ZodDefault<z.ZodNumber>;
247
+ }, "strip", z.ZodTypeAny, {
248
+ max_attempts_per_error: number;
249
+ }, {
250
+ max_attempts_per_error?: number | undefined;
251
+ }>>;
252
+ cleanup: z.ZodDefault<z.ZodObject<{
253
+ context_max_age_days: z.ZodDefault<z.ZodNumber>;
254
+ context_max_size_kb: z.ZodDefault<z.ZodNumber>;
255
+ }, "strip", z.ZodTypeAny, {
256
+ context_max_age_days: number;
257
+ context_max_size_kb: number;
258
+ }, {
259
+ context_max_age_days?: number | undefined;
260
+ context_max_size_kb?: number | undefined;
261
+ }>>;
262
+ patterns: z.ZodDefault<z.ZodObject<{
263
+ match: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
264
+ ignore: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
265
+ }, "strip", z.ZodTypeAny, {
266
+ ignore: string[];
267
+ match: string[];
268
+ }, {
269
+ ignore?: string[] | undefined;
270
+ match?: string[] | undefined;
271
+ }>>;
272
+ }, "strip", z.ZodTypeAny, {
273
+ project: {
274
+ name: string;
275
+ root: string;
276
+ };
277
+ agent: {
278
+ provider: "claude" | "gemini" | "codex";
279
+ timeout: string;
280
+ retries: number;
281
+ command?: string | undefined;
282
+ args?: string[] | undefined;
283
+ stderr_is_progress?: boolean | undefined;
284
+ };
285
+ logs: {
286
+ sources: ({
287
+ path: string;
288
+ name: string;
289
+ type: "file";
290
+ } | {
291
+ name: string;
292
+ type: "docker";
293
+ container: string;
294
+ } | {
295
+ name: string;
296
+ type: "command";
297
+ run: string;
298
+ interval: string;
299
+ })[];
300
+ context_lines_before: number;
301
+ context_lines_after: number;
302
+ max_line_buffer: number;
303
+ };
304
+ verification: {
305
+ test_commands: string[];
306
+ test_command_timeout: string;
307
+ health_checks: string[];
308
+ health_check_timeout: string;
309
+ wait_after_fix: string;
310
+ };
311
+ limits: {
312
+ max_attempts_per_error: number;
313
+ };
314
+ cleanup: {
315
+ context_max_age_days: number;
316
+ context_max_size_kb: number;
317
+ };
318
+ patterns: {
319
+ ignore: string[];
320
+ match: string[];
321
+ };
322
+ }, {
323
+ project: {
324
+ name: string;
325
+ root?: string | undefined;
326
+ };
327
+ agent: {
328
+ provider: "claude" | "gemini" | "codex";
329
+ command?: string | undefined;
330
+ args?: string[] | undefined;
331
+ timeout?: string | undefined;
332
+ retries?: number | undefined;
333
+ stderr_is_progress?: boolean | undefined;
334
+ };
335
+ logs: {
336
+ sources: ({
337
+ path: string;
338
+ name: string;
339
+ type: "file";
340
+ } | {
341
+ name: string;
342
+ type: "docker";
343
+ container: string;
344
+ } | {
345
+ name: string;
346
+ type: "command";
347
+ run: string;
348
+ interval: string;
349
+ })[];
350
+ context_lines_before?: number | undefined;
351
+ context_lines_after?: number | undefined;
352
+ max_line_buffer?: number | undefined;
353
+ };
354
+ verification?: {
355
+ test_commands?: string[] | undefined;
356
+ test_command_timeout?: string | undefined;
357
+ health_checks?: string[] | undefined;
358
+ health_check_timeout?: string | undefined;
359
+ wait_after_fix?: string | undefined;
360
+ } | undefined;
361
+ limits?: {
362
+ max_attempts_per_error?: number | undefined;
363
+ } | undefined;
364
+ cleanup?: {
365
+ context_max_age_days?: number | undefined;
366
+ context_max_size_kb?: number | undefined;
367
+ } | undefined;
368
+ patterns?: {
369
+ ignore?: string[] | undefined;
370
+ match?: string[] | undefined;
371
+ } | undefined;
372
+ }>;
373
+ type Config = z.infer<typeof configSchema>;
374
+ export { commandSourceSchema, configSchema, dockerSourceSchema, durationSchema, fileSourceSchema, logSourceSchema, patternSchema, };
375
+ export type { Config };
@@ -0,0 +1,99 @@
1
+ import { z } from 'zod';
2
+ const MAX_DURATION_MS = 24 * 60 * 60 * 1000;
3
+ const durationSchema = z
4
+ .string()
5
+ .regex(/^\d+[smh]$/, 'Duration must be a number followed by s, m, or h (e.g., "5m", "30s", "1h")')
6
+ .refine((value) => {
7
+ const amount = Number.parseInt(value.slice(0, -1), 10);
8
+ return amount > 0;
9
+ }, 'Duration must be greater than 0')
10
+ .refine((value) => {
11
+ const amount = Number.parseInt(value.slice(0, -1), 10);
12
+ const unit = value.slice(-1);
13
+ const msByUnit = {
14
+ s: 1000,
15
+ m: 60_000,
16
+ h: 3_600_000,
17
+ };
18
+ return amount * msByUnit[unit] <= MAX_DURATION_MS;
19
+ }, 'Duration cannot exceed 24 hours');
20
+ const fileSourceSchema = z.object({
21
+ name: z.string().min(1),
22
+ type: z.literal('file'),
23
+ path: z.string().min(1),
24
+ });
25
+ const dockerSourceSchema = z.object({
26
+ name: z.string().min(1),
27
+ type: z.literal('docker'),
28
+ container: z.string().min(1),
29
+ });
30
+ const commandSourceSchema = z.object({
31
+ name: z.string().min(1),
32
+ type: z.literal('command'),
33
+ run: z.string().min(1),
34
+ interval: durationSchema,
35
+ });
36
+ const logSourceSchema = z.discriminatedUnion('type', [
37
+ fileSourceSchema,
38
+ dockerSourceSchema,
39
+ commandSourceSchema,
40
+ ]);
41
+ const patternSchema = z.string().min(1);
42
+ const configSchema = z.object({
43
+ project: z.object({
44
+ name: z.string().min(1),
45
+ root: z.string().default('.'),
46
+ }),
47
+ agent: z.object({
48
+ provider: z.enum(['claude', 'gemini', 'codex']),
49
+ timeout: durationSchema.default('5m'),
50
+ retries: z.number().int().min(0).default(2),
51
+ command: z.string().optional(),
52
+ args: z.array(z.string()).optional(),
53
+ stderr_is_progress: z.boolean().optional(),
54
+ }),
55
+ logs: z.object({
56
+ sources: z
57
+ .array(logSourceSchema)
58
+ .min(1)
59
+ .refine((sources) => {
60
+ const names = sources.map((source) => source.name);
61
+ return names.length === new Set(names).size;
62
+ }, { message: 'Log source names must be unique' }),
63
+ context_lines_before: z.number().int().min(0).default(10),
64
+ context_lines_after: z.number().int().min(0).default(5),
65
+ max_line_buffer: z.number().int().min(100).default(10000),
66
+ }),
67
+ verification: z
68
+ .object({
69
+ test_commands: z.array(z.string()).default([]),
70
+ test_command_timeout: durationSchema.default('5m'),
71
+ health_checks: z
72
+ .array(z
73
+ .string()
74
+ .url()
75
+ .refine((url) => url.startsWith('http://') || url.startsWith('https://'), { message: 'Health check URL must use http:// or https://' }))
76
+ .default([]),
77
+ health_check_timeout: durationSchema.default('10s'),
78
+ wait_after_fix: durationSchema.default('5s'),
79
+ })
80
+ .default({}),
81
+ limits: z
82
+ .object({
83
+ max_attempts_per_error: z.number().int().min(1).default(3),
84
+ })
85
+ .default({}),
86
+ cleanup: z
87
+ .object({
88
+ context_max_age_days: z.number().int().min(1).default(7),
89
+ context_max_size_kb: z.number().int().min(64).default(256),
90
+ })
91
+ .default({}),
92
+ patterns: z
93
+ .object({
94
+ match: z.array(patternSchema).default([]),
95
+ ignore: z.array(patternSchema).default([]),
96
+ })
97
+ .default({}),
98
+ });
99
+ export { commandSourceSchema, configSchema, dockerSourceSchema, durationSchema, fileSourceSchema, logSourceSchema, patternSchema, };
@@ -0,0 +1,15 @@
1
+ import type { RunResult } from 'better-sqlite3';
2
+ type BindParams = unknown[] | Record<string, unknown>;
3
+ export declare class Database {
4
+ private readonly dbPath;
5
+ private db?;
6
+ constructor(dbPath: string);
7
+ private ensureDirectory;
8
+ private ensureOpen;
9
+ get<T = unknown>(sql: string, params?: BindParams): T | undefined;
10
+ all<T = unknown>(sql: string, params?: BindParams): T[];
11
+ run(sql: string, params?: BindParams): RunResult;
12
+ exec(sql: string): void;
13
+ close(): void;
14
+ }
15
+ export {};
@@ -0,0 +1,71 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import DatabaseDriver from 'better-sqlite3';
4
+ export class Database {
5
+ dbPath;
6
+ db;
7
+ constructor(dbPath) {
8
+ this.dbPath = dbPath;
9
+ }
10
+ ensureDirectory() {
11
+ if (this.dbPath === ':memory:' || this.dbPath.startsWith('file:')) {
12
+ return;
13
+ }
14
+ const directory = path.dirname(this.dbPath);
15
+ if (directory && directory !== '.' && directory !== path.sep) {
16
+ fs.mkdirSync(directory, { recursive: true });
17
+ }
18
+ }
19
+ ensureOpen() {
20
+ if (this.db) {
21
+ return this.db;
22
+ }
23
+ this.ensureDirectory();
24
+ const db = new DatabaseDriver(this.dbPath);
25
+ db.pragma('journal_mode = WAL');
26
+ db.pragma('busy_timeout = 5000');
27
+ db.pragma('synchronous = NORMAL');
28
+ this.db = db;
29
+ return db;
30
+ }
31
+ get(sql, params) {
32
+ const statement = this.ensureOpen().prepare(sql);
33
+ if (params === undefined) {
34
+ return statement.get();
35
+ }
36
+ if (Array.isArray(params)) {
37
+ return statement.get(...params);
38
+ }
39
+ return statement.get(params);
40
+ }
41
+ all(sql, params) {
42
+ const statement = this.ensureOpen().prepare(sql);
43
+ if (params === undefined) {
44
+ return statement.all();
45
+ }
46
+ if (Array.isArray(params)) {
47
+ return statement.all(...params);
48
+ }
49
+ return statement.all(params);
50
+ }
51
+ run(sql, params) {
52
+ const statement = this.ensureOpen().prepare(sql);
53
+ if (params === undefined) {
54
+ return statement.run();
55
+ }
56
+ if (Array.isArray(params)) {
57
+ return statement.run(...params);
58
+ }
59
+ return statement.run(params);
60
+ }
61
+ exec(sql) {
62
+ this.ensureOpen().exec(sql);
63
+ }
64
+ close() {
65
+ if (!this.db) {
66
+ return;
67
+ }
68
+ this.db.close();
69
+ this.db = undefined;
70
+ }
71
+ }
@@ -0,0 +1,45 @@
1
+ import type { ErrorStatus } from '../utils/errors.js';
2
+ import type { Database } from './index.js';
3
+ export type ErrorRecord = {
4
+ id: number;
5
+ hash: string;
6
+ source: string;
7
+ timestamp: string;
8
+ errorType: string;
9
+ message: string;
10
+ stackTrace: string | null;
11
+ rawLog: string;
12
+ status: ErrorStatus;
13
+ suggestion: string | null;
14
+ fixResult: string | null;
15
+ fixAttempts: number;
16
+ lockedBy: string | null;
17
+ lockedAt: string | null;
18
+ createdAt: string;
19
+ updatedAt: string;
20
+ };
21
+ export type ErrorInsert = {
22
+ hash: string;
23
+ source: string;
24
+ timestamp: string;
25
+ errorType: string;
26
+ message: string;
27
+ stackTrace?: string | null;
28
+ rawLog: string;
29
+ status?: ErrorStatus;
30
+ suggestion?: string | null;
31
+ fixResult?: string | null;
32
+ fixAttempts?: number;
33
+ lockedBy?: string | null;
34
+ lockedAt?: string | null;
35
+ createdAt?: string;
36
+ updatedAt?: string;
37
+ };
38
+ export type ActivityAction = 'watcher_start' | 'watcher_stop' | 'error_detected' | 'error_deduplicated' | 'analysis_start' | 'analysis_complete' | 'analysis_failed' | 'analysis_timeout' | 'fix_start' | 'fix_complete' | 'fix_failed' | 'fix_timeout' | 'verification_start' | 'verification_pass' | 'verification_fail' | 'error_ignored' | 'lock_acquired' | 'lock_released' | 'lock_expired' | 'stale_recovery';
39
+ export declare function insertError(db: Database, error: ErrorInsert): number;
40
+ export declare function getError(db: Database, id: number): ErrorRecord | null;
41
+ export declare function getErrorByHash(db: Database, hash: string): ErrorRecord | null;
42
+ export declare function updateErrorStatus(db: Database, id: number, status: ErrorStatus): boolean;
43
+ export declare function getErrorsByStatus(db: Database, statuses: ErrorStatus[]): ErrorRecord[];
44
+ export declare function getPendingErrors(db: Database): ErrorRecord[];
45
+ export declare function logActivity(db: Database, action: ActivityAction, errorId?: number, details?: string): void;