-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-queue.js
More file actions
executable file
·195 lines (162 loc) · 5.81 KB
/
Copy pathcheck-queue.js
File metadata and controls
executable file
·195 lines (162 loc) · 5.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/usr/bin/env node
/**
* Queue Priority Checker
*
* Scans tasks/QUEUE.md and enforces queue-first execution.
* Returns exit code 1 if HIGH/Critical priority tasks exist.
* Returns exit code 0 if queue is empty or all tasks are LOW priority.
*
* Usage:
* node skills/agent-autonomy-kit/check-queue.js
*
* Integration:
* Run this BEFORE saying HEARTBEAT_OK.
* If exit code 1: spawn agent for the HIGH priority task.
* If exit code 0: safe to continue with other work.
*/
const fs = require('fs');
const path = require('path');
// ANSI color codes
const colors = {
reset: '\x1b[0m',
red: '\x1b[31m',
yellow: '\x1b[33m',
green: '\x1b[32m',
cyan: '\x1b[36m',
bold: '\x1b[1m',
};
function parseQueueFile(queuePath) {
if (!fs.existsSync(queuePath)) {
return {
ready: [],
inProgress: [],
blocked: [],
};
}
const content = fs.readFileSync(queuePath, 'utf-8');
const lines = content.split('\n');
let currentSection = null;
const sections = {
ready: [],
inProgress: [],
blocked: [],
};
for (const line of lines) {
const trimmed = line.trim();
// Section headers - more flexible matching
if (trimmed.match(/^##\s+(🔥|🔴)?\s*(High Priority|Ready)/i)) {
currentSection = 'ready';
continue;
}
if (trimmed.match(/^##\s+(🟡|⏳)?\s*(Medium Priority|In Progress)/i)) {
currentSection = 'inProgress';
continue;
}
if (trimmed.match(/^##\s+(🔵|🚫)?\s*Blocked/i)) {
currentSection = 'blocked';
continue;
}
if (trimmed.match(/^##\s+(✅|✔️)?\s*Done/i)) {
currentSection = null; // Ignore completed tasks
continue;
}
if (trimmed.startsWith('##')) {
// Unknown section - might be a subsection, keep current section
continue;
}
// Parse task lines
if (currentSection && trimmed.startsWith('-')) {
const m = trimmed.match(/^-\s*\[([ x])\]\s*(.*)$/);
if (!m) continue;
const checked = m[1] === 'x';
if (checked) continue; // Ignore completed tasks
const taskText = m[2];
const priority = detectPriority(taskText);
sections[currentSection].push({
text: taskText,
priority,
raw: line,
});
}
}
return sections;
}
function detectPriority(taskText) {
const upper = taskText.toUpperCase();
// Explicit priority markers
if (upper.includes('[CRITICAL]') || upper.includes('🔥 CRITICAL') || upper.includes('URGENT:')) {
return 'CRITICAL';
}
if (upper.includes('[HIGH]') || upper.includes('🔴 HIGH') || upper.includes('HIGH PRIORITY')) {
return 'HIGH';
}
if (upper.includes('[MEDIUM]') || upper.includes('🟡 MEDIUM') || upper.includes('MEDIUM PRIORITY') || upper.includes('⭐') && upper.includes('MEDIUM')) {
return 'MEDIUM';
}
if (upper.includes('[LOW]') || upper.includes('🟡 LOW') || upper.includes('LOW PRIORITY')) {
return 'LOW';
}
// Context-based detection
if (upper.includes('FIX:') || upper.includes('BUG:') || upper.includes('BROKEN')) {
return 'HIGH';
}
// Section-based detection (tasks under "🔥 High Priority" header)
if (taskText.startsWith('**')) {
return 'HIGH'; // Bold tasks often indicate importance
}
// Default: MEDIUM
return 'MEDIUM';
}
function checkQueue(queuePath) {
const sections = parseQueueFile(queuePath);
// Only check Ready tasks (tasks that can be picked up NOW)
const readyTasks = sections.ready;
const criticalTasks = readyTasks.filter(t => t.priority === 'CRITICAL');
const highTasks = readyTasks.filter(t => t.priority === 'HIGH');
const mediumTasks = readyTasks.filter(t => t.priority === 'MEDIUM');
const lowTasks = readyTasks.filter(t => t.priority === 'LOW');
const hasUrgentWork = criticalTasks.length > 0 || highTasks.length > 0;
// Output results
console.log(`${colors.bold}${colors.cyan}=== Queue Priority Check ===${colors.reset}\n`);
if (criticalTasks.length > 0) {
console.log(`${colors.red}${colors.bold}🔥 CRITICAL tasks: ${criticalTasks.length}${colors.reset}`);
criticalTasks.forEach(t => console.log(` ${colors.red}• ${t.text.substring(0, 80)}${colors.reset}`));
console.log();
}
if (highTasks.length > 0) {
console.log(`${colors.red}🔴 HIGH priority tasks: ${highTasks.length}${colors.reset}`);
highTasks.forEach(t => console.log(` ${colors.yellow}• ${t.text.substring(0, 80)}${colors.reset}`));
console.log();
}
if (mediumTasks.length > 0) {
console.log(`${colors.yellow}🟡 MEDIUM priority tasks: ${mediumTasks.length}${colors.reset}`);
}
if (lowTasks.length > 0) {
console.log(`${colors.green}🟢 LOW priority tasks: ${lowTasks.length}${colors.reset}`);
}
if (readyTasks.length === 0) {
console.log(`${colors.green}✅ Queue is empty - no ready tasks${colors.reset}`);
}
console.log();
// Enforcement decision
if (hasUrgentWork) {
console.log(`${colors.red}${colors.bold}❌ CANNOT SKIP QUEUE${colors.reset}`);
console.log(`${colors.red}You must spawn an agent for HIGH/CRITICAL tasks before doing other work.${colors.reset}`);
console.log();
// Show top task
const topTask = criticalTasks.length > 0 ? criticalTasks[0] : highTasks[0];
console.log(`${colors.bold}Top priority task:${colors.reset}`);
console.log(`${colors.cyan}${topTask.text}${colors.reset}`);
console.log();
process.exit(1); // Exit code 1 = MUST handle queue
} else {
console.log(`${colors.green}${colors.bold}✅ Safe to continue${colors.reset}`);
console.log(`${colors.green}No HIGH/CRITICAL tasks in queue. You can proceed with other work.${colors.reset}`);
console.log();
process.exit(0); // Exit code 0 = queue is clear
}
}
// Main execution
const workspaceRoot = process.cwd();
const queuePath = path.join(workspaceRoot, 'tasks/QUEUE.md');
checkQueue(queuePath);