process-watchdog 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 (117) hide show
  1. package/config/default.json +16 -0
  2. package/dashboard/watchdog.html +856 -0
  3. package/dist/api/routes.d.ts +6 -0
  4. package/dist/api/routes.d.ts.map +1 -0
  5. package/dist/api/routes.js +105 -0
  6. package/dist/api/routes.js.map +1 -0
  7. package/dist/api/server.d.ts +10 -0
  8. package/dist/api/server.d.ts.map +1 -0
  9. package/dist/api/server.js +16 -0
  10. package/dist/api/server.js.map +1 -0
  11. package/dist/config.d.ts +27 -0
  12. package/dist/config.d.ts.map +1 -0
  13. package/dist/config.js +45 -0
  14. package/dist/config.js.map +1 -0
  15. package/dist/daemon/processwatchdog.err.log +973 -0
  16. package/dist/daemon/processwatchdog.exe +0 -0
  17. package/dist/daemon/processwatchdog.exe.config +6 -0
  18. package/dist/daemon/processwatchdog.out.log +2 -0
  19. package/dist/daemon/processwatchdog.wrapper.log +18 -0
  20. package/dist/daemon/processwatchdog.xml +30 -0
  21. package/dist/index.d.ts +3 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js +203 -0
  24. package/dist/index.js.map +1 -0
  25. package/dist/installer/service.d.ts +3 -0
  26. package/dist/installer/service.d.ts.map +1 -0
  27. package/dist/installer/service.js +41 -0
  28. package/dist/installer/service.js.map +1 -0
  29. package/dist/integrations/mah.d.ts +3 -0
  30. package/dist/integrations/mah.d.ts.map +1 -0
  31. package/dist/integrations/mah.js +22 -0
  32. package/dist/integrations/mah.js.map +1 -0
  33. package/dist/integrations/total-recall.d.ts +3 -0
  34. package/dist/integrations/total-recall.d.ts.map +1 -0
  35. package/dist/integrations/total-recall.js +22 -0
  36. package/dist/integrations/total-recall.js.map +1 -0
  37. package/dist/platform/index.d.ts +4 -0
  38. package/dist/platform/index.d.ts.map +1 -0
  39. package/dist/platform/index.js +10 -0
  40. package/dist/platform/index.js.map +1 -0
  41. package/dist/platform/platform.interface.d.ts +42 -0
  42. package/dist/platform/platform.interface.d.ts.map +1 -0
  43. package/dist/platform/platform.interface.js +2 -0
  44. package/dist/platform/platform.interface.js.map +1 -0
  45. package/dist/platform/windows.d.ts +14 -0
  46. package/dist/platform/windows.d.ts.map +1 -0
  47. package/dist/platform/windows.js +162 -0
  48. package/dist/platform/windows.js.map +1 -0
  49. package/dist/plugins/cpu-monitor.d.ts +11 -0
  50. package/dist/plugins/cpu-monitor.d.ts.map +1 -0
  51. package/dist/plugins/cpu-monitor.js +57 -0
  52. package/dist/plugins/cpu-monitor.js.map +1 -0
  53. package/dist/plugins/disk-health.d.ts +11 -0
  54. package/dist/plugins/disk-health.d.ts.map +1 -0
  55. package/dist/plugins/disk-health.js +111 -0
  56. package/dist/plugins/disk-health.js.map +1 -0
  57. package/dist/plugins/memory-monitor.d.ts +11 -0
  58. package/dist/plugins/memory-monitor.d.ts.map +1 -0
  59. package/dist/plugins/memory-monitor.js +61 -0
  60. package/dist/plugins/memory-monitor.js.map +1 -0
  61. package/dist/plugins/plugin-loader.d.ts +4 -0
  62. package/dist/plugins/plugin-loader.d.ts.map +1 -0
  63. package/dist/plugins/plugin-loader.js +25 -0
  64. package/dist/plugins/plugin-loader.js.map +1 -0
  65. package/dist/plugins/plugin.interface.d.ts +28 -0
  66. package/dist/plugins/plugin.interface.d.ts.map +1 -0
  67. package/dist/plugins/plugin.interface.js +2 -0
  68. package/dist/plugins/plugin.interface.js.map +1 -0
  69. package/dist/plugins/process-guard.d.ts +11 -0
  70. package/dist/plugins/process-guard.d.ts.map +1 -0
  71. package/dist/plugins/process-guard.js +139 -0
  72. package/dist/plugins/process-guard.js.map +1 -0
  73. package/dist/plugins/startup-optimizer.d.ts +11 -0
  74. package/dist/plugins/startup-optimizer.d.ts.map +1 -0
  75. package/dist/plugins/startup-optimizer.js +78 -0
  76. package/dist/plugins/startup-optimizer.js.map +1 -0
  77. package/dist/scheduler.d.ts +16 -0
  78. package/dist/scheduler.d.ts.map +1 -0
  79. package/dist/scheduler.js +46 -0
  80. package/dist/scheduler.js.map +1 -0
  81. package/dist/store/history.d.ts +20 -0
  82. package/dist/store/history.d.ts.map +1 -0
  83. package/dist/store/history.js +60 -0
  84. package/dist/store/history.js.map +1 -0
  85. package/package.json +35 -0
  86. package/src/api/routes.ts +123 -0
  87. package/src/api/server.ts +20 -0
  88. package/src/config.ts +78 -0
  89. package/src/index.ts +228 -0
  90. package/src/installer/service.ts +50 -0
  91. package/src/integrations/mah.ts +22 -0
  92. package/src/integrations/total-recall.ts +27 -0
  93. package/src/platform/index.ts +13 -0
  94. package/src/platform/platform.interface.ts +46 -0
  95. package/src/platform/windows.ts +242 -0
  96. package/src/plugins/cpu-monitor.ts +67 -0
  97. package/src/plugins/disk-health.ts +128 -0
  98. package/src/plugins/memory-monitor.ts +70 -0
  99. package/src/plugins/plugin-loader.ts +27 -0
  100. package/src/plugins/plugin.interface.ts +31 -0
  101. package/src/plugins/process-guard.ts +165 -0
  102. package/src/plugins/startup-optimizer.ts +103 -0
  103. package/src/scheduler.ts +53 -0
  104. package/src/store/history.ts +90 -0
  105. package/tests/api/routes.test.ts +113 -0
  106. package/tests/config.test.ts +24 -0
  107. package/tests/platform/windows.test.ts +59 -0
  108. package/tests/plugins/cpu-monitor.test.ts +69 -0
  109. package/tests/plugins/disk-health.test.ts +69 -0
  110. package/tests/plugins/memory-monitor.test.ts +57 -0
  111. package/tests/plugins/plugin-loader.test.ts +35 -0
  112. package/tests/plugins/process-guard.test.ts +40 -0
  113. package/tests/plugins/startup-optimizer.test.ts +50 -0
  114. package/tests/scheduler.test.ts +69 -0
  115. package/tests/store/history.test.ts +89 -0
  116. package/tsconfig.json +18 -0
  117. package/vitest.config.ts +10 -0
