mirror of
https://github.com/PR0M3TH3AN/TORCH.git
synced 2026-10-27 07:51:52 +00:00
Merge pull request #191 from PR0M3TH3AN/agents/daily/docs-code-investigator-run-2026-02-16-16816399662529169809
Scheduler Daily Run: docs-code-investigator
This commit is contained in:
6 files changed
+116
No files matched your search
@@ -0,0 +1,50 @@
|
||||
# `src/lock-ops.mjs` Overview
|
||||
|
||||
This module implements the core logic for distributed locking using Nostr relays. It handles querying for existing locks, publishing new lock events, and managing relay health and fallbacks.
|
||||
|
||||
## High-Level Summary
|
||||
The `lock-ops` module provides the mechanism for agents to coordinate and avoid race conditions. It uses ephemeral Nostr events (Kind `30078` parameterized replaceable events, though currently using `app_data`) to represent locks. It includes robust retry logic, relay health scoring, and fallback mechanisms to ensure reliability even when some relays are slow or offline.
|
||||
|
||||
## Public Surface
|
||||
|
||||
### `queryLocks(relays, cadence, dateStr, namespace, deps)`
|
||||
Queries the specified relays for active locks matching the cadence and date.
|
||||
- **relays**: Array of relay URLs.
|
||||
- **cadence**: 'daily' or 'weekly'.
|
||||
- **dateStr**: Date string (YYYY-MM-DD).
|
||||
- **namespace**: Application namespace (e.g., 'torch').
|
||||
- **Returns**: Array of active lock objects.
|
||||
|
||||
### `publishLock(relays, event, deps)`
|
||||
Publishes a lock event to the specified relays, ensuring a quorum is met.
|
||||
- **relays**: Array of relay URLs.
|
||||
- **event**: The Nostr event object to publish.
|
||||
- **Returns**: The published event if successful, throws error otherwise.
|
||||
|
||||
### `parseLockEvent(event)`
|
||||
Parses a raw Nostr event into a structured lock object.
|
||||
- **event**: Raw Nostr event.
|
||||
- **Returns**: Structured lock object with `agent`, `cadence`, `expiresAt`, etc.
|
||||
|
||||
## Key Flows
|
||||
|
||||
1. **Lock Acquisition**:
|
||||
- `queryLocks` is called to check for existing locks.
|
||||
- If no valid lock exists, a new lock event is created (external to this module).
|
||||
- `publishLock` is called to broadcast the event.
|
||||
- Race check (reading back) confirms ownership (handled by caller, `src/lib.mjs`).
|
||||
|
||||
2. **Relay Health & Fallback**:
|
||||
- Relays are scored based on latency and success rate.
|
||||
- Failed attempts penalize the relay score.
|
||||
- If primary relays fail, fallback relays are used.
|
||||
|
||||
## Invariants
|
||||
- Locks must have an expiration time.
|
||||
- A lock is only valid if it is the latest event for the `d` tag.
|
||||
- Publishing requires a minimum number of successful relays (quorum).
|
||||
|
||||
## When to Change
|
||||
- If the relay selection or scoring algorithm needs tuning.
|
||||
- If the underlying Nostr event structure changes.
|
||||
- If new telemetry or logging requirements arise.
|
||||
@@ -0,0 +1,14 @@
|
||||
# Context
|
||||
- Agent: docs-code-investigator
|
||||
- Cadence: daily
|
||||
- Run-Start: 2026-02-16T02:11:24Z
|
||||
- Prompt Path: src/prompts/daily/docs-code-investigator.md
|
||||
|
||||
## Goal
|
||||
Document `src/lock-ops.mjs` to improve codebase understandability.
|
||||
|
||||
## Scope
|
||||
`src/lock-ops.mjs` overview and high-level documentation.
|
||||
|
||||
## Constraints
|
||||
No code changes to logic. Documentation only.
|
||||
@@ -0,0 +1,11 @@
|
||||
# Decisions
|
||||
- Agent: docs-code-investigator
|
||||
- Cadence: daily
|
||||
- Run-Start: 2026-02-16T02:11:24Z
|
||||
- Prompt Path: src/prompts/daily/docs-code-investigator.md
|
||||
|
||||
## Decision
|
||||
Create `docs/src-lock-ops-overview.md` instead of extensive inline comments.
|
||||
|
||||
## Rationale
|
||||
To keep the source file clean while providing a comprehensive overview of the complex locking logic and relay interactions.
|
||||
@@ -0,0 +1,15 @@
|
||||
# Test Log
|
||||
- Agent: docs-code-investigator
|
||||
- Cadence: daily
|
||||
- Run-Start: 2026-02-16T02:11:24Z
|
||||
- Prompt Path: src/prompts/daily/docs-code-investigator.md
|
||||
|
||||
- Command: git ls-files '*.mjs' | xargs -n1 wc -l | sort -rn | head -n 20
|
||||
- Result:
|
||||
1079 scripts/agent/run-scheduler-cycle.mjs
|
||||
726 src/lib.mjs
|
||||
586 src/lock-ops.mjs
|
||||
...
|
||||
|
||||
- Command: npm run lint
|
||||
- Result: 0 errors, 11 warnings (passed)
|
||||
@@ -0,0 +1,12 @@
|
||||
# Todo
|
||||
- Agent: docs-code-investigator
|
||||
- Cadence: daily
|
||||
- Run-Start: 2026-02-16T02:11:24Z
|
||||
- Prompt Path: src/prompts/daily/docs-code-investigator.md
|
||||
|
||||
## Pending Tasks
|
||||
- [ ] [pending] Review `src/lock-ops.mjs`
|
||||
|
||||
## Completed Tasks
|
||||
- [x] [completed] Select candidate file (`src/lock-ops.mjs`)
|
||||
- [x] [completed] Create overview document
|
||||
@@ -0,0 +1,14 @@
|
||||
---
|
||||
cadence: daily
|
||||
agent: docs-code-investigator
|
||||
status: completed
|
||||
reason: 'Scheduler cycle completed successfully'
|
||||
created_at: '2026-02-16T02:11:24.000Z'
|
||||
timestamp: '2026-02-16T02:11:24.000Z'
|
||||
platform: jules
|
||||
---
|
||||
|
||||
# Scheduler completed
|
||||
|
||||
- reason: Scheduler cycle completed successfully
|
||||
- platform: jules
|
||||
Reference in new issue
Block a user