Commit Graph
54 Commits
Author SHA1 Message Date
thePR0M3TH3AN 393ba35f32 feat(memory): add append-only event contract with build/verify CLI 2026-03-01 16:05:53 -05:00
thePR0M3TH3AN 1fb668064e update 2026-02-25 16:17:25 -05:00
google-labs-jules[bot]andPR0M3TH3AN d4649f95a2 chore: scheduler run for decompose-agent
Decomposed src/lib.mjs into src/cmd-check.mjs, src/cmd-list.mjs, and src/cmd-complete.mjs to reduce file size.
Extracted logic preserves existing behavior.
Verified with lint and tests.
Reduced src/lib.mjs by 292 lines.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-21 22:32:13 +00:00
thePR0M3TH3AN 9fef4c4f46 update 2026-02-21 15:16:45 -05:00
google-labs-jules[bot]andPR0M3TH3AN c0c5ac5473 fix(torch-lock): re-apply fixes for circular deps and syntax errors
- Moved `withTimeout` implementation to `src/lock-utils.mjs` and exported it correctly.
- Removed duplicate local definitions of `withTimeout`, `mergeRelayList`, and `secureRandom` in `src/lock-ops.mjs` and `src/lock-publisher.mjs`.
- Fixed imports in `src/lock-ops.mjs`, `src/lock-publisher.mjs`, and `src/relay-health.mjs` to use `src/lock-utils.mjs` consistently.
- Updated `test/utils.test.mjs` and `test/utils-async.test.mjs` to fix broken imports and test definitions.
- Verified `npm run lock:complete` and `npm run scheduler:daily` execute correctly.
- Updated `src/todo/TODO_2026-02-20T03-00-00Z.md` to mark verification task as completed.
- Verified `src/relay-health.mjs` does not use `MINUTE_MS` locally, despite mysterious CI error. Confirmed imports are correct.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-21 19:23:48 +00:00
google-labs-jules[bot]andPR0M3TH3AN 0f6bc97a30 fix(lock): remove unused _getTtl import in src/lib.mjs
- Removed unused `getTtl` import from `src/torch-config.mjs` in `src/lib.mjs` to fix CI lint failure.
- Verified with `npm run lint` and `npm test test/lib.test.mjs`.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-21 18:38:50 +00:00
google-labs-jules[bot]andPR0M3TH3AN 002a1549ba refactor(lock): extract cmdLock to src/cmd-lock.mjs and decompose into helpers
- Extracted `cmdLock` from `src/lib.mjs` to `src/cmd-lock.mjs`.
- Decomposed complex logic into semantic helper functions (`validateRoster`, `performRaceCheck`, etc.).
- Maintained exact functionality and dependency injection pattern.
- Updated `src/lib.mjs` to re-export `cmdLock` for backward compatibility.
- Verified with unit and integration tests.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-21 18:33:44 +00:00
google-labs-jules[bot]andPR0M3TH3AN 8c417264e5 Refactor main switch statement into command handlers
- Extracted command logic from `src/lib.mjs` `main` function into `COMMAND_HANDLERS` dispatch map.
- Simplified `main` function to perform argument parsing and dispatching.
- Added `test/main-dispatch.test.mjs` to verify dispatch logic and error handling.
- Ensured no regressions in CLI behavior.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-20 18:15:30 +00:00
Claude be5ec21d5c feat(governance): add prompt versioning, rollback --list, and state backup
- governance/index.js: archive filenames now include ISO timestamp for
  deterministic sorting (<base>_<ts>_<hash>.md); write .meta.json sidecar
  on every archive with proposalId, author, reason, and archivedAt
- governance/index.js: add listPromptVersions(target) — returns archived
  versions for a prompt sorted newest-first with sidecar metadata surfaced
- cmd-rollback.mjs: add --list flag to list available versions without
  restoring (delegates to listPromptVersions)
