claude-flow-novice 2.10.7 → 2.10.9

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 (26) hide show
  1. package/.claude/commands/cfn/CFN_LOOP_TASK_MODE.md +94 -0
  2. package/.claude/commands/cfn/cfn-loop.md +4 -3
  3. package/.claude/hooks/cfn-invoke-pre-edit.sh +88 -0
  4. package/.claude/skills/cfn-agent-spawning/spawn-worker.sh +176 -0
  5. package/claude-assets/agents/csuite/cto-agent.md +371 -0
  6. package/claude-assets/agents/marketing_hybrid/cost_tracker.md +13 -0
  7. package/claude-assets/agents/marketing_hybrid/docker_deployer.md +13 -0
  8. package/claude-assets/agents/marketing_hybrid/zai_worker_spawner.md +13 -0
  9. package/claude-assets/commands/cfn/CFN_LOOP_TASK_MODE.md +94 -0
  10. package/claude-assets/commands/cfn/cfn-loop.md +4 -3
  11. package/claude-assets/hooks/cfn-invoke-pre-edit.sh +88 -0
  12. package/claude-assets/hooks/post-edit.config.json +19 -8
  13. package/claude-assets/skills/cfn-agent-spawning/spawn-worker.sh +176 -0
  14. package/claude-assets/skills/pre-edit-backup/backup.sh +130 -0
  15. package/claude-assets/skills/pre-edit-backup/cleanup.sh +155 -0
  16. package/claude-assets/skills/pre-edit-backup/restore.sh +128 -0
  17. package/claude-assets/skills/pre-edit-backup/revert-file.sh +168 -0
  18. package/dist/agents/agent-loader.js +146 -165
  19. package/dist/agents/agent-loader.js.map +1 -1
  20. package/dist/cli/config-manager.js +91 -109
  21. package/dist/cli/config-manager.js.map +1 -1
  22. package/package.json +1 -1
  23. package/scripts/marketing_hybrid_deployment.sh +45 -0
  24. package/scripts/redis-prometheus-exporter.sh +33 -0
  25. package/scripts/track-zai-costs.sh +19 -0
  26. package/claude-assets/skills/team-provider-routing/spawn-worker.sh +0 -91
