@aeye/cletus 0.1.8 → 0.3.0

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.
Files changed (4) hide show
  1. package/README.md +179 -331
  2. package/dist/embed-worker.js +100 -0
  3. package/dist/index.js +128571 -105557
  4. package/package.json +114 -104
package/README.md CHANGED
@@ -9,28 +9,74 @@ Cletus is a terminal-based AI assistant built with the @aeye library that demons
9
9
 
10
10
  ## Features
11
11
 
12
- ### 🤖 Specialized AI Agents
12
+ ### Adaptive Tooling
13
13
 
14
- Cletus organizes its capabilities into specialized agents, each with domain-specific tools:
14
+ Cletus uses an intelligent tool selection system that automatically picks the most relevant tools based on your conversation context. Instead of having access to all 50+ tools at once (which can overwhelm the AI), Cletus:
15
15
 
16
- - **Architect** - Type definition management for custom data structures
17
- - **Artist** - Image generation, editing, analysis, and semantic search
18
- - **Clerk** - File operations, searching, indexing, and summarization
19
- - **DBA** - Database-like operations on typed data with CRUD capabilities
20
- - **Internet** - Web search, page scraping, and REST API calls
21
- - **Librarian** - Knowledge base management with semantic search
22
- - **Planner** - Todo list management and task tracking
23
- - **Secretary** - Assistant persona management and user memory
16
+ 1. **Analyzes your recent messages** - Uses embeddings to understand what you're asking about
17
+ 2. **Selects relevant tools** - Picks the top 15-20 most semantically similar tools for the task
18
+ 3. **Adapts over time** - As your conversation evolves, the available tools adjust automatically
19
+
20
+ You can also manually switch between specialized **toolsets** to focus on specific domains:
21
+
22
+ - **planner** - Task management and todo operations
23
+ - **librarian** - Knowledge base and semantic search
24
+ - **clerk** - File system operations and shell commands
25
+ - **secretary** - User memories and assistant management
26
+ - **architect** - Custom data type definitions and schema management
27
+ - **artist** - Image generation, editing, and analysis
28
+ - **internet** - Web search and API operations
29
+ - **dba** - Data record management and querying
30
+
31
+ Use the `retool` tool to switch between adaptive mode and specific toolsets
32
+
33
+ ### Examples
34
+
35
+ Here are some examples of what you can do with Cletus:
36
+
37
+ **File Operations:**
38
+ - "Search for all TypeScript files in the src directory"
39
+ - "Read package.json and tell me what dependencies are outdated"
40
+ - "Create a new file called README.md with a project description"
41
+ - "Find all files containing the word 'TODO' and summarize them"
42
+
43
+ **Data Management:**
44
+ - "Create a 'Recipe' type with fields for ingredients, instructions, and cooking time"
45
+ - "Add a new recipe for chocolate chip cookies"
46
+ - "Find all recipes that contain chocolate"
47
+
48
+ **Task Planning:**
49
+ - "Add a todo to implement user authentication"
50
+ - "Show me all my pending todos"
51
+ - "Mark the first todo as done"
52
+
53
+ **Image Operations:**
54
+ - "Generate an image of a sunset over mountains"
55
+ - "Find all images I've generated that contain trees"
56
+ - "Analyze this screenshot and describe what you see"
57
+
58
+ **Web Research:**
59
+ - "Search the web for the latest TypeScript features"
60
+ - "Get the content from https://example.com and summarize it"
61
+
62
+ **Knowledge Base:**
63
+ - "Remember that I prefer tabs over spaces"
64
+ - "Index all files in my project for semantic search"
65
+ - "Search my knowledge base for information about authentication"
66
+
67
+ **Shell Commands:**
68
+ - "Run npm test and show me the results"
69
+ - "Execute git status and tell me what files have changed"
24
70
 
25
71
  ### 🎨 Interactive Terminal UI
26
72
 
27
73
  - Beautiful React/Ink-based interface
28
- - Automatic light/dark mode theme detection for optimal color visibility
29
74
  - Chat history management