- cli-parser.mjs: add --list and --output flags
- lib.mjs: pass list flag to cmdRollback; add backup command dispatch
- cmd-backup.mjs: new torch-lock backup command — snapshots
  .scheduler-memory/memory-store.json and scheduler run state to
  .torch/backups/<timestamp>/; supports --output override and --list
- docs/prompt-versioning.md: comprehensive guide to the full
  proposal → apply → list-versions → rollback workflow, state backup
  and restore procedure, and storage location reference
- test/governance.test.mjs: 7 scenario-based tests (SCN-proposal-create,
  SCN-proposal-list, SCN-proposal-reject, SCN-archive-naming,
  SCN-version-list, SCN-rollback-latest, SCN-rollback-hash)

https://claude.ai/code/session_01Ndq2D72Kp77BYo4owD63uY
2026-02-20 02:27:57 +00:00
Claude 7984c7de66 feat: add torch-lock remove command for complete TORCH uninstallation
Users who installed TORCH via `npm install <tarball> && npx torch-lock init`
had no built-in way to cleanly remove it. This adds a `remove` command that
detects and removes all TORCH artifacts: the torch/ directory, config files,
runtime directories (.torch/, .scheduler-memory/, task-logs/), governance
proposals, host package.json scripts, and the npm package itself.

- Add cmdRemove() in src/ops.mjs with detection, preview, confirmation, and cleanup
- Wire up `remove` command in CLI dispatcher (src/lib.mjs)
- Add TORCH_HOST_SCRIPTS constant in constants.mjs for shared script key list
- Add docs/removal.md with full manual removal instructions
- Add removal section to README.md
- Add 7 scenario tests in test/ops-remove.test.mjs

https://claude.ai/code/session_011Snrxu3iZGLtJ9pnFSajpM
2026-02-20 01:59:30 +00:00
google-labs-jules[bot]andPR0M3TH3AN 2174e8bc4d [constants] Refactor 1000 to MS_PER_SECOND
- Extracted MS_PER_SECOND to src/constants.mjs
- Replaced literal 1000 in src/relay-health.mjs, src/utils.mjs, src/lib.mjs, src/lock-ops.mjs
- Updated test/scheduler-lock-failure-schema.contract.test.mjs to copy constants.mjs
- Added task log and artifacts

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-19 21:34:50 +00:00
google-labs-jules[bot]andPR0M3TH3AN 64b6f43df1 feat: add governance system for prompt evolution
Implement a comprehensive governance system to manage agent prompt changes safely.

Key features:
- **Proposal Workflow:** Prompt changes are now "proposals" stored in `src/proposals/` with metadata and diffs.
- **Governance Agent:** A new `governance-agent` reviews and applies proposals using `scripts/governance/process-proposals.mjs`.
- **Validation:** Strict validation ensures changes are limited to allowed directories (`src/prompts/daily|weekly`) and preserve required headers.
- **Lock Enhancements:** Lock events now include `promptHash`, `promptPath`, and `gitCommit` for full auditability.
- **Rollback:** New `torch-lock rollback` command restores prompts from local history (`.torch/prompt-history/`) or git.
- **CLI:** Added `proposal` (create, list, show, apply, reject) and `rollback` commands.

This establishes a "Stage -> Evaluate -> Apply" gate for prompt evolution, preventing silent drift and ensuring constitutional stability.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-18 21:09:39 +00:00
google-labs-jules[bot]andPR0M3TH3AN 50b0cf5a07 perf: Refactor config loading to be non-blocking async
Replaces synchronous `fs.readFileSync` with `fs.promises.readFile` in `loadTorchConfig` to prevent event loop blocking.
Updates all dependent configuration getters and consumers to use async/await.
Includes benchmark proving non-blocking behavior.
Fixes dashboard tests to properly await server listening.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-17 19:02:46 +00:00
google-labs-jules[bot]andPR0M3TH3AN 24f1853efc refactor(cli): move usage text to constants
Moved the large usage help text from `src/lib.mjs` to `src/constants.mjs` to improve readability and maintainability of the library file.

