@ridit/lens 0.3.7 → 0.3.9
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/dist/index.mjs +105368 -274002
- package/package.json +13 -19
- package/src/colors.ts +15 -15
- package/src/commands/chat.tsx +32 -23
- package/src/commands/provider.tsx +11 -238
- package/src/commands/repo.tsx +66 -120
- package/src/commands/timeline.tsx +11 -22
- package/src/components/ChatView.tsx +238 -0
- package/src/components/Message.tsx +46 -0
- package/src/components/ToolCall.tsx +67 -0
- package/src/components/chat/ChatView.tsx +550 -0
- package/src/components/chat/Message.tsx +152 -0
- package/src/components/chat/StatusBar.tsx +214 -0
- package/src/components/chat/TextArea.tsx +173 -176
- package/src/components/provider/ApiKeyStep.tsx +207 -199
- package/src/components/provider/ModelStep.tsx +90 -88
- package/src/components/provider/ProviderSetup.tsx +331 -0
- package/src/components/provider/ProviderTypeStep.tsx +53 -61
- package/src/components/repo/StepRow.tsx +68 -69
- package/src/components/timeline/TimelineView.tsx +840 -0
- package/src/components/toolcall-utils.ts +103 -0
- package/src/components/watch/RunView.tsx +497 -0
- package/src/hooks/useChatInput.ts +49 -0
- package/src/hooks/useCommandHandler.ts +117 -0
- package/src/index.tsx +386 -139
- package/src/utils/git.ts +149 -155
- package/src/utils/repo.ts +62 -69
- package/src/utils/thinking.tsx +64 -0
- package/src/utils/watch.ts +165 -307
- package/tests/message.test.ts +38 -0
- package/tests/toolcall-utils.test.ts +111 -0
- package/tsconfig.json +8 -24
- package/CLAUDE.md +0 -50
- package/LENS.md +0 -48
- package/LICENSE +0 -21
- package/README.md +0 -93
- package/addons/README.md +0 -55
- package/addons/clean-cache.js +0 -48
- package/addons/generate-readme.js +0 -67
- package/addons/git-stats.js +0 -29
- package/addons/run-tests.js +0 -127
- package/src/commands/commit.tsx +0 -668
- package/src/commands/review.tsx +0 -294
- package/src/commands/run.tsx +0 -56
- package/src/commands/task.tsx +0 -36
- package/src/components/chat/ChatMessage.tsx +0 -195
- package/src/components/chat/ChatOverlays.tsx +0 -399
- package/src/components/chat/ChatRunner.tsx +0 -517
- package/src/components/chat/hooks/useChat.ts +0 -631
- package/src/components/chat/hooks/useChatInput.ts +0 -79
- package/src/components/chat/hooks/useCommandHandlers.ts +0 -327
- package/src/components/provider/ProviderPicker.tsx +0 -76
- package/src/components/provider/RemoveProviderStep.tsx +0 -82
- package/src/components/repo/DiffViewer.tsx +0 -175
- package/src/components/repo/FileReviewer.tsx +0 -70
- package/src/components/repo/FileViewer.tsx +0 -60
- package/src/components/repo/IssueFixer.tsx +0 -666
- package/src/components/repo/LensFileMenu.tsx +0 -115
- package/src/components/repo/NoProviderPrompt.tsx +0 -28
- package/src/components/repo/PreviewRunner.tsx +0 -217
- package/src/components/repo/RepoAnalysis.tsx +0 -534
- package/src/components/task/TaskRunner.tsx +0 -396
- package/src/components/timeline/CommitDetail.tsx +0 -272
- package/src/components/timeline/CommitList.tsx +0 -162
- package/src/components/timeline/TimelineChat.tsx +0 -166
- package/src/components/timeline/TimelineRunner.tsx +0 -1285
- package/src/components/watch/RunRunner.tsx +0 -929
- package/src/prompts/fewshot.ts +0 -252
- package/src/prompts/index.ts +0 -2
- package/src/prompts/system.ts +0 -285
- package/src/tools/chart.ts +0 -202
- package/src/tools/convert-image.ts +0 -312
- package/src/tools/files.ts +0 -253
- package/src/tools/git.ts +0 -603
- package/src/tools/index.ts +0 -17
- package/src/tools/pdf.ts +0 -164
- package/src/tools/shell.ts +0 -96
- package/src/tools/view-image.ts +0 -335
- package/src/tools/web.ts +0 -212
- package/src/types/chat.ts +0 -86
- package/src/types/config.ts +0 -20
- package/src/types/repo.ts +0 -54
- package/src/utils/addons/loadAddons.ts +0 -34
- package/src/utils/ai.ts +0 -321
- package/src/utils/chat.ts +0 -326
- package/src/utils/chatHistory.ts +0 -121
- package/src/utils/config.ts +0 -61
- package/src/utils/files.ts +0 -105
- package/src/utils/intentClassifier.ts +0 -58
- package/src/utils/lensfile.ts +0 -142
- package/src/utils/llm.ts +0 -81
- package/src/utils/memory.ts +0 -209
- package/src/utils/preview.ts +0 -119
- package/src/utils/stats.ts +0 -174
- package/src/utils/tools/builtins.ts +0 -377
- package/src/utils/tools/registry.ts +0 -105
package/CLAUDE.md
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
# CLAUDE.md
|
|
2
|
-
|
|
3
|
-
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
-
|
|
5
|
-
## Project Overview
|
|
6
|
-
|
|
7
|
-
Lens is an AI-powered CLI tool for natural language interaction with codebases. It uses React 19 + Ink 6 for terminal UI rendering, Commander.js for CLI parsing, and supports multiple LLM providers (Anthropic, OpenAI, Gemini, Ollama, custom OpenAI-compatible endpoints).
|
|
8
|
-
|
|
9
|
-
Published as `@ridit/lens` on npm. User config lives in `~/.lens/` (config.json, memory.json, addons/).
|
|
10
|
-
|
|
11
|
-
## Build Commands
|
|
12
|
-
|
|
13
|
-
```bash
|
|
14
|
-
bun run build # Build to dist/index.mjs (adds Node shebang post-build)
|
|
15
|
-
bun install # Install dependencies
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
There are no lint or test scripts configured. TypeScript strict mode serves as the primary static analysis tool.
|
|
19
|
-
|
|
20
|
-
## Architecture
|
|
21
|
-
|
|
22
|
-
**CLI entry** (`src/index.tsx`): Registers 8 commands via Commander.js, loads built-in tools and user addons, then renders Ink React components.
|
|
23
|
-
|
|
24
|
-
**Commands** (`src/commands/`): Each command (chat, commit, review, repo, task, timeline, provider, run) is a React component rendered by Ink.
|
|
25
|
-
|
|
26
|
-
**Components** (`src/components/`): Reusable Ink UI components organized by feature (chat/, provider/, repo/, task/, timeline/, watch/). Chat is the most complex — `ChatRunner.tsx` handles tool execution, permission prompts, and the main interaction loop.
|
|
27
|
-
|
|
28
|
-
**Tools** (`src/tools/`): Capability implementations (file ops, shell, web fetch, PDF, git, charts, images). Registered at startup via the tool registry.
|
|
29
|
-
|
|
30
|
-
**Tool Registry** (`src/utils/tools/registry.ts`): Central registry implementing `@ridit/lens-sdk` interface. Supports intent-based filtering — readonly intents never see write/shell/delete tools. Tools are tagged with `TOOL_TAGS.read`, `write`, `delete`, `shell`, `net`.
|
|
31
|
-
|
|
32
|
-
**Intent Classifier** (`src/utils/intentClassifier.ts`): Regex-based classification of user messages into readonly/mutating/any scopes. Controls which tools appear in the LLM system prompt.
|
|
33
|
-
|
|
34
|
-
**LLM Abstraction** (`src/utils/ai.ts`): `callModel()` provides a unified interface across all 5 provider types.
|
|
35
|
-
|
|
36
|
-
**Response Parsing** (`src/utils/chat.ts`): Parses LLM responses for tool calls (XML tags or fenced code blocks), file patches, and clone operations.
|
|
37
|
-
|
|
38
|
-
**Types** (`src/types/`): Discriminated unions are used throughout — every multi-step UI flow uses `type` + `stage` fields (e.g., `ChatStage`, `ReviewStage`) for exhaustive pattern matching.
|
|
39
|
-
|
|
40
|
-
**Memory** (`src/utils/memory.ts`): File-based persistence with session-only entries (in-memory, 200 max) and persistent entries (~/.lens/memory.json, global + repo-scoped).
|
|
41
|
-
|
|
42
|
-
**Addons** (`src/utils/addons/loadAddons.ts`): Plugin system loading tools from `~/.lens/addons/` using `defineTool()` from `@ridit/lens-sdk`.
|
|
43
|
-
|
|
44
|
-
## Key Patterns
|
|
45
|
-
|
|
46
|
-
- **Discriminated union state machines**: All commands use `{ type, stage }` unions for multi-step flows. Add new stages by extending the union and handling them exhaustively.
|
|
47
|
-
- **Provider-agnostic LLM calls**: All provider differences are encapsulated in `callModel()` — never call provider SDKs directly from commands/components.
|
|
48
|
-
- **Intent-scoped tool visibility**: The intent classifier determines which tools the LLM can see. Readonly queries hide mutating tools for safety.
|
|
49
|
-
- **Conventional commits**: The project uses conventional commit format (e.g., `feat(chat):`, `chore:`, `fix:`).
|
|
50
|
-
- **Bun as package manager and bundler**: Use `bun` for all dependency and build operations, not npm/yarn.
|
package/LENS.md
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
# Lens
|
|
2
|
-
> Generated: 2026-03-24T15:21:42.840Z
|
|
3
|
-
|
|
4
|
-
## Overview
|
|
5
|
-
Lens is an AI-powered CLI tool built with React and Ink that enables natural language interaction with codebases. It provides chat-based exploration, code modification, repository analysis, timeline viewing, and smart commit generation. The tool connects to multiple LLM providers (Anthropic, OpenAI, Gemini, Ollama) and gives AI access to filesystem operations, shell commands, and web tools through a plugin system.
|
|
6
|
-
|
|
7
|
-
## Architecture
|
|
8
|
-
The architecture follows a command-based structure with Ink components for terminal UI rendering. Each CLI command (chat, commit, review, task, timeline) has a corresponding React component in src/commands/ that handles the specific workflow. The system uses discriminated union types for state management across multi-step processes. Tool execution is managed through a centralized registry system that supports plugins via @ridit/lens-sdk.
|
|
9
|
-
|
|
10
|
-
## Tooling & Conventions
|
|
11
|
-
- **packageManager**: bun
|
|
12
|
-
- **language**: TypeScript
|
|
13
|
-
- **runtime**: Node.js
|
|
14
|
-
- **bundler**: bun build
|
|
15
|
-
- **framework**: Ink + React
|
|
16
|
-
- **testRunner**: jest (configured but not actively used)
|
|
17
|
-
- **linter**: TypeScript compiler with strict settings
|
|
18
|
-
|
|
19
|
-
## Important Folders
|
|
20
|
-
- src/commands: Contains CLI command entry points (chat.tsx, commit.tsx, review.tsx, task.tsx, timeline.tsx) that render Ink components
|
|
21
|
-
- src/components: Houses reusable UI components organized by feature (chat/, repo/, timeline/, task/) with associated hooks
|
|
22
|
-
- src/utils: Core utilities including AI integration (ai.ts), configuration management (config.ts), git operations (git.ts), and tool registry (tools/)
|
|
23
|
-
- src/tools: Filesystem, shell, web, and PDF tools that the AI can call through the tool registry system
|
|
24
|
-
|
|
25
|
-
## Key Files
|
|
26
|
-
- src/index.tsx: Main CLI entry point that sets up Commander.js with all command handlers and loads built-in tools
|
|
27
|
-
- src/utils/tools/registry.ts: Central tool registry implementing the @ridit/lens-sdk interface for tool management and system prompt generation
|
|
28
|
-
- src/utils/ai.ts: Provider-agnostic AI integration with support for Anthropic, OpenAI, Ollama, and custom providers through unified interfaces
|
|
29
|
-
- src/types/chat.ts: Core type definitions for chat messages, tool calls, and state management using discriminated unions
|
|
30
|
-
- src/components/chat/ChatRunner.tsx: Main chat interface component handling tool execution, permission prompts, and clone operations
|
|
31
|
-
|
|
32
|
-
## Patterns & Idioms
|
|
33
|
-
- Discriminated union state machines (type + stage fields) for multi-step UI flows in every command component (ChatStage, AnalysisStage, etc)
|
|
34
|
-
- Centralized tool registry pattern with plugin system support through @ridit/lens-sdk interface
|
|
35
|
-
- Provider abstraction layer that supports multiple LLM backends with consistent interfaces
|
|
36
|
-
- File-based memory system that persists chat history and context across sessions per repository
|
|
37
|
-
- Ink component composition with hooks for input handling and state management
|
|
38
|
-
|
|
39
|
-
## Suggestions
|
|
40
|
-
- In src/utils/ai.ts, callModel has no retry logic — adding exponential backoff would improve reliability for ollama which can be slow to start
|
|
41
|
-
- The tool registry in src/utils/tools/registry.ts lacks validation for tool name conflicts during registration
|
|
42
|
-
- src/utils/git.ts uses simple execSync for git operations which could benefit from proper error handling and timeout management
|
|
43
|
-
- The discriminated union types in src/types/chat.ts could use branded types for better type safety
|
|
44
|
-
- The build process in package.json uses a postbuild script to add node shebang which could be replaced with bun's native --target=binary option
|
|
45
|
-
|
|
46
|
-
<!--lens-json
|
|
47
|
-
{"overview":"Lens is an AI-powered CLI tool built with React and Ink that enables natural language interaction with codebases. It provides chat-based exploration, code modification, repository analysis, timeline viewing, and smart commit generation. The tool connects to multiple LLM providers (Anthropic, OpenAI, Gemini, Ollama) and gives AI access to filesystem operations, shell commands, and web tools through a plugin system.","importantFolders":["src/commands: Contains CLI command entry points (chat.tsx, commit.tsx, review.tsx, task.tsx, timeline.tsx) that render Ink components","src/components: Houses reusable UI components organized by feature (chat/, repo/, timeline/, task/) with associated hooks","src/utils: Core utilities including AI integration (ai.ts), configuration management (config.ts), git operations (git.ts), and tool registry (tools/)","src/tools: Filesystem, shell, web, and PDF tools that the AI can call through the tool registry system"],"tooling":{"packageManager":"bun","language":"TypeScript","runtime":"Node.js","bundler":"bun build","framework":"Ink + React","testRunner":"jest (configured but not actively used)","linter":"TypeScript compiler with strict settings"},"keyFiles":["src/index.tsx: Main CLI entry point that sets up Commander.js with all command handlers and loads built-in tools","src/utils/tools/registry.ts: Central tool registry implementing the @ridit/lens-sdk interface for tool management and system prompt generation","src/utils/ai.ts: Provider-agnostic AI integration with support for Anthropic, OpenAI, Ollama, and custom providers through unified interfaces","src/types/chat.ts: Core type definitions for chat messages, tool calls, and state management using discriminated unions","src/components/chat/ChatRunner.tsx: Main chat interface component handling tool execution, permission prompts, and clone operations"],"patterns":["Discriminated union state machines (type + stage fields) for multi-step UI flows in every command component (ChatStage, AnalysisStage, etc)","Centralized tool registry pattern with plugin system support through @ridit/lens-sdk interface","Provider abstraction layer that supports multiple LLM backends with consistent interfaces","File-based memory system that persists chat history and context across sessions per repository","Ink component composition with hooks for input handling and state management"],"architecture":"The architecture follows a command-based structure with Ink components for terminal UI rendering. Each CLI command (chat, commit, review, task, timeline) has a corresponding React component in src/commands/ that handles the specific workflow. The system uses discriminated union types for state management across multi-step processes. Tool execution is managed through a centralized registry system that supports plugins via @ridit/lens-sdk.","suggestions":["In src/utils/ai.ts, callModel has no retry logic — adding exponential backoff would improve reliability for ollama which can be slow to start","The tool registry in src/utils/tools/registry.ts lacks validation for tool name conflicts during registration","src/utils/git.ts uses simple execSync for git operations which could benefit from proper error handling and timeout management","The discriminated union types in src/types/chat.ts could use branded types for better type safety","The build process in package.json uses a postbuild script to add node shebang which could be replaced with bun's native --target=binary option"],"generatedAt":"2026-03-24T15:21:42.840Z","lastUpdated":"2026-03-24T15:21:42.840Z"}
|
|
48
|
-
lens-json-->
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Ridit
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/README.md
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
# Lens
|
|
2
|
-
|
|
3
|
-
Lens is an AI-powered CLI tool that lets you explore, understand, and modify any codebase through natural language. Built with React and Ink for a rich terminal UI, Lens connects to multiple LLM providers and gives the AI direct access to your filesystem, shell, and the web.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- **Chat with your codebase** — ask questions, request changes, scaffold new files
|
|
8
|
-
- **Multi-provider support** — Anthropic, OpenAI, Gemini, Ollama, or any OpenAI-compatible API
|
|
9
|
-
- **Tool system** — AI can read/write files, run shell commands, fetch URLs, search the web, clone repos, generate PDFs, and more
|
|
10
|
-
- **Plugin registry** — extend Lens with custom tools via `@ridit/lens-sdk`
|
|
11
|
-
- **Diff preview** — proposed code changes are shown as a diff before applying
|
|
12
|
-
- **Auto-approve mode** — `/auto` skips confirmation for safe read/search tools
|
|
13
|
-
- **Force-all mode** — `/auto --force-all` approves everything including shell and writes
|
|
14
|
-
- **Persistent memory** — Lens remembers project-specific context across sessions
|
|
15
|
-
- **Chat history** — save, load, rename, and delete chat sessions per repo
|
|
16
|
-
- **Smart commits** — generate conventional commit messages from staged changes
|
|
17
|
-
- **Timeline** — browse and explore commit history
|
|
18
|
-
- **Repo analysis** — deep codebase review from a remote URL or local path
|
|
19
|
-
|
|
20
|
-
## Installation
|
|
21
|
-
|
|
22
|
-
```bash
|
|
23
|
-
# using bun
|
|
24
|
-
bun add @ridit/lens -g
|
|
25
|
-
|
|
26
|
-
# using npm
|
|
27
|
-
npm install -g @ridit/lens
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
## CLI Commands
|
|
31
|
-
|
|
32
|
-
```
|
|
33
|
-
lens chat chat with your codebase
|
|
34
|
-
lens chat -p /path/to/repo chat in a specific repo
|
|
35
|
-
|
|
36
|
-
lens review AI review of the current directory
|
|
37
|
-
lens review /path/to/repo AI review of a specific repo
|
|
38
|
-
|
|
39
|
-
lens repo <url> analyze a remote GitHub repository
|
|
40
|
-
|
|
41
|
-
lens task <text> apply a natural language change to the codebase
|
|
42
|
-
lens task <text> -p /path apply change to a specific repo
|
|
43
|
-
|
|
44
|
-
lens commit generate a smart commit message from staged changes
|
|
45
|
-
lens commit [files...] stage specific files and generate a commit message
|
|
46
|
-
lens commit --auto stage all changes and commit without confirmation
|
|
47
|
-
lens commit --confirm show preview before committing when using --auto
|
|
48
|
-
lens commit --preview show the generated message without committing
|
|
49
|
-
lens commit --push push to remote after committing
|
|
50
|
-
|
|
51
|
-
lens timeline explore commit history
|
|
52
|
-
lens timeline -p /path explore history of a specific repo
|
|
53
|
-
|
|
54
|
-
lens run Run your dev server. Lens detects and fixes errors automatically
|
|
55
|
-
|
|
56
|
-
lens provider configure AI providers
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
## Chat Commands
|
|
60
|
-
|
|
61
|
-
Once inside a `lens chat / vibe` session, use slash commands:
|
|
62
|
-
|
|
63
|
-
```
|
|
64
|
-
/timeline browse commit history
|
|
65
|
-
/review AI review of the current codebase
|
|
66
|
-
/auto toggle auto-approve for safe tools (read, search, fetch)
|
|
67
|
-
/auto --force-all auto-approve ALL tools including shell and writes ⚠️
|
|
68
|
-
/chat list list saved chat sessions for this repo
|
|
69
|
-
/chat load <name> load a saved chat session
|
|
70
|
-
/chat rename <name> rename the current session
|
|
71
|
-
/chat delete <name> delete a saved session
|
|
72
|
-
/memory list list stored memories for this repo
|
|
73
|
-
/memory add <text> add a memory
|
|
74
|
-
/memory delete <id> delete a memory by ID
|
|
75
|
-
/memory clear clear all memories for this repo
|
|
76
|
-
/clear history wipe session memory for this repo
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
## Supported Providers
|
|
80
|
-
|
|
81
|
-
- **Anthropic** — Claude models
|
|
82
|
-
- **OpenAI** — GPT models
|
|
83
|
-
- **Gemini** — Google Gemini models
|
|
84
|
-
- **Ollama** — local models (free, fully offline)
|
|
85
|
-
- **Custom** — any OpenAI-compatible API endpoint
|
|
86
|
-
|
|
87
|
-
## Extending Lens
|
|
88
|
-
|
|
89
|
-
Custom tools can be built and registered using `[@ridit/lens-sdk](https://www.npmjs.com/package/@ridit/lens-sdk)`.
|
|
90
|
-
|
|
91
|
-
## License
|
|
92
|
-
|
|
93
|
-
MIT
|
package/addons/README.md
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
# Sample addons for Lens
|
|
2
|
-
|
|
3
|
-
## These addons are generated by lens.
|
|
4
|
-
|
|
5
|
-
Paste them inside ~/.lens/addons or C:/Users/UserName/.lens/addons
|
|
6
|
-
|
|
7
|
-
## Addon Format
|
|
8
|
-
|
|
9
|
-
Addons use `defineTool` from `@ridit/lens-sdk`:
|
|
10
|
-
|
|
11
|
-
```js
|
|
12
|
-
const { defineTool } = require("@ridit/lens-sdk");
|
|
13
|
-
|
|
14
|
-
defineTool({
|
|
15
|
-
name: "tool-name",
|
|
16
|
-
description: "what it does",
|
|
17
|
-
safe: false,
|
|
18
|
-
permissionLabel: "label shown to user",
|
|
19
|
-
systemPromptEntry: () => `<tool-name>{}</tool-name> — description`,
|
|
20
|
-
parseInput: (body) => JSON.parse(body.trim() || "{}"),
|
|
21
|
-
summariseInput: (input) => "summary",
|
|
22
|
-
execute: async (input, ctx) => {
|
|
23
|
-
// ctx.repoPath is the current repo
|
|
24
|
-
return { kind: "text", value: "result" };
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
## Available Addons
|
|
30
|
-
|
|
31
|
-
### clean-cache
|
|
32
|
-
Clears node_modules and bun install cache
|
|
33
|
-
```xml
|
|
34
|
-
<clean-cache>{}</clean-cache>
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
### generate-readme
|
|
38
|
-
Creates a README.md file for the project
|
|
39
|
-
```xml
|
|
40
|
-
<generate-readme>{}</generate-readme>
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
### git-stats
|
|
44
|
-
Shows git contributor commit counts
|
|
45
|
-
```xml
|
|
46
|
-
<git-stats></git-stats>
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
### run-tests
|
|
50
|
-
Runs test suite or specific test files
|
|
51
|
-
```xml
|
|
52
|
-
<run-tests>{}</run-tests> — full suite
|
|
53
|
-
<run-tests>{"file": "src/utils.test.js"}</run-tests> — specific file
|
|
54
|
-
<run-tests>{"command": "node script.js"}</run-tests> — custom command
|
|
55
|
-
```
|
package/addons/clean-cache.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
const { defineTool } = require("@ridit/lens-sdk");
|
|
2
|
-
const { execSync } = require("child_process");
|
|
3
|
-
|
|
4
|
-
const isWindows = process.platform === "win32";
|
|
5
|
-
|
|
6
|
-
defineTool({
|
|
7
|
-
name: "clean-cache",
|
|
8
|
-
description: "Clean node_modules and bun install cache",
|
|
9
|
-
safe: false,
|
|
10
|
-
permissionLabel: "Clean cache and node_modules",
|
|
11
|
-
|
|
12
|
-
systemPromptEntry: () =>
|
|
13
|
-
`<clean-cache>{}</clean-cache> — clean node_modules and bun cache`,
|
|
14
|
-
|
|
15
|
-
parseInput: (body) => {
|
|
16
|
-
const trimmed = body.trim();
|
|
17
|
-
if (!trimmed || trimmed === "{}") return {};
|
|
18
|
-
return JSON.parse(trimmed);
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
summariseInput: () => "clean cache",
|
|
22
|
-
|
|
23
|
-
execute: async (input, ctx) => {
|
|
24
|
-
const repoPath = ctx.repoPath;
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
// Remove node_modules
|
|
28
|
-
if (isWindows) {
|
|
29
|
-
execSync("rmdir /s /q node_modules", { cwd: repoPath, stdio: "pipe" });
|
|
30
|
-
} else {
|
|
31
|
-
execSync("rm -rf node_modules", { cwd: repoPath, stdio: "pipe" });
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Clean bun cache
|
|
35
|
-
execSync("bun clean", { cwd: repoPath, stdio: "pipe" });
|
|
36
|
-
|
|
37
|
-
return {
|
|
38
|
-
kind: "text",
|
|
39
|
-
value: "Cache cleaned successfully! node_modules removed and bun cache cleared.",
|
|
40
|
-
};
|
|
41
|
-
} catch (err) {
|
|
42
|
-
return {
|
|
43
|
-
kind: "error",
|
|
44
|
-
value: `Failed to clean cache: ${err.message}`,
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
});
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
const { defineTool } = require("@ridit/lens-sdk");
|
|
2
|
-
const fs = require("fs");
|
|
3
|
-
|
|
4
|
-
const readmeTemplate = `# {name}
|
|
5
|
-
|
|
6
|
-
{description}
|
|
7
|
-
|
|
8
|
-
## Getting Started
|
|
9
|
-
|
|
10
|
-
\`\`\`bash
|
|
11
|
-
bun install
|
|
12
|
-
bun run dev
|
|
13
|
-
\`\`\`
|
|
14
|
-
|
|
15
|
-
## Features
|
|
16
|
-
|
|
17
|
-
- Feature one
|
|
18
|
-
- Feature two
|
|
19
|
-
|
|
20
|
-
## Contributing
|
|
21
|
-
|
|
22
|
-
Pull requests welcome.`;
|
|
23
|
-
|
|
24
|
-
defineTool({
|
|
25
|
-
name: "generate-readme",
|
|
26
|
-
description: "Generate a README.md file for the project",
|
|
27
|
-
safe: true,
|
|
28
|
-
permissionLabel: "Generate README",
|
|
29
|
-
|
|
30
|
-
systemPromptEntry: () =>
|
|
31
|
-
`<generate-readme>{}</generate-readme> — generate a README.md`,
|
|
32
|
-
|
|
33
|
-
parseInput: (body) => {
|
|
34
|
-
const trimmed = body.trim();
|
|
35
|
-
if (!trimmed || trimmed === "{}") return {};
|
|
36
|
-
return JSON.parse(trimmed);
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
summariseInput: () => "generate README",
|
|
40
|
-
|
|
41
|
-
execute: async (input, ctx) => {
|
|
42
|
-
const repoPath = ctx.repoPath;
|
|
43
|
-
const pkgPath = `${repoPath}/package.json`;
|
|
44
|
-
|
|
45
|
-
let name = "Project";
|
|
46
|
-
let description = "A brief description.";
|
|
47
|
-
|
|
48
|
-
if (fs.existsSync(pkgPath)) {
|
|
49
|
-
try {
|
|
50
|
-
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
51
|
-
name = pkg.name || name;
|
|
52
|
-
description = pkg.description || description;
|
|
53
|
-
} catch {}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const content = readmeTemplate
|
|
57
|
-
.replace("{name}", name)
|
|
58
|
-
.replace("{description}", description);
|
|
59
|
-
|
|
60
|
-
fs.writeFileSync(`${repoPath}/README.md`, content);
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
kind: "text",
|
|
64
|
-
value: "README.md generated successfully!"
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
});
|
package/addons/git-stats.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
const { defineTool } = require("@ridit/lens-sdk");
|
|
2
|
-
const { execSync } = require("child_process");
|
|
3
|
-
|
|
4
|
-
defineTool({
|
|
5
|
-
name: "git-stats",
|
|
6
|
-
description: "Show git contributor stats",
|
|
7
|
-
safe: true,
|
|
8
|
-
permissionLabel: "View git stats",
|
|
9
|
-
systemPromptEntry: () => "<git-stats>{}</git-stats> — show contributor commit counts",
|
|
10
|
-
parseInput: (body) => JSON.parse(body.trim() || "{}"),
|
|
11
|
-
summariseInput: () => "git contributor stats",
|
|
12
|
-
execute: async (input, ctx) => {
|
|
13
|
-
try {
|
|
14
|
-
const output = execSync("git shortlog -sn --all", {
|
|
15
|
-
cwd: ctx.repoPath,
|
|
16
|
-
stdio: "pipe",
|
|
17
|
-
}).toString();
|
|
18
|
-
return {
|
|
19
|
-
kind: "text",
|
|
20
|
-
value: output || "No commits found",
|
|
21
|
-
};
|
|
22
|
-
} catch (err) {
|
|
23
|
-
return {
|
|
24
|
-
kind: "error",
|
|
25
|
-
value: `Failed to get git stats: ${err.message}`,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
});
|
package/addons/run-tests.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
const { defineTool } = require("@ridit/lens-sdk");
|
|
2
|
-
const { execSync } = require("child_process");
|
|
3
|
-
const fs = require("fs");
|
|
4
|
-
const path = require("path");
|
|
5
|
-
|
|
6
|
-
defineTool({
|
|
7
|
-
name: "run-tests",
|
|
8
|
-
description:
|
|
9
|
-
"Runs Node.js tests — whole suite or a specific file, auto-detected",
|
|
10
|
-
safe: false,
|
|
11
|
-
permissionLabel: "Run tests in the repo",
|
|
12
|
-
|
|
13
|
-
systemPromptEntry: () =>
|
|
14
|
-
`<run-tests>{}</run-tests> — run the full test suite\n` +
|
|
15
|
-
`<run-tests>{"file": "src/utils.test.js"}</run-tests> — run a specific test file\n` +
|
|
16
|
-
`<run-tests>{"command": "node script.js"}</run-tests> — run any custom Node.js command`,
|
|
17
|
-
|
|
18
|
-
parseInput: (body) => {
|
|
19
|
-
const trimmed = body.trim();
|
|
20
|
-
if (!trimmed || trimmed === "{}") return {};
|
|
21
|
-
return JSON.parse(trimmed);
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
summariseInput: (input) => {
|
|
25
|
-
if (input.file) return `test file: ${input.file}`;
|
|
26
|
-
if (input.command) return `command: ${input.command}`;
|
|
27
|
-
return "full test suite";
|
|
28
|
-
},
|
|
29
|
-
|
|
30
|
-
execute: async (input, ctx) => {
|
|
31
|
-
const repoPath = ctx.repoPath;
|
|
32
|
-
|
|
33
|
-
// Helper: run a shell command and capture output
|
|
34
|
-
const run = (cmd) => {
|
|
35
|
-
try {
|
|
36
|
-
const output = execSync(cmd, {
|
|
37
|
-
cwd: repoPath,
|
|
38
|
-
timeout: 60_000,
|
|
39
|
-
stdio: "pipe",
|
|
40
|
-
}).toString();
|
|
41
|
-
return { ok: true, output };
|
|
42
|
-
} catch (err) {
|
|
43
|
-
const output = [err.stdout?.toString(), err.stderr?.toString()]
|
|
44
|
-
.filter(Boolean)
|
|
45
|
-
.join("\n");
|
|
46
|
-
return { ok: false, output: output || err.message };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
// --- Custom command ---
|
|
51
|
-
if (input.command) {
|
|
52
|
-
const result = run(input.command);
|
|
53
|
-
return {
|
|
54
|
-
kind: result.ok ? "text" : "error",
|
|
55
|
-
value: result.output || "(no output)",
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// --- Detect test runner from package.json ---
|
|
60
|
-
const pkgPath = path.join(repoPath, "package.json");
|
|
61
|
-
let pkg = {};
|
|
62
|
-
if (fs.existsSync(pkgPath)) {
|
|
63
|
-
try {
|
|
64
|
-
pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
|
|
65
|
-
} catch {}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const hasScript = (name) => !!pkg.scripts?.[name];
|
|
69
|
-
const hasDep = (name) =>
|
|
70
|
-
!!(pkg.dependencies?.[name] || pkg.devDependencies?.[name]);
|
|
71
|
-
|
|
72
|
-
const detectRunner = () => {
|
|
73
|
-
if (hasScript("test")) return "npm test";
|
|
74
|
-
if (hasDep("jest")) return "npx jest";
|
|
75
|
-
if (hasDep("vitest")) return "npx vitest run";
|
|
76
|
-
if (hasDep("mocha")) return "npx mocha";
|
|
77
|
-
if (hasDep("tap")) return "npx tap";
|
|
78
|
-
return null;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
// --- Specific file ---
|
|
82
|
-
if (input.file) {
|
|
83
|
-
const filePath = path.resolve(repoPath, input.file);
|
|
84
|
-
|
|
85
|
-
if (!fs.existsSync(filePath)) {
|
|
86
|
-
return { kind: "error", value: `File not found: ${input.file}` };
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
let cmd;
|
|
90
|
-
if (
|
|
91
|
-
hasDep("jest") ||
|
|
92
|
-
(hasScript("test") && pkg.scripts.test?.includes("jest"))
|
|
93
|
-
) {
|
|
94
|
-
cmd = `npx jest ${input.file} --no-coverage`;
|
|
95
|
-
} else if (hasDep("vitest")) {
|
|
96
|
-
cmd = `npx vitest run ${input.file}`;
|
|
97
|
-
} else if (hasDep("mocha")) {
|
|
98
|
-
cmd = `npx mocha ${input.file}`;
|
|
99
|
-
} else {
|
|
100
|
-
// Fallback: just run it with Node
|
|
101
|
-
cmd = `node ${input.file}`;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const result = run(cmd);
|
|
105
|
-
return {
|
|
106
|
-
kind: result.ok ? "text" : "error",
|
|
107
|
-
value: result.output || "(no output)",
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// --- Full test suite ---
|
|
112
|
-
const suiteCmd = detectRunner();
|
|
113
|
-
if (!suiteCmd) {
|
|
114
|
-
return {
|
|
115
|
-
kind: "error",
|
|
116
|
-
value:
|
|
117
|
-
"Could not detect a test runner. No 'test' script in package.json and no known test framework (jest, vitest, mocha, tap) found in dependencies.",
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const result = run(suiteCmd);
|
|
122
|
-
return {
|
|
123
|
-
kind: result.ok ? "text" : "error",
|
|
124
|
-
value: result.output || "(no output)",
|
|
125
|
-
};
|
|
126
|
-
},
|
|
127
|
-
});
|