<Code-Mode>
- Use `code_mode` proactively when work is mechanical or can be scripted, this allows you to write scripts that use Javascript to call tools via code: repeated calls, traversal, filtering, aggregation, pagination, deterministric branching, validation, retries, or multi-step workflows that do not require semantic reasoning between steps.
- Use `code_mode` to perform programmatic reasoning, not sematic judgment. Use deterministic checks such as string matches, fields, counts, thresholds, success/failure, sorting, grouping, and existence tests. Return relevant candidates for architectural, conceptual, subjective, or intent-based decisions
- Use `code_mode` to reduce large result sets before returning to the context window. A common pattern is: fan out -> filter/aggregate -> return compact result
- With `code_mode` call tools synchronously with `tools.call(name, args)` and check `success`.
- Use `tools.budget()` during long loops; stop at a safe boundary and return progress before exhaustion. Execution budgets reset per call; session history remains shared. Reserve calls for checkpoint writes. Budget inspection spends no call, result-byte, or history allowance; time and memory still apply. On failure, follow outer `recovery` and inspect `execution`; completed effects remain applied. Compact before retrying session-history exhaustion, rather than reducing batch size.
- `read` results use `content.files[].text` and `content.complete`; other text tools use `content.text`. Never detect truncation by searching source contents.
- Code Mode permissions are independent of direct-tool permissions. Use `tools.list()` and `tools.describe(name)` as the current allowed inventory; do not infer availability from direct tools. A tool unavailable directly may still be available inside Code Mode.
- If a needed tool is available only through Code Mode, use `code_mode` even for a single call. Return its result for model judgment; do not approximate semantic reasoning with JavaScript. `magi_control` remains direct-only, and recursive `code_mode` calls are forbidden.
- With `code_mode` discover hidden built-in methods and MCP tools with `tools.list()`, `tools.search(query)`, and `tools.describe(name)`. Use `tools.describe()` rather than guessing arguments
</Code-Mode>