@cpretzinger/boss-claude 1.0.0 → 1.0.2

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 (87) hide show
  1. package/README.md +304 -1
  2. package/bin/boss-claude.js +1138 -0
  3. package/bin/commands/mode.js +250 -0
  4. package/bin/onyx-guard.js +259 -0
  5. package/bin/onyx-guard.sh +251 -0
  6. package/bin/prompts.js +284 -0
  7. package/bin/rollback.js +85 -0
  8. package/bin/setup-wizard.js +492 -0
  9. package/config/.env.example +17 -0
  10. package/lib/README.md +83 -0
  11. package/lib/agent-logger.js +61 -0
  12. package/lib/agents/memory-engineers/github-memory-engineer.js +251 -0
  13. package/lib/agents/memory-engineers/postgres-memory-engineer.js +633 -0
  14. package/lib/agents/memory-engineers/qdrant-memory-engineer.js +358 -0
  15. package/lib/agents/memory-engineers/redis-memory-engineer.js +383 -0
  16. package/lib/agents/memory-supervisor.js +526 -0
  17. package/lib/agents/registry.js +135 -0
  18. package/lib/auto-monitor.js +131 -0
  19. package/lib/checkpoint-hook.js +112 -0
  20. package/lib/checkpoint.js +319 -0
  21. package/lib/commentator.js +213 -0
  22. package/lib/context-scribe.js +120 -0
  23. package/lib/delegation-strategies.js +326 -0
  24. package/lib/hierarchy-validator.js +643 -0
  25. package/lib/index.js +15 -0
  26. package/lib/init-with-mode.js +261 -0
  27. package/lib/init.js +44 -6
  28. package/lib/memory-result-aggregator.js +252 -0
  29. package/lib/memory.js +35 -7
  30. package/lib/mode-enforcer.js +473 -0
  31. package/lib/onyx-banner.js +169 -0
  32. package/lib/onyx-identity.js +214 -0
  33. package/lib/onyx-monitor.js +381 -0
  34. package/lib/onyx-reminder.js +188 -0
  35. package/lib/onyx-tool-interceptor.js +341 -0
  36. package/lib/onyx-wrapper.js +315 -0
  37. package/lib/orchestrator-gate.js +334 -0
  38. package/lib/output-formatter.js +296 -0
  39. package/lib/postgres.js +1 -1
  40. package/lib/prompt-injector.js +220 -0
  41. package/lib/prompts.js +532 -0
  42. package/lib/session.js +153 -6
  43. package/lib/setup/README.md +187 -0
  44. package/lib/setup/env-manager.js +785 -0
  45. package/lib/setup/error-recovery.js +630 -0
  46. package/lib/setup/explain-scopes.js +385 -0
  47. package/lib/setup/github-instructions.js +333 -0
  48. package/lib/setup/github-repo.js +254 -0
  49. package/lib/setup/import-credentials.js +498 -0
  50. package/lib/setup/index.js +62 -0
  51. package/lib/setup/init-postgres.js +785 -0
  52. package/lib/setup/init-redis.js +456 -0
  53. package/lib/setup/integration-test.js +652 -0
  54. package/lib/setup/progress.js +357 -0
  55. package/lib/setup/rollback.js +670 -0
  56. package/lib/setup/rollback.test.js +452 -0
  57. package/lib/setup/setup-with-rollback.example.js +351 -0
  58. package/lib/setup/summary.js +400 -0
  59. package/lib/setup/test-github-setup.js +10 -0
  60. package/lib/setup/test-postgres-init.js +98 -0
  61. package/lib/setup/verify-setup.js +102 -0
  62. package/lib/task-agent-worker.js +235 -0
  63. package/lib/token-monitor.js +466 -0
  64. package/lib/tool-wrapper-integration.js +369 -0
  65. package/lib/tool-wrapper.js +387 -0
  66. package/lib/validators/README.md +497 -0
  67. package/lib/validators/config.js +583 -0
  68. package/lib/validators/config.test.js +175 -0
  69. package/lib/validators/github.js +310 -0
  70. package/lib/validators/github.test.js +61 -0
  71. package/lib/validators/index.js +15 -0
  72. package/lib/validators/postgres.js +525 -0
  73. package/package.json +98 -13
  74. package/scripts/benchmark-memory.js +433 -0
  75. package/scripts/check-secrets.sh +12 -0
  76. package/scripts/fetch-todos.mjs +148 -0
  77. package/scripts/graceful-shutdown.sh +156 -0
  78. package/scripts/install-onyx-hooks.js +373 -0
  79. package/scripts/install.js +119 -18
  80. package/scripts/redis-monitor.js +284 -0
  81. package/scripts/redis-setup.js +412 -0
  82. package/scripts/test-memory-retrieval.js +201 -0
  83. package/scripts/validate-exports.js +68 -0
  84. package/scripts/validate-package.js +120 -0
  85. package/scripts/verify-onyx-deployment.js +309 -0
  86. package/scripts/verify-redis-deployment.js +354 -0
  87. package/scripts/verify-redis-init.js +219 -0
