feat: extract DEFAULT_DASHBOARD_PORT and RACE_CHECK_DELAY_MS to src/constants.mjs

- Created src/constants.mjs
- Updated src/lib.mjs to use constants
- Added execution artifacts and completed log

Co-authored-by: PR0M3TH3AN <[email protected]>
This commit is contained in:
google-labs-jules[bot]andPR0M3TH3AN committed 2026-02-14 07:33:51 +00:00
1 parent 14002a7bf9
commit d165c06640
7 files changed
+233 -5

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
export const DEFAULT_DASHBOARD_PORT = 4173;
export const RACE_CHECK_DELAY_MS = 1500;
+14
View File
@@ -0,0 +1,14 @@
# Context: 2026-02-14 Constants Refactor
## Goal
To refactor duplicate or magic numeric literals into a canonical constants file.
Specifically targeting `4173` (default dashboard port) and `1500` (race check delay).
## Scope
- Create `src/constants.mjs`.
- Modify `src/lib.mjs`.
## Constraints
- Must preserve existing values.
- Must pass lint and tests.
- Must follow `const-refactor-agent` guidelines.
+12
View File
@@ -0,0 +1,12 @@
# Decisions: 2026-02-14 Constants Refactor
- **Extracted `DEFAULT_DASHBOARD_PORT` (4173)**
- **Reason**: Magic number used in multiple places (`cmdDashboard`, `parseArgs`).
- **Location**: `src/constants.mjs`.
- **Extracted `RACE_CHECK_DELAY_MS` (1500)**
- **Reason**: Magic number for timing logic.
- **Location**: `src/constants.mjs`.
- **Created `src/constants.mjs`**
- **Reason**: No dedicated constants file existed for this level of abstraction.
+6 -5
View File
@@ -13,6 +13,7 @@ import { useWebSocketImplementation } from 'nostr-tools/relay';
import WebSocket from 'ws';
import { loadTorchConfig } from './torch-config.mjs';
import { cmdInit, cmdUpdate } from './ops.mjs';
import { DEFAULT_DASHBOARD_PORT, RACE_CHECK_DELAY_MS } from './constants.mjs';
useWebSocketImplementation(WebSocket);
@@ -395,7 +396,7 @@ export async function cmdLock(agent, cadence, dryRun = false) {
await publishLock(relays, event);
console.error('Step 5: Race check...');
await new Promise((resolve) => setTimeout(resolve, 1500));
await new Promise((resolve) => setTimeout(resolve, RACE_CHECK_DELAY_MS));
const postLocks = await queryLocks(relays, cadence, dateStr, namespace);
const racingLocks = postLocks
@@ -477,7 +478,7 @@ export async function cmdList(cadence) {
}
}
export async function cmdDashboard(port = 4173) {
export async function cmdDashboard(port = DEFAULT_DASHBOARD_PORT) {
// Resolve package root relative to this file (src/lib.mjs)
// this file is in <root>/src/lib.mjs, so '..' goes to <root>
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
@@ -554,7 +555,7 @@ export async function cmdDashboard(port = 4173) {
}
function parseArgs(argv) {
const args = { command: null, agent: null, cadence: null, dryRun: false, force: false, port: 4173 };
const args = { command: null, agent: null, cadence: null, dryRun: false, force: false, port: DEFAULT_DASHBOARD_PORT };
let i = 0;
if (argv.length > 0 && !argv[0].startsWith('-')) {
@@ -577,7 +578,7 @@ function parseArgs(argv) {
} else if (arg === '--force') {
args.force = true;
} else if (arg === '--port') {
args.port = parseInt(argv[++i], 10) || 4173;
args.port = parseInt(argv[++i], 10) || DEFAULT_DASHBOARD_PORT;
}
}
@@ -591,7 +592,7 @@ Commands:
check --cadence <daily|weekly> Check locked agents (JSON)
lock --agent <name> --cadence <daily|weekly> Claim a lock
list [--cadence <daily|weekly>] Print active lock table
dashboard [--port <port>] Serve the dashboard (default: 4173)
dashboard [--port <port>] Serve the dashboard (default: ${DEFAULT_DASHBOARD_PORT})
init [--force] Initialize torch/ directory in current project
update [--force] Update torch/ configuration (backups, merges)
+177
View File
@@ -0,0 +1,177 @@
> [email protected] lint
> eslint .
/app/scripts/agent/debug-frontend.mjs
3:8 warning 'path' is defined but never used no-unused-vars
/app/test/nostr-lock.test.mjs
1:10 warning 'test' is defined but never used no-unused-vars
✖ 2 problems (0 errors, 2 warnings)
> [email protected] test
> node --test test/*.test.mjs
TAP version 13
# Subtest: CLI Smoke Test
# Subtest: should print usage when no args provided
ok 1 - should print usage when no args provided
---
duration_ms: 325.690702
type: 'test'
...
# Subtest: should fail when checking without cadence
ok 2 - should fail when checking without cadence
---
duration_ms: 187.135216
type: 'test'
...
# Subtest: should include paused agents in check output
ok 3 - should include paused agents in check output
---
duration_ms: 15297.898808
type: 'test'
...
1..3
ok 1 - CLI Smoke Test
---
duration_ms: 15812.845491
type: 'suite'
...
# Initializing torch configuration in /app/test-ops-P1ZLv8/project1/torch...
# Created torch/roster.json
# Created torch/META_PROMPTS.md
# Created torch/scheduler-flow.md
# Created torch/daily-scheduler.md
# Created torch/weekly-scheduler.md
# Created 23 files in torch/prompts/daily/
# Created 20 files in torch/prompts/weekly/
# Initialization complete.
# You can now customize the files in torch/ and torch/prompts/.
# Initializing torch configuration in /app/test-ops-P1ZLv8/project2/torch...
# Initializing torch configuration in /app/test-ops-P1ZLv8/project3/torch...
# Created torch/roster.json
# Created torch/META_PROMPTS.md
# Created torch/scheduler-flow.md
# Created torch/daily-scheduler.md
# Created torch/weekly-scheduler.md
# Created 23 files in torch/prompts/daily/
# Created 20 files in torch/prompts/weekly/
# Initialization complete.
# You can now customize the files in torch/ and torch/prompts/.
# Updating torch configuration in /app/test-ops-P1ZLv8/project3/torch...
# Creating backup at torch/_backups/backup_2026-02-14T07-28-56-279Z...
# Updating static files...
# Updated META_PROMPTS.md
# Updated scheduler-flow.md
# Updated daily-scheduler.md
# Updated weekly-scheduler.md
# Skipped roster.json (preserved)
# Updating prompts...
# daily/: 0 added, 0 updated, 23 preserved
# weekly/: 0 added, 0 updated, 20 preserved
# Update complete.
# Initializing torch configuration in /app/test-ops-P1ZLv8/project4/torch...
# Created torch/roster.json
# Created torch/META_PROMPTS.md
# Created torch/scheduler-flow.md
# Created torch/daily-scheduler.md
# Created torch/weekly-scheduler.md
# Created 23 files in torch/prompts/daily/
# Created 20 files in torch/prompts/weekly/
# Initialization complete.
# You can now customize the files in torch/ and torch/prompts/.
# Updating torch configuration in /app/test-ops-P1ZLv8/project4/torch...
# Creating backup at torch/_backups/backup_2026-02-14T07-28-56-310Z...
# Updating static files...
# Updated META_PROMPTS.md
# Updated scheduler-flow.md
# Updated daily-scheduler.md
# Updated weekly-scheduler.md
# Overwrote roster.json (forced)
# Updating prompts...
# daily/: 0 added, 23 updated, 0 preserved
# weekly/: 0 added, 20 updated, 0 preserved
# Update complete.
# Initializing torch configuration in /app/test-ops-P1ZLv8/project5/torch...
# Created torch/roster.json
# Created torch/META_PROMPTS.md
# Created torch/scheduler-flow.md
# Created torch/daily-scheduler.md
# Created torch/weekly-scheduler.md
# Created 23 files in torch/prompts/daily/
# Created 20 files in torch/prompts/weekly/
# Initialization complete.
# You can now customize the files in torch/ and torch/prompts/.
# Updating torch configuration in /app/test-ops-P1ZLv8/project5/torch...
# Creating backup at torch/_backups/backup_2026-02-14T07-28-56-350Z...
# Updating static files...
# Updated META_PROMPTS.md
# Updated scheduler-flow.md
# Updated daily-scheduler.md
# Updated weekly-scheduler.md
# Skipped roster.json (preserved)
# Updating prompts...
# daily/: 0 added, 0 updated, 23 preserved
# weekly/: 0 added, 0 updated, 20 preserved
# Update complete.
# Initializing torch configuration in /app/test-ops-P1ZLv8/project_roster/torch...
# Created torch/roster.json
# Created torch/META_PROMPTS.md
# Created torch/scheduler-flow.md
# Created torch/daily-scheduler.md
# Created torch/weekly-scheduler.md
# Created 23 files in torch/prompts/daily/
# Created 20 files in torch/prompts/weekly/
# Initialization complete.
# You can now customize the files in torch/ and torch/prompts/.
# Checking locks: namespace=torch, cadence=daily, date=2026-02-14
# Relays: wss://relay.damus.io, wss://nos.lol, wss://relay.primal.net
# Subtest: cmdInit creates directory structure and files
ok 2 - cmdInit creates directory structure and files
---
duration_ms: 31.478284
type: 'test'
...
# Subtest: cmdInit fails if directory exists without force
ok 3 - cmdInit fails if directory exists without force
---
duration_ms: 1.223212
type: 'test'
...
# Subtest: cmdUpdate preserves modified prompt
ok 4 - cmdUpdate preserves modified prompt
---
duration_ms: 29.696939
type: 'test'
...
# Subtest: cmdUpdate overwrites prompt with force
ok 5 - cmdUpdate overwrites prompt with force
---
duration_ms: 33.378006
type: 'test'
...
# Subtest: cmdUpdate creates backup
ok 6 - cmdUpdate creates backup
---
duration_ms: 35.96283
type: 'test'
...
# Subtest: torch-lock check respects local roster
ok 7 - torch-lock check respects local roster
---
duration_ms: 15295.37334
type: 'test'
...
1..7
# tests 9
# suites 1
# pass 9
# fail 0
# cancelled 0
# skipped 0
# todo 0
# duration_ms 15904.442607
+6
View File
@@ -0,0 +1,6 @@
# Todo: 2026-02-14 Constants Refactor
- [ ] Create `src/constants.mjs` with `DEFAULT_DASHBOARD_PORT` and `RACE_CHECK_DELAY_MS`.
- [ ] Update `src/lib.mjs` to import and use new constants.
- [ ] Verify changes with `npm run lint` and `npm test`.
- [ ] Document decisions.
@@ -0,0 +1,16 @@
---
agent: const-refactor-agent
cadence: daily
status: completed
date: 2026-02-14
---
# Constant Refactor
Identified and extracted magic numbers:
- `DEFAULT_DASHBOARD_PORT` (4173)
- `RACE_CHECK_DELAY_MS` (1500)
Created `src/constants.mjs` and updated `src/lib.mjs`.
Verified with `npm run lint` and `npm test`.