agentvault 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/.dfx/local/network-id +4 -0
  2. package/.next/trace +2 -0
  3. package/.vercel/README.txt +11 -0
  4. package/.vercel/project.json +1 -0
  5. package/AGENTS.md +43 -0
  6. package/CHANGELOG.md +196 -0
  7. package/LICENSE +21 -0
  8. package/PLAN_VAULT_INTEGRATION.md +318 -0
  9. package/README.md +253 -0
  10. package/backups/agentvault-backup-test-agent-2026-02-12T17-54-28-967Z.json +28 -0
  11. package/backups/agentvault-backup-test-agent-2026-02-12T17-54-29-032Z.backup +1 -0
  12. package/backups/agentvault-backup-test-agent-2026-02-12T17-57-42-373Z.json +28 -0
  13. package/backups/agentvault-backup-test-agent-2026-02-12T17-57-42-428Z.backup +1 -0
  14. package/backups/agentvault-backup-test-agent-2026-02-12T18-52-25-132Z.json +28 -0
  15. package/backups/agentvault-backup-test-agent-2026-02-12T18-52-25-247Z.backup +1 -0
  16. package/backups/agentvault-backup-test-agent-2026-02-12T18-54-09-216Z.json +28 -0
  17. package/backups/agentvault-backup-test-agent-2026-02-12T18-54-09-283Z.backup +1 -0
  18. package/backups/agentvault-backup-test-agent-2026-02-12T22-18-22-772Z.backup +1 -0
  19. package/backups/agentvault-backup-test-agent-2026-02-12T22-18-22-793Z.json +28 -0
  20. package/backups/test-backup.json +28 -0
  21. package/dist/cli/commands/approve.d.ts +4 -0
  22. package/dist/cli/commands/approve.js +232 -0
  23. package/dist/cli/commands/archive.d.ts +4 -0
  24. package/dist/cli/commands/archive.js +192 -0
  25. package/dist/cli/commands/backup.d.ts +4 -0
  26. package/dist/cli/commands/backup.js +164 -0
  27. package/dist/cli/commands/cloud-backup.d.ts +4 -0
  28. package/dist/cli/commands/cloud-backup.js +221 -0
  29. package/dist/cli/commands/cycles.d.ts +8 -0
  30. package/dist/cli/commands/cycles.js +83 -0
  31. package/dist/cli/commands/decrypt.d.ts +16 -0
  32. package/dist/cli/commands/decrypt.js +101 -0
  33. package/dist/cli/commands/deploy.d.ts +32 -0
  34. package/dist/cli/commands/deploy.js +208 -0
  35. package/dist/cli/commands/exec.d.ts +26 -0
  36. package/dist/cli/commands/exec.js +109 -0
  37. package/dist/cli/commands/fetch.d.ts +23 -0
  38. package/dist/cli/commands/fetch.js +164 -0
  39. package/dist/cli/commands/health.d.ts +8 -0
  40. package/dist/cli/commands/health.js +72 -0
  41. package/dist/cli/commands/identity.d.ts +8 -0
  42. package/dist/cli/commands/identity.js +140 -0
  43. package/dist/cli/commands/inference.d.ts +4 -0
  44. package/dist/cli/commands/inference.js +225 -0
  45. package/dist/cli/commands/info.d.ts +8 -0
  46. package/dist/cli/commands/info.js +59 -0
  47. package/dist/cli/commands/init.d.ts +19 -0
  48. package/dist/cli/commands/init.js +135 -0
  49. package/dist/cli/commands/instrument.d.ts +8 -0
  50. package/dist/cli/commands/instrument.js +35 -0
  51. package/dist/cli/commands/list.d.ts +36 -0
  52. package/dist/cli/commands/list.js +173 -0
  53. package/dist/cli/commands/logs.d.ts +8 -0
  54. package/dist/cli/commands/logs.js +96 -0
  55. package/dist/cli/commands/monitor.d.ts +8 -0
  56. package/dist/cli/commands/monitor.js +84 -0
  57. package/dist/cli/commands/network.d.ts +14 -0
  58. package/dist/cli/commands/network.js +258 -0
  59. package/dist/cli/commands/package.d.ts +36 -0
  60. package/dist/cli/commands/package.js +188 -0
  61. package/dist/cli/commands/profile.d.ts +8 -0
  62. package/dist/cli/commands/profile.js +76 -0
  63. package/dist/cli/commands/promote.d.ts +8 -0
  64. package/dist/cli/commands/promote.js +89 -0
  65. package/dist/cli/commands/rebuild.d.ts +21 -0
  66. package/dist/cli/commands/rebuild.js +140 -0
  67. package/dist/cli/commands/rollback.d.ts +8 -0
  68. package/dist/cli/commands/rollback.js +120 -0
  69. package/dist/cli/commands/show.d.ts +36 -0
  70. package/dist/cli/commands/show.js +200 -0
  71. package/dist/cli/commands/stats.d.ts +8 -0
  72. package/dist/cli/commands/stats.js +34 -0
  73. package/dist/cli/commands/status.d.ts +14 -0
  74. package/dist/cli/commands/status.js +83 -0
  75. package/dist/cli/commands/test.d.ts +8 -0
  76. package/dist/cli/commands/test.js +109 -0
  77. package/dist/cli/commands/tokens.d.ts +8 -0
  78. package/dist/cli/commands/tokens.js +62 -0
  79. package/dist/cli/commands/trace.d.ts +8 -0
  80. package/dist/cli/commands/trace.js +68 -0
  81. package/dist/cli/commands/wallet-export.d.ts +13 -0
  82. package/dist/cli/commands/wallet-export.js +140 -0
  83. package/dist/cli/commands/wallet-history.d.ts +10 -0
  84. package/dist/cli/commands/wallet-history.js +127 -0
  85. package/dist/cli/commands/wallet-import.d.ts +10 -0
  86. package/dist/cli/commands/wallet-import.js +209 -0
  87. package/dist/cli/commands/wallet-multi-send.d.ts +17 -0
  88. package/dist/cli/commands/wallet-multi-send.js +195 -0
  89. package/dist/cli/commands/wallet-process-queue.d.ts +19 -0
  90. package/dist/cli/commands/wallet-process-queue.js +209 -0
  91. package/dist/cli/commands/wallet-sign.d.ts +13 -0
  92. package/dist/cli/commands/wallet-sign.js +207 -0
  93. package/dist/cli/commands/wallet.d.ts +12 -0
  94. package/dist/cli/commands/wallet.js +794 -0
  95. package/dist/cli/index.d.ts +10 -0
  96. package/dist/cli/index.js +96 -0
  97. package/dist/vitest.config.d.ts +3 -0
  98. package/dist/vitest.config.js +14 -0
  99. package/fixup_1_0_OSS_release.md +136 -0
  100. package/fixup_REALEASE_PRD.md +136 -0
  101. package/package.json +79 -0
  102. package/pnpm-workspace.yaml +5 -0
  103. package/scripts/dev-dashboard.mjs +84 -0
  104. package/site/README.md +63 -0
  105. package/site/docusaurus.config.ts +148 -0
  106. package/site/package-lock.json +18383 -0
  107. package/site/package.json +47 -0
  108. package/site/sidebars.ts +86 -0
  109. package/site/static/.gitkeep +0 -0
  110. package/site/static/img/logo.svg +28 -0
  111. package/site/static/img/og-image.svg +35 -0
  112. package/src/archival/archive-manager.ts +372 -0
  113. package/src/archival/arweave-client.ts +289 -0
  114. package/src/archival/index.ts +8 -0
  115. package/src/backup/backup.ts +315 -0
  116. package/src/backup/index.ts +7 -0
  117. package/src/cloud-storage/cloud-sync.ts +461 -0
  118. package/src/cloud-storage/index.ts +11 -0
  119. package/src/cloud-storage/provider-detector.ts +198 -0
  120. package/src/cloud-storage/types.ts +104 -0
  121. package/src/debugging/index.ts +6 -0
  122. package/src/debugging/logs.ts +193 -0
  123. package/src/debugging/types.ts +100 -0
  124. package/src/deployment/deployer.ts +274 -0
  125. package/src/deployment/icpClient.ts +620 -0
  126. package/src/deployment/index.ts +46 -0
  127. package/src/deployment/promotion.ts +161 -0
  128. package/src/deployment/types.ts +111 -0
  129. package/src/icp/batch.ts +374 -0
  130. package/src/icp/cycles.ts +50 -0
  131. package/src/icp/environment.ts +215 -0
  132. package/src/icp/icpcli.ts +438 -0
  133. package/src/icp/icwasm.ts +222 -0
  134. package/src/icp/identity.ts +77 -0
  135. package/src/icp/index.ts +94 -0
  136. package/src/icp/optimization.ts +242 -0
  137. package/src/icp/tokens.ts +36 -0
  138. package/src/icp/tool-detector.ts +110 -0
  139. package/src/icp/types.ts +574 -0
  140. package/src/index.ts +25 -0
  141. package/src/inference/bittensor-client.ts +304 -0
  142. package/src/inference/index.ts +8 -0
  143. package/src/inference/inference-manager.ts +327 -0
  144. package/src/metrics/index.ts +7 -0
  145. package/src/metrics/metrics.ts +186 -0
  146. package/src/monitoring/alerting.ts +190 -0
  147. package/src/monitoring/health.ts +197 -0
  148. package/src/monitoring/index.ts +38 -0
  149. package/src/monitoring/info.ts +114 -0
  150. package/src/monitoring/types.ts +99 -0
  151. package/src/network/index.ts +5 -0
  152. package/src/network/network-config.ts +129 -0
  153. package/src/packaging/compiler.ts +647 -0
  154. package/src/packaging/config-persistence.ts +135 -0
  155. package/src/packaging/config-schemas.ts +156 -0
  156. package/src/packaging/detector.ts +220 -0
  157. package/src/packaging/index.ts +90 -0
  158. package/src/packaging/packager.ts +118 -0
  159. package/src/packaging/parsers/clawdbot.ts +278 -0
  160. package/src/packaging/parsers/cline.ts +223 -0
  161. package/src/packaging/parsers/generic.ts +266 -0
  162. package/src/packaging/parsers/goose.ts +214 -0
  163. package/src/packaging/parsers/index.ts +11 -0
  164. package/src/packaging/serializer.ts +260 -0
  165. package/src/packaging/types.ts +144 -0
  166. package/src/packaging/wasmedge-compiler.ts +406 -0
  167. package/src/security/index.ts +17 -0
  168. package/src/security/multisig.ts +415 -0
  169. package/src/security/types.ts +416 -0
  170. package/src/security/vetkeys.ts +655 -0
  171. package/src/testing/index.ts +6 -0
  172. package/src/testing/local-runner.ts +264 -0
  173. package/src/testing/types.ts +104 -0
  174. package/src/wallet/cbor-serializer.ts +323 -0
  175. package/src/wallet/chain-dispatcher.ts +313 -0
  176. package/src/wallet/cross-chain-aggregator.ts +346 -0
  177. package/src/wallet/index.ts +76 -0
  178. package/src/wallet/key-derivation.ts +425 -0
  179. package/src/wallet/providers/base-provider.ts +154 -0
  180. package/src/wallet/providers/cketh-provider.ts +434 -0
  181. package/src/wallet/providers/polkadot-provider.ts +503 -0
  182. package/src/wallet/providers/solana-provider.ts +490 -0
  183. package/src/wallet/transaction-queue.ts +284 -0
  184. package/src/wallet/types.ts +178 -0
  185. package/src/wallet/vetkeys-adapter.ts +431 -0
  186. package/src/wallet/wallet-manager.ts +597 -0
  187. package/src/wallet/wallet-storage.ts +380 -0
  188. package/vercel.json +8 -0
