/**
 * Simulation subagent — read/write workbook analysis worker.
 *
 * Ported from backend/agent/tools/subagents/simulation_agent.py.
 * Tools: execute_code (R/W, action-mode API) + bash.
 */
import { getAgentTempDir } from '../../../config.js';
import { BASH, EXECUTE_CODE } from '../../../tool-names.js';
import { getEnginePrompts, pushActionSharedGuidelines } from '../../prompts/shared-guidelines.js';
import { DEFAULT_SUBAGENT_MODEL, DEFAULT_SUBAGENT_TIMEOUT_SECONDS } from '../defaults.js';
const NAME = 'simulation_agent';
const DESCRIPTION = `\
Read/write workbook analysis worker for scenario analysis, sensitivity testing, auditing formula linkages, debugging, prototyping changes, and other workbook-heavy tasks.`;
/** Build the simulation subagent's read/write workbook system prompt. */
function buildSystemPrompt() {
    const engine = getEnginePrompts();
    const sharedTempDir = getAgentTempDir();
    const sections = [
        `\
======================
WORKBOOK SIMULATION AGENT
======================
You have access to a spreadsheet engine (execute_code) with WRITE access, and a bash tool for computation.
Current date: ${new Date().toISOString().slice(0, 10)}.

Use \`workbook\` and \`worksheet\` globals directly. Create or load workbooks if needed for the task.

Use this workbook environment for any task that benefits from reading and writing to the workbook:
- **What-if / scenario analysis**: change inputs and observe how outputs respond
- **Auditing & validation**: trace formula dependencies, check for broken linkages, verify propagation
- **Debugging**: isolate formulas or sections to diagnose incorrect results
- **Data transformation**: restructure, clean, or reformat data in a scratch copy
- **Prototyping**: build out layouts, formulas, or structures before applying to the real workbook
- **Extraction with computation**: read data, compute derived metrics, export results

## RULES

1. **Track changes**: Note what you modified so results are reproducible
2. **Use formulas**: When testing formula integrity, read both formulas and values
3. **Be concrete**: Report numerical results, not narratives about what the model "means"

## LAST STEP: EXPORT THE WORKBOOK

After all changes are complete, save the modified workbook using execute_code:

\`\`\`typescript
await saveWorkbook("${sharedTempDir}/simulation_result.xlsx");
\`\`\`

This exports the full spreadsheet with all your modifications.

## OUTPUT
- Export the modified workbook as described above. This is your primary output.
- Save reports and analysis to file via bash. Do not try to pass data between execute_code and bash via global variables.
- Return a concise summary of what you did, what the results are, and what the main agent should pay attention to in the saved spreadsheet. Always provide full file paths of results.
`
    ];
    pushActionSharedGuidelines(sections, engine);
    return sections.join('\n\n');
}
export const simulationAgent = {
    name: NAME,
    description: DESCRIPTION,
    get systemPrompt() {
        return buildSystemPrompt();
    },
    tools: [EXECUTE_CODE, BASH],
    model: DEFAULT_SUBAGENT_MODEL,
    thinkingLevel: 'low',
    timeoutSeconds: DEFAULT_SUBAGENT_TIMEOUT_SECONDS
};
//# sourceMappingURL=agent.js.map