How tsingliuwin/autoclaw works
1. What this repo is
AutoClaw is a TypeScript/Node.js CLI agent framework, not a web app. Its architecture is centered on a headless command loop that lets an LLM plan actions and invoke local or external tools.
2. Top-level control flow
The entry point in src/index.ts boots the CLI, parses flags like model selection, non-interactive mode, and auto-confirmation, then hands execution to the agent layer in src/agent.ts.
3. Agent orchestration
src/agent.ts is the core runtime coordinator. It likely owns the conversation state, sends prompts to the LLM via the OpenAI-compatible SDK, receives tool calls, executes them, and feeds results back into the model until the task is complete.
4. Tool abstraction boundary
src/tools/interface.ts and src/tools/index.ts define and register the tool contract. This is the main extensibility boundary: the agent doesn’t hardcode capabilities; it routes actions through a tool interface and a registry.
5. Local system-capability tools
src/tools/core.ts is the likely foundation for low-level filesystem and shell-style operations. These are the “command-driven execution” primitives that make the framework deterministic in headless environments.
6. External-service integrations
Several tools bridge the agent to outside systems:
- src/tools/search.ts for Tavily web search
- src/tools/email.ts for SMTP email sending
- src/tools/notify.ts for webhook notifications such as Feishu, DingTalk, or WeCom
These are separate from core execution so the agent can mix local automation with outbound communication.
7. Context and media helpers
src/tools/image.ts and src/tools/screenshot.ts provide image-related utilities, likely for capturing or processing visual artifacts even though the framework itself is headless. They are support tools rather than the primary interaction model.
8. Prompt and context shaping
src/tools/prompt-optimizer.ts suggests a preprocessing or prompt-refinement step before the LLM is called. This acts as an intelligence layer to improve instruction quality and tool selection rather than as an execution tool itself.
9. Runtime modes and user interaction
The README describes both interactive chat and one-shot headless execution. The architecture therefore has two outer modes around the same agent core: a REPL-like interactive loop and a non-interactive batch path suitable for CI/CD or containerized runs.
10. Configuration flow
Configuration is hierarchical: CLI arguments override environment variables, which override project-local .autoclaw/setting.json, which overrides global config in ~/.autoclaw/setting.json. This matters architecturally because the agent is designed to run in diverse environments without code changes.
11. Security and execution gating
Auto-confirmation (-y) is an explicit boundary around side-effecting tool execution. In normal mode, the framework is meant to pause before running actions, which is important for diagramming trust boundaries between the LLM, the user, and the host system.
12. Packaging/deployment shape
The repo is built as an npm-distributed TypeScript package with shell installers and no server component. That means the deployed unit is a single CLI binary/process, typically run locally, in containers, or in automation pipelines rather than as a multi-service backend.
Main entry points: tools/index.ts Tool registry · agent.ts Agent core · src/index.ts CLI entry · core.ts Core tools
Components 19
Runtime
CLI entrypoint, modes, and orchestration
- CLI entry · Boots the command-line app and hands control to the agent runtime
src/index.ts - Config flow · Resolves CLI flags, environment variables, and persisted settings
- Interactive mode · Chat-like loop for ongoing user interaction
- Headless mode · One-shot non-interactive execution path for automation and CI
- Confirm gate · Boundary for approving side-effecting tool execution
- Agent core · Coordinates conversation state, model calls, tool use, and result feedback
src/agent.ts - LLM API · OpenAI-compatible model interface used by the agent
Tools
Tool contract, registry, and integrations
- Tool registry · Registers available tools and routes tool calls
src/tools/index.ts - Tool contract · Defines the common tool shape and execution boundary
src/tools/interface.ts - Core tools · Filesystem and shell-style primitives for local automation
src/tools/core.ts - Browser tool · Browser-oriented automation capability
src/tools/browser.ts - Search tool · Tavily-backed web search integration
src/tools/search.ts - Email tool · Sends email through SMTP
src/tools/email.ts - Notify tool · Sends outbound notifications to chat and alert services
src/tools/notify.ts - Image utils · Image-related utilities for processing visual artifacts
src/tools/image.ts - Screenshot · Captures visual state for the agent to inspect
src/tools/screenshot.ts - Prompt optimizer · Refines prompts before they are sent to the model
src/tools/prompt-optimizer.ts
Other components
- Host system · Local machine environment where tools execute
- External services · Web search, SMTP, and notification endpoints used by tools
Connections 27
- CLI entry → Config flow: loads settings · Reads flags and runtime configuration
- CLI entry → Interactive mode: selects · Starts the REPL-style path when interactive
- CLI entry → Headless mode: selects · Starts the non-interactive batch path
- Interactive mode → Agent core: drives · Feeds user turns into the agent loop
- Headless mode → Agent core: invokes · Runs the agent for a single task or scriptable job
- Config flow → Agent core: configures · Supplies model, confirmation, and execution settings
- Agent core → LLM API: calls · Sends prompts and receives model/tool decisions
- Agent core → Confirm gate: checks · Pauses or auto-approves side-effecting actions
- Confirm gate → Tool registry: permits · Allows approved tool execution to proceed
- Agent core → Tool registry: dispatches · Routes tool calls to the matching implementation
- Tool registry → Tool contract: implements · Uses the shared tool interface to normalize tools
- Tool registry → Core tools: exposes · Registers local command and filesystem primitives
- Tool registry → Browser tool: exposes · Registers browser automation capability
- Tool registry → Search tool: exposes · Registers web search capability
- Tool registry → Email tool: exposes · Registers outbound email capability
- Tool registry → Notify tool: exposes · Registers notification integrations
- Tool registry → Image utils: exposes · Registers image processing helpers
- Tool registry → Screenshot: exposes · Registers screenshot capture capability
- Tool registry → Prompt optimizer: exposes · Registers prompt-shaping support
- Core tools → Host system: executes on · Reads and writes the local machine and shells out locally
- Search tool → External services: queries · Uses third-party search endpoints
- Email tool → External services: sends via · Delivers mail through SMTP infrastructure
- Notify tool → External services: posts to · Delivers webhook notifications to external services
- Browser tool → External services: browses · Interacts with remote web resources through browser automation
- Screenshot → Host system: captures · Uses the local runtime to capture screen state
- Image utils → Host system: processes · Handles local media artifacts
- Prompt optimizer → LLM API: prepares input · Improves prompt quality before model invocation