Commit Graph
39 Commits
Author SHA1 Message Date
google-labs-jules[bot]andPR0M3TH3AN 74950ca1a9 Decomposed scripts/agent/run-scheduler-cycle.mjs into modular components
Extracted logic into scheduler-config.mjs, scheduler-logger.mjs, and scheduler-state.mjs to improve maintainability and reduce file size (1160 -> 827 lines). Corrected module imports and verified via linting and dry-run usage.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-27 00:15:50 +00:00
thePR0M3TH3AN 1e3f88e488 Fix Windows-unsafe artifact filenames and enforce safe timestamp format 2026-02-25 21:07:32 -05:00
thePR0M3TH3AN 1fa4d4560e Fix host-repo scheduler config resolution and handoff defaults 2026-02-25 14:48:11 -05:00
google-labs-jules[bot]andPR0M3TH3AN 003e18b93b Fix CI lint error in lock-publisher.mjs
- Ensure `src/lock-publisher.mjs` does not import `randomInt`.
- Clean up test output artifacts.
- Re-verify tests pass locally.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-21 20:48:15 +00:00
thePR0M3TH3AN 9fef4c4f46 update 2026-02-21 15:16:45 -05:00
thePR0M3TH3AN 2b8a0c3d0d update 2026-02-20 12:51:17 -05:00
thePR0M3TH3ANandClaude Sonnet 4.6 a5f08ff082 feat(scheduler): add local time-window guard to prevent within-window re-runs
Adds a cadence-aware time-window check that runs after the Nostr relay lock
check to exclude agents that already ran within the current window (24h daily,
7d weekly). This closes the cross-midnight edge case where the relay's
date-scoped d-tag rolls over but the agent ran minutes ago.

Changes:
- scheduler-utils.mjs: export log-parsing helpers (parseDateValue,
  parseTimestampFromFilename, parseAgentFromFilename, isStrictSchedulerLogFilename,
  parseFrontmatterCreatedAt, parseFrontmatterAgent, parseFrontmatterValue) plus
  CADENCE_WINDOW_MS constant and buildRecentlyRunExclusionSet(). Helpers are
  exported so they can be unit-tested independently. Adds 'node:path' import.
- run-scheduler-cycle.mjs: import the moved helpers from utils (removes ~45 lines
  of duplicate definitions), call buildRecentlyRunExclusionSet after excludedSet
  is built from relay data, merge results, log newly-excluded agents. Adds cycle
  saturation detection: when all roster agents are covered by the time-window
  guard, exit 0 with a clear "Cycle complete" message instead of a failure.
- test/scheduler-time-window.test.mjs: 30 new scenario-first unit tests covering
  SCN-TWG-01..11 (in-window exclusion, out-of-window pass-through, cross-midnight,
  frontmatter precedence, weekly threshold, empty dir, missing dir, deferred
  log passthrough, mixed rosters, anti-cheat for non-log files).

All 30 new tests pass. Existing scheduler-ratchet tests (7) still pass.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
2026-02-20 11:05:52 -05:00
google-labs-jules[bot]andPR0M3TH3AN 9278dadab0 Print final run summary in scheduler cycle and prompts
Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-20 04:50:26 +00:00
google-labs-jules[bot]andPR0M3TH3AN ae2e382bfd Fix: Correctly detect agent platform for locks
- Updated `src/utils.mjs` to detect 'claude' platform via `CLAUDE_API_KEY`, `ANTHROPIC_API_KEY`, or `CLAUDE_SESSION_ID`.
- Updated `scripts/agent/scheduler-utils.mjs` `getSafeEnv` to preserve `JULES_`, `CODEX_`, `CLAUDE_`, `ANTHROPIC_`, and `GOOSE_` environment variables when spawning child processes.
- Updated `scripts/agent/run-scheduler-cycle.mjs` to use `detectPlatform()` as a fallback for `AGENT_PLATFORM` instead of hardcoding `'codex'`, ensuring the correct platform is used for lock creation.
- Added unit tests for `detectPlatform` in `test/utils.test.mjs`.