@@ -0,0 +1,415 @@
1
+ /**
2
+ * Multi-Signature Approval Workflows
3
+ *
4
+ * Manages local approval workflows requiring multiple signatures.
5
+ * This is a LOCAL approval tracking system, not cryptographic multisig.
6
+ *
7
+ * IMPORTANT: For production blockchain multisig, use:
8
+ * - ICP canister-based threshold signatures (VetKeys)
9
+ * - The canister multisig module for on-chain verification
10
+ *
11
+ * This module provides:
12
+ * - Approval request tracking
13
+ * - Signature collection and counting
14
+ * - Policy-based approval thresholds
15
+ * - Audit trail for approvals
16
+ */
17
+
18
+ import fs from 'node:fs';
19
+ import path from 'node:path';
20
+ import os from 'node:os';
21
+ import crypto from 'node:crypto';
22
+ import { parse, stringify } from 'yaml';
23
+
24
+ const AGENTVAULT_DIR = path.join(os.homedir(), '.agentvault');
25
+ const APPROVALS_DIR = path.join(AGENTVAULT_DIR, 'approvals');
26
+
27
+ export type ApprovalStatus = 'pending' | 'approved' | 'rejected' | 'expired';
28
+ export type ApprovalPolicy = 'all' | 'majority' | 'quorum';
29
+
30
+ export interface ApprovalRequest {
31
+ id: string;
32
+ type: 'deploy' | 'upgrade' | 'transfer' | 'config_change' | 'rollback';
33
+ agentName: string;
34
+ canisterId?: string;
35
+ description: string;
36
+ proposedBy: string;
37
+ timestamp: Date;
38
+ expiresAt?: Date;
39
+ policy: ApprovalPolicy;
40
+ requiredApprovals: number;
41
+ approvals: ApprovalSignature[];
42
+ status: ApprovalStatus;
43
+ data?: Record<string, unknown>;
44
+ }
45
+
46
+ /**
47
+ * Approval signature (NOT cryptographic - for audit trail only)
48
+ *
49
+ * This represents an approval action, not a cryptographic signature.
50
+ * For cryptographic multisig, use the VetKeys canister integration.
51
+ */
52
+ export interface ApprovalSignature {
53
+ signer: string;
54
+ /** Audit token - NOT a cryptographic signature */
55
+ auditToken: string;
56
+ timestamp: Date;
57
+ comment?: string;
58
+ }
59
+
60
+ export interface ApprovalConfig {
61
+ policy: ApprovalPolicy;
62
+ requiredApprovals?: number;
63
+ approvalTimeoutMs?: number;
64
+ allowedSigners?: string[];
65
+ }
66
+
67
+ function ensureApprovalsDir(): void {
68
+ if (!fs.existsSync(AGENTVAULT_DIR)) {
69
+ fs.mkdirSync(AGENTVAULT_DIR, { recursive: true });
70
+ }
71
+ if (!fs.existsSync(APPROVALS_DIR)) {
72
+ fs.mkdirSync(APPROVALS_DIR, { recursive: true });
73
+ }
74
+ }
75
+
76
+ function getApprovalFilePath(id: string): string {
77
+ ensureApprovalsDir();
78
+ return path.join(APPROVALS_DIR, `${id}.yaml`);
79
+ }
80
+
81
+ function generateRequestId(): string {
82
+ return `req-${Date.now()}-${crypto.randomBytes(4).toString('hex')}`;
83
+ }
84
+
85
+ /**
86
+ * Create a new approval request
87
+ */
88
+ export function createApprovalRequest(
89
+ type: ApprovalRequest['type'],
90
+ agentName: string,
91
+ description: string,
92
+ proposedBy: string,
93
+ config: ApprovalConfig,
94
+ data?: Record<string, any>,
95
+ ): ApprovalRequest {
96
+ const id = generateRequestId();
97
+ const timestamp = new Date();
98
+
99
+ const requiredApprovals =
100
+ config.requiredApprovals || calculateRequiredApprovals(config.policy, config.allowedSigners?.length || 1);
101
+
102
+ const request: ApprovalRequest = {
103
+ id,
104
+ type,
105
+ agentName,
106
+ description,
107
+ proposedBy,
108
+ timestamp,
109
+ policy: config.policy,
110
+ requiredApprovals,
111
+ approvals: [],
112
+ status: 'pending',
113
+ data,
114
+ };
115
+
116
+ if (config.approvalTimeoutMs) {
117
+ request.expiresAt = new Date(timestamp.getTime() + config.approvalTimeoutMs);
118
+ }
119
+
120
+ const filePath = getApprovalFilePath(id);
121
+ fs.writeFileSync(filePath, stringify(request), 'utf8');
122
+
123
+ return request;
124
+ }
125
+
126
+ /**
127
+ * Calculate required approvals based on policy
128
+ */
129
+ export function calculateRequiredApprovals(
130
+ policy: ApprovalPolicy,
131
+ totalSigners: number,
132
+ ): number {
133
+ switch (policy) {
134
+ case 'all':
135
+ return totalSigners;
136
+ case 'majority':
137
+ return Math.floor(totalSigners / 2) + 1;
138
+ case 'quorum':
139
+ default:
140
+ return Math.max(1, Math.ceil(totalSigners * 0.6));
141
+ }
142
+ }
143
+
144
+ /**
145
+ * Sign an approval request
146
+ */
147
+ export function signApprovalRequest(
148
+ id: string,
149
+ signer: string,
150
+ comment?: string,
151
+ ): boolean {
152
+ const request = getApprovalRequest(id);
153
+ if (!request) {
154
+ return false;
155
+ }
156
+
157
+ if (request.status !== 'pending') {
158
+ return false;
159
+ }
160
+
161
+ const existingSignature = request.approvals.find((s) => s.signer === signer);
162
+ if (existingSignature) {
163
+ return false;
164
+ }
165
+
166
+ const approvalSignature: ApprovalSignature = {
167
+ signer,
168
+ auditToken: crypto.createHash('sha256')
169
+ .update(`${id}:${signer}:${Date.now()}:${request.description}`)
170
+ .digest('hex'),
171
+ timestamp: new Date(),
172
+ comment,
173
+ };
174
+
175
+ request.approvals.push(approvalSignature);
176
+
177
+ if (request.approvals.length >= request.requiredApprovals) {
178
+ request.status = 'approved';
179
+ }
180
+
181
+ const filePath = getApprovalFilePath(id);
182
+ fs.writeFileSync(filePath, stringify(request), 'utf8');
183
+
184
+ return true;
185
+ }
186
+
187
+ /**
188
+ * Reject an approval request
189
+ */
190
+ export function rejectApprovalRequest(
191
+ id: string,
192
+ rejectedBy: string,
193
+ reason?: string,
194
+ ): boolean {
195
+ const request = getApprovalRequest(id);
196
+ if (!request) {
197
+ return false;
198
+ }
199
+
200
+ if (request.status !== 'pending') {
201
+ return false;
202
+ }
203
+
204
+ request.status = 'rejected';
205
+ request.approvals.push({
206
+ signer: rejectedBy,
207
+ auditToken: crypto.createHash('sha256')
208
+ .update(`${id}:rejected:${Date.now()}:${reason || 'no-reason'}`)
209
+ .digest('hex'),
210
+ timestamp: new Date(),
211
+ comment: `Rejected: ${reason || 'No reason provided'}`,
212
+ });
213
+
214
+ const filePath = getApprovalFilePath(id);
215
+ fs.writeFileSync(filePath, stringify(request), 'utf8');
216
+
217
+ return true;
218
+ }
219
+
220
+ /**
221
+ * Get approval request by ID
222
+ */
223
+ export function getApprovalRequest(id: string): ApprovalRequest | null {
224
+ try {
225
+ const filePath = getApprovalFilePath(id);
226
+ if (!fs.existsSync(filePath)) {
227
+ return null;
228
+ }
229
+
230
+ const content = fs.readFileSync(filePath, 'utf8');
231
+ interface LegacyApproval {
232
+ signer: string;
233
+ signature?: string;
234
+ auditToken?: string;
235
+ timestamp: string | Date;
236
+ comment?: string;
237
+ }
238
+ interface LegacyApprovalRequest {
239
+ id: string;
240
+ type: ApprovalRequest['type'];
241
+ agentName: string;
242
+ canisterId?: string;
243
+ description: string;
244
+ proposedBy: string;
245
+ timestamp: string | Date;
246
+ expiresAt?: string | Date;
247
+ policy: ApprovalPolicy;
248
+ requiredApprovals: number;
249
+ approvals: LegacyApproval[];
250
+ status: ApprovalStatus;
251
+ data?: Record<string, unknown>;
252
+ }
253
+
254
+ const parsed = parse(content) as LegacyApprovalRequest;
255
+ parsed.timestamp = new Date(parsed.timestamp);
256
+ parsed.expiresAt = parsed.expiresAt ? new Date(parsed.expiresAt) : undefined;
257
+
258
+ // Migrate old 'signature' field to 'auditToken' for backward compatibility
259
+ parsed.approvals = parsed.approvals.map((a): ApprovalSignature => {
260
+ const migrated: ApprovalSignature = {
261
+ signer: a.signer,
262
+ auditToken: a.auditToken || a.signature || '',
263
+ timestamp: new Date(a.timestamp),
264
+ comment: a.comment,
265
+ };
266
+ return migrated;
267
+ });
268
+
269
+ return parsed as ApprovalRequest;
270
+ } catch (error) {
271
+ console.error(`Failed to get approval request ${id}:`, error);
272
+ return null;
273
+ }
274
+ }
275
+
276
+ /**
277
+ * List approval requests
278
+ */
279
+ export function listApprovalRequests(
280
+ agentName?: string,
281
+ status?: ApprovalStatus,
282
+ ): ApprovalRequest[] {
283
+ try {
284
+ ensureApprovalsDir();
285
+ const files = fs.readdirSync(APPROVALS_DIR);
286
+ const requests: ApprovalRequest[] = [];
287
+
288
+ for (const file of files) {
289
+ if (file.endsWith('.yaml')) {
290
+ const id = file.replace('.yaml', '');
291
+ const request = getApprovalRequest(id);
292
+ if (request) {
293
+ if (agentName && request.agentName !== agentName) {
294
+ continue;
295
+ }
296
+ if (status && request.status !== status) {
297
+ continue;
298
+ }
299
+
300
+ if (request.expiresAt && new Date() > request.expiresAt && request.status === 'pending') {
301
+ request.status = 'expired';
302
+ }
303
+
304
+ requests.push(request);
305
+ }
306
+ }
307
+ }
308
+
309
+ return requests.sort((a, b) => b.timestamp.getTime() - a.timestamp.getTime());
310
+ } catch (error) {
311
+ console.error('Failed to list approval requests:', error);
312
+ return [];
313
+ }
314
+ }
315
+
316
+ /**
317
+ * Delete approval request
318
+ */
319
+ export function deleteApprovalRequest(id: string): boolean {
320
+ try {
321
+ const filePath = getApprovalFilePath(id);
322
+ if (!fs.existsSync(filePath)) {
323
+ return false;
324
+ }
325
+
326
+ fs.unlinkSync(filePath);
327
+ return true;
328
+ } catch (error) {
329
+ console.error(`Failed to delete approval request ${id}:`, error);
330
+ return false;
331
+ }
332
+ }
333
+
334
+ /**
335
+ * Check if request is approved
336
+ */
337
+ export function isApproved(id: string): boolean {
338
+ const request = getApprovalRequest(id);
339
+ if (!request) {
340
+ return false;
341
+ }
342
+
343
+ return request.status === 'approved';
344
+ }
345
+
346
+ /**
347
+ * Get approval status summary
348
+ */
349
+ export function getApprovalSummary(id: string): {
350
+ total: number;
351
+ approved: number;
352
+ required: number;
353
+ status: ApprovalStatus;
354
+ } | null {
355
+ const request = getApprovalRequest(id);
356
+ if (!request) {
357
+ return null;
358
+ }
359
+
360
+ return {
361
+ total: request.approvals.length,
362
+ approved: request.requiredApprovals,
363
+ required: request.requiredApprovals,
364
+ status: request.status,
365
+ };
366
+ }
367
+
368
+ /**
369
+ * List pending approvals for a signer
370
+ */
371
+ export function listPendingApprovals(signer: string): ApprovalRequest[] {
372
+ try {
373
+ const requests = listApprovalRequests(undefined, 'pending');
374
+ return requests.filter((r) => !r.approvals.some((a) => a.signer === signer));
375
+ } catch (error) {
376
+ console.error('Failed to list pending approvals:', error);
377
+ return [];
378
+ }
379
+ }
380
+
381
+ /**
382
+ * Clean up expired requests
383
+ */
384
+ export function cleanupExpiredRequests(): number {
385
+ let cleaned = 0;
386
+
387
+ try {
388
+ ensureApprovalsDir();
389
+ const files = fs.readdirSync(APPROVALS_DIR);
390
+ const now = new Date();
391
+
392
+ for (const file of files) {
393
+ if (file.endsWith('.yaml')) {
394
+ const id = file.replace('.yaml', '');
395
+ const request = getApprovalRequest(id);
396
+
397
+ if (
398
+ request &&
399
+ request.expiresAt &&
400
+ now > request.expiresAt &&
401
+ request.status === 'pending'
402
+ ) {
403
+ request.status = 'expired';
404
+ const filePath = getApprovalFilePath(id);
405
+ fs.writeFileSync(filePath, stringify(request), 'utf8');
406
+ cleaned++;
407
+ }
408
+ }
409
+ }
410
+ } catch (error) {
411
+ console.error('Failed to cleanup expired requests:', error);
412
+ }
413
+
414
+ return cleaned;
415
+ }