@@ -0,0 +1,168 @@
1
+ #!/bin/bash
2
+ #
3
+ # Revert File Utility
4
+ # High-level revert interface for agents to use instead of git operations
5
+ #
6
+ # Usage:
7
+ # ./.claude/skills/pre-edit-backup/revert-file.sh <file_path> [--agent-id <id>] [--interactive]
8
+ #
9
+ # Examples:
10
+ # # Revert to most recent backup (auto-select)
11
+ # ./.claude/skills/pre-edit-backup/revert-file.sh src/file.ts --agent-id "coder-1"
12
+ #
13
+ # # Interactive mode (shows list of backups)
14
+ # ./.claude/skills/pre-edit-backup/revert-file.sh src/file.ts --agent-id "coder-1" --interactive
15
+ #
16
+ # # List available backups without reverting
17
+ # ./.claude/skills/pre-edit-backup/revert-file.sh src/file.ts --agent-id "coder-1" --list-only
18
+
19
+ set -euo pipefail
20
+
21
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
22
+ BACKUP_BASE_DIR=".backups"
23
+
24
+ # Parse arguments
25
+ FILE_PATH=""
26
+ AGENT_ID="${AGENT_ID:-unknown}"
27
+ INTERACTIVE=false
28
+ LIST_ONLY=false
29
+
30
+ while [[ $# -gt 0 ]]; do
31
+ case $1 in
32
+ --agent-id)
33
+ AGENT_ID="$2"
34
+ shift 2
35
+ ;;
36
+ --interactive)
37
+ INTERACTIVE=true
38
+ shift
39
+ ;;
40
+ --list-only)
41
+ LIST_ONLY=true
42
+ shift
43
+ ;;
44
+ *)
45
+ FILE_PATH="$1"
46
+ shift
47
+ ;;
48
+ esac
49
+ done
50
+
51
+ # Validate inputs
52
+ if [ -z "$FILE_PATH" ]; then
53
+ echo "Error: File path required"
54
+ echo "Usage: $0 <file_path> [--agent-id <id>] [--interactive] [--list-only]"
55
+ exit 1
56
+ fi
57
+
58
+ # Normalize file path
59
+ FILE_PATH=$(realpath "$FILE_PATH" 2>/dev/null || echo "$FILE_PATH")
60
+
61
+ # Find backups for this file
62
+ AGENT_BACKUP_DIR="$BACKUP_BASE_DIR/$AGENT_ID"
63
+
64
+ if [ ! -d "$AGENT_BACKUP_DIR" ]; then
65
+ echo "❌ No backups found for agent: $AGENT_ID"
66
+ exit 1
67
+ fi
68
+
69
+ # Search for backups matching this file
70
+ MATCHING_BACKUPS=()
71
+ while IFS= read -r backup_dir; do
72
+ metadata_file="$backup_dir/backup_metadata.json"
73
+
74
+ if [ -f "$metadata_file" ]; then
75
+ original_path=$(jq -r '.original_path' "$metadata_file" 2>/dev/null || echo "")
76
+
77
+ # Normalize original path for comparison
78
+ original_path=$(realpath "$original_path" 2>/dev/null || echo "$original_path")
79
+
80
+ if [ "$original_path" = "$FILE_PATH" ]; then
81
+ MATCHING_BACKUPS+=("$backup_dir")
82
+ fi
83
+ fi
84
+ done < <(find "$AGENT_BACKUP_DIR" -mindepth 1 -maxdepth 1 -type d | sort -r)
85
+
86
+ # Check if any backups found
87
+ if [ ${#MATCHING_BACKUPS[@]} -eq 0 ]; then
88
+ echo "❌ No backups found for file: $FILE_PATH"
89
+ exit 1
90
+ fi
91
+
92
+ # List backups function
93
+ list_backups() {
94
+ echo "Available backups for: $FILE_PATH"
95
+ echo "----------------------------------------"
96
+
97
+ local index=1
98
+ for backup_dir in "${MATCHING_BACKUPS[@]}"; do
99
+ metadata_file="$backup_dir/backup_metadata.json"
100
+
101
+ timestamp=$(jq -r '.backup_timestamp' "$metadata_file")
102
+ status=$(jq -r '.backup_status' "$metadata_file")
103
+
104
+ # Convert timestamp to readable date
105
+ if command -v date >/dev/null 2>&1; then
106
+ # Handle millisecond timestamps
107
+ timestamp_seconds=$((timestamp / 1000))
108
+ date_str=$(date -d "@$timestamp_seconds" '+%Y-%m-%d %H:%M:%S' 2>/dev/null || date -r "$timestamp_seconds" '+%Y-%m-%d %H:%M:%S' 2>/dev/null || echo "Unknown")
109
+ else
110
+ date_str="$timestamp"
111
+ fi
112
+
113
+ echo "[$index] $date_str (Status: $status)"
114
+ echo " Path: $backup_dir"
115
+
116
+ ((index++))
117
+ done
118
+ echo "----------------------------------------"
119
+ }
120
+
121
+ # List-only mode
122
+ if [ "$LIST_ONLY" = true ]; then
123
+ list_backups
124
+ exit 0
125
+ fi
126
+
127
+ # Interactive mode
128
+ if [ "$INTERACTIVE" = true ]; then
129
+ list_backups
130
+ echo ""
131
+ echo -n "Select backup to restore [1-${#MATCHING_BACKUPS[@]}] (or 0 to cancel): "
132
+ read -r selection
133
+
134
+ if [ "$selection" = "0" ]; then
135
+ echo "❌ Revert cancelled"
136
+ exit 0
137
+ fi
138
+
139
+ if ! [[ "$selection" =~ ^[0-9]+$ ]] || [ "$selection" -lt 1 ] || [ "$selection" -gt ${#MATCHING_BACKUPS[@]} ]; then
140
+ echo "❌ Invalid selection: $selection"
141
+ exit 1
142
+ fi
143
+
144
+ SELECTED_BACKUP="${MATCHING_BACKUPS[$((selection - 1))]}"
145
+ else
146
+ # Auto-select most recent backup (first in sorted list)
147
+ SELECTED_BACKUP="${MATCHING_BACKUPS[0]}"
148
+
149
+ metadata_file="$SELECTED_BACKUP/backup_metadata.json"
150
+ timestamp=$(jq -r '.backup_timestamp' "$metadata_file")
151
+ timestamp_seconds=$((timestamp / 1000))
152
+ date_str=$(date -d "@$timestamp_seconds" '+%Y-%m-%d %H:%M:%S' 2>/dev/null || date -r "$timestamp_seconds" '+%Y-%m-%d %H:%M:%S' 2>/dev/null || echo "timestamp: $timestamp")
153
+
154
+ echo "🔄 Auto-selecting most recent backup: $date_str"
155
+ fi
156
+
157
+ # Restore using restore.sh
158
+ echo "🔄 Restoring file from backup..."
159
+ "$SCRIPT_DIR/restore.sh" "$SELECTED_BACKUP"
160
+
161
+ if [ $? -eq 0 ]; then
162
+ echo "✅ File successfully reverted to backup"
163
+ echo " Backup: $SELECTED_BACKUP"
164
+ exit 0
165
+ else
166
+ echo "❌ Failed to revert file"
167
+ exit 1
168
+ fi
@@ -1,145 +1,12 @@
1
- "use strict";
2
1
  /**
3
2
  * Dynamic Agent Loader - Reads agent definitions from .claude/agents/ directory
4
3
  * Single source of truth for agent types in the system
5
- */ var __awaiter = this && this.__awaiter || function(thisArg, _arguments, P, generator) {
6
- function adopt(value) {
7
- return value instanceof P ? value : new P(function(resolve) {
8
- resolve(value);
9
- });
10
- }
11
- return new (P || (P = Promise))(function(resolve, reject) {
12
- function fulfilled(value) {
13
- try {
14
- step(generator.next(value));
15
- } catch (e) {
16
- reject(e);
17
- }
18
- }
19
- function rejected(value) {
20
- try {
21
- step(generator["throw"](value));
22
- } catch (e) {
23
- reject(e);
24
- }
25
- }
26
- function step(result) {
27
- result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
28
- }
29
- step((generator = generator.apply(thisArg, _arguments || [])).next());
30
- });
31
- };
32
- var __generator = this && this.__generator || function(thisArg, body) {
33
- var _ = {
34
- label: 0,
35
- sent: function() {
36
- if (t[0] & 1) throw t[1];
37
- return t[1];
38
- },
39
- trys: [],
40
- ops: []
41
- }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
42
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
43
- return this;
44
- }), g;
45
- function verb(n) {
46
- return function(v) {
47
- return step([
48
- n,
49
- v
50
- ]);
51
- };
52
- }
53
- function step(op) {
54
- if (f) throw new TypeError("Generator is already executing.");
55
- while(g && (g = 0, op[0] && (_ = 0)), _)try {
56
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
57
- if (y = 0, t) op = [
58
- op[0] & 2,
59
- t.value
60
- ];
61
- switch(op[0]){
62
- case 0:
63
- case 1:
64
- t = op;
65
- break;
66
- case 4:
67
- _.label++;
68
- return {
69
- value: op[1],
70
- done: false
71
- };
72
- case 5:
73
- _.label++;
74
- y = op[1];
75
- op = [
76
- 0
77
- ];
78
- continue;
79
- case 7:
80
- op = _.ops.pop();
81
- _.trys.pop();
82
- continue;
83
- default:
84
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
85
- _ = 0;
86
- continue;
87
- }
88
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
89
- _.label = op[1];
90
- break;
91
- }
92
- if (op[0] === 6 && _.label < t[1]) {
93
- _.label = t[1];
94
- t = op;
95
- break;
96
- }
97
- if (t && _.label < t[2]) {
98
- _.label = t[2];
99
- _.ops.push(op);
100
- break;
101
- }
102
- if (t[2]) _.ops.pop();
103
- _.trys.pop();
104
- continue;
105
- }
106
- op = body.call(thisArg, _);
107
- } catch (e) {
108
- op = [
109
- 6,
110
- e
111
- ];
112
- y = 0;
113
- } finally{
114
- f = t = 0;
115
- }
116
- if (op[0] & 5) throw op[1];
117
- return {
118
- value: op[0] ? op[1] : void 0,
119
- done: true
120
- };
121
- }
122
- };
123
- var __spreadArray = this && this.__spreadArray || function(to, from, pack) {
124
- if (pack || arguments.length === 2) for(var i = 0, l = from.length, ar; i < l; i++){
125
- if (ar || !(i in from)) {
126
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
127
- ar[i] = from[i];
128
- }
129
- }
130
- return to.concat(ar || Array.prototype.slice.call(from));
131
- };
132
- Object.defineProperty(exports, "__esModule", {
133
- value: true
134
- });
135
- exports.refreshAgents = exports.getAgentsByCategory = exports.isValidAgentType = exports.searchAgents = exports.getAgentCategories = exports.getAllAgents = exports.getAgent = exports.getAvailableAgentTypes = exports.agentLoader = exports.AgentLoader = void 0;
136
- exports.resolveLegacyAgentType = resolveLegacyAgentType;
137
- var node_fs_1 = require("node:fs");
138
- var glob_1 = require("glob");
139
- var node_path_1 = require("node:path");
140
- var yaml_1 = require("yaml");
4
+ */ import { readFileSync, existsSync } from 'node:fs';
5
+ import { glob } from 'glob';
6
+ import { resolve, dirname } from 'node:path';
7
+ import { parse as parseYaml } from 'yaml';
141
8
  // Legacy agent type mapping for backward compatibility
