@tachu/extensions 1.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +77 -0
- package/LICENSE +201 -0
- package/README.md +825 -0
- package/README_ZH.md +815 -0
- package/dist/backends/file.d.ts +18 -0
- package/dist/backends/file.d.ts.map +1 -0
- package/dist/backends/file.js +69 -0
- package/dist/backends/file.js.map +1 -0
- package/dist/backends/index.d.ts +4 -0
- package/dist/backends/index.d.ts.map +1 -0
- package/dist/backends/index.js +4 -0
- package/dist/backends/index.js.map +1 -0
- package/dist/backends/terminal.d.ts +18 -0
- package/dist/backends/terminal.d.ts.map +1 -0
- package/dist/backends/terminal.js +57 -0
- package/dist/backends/terminal.js.map +1 -0
- package/dist/backends/web.d.ts +18 -0
- package/dist/backends/web.d.ts.map +1 -0
- package/dist/backends/web.js +53 -0
- package/dist/backends/web.js.map +1 -0
- package/dist/common/net.d.ts +31 -0
- package/dist/common/net.d.ts.map +1 -0
- package/dist/common/net.js +162 -0
- package/dist/common/net.js.map +1 -0
- package/dist/common/path.d.ts +18 -0
- package/dist/common/path.d.ts.map +1 -0
- package/dist/common/path.js +34 -0
- package/dist/common/path.js.map +1 -0
- package/dist/common/process.d.ts +19 -0
- package/dist/common/process.d.ts.map +1 -0
- package/dist/common/process.js +67 -0
- package/dist/common/process.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/index.d.ts +3 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +3 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/sse-adapter.d.ts +70 -0
- package/dist/mcp/sse-adapter.d.ts.map +1 -0
- package/dist/mcp/sse-adapter.js +176 -0
- package/dist/mcp/sse-adapter.js.map +1 -0
- package/dist/mcp/stdio-adapter.d.ts +73 -0
- package/dist/mcp/stdio-adapter.d.ts.map +1 -0
- package/dist/mcp/stdio-adapter.js +178 -0
- package/dist/mcp/stdio-adapter.js.map +1 -0
- package/dist/observability/index.d.ts +3 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +3 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability/jsonl-emitter.d.ts +58 -0
- package/dist/observability/jsonl-emitter.d.ts.map +1 -0
- package/dist/observability/jsonl-emitter.js +96 -0
- package/dist/observability/jsonl-emitter.js.map +1 -0
- package/dist/observability/otel-emitter.d.ts +52 -0
- package/dist/observability/otel-emitter.d.ts.map +1 -0
- package/dist/observability/otel-emitter.js +143 -0
- package/dist/observability/otel-emitter.js.map +1 -0
- package/dist/providers/anthropic.d.ts +54 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +298 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/index.d.ts +4 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +4 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/mock.d.ts +38 -0
- package/dist/providers/mock.d.ts.map +1 -0
- package/dist/providers/mock.js +79 -0
- package/dist/providers/mock.js.map +1 -0
- package/dist/providers/openai.d.ts +61 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +299 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/rules/index.d.ts +9 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +15 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/no-hallucination.md +11 -0
- package/dist/rules/no-sensitive-output.md +11 -0
- package/dist/rules/prefer-concise-response.md +11 -0
- package/dist/rules/require-tool-verification.md +11 -0
- package/dist/tools/apply-patch/descriptor.md +27 -0
- package/dist/tools/apply-patch/executor.d.ts +19 -0
- package/dist/tools/apply-patch/executor.d.ts.map +1 -0
- package/dist/tools/apply-patch/executor.js +190 -0
- package/dist/tools/apply-patch/executor.js.map +1 -0
- package/dist/tools/fetch-url/descriptor.md +38 -0
- package/dist/tools/fetch-url/executor.d.ts +20 -0
- package/dist/tools/fetch-url/executor.d.ts.map +1 -0
- package/dist/tools/fetch-url/executor.js +34 -0
- package/dist/tools/fetch-url/executor.js.map +1 -0
- package/dist/tools/index.d.ts +12 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +191 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/list-dir/descriptor.md +29 -0
- package/dist/tools/list-dir/executor.d.ts +22 -0
- package/dist/tools/list-dir/executor.d.ts.map +1 -0
- package/dist/tools/list-dir/executor.js +46 -0
- package/dist/tools/list-dir/executor.js.map +1 -0
- package/dist/tools/read-file/descriptor.md +28 -0
- package/dist/tools/read-file/executor.d.ts +15 -0
- package/dist/tools/read-file/executor.d.ts.map +1 -0
- package/dist/tools/read-file/executor.js +22 -0
- package/dist/tools/read-file/executor.js.map +1 -0
- package/dist/tools/run-shell/descriptor.md +39 -0
- package/dist/tools/run-shell/executor.d.ts +20 -0
- package/dist/tools/run-shell/executor.d.ts.map +1 -0
- package/dist/tools/run-shell/executor.js +76 -0
- package/dist/tools/run-shell/executor.js.map +1 -0
- package/dist/tools/search-code/descriptor.md +31 -0
- package/dist/tools/search-code/executor.d.ts +23 -0
- package/dist/tools/search-code/executor.d.ts.map +1 -0
- package/dist/tools/search-code/executor.js +113 -0
- package/dist/tools/search-code/executor.js.map +1 -0
- package/dist/tools/shared.d.ts +21 -0
- package/dist/tools/shared.d.ts.map +1 -0
- package/dist/tools/shared.js +12 -0
- package/dist/tools/shared.js.map +1 -0
- package/dist/tools/write-file/descriptor.md +30 -0
- package/dist/tools/write-file/executor.d.ts +16 -0
- package/dist/tools/write-file/executor.d.ts.map +1 -0
- package/dist/tools/write-file/executor.js +18 -0
- package/dist/tools/write-file/executor.js.map +1 -0
- package/dist/transformers/document-to-text.d.ts +23 -0
- package/dist/transformers/document-to-text.d.ts.map +1 -0
- package/dist/transformers/document-to-text.js +69 -0
- package/dist/transformers/document-to-text.js.map +1 -0
- package/dist/transformers/image-to-text.d.ts +38 -0
- package/dist/transformers/image-to-text.d.ts.map +1 -0
- package/dist/transformers/image-to-text.js +81 -0
- package/dist/transformers/image-to-text.js.map +1 -0
- package/dist/transformers/index.d.ts +3 -0
- package/dist/transformers/index.d.ts.map +1 -0
- package/dist/transformers/index.js +3 -0
- package/dist/transformers/index.js.map +1 -0
- package/dist/vector/index.d.ts +3 -0
- package/dist/vector/index.d.ts.map +1 -0
- package/dist/vector/index.js +3 -0
- package/dist/vector/index.js.map +1 -0
- package/dist/vector/local-fs.d.ts +76 -0
- package/dist/vector/local-fs.d.ts.map +1 -0
- package/dist/vector/local-fs.js +153 -0
- package/dist/vector/local-fs.js.map +1 -0
- package/dist/vector/qdrant.d.ts +65 -0
- package/dist/vector/qdrant.d.ts.map +1 -0
- package/dist/vector/qdrant.js +176 -0
- package/dist/vector/qdrant.js.map +1 -0
- package/package.json +74 -0
package/README.md
ADDED
|
@@ -0,0 +1,825 @@
|
|
|
1
|
+
# Tachu
|
|
2
|
+
|
|
3
|
+
**Production-grade agentic engine — the Harness that turns any LLM into a reliable, observable, production-ready Agent.**
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@tachu/core)
|
|
6
|
+
[](#license)
|
|
7
|
+
[](https://bun.sh)
|
|
8
|
+
[](https://www.typescriptlang.org)
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## What is Tachu?
|
|
13
|
+
|
|
14
|
+
Tachu is a **production-grade agentic engine** — not a toy demo, not a thin wrapper. It is the *Harness* in the equation **Agent = Model + Harness**: it provides the structural skeleton (protocol, lifecycle, safety, memory, orchestration) so that any LLM becomes a reliable, observable, production-capable Agent.
|
|
15
|
+
|
|
16
|
+
The engine is intentionally **domain-agnostic**: it knows nothing about your business logic, your users, or your domain vocabulary. Instead, it defines a small set of core abstractions (Rules, Skills, Tools, Agents) through which your business fills in all the intelligence. Tachu handles the hard parts — 9-phase execution pipeline, dual-plane semantic matching, context window management, token-precise prompt assembly, structured retry/fallback, cancellation propagation, and end-to-end observability.
|
|
17
|
+
|
|
18
|
+
Tachu ships as a Bun-native TypeScript monorepo with three packages: the zero-dependency engine core (`@tachu/core`), a production-quality official extensions library (`@tachu/extensions`), and a fully-featured CLI program (`@tachu/cli`) that doubles as the reference implementation.
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## Key Features
|
|
23
|
+
|
|
24
|
+
- **9-Phase Execution Pipeline** — session management → safety → intent analysis → pre-check → planning → DAG validation → execution → result validation → output normalization; each phase is a typed, hookable stage
|
|
25
|
+
- **Dual-Plane Matching** — semantic discovery (vector similarity) + deterministic execution gate (scopes, whitelist, approval) for every Rule, Skill, Tool, and Agent
|
|
26
|
+
- **Four Core Abstractions** — declare Rules, Skills, Tools, and Agents as Markdown + YAML frontmatter descriptors; the engine resolves, activates, and orchestrates them automatically
|
|
27
|
+
- **Dual Provider Support** — production-grade OpenAI and Anthropic adapters; configurable fallback order for zero-downtime provider switching
|
|
28
|
+
- **MCP Integration** — connect any MCP server (stdio or SSE) via `McpToolAdapter`; MCP tools become first-class engine Tools
|
|
29
|
+
- **Token-Precise Prompt Assembly** — tiktoken-based exact token counting; KV-cache-friendly prompt layout; automatic context compression (Head-Middle-Tail strategy)
|
|
30
|
+
- **Structured Memory** — session context window with configurable limits; archive-before-summarize guarantee; vector recall for long-term memory
|
|
31
|
+
- **OpenTelemetry Observability** — every phase entry/exit, LLM call, tool call, retry, and fallback emits a structured `EngineEvent`; OTel and JSONL emitters included
|
|
32
|
+
- **Production-Grade CLI** — `tachu chat` / `tachu run` / `tachu init` with full parameter sets, streaming render, session persistence, and Ctrl+C cancellation
|
|
33
|
+
- **Fail-Closed Safety Baseline** — loop protection, budget circuit-breaker, and basic input validation are hardwired into the engine and cannot be disabled
|
|
34
|
+
- **Qdrant & LocalFs Vector Stores** — plug in Qdrant for production-grade vector storage or use the built-in in-memory store for development
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Vision
|
|
39
|
+
|
|
40
|
+
> *太初有道,万物之始。以声明式描述符创造 Agent 万物。*
|
|
41
|
+
> *In the beginning was the Tao — all things arise from it. With declarative descriptors, conjure Agent capability from nothing.*
|
|
42
|
+
|
|
43
|
+
The long-term vision of Tachu is a universal Agent framework where **the engine provides the skeleton and business provides the blood**: any organization can build production-grade agentic systems on top of a stable, observable, auditable foundation without re-solving the hard problems of safety, context management, retry logic, and multi-provider orchestration every time.
|
|
44
|
+
|
|
45
|
+
Tachu is built around three convictions:
|
|
46
|
+
|
|
47
|
+
1. **The Harness is the hard part.** Model intelligence is commoditized; reliable orchestration is not. Tachu invests deeply in the engine infrastructure so application developers can focus on domain logic.
|
|
48
|
+
2. **Declaration over implementation.** Rules, Skills, Tools, and Agents are declared as plain Markdown files. The engine resolves them. No framework-specific boilerplate.
|
|
49
|
+
3. **Observable by default.** Every internal event is structured and emittable. Production systems need complete traces — Tachu provides them without opt-in instrumentation.
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## Core Abstractions
|
|
54
|
+
|
|
55
|
+
Tachu's four core abstractions are **co-equal and orthogonal** — each independently registered, independently activated, and composable across all engine phases.
|
|
56
|
+
|
|
57
|
+
| Abstraction | Nature | Activation Gate | Effect |
|
|
58
|
+
|-------------|--------|-----------------|--------|
|
|
59
|
+
| **Rules** | Constraints & guidance | Semantic discovery → direct activation | Injected into LLM System Prompt at each scoped phase |
|
|
60
|
+
| **Skills** | Knowledge & instructions | Semantic discovery → direct activation | Injected into LLM context when activated |
|
|
61
|
+
| **Tools** | Atomic executable operations | Semantic discovery → **mandatory gate** (scopes → whitelist → approval) | Executed with full side-effect tracking |
|
|
62
|
+
| **Agents** | Natural-language-driven execution units | Semantic discovery → activatable | Recursively use engine capabilities; all Tool calls pass through the Tool gate |
|
|
63
|
+
|
|
64
|
+
All four share a **common descriptor schema** (Markdown + YAML frontmatter):
|
|
65
|
+
|
|
66
|
+
```yaml
|
|
67
|
+
name: unique-name # required, unique within type
|
|
68
|
+
description: ... # natural language (used for semantic discovery)
|
|
69
|
+
tags: [tag1, tag2] # for filtering and classification
|
|
70
|
+
trigger: { type: always } # activation condition
|
|
71
|
+
requires:
|
|
72
|
+
- { kind: tool, name: read-file } # explicit dependency references
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Dual-Plane Matching Model
|
|
76
|
+
|
|
77
|
+
Every core abstraction is activated through a two-phase process:
|
|
78
|
+
|
|
79
|
+
```mermaid
|
|
80
|
+
graph LR
|
|
81
|
+
Input[Context Input] --> Discovery[Semantic Discovery Plane]
|
|
82
|
+
Discovery --> Index[(Vector Index)]
|
|
83
|
+
Index --> Candidates[Candidate Set]
|
|
84
|
+
Candidates --> Gate[Deterministic Execution Gate]
|
|
85
|
+
Gate -- scopes / whitelist / approval --> Execution[Execution Plane]
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
- **Semantic discovery plane**: `description` is vectorized on registration; at runtime, the current context is matched against the index to produce a candidate set
|
|
89
|
+
- **Deterministic execution gate**: final activation requires passing a deterministic gate (explicit references, whitelist checks, permission scopes, approval checks)
|
|
90
|
+
|
|
91
|
+
Rules and Skills pass through the gate freely (no side effects). Tools always pass through the full gate. Agents activate freely but all Tool calls they trigger still pass through the Tool gate.
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## Architecture Overview
|
|
96
|
+
|
|
97
|
+
### Three-Layer Structure
|
|
98
|
+
|
|
99
|
+
Tachu is published as three layers:
|
|
100
|
+
|
|
101
|
+
```mermaid
|
|
102
|
+
graph TD
|
|
103
|
+
subgraph "Business Layer"
|
|
104
|
+
A[Business Rules / Domain Tools / Custom Adapters / Domain Skills / Agents / Plan Templates]
|
|
105
|
+
end
|
|
106
|
+
subgraph "Extensions Library — @tachu/extensions"
|
|
107
|
+
B[OpenAI & Anthropic Adapters / 7 Common Tools / Terminal+File+Web Backends / Qdrant+LocalFs VectorStore / MCP Adapter / OTel+JSONL Emitters / 4 Common Rules]
|
|
108
|
+
end
|
|
109
|
+
subgraph "Engine Core — @tachu/core"
|
|
110
|
+
C[Protocol Definitions / 9-Phase Pipeline / Lifecycle Hooks / Session / Memory / Safety / Model Router / Runtime State]
|
|
111
|
+
end
|
|
112
|
+
A --> B
|
|
113
|
+
B --> C
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
| Layer | Package | Responsibility |
|
|
117
|
+
|-------|---------|----------------|
|
|
118
|
+
| Engine Core | `@tachu/core` | Protocol interfaces, 9-phase pipeline skeleton, 8 core modules, Registry, Prompt assembler, VectorStore interface + built-in light implementation |
|
|
119
|
+
| Extensions Library | `@tachu/extensions` | Official concrete implementations: Provider adapters, Tools, Backends, VectorStore adapters, OTel/JSONL emitters, common Rules |
|
|
120
|
+
| Business / CLI | `@tachu/cli` or your code | Assembles core + extensions into a working Agent; provides domain Rules/Skills/Tools/Agents |
|
|
121
|
+
|
|
122
|
+
### 9-Phase Execution Pipeline
|
|
123
|
+
|
|
124
|
+
Every request processed by the engine flows through exactly 9 phases:
|
|
125
|
+
|
|
126
|
+
```mermaid
|
|
127
|
+
graph TD
|
|
128
|
+
Start([Business Request]) --> S1[Phase 1: Session Management]
|
|
129
|
+
S1 --> S2[Phase 2: Minimum Safety Check]
|
|
130
|
+
S2 --> S3[Phase 3: Intent Analysis — LLM]
|
|
131
|
+
S3 -- simple --> S9[Phase 9: Output Normalization]
|
|
132
|
+
S3 -- complex --> S4[Phase 4: Pre-Check]
|
|
133
|
+
S4 --> S5[Phase 5: Task Planning]
|
|
134
|
+
S5 -- Plan mode --> PlanLoop{Plan Review Loop}
|
|
135
|
+
S5 -- Template match --> S6
|
|
136
|
+
S5 -- Dynamic split --> S6[Phase 6: DAG Validation]
|
|
137
|
+
PlanLoop -- confirmed --> S6
|
|
138
|
+
S6 --> S7[Phase 7: Sub-task Execution]
|
|
139
|
+
S7 --> S8[Phase 8: Result Validation — LLM]
|
|
140
|
+
S8 -- pass --> S9
|
|
141
|
+
S8 -- fail --> Retry{Retry / Re-plan}
|
|
142
|
+
Retry -- within limits --> S5
|
|
143
|
+
Retry -- exhausted --> S9
|
|
144
|
+
S9 --> End([Output])
|
|
145
|
+
|
|
146
|
+
style S2 fill:#ffeaa7,stroke:#fdcb6e
|
|
147
|
+
style S7 fill:#dfe6e9,stroke:#b2bec3
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
| # | Phase | LLM Call | Key Output |
|
|
151
|
+
|---|-------|----------|------------|
|
|
152
|
+
| 1 | Session Management | No | Session context loaded |
|
|
153
|
+
| 2 | Minimum Safety Check | No | Pass / reject |
|
|
154
|
+
| 3 | Intent Analysis | **Yes** | `IntentResult` (simple/complex, context relevance) |
|
|
155
|
+
| 4 | Pre-Check | No | Resource availability, deep safety validation |
|
|
156
|
+
| 5 | Task Planning | **Yes** | `PlanningResult` (ranked plans + DAG) |
|
|
157
|
+
| 6 | DAG Validation | No | Cycle detection, node integrity (deterministic) |
|
|
158
|
+
| 7 | Sub-task Execution | Per sub-task | `TaskResult[]` (parallel where possible) |
|
|
159
|
+
| 8 | Result Validation | **Yes** | `ValidationResult` (pass / execution_issue / planning_issue) |
|
|
160
|
+
| 9 | Output Normalization | No | `EngineOutput` (typed, with steps, metadata, artifacts) |
|
|
161
|
+
|
|
162
|
+
**Key pipeline properties:**
|
|
163
|
+
|
|
164
|
+
- **Full-path safety gating** — Phase 2 runs on every request, including fast-path simple responses
|
|
165
|
+
- **Context guard** — Phase 3 decides whether session history is relevant; irrelevant history is not forwarded
|
|
166
|
+
- **Three-strikes limit** — Task-level retries are bounded at 3 (configurable); system-level retries at 2
|
|
167
|
+
- **Last-message-wins** — A new request on the same session cancels the current execution via `AbortController`
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## Installation
|
|
172
|
+
|
|
173
|
+
Tachu requires [Bun](https://bun.sh) as the runtime.
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
# Install the engine core
|
|
177
|
+
bun add @tachu/core
|
|
178
|
+
|
|
179
|
+
# Install the extensions library (providers, tools, backends, vector stores)
|
|
180
|
+
bun add @tachu/extensions
|
|
181
|
+
|
|
182
|
+
# Install and use the CLI globally
|
|
183
|
+
bun add -g @tachu/cli
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
After global installation, verify with:
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
tachu --version
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## Quick Start
|
|
195
|
+
|
|
196
|
+
### CLI
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
# 1. Initialize a new project workspace
|
|
200
|
+
tachu init --template minimal --provider openai
|
|
201
|
+
|
|
202
|
+
# 2. Set your API key (used by the OpenAI provider adapter)
|
|
203
|
+
export OPENAI_API_KEY=sk-...
|
|
204
|
+
|
|
205
|
+
# 3. Run a single prompt
|
|
206
|
+
tachu run "Summarize the last 5 git commits in this repository"
|
|
207
|
+
|
|
208
|
+
# 4. Start an interactive chat session
|
|
209
|
+
tachu chat
|
|
210
|
+
|
|
211
|
+
# Resume the most recent session
|
|
212
|
+
tachu chat --resume
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Programmatic (TypeScript)
|
|
216
|
+
|
|
217
|
+
```typescript
|
|
218
|
+
import { Engine } from '@tachu/core';
|
|
219
|
+
import { OpenAIProviderAdapter } from '@tachu/extensions/providers';
|
|
220
|
+
import { FileBackend, TerminalBackend } from '@tachu/extensions/backends';
|
|
221
|
+
import type { EngineConfig, InputEnvelope, ExecutionContext } from '@tachu/core';
|
|
222
|
+
|
|
223
|
+
const config: EngineConfig = {
|
|
224
|
+
retry: { taskMaxRetries: 3, systemMaxRetries: 2 },
|
|
225
|
+
planning: { planCount: 1, enableValidation: true },
|
|
226
|
+
agent: { maxNestingDepth: 1 },
|
|
227
|
+
context: { maxTokens: 8000, compressionThreshold: 0.8 },
|
|
228
|
+
execution: { defaultTimeout: 120_000 },
|
|
229
|
+
models: {
|
|
230
|
+
capabilityMapping: {
|
|
231
|
+
'high-reasoning': 'gpt-4o',
|
|
232
|
+
'fast-cheap': 'gpt-4o-mini',
|
|
233
|
+
},
|
|
234
|
+
providerFallbackOrder: ['openai'],
|
|
235
|
+
},
|
|
236
|
+
safety: { maxInputSize: 1_000_000, maxRecursionDepth: 10 },
|
|
237
|
+
hooks: { writeHookTimeout: 5000, failureBehavior: 'continue' },
|
|
238
|
+
storage: {},
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
const engine = new Engine(config);
|
|
242
|
+
|
|
243
|
+
// Register a provider
|
|
244
|
+
engine.useProvider(new OpenAIProviderAdapter({ apiKey: process.env.OPENAI_API_KEY! }));
|
|
245
|
+
|
|
246
|
+
// Stream results
|
|
247
|
+
const input: InputEnvelope = {
|
|
248
|
+
content: 'Write a TypeScript function that debounces async operations',
|
|
249
|
+
metadata: { modality: 'text' },
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
const context: ExecutionContext = {
|
|
253
|
+
requestId: crypto.randomUUID(),
|
|
254
|
+
sessionId: 'session-001',
|
|
255
|
+
traceId: crypto.randomUUID(),
|
|
256
|
+
principal: { userId: 'user-001' },
|
|
257
|
+
budget: { maxTokens: 20_000, maxDurationMs: 60_000 },
|
|
258
|
+
scopes: ['read', 'write'],
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
for await (const chunk of engine.runStream(input, context)) {
|
|
262
|
+
if (chunk.type === 'delta') process.stdout.write(chunk.content);
|
|
263
|
+
if (chunk.type === 'done') console.log('\n\nCompleted:', chunk.output.status);
|
|
264
|
+
}
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
---
|
|
268
|
+
|
|
269
|
+
## Package Layout
|
|
270
|
+
|
|
271
|
+
### Package Summary
|
|
272
|
+
|
|
273
|
+
| Package | Description | Key Exports |
|
|
274
|
+
|---------|-------------|-------------|
|
|
275
|
+
| `@tachu/core` | Zero-dependency engine core | `Engine`, `Registry`, `PromptAssembler`, all interfaces and types |
|
|
276
|
+
| `@tachu/extensions` | Official implementations | `OpenAIProviderAdapter`, `AnthropicProviderAdapter`, `McpToolAdapter`, `QdrantVectorStore`, `OtelEmitter`, backends, tools, rules |
|
|
277
|
+
| `@tachu/cli` | Production CLI program | `tachu chat`, `tachu run`, `tachu init` |
|
|
278
|
+
|
|
279
|
+
### Dependency Relationship
|
|
280
|
+
|
|
281
|
+
```mermaid
|
|
282
|
+
graph LR
|
|
283
|
+
cli["@tachu/cli"]
|
|
284
|
+
extensions["@tachu/extensions"]
|
|
285
|
+
core["@tachu/core"]
|
|
286
|
+
|
|
287
|
+
cli --> extensions
|
|
288
|
+
cli --> core
|
|
289
|
+
extensions --> core
|
|
290
|
+
|
|
291
|
+
style core fill:#74b9ff,stroke:#0984e3
|
|
292
|
+
style extensions fill:#a29bfe,stroke:#6c5ce7
|
|
293
|
+
style cli fill:#fd79a8,stroke:#e84393
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
### Core Package Internal Structure
|
|
297
|
+
|
|
298
|
+
```
|
|
299
|
+
@tachu/core / src/
|
|
300
|
+
├── types/ # All TypeScript interfaces: descriptors, context, I/O, config
|
|
301
|
+
├── engine/ # Engine entry class, phase handlers, orchestrator, scheduler
|
|
302
|
+
├── registry/ # Registry: register/lookup/startup validation for all 4 abstractions
|
|
303
|
+
├── modules/ # 8 core modules (session, memory, runtime-state, model-router,
|
|
304
|
+
│ # provider, safety, observability, hooks)
|
|
305
|
+
├── prompt/ # PromptAssembler: token budgeting, KV-cache-friendly ordering
|
|
306
|
+
└── vector/ # VectorStore interface + built-in lightweight implementation
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
---
|
|
310
|
+
|
|
311
|
+
## Providers & Integrations
|
|
312
|
+
|
|
313
|
+
### LLM Providers
|
|
314
|
+
|
|
315
|
+
| Provider | Package | Streaming | Function Calling | Notes |
|
|
316
|
+
|----------|---------|-----------|-----------------|-------|
|
|
317
|
+
| OpenAI | `@tachu/extensions/providers` | ✅ | ✅ | GPT-4o, GPT-4o-mini, and all listable models |
|
|
318
|
+
| Anthropic | `@tachu/extensions/providers` | ✅ | ✅ | Claude 3.5 Sonnet and all listable models |
|
|
319
|
+
| Mock | `@tachu/extensions/providers` | ✅ | ✅ | For testing; configurable responses |
|
|
320
|
+
|
|
321
|
+
Provider fallback is configured via `models.providerFallbackOrder`. When a system-level error occurs (timeout, API error), the engine automatically switches to the next provider in the list without re-planning.
|
|
322
|
+
|
|
323
|
+
### MCP (Model Context Protocol)
|
|
324
|
+
|
|
325
|
+
```typescript
|
|
326
|
+
import { McpToolAdapter } from '@tachu/extensions/mcp';
|
|
327
|
+
|
|
328
|
+
const adapter = new McpToolAdapter();
|
|
329
|
+
|
|
330
|
+
// Connect via stdio (local process)
|
|
331
|
+
await adapter.connect('stdio://path/to/mcp-server');
|
|
332
|
+
|
|
333
|
+
// Connect via SSE (remote server)
|
|
334
|
+
await adapter.connect('http://localhost:3000/sse');
|
|
335
|
+
|
|
336
|
+
// MCP tools are automatically registered in the engine Registry
|
|
337
|
+
const tools = await adapter.listTools(); // returns ToolDescriptor[]
|
|
338
|
+
engine.registry.registerAll(tools);
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
The `McpToolAdapter` handles MCP session lifecycle, capability negotiation, and propagates engine cancellation signals to the MCP server.
|
|
342
|
+
|
|
343
|
+
### Vector Stores
|
|
344
|
+
|
|
345
|
+
| Adapter | Package | Use Case |
|
|
346
|
+
|---------|---------|----------|
|
|
347
|
+
| `InMemoryVectorStore` | `@tachu/core` | Development / testing; built-in, zero dependencies |
|
|
348
|
+
| `LocalFsVectorStore` | `@tachu/extensions/vector` | Single-process production; file-backed persistence |
|
|
349
|
+
| `QdrantVectorStore` | `@tachu/extensions/vector` | Multi-process production; full Qdrant REST API support |
|
|
350
|
+
|
|
351
|
+
```typescript
|
|
352
|
+
import { QdrantVectorStore } from '@tachu/extensions/vector';
|
|
353
|
+
|
|
354
|
+
const vectorStore = new QdrantVectorStore({
|
|
355
|
+
url: 'http://localhost:6333',
|
|
356
|
+
collectionName: 'tachu-descriptors',
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
engine.useVectorStore(vectorStore);
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
### Observability Emitters
|
|
363
|
+
|
|
364
|
+
| Emitter | Package | Output |
|
|
365
|
+
|---------|---------|--------|
|
|
366
|
+
| `OtelEmitter` | `@tachu/extensions/emitters` | OpenTelemetry spans via `@opentelemetry/api` |
|
|
367
|
+
| `JsonlEmitter` | `@tachu/extensions/emitters` | Append-only JSONL file |
|
|
368
|
+
| `ConsoleEmitter` | `@tachu/extensions/emitters` | Structured console output (development) |
|
|
369
|
+
|
|
370
|
+
### Execution Backends
|
|
371
|
+
|
|
372
|
+
| Backend | Package | Description |
|
|
373
|
+
|---------|---------|-------------|
|
|
374
|
+
| `TerminalBackend` | `@tachu/extensions/backends` | Shell command execution in a sandboxed terminal |
|
|
375
|
+
| `FileBackend` | `@tachu/extensions/backends` | File system read/write operations |
|
|
376
|
+
| `WebBackend` | `@tachu/extensions/backends` | HTTP requests to external APIs / web resources |
|
|
377
|
+
|
|
378
|
+
---
|
|
379
|
+
|
|
380
|
+
## Design Principles
|
|
381
|
+
|
|
382
|
+
Tachu is built on seven core engineering principles drawn from its architecture:
|
|
383
|
+
|
|
384
|
+
1. **Dual-Plane Matching** — All four core abstractions are discovered semantically (vector similarity) but activated deterministically (scopes, whitelist, approval). Semantic discovery is advisory; execution gates are authoritative.
|
|
385
|
+
|
|
386
|
+
2. **Full-Path Safety Gating** — The minimum safety check (Phase 2) runs on *every* request path, including the fast path for simple questions. Safety is never traded for performance.
|
|
387
|
+
|
|
388
|
+
3. **Three-Strikes Retry Limit** — Both the task-level retry loop and the system-level retry loop are strictly bounded. Unlimited retry is not allowed. When limits are exhausted, the engine outputs step-level completion status rather than a generic failure.
|
|
389
|
+
|
|
390
|
+
4. **KV-Cache-Friendly Prompt Assembly** — The System Prompt is assembled in a stable order (hard rules → soft preferences → skills → tool definitions) so that the prefix remains unchanged across turns, maximizing KV cache reuse and reducing LLM cost.
|
|
391
|
+
|
|
392
|
+
5. **Last-Message-Wins Cancellation** — When a new message arrives in the same session, the current execution is cancelled via `AbortController` and the new input is processed in the existing context. This guarantees coherent context while avoiding stale work.
|
|
393
|
+
|
|
394
|
+
6. **Engine Agnostic of Business Permissions** — The engine only evaluates coarse-grained `scopes` from the execution context at the Tool gate. Fine-grained business authorization is the responsibility of Tool implementations or dedicated authorization Tools.
|
|
395
|
+
|
|
396
|
+
7. **Fail-Closed Safety Baseline** — Loop protection, budget circuit-breaking, and basic input validation are hardwired into the engine core and *cannot* be disabled by configuration. Even with a completely empty business configuration, the engine does not run unconstrained.
|
|
397
|
+
|
|
398
|
+
---
|
|
399
|
+
|
|
400
|
+
## Configuration
|
|
401
|
+
|
|
402
|
+
The engine is configured via a `tachu.config.ts` file at the project root (generated by `tachu init`):
|
|
403
|
+
|
|
404
|
+
```typescript
|
|
405
|
+
import type { EngineConfig } from '@tachu/core';
|
|
406
|
+
|
|
407
|
+
const config: EngineConfig = {
|
|
408
|
+
// Descriptor registry
|
|
409
|
+
registry: {
|
|
410
|
+
descriptorRoot: '.tachu', // root directory for Rules/Skills/Tools/Agents
|
|
411
|
+
},
|
|
412
|
+
|
|
413
|
+
// Runtime behaviour
|
|
414
|
+
runtime: {
|
|
415
|
+
planMode: false, // enable Plan mode by default
|
|
416
|
+
maxConcurrency: 4, // max parallel sub-tasks
|
|
417
|
+
},
|
|
418
|
+
|
|
419
|
+
// Context window & memory
|
|
420
|
+
memory: {
|
|
421
|
+
maxTokens: 8000, // context window token limit
|
|
422
|
+
compressionThreshold: 0.8, // trigger compression at 80% capacity
|
|
423
|
+
archivePath: '.tachu/archive.jsonl',
|
|
424
|
+
vectorIndexLimit: 10000, // max entries in the built-in vector index
|
|
425
|
+
},
|
|
426
|
+
|
|
427
|
+
// Budget constraints
|
|
428
|
+
budget: {
|
|
429
|
+
maxTokens: 50000, // total token budget per execution
|
|
430
|
+
maxToolCalls: 50, // max tool calls per execution
|
|
431
|
+
maxWallTimeMs: 300000, // 5 minutes wall-time limit
|
|
432
|
+
},
|
|
433
|
+
|
|
434
|
+
// Safety baseline (hardwired minimum; add business policies via hooks)
|
|
435
|
+
safety: {
|
|
436
|
+
maxInputSize: 1_000_000, // bytes
|
|
437
|
+
maxRecursionDepth: 10,
|
|
438
|
+
enablePromptInjectionCheck: true,
|
|
439
|
+
},
|
|
440
|
+
|
|
441
|
+
// Model routing
|
|
442
|
+
models: {
|
|
443
|
+
capabilityMapping: {
|
|
444
|
+
'high-reasoning': { provider: 'openai', model: 'gpt-4o' },
|
|
445
|
+
'fast-cheap': { provider: 'openai', model: 'gpt-4o-mini' },
|
|
446
|
+
'vision': { provider: 'openai', model: 'gpt-4o' },
|
|
447
|
+
},
|
|
448
|
+
providerFallbackOrder: ['openai', 'anthropic'],
|
|
449
|
+
},
|
|
450
|
+
|
|
451
|
+
// Observability
|
|
452
|
+
observability: {
|
|
453
|
+
emitter: 'jsonl',
|
|
454
|
+
jsonlPath: '.tachu/events.jsonl',
|
|
455
|
+
},
|
|
456
|
+
};
|
|
457
|
+
|
|
458
|
+
export default config;
|
|
459
|
+
```
|
|
460
|
+
|
|
461
|
+
All fields have sensible defaults. `tachu init` generates this file pre-filled for your chosen provider.
|
|
462
|
+
|
|
463
|
+
---
|
|
464
|
+
|
|
465
|
+
## CLI Reference
|
|
466
|
+
|
|
467
|
+
### `tachu init`
|
|
468
|
+
|
|
469
|
+
Initialize a new Tachu project workspace.
|
|
470
|
+
|
|
471
|
+
```
|
|
472
|
+
tachu init [options]
|
|
473
|
+
|
|
474
|
+
Options:
|
|
475
|
+
--template <name> Scaffold template: minimal | full (default: minimal)
|
|
476
|
+
--force Overwrite existing files without prompting
|
|
477
|
+
--path <dir> Target directory (default: CWD)
|
|
478
|
+
--provider <name> Default provider: openai | anthropic | mock (default: mock)
|
|
479
|
+
--no-examples Skip generating example rule/tool descriptors
|
|
480
|
+
-h, --help Show help
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
Generates `.tachu/` directory skeleton + `tachu.config.ts` + `.gitignore` entries.
|
|
484
|
+
|
|
485
|
+
---
|
|
486
|
+
|
|
487
|
+
### `tachu run <prompt>`
|
|
488
|
+
|
|
489
|
+
Execute a single prompt and stream the result to stdout.
|
|
490
|
+
|
|
491
|
+
```
|
|
492
|
+
tachu run <prompt> [options]
|
|
493
|
+
|
|
494
|
+
Arguments:
|
|
495
|
+
<prompt> The prompt text (or pipe via stdin)
|
|
496
|
+
|
|
497
|
+
Options:
|
|
498
|
+
--session <id> Use a specific session ID
|
|
499
|
+
--resume Resume the most recent session
|
|
500
|
+
--model <name> Override the high-reasoning model
|
|
501
|
+
--provider <name> Override the default provider
|
|
502
|
+
--input <file> Read prompt from a file
|
|
503
|
+
--json Parse prompt as JSON (structured input)
|
|
504
|
+
--output <fmt> Output format: text | json | markdown (default: text)
|
|
505
|
+
--no-validation Skip Phase 8 result validation
|
|
506
|
+
--plan-mode Enable Plan mode (pause after Phase 5 for approval)
|
|
507
|
+
--verbose, -v Verbose output (phase transitions, LLM call details)
|
|
508
|
+
--no-color Disable ANSI color output (also respects NO_COLOR env var)
|
|
509
|
+
--timeout <ms> Wall-time limit (overrides budget.maxWallTimeMs)
|
|
510
|
+
-h, --help Show help
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
---
|
|
514
|
+
|
|
515
|
+
### `tachu chat`
|
|
516
|
+
|
|
517
|
+
Start an interactive multi-turn chat session.
|
|
518
|
+
|
|
519
|
+
```
|
|
520
|
+
tachu chat [options]
|
|
521
|
+
|
|
522
|
+
Options:
|
|
523
|
+
--session <id> Use a specific session ID
|
|
524
|
+
--resume Resume the most recent session
|
|
525
|
+
--history List all sessions and exit (no interactive prompt)
|
|
526
|
+
--export <file> Export a session to Markdown and exit
|
|
527
|
+
--model <name> Override the high-reasoning model
|
|
528
|
+
--provider <name> Override the default provider
|
|
529
|
+
--plan-mode Enable Plan mode
|
|
530
|
+
--verbose, -v Verbose output
|
|
531
|
+
--no-color Disable color output
|
|
532
|
+
-h, --help Show help
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
**Built-in interactive commands** (prefix with `/`):
|
|
536
|
+
|
|
537
|
+
| Command | Description |
|
|
538
|
+
|---------|-------------|
|
|
539
|
+
| `/exit` | Save session and quit |
|
|
540
|
+
| `/reset` | Clear the current session's memory |
|
|
541
|
+
| `/new` | Start a new session |
|
|
542
|
+
| `/list` | List all saved sessions |
|
|
543
|
+
| `/load <id>` | Switch to a specific session |
|
|
544
|
+
| `/save` | Manually persist the current session |
|
|
545
|
+
| `/export <path>` | Export session to a Markdown file |
|
|
546
|
+
| `/history` | Show this session's message history |
|
|
547
|
+
| `/stats` | Show token usage, tool calls, and remaining budget |
|
|
548
|
+
| `/help` | Show all commands |
|
|
549
|
+
|
|
550
|
+
**Ctrl+C behaviour:**
|
|
551
|
+
- First press: cancel the current LLM/Tool call (return to prompt, session intact)
|
|
552
|
+
- Second press within 1 second: save session and exit gracefully
|
|
553
|
+
- Third press: force exit
|
|
554
|
+
|
|
555
|
+
---
|
|
556
|
+
|
|
557
|
+
## Extension Guide
|
|
558
|
+
|
|
559
|
+
Tachu is extended by creating Markdown descriptor files in the `.tachu/` directory. No code changes are required for Rules, Skills, and Tools — only Agents need executable functions registered separately.
|
|
560
|
+
|
|
561
|
+
### Custom Rule
|
|
562
|
+
|
|
563
|
+
```markdown
|
|
564
|
+
<!-- .tachu/rules/no-external-calls.md -->
|
|
565
|
+
---
|
|
566
|
+
name: no-external-calls
|
|
567
|
+
description: Prevent the agent from making external network calls without explicit approval
|
|
568
|
+
type: rule
|
|
569
|
+
scope: [execution]
|
|
570
|
+
tags: [security, network]
|
|
571
|
+
---
|
|
572
|
+
|
|
573
|
+
Do not make HTTP requests, DNS lookups, or any other external network calls unless
|
|
574
|
+
the tool being invoked has `requiresApproval: true` and the user has confirmed.
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
### Custom Skill
|
|
578
|
+
|
|
579
|
+
```markdown
|
|
580
|
+
<!-- .tachu/skills/git-workflow/SKILL.md -->
|
|
581
|
+
---
|
|
582
|
+
name: git-workflow
|
|
583
|
+
description: Git branching, commit, and PR workflow knowledge for this repository
|
|
584
|
+
tags: [development, git]
|
|
585
|
+
requires:
|
|
586
|
+
- { kind: tool, name: run-command }
|
|
587
|
+
---
|
|
588
|
+
|
|
589
|
+
## Git Workflow
|
|
590
|
+
|
|
591
|
+
This repository follows trunk-based development with short-lived feature branches.
|
|
592
|
+
|
|
593
|
+
### Branch Naming
|
|
594
|
+
- Feature: `feat/<ticket>-<short-desc>`
|
|
595
|
+
- Fix: `fix/<ticket>-<short-desc>`
|
|
596
|
+
|
|
597
|
+
### Commit Convention
|
|
598
|
+
Use Conventional Commits: `type(scope): subject`
|
|
599
|
+
...
|
|
600
|
+
```
|
|
601
|
+
|
|
602
|
+
### Custom Tool
|
|
603
|
+
|
|
604
|
+
```markdown
|
|
605
|
+
<!-- .tachu/tools/query-db.md -->
|
|
606
|
+
---
|
|
607
|
+
name: query-db
|
|
608
|
+
description: Execute a read-only SQL query against the application database
|
|
609
|
+
sideEffect: readonly
|
|
610
|
+
idempotent: true
|
|
611
|
+
requiresApproval: false
|
|
612
|
+
timeout: 10000
|
|
613
|
+
inputSchema:
|
|
614
|
+
type: object
|
|
615
|
+
properties:
|
|
616
|
+
sql: { type: string, description: "SQL SELECT statement" }
|
|
617
|
+
limit: { type: number, description: "Max rows to return", default: 100 }
|
|
618
|
+
required: [sql]
|
|
619
|
+
execute: queryDatabase
|
|
620
|
+
---
|
|
621
|
+
|
|
622
|
+
Executes a parameterized read-only SQL query. Results are returned as a JSON array.
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
Register the execution function in your `engine-factory.ts`:
|
|
626
|
+
|
|
627
|
+
```typescript
|
|
628
|
+
engine.registry.registerExecutor('queryDatabase', async (input, ctx) => {
|
|
629
|
+
const { sql, limit = 100 } = input as { sql: string; limit?: number };
|
|
630
|
+
return db.query(sql).limit(limit).execute();
|
|
631
|
+
});
|
|
632
|
+
```
|
|
633
|
+
|
|
634
|
+
### Custom Agent
|
|
635
|
+
|
|
636
|
+
```markdown
|
|
637
|
+
<!-- .tachu/agents/code-reviewer.md -->
|
|
638
|
+
---
|
|
639
|
+
name: code-reviewer
|
|
640
|
+
description: Reviews pull request diffs and produces structured code review feedback
|
|
641
|
+
sideEffect: readonly
|
|
642
|
+
idempotent: true
|
|
643
|
+
requiresApproval: false
|
|
644
|
+
timeout: 180000
|
|
645
|
+
maxDepth: 1
|
|
646
|
+
availableTools: [read-file, search-code, run-command]
|
|
647
|
+
---
|
|
648
|
+
|
|
649
|
+
You are a careful code reviewer. When given a diff or a set of files:
|
|
650
|
+
1. Understand the intent of the change
|
|
651
|
+
2. Review for correctness, clarity, security, and performance
|
|
652
|
+
3. Produce a structured review with severity levels: critical / major / minor / nit
|
|
653
|
+
```
|
|
654
|
+
|
|
655
|
+
---
|
|
656
|
+
|
|
657
|
+
## Observability & Safety
|
|
658
|
+
|
|
659
|
+
### OpenTelemetry Integration
|
|
660
|
+
|
|
661
|
+
Every engine event maps to an OTel span, enabling full distributed tracing:
|
|
662
|
+
|
|
663
|
+
```typescript
|
|
664
|
+
import { OtelEmitter } from '@tachu/extensions/emitters';
|
|
665
|
+
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
|
|
666
|
+
import { SimpleSpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
667
|
+
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
|
|
668
|
+
|
|
669
|
+
const provider = new NodeTracerProvider();
|
|
670
|
+
provider.addSpanProcessor(
|
|
671
|
+
new SimpleSpanProcessor(new OTLPTraceExporter({ url: 'http://localhost:4318/v1/traces' }))
|
|
672
|
+
);
|
|
673
|
+
provider.register();
|
|
674
|
+
|
|
675
|
+
const engine = new Engine({
|
|
676
|
+
...config,
|
|
677
|
+
// The OtelEmitter consumes EngineEvents and creates OTel spans
|
|
678
|
+
});
|
|
679
|
+
engine.useEmitter(new OtelEmitter());
|
|
680
|
+
```
|
|
681
|
+
|
|
682
|
+
**Events emitted for every request:**
|
|
683
|
+
|
|
684
|
+
| Event Type | When |
|
|
685
|
+
|-----------|------|
|
|
686
|
+
| `phase_enter` / `phase_exit` | Every pipeline phase |
|
|
687
|
+
| `llm_call_start` / `llm_call_end` | Every LLM invocation |
|
|
688
|
+
| `tool_call_start` / `tool_call_end` | Every Tool execution |
|
|
689
|
+
| `retry` | Task-level or system-level retry triggered |
|
|
690
|
+
| `provider_fallback` | Provider downgrade initiated |
|
|
691
|
+
| `budget_warning` | Budget at 80% of limit |
|
|
692
|
+
| `budget_exhausted` | Budget circuit-breaker activated |
|
|
693
|
+
| `error` | Any `EngineError` subclass |
|
|
694
|
+
|
|
695
|
+
### Safety Module
|
|
696
|
+
|
|
697
|
+
The Safety module operates in two independent layers:
|
|
698
|
+
|
|
699
|
+
**Engine baseline (non-disableable):**
|
|
700
|
+
- Input size enforcement (`maxInputSize` bytes)
|
|
701
|
+
- Recursion depth limit (`maxRecursionDepth`)
|
|
702
|
+
- Budget circuit-breaker (terminates immediately when token/time budget is exhausted)
|
|
703
|
+
|
|
704
|
+
**Business-injectable policies** (via hooks or configuration):
|
|
705
|
+
- Prompt injection detection (`enablePromptInjectionCheck: true`)
|
|
706
|
+
- Sensitive operation interception (register via `engine.registerSafetyPolicy()`)
|
|
707
|
+
- Output content compliance checks
|
|
708
|
+
|
|
709
|
+
```typescript
|
|
710
|
+
// Register a custom safety policy
|
|
711
|
+
engine.registerSafetyPolicy(async (input, ctx) => {
|
|
712
|
+
if (containsPersonalData(input.content)) {
|
|
713
|
+
return { passed: false, violations: [{ type: 'pii', message: 'PII detected in input' }] };
|
|
714
|
+
}
|
|
715
|
+
return { passed: true, violations: [] };
|
|
716
|
+
});
|
|
717
|
+
```
|
|
718
|
+
|
|
719
|
+
---
|
|
720
|
+
|
|
721
|
+
## Roadmap
|
|
722
|
+
|
|
723
|
+
### v1.0.0 — Delivered
|
|
724
|
+
|
|
725
|
+
- [x] `@tachu/core`: Engine, 9-phase pipeline, 8 modules, Registry, PromptAssembler, InMemoryVectorStore, full error taxonomy
|
|
726
|
+
- [x] `@tachu/extensions`: OpenAI + Anthropic providers, 7 tools, Terminal/File/Web backends, LocalFs + Qdrant VectorStore, MCP stdio+SSE adapters, OTel+JSONL emitters, 4 common rules
|
|
727
|
+
- [x] `@tachu/cli`: `tachu init` / `tachu run` / `tachu chat` with full parameter sets, session persistence, streaming renderer
|
|
728
|
+
- [x] Test suite (≥80% line coverage) and performance benchmarks
|
|
729
|
+
- [x] English and Chinese READMEs
|
|
730
|
+
|
|
731
|
+
### v1.x — Planned
|
|
732
|
+
|
|
733
|
+
- Additional VectorStore adapters (Pinecone, pgvector)
|
|
734
|
+
- Additional Provider adapters (Google Gemini, Mistral)
|
|
735
|
+
- Additional MCP tool integrations
|
|
736
|
+
- More built-in compression strategies
|
|
737
|
+
- Structured Plan template library
|
|
738
|
+
|
|
739
|
+
### v2 — Vision
|
|
740
|
+
|
|
741
|
+
- Multi-agent collaboration (agent-to-agent communication protocol)
|
|
742
|
+
- Persistent long-term memory across deployment restarts
|
|
743
|
+
- Fine-grained budget allocation per sub-task
|
|
744
|
+
|
|
745
|
+
---
|
|
746
|
+
|
|
747
|
+
## Contributing
|
|
748
|
+
|
|
749
|
+
### Requirements
|
|
750
|
+
|
|
751
|
+
- [Bun](https://bun.sh) >= 1.1.0
|
|
752
|
+
- TypeScript 5.x (provided via dev dependencies)
|
|
753
|
+
|
|
754
|
+
### Development Workflow
|
|
755
|
+
|
|
756
|
+
```bash
|
|
757
|
+
# Clone and install
|
|
758
|
+
git clone https://github.com/dangaogit/tachu
|
|
759
|
+
cd tachu
|
|
760
|
+
bun install
|
|
761
|
+
|
|
762
|
+
# Run all tests
|
|
763
|
+
bun test
|
|
764
|
+
|
|
765
|
+
# Type check
|
|
766
|
+
bun run typecheck
|
|
767
|
+
|
|
768
|
+
# Build all packages
|
|
769
|
+
bun run build
|
|
770
|
+
|
|
771
|
+
# Run a specific package's tests
|
|
772
|
+
bun test --filter packages/core
|
|
773
|
+
```
|
|
774
|
+
|
|
775
|
+
### Project Conventions
|
|
776
|
+
|
|
777
|
+
- File names: `kebab-case`
|
|
778
|
+
- Classes and types: `PascalCase`
|
|
779
|
+
- Functions and variables: `camelCase`
|
|
780
|
+
- Constants: `SCREAMING_SNAKE_CASE`
|
|
781
|
+
- All public APIs must have TSDoc comments (`@param`, `@returns`, `@throws`, `@example`)
|
|
782
|
+
- Test files co-located with source: `*.test.ts`
|
|
783
|
+
- Integration tests under `__tests__/`
|
|
784
|
+
|
|
785
|
+
Pull requests require:
|
|
786
|
+
- All tests passing (`bun test`)
|
|
787
|
+
- Zero TypeScript errors (`bun run typecheck`)
|
|
788
|
+
- Coverage thresholds met (≥80% line, ≥70% branch)
|
|
789
|
+
- TSDoc on any new public API
|
|
790
|
+
|
|
791
|
+
See `CONTRIBUTING.md` for full guidelines.
|
|
792
|
+
|
|
793
|
+
---
|
|
794
|
+
|
|
795
|
+
## Benchmarks
|
|
796
|
+
|
|
797
|
+
Performance baselines are established in `packages/core/benchmarks/` and run with `bun test`:
|
|
798
|
+
|
|
799
|
+
| Benchmark | Metric | Baseline |
|
|
800
|
+
|-----------|--------|----------|
|
|
801
|
+
| `scheduler.bench.ts` — 100 parallel tasks | Scheduling throughput | *Populated by verifier phase* |
|
|
802
|
+
| `vector-store.bench.ts` — 10,000 entries, topK=10 | Search QPS | *Populated by verifier phase* |
|
|
803
|
+
| `prompt-assembler.bench.ts` — 4K token window assembly | Assembly latency (p99) | *Populated by verifier phase* |
|
|
804
|
+
|
|
805
|
+
Benchmarks serve as regression baselines; there are no minimum performance requirements for v1.
|
|
806
|
+
|
|
807
|
+
---
|
|
808
|
+
|
|
809
|
+
## Documentation
|
|
810
|
+
|
|
811
|
+
| Document | Description |
|
|
812
|
+
|----------|-------------|
|
|
813
|
+
| [Architecture Design](./docs/adr/architecture-design.md) | Vision, three-layer structure, four core abstractions, 9-phase pipeline design |
|
|
814
|
+
| [Detailed Design](./docs/adr/detailed-design.md) | TypeScript interfaces, module specs, configuration schema |
|
|
815
|
+
| [Technical Design](./docs/adr/technical-design.md) | Technology choices, engineering structure, implementation guide |
|
|
816
|
+
|
|
817
|
+
---
|
|
818
|
+
|
|
819
|
+
## License
|
|
820
|
+
|
|
821
|
+
[Apache License 2.0](./LICENSE) © 2026 Tachu Contributors
|
|
822
|
+
|
|
823
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this project except in compliance with the License. A copy of the License is included in the [LICENSE](./LICENSE) file or may be obtained at <http://www.apache.org/licenses/LICENSE-2.0>.
|
|
824
|
+
|
|
825
|
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|