feat: 集成 openclaw-zero-token 反检测策略(Profile装饰、干净退出欺骗、AIMD反封延迟)

This commit is contained in:
2026-05-15 17:31:22 +08:00
parent 84a3a7bfe4
commit a1b6a76b8c
3 changed files with 107 additions and 1 deletions
@@ -348,6 +348,14 @@ close 参数:
emit('progress', { step: 'connect', message: `Continuing session: ${sessionId} (mode: ${mode})` });
// Don't navigate — stay on the current chat page for multi-round
continuedSession = true;
// AIMD anti-ban delay: break fixed-interval pattern between successive requests
const baseDelay = parseInt(process.env.GEMINI_BASE_DELAY, 10) || 15;
const maxDelay = parseInt(process.env.GEMINI_MAX_DELAY, 10) || 120;
const jitter = Math.random() * 5;
const delaySec = Math.min(maxDelay, baseDelay * 0.7 + jitter);
emit('progress', { step: 'anti-ban', message: `AIMD delay ${delaySec.toFixed(1)}s (breaking fixed-interval pattern)` });
await sleep(delaySec * 1000);
} else if (args.chatUrl) {
emit('progress', { step: 'navigate', message: `Navigating to chat URL: ${args.chatUrl}` });
await page.goto(args.chatUrl, { waitUntil: 'domcontentloaded', timeout: 60000 });
@@ -0,0 +1,64 @@
/**
* Anti-ban adaptive delay controller.
* AIMD (Additive Increase Multiplicative Decrease) algorithm.
* - Success: delay *= 0.7 (minimum: baseDelay * 0.5)
* - Rate limit / timeout: delay *= 2 (maximum: maxDelay)
* - Each wait adds 0-jitterMax seconds of random jitter
*/
export interface AntiBanConfig {
baseDelay: number; // seconds
maxDelay: number; // seconds
jitterMax: number; // seconds
}
const DEFAULT_CONFIG: AntiBanConfig = {
baseDelay: Number(process.env.GEMINI_BASE_DELAY) || 15,
maxDelay: Number(process.env.GEMINI_MAX_DELAY) || 120,
jitterMax: 5,
};
export class AntiBanController {
private currentDelay: number;
private config: AntiBanConfig;
retryCount = 0;
rateLimitEvents = 0;
constructor(config?: Partial<AntiBanConfig>) {
this.config = { ...DEFAULT_CONFIG, ...config };
this.currentDelay = this.config.baseDelay;
}
/** Call after a successful generation */
onSuccess(): void {
this.currentDelay = Math.max(this.config.baseDelay * 0.5, this.currentDelay * 0.7);
}
/** Call after rate limit / timeout / error */
onRateLimit(): void {
this.rateLimitEvents++;
this.currentDelay = Math.min(this.config.maxDelay, this.currentDelay * 2);
}
/** Wait between requests with jitter */
async wait(): Promise<void> {
const jitter = Math.random() * this.config.jitterMax;
const totalMs = (this.currentDelay + jitter) * 1000;
const log = (await import('./browser.js')).log;
log(`[anti-ban] waiting ${(totalMs / 1000).toFixed(1)}s (base=${this.currentDelay.toFixed(1)}s, jitter=${jitter.toFixed(1)}s)`);
await new Promise((r) => setTimeout(r, totalMs));
}
get delay(): number {
return this.currentDelay;
}
/** Stats for logging */
get stats() {
return {
currentDelay: this.currentDelay,
rateLimitEvents: this.rateLimitEvents,
retryCount: this.retryCount,
};
}
}