@@ -0,0 +1,6 @@
1
+ import { Router } from 'express';
2
+ import { HistoryStore } from '../store/history.js';
3
+ import { WatchdogPlugin } from '../plugins/plugin.interface.js';
4
+ import { WatchdogConfig } from '../config.js';
5
+ export declare function createRoutes(store: HistoryStore, plugins: WatchdogPlugin[], config: WatchdogConfig): Router;
6
+ //# sourceMappingURL=routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../../src/api/routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAgB,MAAM,gCAAgC,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAc9C,wBAAgB,YAAY,CAC1B,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,cAAc,EAAE,EACzB,MAAM,EAAE,cAAc,GACrB,MAAM,CAqGR"}
@@ -0,0 +1,105 @@
1
+ import { Router } from 'express';
2
+ const STATUS_ORDER = ['healthy', 'warning', 'critical'];
3
+ function worstStatus(statuses) {
4
+ let worst = 'healthy';
5
+ for (const s of statuses) {
6
+ if (STATUS_ORDER.indexOf(s) > STATUS_ORDER.indexOf(worst)) {
7
+ worst = s;
8
+ }
9
+ }
10
+ return worst;
11
+ }
12
+ export function createRoutes(store, plugins, config) {
13
+ const router = Router();
14
+ // GET /health
15
+ router.get('/health', (_req, res) => {
16
+ const lastChecks = store.getLastChecks();
17
+ const pluginStatuses = {};
18
+ const statuses = [];
19
+ for (const plugin of plugins) {
20
+ const last = lastChecks[plugin.name];
21
+ pluginStatuses[plugin.name] = {
22
+ status: last ? last.status : 'healthy',
23
+ lastRun: last ? last.timestamp : null,
24
+ };
25
+ if (last) {
26
+ statuses.push(last.status);
27
+ }
28
+ }
29
+ res.json({
30
+ service: 'process-watchdog',
31
+ version: '1.0.0',
32
+ status: worstStatus(statuses),
33
+ uptime: Math.floor(process.uptime()),
34
+ plugins: pluginStatuses,
35
+ });
36
+ });
37
+ // GET /plugins
38
+ router.get('/plugins', (_req, res) => {
39
+ const lastChecks = store.getLastChecks();
40
+ const result = plugins.map((plugin) => {
41
+ const last = lastChecks[plugin.name];
42
+ const pluginConfig = config.plugins[plugin.name];
43
+ return {
44
+ name: plugin.name,
45
+ description: plugin.description,
46
+ interval: pluginConfig ? pluginConfig.interval : plugin.defaultInterval,
47
+ lastCheck: last ? last.timestamp : null,
48
+ };
49
+ });
50
+ res.json(result);
51
+ });
52
+ // GET /plugins/:name
53
+ router.get('/plugins/:name', (req, res) => {
54
+ const plugin = plugins.find((p) => p.name === req.params.name);
55
+ if (!plugin) {
56
+ res.status(404).json({ error: `Plugin '${req.params.name}' not found` });
57
+ return;
58
+ }
59
+ const history = store.getHistory(plugin.name, 50);
60
+ res.json({
61
+ name: plugin.name,
62
+ description: plugin.description,
63
+ history,
64
+ });
65
+ });
66
+ // POST /plugins/:name/run
67
+ router.post('/plugins/:name/run', async (req, res) => {
68
+ const plugin = plugins.find((p) => p.name === req.params.name);
69
+ if (!plugin) {
70
+ res.status(404).json({ error: `Plugin '${req.params.name}' not found` });
71
+ return;
72
+ }
73
+ const action = req.body?.action === 'fix' ? 'fix' : 'check';
74
+ try {
75
+ if (action === 'fix') {
76
+ const result = await plugin.fix();
77
+ store.recordFix(plugin.name, result.actionsKept, result.resourcesFreed);
78
+ res.json({ action, result });
79
+ }
80
+ else {
81
+ const result = await plugin.check();
82
+ store.recordCheck(plugin.name, result.status, result.metrics, result.message);
83
+ res.json({ action, result });
84
+ }
85
+ }
86
+ catch (err) {
87
+ const message = err instanceof Error ? err.message : String(err);
88
+ res.status(500).json({ error: message });
89
+ }
90
+ });
91
+ // GET /history
92
+ router.get('/history', (req, res) => {
93
+ const pluginFilter = typeof req.query.plugin === 'string' ? req.query.plugin : null;
94
+ const limitRaw = parseInt(String(req.query.limit ?? '50'), 10);
95
+ const limit = isNaN(limitRaw) || limitRaw <= 0 ? 50 : limitRaw;
96
+ const history = store.getHistory(pluginFilter, limit);
97
+ res.json(history);
98
+ });
99
+ // GET /config
100
+ router.get('/config', (_req, res) => {
101
+ res.json(config);
102
+ });
103
+ return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AAQ,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC;QAC/D,MAAM,OAAO,GAAG,KAAK,CAAC,UAAU,CAAC,YAAY,EAAE,KAAK,CAAC,CAAC;QACtD,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACpB,CAAC,CAAC,CAAC;IAEH,cAAc;IACd,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE;QAClC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACnB,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,10 @@
1
+ import express from 'express';
2
+ import { HistoryStore } from '../store/history.js';
3
+ import { WatchdogPlugin } from '../plugins/plugin.interface.js';
4
+ import { WatchdogConfig } from '../config.js';
5
+ export declare function createApp(store: HistoryStore, plugins: WatchdogPlugin[], config: WatchdogConfig): express.Express;
6
+ export declare function startServer(store: HistoryStore, plugins: WatchdogPlugin[], config: WatchdogConfig): {
7
+ app: express.Express;
8
+ close: () => import("node:http").Server<typeof import("node:http").IncomingMessage, typeof import("node:http").ServerResponse>;
9
+ };
10
+ //# sourceMappingURL=server.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../../src/api/server.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAG9C,wBAAgB,SAAS,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAKjH;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE,MAAM,EAAE,cAAc;;;EAMjG"}
@@ -0,0 +1,16 @@
1
+ import express from 'express';
2
+ import { createRoutes } from './routes.js';
3
+ export function createApp(store, plugins, config) {
4
+ const app = express();
5
+ app.use(express.json());
6
+ app.use('/api/v1', createRoutes(store, plugins, config));
7
+ return app;
8
+ }
9
+ export function startServer(store, plugins, config) {
10
+ const app = createApp(store, plugins, config);
11
+ const server = app.listen(config.port, () => {
12
+ console.log(`[watchdog] API server running on port ${config.port}`);
13
+ });
14
+ return { app, close: () => server.close() };
15
+ }
16
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/api/server.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAI9B,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,UAAU,SAAS,CAAC,KAAmB,EAAE,OAAyB,EAAE,MAAsB;IAC9F,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC;IACtB,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IACxB,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,YAAY,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;IACzD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAmB,EAAE,OAAyB,EAAE,MAAsB;IAChG,MAAM,GAAG,GAAG,SAAS,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;IAC9C,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;QAC1C,OAAO,CAAC,GAAG,CAAC,yCAAyC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;IACtE,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC;AAC9C,CAAC"}
@@ -0,0 +1,27 @@
1
+ export interface WatchdogConfig {
2
+ port: number;
3
+ logLevel: string;
4
+ historyRetentionDays: number;
5
+ integrations: {
6
+ totalRecall: {
7
+ enabled: boolean;
8
+ url: string;
9
+ };
10
+ mah: {
11
+ enabled: boolean;
12
+ url: string;
13
+ };
14
+ };
15
+ plugins: Record<string, {
16
+ enabled: boolean;
17
+ interval: number;
18
+ autoFix: boolean;
19
+ thresholds: Record<string, number>;
20
+ }>;
21
+ }
22
+ type DeepPartial<T> = {
23
+ [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
24
+ };
25
+ export declare function loadConfig(overrides?: DeepPartial<WatchdogConfig>): Promise<WatchdogConfig>;
26
+ export {};
27
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,YAAY,EAAE;QACZ,WAAW,EAAE;YAAE,OAAO,EAAE,OAAO,CAAC;YAAC,GAAG,EAAE,MAAM,CAAA;SAAE,CAAC;QAC/C,GAAG,EAAE;YAAE,OAAO,EAAE,OAAO,CAAC;YAAC,GAAG,EAAE,MAAM,CAAA;SAAE,CAAC;KACxC,CAAC;IACF,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE;QACtB,OAAO,EAAE,OAAO,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;QACjB,OAAO,EAAE,OAAO,CAAC;QACjB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KACpC,CAAC,CAAC;CACJ;AAED,KAAK,WAAW,CAAC,CAAC,IAAI;KACnB,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAChE,CAAC;AA4BF,wBAAsB,UAAU,CAC9B,SAAS,CAAC,EAAE,WAAW,CAAC,cAAc,CAAC,GACtC,OAAO,CAAC,cAAc,CAAC,CAuBzB"}
package/dist/config.js ADDED
@@ -0,0 +1,45 @@
1
+ import { readFile } from 'fs/promises';
2
+ import { existsSync } from 'fs';
3
+ import { fileURLToPath } from 'url';
4
+ import { resolve, dirname, join } from 'path';
5
+ import os from 'os';
6
+ function isPlainObject(value) {
7
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
8
+ }
9
+ function deepMerge(target, source) {
10
+ const result = { ...target };
11
+ for (const key of Object.keys(source)) {
12
+ const srcVal = source[key];
13
+ const tgtVal = result[key];
14
+ if (isPlainObject(srcVal) && isPlainObject(tgtVal)) {
15
+ result[key] = deepMerge(tgtVal, srcVal);
16
+ }
17
+ else {
18
+ result[key] = srcVal;
19
+ }
20
+ }
21
+ return result;
22
+ }
23
+ const __filename = fileURLToPath(import.meta.url);
24
+ const __dirname = dirname(__filename);
25
+ // src/config.ts lives in <project-root>/src/, so project root is one level up
26
+ const PROJECT_ROOT = resolve(__dirname, '..');
27
+ export async function loadConfig(overrides) {
28
+ // 1. Read config/default.json from the project root
29
+ const defaultPath = join(PROJECT_ROOT, 'config', 'default.json');
30
+ const defaultRaw = await readFile(defaultPath, 'utf-8');
31
+ let config = JSON.parse(defaultRaw);
32
+ // 2. Read ~/.aidev/watchdog.json if it exists
33
+ const userConfigPath = join(os.homedir(), '.aidev', 'watchdog.json');
34
+ if (existsSync(userConfigPath)) {
35
+ const userRaw = await readFile(userConfigPath, 'utf-8');
36
+ const userConfig = JSON.parse(userRaw);
37
+ config = deepMerge(config, userConfig);
38
+ }
39
+ // 3. Apply caller overrides
40
+ if (overrides) {
41
+ config = deepMerge(config, overrides);
42
+ }
43
+ return config;
44
+ }
45
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,EAAE,MAAM,IAAI,CAAC;AAsBpB,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AAC9E,CAAC;AAED,SAAS,SAAS,CAChB,MAAS,EACT,MAA+B;IAE/B,MAAM,MAAM,GAA4B,EAAE,GAAG,MAAM,EAAE,CAAC;IACtD,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;QACtC,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAC3B,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAC3B,IAAI,aAAa,CAAC,MAAM,CAAC,IAAI,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC;YACnD,MAAM,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC1C,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC;QACvB,CAAC;IACH,CAAC;IACD,OAAO,MAAW,CAAC;AACrB,CAAC;AAED,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,S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