@mako10k/shell-server 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 (175) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +114 -0
  3. package/dist/backoffice/index.d.ts +2 -0
  4. package/dist/backoffice/index.d.ts.map +1 -0
  5. package/dist/backoffice/index.js +47 -0
  6. package/dist/backoffice/index.js.map +1 -0
  7. package/dist/backoffice/server.d.ts +45 -0
  8. package/dist/backoffice/server.d.ts.map +1 -0
  9. package/dist/backoffice/server.js +610 -0
  10. package/dist/backoffice/server.js.map +1 -0
  11. package/dist/cli.d.ts +3 -0
  12. package/dist/cli.d.ts.map +1 -0
  13. package/dist/cli.js +525 -0
  14. package/dist/cli.js.map +1 -0
  15. package/dist/core/config-manager.d.ts +80 -0
  16. package/dist/core/config-manager.d.ts.map +1 -0
  17. package/dist/core/config-manager.js +218 -0
  18. package/dist/core/config-manager.js.map +1 -0
  19. package/dist/core/enhanced-history-manager.d.ts +84 -0
  20. package/dist/core/enhanced-history-manager.d.ts.map +1 -0
  21. package/dist/core/enhanced-history-manager.js +319 -0
  22. package/dist/core/enhanced-history-manager.js.map +1 -0
  23. package/dist/core/file-manager.d.ts +79 -0
  24. package/dist/core/file-manager.d.ts.map +1 -0
  25. package/dist/core/file-manager.js +338 -0
  26. package/dist/core/file-manager.js.map +1 -0
  27. package/dist/core/file-storage-subscriber.d.ts +38 -0
  28. package/dist/core/file-storage-subscriber.d.ts.map +1 -0
  29. package/dist/core/file-storage-subscriber.js +132 -0
  30. package/dist/core/file-storage-subscriber.js.map +1 -0
  31. package/dist/core/monitoring-manager.d.ts +32 -0
  32. package/dist/core/monitoring-manager.d.ts.map +1 -0
  33. package/dist/core/monitoring-manager.js +296 -0
  34. package/dist/core/monitoring-manager.js.map +1 -0
  35. package/dist/core/process-manager.d.ts +105 -0
  36. package/dist/core/process-manager.d.ts.map +1 -0
  37. package/dist/core/process-manager.js +1374 -0
  38. package/dist/core/process-manager.js.map +1 -0
  39. package/dist/core/realtime-stream-subscriber.d.ts +93 -0
  40. package/dist/core/realtime-stream-subscriber.d.ts.map +1 -0
  41. package/dist/core/realtime-stream-subscriber.js +200 -0
  42. package/dist/core/realtime-stream-subscriber.js.map +1 -0
  43. package/dist/core/remote-http-client.d.ts +15 -0
  44. package/dist/core/remote-http-client.d.ts.map +1 -0
  45. package/dist/core/remote-http-client.js +60 -0
  46. package/dist/core/remote-http-client.js.map +1 -0
  47. package/dist/core/remote-process-service.d.ts +50 -0
  48. package/dist/core/remote-process-service.d.ts.map +1 -0
  49. package/dist/core/remote-process-service.js +20 -0
  50. package/dist/core/remote-process-service.js.map +1 -0
  51. package/dist/core/server-manager.d.ts +71 -0
  52. package/dist/core/server-manager.d.ts.map +1 -0
  53. package/dist/core/server-manager.js +680 -0
  54. package/dist/core/server-manager.js.map +1 -0
  55. package/dist/core/stream-publisher.d.ts +75 -0
  56. package/dist/core/stream-publisher.d.ts.map +1 -0
  57. package/dist/core/stream-publisher.js +127 -0
  58. package/dist/core/stream-publisher.js.map +1 -0
  59. package/dist/core/streaming-pipeline-reader.d.ts +67 -0
  60. package/dist/core/streaming-pipeline-reader.d.ts.map +1 -0
  61. package/dist/core/streaming-pipeline-reader.js +191 -0
  62. package/dist/core/streaming-pipeline-reader.js.map +1 -0
  63. package/dist/core/terminal-manager.d.ts +96 -0
  64. package/dist/core/terminal-manager.d.ts.map +1 -0
  65. package/dist/core/terminal-manager.js +515 -0
  66. package/dist/core/terminal-manager.js.map +1 -0
  67. package/dist/daemon/server.d.ts +8 -0
  68. package/dist/daemon/server.d.ts.map +1 -0
  69. package/dist/daemon/server.js +416 -0
  70. package/dist/daemon/server.js.map +1 -0
  71. package/dist/daemon/uds-transport.d.ts +31 -0
  72. package/dist/daemon/uds-transport.d.ts.map +1 -0
  73. package/dist/daemon/uds-transport.js +149 -0
  74. package/dist/daemon/uds-transport.js.map +1 -0
  75. package/dist/executor/server.d.ts +20 -0
  76. package/dist/executor/server.d.ts.map +1 -0
  77. package/dist/executor/server.js +375 -0
  78. package/dist/executor/server.js.map +1 -0
  79. package/dist/index.d.ts +2 -0
  80. package/dist/index.d.ts.map +1 -0
  81. package/dist/index.js +73 -0
  82. package/dist/index.js.map +1 -0
  83. package/dist/runtime/daemon-runtime.d.ts +4 -0
  84. package/dist/runtime/daemon-runtime.d.ts.map +1 -0
  85. package/dist/runtime/daemon-runtime.js +4 -0
  86. package/dist/runtime/daemon-runtime.js.map +1 -0
  87. package/dist/runtime/index.d.ts +3 -0
  88. package/dist/runtime/index.d.ts.map +1 -0
  89. package/dist/runtime/index.js +3 -0
  90. package/dist/runtime/index.js.map +1 -0
  91. package/dist/runtime/tool-runtime.d.ts +52 -0
  92. package/dist/runtime/tool-runtime.d.ts.map +1 -0
  93. package/dist/runtime/tool-runtime.js +161 -0
  94. package/dist/runtime/tool-runtime.js.map +1 -0
  95. package/dist/security/chat-completion-adapter.d.ts +443 -0
  96. package/dist/security/chat-completion-adapter.d.ts.map +1 -0
  97. package/dist/security/chat-completion-adapter.js +475 -0
  98. package/dist/security/chat-completion-adapter.js.map +1 -0
  99. package/dist/security/enhanced-evaluator.d.ts +139 -0
  100. package/dist/security/enhanced-evaluator.d.ts.map +1 -0
  101. package/dist/security/enhanced-evaluator.js +1208 -0
  102. package/dist/security/enhanced-evaluator.js.map +1 -0
  103. package/dist/security/evaluator-types.d.ts +614 -0
  104. package/dist/security/evaluator-types.d.ts.map +1 -0
  105. package/dist/security/evaluator-types.js +124 -0
  106. package/dist/security/evaluator-types.js.map +1 -0
  107. package/dist/security/manager.d.ts +76 -0
  108. package/dist/security/manager.d.ts.map +1 -0
  109. package/dist/security/manager.js +445 -0
  110. package/dist/security/manager.js.map +1 -0
  111. package/dist/security/security-llm-prompt-generator.d.ts +105 -0
  112. package/dist/security/security-llm-prompt-generator.d.ts.map +1 -0
  113. package/dist/security/security-llm-prompt-generator.js +323 -0
  114. package/dist/security/security-llm-prompt-generator.js.map +1 -0
  115. package/dist/security/security-tools.d.ts +174 -0
  116. package/dist/security/security-tools.d.ts.map +1 -0
  117. package/dist/security/security-tools.js +159 -0
  118. package/dist/security/security-tools.js.map +1 -0
  119. package/dist/security/validator-criteria-manager.d.ts +47 -0
  120. package/dist/security/validator-criteria-manager.d.ts.map +1 -0
  121. package/dist/security/validator-criteria-manager.js +169 -0
  122. package/dist/security/validator-criteria-manager.js.map +1 -0
  123. package/dist/tools/shell-tools.d.ts +474 -0
  124. package/dist/tools/shell-tools.d.ts.map +1 -0
  125. package/dist/tools/shell-tools.js +861 -0
  126. package/dist/tools/shell-tools.js.map +1 -0
  127. package/dist/types/enhanced-security.d.ts +529 -0
  128. package/dist/types/enhanced-security.d.ts.map +1 -0
  129. package/dist/types/enhanced-security.js +286 -0
  130. package/dist/types/enhanced-security.js.map +1 -0
  131. package/dist/types/index.d.ts +282 -0
  132. package/dist/types/index.d.ts.map +1 -0
  133. package/dist/types/index.js +158 -0
  134. package/dist/types/index.js.map +1 -0
  135. package/dist/types/quick-schemas.d.ts +177 -0
  136. package/dist/types/quick-schemas.d.ts.map +1 -0
  137. package/dist/types/quick-schemas.js +113 -0
  138. package/dist/types/quick-schemas.js.map +1 -0
  139. package/dist/types/response-schemas.d.ts +41 -0
  140. package/dist/types/response-schemas.d.ts.map +1 -0
  141. package/dist/types/response-schemas.js +41 -0
  142. package/dist/types/response-schemas.js.map +1 -0
  143. package/dist/types/schemas.d.ts +578 -0
  144. package/dist/types/schemas.d.ts.map +1 -0
  145. package/dist/types/schemas.js +498 -0
  146. package/dist/types/schemas.js.map +1 -0
  147. package/dist/utils/criteria-manager.d.ts +47 -0
  148. package/dist/utils/criteria-manager.d.ts.map +1 -0
  149. package/dist/utils/criteria-manager.js +228 -0
  150. package/dist/utils/criteria-manager.js.map +1 -0
  151. package/dist/utils/errors.d.ts +27 -0
  152. package/dist/utils/errors.d.ts.map +1 -0
  153. package/dist/utils/errors.js +67 -0
  154. package/dist/utils/errors.js.map +1 -0
  155. package/dist/utils/helpers.d.ts +85 -0
  156. package/dist/utils/helpers.d.ts.map +1 -0
  157. package/dist/utils/helpers.js +400 -0
  158. package/dist/utils/helpers.js.map +1 -0
  159. package/dist/utils/json-repair.d.ts +23 -0
  160. package/dist/utils/json-repair.d.ts.map +1 -0
  161. package/dist/utils/json-repair.js +208 -0
  162. package/dist/utils/json-repair.js.map +1 -0
  163. package/dist/utils/process-utils.d.ts +31 -0
  164. package/dist/utils/process-utils.d.ts.map +1 -0
  165. package/dist/utils/process-utils.js +217 -0
  166. package/dist/utils/process-utils.js.map +1 -0
  167. package/dist/utils/server-helpers.d.ts +4 -0
  168. package/dist/utils/server-helpers.d.ts.map +1 -0
  169. package/dist/utils/server-helpers.js +10 -0
  170. package/dist/utils/server-helpers.js.map +1 -0
  171. package/dist/utils/sse.d.ts +2 -0
  172. package/dist/utils/sse.d.ts.map +1 -0
  173. package/dist/utils/sse.js +6 -0
  174. package/dist/utils/sse.js.map +1 -0
  175. package/package.json +47 -0
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Security Evaluation Tools for Function Calling
3
+ * New individual tool approach - each evaluation result has its own tool
4
+ */
5
+ // Individual Security Evaluation Tools
6
+ export const allowTool = {
7
+ type: 'function',
8
+ function: {
9
+ name: 'allow',
10
+ description: 'Allow command execution - the command is safe to execute',
11
+ parameters: {
12
+ type: "object",
13
+ properties: {
14
+ reasoning: {
15
+ type: "string",
16
+ description: 'Detailed reasoning for why the command is safe'
17
+ }
18
+ },
19
+ required: ['reasoning'],
20
+ additionalProperties: false
21
+ }
22
+ }
23
+ };
24
+ export const denyTool = {
25
+ type: 'function',
26
+ function: {
27
+ name: 'deny',
28
+ description: 'Deny command execution - the command is too dangerous to execute',
29
+ parameters: {
30
+ type: "object",
31
+ properties: {
32
+ reasoning: {
33
+ type: "string",
34
+ description: 'Detailed reasoning for why the command is dangerous'
35
+ },
36
+ suggested_alternatives: {
37
+ type: "array",
38
+ items: { type: "string" },
39
+ description: 'List of safer alternative commands'
40
+ }
41
+ },
42
+ required: ['reasoning', 'suggested_alternatives'],
43
+ additionalProperties: false
44
+ }
45
+ }
46
+ };
47
+ export const userConfirmTool = {
48
+ type: 'function',
49
+ function: {
50
+ name: 'user_confirm',
51
+ description: 'Request user confirmation - the command requires explicit user permission before execution',
52
+ parameters: {
53
+ type: "object",
54
+ properties: {
55
+ reasoning: {
56
+ type: "string",
57
+ description: 'Detailed reasoning for why user confirmation is needed'
58
+ },
59
+ confirmation_question: {
60
+ type: "string",
61
+ description: 'Specific question to ask the user for confirmation (include alternatives if applicable)'
62
+ }
63
+ },
64
+ required: ['reasoning', 'confirmation_question'],
65
+ additionalProperties: false
66
+ }
67
+ }
68
+ };
69
+ export const addMoreHistoryTool = {
70
+ type: 'function',
71
+ function: {
72
+ name: 'add_more_history',
73
+ description: 'Request additional command history - need more system context to make a decision',
74
+ parameters: {
75
+ type: "object",
76
+ properties: {
77
+ reasoning: {
78
+ type: "string",
79
+ description: 'Detailed reasoning for why more history is needed'
80
+ },
81
+ command_history_depth: {
82
+ type: "number",
83
+ minimum: 1,
84
+ maximum: 50,
85
+ description: 'How many more commands back in history to examine'
86
+ },
87
+ execution_results_count: {
88
+ type: "number",
89
+ minimum: 0,
90
+ maximum: 10,
91
+ description: 'How many recent commands need their execution details'
92
+ },
93
+ user_intent_search_keywords: {
94
+ type: "array",
95
+ items: { type: "string" },
96
+ description: 'Keywords to search for in previous user intent responses'
97
+ }
98
+ },
99
+ required: ['reasoning', 'command_history_depth'],
100
+ additionalProperties: false
101
+ }
102
+ }
103
+ };
104
+ export const aiAssistantConfirmTool = {
105
+ type: 'function',
106
+ function: {
107
+ name: 'ai_assistant_confirm',
108
+ description: 'Request information from AI assistant - need additional context that assistant can provide',
109
+ parameters: {
110
+ type: "object",
111
+ properties: {
112
+ reasoning: {
113
+ type: "string",
114
+ description: 'Detailed reasoning for why assistant information is needed'
115
+ },
116
+ assistant_request_message: {
117
+ type: "string",
118
+ description: 'Specific message/question to show to the AI assistant'
119
+ },
120
+ next_action: {
121
+ type: "object",
122
+ description: 'Next action for the AI assistant to take',
123
+ properties: {
124
+ instruction: {
125
+ type: "string",
126
+ description: 'Clear instruction for what the assistant should do'
127
+ },
128
+ method: {
129
+ type: "string",
130
+ description: 'How the assistant should gather the required information'
131
+ },
132
+ expected_outcome: {
133
+ type: "string",
134
+ description: 'What result is expected from the assistant action'
135
+ },
136
+ executable_commands: {
137
+ type: "array",
138
+ items: { type: "string" },
139
+ description: 'List of specific commands the assistant should execute to gather information'
140
+ }
141
+ },
142
+ required: ['instruction', 'method', 'expected_outcome'],
143
+ additionalProperties: false
144
+ }
145
+ },
146
+ required: ['reasoning', 'assistant_request_message', 'next_action'],
147
+ additionalProperties: false
148
+ }
149
+ }
150
+ };
151
+ // Combined tools array for easy import
152
+ export const newSecurityEvaluationTools = [
153
+ allowTool,
154
+ denyTool,
155
+ userConfirmTool,
156
+ addMoreHistoryTool,
157
+ aiAssistantConfirmTool
158
+ ];
159
+ //# sourceMappingURL=security-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"security-tools.js","sourceRoot":"","sources":["../../src/security/security-tools.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,uCAAuC;AAEvC,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,IAAI,EAAE,UAAmB;IACzB,QAAQ,EAAE;QACR,IAAI,EAAE,OAAO;QACb,WAAW,EAAE,0DAA0D;QACvE,UAAU,EAAE;YACV,IAAI,EAAE,QAAiB;YACvB,UAAU,EAAE;gBACV,SAAS,EAAE;oBACT,IAAI,EAAE,QAAiB;oBACvB,WAAW,EAAE,gDAAgD;iBAC9D;aACF;YACD,QAAQ,EAAE,CAAC,WAAW,CAAC;YACvB,oBAAoB,EAAE,KAAK;SAC5B;KACF;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,IAAI,EAAE,UAAmB;IACzB,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM;QACZ,WAAW,EAA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C,aAAa,EAAE,QAAQ,EAAE,kBAAkB,CAAC;oBACvD,oBAAoB,EAAE,KAAK;iBAC5B;aACF;YACD,QAAQ,EAAE,CAAC,WAAW,EAAE,2BAA2B,EAAE,aAAa,CAAC;YACnE,oBAAoB,EAAE,KAAK;SAC5B;KACF;CACF,CAAC;AAEF,uCAAuC;AACvC,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,SAAS;IACT,QAAQ;IACR,eAAe;IACf,kBAAkB;IAClB,sBAAsB;CACvB,CAAC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Validator-side criteria management for security evaluation
3
+ * This manages criteria files that the Validator uses to evaluate commands
4
+ * Separate from MCP client-side criteria management for security isolation
5
+ */
6
+ export interface ValidatorCriteriaConfig {
7
+ criteriaText: string;
8
+ lastModified: Date;
9
+ backupPath?: string | undefined;
10
+ }
11
+ export declare class ValidatorCriteriaManager {
12
+ private static instance;
13
+ private readonly defaultCriteriaPath;
14
+ private readonly backupDirectory;
15
+ private currentCriteria;
16
+ private lastFileModTime;
17
+ private constructor();
18
+ static getInstance(): ValidatorCriteriaManager;
19
+ /**
20
+ * Adjust validator criteria with backup support
21
+ */
22
+ adjustCriteria(criteriaText: string, backupExisting?: boolean): Promise<{
23
+ success: boolean;
24
+ message: string;
25
+ backupPath?: string;
26
+ }>;
27
+ /**
28
+ * Load current criteria for validator use
29
+ */
30
+ loadCriteria(): Promise<string | null>;
31
+ /**
32
+ * Get current criteria configuration
33
+ */
34
+ getCriteriaConfig(): Promise<ValidatorCriteriaConfig | null>;
35
+ private createBackup;
36
+ private getLatestBackupPath;
37
+ private ensureDirectoryExists;
38
+ /**
39
+ * Get criteria file paths for debugging
40
+ */
41
+ getCriteriaPaths(): {
42
+ criteriaPath: string;
43
+ backupDirectory: string;
44
+ environmentVariable: string | undefined;
45
+ };
46
+ }
47
+ //# sourceMappingURL=validator-criteria-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator-criteria-manager.d.ts","sourceRoot":"","sources":["../../src/security/validator-criteria-manager.ts"],"names":[],"mappings":"AAiBA;;;;GAIG;AAEH,MAAM,WAAW,uBAAuB;IACtC,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,IAAI,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACjC;AAED,qBAAa,wBAAwB;IACnC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA2B;IAClD,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAS;IAC7C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO,CAAC,eAAe,CAAuB;IAC9C,OAAO,CAAC,eAAe,CAAa;IAEpC,OAAO;WAWO,WAAW,IAAI,wBAAwB;IAOrD;;OAEG;IACU,cAAc,CAAC,YAAY,EAAE,MAAM,EAAE,cAAc,GAAE,OAAc,GAAG,OAAO,CAAC;QACzF,OAAO,EAAE,OAAO,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;IAoCF;;OAEG;IACU,YAAY,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IA2BnD;;OAEG;IACU,iBAAiB,IAAI,OAAO,CAAC,uBAAuB,GAAG,IAAI,CAAC;YAwB3D,YAAY;IAQ1B,OAAO,CAAC,mBAAmB;IAoB3B,OAAO,CAAC,qBAAqB;IAW7B;;OAEG;IACI,gBAAgB,IAAI;QACzB,YAAY,EAAE,MAAM,CAAC;QACrB,eAAe,EAAE,MAAM,CAAC;QACxB,mBAAmB,EAAE,MAAM,GAAG,SAAS,CAAC;KACzC;CAOF"}
@@ -0,0 +1,169 @@
1
+ /**
2
+ * UNUSED (2025-08-13)
3
+ * This ValidatorCriteriaManager implementation is currently NOT referenced anywhere in the codebase.
4
+ * Rationale: A parallel design was explored to separate validator-side criteria storage from the
5
+ * generic criteria manager in `src/utils/criteria-manager.ts`. The active system now only uses the
6
+ * util-based functions (adjustCriteria / loadCriteria, etc.).
7
+ * We keep this file temporarily to preserve the concept of a future isolated validator process
8
+ * that might require a distinct storage path & singleton lifecycle with backup introspection.
9
+ * If this isolation is not implemented by a future release, this file should be deleted.
10
+ *
11
+ * To re-enable: import ValidatorCriteriaManager where validator-specific criteria loading is needed
12
+ * and replace direct calls to util `adjustCriteria` with the class API.
13
+ */
14
+ import * as fs from 'fs';
15
+ import * as path from 'path';
16
+ import { logger } from '../utils/helpers.js';
17
+ export class ValidatorCriteriaManager {
18
+ static instance;
19
+ defaultCriteriaPath;
20
+ backupDirectory;
21
+ currentCriteria = null;
22
+ lastFileModTime = 0;
23
+ constructor() {
24
+ // Default path for validator criteria (separate from MCP client path)
25
+ this.defaultCriteriaPath = process.env['VALIDATOR_CRITERIA_PATH'] ||
26
+ '/tmp/mcp-shell-server/validator_criteria.txt';
27
+ this.backupDirectory = path.dirname(this.defaultCriteriaPath) + '/criteria_backups';
28
+ // Ensure directories exist
29
+ this.ensureDirectoryExists(path.dirname(this.defaultCriteriaPath));
30
+ this.ensureDirectoryExists(this.backupDirectory);
31
+ }
32
+ static getInstance() {
33
+ if (!ValidatorCriteriaManager.instance) {
34
+ ValidatorCriteriaManager.instance = new ValidatorCriteriaManager();
35
+ }
36
+ return ValidatorCriteriaManager.instance;
37
+ }
38
+ /**
39
+ * Adjust validator criteria with backup support
40
+ */
41
+ async adjustCriteria(criteriaText, backupExisting = true) {
42
+ try {
43
+ let backupPath;
44
+ // Create backup if requested and file exists
45
+ if (backupExisting && fs.existsSync(this.defaultCriteriaPath)) {
46
+ backupPath = await this.createBackup();
47
+ logger.info('Validator criteria backup created', { backupPath });
48
+ }
49
+ // Write new criteria
50
+ await fs.promises.writeFile(this.defaultCriteriaPath, criteriaText, 'utf-8');
51
+ // Update cached criteria
52
+ this.currentCriteria = criteriaText;
53
+ this.lastFileModTime = Date.now();
54
+ logger.info('Validator criteria updated successfully', {
55
+ criteriaLength: criteriaText.length,
56
+ backupCreated: !!backupPath
57
+ });
58
+ return {
59
+ success: true,
60
+ message: 'Validator criteria updated successfully',
61
+ ...(backupPath && { backupPath })
62
+ };
63
+ }
64
+ catch (error) {
65
+ logger.error('Failed to adjust validator criteria', { error });
66
+ return {
67
+ success: false,
68
+ message: `Failed to update criteria: ${error instanceof Error ? error.message : 'Unknown error'}`
69
+ };
70
+ }
71
+ }
72
+ /**
73
+ * Load current criteria for validator use
74
+ */
75
+ async loadCriteria() {
76
+ try {
77
+ if (!fs.existsSync(this.defaultCriteriaPath)) {
78
+ logger.debug('Validator criteria file not found, using default criteria');
79
+ return null;
80
+ }
81
+ const fileStats = await fs.promises.stat(this.defaultCriteriaPath);
82
+ const currentModTime = fileStats.mtime.getTime();
83
+ // Reload if file was modified or not cached
84
+ if (currentModTime !== this.lastFileModTime || this.currentCriteria === null) {
85
+ this.currentCriteria = await fs.promises.readFile(this.defaultCriteriaPath, 'utf-8');
86
+ this.lastFileModTime = currentModTime;
87
+ logger.debug('Validator criteria loaded/refreshed', {
88
+ criteriaLength: this.currentCriteria.length,
89
+ lastModified: new Date(currentModTime).toISOString()
90
+ });
91
+ }
92
+ return this.currentCriteria;
93
+ }
94
+ catch (error) {
95
+ logger.error('Failed to load validator criteria', { error });
96
+ return null;
97
+ }
98
+ }
99
+ /**
100
+ * Get current criteria configuration
101
+ */
102
+ async getCriteriaConfig() {
103
+ try {
104
+ if (!fs.existsSync(this.defaultCriteriaPath)) {
105
+ return null;
106
+ }
107
+ const criteriaText = await this.loadCriteria();
108
+ if (!criteriaText) {
109
+ return null;
110
+ }
111
+ const fileStats = await fs.promises.stat(this.defaultCriteriaPath);
112
+ return {
113
+ criteriaText,
114
+ lastModified: fileStats.mtime,
115
+ ...(this.getLatestBackupPath() && { backupPath: this.getLatestBackupPath() })
116
+ };
117
+ }
118
+ catch (error) {
119
+ logger.error('Failed to get validator criteria config', { error });
120
+ return null;
121
+ }
122
+ }
123
+ async createBackup() {
124
+ const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
125
+ const backupPath = path.join(this.backupDirectory, `validator_criteria_${timestamp}.txt`);
126
+ await fs.promises.copyFile(this.defaultCriteriaPath, backupPath);
127
+ return backupPath;
128
+ }
129
+ getLatestBackupPath() {
130
+ try {
131
+ if (!fs.existsSync(this.backupDirectory)) {
132
+ return undefined;
133
+ }
134
+ const backupFiles = fs.readdirSync(this.backupDirectory)
135
+ .filter(file => file.startsWith('validator_criteria_') && file.endsWith('.txt'))
136
+ .sort()
137
+ .reverse();
138
+ return backupFiles.length > 0 && backupFiles[0]
139
+ ? path.join(this.backupDirectory, backupFiles[0])
140
+ : undefined;
141
+ }
142
+ catch (error) {
143
+ logger.warn('Failed to find latest backup', { error });
144
+ return undefined;
145
+ }
146
+ }
147
+ ensureDirectoryExists(dirPath) {
148
+ try {
149
+ if (!fs.existsSync(dirPath)) {
150
+ fs.mkdirSync(dirPath, { recursive: true });
151
+ logger.debug('Validator criteria directory created', { dirPath });
152
+ }
153
+ }
154
+ catch (error) {
155
+ logger.error('Failed to create validator criteria directory', { dirPath, error });
156
+ }
157
+ }
158
+ /**
159
+ * Get criteria file paths for debugging
160
+ */
161
+ getCriteriaPaths() {
162
+ return {
163
+ criteriaPath: this.defaultCriteriaPath,
164
+ backupDirectory: this.backupDirectory,
165
+ environmentVariable: process.env['VALIDATOR_CRITERIA_PATH']
166
+ };
167
+ }
168
+ }
169
+ //# sourceMappingURL=validator-criteria-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validator-criteria-manager.js","sourceRoot":"","sources":["../../src/security/validator-criteria-manager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAc7C,MAAM,OAAO,wBAAwB;IAC3B,MAAM,CAAC,QAAQ,CAA2B;IACjC,mBAAmB,CAAS;IAC5B,eAA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