pm-orchestrator-runner 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 (215) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +108 -0
  3. package/dist/cli/cli-interface.d.ts +150 -0
  4. package/dist/cli/cli-interface.d.ts.map +1 -0
  5. package/dist/cli/cli-interface.js +606 -0
  6. package/dist/cli/cli-interface.js.map +1 -0
  7. package/dist/cli/index.d.ts +13 -0
  8. package/dist/cli/index.d.ts.map +1 -0
  9. package/dist/cli/index.js +243 -0
  10. package/dist/cli/index.js.map +1 -0
  11. package/dist/cli/llm-sentinel.d.ts +15 -0
  12. package/dist/cli/llm-sentinel.d.ts.map +1 -0
  13. package/dist/cli/llm-sentinel.js +184 -0
  14. package/dist/cli/llm-sentinel.js.map +1 -0
  15. package/dist/config/configuration-manager.d.ts +149 -0
  16. package/dist/config/configuration-manager.d.ts.map +1 -0
  17. package/dist/config/configuration-manager.js +241 -0
  18. package/dist/config/configuration-manager.js.map +1 -0
  19. package/dist/continuation/continuation-control-manager.d.ts +154 -0
  20. package/dist/continuation/continuation-control-manager.d.ts.map +1 -0
  21. package/dist/continuation/continuation-control-manager.js +303 -0
  22. package/dist/continuation/continuation-control-manager.js.map +1 -0
  23. package/dist/core/runner-core.d.ts +474 -0
  24. package/dist/core/runner-core.d.ts.map +1 -0
  25. package/dist/core/runner-core.js +1311 -0
  26. package/dist/core/runner-core.js.map +1 -0
  27. package/dist/errors/error-codes.d.ts +105 -0
  28. package/dist/errors/error-codes.d.ts.map +1 -0
  29. package/dist/errors/error-codes.js +198 -0
  30. package/dist/errors/error-codes.js.map +1 -0
  31. package/dist/errors/runner-error.d.ts +14 -0
  32. package/dist/errors/runner-error.d.ts.map +1 -0
  33. package/dist/errors/runner-error.js +33 -0
  34. package/dist/errors/runner-error.js.map +1 -0
  35. package/dist/evidence/evidence-manager.d.ts +112 -0
  36. package/dist/evidence/evidence-manager.d.ts.map +1 -0
  37. package/dist/evidence/evidence-manager.js +337 -0
  38. package/dist/evidence/evidence-manager.js.map +1 -0
  39. package/dist/executor/claude-code-executor.d.ts +136 -0
  40. package/dist/executor/claude-code-executor.d.ts.map +1 -0
  41. package/dist/executor/claude-code-executor.js +643 -0
  42. package/dist/executor/claude-code-executor.js.map +1 -0
  43. package/dist/executor/deterministic-executor.d.ts +40 -0
  44. package/dist/executor/deterministic-executor.d.ts.map +1 -0
  45. package/dist/executor/deterministic-executor.js +269 -0
  46. package/dist/executor/deterministic-executor.js.map +1 -0
  47. package/dist/lifecycle/lifecycle-controller.d.ts +270 -0
  48. package/dist/lifecycle/lifecycle-controller.d.ts.map +1 -0
  49. package/dist/lifecycle/lifecycle-controller.js +596 -0
  50. package/dist/lifecycle/lifecycle-controller.js.map +1 -0
  51. package/dist/limits/resource-limit-manager.d.ts +200 -0
  52. package/dist/limits/resource-limit-manager.d.ts.map +1 -0
  53. package/dist/limits/resource-limit-manager.js +376 -0
  54. package/dist/limits/resource-limit-manager.js.map +1 -0
  55. package/dist/locks/lock-manager.d.ts +116 -0
  56. package/dist/locks/lock-manager.d.ts.map +1 -0
  57. package/dist/locks/lock-manager.js +306 -0
  58. package/dist/locks/lock-manager.js.map +1 -0
  59. package/dist/logging/index.d.ts +8 -0
  60. package/dist/logging/index.d.ts.map +1 -0
  61. package/dist/logging/index.js +22 -0
  62. package/dist/logging/index.js.map +1 -0
  63. package/dist/logging/sensitive-data-masker.d.ts +90 -0
  64. package/dist/logging/sensitive-data-masker.d.ts.map +1 -0
  65. package/dist/logging/sensitive-data-masker.js +228 -0
  66. package/dist/logging/sensitive-data-masker.js.map +1 -0
  67. package/dist/logging/task-log-manager.d.ts +215 -0
  68. package/dist/logging/task-log-manager.d.ts.map +1 -0
  69. package/dist/logging/task-log-manager.js +743 -0
  70. package/dist/logging/task-log-manager.js.map +1 -0
  71. package/dist/mediation/fail-closed-runner.d.ts +131 -0
  72. package/dist/mediation/fail-closed-runner.d.ts.map +1 -0
  73. package/dist/mediation/fail-closed-runner.js +245 -0
  74. package/dist/mediation/fail-closed-runner.js.map +1 -0
  75. package/dist/mediation/llm-client-with-evidence.d.ts +123 -0
  76. package/dist/mediation/llm-client-with-evidence.d.ts.map +1 -0
  77. package/dist/mediation/llm-client-with-evidence.js +245 -0
  78. package/dist/mediation/llm-client-with-evidence.js.map +1 -0
  79. package/dist/mediation/llm-client.d.ts +102 -0
  80. package/dist/mediation/llm-client.d.ts.map +1 -0
  81. package/dist/mediation/llm-client.js +206 -0
  82. package/dist/mediation/llm-client.js.map +1 -0
  83. package/dist/mediation/llm-evidence-manager.d.ts +108 -0
  84. package/dist/mediation/llm-evidence-manager.d.ts.map +1 -0
  85. package/dist/mediation/llm-evidence-manager.js +230 -0
  86. package/dist/mediation/llm-evidence-manager.js.map +1 -0
  87. package/dist/mediation/llm-mediation-layer.d.ts +175 -0
  88. package/dist/mediation/llm-mediation-layer.d.ts.map +1 -0
  89. package/dist/mediation/llm-mediation-layer.js +315 -0
  90. package/dist/mediation/llm-mediation-layer.js.map +1 -0
  91. package/dist/mediation/llm-sentinel.d.ts +107 -0
  92. package/dist/mediation/llm-sentinel.d.ts.map +1 -0
  93. package/dist/mediation/llm-sentinel.js +187 -0
  94. package/dist/mediation/llm-sentinel.js.map +1 -0
  95. package/dist/mediation/real-llm-mediation-layer.d.ts +104 -0
  96. package/dist/mediation/real-llm-mediation-layer.d.ts.map +1 -0
  97. package/dist/mediation/real-llm-mediation-layer.js +322 -0
  98. package/dist/mediation/real-llm-mediation-layer.js.map +1 -0
  99. package/dist/mediation/verdict-reporter.d.ts +61 -0
  100. package/dist/mediation/verdict-reporter.d.ts.map +1 -0
  101. package/dist/mediation/verdict-reporter.js +178 -0
  102. package/dist/mediation/verdict-reporter.js.map +1 -0
  103. package/dist/models/enums.d.ts +133 -0
  104. package/dist/models/enums.d.ts.map +1 -0
  105. package/dist/models/enums.js +201 -0
  106. package/dist/models/enums.js.map +1 -0
  107. package/dist/models/evidence.d.ts +60 -0
  108. package/dist/models/evidence.d.ts.map +1 -0
  109. package/dist/models/evidence.js +135 -0
  110. package/dist/models/evidence.js.map +1 -0
  111. package/dist/models/execution-result.d.ts +89 -0
  112. package/dist/models/execution-result.d.ts.map +1 -0
  113. package/dist/models/execution-result.js +197 -0
  114. package/dist/models/execution-result.js.map +1 -0
  115. package/dist/models/file-lock.d.ts +62 -0
  116. package/dist/models/file-lock.d.ts.map +1 -0
  117. package/dist/models/file-lock.js +133 -0
  118. package/dist/models/file-lock.js.map +1 -0
  119. package/dist/models/index.d.ts +12 -0
  120. package/dist/models/index.d.ts.map +1 -0
  121. package/dist/models/index.js +91 -0
  122. package/dist/models/index.js.map +1 -0
  123. package/dist/models/repl/index.d.ts +7 -0
  124. package/dist/models/repl/index.d.ts.map +1 -0
  125. package/dist/models/repl/index.js +32 -0
  126. package/dist/models/repl/index.js.map +1 -0
  127. package/dist/models/repl/model-registry.d.ts +73 -0
  128. package/dist/models/repl/model-registry.d.ts.map +1 -0
  129. package/dist/models/repl/model-registry.js +116 -0
  130. package/dist/models/repl/model-registry.js.map +1 -0
  131. package/dist/models/repl/repl-state.d.ts +86 -0
  132. package/dist/models/repl/repl-state.d.ts.map +1 -0
  133. package/dist/models/repl/repl-state.js +152 -0
  134. package/dist/models/repl/repl-state.js.map +1 -0
  135. package/dist/models/repl/task-log.d.ts +247 -0
  136. package/dist/models/repl/task-log.d.ts.map +1 -0
  137. package/dist/models/repl/task-log.js +178 -0
  138. package/dist/models/repl/task-log.js.map +1 -0
  139. package/dist/models/session.d.ts +71 -0
  140. package/dist/models/session.d.ts.map +1 -0
  141. package/dist/models/session.js +140 -0
  142. package/dist/models/session.js.map +1 -0
  143. package/dist/models/supporting.d.ts +97 -0
  144. package/dist/models/supporting.d.ts.map +1 -0
  145. package/dist/models/supporting.js +208 -0
  146. package/dist/models/supporting.js.map +1 -0
  147. package/dist/models/task.d.ts +77 -0
  148. package/dist/models/task.d.ts.map +1 -0
  149. package/dist/models/task.js +170 -0
  150. package/dist/models/task.js.map +1 -0
  151. package/dist/output/output-control-manager.d.ts +217 -0
  152. package/dist/output/output-control-manager.d.ts.map +1 -0
  153. package/dist/output/output-control-manager.js +378 -0
  154. package/dist/output/output-control-manager.js.map +1 -0
  155. package/dist/pool/agent-pool.d.ts +284 -0
  156. package/dist/pool/agent-pool.d.ts.map +1 -0
  157. package/dist/pool/agent-pool.js +451 -0
  158. package/dist/pool/agent-pool.js.map +1 -0
  159. package/dist/repl/commands/index.d.ts +12 -0
  160. package/dist/repl/commands/index.d.ts.map +1 -0
  161. package/dist/repl/commands/index.js +26 -0
  162. package/dist/repl/commands/index.js.map +1 -0
  163. package/dist/repl/commands/init.d.ts +31 -0
  164. package/dist/repl/commands/init.d.ts.map +1 -0
  165. package/dist/repl/commands/init.js +234 -0
  166. package/dist/repl/commands/init.js.map +1 -0
  167. package/dist/repl/commands/keys.d.ts +63 -0
  168. package/dist/repl/commands/keys.d.ts.map +1 -0
  169. package/dist/repl/commands/keys.js +114 -0
  170. package/dist/repl/commands/keys.js.map +1 -0
  171. package/dist/repl/commands/logs.d.ts +91 -0
  172. package/dist/repl/commands/logs.d.ts.map +1 -0
  173. package/dist/repl/commands/logs.js +200 -0
  174. package/dist/repl/commands/logs.js.map +1 -0
  175. package/dist/repl/commands/model.d.ts +85 -0
  176. package/dist/repl/commands/model.d.ts.map +1 -0
  177. package/dist/repl/commands/model.js +225 -0
  178. package/dist/repl/commands/model.js.map +1 -0
  179. package/dist/repl/commands/models.d.ts +50 -0
  180. package/dist/repl/commands/models.d.ts.map +1 -0
  181. package/dist/repl/commands/models.js +180 -0
  182. package/dist/repl/commands/models.js.map +1 -0
  183. package/dist/repl/commands/provider.d.ts +79 -0
  184. package/dist/repl/commands/provider.d.ts.map +1 -0
  185. package/dist/repl/commands/provider.js +291 -0
  186. package/dist/repl/commands/provider.js.map +1 -0
  187. package/dist/repl/commands/session.d.ts +50 -0
  188. package/dist/repl/commands/session.d.ts.map +1 -0
  189. package/dist/repl/commands/session.js +152 -0
  190. package/dist/repl/commands/session.js.map +1 -0
  191. package/dist/repl/commands/status.d.ts +55 -0
  192. package/dist/repl/commands/status.d.ts.map +1 -0
  193. package/dist/repl/commands/status.js +182 -0
  194. package/dist/repl/commands/status.js.map +1 -0
  195. package/dist/repl/index.d.ts +6 -0
  196. package/dist/repl/index.d.ts.map +1 -0
  197. package/dist/repl/index.js +25 -0
  198. package/dist/repl/index.js.map +1 -0
  199. package/dist/repl/repl-interface.d.ts +371 -0
  200. package/dist/repl/repl-interface.d.ts.map +1 -0
  201. package/dist/repl/repl-interface.js +1214 -0
  202. package/dist/repl/repl-interface.js.map +1 -0
  203. package/dist/session/session-manager.d.ts +85 -0
  204. package/dist/session/session-manager.d.ts.map +1 -0
  205. package/dist/session/session-manager.js +217 -0
  206. package/dist/session/session-manager.js.map +1 -0
  207. package/dist/supervisor/executor-supervisor.d.ts +90 -0
  208. package/dist/supervisor/executor-supervisor.d.ts.map +1 -0
  209. package/dist/supervisor/executor-supervisor.js +223 -0
  210. package/dist/supervisor/executor-supervisor.js.map +1 -0
  211. package/dist/supervisor/index.d.ts +5 -0
  212. package/dist/supervisor/index.d.ts.map +1 -0
  213. package/dist/supervisor/index.js +9 -0
  214. package/dist/supervisor/index.js.map +1 -0
  215. package/package.json +57 -0
