Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,9 @@ Uses the [Deep Agents](https://github.com/langchain-ai/deepagentsjs) library to
| `search` | Multi-source search (web, docs, codebase) with synthesis | `webSearch`, `webExtract`, `grep`, `glob`, `sessionSearch` |
| `security-audit` | Security scanning, dependency auditing, vulnerability detection | `readFile`, `grep`, `glob`, `process` |
| `testing` | Test generation, gap analysis, and coverage improvements | `readFile`, `grep`, `glob`, `process` |
| `textEditor` | Text processing — summarize, rewrite, tone adjustment, grammar correction, shorten, expand | `webSearch`, `webExtract` |
| `seoAnalyst` | SEO analysis — keyword density, meta description generation, SERP analysis, content optimization | `webSearch`, `webExtract` |
| `translator` | Multi-language translation and language detection | _(none)_ |

**Default subagent temperatures:**

Expand All @@ -475,6 +478,9 @@ Uses the [Deep Agents](https://github.com/langchain-ai/deepagentsjs) library to
| `search` | 0.5 | Exploratory search |
| `security-audit` | 0.1 | Maximum precision for security analysis |
| `testing` | 0.2 | Structured, deterministic output |
| `textEditor` | 0.4 | Balanced creativity and precision for language |
| `seoAnalyst` | 0.3 | Analytical precision with room for insight |
| `translator` | 0.3 | Nuanced translation with cultural fidelity |

Temperatures are configurable via `subAgentsTemperature` in `config.yaml` or environment variables (`SUB_AGENTS_TEMPERATURE_<AGENT_NAME>`).

Expand Down
3 changes: 3 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,7 @@ subAgentsTemperature:
documentation: 0.3
"security-audit": 0.1
performance: 0.2
textEditor: 0.4
seoAnalyst: 0.3
translator: 0.3
cwd: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-08-23
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
## Context

The madz project has tools for file extraction, web search, and image generation, but lacks dedicated text processing capabilities. Marketing and content workflows require structured tooling for copywriting, SEO analysis, and translation. Currently the agent relies on chain-of-thought LLM calls without structured tooling, producing inconsistent output and losing context across turns.

## Goals / Non-Goals

**Goals:**
- Add three MVP tools: text (copywriting/editing), seo (SEO analysis), translate (translation with language detection)
- Each tool follows the existing pattern: zod schema, impl function, registration in index.js
- Structured JSON output from all tools for reliable agent parsing
- Input validation with 10,000 character limit across all tools
- Translation tool includes caching (24h TTL) and rate limiting (10 req/s)

**Non-Goals:**
- Social media content generation (deferred)
- Structured data extraction (deferred)
- Text comparison (deferred)
- Fallback to LLM-based translation (deferred)

## Decisions

1. **Three separate tools, not one monolithic tool.** Each tool has a distinct purpose and may have different dependencies (translate needs google-translate-api). This keeps each tool focused and testable.

2. **LLM calls via existing agent framework for text and seo tools.** No additional npm dependencies needed. Each action maps to a specific system prompt. This is consistent with how other tools in the codebase work.

3. **google-translate-api (v3.x) for translate tool.** Lightweight wrapper around Google Translate API. Requires API key via env var. Alternative (LibreTranslate) deferred — requires server setup.

4. **tiny-lru for caching.** The project already uses tiny-lru for caching elsewhere. Reuse this pattern for translation result caching.

5. **Structured JSON output, not free-text.** All tools return JSON with result, action, and metadata fields. This allows the agent to parse results reliably and use them in subsequent turns.

6. **Input size limit of 10,000 characters.** Prevents excessive LLM token usage. Larger inputs are rejected with a clear error message.

## Risks / Trade-offs

- **Translation API dependency:** google-translate-api requires an API key. Users without one cannot use the translate tool. Mitigation: clear error message, document the requirement.
- **LLM latency:** Text and seo tools depend on LLM calls which can be slow. Mitigation: document expected latency, consider adding timeouts.
- **Rate limiting:** Translation API has rate limits. Client-side rate limiting (10 req/s) prevents triggering provider blocks but may cause queuing under heavy use.
- **No NLP libraries:** Keyword density uses string matching, not proper NLP. This is intentional for simplicity but may produce less accurate results for complex text.

## Migration Plan

No migration needed — these are new tools. Existing tools are unaffected.

## Open Questions

- Should the text tool support chunking for inputs > 10,000 characters, or reject them outright?
- Should SEO tool include a "content score" metric based on keyword usage, readability, and length?
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
## Why

The existing tools handle file extraction, web search, and image generation — but there is no dedicated capability for text processing and content generation. Marketing workflows need structured tooling for tone adjustment, summarization, rewriting, SEO analysis, social media content generation, translation, and text-to-structured-data. Currently the agent must rely on the LLM chain-of-thought without structured tooling, which is inconsistent and loses context.

## What Changes

- Add `text` tool: copywriting, editing, summarization, rewriting, grammar correction, length adjustment (shorten/expand)
- Add `seo` tool: keyword density analysis, meta description generation, SERP analysis, content optimization suggestions
- Add `translate` tool: multi-language translation with language detection, using google-translate-api
- Register all three tools in `src/tools/index.js`
- Add `google-translate-api` dependency to package.json
- Add unit tests for each tool

## Capabilities

### New Capabilities
- `text-processing`: Copywriting and editing operations — summarize, rewrite, tone adjustment, grammar correction, length adjustment
- `seo-analysis`: SEO analysis operations — keyword density, meta description generation, SERP analysis, content optimization
- `translation`: Multi-language translation and language detection with caching and rate limiting

### Modified Capabilities
<!-- None — all new capabilities -->

## Impact

- **Affected code**: `src/tools/index.js` (registration), `src/tools/text.js` (new), `src/tools/seo.js` (new), `src/tools/translate.js` (new)
- **Dependencies**: `google-translate-api` (v3.x) added to package.json
- **Tests**: New test files in `tests/unit/tools/text.test.js`, `tests/unit/tools/seo.test.js`, `tests/unit/tools/translate.test.js`
- **Security**: Translation API key via `process.env.GOOGLE_TRANSLATE_API_KEY` — never stored in config files

## Non-goals

- Social media content generation (post scheduling, platform-specific formatting) — deferred to follow-up PR
- Structured data extraction (entity extraction, sentiment analysis, topic classification) — deferred
- Text comparison (diff, similarity scoring, plagiarism detection) — deferred
- Fallback to LLM-based translation when API is unavailable — deferred
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## ADDED Requirements

### Requirement: SEO tool supports keyword density analysis
The seo tool SHALL accept a "keyword-density" action that analyzes keyword frequency in the input text.

#### Scenario: Analyze keyword density
- **WHEN** the user calls the seo tool with action "keyword-density", input text, and keywords ["seo", "marketing"]
- **THEN** the tool returns structured JSON with keyword density percentages for each keyword

#### Scenario: No keywords provided
- **WHEN** the user calls the seo tool with action "keyword-density" and input text but no keywords
- **THEN** the tool returns an error indicating keywords are required

### Requirement: SEO tool supports meta description generation
The seo tool SHALL accept a "meta-description" action that generates an SEO-optimized meta description.

#### Scenario: Generate meta description
- **WHEN** the user calls the seo tool with action "meta-description", input text, and options { targetKeywords: ["seo", "marketing"] }
- **THEN** the tool returns structured JSON with a meta description under 160 characters containing the target keywords

#### Scenario: Generate meta description without keywords
- **WHEN** the user calls the seo tool with action "meta-description" and input text without target keywords
- **THEN** the tool returns a meta description under 160 characters based on the input text

### Requirement: SEO tool input validation
The seo tool SHALL validate all inputs against a zod schema before processing.

#### Scenario: Missing input field
- **WHEN** the user calls the seo tool without an "input" field
- **THEN** the tool returns a validation error

#### Scenario: Input exceeds size limit
- **WHEN** the user calls the seo tool with input text exceeding 10,000 characters
- **THEN** the tool returns an error indicating the input exceeds the maximum size limit

### Requirement: SEO tool structured output
The seo tool SHALL return structured JSON output with result, action, and metadata fields.

#### Scenario: Successful SEO operation
- **WHEN** the seo tool processes a valid request
- **THEN** the tool returns JSON with { result: object, action: string, metadata: { inputLength: number } }
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
## ADDED Requirements

### Requirement: Text tool supports summarize action
The text tool SHALL accept a "summarize" action that produces a condensed version of the input text.

#### Scenario: Summarize normal text
- **WHEN** the user calls the text tool with action "summarize", input text of 500+ characters, and options { targetLength: 100 }
- **THEN** the tool returns structured JSON with result containing a summary of approximately 100 characters

#### Scenario: Summarize short text
- **WHEN** the user calls the text tool with action "summarize" and input text of 50 characters
- **THEN** the tool returns the input text unchanged (no summarization needed)

### Requirement: Text tool supports rewrite action
The text tool SHALL accept a "rewrite" action that rephrases the input text while preserving meaning.

#### Scenario: Rewrite with different tone
- **WHEN** the user calls the text tool with action "rewrite", input text, and options { tone: "professional" }
- **THEN** the tool returns structured JSON with result containing a professionally toned rewrite

#### Scenario: Rewrite without tone option
- **WHEN** the user calls the text tool with action "rewrite" and input text without tone option
- **THEN** the tool returns a rephrased version of the input text

### Requirement: Text tool supports tone adjustment
The text tool SHALL accept a "tone" action that adjusts the tone of the input text.

#### Scenario: Adjust to formal tone
- **WHEN** the user calls the text tool with action "tone", input text, and options { tone: "formal" }
- **THEN** the tool returns structured JSON with result containing the text adjusted to a formal tone

#### Scenario: Adjust to casual tone
- **WHEN** the user calls the text tool with action "tone", input text, and options { tone: "casual" }
- **THEN** the tool returns structured JSON with result containing the text adjusted to a casual tone

### Requirement: Text tool supports grammar correction
The text tool SHALL accept a "grammar" action that corrects grammatical errors in the input text.

#### Scenario: Correct grammar errors
- **WHEN** the user calls the text tool with action "grammar" and input text containing grammatical errors
- **THEN** the tool returns structured JSON with result containing the corrected text

#### Scenario: Text with no errors
- **WHEN** the user calls the text tool with action "grammar" and grammatically correct input text
- **THEN** the tool returns the input text unchanged

### Requirement: Text tool supports length adjustment
The text tool SHALL accept "shorten" and "expand" actions that adjust the length of the input text.

#### Scenario: Shorten text
- **WHEN** the user calls the text tool with action "shorten", input text of 500+ characters, and options { targetLength: 200 }
- **THEN** the tool returns structured JSON with result containing a shortened version of approximately 200 characters

#### Scenario: Expand text
- **WHEN** the user calls the text tool with action "expand", input text of 50 characters, and options { targetLength: 200 }
- **THEN** the tool returns structured JSON with result containing an expanded version of approximately 200 characters

### Requirement: Text tool input validation
The text tool SHALL validate all inputs against a zod schema before processing.

#### Scenario: Missing input field
- **WHEN** the user calls the text tool without an "input" field
- **THEN** the tool returns a validation error

#### Scenario: Input exceeds size limit
- **WHEN** the user calls the text tool with input text exceeding 10,000 characters
- **THEN** the tool returns an error indicating the input exceeds the maximum size limit

### Requirement: Text tool structured output
The text tool SHALL return structured JSON output with result, action, and metadata fields.

#### Scenario: Successful text operation
- **WHEN** the text tool processes a valid request
- **THEN** the tool returns JSON with { result: string, action: string, metadata: { inputLength: number, outputLength: number } }

## ADDED Requirements

### Requirement: SEO tool supports keyword density analysis
The seo tool SHALL accept a "keyword-density" action that analyzes keyword frequency in the input text.

#### Scenario: Analyze keyword density
- **WHEN** the user calls the seo tool with action "keyword-density", input text, and keywords ["seo", "marketing"]
- **THEN** the tool returns structured JSON with keyword density percentages for each keyword

#### Scenario: No keywords provided
- **WHEN** the user calls the seo tool with action "keyword-density" and input text but no keywords
- **THEN** the tool returns an error indicating keywords are required

### Requirement: SEO tool supports meta description generation
The seo tool SHALL accept a "meta-description" action that generates an SEO-optimized meta description.

#### Scenario: Generate meta description
- **WHEN** the user calls the seo tool with action "meta-description", input text, and options { targetKeywords: ["seo", "marketing"] }
- **THEN** the tool returns structured JSON with a meta description under 160 characters containing the target keywords

#### Scenario: Generate meta description without keywords
- **WHEN** the user calls the seo tool with action "meta-description" and input text without target keywords
- **THEN** the tool returns a meta description under 160 characters based on the input text

### Requirement: SEO tool input validation
The seo tool SHALL validate all inputs against a zod schema before processing.

#### Scenario: Missing input field
- **WHEN** the user calls the seo tool without an "input" field
- **THEN** the tool returns a validation error

#### Scenario: Input exceeds size limit
- **WHEN** the user calls the seo tool with input text exceeding 10,000 characters
- **THEN** the tool returns an error indicating the input exceeds the maximum size limit

### Requirement: SEO tool structured output
The seo tool SHALL return structured JSON output with result, action, and metadata fields.

#### Scenario: Successful SEO operation
- **WHEN** the seo tool processes a valid request
- **THEN** the tool returns JSON with { result: object, action: string, metadata: { inputLength: number } }

## ADDED Requirements

### Requirement: Translate tool supports translation
The translate tool SHALL accept a "translate" action that translates input text to a target language.

#### Scenario: Translate English to Spanish
- **WHEN** the user calls the translate tool with action "translate", input "Hello world", and options { targetLanguage: "es" }
- **THEN** the tool returns structured JSON with result containing the Spanish translation

#### Scenario: Translate with source language specified
- **WHEN** the user calls the translate tool with action "translate", input text, and options { sourceLanguage: "en", targetLanguage: "fr" }
- **THEN** the tool returns structured JSON with the French translation

### Requirement: Translate tool supports language detection
The translate tool SHALL accept a "detect" action that identifies the language of the input text.

#### Scenario: Detect English text
- **WHEN** the user calls the translate tool with action "detect" and input "Hello world"
- **THEN** the tool returns structured JSON with result containing { language: "en", confidence: number }

#### Scenario: Detect Spanish text
- **WHEN** the user calls the translate tool with action "detect" and input "Hola mundo"
- **THEN** the tool returns structured JSON with result containing { language: "es", confidence: number }

### Requirement: Translate tool caching
The translate tool SHALL cache translation results by (input, sourceLanguage, targetLanguage) key with a 24-hour TTL.

#### Scenario: Cached translation result
- **WHEN** the user calls the translate tool with the same (input, sourceLanguage, targetLanguage) twice within 24 hours
- **THEN** the second call returns the cached result without making a new API request

#### Scenario: Expired cache
- **WHEN** the user calls the translate tool with a cached key that is older than 24 hours
- **THEN** the tool makes a new API request and updates the cache

### Requirement: Translate tool input validation
The translate tool SHALL validate all inputs against a zod schema before processing.

#### Scenario: Missing input field
- **WHEN** the user calls the translate tool without an "input" field
- **THEN** the tool returns a validation error

#### Scenario: Input exceeds size limit
- **WHEN** the user calls the translate tool with input text exceeding 10,000 characters
- **THEN** the tool returns an error indicating the input exceeds the maximum size limit

### Requirement: Translate tool structured output
The translate tool SHALL return structured JSON output with result, action, and metadata fields.

#### Scenario: Successful translation
- **WHEN** the translate tool processes a valid request
- **THEN** the tool returns JSON with { result: string, action: string, metadata: { sourceLanguage: string, targetLanguage: string, cached: boolean } }
Loading