30
75
  - Real-time streaming responses
31
- - Syntax-highlighted code blocks
76
+ - Markdown rendering
32
77
  - Operation approval/rejection system
33
78
  - Settings configuration wizard
79
+ - Automatic light/dark mode theme detection for optimal color visibility
34
80
 
35
81
  ### 💾 Persistent Storage
36
82
 
@@ -76,16 +122,6 @@ npm link
76
122
  cletus
77
123
  ```
78
124
 
79
- ### Development Mode
80
-
81
- ```bash
82
- # Watch mode with hot reload
83
- npm run dev
84
-
85
- # Or run directly with tsx
86
- npm start
87
- ```
88
-
89
125
  ## Quick Start
90
126
 
91
127
  ### First Launch
@@ -111,6 +147,10 @@ cletus
111
147
  # - Exit
112
148
  ```
113
149
 
150
+ ### Command Line Arguments
151
+
152
+ - `--profile=NAME` or `--profile NAME` - Use a specific configuration profile
153
+
114
154
  ### Creating a Chat
115
155
 
116
156
  1. Select "New Chat" from the main menu
@@ -118,6 +158,93 @@ cletus
118
158
  3. Optionally provide a custom system prompt
119
159
  4. Start chatting!
120
160
 
161
+ ## Tools
162
+
163
+ Cletus provides 50+ tools organized into specialized toolsets. Here's what each toolset offers:
164
+
165
+ ### 🗂️ Planner (`planner`)
166
+ Task management and todo operations:
167
+ - `todosList` - View all todos
168
+ - `todosAdd` - Add a new todo
169
+ - `todosDone` - Mark a todo as complete
170
+ - `todosGet` - Get a specific todo by ID
171
+ - `todosRemove` - Remove a todo
172
+ - `todosReplace` - Replace/update a todo
173
+ - `todosClear` - Clear all todos
174
+
175
+ ### 📚 Librarian (`librarian`)
176
+ Knowledge base with semantic search:
177
+ - `knowledgeSearch` - Search knowledge base semantically
178
+ - `knowledgeSources` - List all knowledge sources
179
+ - `knowledgeAdd` - Add user memories to knowledge base
180
+ - `knowledgeDelete` - Delete knowledge source
181
+
182
+ ### 📁 Clerk (`clerk`)
183
+ File system operations and shell commands:
184
+ - `fileSearch` - Search files by glob pattern
185
+ - `fileSummary` - Get AI summary of file content
186
+ - `fileIndex` - Index files into knowledge base
187
+ - `fileRead` - Read file contents
188
+ - `fileEdit` - Edit file with find/replace
189
+ - `fileCreate` - Create new file
190
+ - `fileCopy` - Copy file
191
+ - `fileMove` - Move/rename file
192
+ - `fileDelete` - Delete file
193
+ - `fileStats` - Get file metadata
194
+ - `fileAttach` - Attach file to message
195
+ - `textSearch` - Search file contents with regex
196
+ - `dirCreate` - Create directory
197
+ - `dirSummary` - Summarize directory contents
198
+ - `shell` - Execute shell commands
199
+
200
+ ### 👤 Secretary (`secretary`)
201
+ User preferences and assistant management:
202
+ - `assistantSwitch` - Switch to different assistant
203
+ - `assistantUpdate` - Update assistant prompt
204
+ - `assistantAdd` - Create new assistant
205
+ - `memoryList` - List user memories
206
+ - `memoryUpdate` - Update user memories
207
+
208
+ ### 🏗️ Architect (`architect`)
209
+ Custom data type system:
210
+ - `typeList` - List all custom types
211
+ - `typeInfo` - Get type definition
212
+ - `typeCreate` - Define new data type
213
+ - `typeUpdate` - Update type definition
214
+ - `typeDelete` - Delete type
215
+ - `typeImport` - Import type from JSON schema
216
+
217
+ ### 🎨 Artist (`artist`)
218
+ Image generation and analysis:
219
+ - `imageGenerate` - Generate images from text
220
+ - `imageEdit` - Edit existing images
221
+ - `imageAnalyze` - Analyze image with vision AI
222
+ - `imageDescribe` - Get detailed image description
223
+ - `imageFind` - Search generated images
224
+ - `imageAttach` - Attach image to message
225
+
226
+ ### 🌐 Internet (`internet`)
227
+ Web operations:
228
+ - `webSearch` - Search the web (via Tavily)
229
+ - `webGetPage` - Fetch and extract page content
230
+ - `webApiCall` - Make HTTP API requests
231
+
232
+ ### 💾 DBA (`dba`)
233
+ Data record management:
234
+ - `dataIndex` - Index data records into knowledge base
235
+ - `dataImport` - Import data from files
236
+ - `dataSearch` - Semantic search over data records
237
+ - `dataGet` - Get specific data record
238
+ - `dbaQuery` - Query data with filters and sorting
239
+
240
+ ### 🔧 Utility (always available)
241
+ Core system tools:
242
+ - `getOperationOutput` - Retrieve truncated operation output
243
+ - `about` - Information about Cletus
244
+ - `retool` - Switch toolsets or enable adaptive mode
245
+ - `hypothetical` - Switch to restrictive mode for exploration
246
+ - `ask` - Ask user multiple-choice questions with special UI
247
+
121
248
  ## Configuration
