claude-flow-novice 1.5.12 → 1.5.14
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.
- package/.claude/agents/analysis/code-review/analyze-code-quality.md +160 -177
- package/.claude/agents/architecture/system-design/arch-system-design.md +118 -153
- package/.claude-flow-novice/dist/mcp/auth.js +347 -0
- package/.claude-flow-novice/dist/mcp/claude-code-wrapper.js +717 -0
- package/.claude-flow-novice/dist/mcp/claude-flow-tools.js +1365 -0
- package/.claude-flow-novice/dist/mcp/client.js +201 -0
- package/.claude-flow-novice/dist/mcp/index.js +192 -0
- package/.claude-flow-novice/dist/mcp/integrate-wrapper.js +85 -0
- package/.claude-flow-novice/dist/mcp/lifecycle-manager.js +348 -0
- package/.claude-flow-novice/dist/mcp/load-balancer.js +386 -0
- package/.claude-flow-novice/dist/mcp/mcp-config-manager.js +1362 -0
- package/.claude-flow-novice/dist/mcp/mcp-server-novice-simplified.js +583 -0
- package/.claude-flow-novice/dist/mcp/mcp-server-novice.js +723 -0
- package/.claude-flow-novice/dist/mcp/mcp-server-sdk.js +649 -0
- package/.claude-flow-novice/dist/mcp/mcp-server.js +2256 -0
- package/.claude-flow-novice/dist/mcp/orchestration-integration.js +800 -0
- package/.claude-flow-novice/dist/mcp/performance-monitor.js +489 -0
- package/.claude-flow-novice/dist/mcp/protocol-manager.js +376 -0
- package/.claude-flow-novice/dist/mcp/router.js +220 -0
- package/.claude-flow-novice/dist/mcp/ruv-swarm-tools.js +671 -0
- package/.claude-flow-novice/dist/mcp/ruv-swarm-wrapper.js +254 -0
- package/.claude-flow-novice/dist/mcp/server-with-wrapper.js +32 -0
- package/.claude-flow-novice/dist/mcp/server-wrapper-mode.js +26 -0
- package/.claude-flow-novice/dist/mcp/server.js +539 -0
- package/.claude-flow-novice/dist/mcp/session-manager.js +338 -0
- package/.claude-flow-novice/dist/mcp/sparc-modes.js +455 -0
- package/.claude-flow-novice/dist/mcp/swarm-tools.js +903 -0
- package/.claude-flow-novice/dist/mcp/tools.js +426 -0
- package/.claude-flow-novice/dist/src/cli/commands/swarm.js +23 -1
- package/.claude-flow-novice/dist/src/cli/commands/swarm.js.map +1 -1
- package/.claude-flow-novice/dist/src/cli/simple-commands/init/templates/CLAUDE.md +42 -102
- package/.claude-flow-novice/dist/src/config/web-portal-config.js +2 -1
- package/.claude-flow-novice/dist/src/config/web-portal-config.js.map +1 -1
- package/.claude-flow-novice/dist/src/coordination/swarm-coordinator-factory.js +36 -0
- package/.claude-flow-novice/dist/src/coordination/swarm-coordinator-factory.js.map +1 -0
- package/.claude-flow-novice/dist/src/preferences/user-preference-manager.js +371 -0
- package/.claude-flow-novice/dist/src/preferences/user-preference-manager.js.map +1 -0
- package/.claude-flow-novice/dist/src/validators/index.js +12 -0
- package/.claude-flow-novice/dist/src/validators/index.js.map +1 -0
- package/.claude-flow-novice/dist/src/validators/swarm-init-validator.js +261 -0
- package/.claude-flow-novice/dist/src/validators/swarm-init-validator.js.map +1 -0
- package/.claude-flow-novice/dist/src/validators/todowrite-batching-validator.js +204 -0
- package/.claude-flow-novice/dist/src/validators/todowrite-batching-validator.js.map +1 -0
- package/.claude-flow-novice/dist/src/validators/todowrite-integration.js +189 -0
- package/.claude-flow-novice/dist/src/validators/todowrite-integration.js.map +1 -0
- package/.claude-flow-novice/dist/src/web/portal-server.js +12 -5
- package/.claude-flow-novice/dist/src/web/portal-server.js.map +1 -1
- package/config/hooks/post-edit-pipeline.js +231 -10
- package/package.json +4 -2
- package/scripts/src/web/frontend/.claude-flow/metrics/agent-metrics.json +1 -0
- package/scripts/src/web/frontend/.claude-flow/metrics/performance.json +9 -0
- package/scripts/src/web/frontend/.claude-flow/metrics/task-metrics.json +10 -0
- package/src/cli/simple-commands/init/templates/CLAUDE.md +4 -1
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User Preference Storage Manager
|
|
3
|
+
*
|
|
4
|
+
* A simple preference manager for storing user-specific settings.
|
|
5
|
+
* Follows the architecture patterns from config-manager.ts
|
|
6
|
+
*
|
|
7
|
+
* @module UserPreferenceManager
|
|
8
|
+
*/ import { promises as fs } from "fs";
|
|
9
|
+
import path from "path";
|
|
10
|
+
import os from "os";
|
|
11
|
+
import { EventEmitter } from "events";
|
|
12
|
+
/**
|
|
13
|
+
* Custom error for preference operations
|
|
14
|
+
*/ export class PreferenceError extends Error {
|
|
15
|
+
constructor(message){
|
|
16
|
+
super(message);
|
|
17
|
+
this.name = "PreferenceError";
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Default preferences for new installations
|
|
22
|
+
*/ const DEFAULT_PREFERENCES = {
|
|
23
|
+
theme: "light",
|
|
24
|
+
language: "en",
|
|
25
|
+
notifications: true,
|
|
26
|
+
autoSave: true,
|
|
27
|
+
maxHistoryItems: 50
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* User Preference Manager
|
|
31
|
+
*
|
|
32
|
+
* Manages user-specific preferences with automatic persistence,
|
|
33
|
+
* error handling, and type safety.
|
|
34
|
+
*/ export class UserPreferenceManager extends EventEmitter {
|
|
35
|
+
preferences;
|
|
36
|
+
storagePath;
|
|
37
|
+
autoSave;
|
|
38
|
+
cacheEnabled;
|
|
39
|
+
isInitialized;
|
|
40
|
+
/**
|
|
41
|
+
* Creates a new UserPreferenceManager instance
|
|
42
|
+
*
|
|
43
|
+
* @param options - Configuration options for the preference manager
|
|
44
|
+
*/ constructor(options = {}){
|
|
45
|
+
super();
|
|
46
|
+
this.preferences = new Map();
|
|
47
|
+
this.storagePath = options.storagePath || path.join(os.homedir(), ".claude-flow", "user-preferences.json");
|
|
48
|
+
this.autoSave = options.autoSave ?? true;
|
|
49
|
+
this.cacheEnabled = options.cacheEnabled ?? true;
|
|
50
|
+
this.isInitialized = false;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Initializes the preference manager and loads existing preferences
|
|
54
|
+
*
|
|
55
|
+
* @returns Promise that resolves when initialization is complete
|
|
56
|
+
* @throws {PreferenceError} If initialization fails
|
|
57
|
+
*/ async initialize() {
|
|
58
|
+
try {
|
|
59
|
+
// Ensure storage directory exists
|
|
60
|
+
const dir = path.dirname(this.storagePath);
|
|
61
|
+
await fs.mkdir(dir, {
|
|
62
|
+
recursive: true
|
|
63
|
+
});
|
|
64
|
+
// Load existing preferences or create defaults
|
|
65
|
+
try {
|
|
66
|
+
await this.load();
|
|
67
|
+
} catch (error) {
|
|
68
|
+
// No existing preferences file, load defaults
|
|
69
|
+
await this.loadDefaults();
|
|
70
|
+
if (this.autoSave) {
|
|
71
|
+
await this.save();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
this.isInitialized = true;
|
|
75
|
+
this.emit("initialized", {
|
|
76
|
+
timestamp: new Date()
|
|
77
|
+
});
|
|
78
|
+
} catch (error) {
|
|
79
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
80
|
+
throw new PreferenceError(`Failed to initialize preference manager: ${errorMessage}`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Retrieves a preference value by key
|
|
85
|
+
*
|
|
86
|
+
* @param key - The preference key to retrieve
|
|
87
|
+
* @param defaultValue - Optional default value if preference doesn't exist
|
|
88
|
+
* @returns The preference value or defaultValue if not found
|
|
89
|
+
* @throws {PreferenceError} If manager is not initialized
|
|
90
|
+
*/ getPreference(key, defaultValue) {
|
|
91
|
+
this.ensureInitialized();
|
|
92
|
+
try {
|
|
93
|
+
const preference = this.preferences.get(key);
|
|
94
|
+
if (!preference) {
|
|
95
|
+
this.emit("preferenceNotFound", {
|
|
96
|
+
key,
|
|
97
|
+
timestamp: new Date()
|
|
98
|
+
});
|
|
99
|
+
return defaultValue;
|
|
100
|
+
}
|
|
101
|
+
this.emit("preferenceRetrieved", {
|
|
102
|
+
key,
|
|
103
|
+
type: preference.type,
|
|
104
|
+
timestamp: new Date()
|
|
105
|
+
});
|
|
106
|
+
return preference.value;
|
|
107
|
+
} catch (error) {
|
|
108
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
109
|
+
throw new PreferenceError(`Failed to get preference '${key}': ${errorMessage}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Sets a preference value
|
|
114
|
+
*
|
|
115
|
+
* @param key - The preference key to set
|
|
116
|
+
* @param value - The value to store
|
|
117
|
+
* @returns Promise that resolves when preference is set (and saved if autoSave is enabled)
|
|
118
|
+
* @throws {PreferenceError} If manager is not initialized or value is invalid
|
|
119
|
+
*/ async setPreference(key, value) {
|
|
120
|
+
this.ensureInitialized();
|
|
121
|
+
try {
|
|
122
|
+
// Validate input
|
|
123
|
+
if (!key || typeof key !== "string") {
|
|
124
|
+
throw new PreferenceError("Preference key must be a non-empty string");
|
|
125
|
+
}
|
|
126
|
+
if (value === undefined) {
|
|
127
|
+
throw new PreferenceError("Preference value cannot be undefined");
|
|
128
|
+
}
|
|
129
|
+
// Determine value type
|
|
130
|
+
const valueType = this.determineType(value);
|
|
131
|
+
// Create preference object
|
|
132
|
+
const preference = {
|
|
133
|
+
key,
|
|
134
|
+
value,
|
|
135
|
+
type: valueType,
|
|
136
|
+
timestamp: Date.now()
|
|
137
|
+
};
|
|
138
|
+
// Store in map
|
|
139
|
+
const oldValue = this.preferences.get(key);
|
|
140
|
+
this.preferences.set(key, preference);
|
|
141
|
+
// Emit change event
|
|
142
|
+
this.emit("preferenceChanged", {
|
|
143
|
+
key,
|
|
144
|
+
oldValue: oldValue?.value,
|
|
145
|
+
newValue: value,
|
|
146
|
+
timestamp: new Date()
|
|
147
|
+
});
|
|
148
|
+
// Auto-save if enabled
|
|
149
|
+
if (this.autoSave) {
|
|
150
|
+
await this.save();
|
|
151
|
+
}
|
|
152
|
+
} catch (error) {
|
|
153
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
154
|
+
throw new PreferenceError(`Failed to set preference '${key}': ${errorMessage}`);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Removes a preference by key
|
|
159
|
+
*
|
|
160
|
+
* @param key - The preference key to remove
|
|
161
|
+
* @returns Promise that resolves when preference is removed
|
|
162
|
+
* @throws {PreferenceError} If manager is not initialized
|
|
163
|
+
*/ async removePreference(key) {
|
|
164
|
+
this.ensureInitialized();
|
|
165
|
+
try {
|
|
166
|
+
const existed = this.preferences.has(key);
|
|
167
|
+
if (existed) {
|
|
168
|
+
const preference = this.preferences.get(key);
|
|
169
|
+
this.preferences.delete(key);
|
|
170
|
+
this.emit("preferenceRemoved", {
|
|
171
|
+
key,
|
|
172
|
+
value: preference?.value,
|
|
173
|
+
timestamp: new Date()
|
|
174
|
+
});
|
|
175
|
+
if (this.autoSave) {
|
|
176
|
+
await this.save();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return existed;
|
|
180
|
+
} catch (error) {
|
|
181
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
182
|
+
throw new PreferenceError(`Failed to remove preference '${key}': ${errorMessage}`);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Loads default preferences
|
|
187
|
+
*
|
|
188
|
+
* @returns Promise that resolves when defaults are loaded
|
|
189
|
+
* @throws {PreferenceError} If loading defaults fails
|
|
190
|
+
*/ async loadDefaults() {
|
|
191
|
+
try {
|
|
192
|
+
this.preferences.clear();
|
|
193
|
+
for (const [key, value] of Object.entries(DEFAULT_PREFERENCES)){
|
|
194
|
+
const preference = {
|
|
195
|
+
key,
|
|
196
|
+
value,
|
|
197
|
+
type: this.determineType(value),
|
|
198
|
+
timestamp: Date.now()
|
|
199
|
+
};
|
|
200
|
+
this.preferences.set(key, preference);
|
|
201
|
+
}
|
|
202
|
+
this.emit("defaultsLoaded", {
|
|
203
|
+
count: this.preferences.size,
|
|
204
|
+
timestamp: new Date()
|
|
205
|
+
});
|
|
206
|
+
} catch (error) {
|
|
207
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
208
|
+
throw new PreferenceError(`Failed to load defaults: ${errorMessage}`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Saves preferences to storage
|
|
213
|
+
*
|
|
214
|
+
* @returns Promise that resolves when save is complete
|
|
215
|
+
* @throws {PreferenceError} If save operation fails
|
|
216
|
+
*/ async save() {
|
|
217
|
+
try {
|
|
218
|
+
// Convert Map to serializable object
|
|
219
|
+
const data = {};
|
|
220
|
+
for (const [key, preference] of this.preferences.entries()){
|
|
221
|
+
data[key] = preference;
|
|
222
|
+
}
|
|
223
|
+
// Write to file
|
|
224
|
+
const content = JSON.stringify(data, null, 2);
|
|
225
|
+
await fs.writeFile(this.storagePath, content, "utf8");
|
|
226
|
+
this.emit("preferencesSaved", {
|
|
227
|
+
count: this.preferences.size,
|
|
228
|
+
path: this.storagePath,
|
|
229
|
+
timestamp: new Date()
|
|
230
|
+
});
|
|
231
|
+
} catch (error) {
|
|
232
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
233
|
+
throw new PreferenceError(`Failed to save preferences: ${errorMessage}`);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Loads preferences from storage
|
|
238
|
+
*
|
|
239
|
+
* @returns Promise that resolves when load is complete
|
|
240
|
+
* @throws {PreferenceError} If load operation fails
|
|
241
|
+
*/ async load() {
|
|
242
|
+
try {
|
|
243
|
+
const content = await fs.readFile(this.storagePath, "utf8");
|
|
244
|
+
const data = JSON.parse(content);
|
|
245
|
+
this.preferences.clear();
|
|
246
|
+
for (const [key, preference] of Object.entries(data)){
|
|
247
|
+
// Validate loaded preference structure
|
|
248
|
+
if (this.isValidPreference(preference)) {
|
|
249
|
+
this.preferences.set(key, preference);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
this.emit("preferencesLoaded", {
|
|
253
|
+
count: this.preferences.size,
|
|
254
|
+
path: this.storagePath,
|
|
255
|
+
timestamp: new Date()
|
|
256
|
+
});
|
|
257
|
+
} catch (error) {
|
|
258
|
+
if (error.code === "ENOENT") {
|
|
259
|
+
throw new PreferenceError(`Preferences file not found: ${this.storagePath}`);
|
|
260
|
+
}
|
|
261
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
262
|
+
throw new PreferenceError(`Failed to load preferences: ${errorMessage}`);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Gets all preferences as a plain object
|
|
267
|
+
*
|
|
268
|
+
* @returns Object containing all preferences
|
|
269
|
+
*/ getAllPreferences() {
|
|
270
|
+
this.ensureInitialized();
|
|
271
|
+
const result = {};
|
|
272
|
+
for (const [key, preference] of this.preferences.entries()){
|
|
273
|
+
result[key] = preference.value;
|
|
274
|
+
}
|
|
275
|
+
return result;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Resets all preferences to defaults
|
|
279
|
+
*
|
|
280
|
+
* @returns Promise that resolves when reset is complete
|
|
281
|
+
*/ async reset() {
|
|
282
|
+
this.ensureInitialized();
|
|
283
|
+
await this.loadDefaults();
|
|
284
|
+
if (this.autoSave) {
|
|
285
|
+
await this.save();
|
|
286
|
+
}
|
|
287
|
+
this.emit("preferencesReset", {
|
|
288
|
+
timestamp: new Date()
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Checks if a preference exists
|
|
293
|
+
*
|
|
294
|
+
* @param key - The preference key to check
|
|
295
|
+
* @returns True if preference exists, false otherwise
|
|
296
|
+
*/ hasPreference(key) {
|
|
297
|
+
this.ensureInitialized();
|
|
298
|
+
return this.preferences.has(key);
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Gets the storage path
|
|
302
|
+
*
|
|
303
|
+
* @returns The current storage path
|
|
304
|
+
*/ getStoragePath() {
|
|
305
|
+
return this.storagePath;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Gets preference count
|
|
309
|
+
*
|
|
310
|
+
* @returns Number of stored preferences
|
|
311
|
+
*/ getPreferenceCount() {
|
|
312
|
+
return this.preferences.size;
|
|
313
|
+
}
|
|
314
|
+
// Private helper methods
|
|
315
|
+
/**
|
|
316
|
+
* Ensures the manager is initialized before operations
|
|
317
|
+
*
|
|
318
|
+
* @throws {PreferenceError} If not initialized
|
|
319
|
+
*/ ensureInitialized() {
|
|
320
|
+
if (!this.isInitialized) {
|
|
321
|
+
throw new PreferenceError("PreferenceManager not initialized. Call initialize() first.");
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Determines the type of a value
|
|
326
|
+
*
|
|
327
|
+
* @param value - Value to check
|
|
328
|
+
* @returns Type string
|
|
329
|
+
*/ determineType(value) {
|
|
330
|
+
if (typeof value === "string") return "string";
|
|
331
|
+
if (typeof value === "number") return "number";
|
|
332
|
+
if (typeof value === "boolean") return "boolean";
|
|
333
|
+
return "object";
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Validates a preference object structure
|
|
337
|
+
*
|
|
338
|
+
* @param preference - Preference to validate
|
|
339
|
+
* @returns True if valid, false otherwise
|
|
340
|
+
*/ isValidPreference(preference) {
|
|
341
|
+
return preference && typeof preference === "object" && typeof preference.key === "string" && preference.value !== undefined && [
|
|
342
|
+
"string",
|
|
343
|
+
"number",
|
|
344
|
+
"boolean",
|
|
345
|
+
"object"
|
|
346
|
+
].includes(preference.type) && typeof preference.timestamp === "number";
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Export singleton instance factory
|
|
351
|
+
*/ let defaultInstance = null;
|
|
352
|
+
/**
|
|
353
|
+
* Gets the default preference manager instance
|
|
354
|
+
*
|
|
355
|
+
* @returns Singleton instance of UserPreferenceManager
|
|
356
|
+
*/ export function getDefaultPreferenceManager() {
|
|
357
|
+
if (!defaultInstance) {
|
|
358
|
+
defaultInstance = new UserPreferenceManager();
|
|
359
|
+
}
|
|
360
|
+
return defaultInstance;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Creates a new preference manager instance
|
|
364
|
+
*
|
|
365
|
+
* @param options - Configuration options
|
|
366
|
+
* @returns New UserPreferenceManager instance
|
|
367
|
+
*/ export function createPreferenceManager(options) {
|
|
368
|
+
return new UserPreferenceManager(options);
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
//# sourceMappingURL=user-preference-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/preferences/user-preference-manager.ts"],"names":["promises","fs","path","os","EventEmitter","PreferenceError","Error","message","name","DEFAULT_PREFERENCES","theme","language","notifications","autoSave","maxHistoryItems","UserPreferenceManager","preferences","storagePath","cacheEnabled","isInitialized","options","Map","join","homedir","initialize","dir","dirname","mkdir","recursive","load","error","loadDefaults","save","emit","timestamp","Date","errorMessage","getPreference","key","defaultValue","ensureInitialized","preference","get","type","value","setPreference","undefined","valueType","determineType","now","oldValue","set","newValue","removePreference","existed","has","delete","clear","Object","entries","count","size","data","content","JSON","stringify","writeFile","readFile","parse","isValidPreference","code","getAllPreferences","result","reset","hasPreference","getStoragePath","getPreferenceCount","includes","defaultInstance","getDefaultPreferenceManager","createPreferenceManager"],"mappings":"AAAA;;;;;;;CAOC,GAED,SAASA,YAAYC,EAAE,QAAQ,KAAK;AACpC,OAAOC,UAAU,OAAO;AACxB,OAAOC,QAAQ,KAAK;AACpB,SAASC,YAAY,QAAQ,SAAS;AAqBtC;;CAEC,GACD,OAAO,MAAMC,wBAAwBC;IACnC,YAAYC,OAAe,CAAE;QAC3B,KAAK,CAACA;QACN,IAAI,CAACC,IAAI,GAAG;IACd;AACF;AAEA;;CAEC,GACD,MAAMC,sBAA2C;IAC/CC,OAAO;IACPC,UAAU;IACVC,eAAe;IACfC,UAAU;IACVC,iBAAiB;AACnB;AAEA;;;;;CAKC,GACD,OAAO,MAAMC,8BAA8BX;IACjCY,YAAyC;IACzC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C,IAAI,CAACrB,aAAa,EAAE;YACvB,MAAM,IAAId,gBACR;QAEJ;IACF;IAEA;;;;;GAKC,GACD,AAAQ2C,cACNJ,KAAU,EACkC;QAC5C,IAAI,OAAOA,UAAU,UAAU,OAAO;QACtC,IAAI,OAAOA,UAAU,UAAU,OAAO;QACtC,IAAI,OAAOA,UAAU,WAAW,OAAO;QACvC,OAAO;IACT;IAEA;;;;;GAKC,GACD,AAAQyB,kBAAkB5B,UAAe,EAAgC;QACvE,OACEA,cACA,OAAOA,eAAe,YACtB,OAAOA,WAAWH,GAAG,KAAK,YAC1BG,WAAWG,KAAK,KAAKE,aACrB;YAAC;YAAU;YAAU;YAAW;SAAS,CAAC+B,QAAQ,CAACpC,WAAWE,IAAI,KAClE,OAAOF,WAAWP,SAAS,KAAK;IAEpC;AACF;AAEA;;CAEC,GACD,IAAI4C,kBAAgD;AAEpD;;;;CAIC,GACD,OAAO,SAASC;IACd,IAAI,CAACD,iBAAiB;QACpBA,kBAAkB,IAAI/D;IACxB;IACA,OAAO+D;AACT;AAEA;;;;;CAKC,GACD,OAAO,SAASE,wBACd5D,OAA2B;IAE3B,OAAO,IAAIL,sBAAsBK;AACnC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validators Module
|
|
3
|
+
*
|
|
4
|
+
* Provides validation functionality for enforcing best practices and detecting anti-patterns.
|
|
5
|
+
*
|
|
6
|
+
* @module validators
|
|
7
|
+
*/ // TodoWrite Batching Validator
|
|
8
|
+
export { TodoWriteValidator, getGlobalValidator, resetGlobalValidator } from "./todowrite-batching-validator";
|
|
9
|
+
// TodoWrite Integration
|
|
10
|
+
export { isValidationEnabled, getIntegrationConfig, validateTodoWrite, parseValidationFlags, displayValidationHelp, todoWriteWithValidation, createValidationMiddleware, getValidationStatus } from "./todowrite-integration";
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/validators/index.ts"],"names":["TodoWriteValidator","getGlobalValidator","resetGlobalValidator","isValidationEnabled","getIntegrationConfig","validateTodoWrite","parseValidationFlags","displayValidationHelp","todoWriteWithValidation","createValidationMiddleware","getValidationStatus"],"mappings":"AAAA;;;;;;CAMC,GAED,+BAA+B;AAC/B,SACEA,kBAAkB,EAClBC,kBAAkB,EAClBC,oBAAoB,QAKf,iCAAiC;AAExC,wBAAwB;AACxB,SACEC,mBAAmB,EACnBC,oBAAoB,EACpBC,iBAAiB,EACjBC,oBAAoB,EACpBC,qBAAqB,EACrBC,uBAAuB,EACvBC,0BAA0B,EAC1BC,mBAAmB,QAEd,0BAA0B"}
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Swarm Initialization Validator
|
|
3
|
+
*
|
|
4
|
+
* Validates that swarm initialization is performed before spawning multiple agents.
|
|
5
|
+
* Ensures proper coordination and prevents inconsistent implementations across agents.
|
|
6
|
+
*
|
|
7
|
+
* @module validators/swarm-init-validator
|
|
8
|
+
*/ import { Logger } from '../core/logger.js';
|
|
9
|
+
const DEFAULT_CONFIG = {
|
|
10
|
+
requireSwarmForMultiAgent: true,
|
|
11
|
+
minAgentsRequiringSwarm: 2,
|
|
12
|
+
meshTopologyMaxAgents: 7,
|
|
13
|
+
hierarchicalTopologyMinAgents: 8
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Validates swarm initialization before agent spawning
|
|
17
|
+
*
|
|
18
|
+
* @param agentCount - Number of agents to spawn
|
|
19
|
+
* @param swarmStatus - Current swarm status (optional, will check environment if not provided)
|
|
20
|
+
* @param config - Validator configuration
|
|
21
|
+
* @returns Validation result with error messages and suggestions
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const result = await validateSwarmInit(3);
|
|
26
|
+
* if (!result.valid) {
|
|
27
|
+
* console.error(result.error);
|
|
28
|
+
* console.log(result.suggestion);
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/ export async function validateSwarmInit(agentCount, swarmStatus, config = {}) {
|
|
32
|
+
const logger = new Logger('SwarmInitValidator');
|
|
33
|
+
const cfg = {
|
|
34
|
+
...DEFAULT_CONFIG,
|
|
35
|
+
...config
|
|
36
|
+
};
|
|
37
|
+
// Single agent spawning doesn't require swarm
|
|
38
|
+
if (agentCount < cfg.minAgentsRequiringSwarm) {
|
|
39
|
+
return {
|
|
40
|
+
valid: true
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
// Check if swarm is required for this agent count
|
|
44
|
+
if (!cfg.requireSwarmForMultiAgent) {
|
|
45
|
+
logger.warn('Swarm validation is disabled in configuration');
|
|
46
|
+
return {
|
|
47
|
+
valid: true
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
// Get swarm status
|
|
51
|
+
const status = swarmStatus || await getSwarmStatus();
|
|
52
|
+
// Validate swarm is initialized
|
|
53
|
+
if (!status.initialized) {
|
|
54
|
+
const topology = agentCount <= cfg.meshTopologyMaxAgents ? 'mesh' : 'hierarchical';
|
|
55
|
+
return {
|
|
56
|
+
valid: false,
|
|
57
|
+
error: createErrorMessage(agentCount),
|
|
58
|
+
suggestion: createSuggestion(agentCount, topology),
|
|
59
|
+
topology,
|
|
60
|
+
maxAgents: agentCount
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
// Validate topology matches agent count
|
|
64
|
+
const topologyValidation = validateTopology(agentCount, status, cfg);
|
|
65
|
+
if (!topologyValidation.valid) {
|
|
66
|
+
return topologyValidation;
|
|
67
|
+
}
|
|
68
|
+
// Validate max agents capacity
|
|
69
|
+
if (status.maxAgents && agentCount > status.maxAgents) {
|
|
70
|
+
return {
|
|
71
|
+
valid: false,
|
|
72
|
+
error: `Cannot spawn ${agentCount} agents. Swarm configured for maximum ${status.maxAgents} agents.`,
|
|
73
|
+
suggestion: `Reinitialize swarm with increased maxAgents:\n npx claude-flow-novice swarm init --topology ${status.topology} --max-agents ${agentCount}`
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
logger.info(`Swarm validation passed for ${agentCount} agents`);
|
|
77
|
+
return {
|
|
78
|
+
valid: true
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Validates that topology matches agent count requirements
|
|
83
|
+
*/ function validateTopology(agentCount, status, config) {
|
|
84
|
+
const expectedTopology = agentCount <= config.meshTopologyMaxAgents ? 'mesh' : 'hierarchical';
|
|
85
|
+
if (status.topology && status.topology !== expectedTopology) {
|
|
86
|
+
return {
|
|
87
|
+
valid: false,
|
|
88
|
+
error: `Topology mismatch: ${agentCount} agents require '${expectedTopology}' topology, but swarm is using '${status.topology}'.`,
|
|
89
|
+
suggestion: `Reinitialize swarm with correct topology:\n npx claude-flow-novice swarm init --topology ${expectedTopology} --max-agents ${agentCount}`,
|
|
90
|
+
topology: expectedTopology,
|
|
91
|
+
maxAgents: agentCount
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
valid: true
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Creates error message for missing swarm initialization
|
|
100
|
+
*/ function createErrorMessage(agentCount) {
|
|
101
|
+
return `
|
|
102
|
+
❌ SWARM INITIALIZATION REQUIRED
|
|
103
|
+
|
|
104
|
+
You are attempting to spawn ${agentCount} agents without initializing swarm.
|
|
105
|
+
|
|
106
|
+
Without swarm coordination:
|
|
107
|
+
• Agents work independently with no shared context
|
|
108
|
+
• Results may be inconsistent (e.g., 3 different JWT secret solutions)
|
|
109
|
+
• No consensus validation or Byzantine fault tolerance
|
|
110
|
+
• Memory coordination is disabled
|
|
111
|
+
|
|
112
|
+
This violates the mandatory coordination requirements in CLAUDE.md.
|
|
113
|
+
`.trim();
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Creates suggestion message with fix command
|
|
117
|
+
*/ function createSuggestion(agentCount, topology) {
|
|
118
|
+
return `
|
|
119
|
+
Fix:
|
|
120
|
+
1. Initialize swarm first:
|
|
121
|
+
npx claude-flow-novice swarm init --topology ${topology} --max-agents ${agentCount}
|
|
122
|
+
|
|
123
|
+
2. Then spawn agents:
|
|
124
|
+
[Your agent spawning command]
|
|
125
|
+
|
|
126
|
+
Topology Selection:
|
|
127
|
+
• mesh: 2-7 agents (peer-to-peer coordination)
|
|
128
|
+
• hierarchical: 8+ agents (coordinator-led structure)
|
|
129
|
+
|
|
130
|
+
See CLAUDE.md section "Swarm Initialization" for coordination requirements.
|
|
131
|
+
`.trim();
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Gets current swarm status from environment or MCP server
|
|
135
|
+
*/ async function getSwarmStatus() {
|
|
136
|
+
const logger = new Logger('SwarmInitValidator');
|
|
137
|
+
// Check environment variables
|
|
138
|
+
const swarmId = process.env['CLAUDE_SWARM_ID'];
|
|
139
|
+
if (!swarmId) {
|
|
140
|
+
return {
|
|
141
|
+
initialized: false
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
// Try to get status from MCP server via swarm coordinator
|
|
145
|
+
try {
|
|
146
|
+
// Import dynamically to avoid circular dependencies
|
|
147
|
+
const { getSwarmCoordinator } = await import('../coordination/swarm-coordinator-factory.js').catch(()=>({
|
|
148
|
+
getSwarmCoordinator: null
|
|
149
|
+
}));
|
|
150
|
+
if (getSwarmCoordinator) {
|
|
151
|
+
const coordinator = getSwarmCoordinator();
|
|
152
|
+
if (coordinator) {
|
|
153
|
+
const status = coordinator.getSwarmStatus();
|
|
154
|
+
return {
|
|
155
|
+
initialized: true,
|
|
156
|
+
swarmId,
|
|
157
|
+
activeAgents: status.agents.total,
|
|
158
|
+
maxAgents: status.agents.total
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
} catch (error) {
|
|
163
|
+
logger.debug('Could not get swarm status from coordinator', error);
|
|
164
|
+
}
|
|
165
|
+
// If we have a swarm ID but can't get details, assume initialized
|
|
166
|
+
return {
|
|
167
|
+
initialized: true,
|
|
168
|
+
swarmId
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Validates swarm initialization and throws error if invalid
|
|
173
|
+
*
|
|
174
|
+
* This is a convenience wrapper for validateSwarmInit that throws on validation failure.
|
|
175
|
+
* Use this in CLI commands where you want to halt execution on validation errors.
|
|
176
|
+
*
|
|
177
|
+
* @param agentCount - Number of agents to spawn
|
|
178
|
+
* @param swarmStatus - Current swarm status (optional)
|
|
179
|
+
* @param config - Validator configuration
|
|
180
|
+
* @throws Error if validation fails
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```typescript
|
|
184
|
+
* try {
|
|
185
|
+
* await requireSwarmInit(3);
|
|
186
|
+
* // Proceed with spawning agents
|
|
187
|
+
* } catch (error) {
|
|
188
|
+
* console.error(error.message);
|
|
189
|
+
* process.exit(1);
|
|
190
|
+
* }
|
|
191
|
+
* ```
|
|
192
|
+
*/ export async function requireSwarmInit(agentCount, swarmStatus, config) {
|
|
193
|
+
const result = await validateSwarmInit(agentCount, swarmStatus, config);
|
|
194
|
+
if (!result.valid) {
|
|
195
|
+
const errorMessage = `${result.error}\n\n${result.suggestion}`;
|
|
196
|
+
throw new Error(errorMessage);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Gets recommended topology for agent count
|
|
201
|
+
*
|
|
202
|
+
* @param agentCount - Number of agents
|
|
203
|
+
* @param config - Validator configuration
|
|
204
|
+
* @returns Recommended topology
|
|
205
|
+
*/ export function getRecommendedTopology(agentCount, config = {}) {
|
|
206
|
+
const cfg = {
|
|
207
|
+
...DEFAULT_CONFIG,
|
|
208
|
+
...config
|
|
209
|
+
};
|
|
210
|
+
return agentCount <= cfg.meshTopologyMaxAgents ? 'mesh' : 'hierarchical';
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Checks if swarm initialization is required for agent count
|
|
214
|
+
*
|
|
215
|
+
* @param agentCount - Number of agents
|
|
216
|
+
* @param config - Validator configuration
|
|
217
|
+
* @returns true if swarm initialization is required
|
|
218
|
+
*/ export function isSwarmRequired(agentCount, config = {}) {
|
|
219
|
+
const cfg = {
|
|
220
|
+
...DEFAULT_CONFIG,
|
|
221
|
+
...config
|
|
222
|
+
};
|
|
223
|
+
return cfg.requireSwarmForMultiAgent && agentCount >= cfg.minAgentsRequiringSwarm;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Validates swarm configuration before initialization
|
|
227
|
+
*
|
|
228
|
+
* @param topology - Requested topology
|
|
229
|
+
* @param maxAgents - Maximum number of agents
|
|
230
|
+
* @param config - Validator configuration
|
|
231
|
+
* @returns Validation result
|
|
232
|
+
*/ export function validateSwarmConfig(topology, maxAgents, config = {}) {
|
|
233
|
+
const cfg = {
|
|
234
|
+
...DEFAULT_CONFIG,
|
|
235
|
+
...config
|
|
236
|
+
};
|
|
237
|
+
// Validate topology matches max agents
|
|
238
|
+
const recommendedTopology = getRecommendedTopology(maxAgents, config);
|
|
239
|
+
if (topology !== recommendedTopology) {
|
|
240
|
+
return {
|
|
241
|
+
valid: false,
|
|
242
|
+
error: `Topology '${topology}' is not optimal for ${maxAgents} agents.`,
|
|
243
|
+
suggestion: `Recommended topology: '${recommendedTopology}'\n • mesh: 2-${cfg.meshTopologyMaxAgents} agents\n • hierarchical: ${cfg.hierarchicalTopologyMinAgents}+ agents`,
|
|
244
|
+
topology: recommendedTopology,
|
|
245
|
+
maxAgents
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
return {
|
|
249
|
+
valid: true
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Factory for creating a swarm coordinator factory module
|
|
254
|
+
* This is a placeholder that will be replaced with actual implementation
|
|
255
|
+
*/ export const SwarmCoordinatorFactory = {
|
|
256
|
+
getSwarmCoordinator () {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
//# sourceMappingURL=swarm-init-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/validators/swarm-init-validator.ts"],"names":["Logger","DEFAULT_CONFIG","requireSwarmForMultiAgent","minAgentsRequiringSwarm","meshTopologyMaxAgents","hierarchicalTopologyMinAgents","validateSwarmInit","agentCount","swarmStatus","config","logger","cfg","valid","warn","status","getSwarmStatus","initialized","topology","error","createErrorMessage","suggestion","createSuggestion","maxAgents","topologyValidation","validateTopology","info","expectedTopology","trim","swarmId","process","env","getSwarmCoordinator","catch","coordinator","activeAgents","agents","total","debug","requireSwarmInit","result","errorMessage","Error","getRecommendedTopology","isSwarmRequired","validateSwarmConfig","recommendedTopology","SwarmCoordinatorFactory"],"mappings":"AAAA;;;;;;;CAOC,GAED,SAASA,MAAM,QAAQ,oBAAoB;AAmC3C,MAAMC,iBAAiD;IACrDC,2BAA2B;IAC3BC,yBAAyB;IACzBC,uBAAuB;IACvBC,+BAA+B;AACjC;AAEA;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,eAAeC,kBACpBC,UAAkB,EAClBC,WAAyB,EACzBC,SAA+B,CAAC,CAAC;IAEjC,MAAMC,SAAS,IAAIV,OAAO;IAC1B,MAAMW,MAAM;QAAE,GAAGV,cAAc;QAAE,GAAGQ,MAAM;IAAC;IAE3C,8CAA8C;IAC9C,IAAIF,aAAaI,IAAIR,uBAAuB,EAAE;QAC5C,OAAO;YACLS,OAAO;QACT;IACF;IAEA,kDAAkD;IAClD,IAAI,CAACD,IAAIT,yBAAyB,EAAE;QAClCQ,OAAOG,IAAI,CAAC;QACZ,OAAO;YACLD,OAAO;QACT;IACF;IAEA,mBAAmB;IACnB,MAAME,SAASN,eAAgB,MAAMO;IAErC,gCAAgC;IAChC,IAAI,CAACD,OAAOE,WAAW,EAAE;QACvB,MAAMC,WAAWV,cAAcI,IAAIP,qBAAqB,GAAG,SAAS;QAEpE,OAAO;YACLQ,OAAO;YACPM,O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