pikakit 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 (145) hide show
  1. package/README.md +239 -0
  2. package/bin/add-skill-kit.js +3 -0
  3. package/bin/cli.mjs +6 -0
  4. package/bin/kit.mjs +89 -0
  5. package/bin/lib/agents.js +208 -0
  6. package/bin/lib/commands/analyze.js +70 -0
  7. package/bin/lib/commands/cache.js +65 -0
  8. package/bin/lib/commands/doctor.js +75 -0
  9. package/bin/lib/commands/help.js +155 -0
  10. package/bin/lib/commands/info.js +38 -0
  11. package/bin/lib/commands/init.js +39 -0
  12. package/bin/lib/commands/install.js +803 -0
  13. package/bin/lib/commands/list.js +43 -0
  14. package/bin/lib/commands/lock.js +57 -0
  15. package/bin/lib/commands/uninstall.js +307 -0
  16. package/bin/lib/commands/update.js +55 -0
  17. package/bin/lib/commands/validate.js +69 -0
  18. package/bin/lib/commands/verify.js +56 -0
  19. package/bin/lib/config.js +81 -0
  20. package/bin/lib/helpers.js +196 -0
  21. package/bin/lib/helpers.test.js +60 -0
  22. package/bin/lib/installer.js +164 -0
  23. package/bin/lib/skills.js +119 -0
  24. package/bin/lib/skills.test.js +109 -0
  25. package/bin/lib/types.js +82 -0
  26. package/bin/lib/ui.js +329 -0
  27. package/lib/agent-cli/README.md +21 -0
  28. package/lib/agent-cli/__tests__/adaptive_engine.test.js +190 -0
  29. package/lib/agent-cli/__tests__/integration/cross_script.test.js +222 -0
  30. package/lib/agent-cli/__tests__/integration/full_cycle.test.js +230 -0
  31. package/lib/agent-cli/__tests__/pattern_analyzer.test.js +173 -0
  32. package/lib/agent-cli/__tests__/pre_execution_check.test.js +167 -0
  33. package/lib/agent-cli/__tests__/skill_injector.test.js +191 -0
  34. package/lib/agent-cli/bin/agent.js +191 -0
  35. package/lib/agent-cli/dashboard/dashboard_server.js +340 -0
  36. package/lib/agent-cli/dashboard/index.html +538 -0
  37. package/lib/agent-cli/lib/audit.js +154 -0
  38. package/lib/agent-cli/lib/audit.test.js +100 -0
  39. package/lib/agent-cli/lib/auto-learn.js +319 -0
  40. package/lib/agent-cli/lib/backup.js +138 -0
  41. package/lib/agent-cli/lib/backup.test.js +78 -0
  42. package/lib/agent-cli/lib/cognitive-lesson.js +476 -0
  43. package/lib/agent-cli/lib/completion.js +149 -0
  44. package/lib/agent-cli/lib/config.js +35 -0
  45. package/lib/agent-cli/lib/eslint-fix.js +238 -0
  46. package/lib/agent-cli/lib/evolution-signal.js +215 -0
  47. package/lib/agent-cli/lib/export.js +86 -0
  48. package/lib/agent-cli/lib/export.test.js +65 -0
  49. package/lib/agent-cli/lib/fix.js +337 -0
  50. package/lib/agent-cli/lib/fix.test.js +80 -0
  51. package/lib/agent-cli/lib/gemini-export.js +83 -0
  52. package/lib/agent-cli/lib/generate-registry.js +42 -0
  53. package/lib/agent-cli/lib/hooks/install-hooks.js +152 -0
  54. package/lib/agent-cli/lib/hooks/lint-learn.js +172 -0
  55. package/lib/agent-cli/lib/ignore.js +116 -0
  56. package/lib/agent-cli/lib/ignore.test.js +58 -0
  57. package/lib/agent-cli/lib/init.js +124 -0
  58. package/lib/agent-cli/lib/learn.js +255 -0
  59. package/lib/agent-cli/lib/learn.test.js +70 -0
  60. package/lib/agent-cli/lib/migrate-to-v4.js +322 -0
  61. package/lib/agent-cli/lib/proposals.js +199 -0
  62. package/lib/agent-cli/lib/proposals.test.js +56 -0
  63. package/lib/agent-cli/lib/recall.js +820 -0
  64. package/lib/agent-cli/lib/recall.test.js +107 -0
  65. package/lib/agent-cli/lib/selfevolution-bridge.js +167 -0
  66. package/lib/agent-cli/lib/settings.js +227 -0
  67. package/lib/agent-cli/lib/skill-learn.js +296 -0
  68. package/lib/agent-cli/lib/stats.js +132 -0
  69. package/lib/agent-cli/lib/stats.test.js +94 -0
  70. package/lib/agent-cli/lib/types.js +33 -0
  71. package/lib/agent-cli/lib/ui/audit-ui.js +146 -0
  72. package/lib/agent-cli/lib/ui/backup-ui.js +107 -0
  73. package/lib/agent-cli/lib/ui/clack-helpers.js +317 -0
  74. package/lib/agent-cli/lib/ui/common.js +83 -0
  75. package/lib/agent-cli/lib/ui/completion-ui.js +126 -0
  76. package/lib/agent-cli/lib/ui/custom-select.js +69 -0
  77. package/lib/agent-cli/lib/ui/dashboard-ui.js +222 -0
  78. package/lib/agent-cli/lib/ui/evolution-signals-ui.js +107 -0
  79. package/lib/agent-cli/lib/ui/export-ui.js +94 -0
  80. package/lib/agent-cli/lib/ui/fix-all-ui.js +191 -0
  81. package/lib/agent-cli/lib/ui/help-ui.js +49 -0
  82. package/lib/agent-cli/lib/ui/index.js +199 -0
  83. package/lib/agent-cli/lib/ui/init-ui.js +56 -0
  84. package/lib/agent-cli/lib/ui/knowledge-ui.js +55 -0
  85. package/lib/agent-cli/lib/ui/learn-ui.js +706 -0
  86. package/lib/agent-cli/lib/ui/lessons-ui.js +148 -0
  87. package/lib/agent-cli/lib/ui/pretty.js +145 -0
  88. package/lib/agent-cli/lib/ui/proposals-ui.js +99 -0
  89. package/lib/agent-cli/lib/ui/recall-ui.js +342 -0
  90. package/lib/agent-cli/lib/ui/routing-demo.js +79 -0
  91. package/lib/agent-cli/lib/ui/routing-ui.js +325 -0
  92. package/lib/agent-cli/lib/ui/settings-ui.js +381 -0
  93. package/lib/agent-cli/lib/ui/stats-ui.js +123 -0
  94. package/lib/agent-cli/lib/ui/watch-ui.js +236 -0
  95. package/lib/agent-cli/lib/watcher.js +181 -0
  96. package/lib/agent-cli/lib/watcher.test.js +85 -0
  97. package/lib/agent-cli/package.json +51 -0
  98. package/lib/agent-cli/scripts/adaptive_engine.js +381 -0
  99. package/lib/agent-cli/scripts/dashboard_server.js +224 -0
  100. package/lib/agent-cli/scripts/error_sensor.js +565 -0
  101. package/lib/agent-cli/scripts/learn_from_failure.js +225 -0
  102. package/lib/agent-cli/scripts/pattern_analyzer.js +781 -0
  103. package/lib/agent-cli/scripts/pre_execution_check.js +623 -0
  104. package/lib/agent-cli/scripts/rule_sharing.js +374 -0
  105. package/lib/agent-cli/scripts/skill_injector.js +387 -0
  106. package/lib/agent-cli/scripts/success_sensor.js +500 -0
  107. package/lib/agent-cli/scripts/user_correction_sensor.js +426 -0
  108. package/lib/agent-cli/services/auto-learn-service.js +247 -0
  109. package/lib/agent-cli/src/MIGRATION.md +418 -0
  110. package/lib/agent-cli/src/README.md +367 -0
  111. package/lib/agent-cli/src/core/evolution/evolution-signal.js +42 -0
  112. package/lib/agent-cli/src/core/evolution/index.js +17 -0
  113. package/lib/agent-cli/src/core/evolution/review-gate.js +40 -0
  114. package/lib/agent-cli/src/core/evolution/signal-detector.js +137 -0
  115. package/lib/agent-cli/src/core/evolution/signal-queue.js +79 -0
  116. package/lib/agent-cli/src/core/evolution/threshold-checker.js +79 -0
  117. package/lib/agent-cli/src/core/index.js +15 -0
  118. package/lib/agent-cli/src/core/learning/cognitive-enhancer.js +282 -0
  119. package/lib/agent-cli/src/core/learning/index.js +12 -0
  120. package/lib/agent-cli/src/core/learning/lesson-synthesizer.js +83 -0
  121. package/lib/agent-cli/src/core/scanning/index.js +14 -0
  122. package/lib/agent-cli/src/data/index.js +13 -0
  123. package/lib/agent-cli/src/data/repositories/index.js +8 -0
  124. package/lib/agent-cli/src/data/repositories/lesson-repository.js +130 -0
  125. package/lib/agent-cli/src/data/repositories/signal-repository.js +119 -0
  126. package/lib/agent-cli/src/data/storage/index.js +8 -0
  127. package/lib/agent-cli/src/data/storage/json-storage.js +64 -0
  128. package/lib/agent-cli/src/data/storage/yaml-storage.js +66 -0
  129. package/lib/agent-cli/src/infrastructure/index.js +13 -0
  130. package/lib/agent-cli/src/presentation/formatters/skill-formatter.js +232 -0
  131. package/lib/agent-cli/src/services/export-service.js +162 -0
  132. package/lib/agent-cli/src/services/index.js +13 -0
  133. package/lib/agent-cli/src/services/learning-service.js +99 -0
  134. package/lib/agent-cli/types/index.d.ts +343 -0
  135. package/lib/agent-cli/utils/benchmark.js +269 -0
  136. package/lib/agent-cli/utils/logger.js +303 -0
  137. package/lib/agent-cli/utils/ml_patterns.js +300 -0
  138. package/lib/agent-cli/utils/recovery.js +312 -0
  139. package/lib/agent-cli/utils/telemetry.js +290 -0
  140. package/lib/agentskillskit-cli/README.md +21 -0
  141. package/lib/agentskillskit-cli/ag-smart.js +158 -0
  142. package/lib/agentskillskit-cli/package.json +51 -0
  143. package/package.json +79 -0
  144. package/specs/ADD_SKILL_SPEC.md +333 -0
  145. package/specs/REGISTRY_V2_SPEC.md +334 -0
