@blogic-cz/agent-tools 0.5.6 → 0.5.7
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/package.json
CHANGED
|
@@ -45,6 +45,7 @@ export type CredentialGuard = {
|
|
|
45
45
|
isDangerousBashCommand: (command: string) => boolean;
|
|
46
46
|
getBlockedCliTool: (command: string) => { name: string; wrapper: string } | null;
|
|
47
47
|
isGhCommandAllowed: (command: string) => boolean;
|
|
48
|
+
detectSleepPolling: (command: string) => string | null;
|
|
48
49
|
};
|
|
49
50
|
|
|
50
51
|
// ============================================================================
|
|
@@ -184,6 +185,34 @@ const DEFAULT_BLOCKED_CLI_TOOLS: BlockedCliTool[] = [
|
|
|
184
185
|
},
|
|
185
186
|
];
|
|
186
187
|
|
|
188
|
+
type PollingDetectionRule = {
|
|
189
|
+
pattern: RegExp;
|
|
190
|
+
suggestion: string;
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const DEFAULT_POLLING_DETECTION_RULES: PollingDetectionRule[] = [
|
|
194
|
+
{
|
|
195
|
+
pattern: /workflow\s+(?:list|view|jobs|logs|job-logs)\b/,
|
|
196
|
+
suggestion: "bun agent-tools-gh workflow watch --run <ID>",
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
pattern: /pr\s+checks(?![\w-])(?!.*--watch)/,
|
|
200
|
+
suggestion: "bun agent-tools-gh pr checks --pr <N> --watch",
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
pattern: /pr\s+rerun-checks\b/,
|
|
204
|
+
suggestion: "bun agent-tools-gh pr checks --pr <N> --watch (after rerun completes)",
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
pattern: /kubectl\b/,
|
|
208
|
+
suggestion: 'bun agent-tools-k8s kubectl --env <env> --cmd "wait --for=condition=..."',
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
pattern: /\bpipelines?\s+runs?\b/,
|
|
212
|
+
suggestion: "bun agent-tools-az build summary --build-id <ID>",
|
|
213
|
+
},
|
|
214
|
+
];
|
|
215
|
+
|
|
187
216
|
/**
|
|
188
217
|
* Read-only gh subcommands safe on external repos with -R flag.
|
|
189
218
|
*/
|
|
@@ -325,6 +354,17 @@ export function createCredentialGuard(config?: CredentialGuardConfig): Credentia
|
|
|
325
354
|
return ghSegments.every((segment) => isGhCommandAllowed(segment.trim()));
|
|
326
355
|
}
|
|
327
356
|
|
|
357
|
+
function detectSleepPolling(command: string): string | null {
|
|
358
|
+
if (!/\bsleep\s+\d+/.test(command)) return null;
|
|
359
|
+
|
|
360
|
+
for (const { pattern, suggestion } of DEFAULT_POLLING_DETECTION_RULES) {
|
|
361
|
+
if (pattern.test(command)) {
|
|
362
|
+
return suggestion;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
return null;
|
|
366
|
+
}
|
|
367
|
+
|
|
328
368
|
function getBlockedCliTool(command: string): { name: string; wrapper: string } | null {
|
|
329
369
|
for (const { pattern, name, wrapper } of blockedCliTools) {
|
|
330
370
|
if (pattern.test(command)) {
|
|
@@ -390,6 +430,17 @@ export function createCredentialGuard(config?: CredentialGuardConfig): Credentia
|
|
|
390
430
|
);
|
|
391
431
|
}
|
|
392
432
|
|
|
433
|
+
const sleepSuggestion = detectSleepPolling(command);
|
|
434
|
+
if (sleepSuggestion) {
|
|
435
|
+
throw new Error(
|
|
436
|
+
`\u{26A0}\u{FE0F} Sleep-polling detected.\n\n` +
|
|
437
|
+
`Instead of polling with sleep, use the built-in watch command:\n\n` +
|
|
438
|
+
`Use instead: ${sleepSuggestion}\n\n` +
|
|
439
|
+
`Watch commands block until completion — no polling needed.\n\n` +
|
|
440
|
+
`→ Skill "agent-tools"`,
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
|
|
393
444
|
const blockedTool = getBlockedCliTool(command);
|
|
394
445
|
if (blockedTool) {
|
|
395
446
|
throw new Error(
|
|
@@ -412,6 +463,7 @@ export function createCredentialGuard(config?: CredentialGuardConfig): Credentia
|
|
|
412
463
|
isDangerousBashCommand,
|
|
413
464
|
getBlockedCliTool,
|
|
414
465
|
isGhCommandAllowed,
|
|
466
|
+
detectSleepPolling,
|
|
415
467
|
};
|
|
416
468
|
}
|
|
417
469
|
|
|
@@ -441,3 +493,6 @@ export const getBlockedCliTool = defaultGuard.getBlockedCliTool;
|
|
|
441
493
|
|
|
442
494
|
/** Check if a gh command is allowed (default guard). */
|
|
443
495
|
export const isGhCommandAllowed = defaultGuard.isGhCommandAllowed;
|
|
496
|
+
|
|
497
|
+
/** Detect sleep-polling with agent-tools wrapper commands (default guard). */
|
|
498
|
+
export const detectSleepPolling = defaultGuard.detectSleepPolling;
|