[Refactor] Unify Skip List Logic Across All Agent Loops into a Shared Library #1417

Closed
opened 2026-03-24 13:04:32 +00:00 by Timmy · 1 comment
Owner

Context: timmy-loop.sh, kimi-loop.sh, and claude-loop.sh duplicate inline JSON skip-list interactions via python3 -c.

Acceptance Criteria:

  • Abstract skip-list operations into a standard python package inside the repository.
  • Utilize standard file locking.
**Context:** `timmy-loop.sh`, `kimi-loop.sh`, and `claude-loop.sh` duplicate inline JSON skip-list interactions via `python3 -c`. **Acceptance Criteria:** - Abstract skip-list operations into a standard python package inside the repository. - Utilize standard file locking.
Author
Owner

KIMI IMPLEMENTATION INSTRUCTIONS:

Unify the duplicated skip-list logic across all agent loops into a reusable library.

FILES TO CREATE:

src/infrastructure/agent_loops/__init__.py
src/infrastructure/agent_loops/skip_list.py
src/infrastructure/agent_loops/file_lock.py
tests/infrastructure/test_skip_list.py

FILES TO MODIFY:

scripts/timmy-loop.sh
scripts/kimi-loop.sh
scripts/claude-loop.sh

STEP-BY-STEP IMPLEMENTATION:

  1. Create Skip List Core (src/infrastructure/agent_loops/skip_list.py):

    • SkipListManager class with load(), save(), add_item(), remove_item(), contains()
    • JSON file handling with atomic writes
    • Integration with file locking for concurrent access
    • Proper error handling and validation
  2. Create File Locking (src/infrastructure/agent_loops/file_lock.py):

    • FileLock context manager using fcntl (Unix) or msvcrt (Windows)
    • Timeout handling for lock acquisition
    • Automatic cleanup on context exit
  3. Update Agent Scripts - Replace inline JSON operations:

    • timmy-loop.sh: Replace python3 -c JSON operations with library calls
    • kimi-loop.sh: Same refactoring
    • claude-loop.sh: Same refactoring
    • Preserve existing command-line interfaces
  4. Add Comprehensive Tests (tests/infrastructure/test_skip_list.py):

    • Test JSON loading/saving
    • Test concurrent access with multiple processes
    • Test file locking behavior
    • Test error conditions (corrupted JSON, permission errors)

VERIFICATION:

  • Run tox -e unit - all tests must pass
  • All three agent scripts should work identically to before
  • Skip list operations should be thread-safe with proper locking
  • No race conditions in concurrent skip list access

CRITICAL: Preserve exact behavior of existing scripts while removing code duplication.

PROCEED WITH IMPLEMENTATION.

**KIMI IMPLEMENTATION INSTRUCTIONS:** Unify the duplicated skip-list logic across all agent loops into a reusable library. **FILES TO CREATE:** ``` src/infrastructure/agent_loops/__init__.py src/infrastructure/agent_loops/skip_list.py src/infrastructure/agent_loops/file_lock.py tests/infrastructure/test_skip_list.py ``` **FILES TO MODIFY:** ``` scripts/timmy-loop.sh scripts/kimi-loop.sh scripts/claude-loop.sh ``` **STEP-BY-STEP IMPLEMENTATION:** 1. **Create Skip List Core** (`src/infrastructure/agent_loops/skip_list.py`): - SkipListManager class with load(), save(), add_item(), remove_item(), contains() - JSON file handling with atomic writes - Integration with file locking for concurrent access - Proper error handling and validation 2. **Create File Locking** (`src/infrastructure/agent_loops/file_lock.py`): - FileLock context manager using fcntl (Unix) or msvcrt (Windows) - Timeout handling for lock acquisition - Automatic cleanup on context exit 3. **Update Agent Scripts** - Replace inline JSON operations: - timmy-loop.sh: Replace python3 -c JSON operations with library calls - kimi-loop.sh: Same refactoring - claude-loop.sh: Same refactoring - Preserve existing command-line interfaces 4. **Add Comprehensive Tests** (`tests/infrastructure/test_skip_list.py`): - Test JSON loading/saving - Test concurrent access with multiple processes - Test file locking behavior - Test error conditions (corrupted JSON, permission errors) **VERIFICATION:** - Run `tox -e unit` - all tests must pass - All three agent scripts should work identically to before - Skip list operations should be thread-safe with proper locking - No race conditions in concurrent skip list access **CRITICAL:** Preserve exact behavior of existing scripts while removing code duplication. PROCEED WITH IMPLEMENTATION.
kimi was assigned by Timmy 2026-03-24 15:06:45 +00:00
kimi was unassigned by Timmy 2026-03-24 19:32:19 +00:00
Timmy closed this issue 2026-03-24 21:54:09 +00:00
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#1417