122
249
 
123
250
  Cletus stores its data in `~/.cletus/`:
@@ -138,277 +265,21 @@ Cletus stores its data in `~/.cletus/`:
138
265
  ### Provider Configuration
139
266
 
140
267
  Cletus supports multiple AI providers:
268
+ - OpenAI (For all model types)
269
+ - OpenRouter (For chat models)
270
+ - Replicate (For image generation & editing primarily)
271
+ - AWS (For chat models)
272
+ - Tavily (For web search)
141
273
 
142
- #### OpenAI
143
-
144
- ```json
145
- {
146
- "providers": {
147
- "openai": {
148
- "apiKey": "sk-...",
149
- "organization": "org-...", // Optional
150
- "project": "proj_...", // Optional
151
- "defaultModels": {
152
- "chat": "gpt-4o",
153
- "imageGenerate": "dall-e-3",
154
- "transcription": "whisper-1",
155
- "embedding": "text-embedding-3-large"
156
- }
157
- }
158
- }
159
- }
160
- ```
161
-
162
- #### OpenRouter
163
-
164
- ```json
165
- {
166
- "providers": {
167
- "openrouter": {
168
- "apiKey": "sk-or-...",
169
- "defaultParams": {
170
- "siteUrl": "https://yoursite.com",
171
- "appName": "Cletus",
172
- "providers": {
173
- "order": ["openai", "anthropic"],
174
- "allowFallbacks": true
175
- }
176
- }
177
- }
178
- }
179
- }
180
- ```
181
-
182
- #### Replicate
183
-
184
- ```json
185
- {
186
- "providers": {
187
- "replicate": {
188
- "apiKey": "r8_..."
189
- }
190
- }
191
- }
192
- ```
193
-
194
- #### AWS Bedrock
195
-
196
- Access to Claude, Llama, Mistral, and other models via AWS Bedrock. Supports credential auto-discovery from environment variables or IAM roles.
197
-
198
- ```json
199
- {
200
- "providers": {
201
- "aws": {
202
- "region": "us-east-1",
203
- "credentials": {
204
- "accessKeyId": "AKIA...",
205
- "secretAccessKey": "..."
206
- }
207
- }
208
- }
209
- }
210
- ```
211
-
212
- Alternatively, set environment variables (recommended):
213
- ```bash
214
- export AWS_REGION=us-east-1
215
- export AWS_ACCESS_KEY_ID=AKIA...
216
- export AWS_SECRET_ACCESS_KEY=...
217
- ```
218
-
219
- #### Tavily (Web Search)
220
-
221
- ```json
222
- {
223
- "tavily": {
224
- "apiKey": "tvly-..."
225
- }
226
- }
227
- ```
274
+ Common environment variables & AWS profiles are auto-detected
228
275
 