- Added `USAGE_TEXT` to `src/constants.mjs`.
- Updated `src/lib.mjs` to import and use `USAGE_TEXT`.
- Removed unused `DEFAULT_DASHBOARD_PORT` import from `src/lib.mjs`.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-17 18:35:55 +00:00
google-labs-jules[bot]andPR0M3TH3AN 456bc2df18 feat(security): add authentication and host binding to dashboard
This commit addresses the missing authentication vulnerability in the
dashboard server.

Changes:
- Added Basic Authentication support via TORCH_DASHBOARD_AUTH env var
  or dashboard.auth config field.
- Defaulted dashboard host binding to 127.0.0.1 for better security.
- Added --host CLI argument to allow overriding the bind address.
- Used crypto.timingSafeEqual for secure credential comparison.
- Fixed a potential crash when parsing malformed Authorization headers.
- Added comprehensive unit tests for dashboard authentication.
- Updated documentation in README.md and torch-config.example.json.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-17 17:24:33 +00:00
google-labs-jules[bot]andPR0M3TH3AN c0972af7b6 [decompose] extract getCompletedAgents from src/lib.mjs
Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-15 23:27:29 +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 3156ee0bb5 Merge branch 'main' of https://github.com/PR0M3TH3AN/TORCH 2026-02-15 14:27:20 -05:00
thePR0M3TH3AN c20af61643 making Torch more Goose friendly 2026-02-15 14:27:11 -05:00
google-labs-jules[bot]andPR0M3TH3AN cbc5054b94 feat: make lock event hashtag configurable via config and env var
- Added `getHashtag` function to `src/torch-config.mjs` to resolve hashtag from `NOSTR_LOCK_HASHTAG` env var, `dashboard.hashtag` config, or default to `${namespace}-agent-lock`.
- Updated `src/lib.mjs` to use `getHashtag()` in `cmdLock` and `cmdComplete` for publishing events.
- Updated `dashboard/index.html` to remove hardcoded `#torch-agent-lock` string and rely on dynamic configuration.
- Updated `src/docs/TORCH.md` and `README.md` to document the new configuration options.
- Verified changes with unit tests and frontend verification script.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-15 18:54:46 +00:00
google-labs-jules[bot]andPR0M3TH3AN dba1d43c94 refactor(core): extract parseArgs to cli-parser.mjs
- Extracted `parseArgs` function from `src/lib.mjs` to `src/cli-parser.mjs`.
- Added unit tests for argument parsing logic in `test/cli-parser.test.mjs`.
- Updated `src/lib.mjs` to import `parseArgs`.
- Fixed roster drift in `src/prompts/weekly-scheduler.md` to match `roster.json`.
- Verified with `npm test` and `npm run lint`.
- Completed weekly scheduler task for `refactor-agent`.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-15 15:49:29 +00:00
google-labs-jules[bot]andPR0M3TH3AN 1d4097483c Fix race condition in cmdLock sort order
- Add deterministic tie-breaker (eventId) for lock events with identical timestamps in `src/lib.mjs`.
- Add regression tests in `test/lib.test.mjs` verifying win/loss conditions.
- Create weekly race condition report and run artifacts.
- Mark `race-condition-agent` task as completed.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-15 15:31:28 +00:00
thePR0M3TH3AN 1e97118e8b Add relay health preflight job and scheduler deferral handling 2026-02-14 19:35:56 -05:00
google-labs-jules[bot]andPR0M3TH3AN 426b3221b5 chore(ai): document src/lib.mjs
- Added JSDoc to all exported functions in src/lib.mjs
- Added detailed flow comments for cmdLock and cmdComplete
- Created docs/lib-overview.md with high-level architectural documentation
- Created src/context/CONTEXT_2026-02-14T21-30-00Z.md
- Updated task-logs/daily/ with completion record

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-14 22:09:48 +00:00
thePR0M3TH3AN 7cef8242a1 Add memory admin CLI hooks and safe telemetry events 2026-02-14 15:15:15 -05:00
thePR0M3TH3AN cfe7e9ec8e Merge pull request #84 from PR0M3TH3AN/torch-lock-completion-6824629536982484145
feat: add torch-lock complete command for persistent history
2026-02-14 13:52:44 -05:00
google-labs-jules[bot]andPR0M3TH3AN 7a8bab4b1b I have implemented 'torch-lock complete' for persistent task history. This involved adding cmdComplete to src/lib.mjs to handle permanent completion events, updating cmdLock to prevent locking completed tasks, modifying cmdList to show 'done' status, exposing the command in the CLI, and adding the necessary unit tests.
Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-14 18:46:04 +00:00
google-labs-jules[bot]andPR0M3TH3AN 433b81d2d3 feat: implement scheduler ratcheting by excluding completed tasks
- Update `torch-lock check` to scan `task-logs/<cadence>` for completed tasks.
- Add `--log-dir` and `--ignore-logs` flags to `check` command.
- Implement `getIsoWeekStr` utility for robust weekly cadence checking.
- Ensure completed agents are added to the `excluded` list, enabling the scheduler to skip them.
- Add comprehensive tests for log checking and date utilities.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-14 18:29:20 +00:00
google-labs-jules[bot]andPR0M3TH3AN 6d072448e3 Fix torch-lock init command and update landing page instructions
- Fix multiple syntax errors in `src/lib.mjs` (redundant declarations, broken loops, missing imports).
- Fix syntax error in `src/dashboard.mjs` (invalid catch block).
- Remove redundant local function definitions in `src/lib.mjs` in favor of imports from `src/torch-config.mjs` and `src/utils.mjs`.
- Update `landing/index.html` installation command to include `npx torch-lock init` step.
- Verify `torch-lock init` works correctly.
- Ensure all tests pass and linting is clean for `src/lib.mjs`.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-14 17:45:21 +00:00
thePR0M3TH3AN ec31a64736 Merge pull request #62 from PR0M3TH3AN/perf-async-dashboard-io-5891481615082085195
⚡ Replace Blocking Sync I/O in HTTP Request Handler
2026-02-14 12:12:16 -05:00
thePR0M3TH3AN d46aa0b449 Merge branch 'main' into refactor/valid-cadences-7741695179358615025 2026-02-14 12:12:02 -05:00
thePR0M3TH3AN e15ba3fe42 Merge pull request #71 from PR0M3TH3AN/refactor/constants-kind-app-data-17267465416565685977
Refactor magic number 30078 to KIND_APP_DATA constant
2026-02-14 12:11:50 -05:00
thePR0M3TH3AN 716b28fddc Merge branch 'main' into unit-tests-lib-mjs-1840636568505209047 2026-02-14 12:10:58 -05:00
thePR0M3TH3AN bcea60fbee Merge pull request #76 from PR0M3TH3AN/perf-optimize-lock-filtering-15960706450530800656
⚡ Optimize lock filtering with Set lookups
2026-02-14 12:10:36 -05:00
thePR0M3TH3AN cc1df8d304 Merge pull request #61 from PR0M3TH3AN/fix-empty-catch-blocks-17156965692183891029
🧹 improve observability by adding console.debug to empty catch blocks
2026-02-14 12:07:34 -05:00
thePR0M3TH3AN 279e39273b Merge branch 'main' into fix-dashboard-binding-9664858879592007216 2026-02-14 12:06:13 -05:00
google-labs-jules[bot]andPR0M3TH3AN 0a7f64d1dc Refactor lock filtering to use Set lookups instead of linear scans
Optimized `cmdCheck` and `cmdList` in `src/lib.mjs` by replacing O(N*M) linear scans with O(N) Set lookups.
- Introduced `rosterSet` and `excludedAgentsSet` to replace `Array.includes()` calls with `Set.has()`.
- Benchmark showed ~99% performance improvement (from ~280ms to ~2ms for 10k agents and 2k locks).
- Verified with existing tests and custom benchmark.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-14 14:26:25 +00:00
google-labs-jules[bot]andPR0M3TH3AN 9eda853e7e feat: add unit tests for src/lib.mjs via dependency injection
Refactor src/lib.mjs to support dependency injection for cmdCheck, cmdLock, and cmdList.
This allows unit testing without heavy mocking frameworks or side effects.
Add test/lib.test.mjs covering:
- cmdCheck: happy path, paused/excluded agents, unknown agents.
- cmdLock: success, roster check, existing lock check, race check (lost), dry run.
- cmdList: listing locks, empty state.

