A Node.js package for batch processing folders with OpenCode AI SDK.
For detailed configuration documentation, see CONFIG_GUIDE.md.
- Extract compressed files (zip, tar, tar.gz, rar, 7z)
- Process each folder with configurable agent and prompts
- Structured output scoring with JSON Schema
- Export results to CSV
npm install# Validate configuration
node bin/opencode-batch.js --config config.example.md --validate
# Process folders (point to the directory containing archives/subfolders)
node bin/opencode-batch.js --config config.example.md --input "./Example/files" --output ./results.csv
# Enable debug output for troubleshooting
node bin/opencode-batch.js --config config.example.md --input "./Example/files" --debugconst { BatchProcessor } = require('./src');
const processor = BatchProcessor.fromConfigFile('config.md');
await processor.run('./Example/files', './results.csv');The configuration file uses YAML frontmatter with markdown content:
---
agent: Build
model: anthropic/claude-3-5-sonnet-20241022
base_url: http://localhost:4096
extract: true
output_csv: results.csv
structured_output:
type: json_schema
schema:
type: object
properties:
format_score:
type: number
description: Format score (0-100)
prompt_effort_score:
type: number
description: Prompt effort score (0-100)
core_prediction:
type: number
description: Core prediction result score (0-100)
report_score:
type: number
description: Report score (0-100)
required: [format_score, prompt_effort_score, core_prediction, report_score]
---
# Prompts
Please grade the student's assignment based on the following criteria:
1. Format: Check if the report follows the required format
2. Prompt Effort: Evaluate the effort put into prompt engineering
3. Core Prediction: Assess the accuracy of core predictions
4. Report Quality: Evaluate overall report quality
Folder contents:
{folder_contents}
Please provide scores for each dimension.| Option | Type | Default | Description |
|---|---|---|---|
| agent | string | Build | Agent name |
| model | string | null | Model identifier (provider/model) |
| base_url | string | http://localhost:4096 | OpenCode server URL |
| username | string | opencode | OpenCode server username (for basic auth) |
| password | string | null | OpenCode server password (for basic auth) |
| extract | boolean | true | Auto-extract archives |
| extract_extensions | array | [.zip, .tar, .tar.gz, .tgz, .rar, .7z] | Extensions to extract |
| auto_approve | boolean | true | Auto-approve Agent permission requests |
| timeout | number | 300 | Prompt timeout in seconds |
| delay_between_folders | number | 0 | Delay in seconds between processing folders (0 = no delay) |
| retry_count | number | 0 | Number of retries on failure (0 = no retry). Waits 10s between retries. |
| output_csv | string | results.csv | Output CSV filename |
| structured_output | object | null | JSON Schema for structured output |
| csv_columns | object | null | Column name mapping |
Before running, check what models are available on your OpenCode server:
# List available models
curl http://localhost:4096/config/providers
# Or with authentication
curl -u opencode:yourpassword http://localhost:4096/config/providers| Option | Description |
|---|---|
-c, --config <path> |
Path to configuration markdown file (required) |
-i, --input <path> |
Input directory containing archives/subfolders |
-o, --output <path> |
Output CSV file path |
--validate |
Validate configuration file only |
--debug |
Enable debug output for troubleshooting |
--filter <file> |
Only process folders listed in the filter file |
If some folders fail processing, they are automatically saved to failed.txt in the input directory. To retry only those folders:
# First run - some may fail
node bin/opencode-batch.js --config config.example.md --input "./Example/files"
# Retry only failed folders
node bin/opencode-batch.js --config config.example.md --input "./Example/files" --filter ./Example/files/failed.txtWhen auto_approve: true (default), the tool will:
- Subscribe to OpenCode server events
- Listen for permission requests from the Agent
- Automatically approve all permissions with "always" response
- This prevents the Agent from stopping and waiting for user input
If you want manual control, set auto_approve: false.