229
276
  ### Model Selection
230
277
 
231
- Override default models in the user configuration:
232
-
233
- ```json
234
- {
235
- "user": {
236
- "models": {
237
- "chat": "gpt-4o-mini",
238
- "imageGenerate": "dall-e-3",
239
- "imageAnalyze": "gpt-4o",
240
- "embedding": "text-embedding-3-small",
241
- "summary": "gpt-4o-mini"
242
- }
243
- }
244
- }
245
- ```
278
+ In the settings you can configure what models you want to use for each behavior.
246
279
 
247
280
  ### Autonomous Mode
248
281
 
249
- Configure how the AI handles operations:
250
-
251
- ```json
252
- {
253
- "user": {
254
- "autonomous": {
255
- "maxIterations": 10, // Max tool calls without approval
256
- "timeout": 300000 // 5 minutes in milliseconds
257
- }
258
- }
259
- }
260
- ```
261
-
262
- ## Tool Categories
263
-
264
- ### Architect Tools
265
-
266
- Manage custom data type definitions:
267
-
268
- - `type_info` - View type schema and fields
269
- - `type_create` - Create new type definitions
270
- - `type_update` - Update types (backwards compatible)
271
-
272
- ### Artist Tools
273
-
274
- Image operations:
275
-
276
- - `image_generate` - Generate images from prompts
277
- - `image_edit` - Edit existing images
278
- - `image_analyze` - Ask questions about images
279
- - `image_describe` - Get detailed image descriptions
280
- - `image_find` - Semantic search over images
281
-
282
- ### Clerk Tools
283
-
284
- File management:
285
-
286
- - `file_search` - Find files with glob patterns
287
- - `file_summary` - AI-generated file summaries
288
- - `file_index` - Index files for semantic search
289
- - `file_create` - Create new files
290
- - `file_read` - Read file contents
291
- - `file_edit` - Edit file contents
292
- - `file_copy` - Copy files
293
- - `file_move` - Move/rename files
294
- - `file_delete` - Delete files
295
- - `file_stats` - Get file metadata
296
- - `text_search` - Search text content with regex
297
- - `dir_create` - Create directories
298
-
299
- ### DBA Tools
300
-
301
- Data operations (dynamically generated for each custom type):
302
-
303
- - `data_create` - Create new records
304
- - `data_update` - Update records by ID
305
- - `data_delete` - Delete records by ID
306
- - `data_select` - Query records with filters
307
- - `data_update_many` - Bulk update operations
308
- - `data_delete_many` - Bulk delete operations
309
- - `data_aggregate` - Count and aggregate data
310
- - `data_index` - Reindex knowledge base
311
- - `data_import` - Import from files (CSV, JSON, etc.)
312
- - `data_search` - Semantic search over records
313
-
314
- ### Internet Tools
315
-
316
- Web operations:
317
-
318
- - `web_search` - Search the web (via Tavily)
319
- - `web_get_page` - Scrape web pages
320
- - `web_api_call` - Make REST API requests
321
-
322
- ### Librarian Tools
323
-
324
- Knowledge base management:
325
-
326
- - `knowledge_search` - Semantic search
327
- - `knowledge_sources` - List knowledge sources
328
- - `knowledge_add` - Add user memories
329
- - `knowledge_delete` - Remove knowledge entries
330
-
331
- ### Planner Tools
332
-
333
- Task management:
334
-
335
- - `todos_list` - List all todos
336
- - `todos_add` - Add new todo
337
- - `todos_done` - Mark todo complete
338
- - `todos_get` - Get todo details
339
- - `todos_remove` - Delete todo
340
- - `todos_clear` - Clear all todos
341
- - `todos_replace` - Replace entire todo list
342
-
343
- ### Secretary Tools
344
-
345
- Assistant and memory management:
346
-
347
- - `assistant_switch` - Change assistant persona
348
- - `assistant_update` - Modify assistant prompt
349
- - `assistant_add` - Create new assistant
350
- - `memory_list` - View user memories
351
- - `memory_update` - Add/update memories
352
-
353
- ## Examples
354
-
355
- ### File Operations
356
-
357
- ```
358
- You: Summarize all TypeScript files in the src directory
359
-
360
- Cletus: I'll search for TypeScript files and summarize them...
361
- [Uses file_search and file_summary tools]
362
- ```
363
-
364
- ### Data Management
365
-
366
- ```
367
- You: Create a new type for tracking books with title, author, and year
368
-
369
- Cletus: I'll create a book type definition...
370
- [Uses type_create tool]
371
-
372
- You: Add "1984" by George Orwell published in 1949
373
-
374
- Cletus: I'll create a new book record...
375
- [Uses data_create tool with the book type]
376
- ```
377
-
378
- ### Image Generation
379
-
380
- ```
381
- You: Generate an image of a sunset over mountains
382
-
383
- Cletus: I'll generate that image for you...
384
- [Uses image_generate tool, saves to .cletus/images/]
385
- [Generated image: sunset_mountains_abc123.png](~/.cletus/images/sunset_mountains_abc123.png)
386
- ```
387
-
388
- ### Web Research
389
-
390
- ```
391
- You: Search for recent TypeScript 5.0 features and summarize them
392
-
393
- Cletus: Let me search for that information...
394
- [Uses web_search tool]
395
- [Summarizes findings from multiple sources]
396
- ```
397
-
398
- ### Knowledge Base
399
-
400
- ```
401
- You: Remember that I prefer using async/await over promises
402
-
403
- Cletus: I'll add that to your memories...
404
- [Uses knowledge_add tool]
405
-
406
- You: What are my coding preferences?
407
-
408
- Cletus: Let me search your memories...
409
- [Uses knowledge_search tool]
410
- You prefer using async/await over promises...
411
- ```
282
+ You choose how autonomous Cletus is - either automatically performing certain operations or asking for approval.
412
283
 