This resolves the issue where lock cards displayed "Unknown" or incorrect platforms.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-18 21:42:56 +00:00
google-labs-jules[bot]andPR0M3TH3AN 9e993800fa [scheduler] daily/decompose-agent: Decompose scripts/agent/run-scheduler-cycle.mjs
- Executed daily scheduler cycle.
- Selected `decompose-agent` (next in roster).
- Decomposed `scripts/agent/run-scheduler-cycle.mjs` (1127 lines) into `scripts/agent/scheduler-utils.mjs` (195 lines) and `scripts/agent/scheduler-lock.mjs` (173 lines).
- Resulting main file size: 788 lines (339 lines reduction).
- Fixed lint warnings.
- Updated `test/scheduler-preflight-lock.e2e.test.mjs`, `test/run-scheduler-cycle-memory-policy.test.mjs`, `test/scheduler-lock-failure-schema.contract.test.mjs` to copy new modules into test fixtures.
- Updated `test/scheduler-ratchet.test.mjs` to verify moved functions in `scheduler-lock.mjs`.
- Note: `scripts/check-file-size.mjs` was not updated as it lacks the baseline feature referenced in the prompt.
- Created artifacts: `src/context/CONTEXT_...`, `src/decisions/DECISIONS_...`, `src/test_logs/TEST_LOG_...`, `src/todo/TODO_...`.
- Created scheduler log: `task-logs/daily/2026-02-17T22-29-00Z__decompose-agent__completed.md`.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-17 22:41:37 +00:00
google-labs-jules[bot]andPR0M3TH3AN bd9641a536 Sanitize environment variables in run-scheduler-cycle.mjs
Prevent sensitive environment variables from leaking into child processes spawned by the scheduler. Introduce `getSafeEnv` whitelist and default `runCommand` to use it. Explicitly allow system, node, CI, and application-specific (NOSTR_, TORCH_, SCHEDULER_, AGENT_) variables. Removed `inheritProcessEnv: true` from user commands to enforce this security policy. Added `Path` support for Windows.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-17 18:59:10 +00:00
thePR0M3TH3AN b3f4a5c9cd Merge pull request #242 from PR0M3TH3AN/scheduler-cycle-optimization-6566135138689301144
⚡ Optimize scheduler cycle log reading performance
2026-02-17 13:38:36 -05:00
google-labs-jules[bot]andPR0M3TH3AN 32ba0d2621 perf(scheduler): parallelize log file reading in getLatestFile
Optimizes the `getLatestFile` function in `scripts/agent/run-scheduler-cycle.mjs` by parallelizing the reading and parsing of log files using `Promise.all`. This replaces the sequential `for...of` loop which caused I/O bottlenecks when processing large numbers of log files.

Measured improvement: ~56% faster (530ms -> 207ms) for 1000 log files.

Also removed a tracked `test_output.log` file that shouldn't be in the repository.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-17 18:37:39 +00:00
google-labs-jules[bot]andPR0M3TH3AN 3d459ef905 perf(scheduler): parallelize artifact checks in verifyMemoryStep
Optimize the `verifyMemoryStep` function in `scripts/agent/run-scheduler-cycle.mjs` to check for artifact existence in parallel using `Promise.all` instead of a sequential loop.

Benchmarks indicate a ~10x performance improvement (from ~500ms to ~50ms) when checking for 10 artifacts where none or the last one exists, with no regression in the best-case scenario.

Verified with `test/run-scheduler-cycle-memory-policy.test.mjs`.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-17 18:32:46 +00:00
google-labs-jules[bot]andPR0M3TH3AN fa4c9ca175 perf: optimize lock failure reason summarization
Replace inefficient `[...events].reverse().find()` with `events.findLast()`.
This avoids a shallow copy of the array and an in-place reverse,
improving performance from O(N) space/time to O(1) space and O(N) time
(where N is the number of events searched).

In benchmarks with 100,000 events:
- Element near the end: 99.9% improvement (~0.8ms vs ~950ms)
- Element at the beginning: ~42% improvement (~145ms vs ~250ms)

Node.js v18.6.0+ is required for `findLast`, which is supported in the
current environment (v22.22.0).

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-17 17:11:16 +00:00
google-labs-jules[bot]andPR0M3TH3AN 2a39713189 feat(scheduler): generate unique memory update files per run to avoid merge conflicts
- Modified `scripts/agent/run-scheduler-cycle.mjs` to generate a unique `memory-updates/<timestamp>__<agent>.md` path and pass it via `SCHEDULER_MEMORY_FILE` env var.
- Updated `scripts/memory/store.mjs` to prioritize `SCHEDULER_MEMORY_FILE` for ingestion.
- Updated `src/prompts/scheduler-flow.md` to instruct agents to write to the unique memory file.
- Updated `src/prompts/daily/torch-garbage-collection-agent.md` to include `memory-updates/*.md` in the cleanup scope.
- Moved existing `memory-update.md` to `memory-updates/legacy-memory-update-<timestamp>.md` to clear the root.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-17 15:19:52 +00:00
google-labs-jules[bot]andPR0M3TH3AN d02fa41079 fix(scheduler): relax prompt validation and correct default lint command
- Update `scripts/agent/run-scheduler-cycle.mjs` to allow prompt files to start with a blockquote (`>`) in addition to a markdown header (`#`), unblocking agents with shared contract headers.
- Fix default validation command from `['npm', 'run', 'lint']` to `['npm run lint']` to prevent `npm` usage errors.
- Include daily task logs demonstrating successful scheduler cycle execution (skipping failed locks and completing `load-test-agent`).

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-16 16:33:37 +00:00
thePR0M3TH3AN 118c365022 Merge branch 'main' into feat/nostr-platform-model-info-17811919130475421613 2026-02-15 17:41:19 -05:00
google-labs-jules[bot]andPR0M3TH3AN 754a1c2ce1 feat: support platform and model info in nostr lock events
This change enables agents to report their execution platform (e.g., Jules, Codex, Goose) and model (e.g., DeepSeek 3.2) in the Nostr lock events.