Coverage for src/lib.mjs is now significantly improved.
Verification: Ran `npm test` and verified all tests pass.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-14 14:23:03 +00:00
google-labs-jules[bot]andPR0M3TH3AN 02e96d49be Refactor magic number 30078 to KIND_APP_DATA constant
- Added KIND_APP_DATA to src/constants.mjs
- Updated src/lib.mjs, src/lock-ops.mjs, and dashboard/index.html to use the constant
- Added missing src files to package.json files list
- Updated build.mjs to copy src/constants.mjs to dist/src/

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-14 14:16:44 +00:00
google-labs-jules[bot]andPR0M3TH3AN fdfbb39da6 Decompose src/lib.mjs
Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-14 14:16:01 +00:00
google-labs-jules[bot]andPR0M3TH3AN c94ff84da8 Refactor src/lib.mjs to use VALID_CADENCES constant
Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-14 14:15:55 +00:00
google-labs-jules[bot]andPR0M3TH3AN b044570f72 ⚡ optimize: replace blocking sync I/O in dashboard request handler
Converted the dashboard HTTP request handler to an async function and replaced synchronous `fs.existsSync` and `fs.statSync` calls with non-blocking `fs.promises.stat`. This improves server responsiveness and concurrency by ensuring the event loop is not blocked during file system checks.