413
284
  ## Custom Assistants
414
285
 
@@ -443,38 +314,6 @@ Cletus: Switching assistant...
443
314
 
444
315
  Define structured data with validation:
445
316
 
446
- ```typescript
447
- // Example type definition
448
- {
449
- name: "project",
450
- friendlyName: "Project",
451
- description: "Software project tracking",
452
- knowledgeTemplate: "Project: {{name}}\nStatus: {{status}}\n{{#if description}}Description: {{description}}{{/if}}",
453
- fields: [
454
- {
455
- name: "name",
456
- friendlyName: "Name",
457
- type: "string",
458
- required: true
459
- },
460
- {
461
- name: "status",
462
- friendlyName: "Status",
463
- type: "enum",
464
- enumOptions: ["planning", "active", "completed"],
465
- required: true,
466
- default: "planning"
467
- },
468
- {
469
- name: "description",
470
- friendlyName: "Description",
471
- type: "string",
472
- required: false
473
- }
474
- ]
475
- }
476
- ```
477
-
478
317
  ### Semantic Search
479
318
 
480
319
  Files, data records, and user memories are automatically embedded and searchable:
@@ -500,15 +339,6 @@ Operations:
500
339
  - OCR for images in documents
501
340
  - Image description and analysis
502
341
 
503
- ## Keyboard Shortcuts
504
-
505
- - **Ctrl+C** - Exit current view (returns to main menu)
506
- - **Arrow Keys** - Navigate menus
507
- - **Enter** - Select menu item
508
- - **Type** - In chat view, type messages
509
-
510
- ## Troubleshooting
511
-
512
342
  ### "No provider configured"
513
343
 
514
344
  Add at least one provider in settings or edit `~/.cletus/config.json` to include API keys.
@@ -583,10 +413,28 @@ const myNewTool = ai.tool({
583
413
  });
584
414
 
585
415
  // 3. operations/clerk.tsx