Key changes:
- Updated `torch-lock` CLI to accept `--platform` and `--model` arguments.
- Implemented `detectPlatform` utility to infer platform from environment variables if not provided.
- Updated `src/lib.mjs` to include these fields in the event content.
- Updated `scripts/agent/run-scheduler-cycle.mjs` to propagate `--model` and `AGENT_MODEL`.
- Updated `dashboard/index.html` to display the model information on the lock card.
- Fixed a regression in `scripts/validate-scheduler-flow-parity.mjs` and `test/scheduler-ratchet.test.mjs` caused by argument string matching.
- Deleted `repro_test.mjs` temporary file.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-15 20:18:59 +00:00
google-labs-jules[bot]andPR0M3TH3AN 512a0413c7 feat: truncate logs and inject memory into prompts to reduce token burn
This change implements several optimizations to reduce token consumption and improve agent context:

1.  **Log Truncation**: `scripts/agent/run-scheduler-cycle.mjs` now truncates the echoed output of spawned processes to 20KB per stream (stdout/stderr). This prevents the scheduler agent's context from being flooded with excessive logs from sub-agents.
2.  **Memory Injection**: `torch-config.json`'s `retrieveCommand` has been updated to write retrieved memories to `.scheduler-memory/latest/<cadence>/memories.md`. `scripts/agent/run-selected-prompt.mjs` now checks for this file and injects its content into the agent's prompt, providing immediate context from the memory system.
3.  **CLI Optimization**: The `torch-lock list-memories` command now truncates the `content` field of memories to 200 characters by default. A new `--full` flag has been added to `src/cli-parser.mjs` and `src/lib.mjs` to view the full content when needed.

These changes aim to make the agent process more efficient ("error on the side of caution") and leverage the memory system more effectively.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-15 19:55:20 +00:00
thePR0M3TH3AN c20af61643 making Torch more Goose friendly 2026-02-15 14:27:11 -05:00
thePR0M3TH3AN 969b72d3e1 Add scheduler error rendering snapshot coverage 2026-02-14 20:10:26 -05:00
thePR0M3TH3AN c1d0de071c test: add scheduler lock failure frontmatter contract coverage 2026-02-14 20:01:32 -05:00
thePR0M3TH3AN ccc76d8b51 Add scheduler lock preflight e2e coverage 2026-02-14 19:56:25 -05:00
thePR0M3TH3AN 874747de91 Classify scheduler failures and document lock remediation 2026-02-14 19:42:03 -05:00
thePR0M3TH3AN 1e97118e8b Add relay health preflight job and scheduler deferral handling 2026-02-14 19:35:56 -05:00
thePR0M3TH3AN 46198a500e Improve lock publish diagnostics and scheduler failure summaries 2026-02-14 19:30:00 -05:00
thePR0M3TH3AN 9aad0d933d Add lock deferral policy for scheduler backend failures 2026-02-14 19:23:37 -05:00
thePR0M3TH3AN ecb26dfa99 Improve scheduler lock observability and reliability reporting 2026-02-14 18:42:52 -05:00
thePR0M3TH3AN bc51e2f2e8 Add scheduler relay health preflight gate 2026-02-14 18:36:01 -05:00
thePR0M3TH3AN 9c069f75a6 Add scheduler lock retries for backend failures 2026-02-14 18:29:55 -05:00
thePR0M3TH3AN c38dfe1258 Enrich scheduler lock backend failure logging 2026-02-14 18:23:52 -05:00
thePR0M3TH3AN 827c7038c9 Harden scheduler log candidate selection 2026-02-14 18:10:29 -05:00
thePR0M3TH3AN 909a7f9541 Strengthen run-artifact verification metadata and issue linkage 2026-02-14 18:05:54 -05:00
thePR0M3TH3AN 5e74287a57 Align scheduler flow docs with runtime behavior 2026-02-14 17:28:31 -05:00
thePR0M3TH3AN d997963ea7 Enforce scheduler memory workflow and verification 2026-02-14 17:05:47 -05:00
thePR0M3TH3AN 5221225a1f Add scheduler run artifact compliance gate 2026-02-14 17:01:23 -05:00
thePR0M3TH3AN a48f8743f4 Require scheduler handoff command for valid task execution 2026-02-14 16:58:56 -05:00
thePR0M3TH3AN fce1256200 feat(scheduler): add single-command scheduler cycle runner 2026-02-14 16:51:55 -05:00