@@ -0,0 +1,230 @@
1
+ "use strict";
2
+ /**
3
+ * LLM Evidence Manager
4
+ *
5
+ * Tracks and verifies evidence of real LLM API calls.
6
+ * This is the fail-closed mechanism that ensures:
7
+ * 1. Every LLM call generates a proof file
8
+ * 2. COMPLETE status can only be asserted with evidence
9
+ * 3. Evidence files are tamper-resistant (hash verification)
10
+ *
11
+ * ARCHITECTURAL RULES:
12
+ * - No evidence file = LLM call did not happen
13
+ * - Evidence must exist BEFORE asserting COMPLETE
14
+ * - Failed calls are also recorded (to prove attempt)
15
+ */
16
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ var desc = Object.getOwnPropertyDescriptor(m, k);
19
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
20
+ desc = { enumerable: true, get: function() { return m[k]; } };
21
+ }
22
+ Object.defineProperty(o, k2, desc);
23
+ }) : (function(o, m, k, k2) {
24
+ if (k2 === undefined) k2 = k;
25
+ o[k2] = m[k];
26
+ }));
27
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
28
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
29
+ }) : function(o, v) {
30
+ o["default"] = v;
31
+ });
32
+ var __importStar = (this && this.__importStar) || (function () {
33
+ var ownKeys = function(o) {
34
+ ownKeys = Object.getOwnPropertyNames || function (o) {
35
+ var ar = [];
36
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
37
+ return ar;
38
+ };
39
+ return ownKeys(o);
40
+ };
41
+ return function (mod) {
42
+ if (mod && mod.__esModule) return mod;
43
+ var result = {};
44
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
45
+ __setModuleDefault(result, mod);
46
+ return result;
47
+ };
48
+ })();
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.LLMEvidenceManager = void 0;
51
+ exports.hashRequest = hashRequest;
52
+ exports.hashResponse = hashResponse;
53
+ const fs = __importStar(require("fs"));
54
+ const path = __importStar(require("path"));
55
+ const crypto = __importStar(require("crypto"));
56
+ /**
57
+ * LLM Evidence Manager
58
+ *
59
+ * Manages evidence files for LLM API calls.
60
+ * Uses file-based storage for durability and auditability.
61
+ */
62
+ class LLMEvidenceManager {
63
+ evidenceDir;
64
+ evidenceMap = new Map();
65
+ constructor(baseDir) {
66
+ this.evidenceDir = path.join(baseDir, 'llm');
67
+ // Ensure evidence directory exists
68
+ if (!fs.existsSync(this.evidenceDir)) {
69
+ fs.mkdirSync(this.evidenceDir, { recursive: true });
70
+ }
71
+ // Load existing evidence files
72
+ this.loadExistingEvidence();
73
+ }
74
+ /**
75
+ * Load existing evidence files from disk
76
+ */
77
+ loadExistingEvidence() {
78
+ if (!fs.existsSync(this.evidenceDir)) {
79
+ return;
80
+ }
81
+ const files = fs.readdirSync(this.evidenceDir);
82
+ for (const file of files) {
83
+ if (file.endsWith('.json')) {
84
+ try {
85
+ const content = fs.readFileSync(path.join(this.evidenceDir, file), 'utf-8');
86
+ const evidenceFile = JSON.parse(content);
87
+ if (evidenceFile.evidence && evidenceFile.evidence.call_id) {
88
+ this.evidenceMap.set(evidenceFile.evidence.call_id, evidenceFile.evidence);
89
+ }
90
+ }
91
+ catch {
92
+ // Skip invalid files
93
+ }
94
+ }
95
+ }
96
+ }
97
+ /**
98
+ * Record evidence for an LLM call
99
+ * @returns Path to the evidence file
100
+ */
101
+ recordEvidence(evidence) {
102
+ // Calculate integrity hash of the evidence
103
+ const evidenceJson = JSON.stringify(evidence);
104
+ const integrityHash = crypto.createHash('sha256').update(evidenceJson).digest('hex');
105
+ const evidenceFile = {
106
+ evidence,
107
+ integrity_hash: integrityHash,
108
+ };
109
+ // Write to file
110
+ const filename = `${evidence.call_id}.json`;
111
+ const filepath = path.join(this.evidenceDir, filename);
112
+ fs.writeFileSync(filepath, JSON.stringify(evidenceFile, null, 2), 'utf-8');
113
+ // Update in-memory map
114
+ this.evidenceMap.set(evidence.call_id, evidence);
115
+ return filepath;
116
+ }
117
+ /**
118
+ * Check if evidence exists for a call
119
+ */
120
+ hasEvidence(callId) {
121
+ // First check in-memory
122
+ if (this.evidenceMap.has(callId)) {
123
+ return true;
124
+ }
125
+ // Then check on disk
126
+ const filepath = path.join(this.evidenceDir, `${callId}.json`);
127
+ return fs.existsSync(filepath);
128
+ }
129
+ /**
130
+ * Get evidence by call ID
131
+ */
132
+ getEvidence(callId) {
133
+ // First check in-memory
134
+ if (this.evidenceMap.has(callId)) {
135
+ return this.evidenceMap.get(callId);
136
+ }
137
+ // Then check on disk
138
+ const filepath = path.join(this.evidenceDir, `${callId}.json`);
139
+ if (!fs.existsSync(filepath)) {
140
+ return null;
141
+ }
142
+ try {
143
+ const content = fs.readFileSync(filepath, 'utf-8');
144
+ const evidenceFile = JSON.parse(content);
145
+ // Cache in memory
146
+ this.evidenceMap.set(callId, evidenceFile.evidence);
147
+ return evidenceFile.evidence;
148
+ }
149
+ catch {
150
+ return null;
151
+ }
152
+ }
153
+ /**
154
+ * List all evidence
155
+ */
156
+ listEvidence() {
157
+ // Reload from disk to ensure we have all evidence
158
+ this.loadExistingEvidence();
159
+ return Array.from(this.evidenceMap.values());
160
+ }
161
+ /**
162
+ * Get evidence statistics
163
+ */
164
+ getStats() {
165
+ const allEvidence = this.listEvidence();
166
+ const successful = allEvidence.filter(e => e.success);
167
+ const failed = allEvidence.filter(e => !e.success);
168
+ return {
169
+ total_calls: allEvidence.length,
170
+ successful_calls: successful.length,
171
+ failed_calls: failed.length,
172
+ };
173
+ }
174
+ /**
175
+ * Check if we can assert COMPLETE status
176
+ * Requires at least one successful LLM call with evidence
177
+ */
178
+ canAssertComplete() {
179
+ const allEvidence = this.listEvidence();
180
+ // No evidence at all = cannot assert COMPLETE
181
+ if (allEvidence.length === 0) {
182
+ return false;
183
+ }
184
+ // At least one successful call required
185
+ return allEvidence.some(e => e.success);
186
+ }
187
+ /**
188
+ * Verify integrity of an evidence file
189
+ * Detects tampering by comparing stored hash with recalculated hash
190
+ */
191
+ verifyIntegrity(callId) {
192
+ const filepath = path.join(this.evidenceDir, `${callId}.json`);
193
+ if (!fs.existsSync(filepath)) {
194
+ return false;
195
+ }
196
+ try {
197
+ const content = fs.readFileSync(filepath, 'utf-8');
198
+ const evidenceFile = JSON.parse(content);
199
+ // Recalculate hash
200
+ const evidenceJson = JSON.stringify(evidenceFile.evidence);
201
+ const calculatedHash = crypto.createHash('sha256').update(evidenceJson).digest('hex');
202
+ // Compare with stored hash
203
+ return calculatedHash === evidenceFile.integrity_hash;
204
+ }
205
+ catch {
206
+ return false;
207
+ }
208
+ }
209
+ /**
210
+ * Get evidence directory path
211
+ */
212
+ getEvidenceDir() {
213
+ return this.evidenceDir;
214
+ }
215
+ }
216
+ exports.LLMEvidenceManager = LLMEvidenceManager;
217
+ /**
218
+ * Create hash for request payload
219
+ */
220
+ function hashRequest(messages) {
221
+ const content = JSON.stringify(messages);
222
+ return 'sha256:' + crypto.createHash('sha256').update(content).digest('hex');
223
+ }
224
+ /**
225
+ * Create hash for response content
226
+ */
227
+ function hashResponse(content) {
228
+ return 'sha256:' + crypto.createHash('sha256').update(content).digest('hex');
229
+ }
230
+ //# sourceMappingURL=llm-evidence-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llm-evidence-manager.js","sourceRoot":"","sources":["../../src/mediation/llm-evidence-manager.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;GAaG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2OH,kCAGC;AAKD,oCAEC;AAnPD,uCAAyB;AACzB,2CAA6B;AAC7B,+CAAiC;AA4CjC;;;;;GAKG;AACH,MAAa,kBAAkB;IACZ,WAAW,CAAS;IACpB,WAAW,GAA6B,IAAI,GAAG,EAAE,CAAC;IAEnE,YAAY,OAAe;QACzB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;QAE7C,mCAAmC;QACnC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;YACrC,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACtD,CAAC;QAED,+BAA+B;QAC/B,IAAI,CAAC,oBAAoB,EAAE,CAAC;IAC9B,CAAC;IAED;;OAEG;IACK,oBAAoB;QAC1B,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;YACrC,OAAO;QACT,CAAC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* Runner Core returns structured signals (facts only), this layer:
6
+ * - Generates natural language questions to users
7
+ * - Interprets user responses
8
+ * - Normalizes responses into explicit tasks for Runner
9
+ *
10
+ * ARCHITECTURAL RULES:
11
+ * - Runner MUST NOT contain conversational phrasing logic
12
+ * - Runner MUST NOT contain file-name-specific logic
13
+ * - This layer is the ONLY component that asks questions
14
+ * - This layer decides how to phrase clarification questions
15
+ * - This layer decides follow-up actions based on user answers
16
+ */
17
+ /**
18
+ * Clarification reason codes from Runner (structured, no conversation)
19
+ */
20
+ export type ClarificationReason = 'target_file_exists' | 'target_file_ambiguous' | 'target_action_ambiguous' | 'missing_required_info';
21
+ /**
22
+ * Structured signal from Runner Core (facts only)
23
+ */
24
+ export interface RunnerSignal {
25
+ /** Whether clarification is needed before proceeding */
26
+ clarification_needed: boolean;
27
+ /** Reason code for clarification (structured, not conversational) */
28
+ clarification_reason?: ClarificationReason;
29
+ /** Target file path if identified (fact) */
30
+ target_file?: string;
31
+ /** Whether to proceed with next action */
32
+ next_action: boolean;
33
+ /** Original prompt that was analyzed */
34
+ original_prompt?: string;
35
+ /** Task execution result if executed */
36
+ execution_result?: {
37
+ status: 'COMPLETE' | 'INCOMPLETE' | 'NO_EVIDENCE' | 'ERROR';
38
+ output?: string;
39
+ files_modified?: string[];
40
+ verified_files?: Array<{
41
+ path: string;
42
+ exists: boolean;
43
+ size?: number;
44
+ }>;
45
+ };
46
+ }
47
+ /**
48
+ * User response types after clarification
49
+ */
50
+ export type UserResponseType = 'overwrite' | 'new_name' | 'cancel' | 'specify_file' | 'specify_action' | 'unknown';
51
+ /**
52
+ * Parsed user response
53
+ */
54
+ export interface ParsedUserResponse {
55
+ type: UserResponseType;
56
+ /** New file name if type is 'new_name' or 'specify_file' */
57
+ new_file_name?: string;
58
+ /** Specified action if type is 'specify_action' */
59
+ specified_action?: string;
60
+ /** Raw user input */
61
+ raw_input: string;
62
+ }
63
+ /**
64
+ * Normalized task to send back to Runner
65
+ */
66
+ export interface NormalizedTask {
67
+ /** Explicit, unambiguous task description for Runner */
68
+ explicit_prompt: string;
69
+ /** Target file path */
70
+ target_file?: string;
71
+ /** Action type */
72
+ action: 'create' | 'overwrite' | 'create_new' | 'modify' | 'cancel';
73
+ /** Original context for tracing */
74
+ original_context: {
75
+ original_prompt: string;
76
+ clarification_reason?: ClarificationReason;
77
+ user_response: string;
78
+ };
79
+ }
80
+ /**
81
+ * LLM Mediation Layer output to user
82
+ */
83
+ export interface MediationOutput {
84
+ /** Whether to show a question to user */
85
+ needs_user_input: boolean;
86
+ /** Question to display to user (natural language) */
87
+ question?: string;
88
+ /** Suggested responses for user (optional hints) */
89
+ suggested_responses?: string[];
90
+ /** If no user input needed, the normalized task to execute */
91
+ normalized_task?: NormalizedTask;
92
+ /** Status message to display */
93
+ status_message?: string;
94
+ }
95
+ /**
96
+ * LLM Mediation Layer
97
+ *
98
+ * Handles all user interaction and decision making.
99
+ * Receives structured signals from Runner, generates natural language,
100
+ * interprets user responses, and normalizes them into explicit tasks.
101
+ */
102
+ export declare class LLMMediationLayer {
103
+ /**
104
+ * Process Runner signal and generate appropriate output
105
+ *
106
+ * @param signal - Structured signal from Runner Core
107
+ * @returns Mediation output (question to user or normalized task)
108
+ */
109
+ processRunnerSignal(signal: RunnerSignal): MediationOutput;
110
+ /**
111
+ * Parse user response and determine response type
112
+ *
113
+ * @param userInput - Raw user input string
114
+ * @param context - Context from previous clarification
115
+ * @returns Parsed user response
116
+ */
117
+ parseUserResponse(userInput: string, context: {
118
+ clarification_reason?: ClarificationReason;
119
+ target_file?: string;
120
+ }): ParsedUserResponse;
121
+ /**
122
+ * Normalize user response into explicit task for Runner
123
+ *
124
+ * @param originalPrompt - Original user prompt
125
+ * @param signal - Runner signal that triggered clarification
126
+ * @param parsedResponse - Parsed user response
127
+ * @returns Normalized task or null if cancelled
128
+ */
129
+ normalizeToTask(originalPrompt: string, signal: RunnerSignal, parsedResponse: ParsedUserResponse): NormalizedTask | null;
130
+ /**
131
+ * Handle case when target file already exists
132
+ */
133
+ private handleFileExistsCase;
134
+ /**
135
+ * Handle case when target file is ambiguous
136
+ */
137
+ private handleFileAmbiguousCase;
138
+ /**
139
+ * Handle case when action is ambiguous
140
+ */
141
+ private handleActionAmbiguousCase;
142
+ /**
143
+ * Handle case when required info is missing
144
+ */
145
+ private handleMissingInfoCase;
146
+ /**
147
+ * Generate status message for non-clarification cases
148
+ */
149
+ private generateStatusMessage;
150
+ /**
151
+ * Check if input indicates cancel intent
152
+ */
153
+ private isCancelIntent;
154
+ /**
155
+ * Parse response for overwrite/new decision
156
+ */
157
+ private parseOverwriteResponse;
158
+ /**
159
+ * Parse response for file specification
160
+ */
161
+ private parseFileSpecification;
162
+ /**
163
+ * Parse response for action specification
164
+ */
165
+ private parseActionSpecification;
166
+ /**
167
+ * Extract file name from user input
168
+ */
169
+ private extractFileName;
170
+ /**
171
+ * Generate alternative file name
172
+ */
173
+ private generateAlternativeName;
174
+ }
175
+ //# sourceMappingURL=llm-mediation-layer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llm-mediation-layer.d.ts","sourceRoot":"","sources":["../../src/mediation/llm-mediation-layer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAC3B,oBAAoB,GACpB,uBAAuB,GACvB,yBAAyB,GACzB,uBAAuB,CAAC;AAE5B;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,wDAAwD;IACxD,oBAAoB,EAAE,OAAO,CAAC;IAC9B,qEAAqE;IACrE,oBAAoB,CAAC,EAAE,mBAAmB,CAAC;IAC3C,4CAA4C;IAC5C,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,0CAA0C;IAC1C,WAAW,EAAE,OAAO,CAAC;IACrB,wCAAwC;IACxC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,wCAAwC;IACxC,gBAAgB,CAAC,EAAE;QACjB,MAAM,EAAE,UAAU,GAAG,YAAY,GAAG,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