@musashishao/agent-kit 1.0.1 → 1.1.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.
- package/.agent/FEATURE_ROADMAP.md +5 -5
- package/.agent/skills/context-engineering/SKILL.md +74 -0
- package/.agent/skills/context-engineering/examples/advanced_code_request.md +73 -0
- package/.agent/skills/context-engineering/scripts/repo_mapper.py +27 -0
- package/.agent/skills/context-engineering/scripts/token_counter.py +65 -0
- package/.agent/skills/context-engineering/strategies/context-caching.md +50 -0
- package/.agent/skills/context-engineering/strategies/few-shot-examples.md +56 -0
- package/.agent/skills/context-engineering/strategies/skeleton-code.md +59 -0
- package/.agent/skills/context-engineering/strategies/xml-framing.md +57 -0
- package/.agent/workflows/context.md +47 -0
- package/package.json +2 -2
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
|---------|-----------|-------------|-------------|---------------------|
|
|
12
12
|
| Skills/Agents | 50+ skills, 45 agents | Task-focused | Plugins | 40 skills, 16 agents |
|
|
13
13
|
| Marketplace | ✅ Plugin marketplace | ✅ npm package | ✅ Plugins dir | ❌ Manual install |
|
|
14
|
-
| MCP Support | ✅ mcp-builder, mcp-management | ✅ MCP integration | ✅ Built-in |
|
|
14
|
+
| MCP Support | ✅ mcp-builder, mcp-management | ✅ MCP integration | ✅ Built-in | ✅ mcp-builder skill |
|
|
15
15
|
| CLI Tool | ❌ | ✅ task-master CLI | ✅ claude CLI | ⚠️ Basic (ag-kit) |
|
|
16
16
|
| Task Management | ❌ | ✅ (Core feature) | ⚠️ Basic | ❌ Missing |
|
|
17
17
|
| Web UI/Dashboard | ❌ | ❌ | ❌ | ⚠️ Docs only |
|
|
18
18
|
| Multi-AI Support | ✅ Claude-focused | ✅ Any AI chat | ✅ Claude only | ✅ Gemini + others |
|
|
19
|
-
| Problem-Solving Skills | ✅ 6 frameworks | ❌ | ❌ |
|
|
19
|
+
| Problem-Solving Skills | ✅ 6 frameworks | ❌ | ❌ | ✅ 6 frameworks used |
|
|
20
20
|
| Marketing Skills | ✅ 28 agents | ❌ | ❌ | ❌ Missing |
|
|
21
21
|
|
|
22
22
|
---
|
|
@@ -410,10 +410,10 @@ compatible_with:
|
|
|
410
410
|
|
|
411
411
|
## 🎯 Quick Wins (< 1 day each)
|
|
412
412
|
|
|
413
|
-
1. **Add `mcp-builder` skill** - Port từ ClaudeKit
|
|
414
|
-
2. **Add problem-solving skills** (6 frameworks)
|
|
413
|
+
1. **Add `mcp-builder` skill** - Port từ ClaudeKit ✅ Done
|
|
414
|
+
2. **Add problem-solving skills** (6 frameworks) ✅ Done
|
|
415
415
|
3. **Add `mermaidjs` skill** for diagrams
|
|
416
|
-
4. **Add `context-engineering` skill**
|
|
416
|
+
4. **Add `context-engineering` skill** ✅ Done
|
|
417
417
|
5. **Improve CLI với `ag-kit skills list`**
|
|
418
418
|
6. **Add `/task` workflow** cho task management
|
|
419
419
|
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: context-engineering
|
|
3
|
+
description: Advanced strategies to optimize LLM context window, reduce lost-in-the-middle phenomena, and improve reasoning through structured inputs.
|
|
4
|
+
requirements:
|
|
5
|
+
- python >= 3.8
|
|
6
|
+
- tiktoken (for counting tokens)
|
|
7
|
+
types:
|
|
8
|
+
- strategy
|
|
9
|
+
- optimization
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
# Context Engineering
|
|
13
|
+
|
|
14
|
+
> **"Context is King."** - In the era of LLMs, managing the context window is the single most important factor for performance, accuracy, and cost efficiency.
|
|
15
|
+
|
|
16
|
+
This skill provides a systematic approach to curating, structuring, and optimizing the information sent to AI models. It moves beyond simple "prompt engineering" into the architectural design of information flow.
|
|
17
|
+
|
|
18
|
+
## 🧠 Core Philosophy: The 4 Pillars
|
|
19
|
+
|
|
20
|
+
1. **Context Curation (Signal-to-Noise Ratio):**
|
|
21
|
+
- NEVER dump the entire codebase.
|
|
22
|
+
- Use **Dependency Graphs** and **Symbol Jumping** to select only highly relevant files.
|
|
23
|
+
- *Technique:* `RepoMap` (Tree structure) for high-level understanding + `Skeleton` (Signatures) for interface understanding.
|
|
24
|
+
|
|
25
|
+
2. **Context Structuring (XML & Framing):**
|
|
26
|
+
- Use explicit XML tags (`<documents>`, `<instructions>`, `<history>`) to separate semantic zones.
|
|
27
|
+
- **Prime Positioning:** Place critical instructions at the very end of the prompt (Recency Bias).
|
|
28
|
+
- **Context Caching:** Structure static content (docs, rules) at the top to leverage API caching (Anthropic/Gemini).
|
|
29
|
+
|
|
30
|
+
3. **Context Compression (Information Density):**
|
|
31
|
+
- **Skeletonization:** Replace function bodies with `...` or `pass` when only the interface is needed.
|
|
32
|
+
- **Summarization:** Compress chat history into key architectural decisions, discarding "chit-chat".
|
|
33
|
+
- **Token Budgeting:** Allocate tokens strictly: 40% Active Code, 30% Reference, 20% Reasoning buffer, 10% History.
|
|
34
|
+
|
|
35
|
+
4. **In-Context Guidance (Few-Shot & CoT):**
|
|
36
|
+
- **Few-Shot Learning:** Include 2-3 examples of "Golden Code" (perfect code style for this project) to align style instantly.
|
|
37
|
+
- **Chain-of-Thought (CoT):** Force the model to `<think>` before answering.
|
|
38
|
+
|
|
39
|
+
## 📂 Skill Structure
|
|
40
|
+
|
|
41
|
+
```text
|
|
42
|
+
skills/context-engineering/
|
|
43
|
+
├── SKILL.md # You are here
|
|
44
|
+
├── strategies/
|
|
45
|
+
│ ├── xml-framing.md # How to organize the prompt payload
|
|
46
|
+
│ ├── context-caching.md # Optimizing for Anthropic/Gemini Cache
|
|
47
|
+
│ ├── skeleton-code.md # Technique to compress code reading
|
|
48
|
+
│ └── few-shot-examples.md # Constructing powerful examples
|
|
49
|
+
└── scripts/
|
|
50
|
+
├── token_counter.py # Utility to estimate token usage
|
|
51
|
+
└── repo_mapper.py # Generates a tree-view map of the project
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## 🚀 How to Apply
|
|
55
|
+
|
|
56
|
+
### 1. Before asking a complex question:
|
|
57
|
+
- Run `repo_mapper.py` to give the AI a high-level map.
|
|
58
|
+
- Decide which files are "Active" (need editing) vs "Reference" (need reading).
|
|
59
|
+
- Use **Skeleton** mode for Reference files to save tokens.
|
|
60
|
+
|
|
61
|
+
### 2. When writing instructions:
|
|
62
|
+
- Wrap your request in standard XML structures.
|
|
63
|
+
- Use the **Golden Rule of Positioning**:
|
|
64
|
+
- Top: Static Context (Docs, Project Rules) -> *Cached*
|
|
65
|
+
- Middle: Dynamic Context (Current Files, Chat History)
|
|
66
|
+
- Bottom: The Request (Instruction + Output Format)
|
|
67
|
+
|
|
68
|
+
### 3. For Debugging & Architecture:
|
|
69
|
+
- Enable **Chain-of-Thought**: Ask the AI to "Think step-by-step inside <thinking> tags".
|
|
70
|
+
|
|
71
|
+
## 📚 References
|
|
72
|
+
- **MemGPT:** Paging and eviction strategies (Working vs Reference memory).
|
|
73
|
+
- **Anthropic Research:** Long-context prompting, finding the needle in a haystack.
|
|
74
|
+
- **LlamaIndex:** Node parsing and index retrieval strategies.
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# 🤖 Advanced Context-Engineered Prompt Template
|
|
2
|
+
|
|
3
|
+
Copy this entire block and fill in the placeholders to experience "SOTA" (State-of-the-Art) AI coding.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
```xml
|
|
8
|
+
<system_context>
|
|
9
|
+
<role>
|
|
10
|
+
You are a Principal Software Architect at Google Deepmind, specialized in Next.js, TypeScript, and Shadcn UI.
|
|
11
|
+
Your goal is to write "Golden Code": secure, performant, readable, and perfectly typed.
|
|
12
|
+
</role>
|
|
13
|
+
<constraints>
|
|
14
|
+
1. NO "any" types. Use proper interfaces or generics.
|
|
15
|
+
2. Use functional components with hooks.
|
|
16
|
+
3. Prioritize "Composition over Inheritance".
|
|
17
|
+
4. Measure twice, cut once: Think before coding.
|
|
18
|
+
</constraints>
|
|
19
|
+
</system_context>
|
|
20
|
+
|
|
21
|
+
<project_structure>
|
|
22
|
+
./
|
|
23
|
+
web/
|
|
24
|
+
src/
|
|
25
|
+
components/
|
|
26
|
+
ui/ # Base Shadcn components
|
|
27
|
+
layout/ # Structure components
|
|
28
|
+
app/
|
|
29
|
+
docs/ # Documentation pages
|
|
30
|
+
lib/
|
|
31
|
+
utils.ts # Helper functions
|
|
32
|
+
</project_structure>
|
|
33
|
+
|
|
34
|
+
<reference_documents>
|
|
35
|
+
<!-- We inject the "Skeleton" of a relevant utility to save tokens -->
|
|
36
|
+
<document path="web/src/lib/utils.ts" type="skeleton">
|
|
37
|
+
export function cn(...inputs: ClassValue[]): string;
|
|
38
|
+
export function formatDate(date: Date): string;
|
|
39
|
+
</document>
|
|
40
|
+
|
|
41
|
+
<!-- We inject the design system rules -->
|
|
42
|
+
<document path="web/tailwind.config.ts" type="summary">
|
|
43
|
+
Primary Color: HSL(222.2, 47.4%, 11.2%)
|
|
44
|
+
Border Radius: 0.5rem
|
|
45
|
+
Font: Inter
|
|
46
|
+
</document>
|
|
47
|
+
</reference_documents>
|
|
48
|
+
|
|
49
|
+
<user_instruction>
|
|
50
|
+
<task>
|
|
51
|
+
Create a new "FeatureCard" component in `web/src/components/ui/feature-card.tsx`.
|
|
52
|
+
</task>
|
|
53
|
+
|
|
54
|
+
<requirements>
|
|
55
|
+
1. It must look premium (glassmorphism effect).
|
|
56
|
+
2. It should accept an Icon, Title, Description, and an optional "Learn More" link.
|
|
57
|
+
3. It must be responsive (stack on mobile, grid on desktop).
|
|
58
|
+
4. Use the `cn()` utility for class merging.
|
|
59
|
+
</requirements>
|
|
60
|
+
|
|
61
|
+
<example_output>
|
|
62
|
+
Provide the full code for `feature-card.tsx` and a usage example.
|
|
63
|
+
</example_output>
|
|
64
|
+
</user_instruction>
|
|
65
|
+
|
|
66
|
+
<thinking_process_guidance>
|
|
67
|
+
Before generating the code, you must perform a "Chain of Thought" analysis inside <thinking> tags:
|
|
68
|
+
1. Analyze the requirements.
|
|
69
|
+
2. Check the <reference_documents> for available tools (cn).
|
|
70
|
+
3. Plan the component API (Props interface).
|
|
71
|
+
4. Plan the Tailwind classes for "glassmorphism".
|
|
72
|
+
</thinking_process_guidance>
|
|
73
|
+
```
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
def generate_repo_map(root_dir, ignore_dirs=None):
|
|
5
|
+
if ignore_dirs is None:
|
|
6
|
+
ignore_dirs = {'.git', 'node_modules', 'dist', 'build', '.next', '__pycache__', '.agent'}
|
|
7
|
+
|
|
8
|
+
repo_map = []
|
|
9
|
+
|
|
10
|
+
for root, dirs, files in os.walk(root_dir):
|
|
11
|
+
# Modify dirs in-place to skip ignored directories
|
|
12
|
+
dirs[:] = [d for d in dirs if d not in ignore_dirs]
|
|
13
|
+
|
|
14
|
+
level = root.replace(root_dir, '').count(os.sep)
|
|
15
|
+
indent = ' ' * 4 * (level)
|
|
16
|
+
repo_map.append(f'{indent}{os.path.basename(root)}/')
|
|
17
|
+
|
|
18
|
+
subindent = ' ' * 4 * (level + 1)
|
|
19
|
+
for f in files:
|
|
20
|
+
if f.startswith('.'): continue
|
|
21
|
+
repo_map.append(f'{subindent}{f}')
|
|
22
|
+
|
|
23
|
+
return '\n'.join(repo_map)
|
|
24
|
+
|
|
25
|
+
if __name__ == "__main__":
|
|
26
|
+
path = sys.argv[1] if len(sys.argv) > 1 else "."
|
|
27
|
+
print(generate_repo_map(path))
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import tiktoken
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
def count_tokens(text):
|
|
6
|
+
"""
|
|
7
|
+
Count tokens using cl100k_base encoding (used by GPT-4, Claude 3, Gemini).
|
|
8
|
+
This is an approximation for non-OpenAI models but generally accurate enough for budgeting.
|
|
9
|
+
"""
|
|
10
|
+
try:
|
|
11
|
+
encoding = tiktoken.get_encoding("cl100k_base")
|
|
12
|
+
num_tokens = len(encoding.encode(text))
|
|
13
|
+
return num_tokens
|
|
14
|
+
except Exception as e:
|
|
15
|
+
print(f"Error initializing tokenizer: {e}")
|
|
16
|
+
return 0
|
|
17
|
+
|
|
18
|
+
def estimate_cost(tokens, model="gpt-4o"):
|
|
19
|
+
# Approx prices per 1M tokens (as of late 2024/2025)
|
|
20
|
+
pricing = {
|
|
21
|
+
"gpt-4o": 5.00, # Input
|
|
22
|
+
"claude-3-5-sonnet": 3.00,
|
|
23
|
+
"gemini-1.5-pro": 3.50
|
|
24
|
+
}
|
|
25
|
+
price_per_1m = pricing.get(model, 5.00)
|
|
26
|
+
cost = (tokens / 1_000_000) * price_per_1m
|
|
27
|
+
return cost
|
|
28
|
+
|
|
29
|
+
if __name__ == "__main__":
|
|
30
|
+
if len(sys.argv) < 2:
|
|
31
|
+
print("Usage: python token_counter.py <file_or_directory>")
|
|
32
|
+
sys.exit(1)
|
|
33
|
+
|
|
34
|
+
path = sys.argv[1]
|
|
35
|
+
total_tokens = 0
|
|
36
|
+
|
|
37
|
+
if os.path.isfile(path):
|
|
38
|
+
with open(path, 'r', encoding='utf-8', errors='ignore') as f:
|
|
39
|
+
content = f.read()
|
|
40
|
+
total_tokens = count_tokens(content)
|
|
41
|
+
print(f"File: {path}")
|
|
42
|
+
print(f"Tokens: {total_tokens}")
|
|
43
|
+
elif os.path.isdir(path):
|
|
44
|
+
print(f"Scanning directory: {path} (ignoring hidden & node_modules)...")
|
|
45
|
+
for root, dirs, files in os.walk(path):
|
|
46
|
+
dirs[:] = [d for d in dirs if not d.startswith('.') and d != 'node_modules']
|
|
47
|
+
for file in files:
|
|
48
|
+
if file.startswith('.'): continue
|
|
49
|
+
if file.endswith(('.png', '.jpg', '.jpeg', '.gif', '.svg', '.ico', '.woff', '.ttf')): continue
|
|
50
|
+
|
|
51
|
+
file_path = os.path.join(root, file)
|
|
52
|
+
try:
|
|
53
|
+
with open(file_path, 'r', encoding='utf-8', errors='ignore') as f:
|
|
54
|
+
content = f.read()
|
|
55
|
+
tokens = count_tokens(content)
|
|
56
|
+
total_tokens += tokens
|
|
57
|
+
# Optional: Print large files
|
|
58
|
+
if tokens > 5000:
|
|
59
|
+
print(f" - Large file: {file_path} ({tokens} tokens)")
|
|
60
|
+
except Exception as e:
|
|
61
|
+
pass
|
|
62
|
+
|
|
63
|
+
print("-" * 30)
|
|
64
|
+
print(f"TOTAL TOKENS: {total_tokens:,}")
|
|
65
|
+
print(f"Est. Input Cost (GPT-4o/Claude-3.5): ~${estimate_cost(total_tokens):.4f}")
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Context Caching Strategy
|
|
2
|
+
|
|
3
|
+
Context Caching is a game-changer for reducing latency and cost when dealing with large contexts (e.g., full documentation, design systems, or large codebases).
|
|
4
|
+
|
|
5
|
+
## How it Works
|
|
6
|
+
|
|
7
|
+
Most LLM providers (Anthropic, Google Gemini) process the prompt sequentially. If the first part of the prompt (the "prefix") is identical across multiple requests, the server can cache the computed attention states of that prefix.
|
|
8
|
+
|
|
9
|
+
- **Hit:** Instant processing, drastically reduced cost (usually ~10% of input price).
|
|
10
|
+
- **Miss:** Normal processing time and cost.
|
|
11
|
+
|
|
12
|
+
## The "Static-First" Rule
|
|
13
|
+
|
|
14
|
+
To maximize cache hits, you must structure your prompt so that **static content is always at the top**.
|
|
15
|
+
|
|
16
|
+
### ✅ Optimized Structure (Cache-Friendly)
|
|
17
|
+
|
|
18
|
+
```xml
|
|
19
|
+
<!-- BLOCK 1: STATIC (Cached) -->
|
|
20
|
+
<system_instructions>...</system_instructions>
|
|
21
|
+
<project_rules>...</project_rules>
|
|
22
|
+
<library_documentation>...</library_documentation>
|
|
23
|
+
<design_system>...</design_system>
|
|
24
|
+
|
|
25
|
+
<!-- BLOCK 2: DYNAMIC (Not Cached) -->
|
|
26
|
+
<chat_history>
|
|
27
|
+
User: Hi
|
|
28
|
+
AI: Hello
|
|
29
|
+
</chat_history>
|
|
30
|
+
<current_file_content>...</current_file_content>
|
|
31
|
+
<new_user_request>...</new_user_request>
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### ❌ Bad Structure (Cache-Killer)
|
|
35
|
+
|
|
36
|
+
```xml
|
|
37
|
+
<chat_history>...</chat_history> <!-- Changes every turn! -->
|
|
38
|
+
<system_instructions>...</system_instructions> <!-- Reformatted every time, cache miss! -->
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Implementation Guidelines
|
|
42
|
+
|
|
43
|
+
1. **Breakpoint Management:** Providers usually require a minimum token count to activate caching (e.g., 1024 tokens for Anthropic). Ensure your static block is large enough.
|
|
44
|
+
2. **Immutable Docs:** Treat your documentation and rules as "Immutable". Do not change them dynamically per request unless necessary.
|
|
45
|
+
3. **Cache Control:** Explicitly mark the boundary where caching should stop (if the API supports explicit cache control headers or breakpoints).
|
|
46
|
+
|
|
47
|
+
## Provider Specifics
|
|
48
|
+
|
|
49
|
+
- **Anthropic:** Supports `cache_control: {"type": "ephemeral"}` on specific blocks.
|
|
50
|
+
- **Gemini:** Automatic prefix caching for high-volume endpoints (check current API docs).
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Few-Shot Learning & In-Context Guidance
|
|
2
|
+
|
|
3
|
+
"Show, Don't Tell". LLMs are excellent pattern matchers. Instead of writing 10 paragraphs of rules explaining your coding style, provide **2-3 examples** of code that follows those rules.
|
|
4
|
+
|
|
5
|
+
## The Power of Few-Shot
|
|
6
|
+
|
|
7
|
+
- **Zero-Shot:** "Write a Python function to add numbers." -> *Generic output.*
|
|
8
|
+
- **Few-Shot:** "Here are 3 examples of our project's Python style. Now write a function to add numbers." -> *Output perfectly matches your project's error handling, typing, and docstring standards.*
|
|
9
|
+
|
|
10
|
+
## Constructing "Golden Examples"
|
|
11
|
+
|
|
12
|
+
A Golden Example should demonstrate the **Key Pillars** of your architecture.
|
|
13
|
+
|
|
14
|
+
### Example: "The Robust Handler Pattern"
|
|
15
|
+
|
|
16
|
+
If your project requires all API handlers to have Try-Catch, Logging, and Zod Validation, create an example like this:
|
|
17
|
+
|
|
18
|
+
```xml
|
|
19
|
+
<examples>
|
|
20
|
+
<example>
|
|
21
|
+
<input>Create a handler to update user profile.</input>
|
|
22
|
+
<output>
|
|
23
|
+
<thinking>
|
|
24
|
+
1. Validate input with Zod.
|
|
25
|
+
2. Use UserService for logic.
|
|
26
|
+
3. Wrap in try/catch for global error handler.
|
|
27
|
+
</thinking>
|
|
28
|
+
<code>
|
|
29
|
+
export const updateProfile = async (req: Request, res: Response) => {
|
|
30
|
+
try {
|
|
31
|
+
const schema = z.object({ name: z.string() });
|
|
32
|
+
const data = schema.parse(req.body);
|
|
33
|
+
const user = await UserService.update(req.user.id, data);
|
|
34
|
+
return res.json({ success: true, data: user });
|
|
35
|
+
} catch (error) {
|
|
36
|
+
logger.error("Update profile failed", error);
|
|
37
|
+
next(error);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
</code>
|
|
41
|
+
</output>
|
|
42
|
+
</example>
|
|
43
|
+
</examples>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## When to use?
|
|
47
|
+
|
|
48
|
+
1. **New File Creation:** Essential. The AI needs to know the "boilerplate" feel.
|
|
49
|
+
2. **Complex Refactoring:** Useful to show "Before vs After" examples.
|
|
50
|
+
3. **Specific Libraries:** If using a niche library, provide examples of its usage.
|
|
51
|
+
|
|
52
|
+
## Strategy: Dynamic Retrieval
|
|
53
|
+
|
|
54
|
+
Don't stuff 50 examples into the context. Use **RAG (Retrieval Augmented Generation)** (or a simple grep-based selector) to find the *most relevant* example for the current task.
|
|
55
|
+
- Task: "Create React Component" -> Inject "React Component Example".
|
|
56
|
+
- Task: "Create SQL Query" -> Inject "SQL Query Example".
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Skeleton Code Strategy
|
|
2
|
+
|
|
3
|
+
**Context Compression** is vital. You rarely need the full implementation of imported modules to understand how to use them. You only need the **Interface** (signatures).
|
|
4
|
+
|
|
5
|
+
## What is Skeleton Code?
|
|
6
|
+
|
|
7
|
+
Skeleton code retains the structure but removes the logic implementation.
|
|
8
|
+
|
|
9
|
+
### Original `auth.service.ts`:
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
export class AuthService {
|
|
13
|
+
private apiUrl: string;
|
|
14
|
+
|
|
15
|
+
constructor(config: Config) {
|
|
16
|
+
this.apiUrl = config.apiUrl;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async login(credentials: Credentials): Promise<AuthResponse> {
|
|
20
|
+
if (!credentials.email || !credentials.password) {
|
|
21
|
+
throw new Error("Invalid input");
|
|
22
|
+
}
|
|
23
|
+
// ... 50 lines of logic ...
|
|
24
|
+
return response.data;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
async logout(): Promise<void> {
|
|
28
|
+
// ... logic ...
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Skeleton Version (Token Cost: ~10%):
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
export class AuthService {
|
|
37
|
+
private apiUrl: string;
|
|
38
|
+
constructor(config: Config);
|
|
39
|
+
async login(credentials: Credentials): Promise<AuthResponse>;
|
|
40
|
+
async logout(): Promise<void>;
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## When to use?
|
|
45
|
+
|
|
46
|
+
| File Type | Usage | Strategy |
|
|
47
|
+
| :--- | :--- | :--- |
|
|
48
|
+
| **Active File** | The file being edited | **Full Content** |
|
|
49
|
+
| **Direct Import** | Used by Active File | **Skeleton** (usually) |
|
|
50
|
+
| **Reference** | For understanding patterns | **Skeleton** or **Summary** |
|
|
51
|
+
| **Config/Types** | TypeScript interfaces, Zod schemas | **Full Content** (Critical for correctness) |
|
|
52
|
+
|
|
53
|
+
## Implementation Logic
|
|
54
|
+
|
|
55
|
+
1. Parse the AST (Abstract Syntax Tree) of the code.
|
|
56
|
+
2. Keep `class`, `function` definitions, `interface`, `type`.
|
|
57
|
+
3. Keep Docstrings/JSDoc (optional, usually helpful for semantics).
|
|
58
|
+
4. Remove function bodies `{ ... }`.
|
|
59
|
+
5. Remove private members (unless relevant for inheritance).
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# XML Framing Strategy
|
|
2
|
+
|
|
3
|
+
Use structured XML tags to clearly separate different types of information in the context. This helps the LLM distinguish between instructions, reference data, and user input.
|
|
4
|
+
|
|
5
|
+
## Standard Prompt Structure
|
|
6
|
+
|
|
7
|
+
```xml
|
|
8
|
+
<system_context>
|
|
9
|
+
<role>You are a Senior Software Engineer specialized in [Domain].</role>
|
|
10
|
+
<rules>
|
|
11
|
+
<!-- Project-specific rules (GEMINI.md) -->
|
|
12
|
+
</rules>
|
|
13
|
+
</system_context>
|
|
14
|
+
|
|
15
|
+
<reference_documents>
|
|
16
|
+
<document path="docs/api_spec.md">
|
|
17
|
+
... content ...
|
|
18
|
+
</document>
|
|
19
|
+
<document path="src/types.ts" mode="skeleton">
|
|
20
|
+
... content ...
|
|
21
|
+
</document>
|
|
22
|
+
</reference_documents>
|
|
23
|
+
|
|
24
|
+
<project_structure>
|
|
25
|
+
<!-- Output of repo_mapper.py -->
|
|
26
|
+
</project_structure>
|
|
27
|
+
|
|
28
|
+
<chat_history>
|
|
29
|
+
<!-- Compressed history -->
|
|
30
|
+
</chat_history>
|
|
31
|
+
|
|
32
|
+
<user_request>
|
|
33
|
+
<instruction>
|
|
34
|
+
Refactor the login function to use the new AuthService.
|
|
35
|
+
</instruction>
|
|
36
|
+
<constraints>
|
|
37
|
+
- Do not change the function signature.
|
|
38
|
+
- Add comprehensive error handling.
|
|
39
|
+
</constraints>
|
|
40
|
+
<active_file path="src/auth.ts">
|
|
41
|
+
... full content of the file to edit ...
|
|
42
|
+
</active_file>
|
|
43
|
+
</user_request>
|
|
44
|
+
|
|
45
|
+
<output_format>
|
|
46
|
+
Please provide the solution in the following format:
|
|
47
|
+
1. <thinking>: Analysis of the problem.
|
|
48
|
+
2. <plan>: Step-by-step implementation plan.
|
|
49
|
+
3. <code>: The modified code blocks.
|
|
50
|
+
</output_format>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Key Principles
|
|
54
|
+
|
|
55
|
+
1. **Wrappers matter:** `<code_block>` is better than just backticks for parsing.
|
|
56
|
+
2. **Attributes:** Use attributes like `<file path="...">` so the LLM knows the source.
|
|
57
|
+
3. **Nesting:** Don't go too deep (max 3 levels of nesting) to avoid confusing the attention mechanism.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Auto-generate optimized context for complex tasks using Context Engineering strategies.
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Context Optimization Workflow
|
|
6
|
+
|
|
7
|
+
This workflow automates the "Context Engineering" process. It analyzes your request, maps the project structure, summarizes relevant files, and wraps everything in a high-performance XML prompt structure for the AI.
|
|
8
|
+
|
|
9
|
+
**Trigger:** `/context [your task description]`
|
|
10
|
+
|
|
11
|
+
## Steps
|
|
12
|
+
|
|
13
|
+
1. **Analyze Intent:**
|
|
14
|
+
Take the user's task description ("{{task_description}}") and identify key domains (e.g., frontend, auth, database).
|
|
15
|
+
|
|
16
|
+
2. **Generate Repo Map:**
|
|
17
|
+
// turbo
|
|
18
|
+
Run the repo mapper to see the current structure.
|
|
19
|
+
`python3 .agent/skills/context-engineering/scripts/repo_mapper.py .`
|
|
20
|
+
|
|
21
|
+
3. **Construct Optimized Prompt:**
|
|
22
|
+
Based on the repo map and task, construct the following `Advanced Context` block.
|
|
23
|
+
|
|
24
|
+
**(Internal Instruction to AI):**
|
|
25
|
+
> You must now act as a Context Engineer. Do NOT just answer the user yet.
|
|
26
|
+
> Instead, OUTPUT a structured plan and code analysis using the gathered context.
|
|
27
|
+
> Use the `<thinking>` tag to analyze the Repo Map below.
|
|
28
|
+
> If the user's task matches specific files in the map, read them using `view_file`.
|
|
29
|
+
|
|
30
|
+
**Structure to enforce:**
|
|
31
|
+
```xml
|
|
32
|
+
<system_role>Senior Architect</system_role>
|
|
33
|
+
<project_context>
|
|
34
|
+
[Insert Output from Step 2 here]
|
|
35
|
+
</project_context>
|
|
36
|
+
<user_task>
|
|
37
|
+
{{task_description}}
|
|
38
|
+
</user_task>
|
|
39
|
+
<instruction>
|
|
40
|
+
1. Analyze the project structure above.
|
|
41
|
+
2. Identify ensuring files that need to be read or modified.
|
|
42
|
+
3. Proceed with solving the user's task using Chain-of-Thought (<thinking> tags).
|
|
43
|
+
</instruction>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
4. **Execute:**
|
|
47
|
+
Proceed to solve the user's request using the heightened context awareness.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@musashishao/agent-kit",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "AI Agent templates - Skills, Agents, and Workflows for enhanced coding assistance",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -40,4 +40,4 @@
|
|
|
40
40
|
"engines": {
|
|
41
41
|
"node": ">=16.0.0"
|
|
42
42
|
}
|
|
43
|
-
}
|
|
43
|
+
}
|