feat: comprehensive codebase improvements (cleanup, logic, performance)

Code Cleanups:
- Consolidated PlanTaskStatus and TddPhase types to types.ts
- Standardized node: prefix for Node.js builtin imports
- Fixed timer type to NodeJS.Timeout in respawn-controller

Logic Improvements:
- Fixed AI check race condition with UUID tracking in respawn-controller
- Added comprehensive _isStopped guards in session timer callbacks
- Made RalphTracker reset events non-reentrant via process.nextTick()
- Improved SessionManager mutex pattern reliability

Performance Optimizations:
- Fixed pendingToolCalls memory leak with TTL cleanup in subagent-watcher
- Improved LRUMap.newest() from O(n) to O(1) with _newestKey tracking

Documentation:
- Enhanced README antiflicker section with 6-layer technical details

Version: 0.1441

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
arkon
2026-01-30 19:05:46 +01:00
co-authored by Claude Opus 4.5
parent ea81d94173
commit 20283019f4
17 changed files with 342 additions and 820 deletions
+54
View File
@@ -1159,6 +1159,60 @@ describe('SubagentWatcher', () => {
expect(updatedInfo.description).toBeDefined();
expect(updatedInfo.description).toContain('Create unit tests');
});
it('should extract description from parent transcript toolUseResult', async () => {
// Create parent transcript with toolUseResult containing agentId and description
const parentTranscript = JSON.stringify({
type: 'user',
timestamp: new Date().toISOString(),
message: { role: 'user', content: [] },
toolUseResult: {
isAsync: true,
status: 'async_launched',
agentId: 'parentdesc',
description: 'Research codebase cleanups',
},
});
const mockRl = new EventEmitter();
mockCreateInterface.mockReturnValue(mockRl);
mockCreateReadStream.mockReturnValue({});
mockExistsSync.mockReturnValue(true);
mockReaddirSync.mockImplementation((path: string) => {
if (path.includes('subagents')) return ['agent-parentdesc.jsonl'];
if (path.includes('session1')) return ['subagents'];
if (path.includes('project1')) return ['session1'];
return ['project1'];
});
mockStatSync.mockReturnValue({
isDirectory: () => true,
birthtime: new Date(),
mtime: new Date(),
size: 100,
});
// Return parent transcript when reading the session transcript
// Return empty for subagent file (will fall back, but we want to test parent extraction)
mockReadFileSync.mockImplementation((filepath: string) => {
if (filepath.includes('session1.jsonl')) {
return parentTranscript;
}
return ''; // Empty subagent file
});
const discoveredHandler = vi.fn();
watcher.on('subagent:discovered', discoveredHandler);
watcher.start();
mockRl.emit('close');
await vi.advanceTimersByTimeAsync(100);
expect(discoveredHandler).toHaveBeenCalled();
const info = discoveredHandler.mock.calls[0][0] as SubagentInfo;
// Should have extracted description from parent transcript
expect(info.description).toBe('Research codebase cleanups');
});
});
describe('getRecentSubagents', () => {