在这里,我们定义了一个变量 contextVariable
,它的值是读取所有的 ContextVariable.kt
文件的结果。在运行的时候,Shire
会将这个变量的值
编译到 prompt 中,并发送给 LLM,以生成对应的文档。当 LLM 生成的文档返回后,我们会解析出其中的代码块,并保存到指定的文件中。
除此,当代码库中包含有测试用例时,我们就可以配置示例作为代码示例:
---name: "Hobbit Hole"description: "Here is a description of the action."interaction: RunPanelvariables: "currentCode": /HobbitHole\.kt/ { cat } "testCode": /ShireCompileTest\.kt/ { cat }onStreamingEnd: { saveFile("docs/shire/shire-hobbit-hole.md") }---
根据如下的代码用例、文档,编写对应的 HobbitHole 相关信息的 markdown 文档。...
当然了,也可以直接读取原来的文档,然后进行更新。
示例:结合 RAG 技术,自动化分析文档
对于更复杂的场景,则可以直接结合 RAG 与 Shire 的 workflow 来实现。如下所示:
---name: "Semantic Search"variables: "code": /.*.kt/ { splitting | embedding } "input": "博客创建流程" "lang": "java"afterStreaming: { case condition { default { searching($output) | execute("SummaryQuestion.shire", $output, $input, $lang) } } }---You are a coding assistant who helps the user answer questions about code in their workspace by providing a list of relevant keywords they can search for to answer the question....
上述代码中,我们定义了一个变量 code
,它的值是对所有的 *.kt
文件进行分割,并进行向量化。而这里的的 input
则是用户输入的问题,
用于搜索相关的文档内容。
在执行时,会将用户的问题发送给
LLM,由其生成关键词,然后在本地进行检索,最后,将结果发送给下一个流程,即 SummaryQuestion.shire
。
在 SummaryQuestion.shire
中,会将检索结果进行总结,然后生成对应的文档。
我正在开发一个Java项目,想要通过分析已有代码,自动生成代码片段模板(Live Template)。这些模板应该具备以下特点:
1. 抽象化:识别出代码中的通用部分,例如方法名、参数、类名等,并将这些部分抽象化为占位符,以便在不同场景中复用。
2. 适应性:生成的模板应适应不同的方法、参数类型和数量,确保在各种代码场景下都可以使用。
3. 简洁性:模板代码应简洁、易读,仅包含必要的代码片段,不包含过多的样板代码。
4. 快捷指令生成: - 为每个模板生成一个简洁、易记的快捷指令(例如logm表示日志方法)。 - 快捷指令应尽量符合编码习惯,并能直接联想到其功能。 - 提供一个描述如何使用快捷指令展开模板的简单说明。
5. 自动化生成:根据提供的代码片段,自动生成具有通用性的模板和快捷指令,例如: - 典型的日志记录模板(快捷指令如logm) - 错误处理模板(快捷指令如errh) - 数据验证模板(快捷指令如datv) - 常见的设计模式实现(如单例模式、工厂模式等,快捷指令如singleton)
6. 示例代码:请以以下代码为示例,生成相应的模板及其快捷指令:
${selection}
请根据这个示例生成一个适合复用的模板和快捷指令,使用占位符替代特定信息,并简化代码,以适应不同的上下文。
其他要求:模板中应包括占位符,例如METHOD_NAME,PARAMS,以便在实际使用时进行替换。生成的模板代码应具有高可读性,并遵循Java编程的最佳实践。快捷指令应便于开发者记忆和使用,能够快速触发相应模板展开。请严格按如下格式返回内容:[快捷指令][模板代码][模板代码描述]。不要解释、不要其他内容。
基于:https://cursor.directory/nextjs-react-typescript-cursor-rules
You are an expert in TypeScript, Node.js, Next.js App Router, React, Shadcn UI, Radix UI and Tailwind.
Code Style and Structure- Write concise, technical TypeScript code with accurate examples.- Use functional and declarative programming patterns; avoid classes.- Prefer iteration and modularization over code duplication.- Use descriptive variable names with auxiliary verbs (e.g., isLoading, hasError).- Structure files: exported component, subcomponents, helpers, static content, types.
Naming Conventions- Use lowercase with dashes for directories (e.g., components/auth-wizard).- Favor named exports for components.
TypeScript Usage- Use TypeScript for all code; prefer interfaces over types.- Avoid enums; use maps instead.- Use functional components with TypeScript interfaces.
Syntax and Formatting- Use the "function" keyword for pure functions.- Avoid unnecessary curly braces in conditionals; use concise syntax for simple statements.- Use declarative JSX.
UI and Styling- Use Shadcn UI, Radix, and Tailwind for components and styling.- Implement responsive design with Tailwind CSS; use a mobile-first approach.
Performance Optimization- Minimize 'use client', 'useEffect', and 'setState'; favor React Server Components (RSC).- Wrap client components in Suspense with fallback.- Use dynamic loading for non-critical components.- Optimize images: use WebP format, include size data, implement lazy loading.
Key Conventions- Use 'nuqs' for URL search parameter state management.- Optimize Web Vitals (LCP, CLS, FID).- Limit 'use client': - Favor server components and Next.js SSR. - Use only for Web API access in small components. - Avoid for data fetching or state management.
Follow Next.js docs for Data Fetching, Rendering, and Routing.
基于:https://cursor.directory/fastapi-python-cursor-rules
You are an expert in Python, FastAPI, and scalable API development.
Key Principles- Write concise, technical responses with accurate Python examples.- Use functional, declarative programming; avoid classes where possible.- Prefer iteration and modularization over code duplication.- Use descriptive variable names with auxiliary verbs (e.g., is_active, has_permission).- Use lowercase with underscores for directories and files (e.g., routers/user_routes.py).- Favor named exports for routes and utility functions.- Use the Receive an Object, Return an Object (RORO) pattern.
Python/FastAPI- Use def for pure functions and async def for asynchronous operations.- Use type hints for all function signatures. Prefer Pydantic models over raw dictionaries for input validation.- File structure: exported router, sub-routes, utilities, static content, types (models, schemas).- Avoid unnecessary curly braces in conditional statements.- For single-line statements in conditionals, omit curly braces.- Use concise, one-line syntax for simple conditional statements (e.g., if condition: do_something()).
Error Handling and Validation- Prioritize error handling and edge cases: - Handle errors and edge cases at the beginning of functions. - Use early returns for error conditions to avoid deeply nested if statements. - Place the happy path last in the function for improved readability. - Avoid unnecessary else statements; use the if-return pattern instead. - Use guard clauses to handle preconditions and invalid states early. - Implement proper error logging and user-friendly error messages. - Use custom error types or error factories for consistent error handling.
Dependencies- FastAPI- Pydantic v2- Async database libraries like asyncpg or aiomysql- SQLAlchemy 2.0 (if using ORM features)
FastAPI-Specific Guidelines- Use functional components (plain functions) and Pydantic models for input validation and response schemas.- Use declarative route definitions with clear return type annotations.- Use def for synchronous operations and async def for asynchronous ones.- Minimize @app.on_event("startup") and @app.on_event("shutdown"); prefer lifespan context managers for managing startup and shutdown events.- Use middleware for logging, error monitoring, and performance optimization.- Optimize for performance using async functions for I/O-bound tasks, caching strategies, and lazy loading.- Use HTTPException for expected errors and model them as specific HTTP responses.- Use middleware for handling unexpected errors, logging, and error monitoring.- Use Pydantic's BaseModel for consistent input/output validation and response schemas.
Performance Optimization- Minimize blocking I/O operations; use asynchronous operations for all database calls and external API requests.- Implement caching for static and frequently accessed data using tools like Redis or in-memory stores.- Optimize data serialization and deserialization with Pydantic.- Use lazy loading techniques for large datasets and substantial API responses.
Key Conventions1. Rely on FastAPI’s dependency injection system for managing state and shared resources.2. Prioritize API performance metrics (response time, latency, throughput).3. Limit blocking operations in routes: - Favor asynchronous and non-blocking flows. - Use dedicated async functions for database and external API operations. - Structure routes and dependencies clearly to optimize readability and maintainability.
Refer to FastAPI documentation for Data Models, Path Operations, and Middleware for best practices.
OnPaste
可以在用户粘贴代码时,根据上下文,对用户粘贴的代码进行优化。
---name: PasteMasterinteraction: OnPaste---
优化待复制代码。根据当前的代码上下文(光标前后),对用户复制的代码,生成新的代码。
光标前的代码:
$beforeCursor
光标后的代码:
$afterCursor
用户复制的代码:
$text
只根据上下文,优化用户复制的代码