586
- case 'my_new_tool': {
587
- const result = await doSomething(operation.input);
588
- return { output: result };
589
- }
416
+ export const myNewTool = operationOf<
417
+ { input: string },
418
+ { result: string }
419
+ >({
420
+ mode: 'read',
421
+ signature: 'my_new_tool(input: string)',
422
+ status: (input) => `Processing: ${input.input}`,
423
+ analyze: async ({ input }, { cwd }) => ({
424
+ analysis: `This will process: ${input.input}`,
425
+ doable: true,
426
+ }),
427
+ do: async ({ input }, ctx) => {
428
+ const result = await doSomething(input.input);
429
+ return { result };
430
+ },
431
+ render: (op, ai, showInput, showOutput) => renderOperation(
432
+ op,
433
+ `MyNewTool("${op.input.input}")`,
434
+ (op) => op.output ? `Result: ${op.output.result}` : null,
435
+ showInput, showOutput
436
+ ),
437
+ });
590
438
  ```
591
439
 
592
440
  ### Building
@@ -0,0 +1,100 @@
1
+
2
+ import { createRequire as __createRequire } from 'module';
3
+ import { fileURLToPath as __fileURLToPath } from 'url';
4
+ import { dirname as __dirname_func } from 'path';
5
+ const __filename = __fileURLToPath(import.meta.url);
6
+ const __dirname = __dirname_func(__filename);
7
+ const require = __createRequire(import.meta.url);
8
+
9
+
10
+ // src/embed-worker.ts
11
+ import { parentPort, workerData } from "worker_threads";
12
+ import { EmbeddingModel, FlagEmbedding } from "fastembed";
13
+ var embeddingModel = null;
14
+ var initPromise = null;
15
+ async function initModel(cacheDir) {
16
+ if (!initPromise) {
17
+ initPromise = (async () => {
18
+ try {
19
+ return await FlagEmbedding.init({
20
+ model: EmbeddingModel.BGEBaseENV15,
21
+ cacheDir
22
+ });
23
+ } catch (err) {
24
+ console.error("Worker: Failed to load embedding model:", err);
25
+ return null;
26
+ }
27
+ })();
28
+ }
29
+ return initPromise;
30
+ }
31
+ async function handleMessage(message) {
32
+ const { type, id } = message;
33
+ try {
34
+ switch (type) {
35
+ case "init": {
36
+ embeddingModel = await initModel(message.cacheDir);
37
+ return {
38
+ type: "init",
39
+ id,
40
+ success: embeddingModel !== null,
41
+ result: embeddingModel !== null
42
+ };
43
+ }
44
+ case "canEmbed": {
45
+ return {
46
+ type: "canEmbed",
47
+ id,
48
+ success: true,
49
+ result: embeddingModel !== null
50
+ };
51
+ }
52
+ case "embed": {
53
+ if (!embeddingModel) {
54
+ return {
55
+ type: "embed",
56
+ id,
57
+ success: false,
58
+ error: "Embedding model not initialized"
59
+ };
60
+ }
61
+ const batches = embeddingModel.embed(message.texts);
62
+ const results = [];
63
+ for await (const batch of batches) {
64
+ results.push(...batch.map((x) => Array.prototype.slice.call(x)));
65
+ }
66
+ return {
67
+ type: "embed",
68
+ id,
69
+ success: true,
70
+ result: results
71
+ };
72
+ }
73
+ default:
74
+ return {
75
+ type,
76
+ id,
77
+ success: false,
78
+ error: `Unknown message type: ${type}`
79
+ };
80
+ }
81
+ } catch (error) {
82
+ return {
83
+ type,
84
+ id,
85
+ success: false,
86
+ error: error.message
87
+ };
88
+ }
89
+ }
90
+ if (parentPort) {
91
+ parentPort.on("message", async (message) => {
92
+ const response = await handleMessage(message);
93
+ parentPort.postMessage(response);
94
+ });
95
+ if (workerData?.cacheDir) {
96
+ initModel(workerData.cacheDir).then((model) => {
97
+ embeddingModel = model;
98
+ });
99
+ }
100
+ }