Forge Optimizer
When to Use
- Running
/forge-optimizercommand (with conversation title,--latest, or--project) - Reviewing agentic execution quality
Prerequisites
npx tsxis available (tsx is installed globally)pgnpm package is installed inForge/Skills/Forge_Optimizer/scripts/node_modules/(runnpm installin that folder if missing)- Network access to the internal Postgres instance is available
OPENAI_API_KEYis present in the environment (read from/proc/1/environ)Forge/Skills/Forge_Optimizer/references/extraction_prompt.mdexists
Procedure
Export Railway env vars before running the script (they are not in process.env by default):
Single-conversation mode
Project mode
In project mode, the script queries AgentJob for all conversations associated with the project, builds a combined transcript from all of them, and analyzes the project as a whole. This provides cross-conversation insights like repeated mistakes, knowledge gaps, and workflow inefficiencies.
The default model for each mode is determined by the use case (see Forge/Skills/Choose_AI_Model/Models/ for current models and their quirks). The user can override with --model.
When running in project mode, also check for persisted evaluation report files ({Project}_Eval_{N}.md, {Project}_Spec_Eval.md, etc.) in the project directory and include them as supporting context for the analysis.
The script saves the report to {Project}_Optimizer_Report.md in the project folder. If the file already exists, a new ## Run — {date} section is appended; otherwise the file is created with frontmatter and a header. After the script completes, spawn the Page Manager bot via spawnAgent with { botGroup: 'forge', botHandle: 'page-manager' } to add the sidebar entry (if the file is new), build, commit, push.
Generate runs summary
This generates a {Project}_Runs.md file with per-conversation agent, model, task, duration, tokens, and cost data.
Single-conversation mode: Output the analysis directly in the conversation — do not create a report file. Ask if the user wants to implement any of the checked findings.
Project mode: The script saves the report to {Project}_Optimizer_Report.md in the project folder. After spawning Page Manager to commit the file, present a summary of findings in the conversation and ask if the user wants to implement any of them.
What the Scripts Do
optimize.ts
- Connects to Postgres — see
Forge/Skills/Choose_AI_Model/Models/for model-specific quirks - Fetches conversation(s) + all messages, builds a redacted transcript
- Sends transcript + the extraction prompt to the selected model using
references/extraction_prompt.md - Prints the analysis to stdout (agent presents it in conversation)
- In project mode: saves the report to
{Project}_Optimizer_Report.mdin the project folder (creates or appends)
generate-runs.ts
- Connects to Postgres (AgentJob and messages)
- Queries all jobs for the given project
- Computes token usage and cost per conversation
- Generates
{Project}_Runs.mdfrom the Runs_Template
Rules
- Treat the prerequisites above as preconfigured environment requirements, not setup steps
- If any prerequisite is missing, stop and report a skill/environment contract failure
- Never analyze the current conversation — only past ones
- Consult
Forge/Skills/Choose_AI_Model/Models/for model defaults, quirks, and parameter requirements - User can override model with
--modelflag in either mode - Present findings to user before implementing any changes