Skip to content

Add codemode: typechecked TypeScript execution with tools#16

Open
jonastemplestein wants to merge 14 commits intomainfrom
codemode-execution
Open

Add codemode: typechecked TypeScript execution with tools#16
jonastemplestein wants to merge 14 commits intomainfrom
codemode-execution

Conversation

@jonastemplestein
Copy link
Contributor

@jonastemplestein jonastemplestein commented Dec 5, 2025

Summary

Adds codemode execution to the agent: the LLM can write TypeScript code blocks that are typechecked and executed, with access to tools for file I/O, shell commands, web fetching, and secrets.

Features

Code Execution

  • <codemode>...</codemode> blocks are typechecked with strict TypeScript
  • Executed in a Bun subprocess with streamed stdout/stderr
  • Type errors trigger agent retry (agent sees errors and can fix)

Available Tools

  • t.sendMessage(msg) — show message to USER (no agent turn)
  • t.readFile(path) / t.writeFile(path, content) — file I/O
  • t.exec(command) — run shell commands
  • t.fetch(url) — HTTP requests
  • t.getSecret(name) — access secrets (hidden from LLM)

Agent Loop

  • console.log() output triggers another agent turn
  • t.sendMessage() output goes to user, no turn
  • Most tasks complete in one turn
  • Max 3 iterations before forced stop

Event Model

  • Added triggerAgentTurn property to all events
  • LLM triggered by any event with triggerAgentTurn="after-current-turn"
  • CodemodeResultEvent persisted with stdout/stderr for conversation history

Files Added

  • src/codemode.model.ts — code block parsing, event types
  • src/codemode.service.ts — orchestrates parse → typecheck → execute
  • src/codemode.repository.ts — stores generated code files
  • src/code-executor.service.ts — runs code in Bun subprocess
  • src/typechecker.service.ts — TypeScript type checking
  • test/codemode.e2e.test.ts — end-to-end tests

All 75 tests pass.


Note

Adds codemode enabling LLM-emitted TypeScript to be typechecked and executed via Bun with tools, persisting results to drive an agent loop across CLI/UI/HTTP and a new per-context storage layout.

  • Codemode (core):
    • Add codemode pipeline: parse <codemode> blocks, typecheck (TS), execute via Bun subprocess, stream events.
    • New services: CodemodeService, TypecheckService, CodeExecutor, CodemodeRepository.
    • New events: CodemodeResultEvent, CodemodeValidationErrorEvent and codemode streaming events; add triggerAgentTurn to events.
    • LLM prompt building updated to include codemode results/validation.
  • Context/Agent:
    • ContextService.addEvents supports codemode and emits codemode events; swaps in codemode system prompt when enabled.
    • Agent continuation driven by triggerAgentTurn with persisted CodemodeResult.
  • CLI/UI:
    • Add codemode run subcommand; integrate codemode into chat flow with an agent loop (iteration cap) and colored streaming output.
    • TUI updated to render codemode results/validation and ignore ephemeral codemode stream events.
  • HTTP/Adapters:
    • SSE streaming and LayerCode adapter generalized to ContextOrCodemodeEvent.
  • Persistence:
    • Contexts now stored per-directory with events.yaml; repository APIs updated (getContextDir, listing by directories).
  • Tests/Config:
    • Add E2E and unit tests for codemode; vitest config includes src/**/*.test.ts.
    • ESLint ignores .mini-agent/**.

Written by Cursor Bugbot for commit 8f32ec5. This will update automatically on new commits. Configure here.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant