feat: add auto-clear, timed respawn, and enable on existing sessions

- Add token tracking to Session class (input/output tokens)
- Add auto-clear feature that sends /clear when token threshold reached
- Add API endpoint to enable respawn on existing running sessions
- Add timed duration setting for respawn (auto-stops after N minutes)
- Add TaskTracker class for background task detection and tree display
- Update UI with duration input, auto-clear settings, and "Enable on Current" button
- Add respawn timer display in banner when timed run is active
- Add token count display in respawn banner

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
arkon
2026-01-19 00:38:11 +01:00
co-authored by Claude Opus 4.5
parent fd9254d8e5
commit ad99fe5922
8 changed files with 2240 additions and 2779 deletions
+20 -2
View File
@@ -26,6 +26,10 @@ export interface RespawnConfig {
interStepDelayMs: number;
/** Whether to enable respawn loop */
enabled: boolean;
/** Whether to send /clear after update prompt */
sendClear: boolean;
/** Whether to send /init after /clear */
sendInit: boolean;
}
export interface RespawnEvents {
@@ -43,6 +47,8 @@ const DEFAULT_CONFIG: RespawnConfig = {
updatePrompt: 'update all the docs and CLAUDE.md',
interStepDelayMs: 1000, // 1 second between steps
enabled: true,
sendClear: true, // send /clear after update prompt
sendInit: true, // send /init after /clear
};
/**
@@ -306,7 +312,14 @@ export class RespawnController extends EventEmitter {
if (this.promptDetected && !this.workingDetected) {
this.log('Update docs completed');
this.emit('stepCompleted', 'update');
this.sendClear();
// Proceed based on config
if (this.config.sendClear) {
this.sendClear();
} else if (this.config.sendInit) {
this.sendInit();
} else {
this.completeCycle();
}
}
}, 3000); // 3 second verification
}
@@ -332,7 +345,12 @@ export class RespawnController extends EventEmitter {
this.idleTimer = setTimeout(() => {
this.log('/clear completed');
this.emit('stepCompleted', 'clear');
this.sendInit();
// Proceed based on config
if (this.config.sendInit) {
this.sendInit();
} else {
this.completeCycle();
}
}, 1000); // 1 second for clear
}
}