ClawsCode
TypeScript Bun Responses API
Project Overview
A terminal-based AI coding assistant in TypeScript. Intended as a learning project to discover how AI agents work internally and to explore OpenAI’s Responses API.
Features
- AI-Powered (LLM) Coding Assistant in the Unix Command-line interface(CLI).
- Tool Calling: The model invokes tools (Read, Write, Bash) to write files and execute commands.
- Conversation History: The agent maintains context by storing user messages.
- Interactive Modes:
- Prompt mode: Run with -p flag then “your prompt” for single tasks.
- REPL mode: Interactive chat session for ongoing conversation.
Project Structure
src/
├── index.ts # Entry point
├── core/
│ ├── agent.ts # AI client & agent loop
│ └── config.ts # Configuration management
└── tools/
├── definitions.ts # Tool schemas (definitions)
└── handlers.ts # Tool execution logic
What I Learned
- Setting up an AI agent - Initializing an AI client with API keys and base URLs.
- Standard API for AI agents - Using the OpenAI Responses API (not Chat API) for agentic workflows.
- Tool advertising - Defining tools using OpenAI’s FunctionTool format with name, description, and JSON schema parameters.
- Tool implementation - Creating handlers (Read, Write, Bash) that execute actual filesystem/shell operations.
- Agent loop - Building a conversation loop that sends history to the model, handles tool calls by executing handlers and appending results, and continues until the model returns a final message.
- History management - Maintaining conversation context by appending user messages, assistant responses, and tool outputs.
Future Improvements
- Switch to WebSocket mode for the Responses API instead of HTTP/REST
- Introduce Sessions & resume capability
- Improve UI