mirror of
https://github.com/PR0M3TH3AN/TORCH.git
synced 2026-10-27 16:01:54 +00:00
- Added JSDoc to src/ops.mjs - Created docs/ops-overview.md - Updated run artifacts Co-authored-by: PR0M3TH3AN <[email protected]>
2.5 KiB
2.5 KiB
Ops Module Overview (src/ops.mjs)
What this module does
This module implements the core CLI operations for the Torch agent system: init and update. It handles the scaffolding of the agent environment, including directory structure creation, asset copying, configuration generation, and upgrades.
Initialization Flow (cmdInit)
- Resolve Configuration:
- Queries user for install directory, namespace, hashtag, and relays.
- Validates inputs (prevents path injection).
- Ensure Directories:
- Creates
torch/prompts/,src/proposals/,.torch/prompt-history/.
- Creates
- Install Assets:
- Copies app directories (
src,bin,dashboard, etc.). - Copies static files (
META_PROMPTS.md, scheduler docs). - Copies prompts (
daily/,weekly/).
- Copies app directories (
- Configure:
- Generates
torch-config.json. - Updates
.gitignoreto excludenode_modules. - Generates
TORCH_DASHBOARD.md.
- Generates
- Inject Scripts:
- Adds
torch:*scripts to the hostpackage.jsonif installed in a subdirectory.
- Adds
Update Flow (cmdUpdate)
- Detect Installation:
- Finds the existing
torchdirectory.
- Finds the existing
- Backup:
- Creates a timestamped backup in
torch/_backups/.
- Creates a timestamped backup in
- Update App:
- Overwrites application code (
src,bin, etc.). - Overwrites static files.
- Overwrites application code (
- Update Prompts:
- Adds new prompts from the package.
- Preserves existing prompts (unless
--forceis used).
- Preserve Roster:
roster.jsonis preserved to avoid resetting rotation (unless--forceis used).
Public API
cmdInit(force, cwd, mockAnswers)
Initializes a new Torch environment.
force: Boolean, overwrite existing directory if not empty.cwd: Current working directory.mockAnswers: Optional object for testing (bypasses interactive prompts).
cmdUpdate(force, cwd)
Updates an existing Torch environment.
force: Boolean, overwrite modified prompts/roster.cwd: Current working directory.
Key Invariants
- Safe Installation:
validateInstallDirensures the target directory name is safe (alphanumeric + safe chars). - Non-Destructive Defaults:
initfails if directory is not empty (unless forced).updatepreserves user data (prompts, roster, config) by default. - Backup First:
updatealways creates a full backup before modifying files.
When to change
- When adding new CLI commands or workflows.
- When changing the directory structure or asset layout.
- When updating the default configuration logic or
torch-config.jsonschema.