Also added robust error handling to the asynchronous handler to prevent unhandled promise rejections and ensure consistent 500 responses on internal errors.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-14 13:56:15 +00:00
google-labs-jules[bot]andPR0M3TH3AN 983ad0627b 🧹 improve observability by adding console.debug to empty catch blocks
Replaced empty catch blocks in `loadCanonicalRoster` and `parseLockEvent`
with `console.debug` statements that log the error message. This
improves observability of failures while maintaining the graceful
fallback behavior.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-14 13:55:21 +00:00
google-labs-jules[bot]andPR0M3TH3AN c275b452be security: bind dashboard server to 127.0.0.1
Explicitly bind the dashboard server to the local loopback interface
to prevent external access. This addresses a vulnerability where
the server was binding to all network interfaces by default.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-14 13:52:27 +00:00
thePR0M3TH3AN e67d8441a4 Merge pull request #58 from PR0M3TH3AN/agents/daily/decompose-agent-v1-14520720754219938139
[decompose] Extract modules from src/lib.mjs
2026-02-14 08:51:26 -05:00
google-labs-jules[bot]andPR0M3TH3AN 581dc3484e [decompose] extract modules from src/lib.mjs
Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-14 13:18:07 +00:00
google-labs-jules[bot]andPR0M3TH3AN 9716fe3812 perf: parallelize daily/weekly lock queries in list command
- Modified `src/lib.mjs` to execute `queryLocks` for all cadences in parallel.
- Added `scripts/perf-benchmark.mjs` for measuring CLI performance.
- Added `weekly-perf-report-2026-02-14.md` with baseline and verification data.
- Added `task-logs/weekly/2026-02-14T13-14-38Z__perf-deepdive-agent__completed.md`.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-14 13:17:27 +00:00
thePR0M3TH3AN c731f2b09d Merge pull request #53 from PR0M3TH3AN/agents/weekly/fuzz-agent-1863848784432453944
fuzz-agent: fix parseLockEvent crash on null content
2026-02-14 07:51:03 -05:00