@@ -0,0 +1,387 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * TOOL WRAPPER - Auto-Delegation System
4
+ *
5
+ * Intercepts Read/Write/Edit/Bash/Glob/Grep tool calls and automatically
6
+ * delegates them to Task agent when appropriate.
7
+ *
8
+ * NO USER PROMPTS - Fully automated delegation based on strategies.
9
+ */
10
+
11
+ import chalk from 'chalk';
12
+ import { shouldDelegateTool, generateDelegationMessage } from './delegation-strategies.js';
13
+ import taskWorker from './task-agent-worker.js';
14
+
15
+ /**
16
+ * Tool Wrapper Class
17
+ *
18
+ * Wraps tool execution with auto-delegation logic
19
+ */
20
+ export class ToolWrapper {
21
+ constructor(config = {}) {
22
+ this.agentName = config.agentName || 'ONYX';
23
+ this.enabled = config.enabled !== false;
24
+ this.taskWorker = taskWorker;
25
+ this.executionLog = [];
26
+ this.delegationLog = [];
27
+ this.directExecutionLog = [];
28
+
29
+ // Statistics
30
+ this.stats = {
31
+ total: 0,
32
+ delegated: 0,
33
+ direct: 0,
34
+ errors: 0
35
+ };
36
+ }
37
+
38
+ /**
39
+ * Execute tool with auto-delegation
40
+ *
41
+ * @param {string} toolName - Tool name (Read, Write, Edit, etc.)
42
+ * @param {Object} toolParams - Tool parameters
43
+ * @param {Object} options - Execution options
44
+ * @returns {Promise<Object>} Execution result
45
+ */
46
+ async executeTool(toolName, toolParams = {}, options = {}) {
47
+ if (!this.enabled) {
48
+ // Wrapper disabled - pass through to executor
49
+ return this._executeDirectly(toolName, toolParams, options);
50
+ }
51
+
52
+ const startTime = Date.now();
53
+
54
+ // Determine if delegation is needed
55
+ const decision = shouldDelegateTool(toolName, toolParams, {
56
+ agentName: this.agentName,
57
+ ...options.context
58
+ });
59
+
60
+ this.stats.total++;
61
+
62
+ if (decision.shouldDelegate) {
63
+ // AUTO-DELEGATE to Task agent
64
+ return await this._executeDelegated(toolName, toolParams, decision, options, startTime);
65
+ } else {
66
+ // Execute directly
67
+ return await this._executeDirectly(toolName, toolParams, options, decision, startTime);
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Execute via delegation to Task agent
73
+ */
74
+ async _executeDelegated(toolName, toolParams, decision, options, startTime) {
75
+ this.stats.delegated++;
76
+
77
+ console.log(chalk.cyan('\nšŸ”„ AUTO-DELEGATION TRIGGERED'));
78
+ console.log(chalk.dim('─'.repeat(60)));
79
+ console.log(chalk.white(`Agent: ${chalk.bold(this.agentName)}`));
80
+ console.log(chalk.white(`Tool: ${chalk.red(toolName)}`));
81
+ console.log(chalk.white(`Reason: ${decision.reason}`));
82
+ console.log(chalk.white(`Strategy: ${chalk.yellow(decision.strategy)}`));
83
+ console.log(chalk.dim('─'.repeat(60)));
84
+
85
+ try {
86
+ // Generate delegation message
87
+ const delegation = generateDelegationMessage(toolName, toolParams, decision);
88
+
89
+ // Execute via Task worker
90
+ const result = await this.taskWorker.executeDelegation(delegation);
91
+
92
+ const executionTime = Date.now() - startTime;
93
+
94
+ const logEntry = {
95
+ timestamp: new Date().toISOString(),
96
+ tool: toolName,
97
+ params: toolParams,
98
+ delegated: true,
99
+ decision,
100
+ result,
101
+ executionTime,
102
+ success: result.success
103
+ };
104
+
105
+ this.executionLog.push(logEntry);
106
+ this.delegationLog.push(logEntry);
107
+
108
+ return {
109
+ success: result.success,
110
+ delegated: true,
111
+ tool: toolName,
112
+ delegateTo: 'Task',
113
+ strategy: decision.strategy,
114
+ reason: decision.reason,
115
+ result: result.result,
116
+ executionTime
117
+ };
118
+
119
+ } catch (error) {
120
+ this.stats.errors++;
121
+
122
+ const executionTime = Date.now() - startTime;
123
+
124
+ const logEntry = {
125
+ timestamp: new Date().toISOString(),
126
+ tool: toolName,
127
+ params: toolParams,
128
+ delegated: true,
129
+ error: error.message,
130
+ executionTime,
131
+ success: false
132
+ };
133
+
134
+ this.executionLog.push(logEntry);
135
+
136
+ console.log(chalk.red(`āŒ Delegation error: ${error.message}`));
137
+
138
+ return {
139
+ success: false,
140
+ delegated: true,
141
+ tool: toolName,
142
+ error: error.message,
143
+ executionTime
144
+ };
145
+ }
146
+ }
147
+
148
+ /**
149
+ * Execute tool directly (no delegation)
150
+ */
151
+ async _executeDirectly(toolName, toolParams, options, decision = null, startTime = Date.now()) {
152
+ this.stats.direct++;
153
+
154
+ if (decision) {
155
+ console.log(chalk.dim(`\n⚔ Direct execution: ${toolName} (${decision.reason})`));
156
+ }
157
+
158
+ try {
159
+ // Execute via provided executor
160
+ if (options.executor && typeof options.executor === 'function') {
161
+ const result = await options.executor(toolName, toolParams);
162
+
163
+ const executionTime = Date.now() - startTime;
164
+
165
+ const logEntry = {
166
+ timestamp: new Date().toISOString(),
167
+ tool: toolName,
168
+ params: toolParams,
169
+ delegated: false,
170
+ result,
171
+ executionTime,
172
+ success: true,
173
+ decision
174
+ };
175
+
176
+ this.executionLog.push(logEntry);
177
+ this.directExecutionLog.push(logEntry);
178
+
179
+ return {
180
+ success: true,
181
+ delegated: false,
182
+ tool: toolName,
183
+ result,
184
+ executionTime
185
+ };
186
+ }
187
+
188
+ // No executor - dry run
189
+ const executionTime = Date.now() - startTime;
190
+
191
+ const logEntry = {
192
+ timestamp: new Date().toISOString(),
193
+ tool: toolName,
194
+ params: toolParams,
195
+ delegated: false,
196
+ dryRun: true,
197
+ executionTime,
198
+ success: true,
199
+ decision
200
+ };
201
+
202
+ this.executionLog.push(logEntry);
203
+ this.directExecutionLog.push(logEntry);
204
+
205
+ return {
206
+ success: true,
207
+ delegated: false,
208
+ dryRun: true,
209
+ tool: toolName,
210
+ params: toolParams,
211
+ message: 'No executor provided - dry run mode',
212
+ executionTime
213
+ };
214
+
215
+ } catch (error) {
216
+ this.stats.errors++;
217
+
218
+ const executionTime = Date.now() - startTime;
219
+
220
+ const logEntry = {
221
+ timestamp: new Date().toISOString(),
222
+ tool: toolName,
223
+ params: toolParams,
224
+ delegated: false,
225
+ error: error.message,
226
+ executionTime,
227
+ success: false
228
+ };
229
+
230
+ this.executionLog.push(logEntry);
231
+
232
+ console.log(chalk.red(`āŒ Direct execution error: ${error.message}`));
233
+
234
+ return {
235
+ success: false,
236
+ delegated: false,
237
+ tool: toolName,
238
+ error: error.message,
239
+ executionTime
240
+ };
241
+ }
242
+ }
243
+
244
+ /**
245
+ * Configure task executor
246
+ */
247
+ setTaskExecutor(executor) {
248
+ this.taskWorker.setTaskExecutor(executor);
249
+ }
250
+
251
+ /**
252
+ * Get wrapper statistics
253
+ */
254
+ getStats() {
255
+ const delegationRate = this.stats.total > 0
256
+ ? (this.stats.delegated / this.stats.total * 100).toFixed(2)
257
+ : 0;
258
+
259
+ const errorRate = this.stats.total > 0
260
+ ? (this.stats.errors / this.stats.total * 100).toFixed(2)
261
+ : 0;
262
+
263
+ return {
264
+ ...this.stats,
265
+ delegationRate: parseFloat(delegationRate),
266
+ errorRate: parseFloat(errorRate)
267
+ };
268
+ }
269
+
270
+ /**
271
+ * Print comprehensive report
272
+ */
273
+ printReport() {
274
+ const stats = this.getStats();
275
+ const taskStats = this.taskWorker.getStats();
276
+
277
+ console.log(chalk.blue('\nšŸ“Š TOOL WRAPPER REPORT'));
278
+ console.log(chalk.dim('═'.repeat(60)));
279
+ console.log(chalk.white(`Agent: ${chalk.bold(this.agentName)}`));
280
+ console.log(chalk.white(`Status: ${this.enabled ? chalk.green('ENABLED') : chalk.red('DISABLED')}`));
281
+ console.log(chalk.dim('─'.repeat(60)));
282
+ console.log(chalk.white(`Total Tool Calls: ${chalk.magenta(stats.total)}`));
283
+ console.log(chalk.white(`Delegated: ${chalk.cyan(stats.delegated)} (${stats.delegationRate}%)`));
284
+ console.log(chalk.white(`Direct: ${chalk.green(stats.direct)}`));
285
+ console.log(chalk.white(`Errors: ${chalk.red(stats.errors)} (${stats.errorRate}%)`));
286
+ console.log(chalk.dim('═'.repeat(60)));
287
+
288
+ if (this.delegationLog.length > 0) {
289
+ console.log(chalk.cyan('\nRecent Delegations:'));
290
+ this.delegationLog.slice(-5).forEach(log => {
291
+ const status = log.success ? chalk.green('āœ“') : chalk.red('āœ—');
292
+ console.log(` ${status} ${log.tool} - ${log.decision.strategy}`);
293
+ });
294
+ }
295
+
296
+ if (this.directExecutionLog.length > 0) {
297
+ console.log(chalk.green('\nRecent Direct Executions:'));
298
+ this.directExecutionLog.slice(-5).forEach(log => {
299
+ const status = log.success ? chalk.green('āœ“') : chalk.red('āœ—');
300
+ console.log(` ${status} ${log.tool}${log.dryRun ? ' (dry run)' : ''}`);
301
+ });
302
+ }
303
+
304
+ console.log(chalk.dim('═'.repeat(60)));
305
+
306
+ // Task worker stats
307
+ if (taskStats.total > 0) {
308
+ console.log(chalk.blue('\nšŸ“¤ TASK WORKER STATS'));
309
+ console.log(chalk.dim('─'.repeat(60)));
310
+ console.log(chalk.white(`Success Rate: ${chalk.cyan(taskStats.successRate + '%')}`));
311
+ console.log(chalk.white(`Avg Execution Time: ${chalk.yellow(taskStats.avgExecutionTime + 'ms')}`));
312
+ console.log(chalk.dim('─'.repeat(60)));
313
+ }
314
+ }
315
+
316
+ /**
317
+ * Get execution log
318
+ */
319
+ getLog(limit = 20) {
320
+ return this.executionLog.slice(-limit);
321
+ }
322
+
323
+ /**
324
+ * Enable/disable wrapper
325
+ */
326
+ setEnabled(enabled) {
327
+ this.enabled = enabled;
328
+ console.log(chalk.cyan(`\nšŸ”§ Tool Wrapper: ${enabled ? 'ENABLED' : 'DISABLED'}`));
329
+ }
330
+
331
+ /**
332
+ * Reset wrapper state
333
+ */
334
+ reset() {
335
+ this.executionLog = [];
336
+ this.delegationLog = [];
337
+ this.directExecutionLog = [];
338
+ this.stats = {
339
+ total: 0,
340
+ delegated: 0,
341
+ direct: 0,
342
+ errors: 0
343
+ };
344
+ this.taskWorker.reset();
345
+ console.log(chalk.green('āœ… Tool Wrapper reset'));
346
+ }
347
+ }
348
+
349
+ // Singleton instance
350
+ const toolWrapper = new ToolWrapper();
351
+
352
+ export default toolWrapper;
353
+
354
+ /**
355
+ * USAGE EXAMPLES:
356
+ *
357
+ * 1. Basic auto-delegation:
358
+ *
359
+ * import toolWrapper from '@cpretzinger/boss-claude/lib/tool-wrapper.js';
360
+ *
361
+ * const result = await toolWrapper.executeTool('Read', {
362
+ * file_path: '/path/to/file.js'
363
+ * });
364
+ *
365
+ * // If ONYX agent, automatically delegates to Task
366
+ * // If below threshold, executes directly
367
+ *
368
+ * 2. With executor function:
369
+ *
370
+ * const result = await toolWrapper.executeTool('Read', {
371
+ * file_path: '/path/to/file.js'
372
+ * }, {
373
+ * executor: async (tool, params) => {
374
+ * return await actualReadTool(params);
375
+ * }
376
+ * });
377
+ *
378
+ * 3. Configure task executor:
379
+ *
380
+ * toolWrapper.setTaskExecutor(async (taskParams) => {
381
+ * return await taskTool.execute(taskParams);
382
+ * });
383
+ *
384
+ * 4. Print report:
385
+ *
386
+ * toolWrapper.printReport();
387
+ */