142
- var LEGACY_AGENT_MAPPING = {
9
+ const LEGACY_AGENT_MAPPING = {
143
10
  analyst: 'code-analyzer',
144
11
  coordinator: 'hierarchical-coordinator',
145
12
  optimizer: 'perf-analyzer',
@@ -150,40 +17,38 @@ var LEGACY_AGENT_MAPPING = {
150
17
  };
151
18
  /**
152
19
  * Resolve legacy agent types to current equivalents
153
- */ function resolveLegacyAgentType(legacyType) {
20
+ */ export function resolveLegacyAgentType(legacyType) {
154
21
  return LEGACY_AGENT_MAPPING[legacyType] || legacyType;
155
22
  }
156
- var AgentLoader = /** @class */ function() {
157
- function AgentLoader() {
158
- this.agentCache = new Map();
159
- this.categoriesCache = [];
160
- this.lastLoadTime = 0;
161
- this.CACHE_EXPIRY = 60000; // 1 minute cache
162
- }
163
- AgentLoader.prototype.getAgentsDirectory = function() {
164
- var currentDir = process.cwd();
23
+ export class AgentLoader {
24
+ agentCache = new Map();
25
+ categoriesCache = [];
26
+ lastLoadTime = 0;
27
+ CACHE_EXPIRY = 60_000;
28
+ getAgentsDirectory() {
29
+ let currentDir = process.cwd();
165
30
  while(currentDir !== '/'){
166
- var claudeAgentsPath = (0, node_path_1.resolve)(currentDir, '.claude', 'agents');
167
- if ((0, node_fs_1.existsSync)(claudeAgentsPath)) {
31
+ const claudeAgentsPath = resolve(currentDir, '.claude', 'agents');
32
+ if (existsSync(claudeAgentsPath)) {
168
33
  return claudeAgentsPath;
169
34
  }
170
- currentDir = (0, node_path_1.dirname)(currentDir);
35
+ currentDir = dirname(currentDir);
171
36
  }
172
- return (0, node_path_1.resolve)(process.cwd(), '.claude', 'agents');
173
- };
174
- AgentLoader.prototype.parseAgentFile = function(filePath) {
37
+ return resolve(process.cwd(), '.claude', 'agents');
38
+ }
39
+ parseAgentFile(filePath) {
175
40
  try {
176
- var content = (0, node_fs_1.readFileSync)(filePath, 'utf-8');
177
- var frontmatterMatch = content.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)$/);
41
+ const content = readFileSync(filePath, 'utf-8');
42
+ const frontmatterMatch = content.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)$/);
178
43
  if (!frontmatterMatch) {
179
- console.warn("No frontmatter found in ".concat(filePath));
44
+ console.warn(`No frontmatter found in ${filePath}`);
180
45
  return null;
181
46
  }
182
- var yamlContent = frontmatterMatch[1], markdownContent = frontmatterMatch[2];
183
- var frontmatter = (0, yaml_1.parse)(yamlContent);
184
- var description = frontmatter.description;
47
+ const [, yamlContent, markdownContent] = frontmatterMatch;
48
+ const frontmatter = parseYaml(yamlContent);
49
+ const description = frontmatter.description;
185
50
  if (!frontmatter.name || !description) {
186
- console.warn("Missing required fields (name, description) in ".concat(filePath));
51
+ console.warn(`Missing required fields (name, description) in ${filePath}`);
187
52
  return null;
188
53
  }
189
54
  return {
@@ -204,13 +69,129 @@ var AgentLoader = /** @class */ function() {
204
69
  content: markdownContent.trim()
205
70
  };
206
71
  } catch (error) {
207
- console.error("Error parsing agent file ".concat(filePath, ":"), error);
72
+ console.error(`Error parsing agent file ${filePath}:`, error);
208
73
  return null;
209
74
  }
210
- };
211
- AgentLoader.prototype.parseTools = function(frontmatter) {
212
- var extractTools = function(input) {
75
+ }
76
+ parseTools(frontmatter) {
77
+ const extractTools = (input)=>{
213
78
  if (Array.isArray(input)) return input.map(String);
79
+ if (typeof input === 'string') {
80
+ return input.split(/[,\s]+/).map((t)=>t.trim()).filter((t)=>t.length > 0);
81
+ }
82
+ return [];
83
+ };
84
+ // Safely handle tools and capabilities.tools
85
+ const toolsFromFrontmatter = frontmatter.tools ? extractTools(frontmatter.tools) : [];
86
+ const toolsFromCapabilities = frontmatter.capabilities && typeof frontmatter.capabilities === 'object' ? extractTools(Object(frontmatter.capabilities).tools) : [];
87
+ return [
88
+ ...toolsFromFrontmatter,
89
+ ...toolsFromCapabilities
90
+ ];
91
+ }
92
+ async loadAgents() {
93
+ const agentsDir = this.getAgentsDirectory();
94
+ if (!existsSync(agentsDir)) {
95
+ console.warn(`Agents directory not found: ${agentsDir}`);
96
+ return;
97
+ }
98
+ const agentFiles = await new Promise((resolve, reject)=>{
99
+ glob('**/*.md', {
100
+ cwd: agentsDir,
101
+ ignore: [
102
+ '**/README.md',
103
+ '**/MIGRATION_SUMMARY.md'
104
+ ],
105
+ absolute: true
106
+ }, (err, matches)=>{
107
+ if (err) reject(err);
108
+ else resolve(matches);
109
+ });
110
+ });
111
+ this.agentCache.clear();
112
+ this.categoriesCache = [];
113
+ const categoryMap = new Map();
114
+ for (const filePath of agentFiles){
115
+ const agent = this.parseAgentFile(filePath);
116
+ if (agent) {
117
+ this.agentCache.set(agent.name, agent);
118
+ const relativePath = filePath.replace(agentsDir, '');
119
+ const pathParts = relativePath.split('/');
120
+ const category = pathParts[1] || 'uncategorized';
121
+ if (!categoryMap.has(category)) {
122
+ categoryMap.set(category, []);
123
+ }
124
+ categoryMap.get(category).push(agent);
125
+ }
126
+ }
127
+ this.categoriesCache = Array.from(categoryMap.entries()).map(([name, agents])=>({
128
+ name,
129
+ agents: agents.sort((a, b)=>a.name.localeCompare(b.name))
130
+ }));
131
+ this.lastLoadTime = Date.now();
132
+ }
133
+ // Rest of the methods remain similar to the original implementation
134
+ needsRefresh() {
135
+ return Date.now() - this.lastLoadTime > this.CACHE_EXPIRY;
136
+ }
137
+ async ensureLoaded() {
138
+ if (this.agentCache.size === 0 || this.needsRefresh()) {
139
+ await this.loadAgents();
140
+ }
141
+ }
142
+ async getAvailableAgentTypes() {
143
+ await this.ensureLoaded();
144
+ const currentTypes = Array.from(this.agentCache.keys());
145
+ const legacyTypes = Object.keys(LEGACY_AGENT_MAPPING);
146
+ return Array.from(new Set([
147
+ ...currentTypes,
148
+ ...legacyTypes
149
+ ])).sort();
150
+ }
151
+ async getAgent(name) {
152
+ await this.ensureLoaded();
153
+ return this.agentCache.get(name) || this.agentCache.get(resolveLegacyAgentType(name)) || null;
154
+ }
155
+ async getAllAgents() {
156
+ await this.ensureLoaded();
157
+ return Array.from(this.agentCache.values()).sort((a, b)=>a.name.localeCompare(b.name));
158
+ }
159
+ async getAgentCategories() {
160
+ await this.ensureLoaded();
161
+ return this.categoriesCache;
162
+ }
163
+ async searchAgents(query) {
164
+ await this.ensureLoaded();
165
+ const lowerQuery = query.toLowerCase();
166
+ return Array.from(this.agentCache.values()).filter((agent)=>agent.name.toLowerCase().includes(lowerQuery) || agent.description.toLowerCase().includes(lowerQuery) || agent.capabilities?.some((cap)=>cap.toLowerCase().includes(lowerQuery)));
167
+ }
168
+ async isValidAgentType(name) {
169
+ await this.ensureLoaded();
170
+ return this.agentCache.has(name) || this.agentCache.has(resolveLegacyAgentType(name));
171
+ }
172
+ async getAgentsByCategory(category) {
173
+ const categories = await this.getAgentCategories();
174
+ const found = categories.find((cat)=>cat.name === category);
175
+ return found?.agents || [];
176
+ }
177
+ async refresh() {
178
+ this.lastLoadTime = 0;
179
+ await this.loadAgents();
180
+ }
181
+ }
182
+ // Singleton instance
183
+ export const agentLoader = new AgentLoader();
184
+ // Convenience exports for use in other modules
185
+ export const getAvailableAgentTypes = ()=>agentLoader.getAvailableAgentTypes();
186
+ export const getAgent = (name)=>agentLoader.getAgent(name);
187
+ export const getAllAgents = ()=>agentLoader.getAllAgents();
188
+ export const getAgentCategories = ()=>agentLoader.getAgentCategories();
189
+ export const searchAgents = (query)=>agentLoader.searchAgents(query);
190
+ export const isValidAgentType = (name)=>agentLoader.isValidAgentType(name);
191
+ export const getAgentsByCategory = (category)=>agentLoader.getAgentsByCategory(category);
192
+ export const refreshAgents = ()=>agentLoader.refresh();
193
+
194
+ //# sourceMappingURL=agent-loader.js.map.isArray(input)) return input.map(String);
214
195
  if (typeof input === 'string') {
215
196
  return input.split(/[,\s]+/).map(function(t) {
216
197
  return t.trim();