@@ -0,0 +1,312 @@
1
+ /**
2
+ * Self-healing Recovery Utility
3
+ *
4
+ * Provides checkpoint and rollback capabilities:
5
+ * - Save state before risky operations
6
+ * - Rollback on failure
7
+ * - Recovery logging
8
+ *
9
+ * Usage:
10
+ * import recovery from './recovery.js';
11
+ *
12
+ * const checkpoint = recovery.save('operation-name', currentState);
13
+ * try {
14
+ * // risky operation
15
+ * } catch (error) {
16
+ * recovery.rollback(checkpoint);
17
+ * }
18
+ */
19
+
20
+ import fs from 'fs';
21
+ import path from 'path';
22
+ import { fileURLToPath } from 'url';
23
+
24
+ const __filename = fileURLToPath(import.meta.url);
25
+ const __dirname = path.dirname(__filename);
26
+
27
+ // ==================== STORAGE ====================
28
+
29
+ const checkpoints = new Map();
30
+ const history = [];
31
+ const MAX_CHECKPOINTS = 10;
32
+
33
+ // ==================== COLORS ====================
34
+
35
+ const c = {
36
+ reset: '\x1b[0m',
37
+ red: '\x1b[31m',
38
+ green: '\x1b[32m',
39
+ yellow: '\x1b[33m',
40
+ cyan: '\x1b[36m',
41
+ gray: '\x1b[90m'
42
+ };
43
+
44
+ // ==================== CHECKPOINT ====================
45
+
46
+ /**
47
+ * Generate checkpoint ID
48
+ */
49
+ function generateId() {
50
+ return `CP-${Date.now()}-${Math.random().toString(36).substr(2, 6)}`;
51
+ }
52
+
53
+ /**
54
+ * Save a state checkpoint
55
+ * @param {string} operation - Operation name
56
+ * @param {any} state - State to save (will be deep cloned)
57
+ * @param {object} options - Options
58
+ * @returns {object} Checkpoint reference
59
+ */
60
+ function save(operation, state, options = {}) {
61
+ const id = generateId();
62
+ const checkpoint = {
63
+ id,
64
+ operation,
65
+ state: JSON.parse(JSON.stringify(state)), // Deep clone
66
+ timestamp: new Date().toISOString(),
67
+ options
68
+ };
69
+
70
+ checkpoints.set(id, checkpoint);
71
+ history.push({ type: 'save', id, operation, timestamp: checkpoint.timestamp });
72
+
73
+ // Cleanup old checkpoints
74
+ if (checkpoints.size > MAX_CHECKPOINTS) {
75
+ const oldest = [...checkpoints.keys()][0];
76
+ checkpoints.delete(oldest);
77
+ }
78
+
79
+ console.log(`${c.gray}šŸ’¾ Checkpoint saved: ${operation} (${id})${c.reset}`);
80
+
81
+ return checkpoint;
82
+ }
83
+
84
+ /**
85
+ * Rollback to a checkpoint
86
+ * @param {object|string} checkpoint - Checkpoint reference or ID
87
+ * @returns {any} Restored state
88
+ */
89
+ function rollback(checkpoint) {
90
+ const id = typeof checkpoint === 'string' ? checkpoint : checkpoint.id;
91
+ const saved = checkpoints.get(id);
92
+
93
+ if (!saved) {
94
+ console.error(`${c.red}āŒ Checkpoint not found: ${id}${c.reset}`);
95
+ return null;
96
+ }
97
+
98
+ history.push({
99
+ type: 'rollback',
100
+ id,
101
+ operation: saved.operation,
102
+ timestamp: new Date().toISOString()
103
+ });
104
+
105
+ console.log(`${c.yellow}āŖ Rolling back: ${saved.operation}${c.reset}`);
106
+
107
+ return saved.state;
108
+ }
109
+
110
+ /**
111
+ * Get a checkpoint by ID
112
+ * @param {string} id - Checkpoint ID
113
+ */
114
+ function get(id) {
115
+ return checkpoints.get(id);
116
+ }
117
+
118
+ /**
119
+ * List all checkpoints
120
+ */
121
+ function list() {
122
+ return [...checkpoints.values()].map(cp => ({
123
+ id: cp.id,
124
+ operation: cp.operation,
125
+ timestamp: cp.timestamp
126
+ }));
127
+ }
128
+
129
+ // ==================== FILE RECOVERY ====================
130
+
131
+ /**
132
+ * Backup a file before modification
133
+ * @param {string} filePath - File to backup
134
+ * @returns {object} Backup reference
135
+ */
136
+ function backupFile(filePath) {
137
+ if (!fs.existsSync(filePath)) {
138
+ return { id: null, exists: false, path: filePath };
139
+ }
140
+
141
+ const content = fs.readFileSync(filePath, 'utf8');
142
+ const backup = save(`file:${path.basename(filePath)}`, {
143
+ path: filePath,
144
+ content,
145
+ exists: true
146
+ });
147
+
148
+ return backup;
149
+ }
150
+
151
+ /**
152
+ * Restore a file from backup
153
+ * @param {object|string} backup - Backup reference
154
+ */
155
+ function restoreFile(backup) {
156
+ const state = rollback(backup);
157
+
158
+ if (!state) {
159
+ return false;
160
+ }
161
+
162
+ if (state.exists) {
163
+ fs.writeFileSync(state.path, state.content, 'utf8');
164
+ console.log(`${c.green}āœ“ Restored: ${state.path}${c.reset}`);
165
+ } else {
166
+ // File didn't exist, delete if created
167
+ if (fs.existsSync(state.path)) {
168
+ fs.unlinkSync(state.path);
169
+ console.log(`${c.green}āœ“ Removed: ${state.path}${c.reset}`);
170
+ }
171
+ }
172
+
173
+ return true;
174
+ }
175
+
176
+ // ==================== TRANSACTION ====================
177
+
178
+ /**
179
+ * Execute operation with automatic rollback on failure
180
+ * @param {string} name - Operation name
181
+ * @param {any} state - State to checkpoint
182
+ * @param {Function} operation - Operation to execute
183
+ * @returns {Promise<{success: boolean, result?: any, error?: Error}>}
184
+ */
185
+ async function withRecovery(name, state, operation) {
186
+ const checkpoint = save(name, state);
187
+
188
+ try {
189
+ const result = await operation();
190
+
191
+ history.push({
192
+ type: 'success',
193
+ id: checkpoint.id,
194
+ operation: name,
195
+ timestamp: new Date().toISOString()
196
+ });
197
+
198
+ console.log(`${c.green}āœ“ ${name} completed successfully${c.reset}`);
199
+
200
+ return { success: true, result };
201
+ } catch (error) {
202
+ const restored = rollback(checkpoint);
203
+
204
+ history.push({
205
+ type: 'failure',
206
+ id: checkpoint.id,
207
+ operation: name,
208
+ error: error.message,
209
+ timestamp: new Date().toISOString()
210
+ });
211
+
212
+ console.error(`${c.red}āŒ ${name} failed, rolled back${c.reset}`);
213
+ console.error(`${c.gray} Error: ${error.message}${c.reset}`);
214
+
215
+ return { success: false, error, restored };
216
+ }
217
+ }
218
+
219
+ // ==================== HISTORY ====================
220
+
221
+ /**
222
+ * Get recovery history
223
+ */
224
+ function getHistory() {
225
+ return [...history];
226
+ }
227
+
228
+ /**
229
+ * Get statistics
230
+ */
231
+ function getStats() {
232
+ const stats = {
233
+ totalCheckpoints: checkpoints.size,
234
+ totalOperations: history.length,
235
+ saves: history.filter(h => h.type === 'save').length,
236
+ rollbacks: history.filter(h => h.type === 'rollback').length,
237
+ successes: history.filter(h => h.type === 'success').length,
238
+ failures: history.filter(h => h.type === 'failure').length
239
+ };
240
+
241
+ stats.successRate = stats.successes + stats.failures > 0
242
+ ? (stats.successes / (stats.successes + stats.failures) * 100).toFixed(1) + '%'
243
+ : 'N/A';
244
+
245
+ return stats;
246
+ }
247
+
248
+ /**
249
+ * Print history summary
250
+ */
251
+ function printHistory() {
252
+ console.log(`\n${c.cyan}═══ Recovery History ═══${c.reset}\n`);
253
+
254
+ if (history.length === 0) {
255
+ console.log(`${c.gray}No recovery operations yet.${c.reset}`);
256
+ return;
257
+ }
258
+
259
+ for (const entry of history.slice(-10)) {
260
+ const icon = {
261
+ save: 'šŸ’¾',
262
+ rollback: 'āŖ',
263
+ success: 'āœ…',
264
+ failure: 'āŒ'
265
+ }[entry.type];
266
+
267
+ console.log(`${icon} ${entry.operation} (${entry.type})`);
268
+ }
269
+
270
+ const stats = getStats();
271
+ console.log(`\n${c.gray}Stats: ${stats.successes} success, ${stats.failures} failures (${stats.successRate})${c.reset}`);
272
+ }
273
+
274
+ /**
275
+ * Clear all checkpoints and history
276
+ */
277
+ function clear() {
278
+ checkpoints.clear();
279
+ history.length = 0;
280
+ }
281
+
282
+ // ==================== EXPORTS ====================
283
+
284
+ const recovery = {
285
+ save,
286
+ rollback,
287
+ get,
288
+ list,
289
+ backupFile,
290
+ restoreFile,
291
+ withRecovery,
292
+ getHistory,
293
+ getStats,
294
+ printHistory,
295
+ clear
296
+ };
297
+
298
+ export {
299
+ save,
300
+ rollback,
301
+ get,
302
+ list,
303
+ backupFile,
304
+ restoreFile,
305
+ withRecovery,
306
+ getHistory,
307
+ getStats,
308
+ printHistory,
309
+ clear
310
+ };
311
+
312
+ export default recovery;
@@ -0,0 +1,290 @@
1
+ /**
2
+ * Telemetry Utility - Local Metrics Collection
3
+ *
4
+ * Provides opt-in anonymous metrics collection:
5
+ * - Local storage only (no external transmission)
6
+ * - Error frequency tracking
7
+ * - Usage patterns
8
+ * - Performance metrics
9
+ *
10
+ * Usage:
11
+ * import telemetry from './telemetry.js';
12
+ * telemetry.track('error_detected', { type: 'test' });
13
+ * telemetry.report();
14
+ */
15
+
16
+ import fs from 'fs';
17
+ import path from 'path';
18
+ import { fileURLToPath } from 'url';
19
+
20
+ const __filename = fileURLToPath(import.meta.url);
21
+ const __dirname = path.dirname(__filename);
22
+
23
+ // ==================== CONFIGURATION ====================
24
+
25
+ const config = {
26
+ enabled: true, // Master switch
27
+ storeLocally: true, // Store to file
28
+ maxEvents: 1000, // Max events to keep
29
+ maxAge: 30 * 24 * 60 * 60 * 1000, // 30 days
30
+ storagePath: null // Will be set dynamically
31
+ };
32
+
33
+ // ==================== STORAGE ====================
34
+
35
+ const events = [];
36
+ const counters = new Map();
37
+ const gauges = new Map();
38
+
39
+ // ==================== HELPERS ====================
40
+
41
+ /**
42
+ * Get storage path
43
+ */
44
+ function getStoragePath() {
45
+ if (config.storagePath) return config.storagePath;
46
+
47
+ // Try to find project root
48
+ let dir = process.cwd();
49
+ while (dir !== path.dirname(dir)) {
50
+ if (fs.existsSync(path.join(dir, 'package.json'))) {
51
+ return path.join(dir, '.agent', 'knowledge', 'telemetry.json');
52
+ }
53
+ dir = path.dirname(dir);
54
+ }
55
+
56
+ return path.join(process.cwd(), '.agent', 'knowledge', 'telemetry.json');
57
+ }
58
+
59
+ /**
60
+ * Load existing telemetry data
61
+ */
62
+ function load() {
63
+ const storagePath = getStoragePath();
64
+ if (!fs.existsSync(storagePath)) return;
65
+
66
+ try {
67
+ const data = JSON.parse(fs.readFileSync(storagePath, 'utf8'));
68
+ if (data.events) events.push(...data.events);
69
+ if (data.counters) {
70
+ for (const [k, v] of Object.entries(data.counters)) {
71
+ counters.set(k, v);
72
+ }
73
+ }
74
+ } catch (e) {
75
+ // Ignore parse errors
76
+ }
77
+ }
78
+
79
+ /**
80
+ * Save telemetry data
81
+ */
82
+ function save() {
83
+ if (!config.storeLocally) return;
84
+
85
+ const storagePath = getStoragePath();
86
+ const dir = path.dirname(storagePath);
87
+
88
+ if (!fs.existsSync(dir)) {
89
+ fs.mkdirSync(dir, { recursive: true });
90
+ }
91
+
92
+ const data = {
93
+ events: events.slice(-config.maxEvents),
94
+ counters: Object.fromEntries(counters),
95
+ gauges: Object.fromEntries(gauges),
96
+ savedAt: new Date().toISOString()
97
+ };
98
+
99
+ fs.writeFileSync(storagePath, JSON.stringify(data, null, 2));
100
+ }
101
+
102
+ // ==================== TRACKING ====================
103
+
104
+ /**
105
+ * Track an event
106
+ * @param {string} name - Event name
107
+ * @param {object} properties - Event properties
108
+ */
109
+ function track(name, properties = {}) {
110
+ if (!config.enabled) return;
111
+
112
+ const event = {
113
+ name,
114
+ properties,
115
+ timestamp: new Date().toISOString()
116
+ };
117
+
118
+ events.push(event);
119
+
120
+ // Increment counter
121
+ increment(name);
122
+
123
+ // Cleanup old events
124
+ if (events.length > config.maxEvents) {
125
+ events.splice(0, events.length - config.maxEvents);
126
+ }
127
+ }
128
+
129
+ /**
130
+ * Increment a counter
131
+ * @param {string} name - Counter name
132
+ * @param {number} value - Value to add (default: 1)
133
+ */
134
+ function increment(name, value = 1) {
135
+ if (!config.enabled) return;
136
+ counters.set(name, (counters.get(name) || 0) + value);
137
+ }
138
+
139
+ /**
140
+ * Set a gauge value
141
+ * @param {string} name - Gauge name
142
+ * @param {number} value - Value to set
143
+ */
144
+ function gauge(name, value) {
145
+ if (!config.enabled) return;
146
+ gauges.set(name, value);
147
+ }
148
+
149
+ // ==================== TIMING ====================
150
+
151
+ /**
152
+ * Time an operation
153
+ * @param {string} name - Operation name
154
+ */
155
+ function startTimer(name) {
156
+ const start = Date.now();
157
+ return {
158
+ end: () => {
159
+ const duration = Date.now() - start;
160
+ track(`${name}_duration`, { duration });
161
+ return duration;
162
+ }
163
+ };
164
+ }
165
+
166
+ // ==================== REPORTING ====================
167
+
168
+ /**
169
+ * Get summary statistics
170
+ */
171
+ function getSummary() {
172
+ const now = Date.now();
173
+ const cutoff = now - 24 * 60 * 60 * 1000; // Last 24 hours
174
+
175
+ const recentEvents = events.filter(e =>
176
+ new Date(e.timestamp).getTime() > cutoff
177
+ );
178
+
179
+ const byName = {};
180
+ for (const event of recentEvents) {
181
+ byName[event.name] = (byName[event.name] || 0) + 1;
182
+ }
183
+
184
+ return {
185
+ totalEvents: events.length,
186
+ last24h: recentEvents.length,
187
+ counters: Object.fromEntries(counters),
188
+ gauges: Object.fromEntries(gauges),
189
+ byEvent: byName
190
+ };
191
+ }
192
+
193
+ /**
194
+ * Print telemetry report
195
+ */
196
+ function report() {
197
+ const summary = getSummary();
198
+
199
+ console.log('\nšŸ“Š Telemetry Report');
200
+ console.log('═══════════════════\n');
201
+
202
+ console.log(`Total Events: ${summary.totalEvents}`);
203
+ console.log(`Last 24h: ${summary.last24h}`);
204
+
205
+ if (Object.keys(summary.counters).length > 0) {
206
+ console.log('\nCounters:');
207
+ for (const [name, count] of Object.entries(summary.counters)) {
208
+ console.log(` ${name}: ${count}`);
209
+ }
210
+ }
211
+
212
+ if (Object.keys(summary.byEvent).length > 0) {
213
+ console.log('\nRecent Events (24h):');
214
+ const sorted = Object.entries(summary.byEvent)
215
+ .sort((a, b) => b[1] - a[1])
216
+ .slice(0, 10);
217
+
218
+ for (const [name, count] of sorted) {
219
+ console.log(` ${name}: ${count}`);
220
+ }
221
+ }
222
+ }
223
+
224
+ // ==================== CONFIGURATION ====================
225
+
226
+ /**
227
+ * Enable telemetry
228
+ */
229
+ function enable() {
230
+ config.enabled = true;
231
+ }
232
+
233
+ /**
234
+ * Disable telemetry
235
+ */
236
+ function disable() {
237
+ config.enabled = false;
238
+ }
239
+
240
+ /**
241
+ * Check if enabled
242
+ */
243
+ function isEnabled() {
244
+ return config.enabled;
245
+ }
246
+
247
+ /**
248
+ * Clear all telemetry data
249
+ */
250
+ function clear() {
251
+ events.length = 0;
252
+ counters.clear();
253
+ gauges.clear();
254
+ }
255
+
256
+ // ==================== EXPORTS ====================
257
+
258
+ const telemetry = {
259
+ track,
260
+ increment,
261
+ gauge,
262
+ startTimer,
263
+ getSummary,
264
+ report,
265
+ enable,
266
+ disable,
267
+ isEnabled,
268
+ clear,
269
+ save,
270
+ load,
271
+ config
272
+ };
273
+
274
+ export {
275
+ track,
276
+ increment,
277
+ gauge,
278
+ startTimer,
279
+ getSummary,
280
+ report,
281
+ enable,
282
+ disable,
283
+ isEnabled,
284
+ clear,
285
+ save,
286
+ load,
287
+ config
288
+ };
289
+
290
+ export default telemetry;
@@ -0,0 +1,21 @@
1
+ # Agent Skill Kit CLI
2
+
3
+ The intelligent CLI engine for Agent Skill Kit, featuring:
4
+ - **Routing Engine**: Semantic routing validation
5
+ - **Audit System**: Skill usage auditing and metrics
6
+ - **Interactive Mode**: Smart interactive agent interface
7
+
8
+ ## Installation
9
+
10
+ This package is typically managed by the `add-skill-kit` installer.
11
+
12
+ ```bash
13
+ # Global install (managed by installer)
14
+ npm install -g @agentskillskit/cli
15
+
16
+ # Usage
17
+ agent
18
+ ```
19
+
20
+ ## Documentation
21
+ See the main [Agent Skill Kit](https://github.com/agentskillskit/agent-skills) repository.