Advertisement
Guest User

Untitled

a guest
Jul 14th, 2025
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.50 KB | None | 0 0
  1. # AlterActionGenerator - AI Context
  2.  
  3. ## 1. Project Overview
  4.  
  5. - **Vision:** Generate programmatic Alter Actions for the Alter macOS AI assistant, enabling automated creation of AI-powered workflows that integrate with macOS applications
  6. - **Current Phase:** Initial development and template collection
  7. - **Key Architecture:** YAML-based configuration system for AI workflow definitions with context-aware triggering and templated prompts
  8. - **Development Strategy:** Build a generator tool that understands the Alter Action specification and can create new actions based on user requirements and existing patterns
  9.  
  10. ## 2. Project Structure
  11.  
  12. **⚠️ CRITICAL: AI agents MUST read the [Project Structure documentation](/docs/ai-context/project-structure.md) before attempting any task to understand the complete technology stack, file tree and project organization.**
  13.  
  14. AlterActionGenerator follows a YAML-based template collection pattern with documentation and example analysis. The project contains a collection of Alter Action templates in YAML format that define AI-powered workflows for macOS automation. For the complete tech stack and file tree structure, see [docs/ai-context/project-structure.md](/docs/ai-context/project-structure.md).
  15.  
  16. ## 3. Understanding Alter Actions
  17.  
  18. ### What is Alter?
  19.  
  20. Alter is a macOS AI assistant that lives in the notch and integrates deeply with macOS applications. It provides context-aware AI interactions through "Alter Actions" - YAML-defined workflows that trigger based on system context and execute AI tasks.
  21.  
  22. ### Alter Action YAML Structure
  23.  
  24. Every Alter Action follows a consistent YAML structure with specific required and optional fields:
  25.  
  26. #### Required Fields:
  27.  
  28. ```yaml
  29. id: "unique-action-identifier" # Unique string identifier
  30. name: "Human Readable Action Name" # Display name in menus
  31. onlyIfRunning: true # Only show if specified apps running
  32. onlyIfActive: true # Only show if specified apps active
  33. prompt: # AI prompt configuration
  34. system: | # System prompt for AI model
  35. You are an expert assistant that...
  36. user: |- # User prompt with template variables
  37. {{ textSelection }}
  38. ```
  39.  
  40. #### Common Optional Fields:
  41.  
  42. ```yaml
  43. description: "What this action does" # Action explanation
  44. icon: "text.quote" # SF Symbols icon name
  45. enabled: true # Menu visibility control
  46. core: true # Core system action flag
  47. category: "code" # Action grouping
  48. color: "purple" # Visual theming
  49. consumer: "markdown" # Output display format
  50. temperature: 0.7 # AI model temperature
  51. model: "claude-3-5-sonnet" # Specific AI model
  52. ```
  53.  
  54. #### Application Context System:
  55.  
  56. ```yaml
  57. installedApplications: # Required applications
  58. - com.microsoft.VSCode
  59. - com.apple.Terminal
  60. - dev.zed.Zed
  61. onlyIfRunning: true # Only if apps are running
  62. onlyIfActive: true # Only if apps are active
  63. onlyIfBrowserTab: ["github", "gitlab"] # Browser-specific contexts
  64. ```
  65.  
  66. #### Context Keys Available:
  67.  
  68. Actions can access various macOS context through template variables:
  69.  
  70. - `{{ textSelection }}` - Selected text in active app
  71. - `{{ selectedFiles }}` - File selections in Finder
  72. - `{{ activeTab }}` - Browser tab information
  73. - `{{ clipboard }}` - System clipboard content
  74. - `{{ mail }}` - Email context data
  75. - `{{ keynote }}` - Keynote presentation data
  76. - `{{ youtubeTranscript }}` - YouTube video transcripts
  77. - `{{ windowContent }}` - Active window content
  78.  
  79. **Enhanced Context Types (from GUI analysis):**
  80.  
  81. - `{{ activeApplication }}` - Currently active application
  82. - `{{ activeWindow }}` - Active window information
  83. - `{{ keynoteDocument }}` - Keynote document context
  84. - `{{ currentSlideInKeynote }}` - Current Keynote slide
  85. - `{{ currentThemeInKeynote }}` - Current Keynote theme
  86. - `{{ appleMail }}` - Apple Mail specific context
  87. - `{{ finderFileSelection }}` - Finder file selections
  88. - `{{ activeWindowContent }}` - Content of active window
  89.  
  90. #### Prompt System with Templating:
  91.  
  92. ```yaml
  93. prompt:
  94. system: |
  95. # IDENTITY and PURPOSE
  96. You are an expert coder that explains code...
  97.  
  98. # STEPS
  99. 1. Analyze the provided code
  100. 2. Explain its purpose and functionality
  101.  
  102. # OUTPUT INSTRUCTIONS
  103. - Use clear, concise language
  104. - Provide structured explanations
  105. user: |-
  106. {% if textSelection %}
  107. Please explain this code:
  108. {{ textSelection }}
  109. {% endif %}
  110. {% if selectedFiles %}
  111. Files to analyze: {{ selectedFiles }}
  112. {% endif %}
  113. ```
  114.  
  115. #### Organization and Advanced Features (GUI Analysis):
  116.  
  117. ```yaml
  118. # Organization
  119. folder: "Code Analysis" # Organize actions in folders
  120. category: "code" # Action category
  121.  
  122. # User Interface
  123. includeProfile: true # Include user profile in context
  124. globalKeyboardShortcut: "Cmd+Shift+C" # Global shortcut
  125. presenter: "markdown" # Presentation format (markdown/code/diff)
  126.  
  127. # Advanced Features
  128. model: "claude-sonnet-4-20250514" # Specific model to use
  129. workspace: "Development" # Workspace-specific actions
  130. quickAction: "format-output" # Execute another action after completion
  131. ```
  132.  
  133. #### Parameter System:
  134.  
  135. Interactive form inputs collected before action execution:
  136.  
  137. ```yaml
  138. parameters:
  139. - name: language
  140. label: Target Language
  141. type: select
  142. choices: [English, French, Spanish, German]
  143. default: English
  144. - name: input
  145. label: Additional Instructions
  146. type: text
  147. placeholder: "Enter your specific requirements..."
  148. - name: formal
  149. label: Use Formal Tone
  150. type: boolean
  151. default: false
  152. ```
  153.  
  154. **Parameter Types:**
  155.  
  156. - `boolean` - Toggle switches
  157. - `string` - Single-line text input
  158. - `text` - Multi-line text areas
  159. - `select` - Dropdown menus with choices
  160. - `radio` - Radio button groups
  161. - `float`/`integer` - Numeric inputs
  162. - `search` - Large search input fields
  163.  
  164. #### Consumer Types (Output Formats):
  165.  
  166. ```yaml
  167. consumer: "markdown" # Default rich text display
  168. consumer: "inPlace" # Replace selected text directly
  169. consumer: "code" # Syntax-highlighted code display
  170. consumer: "diff" # Show differences/changes
  171. consumer: "magicDiff" # Enhanced diff viewer
  172. consumer: "keynoteDeckEditor" # Keynote slide editing
  173. ```
  174.  
  175. #### Advanced Features:
  176.  
  177. ```yaml
  178. needsContextKeys: # Required contexts
  179. - ["textSelection"] # Requires text selection
  180. - ["selectedFiles"] # OR file selection
  181.  
  182. using: # Multi-context support
  183. - textSelection
  184. - selectedFiles
  185. - mail
  186. - youtubeTranscript
  187.  
  188. prompt:
  189. author: # Attribution
  190. name: "fabric"
  191. link: "https://github.com/danielmiessler/fabric"
  192. ```
  193.  
  194. ### Action Categories and Examples:
  195.  
  196. **Code-Related Actions:**
  197.  
  198. - `explain-code` - Code explanation and documentation
  199. - `fix-code` - Error detection and correction
  200. - `document-code` - Generate code documentation
  201.  
  202. **Content Processing:**
  203.  
  204. - `summarize` - Content summarization with structured output
  205. - `translate` - Multi-language translation
  206. - `rewrite` - Content rewriting and style adjustment
  207.  
  208. **Git Integration:**
  209.  
  210. - `git-commit` - Generate commit messages
  211. - `git-review` - Code review assistance
  212.  
  213. **Creative Actions:**
  214.  
  215. - `create-react-app` - Generate React applications
  216. - `create-images` - AI image generation
  217. - `create-diagrams` - Diagram creation
  218.  
  219. ### Key Design Principles:
  220.  
  221. 1. **Context-Aware Activation**: Actions appear only when relevant apps/contexts are available
  222. 2. **Template-Driven Prompts**: Flexible prompt system with variable substitution
  223. 3. **Structured Output**: Consistent formatting with sections and bullet points
  224. 4. **User Parameter Integration**: Dynamic form inputs that modify AI behavior
  225. 5. **Multi-Modal Support**: Handle text, files, images, and specialized content types
  226. 6. **Cross-Application Integration**: Work seamlessly across browsers, editors, and system apps
  227.  
  228. ## 4. Coding Standards & AI Instructions
  229.  
  230. ### General Instructions
  231.  
  232. - Your most important job is to manage your own context. Always read any relevant files BEFORE planning changes.
  233. - When updating documentation, keep updates concise and on point to prevent bloat.
  234. - Write code following KISS, YAGNI, and DRY principles.
  235. - When in doubt follow proven best practices for implementation.
  236. - Do not commit to git without user approval.
  237. - Do not run any servers, rather tell the user to run servers for testing.
  238. - Always consider industry standard libraries/frameworks first over custom implementations.
  239. - Never mock anything. Never use placeholders. Never omit code.
  240. - Apply SOLID principles where relevant. Use modern framework features rather than reinventing solutions.
  241. - Be brutally honest about whether an idea is good or bad.
  242. - Make side effects explicit and minimal.
  243. - Design database schema to be evolution-friendly (avoid breaking changes).
  244.  
  245.  
  246. ### File Organization & Modularity
  247.  
  248. - Default to creating multiple small, focused files rather than large monolithic ones
  249. - Each file should have a single responsibility and clear purpose
  250. - Keep files under 350 lines when possible - split larger files by extracting utilities, constants, types, or logical components into separate modules
  251. - Separate concerns: utilities, constants, types, components, and business logic into different files
  252. - Prefer composition over inheritance - use inheritance only for true 'is-a' relationships, favor composition for 'has-a' or behavior mixing
  253.  
  254. - Follow existing project structure and conventions - place files in appropriate directories. Create new directories and move files if deemed appropriate.
  255. - Use well defined sub-directories to keep things organized and scalable
  256. - Structure projects with clear folder hierarchies and consistent naming conventions
  257. - Import/export properly - design for reusability and maintainability
  258.  
  259. ### YAML Standards
  260.  
  261. - **Always** validate YAML structure and required fields
  262. - Use consistent indentation (2 spaces preferred)
  263. - Quote strings containing special characters
  264. - Validate template variable syntax using Stencil format
  265.  
  266. ```yaml
  267. # Good YAML structure
  268. id: "action-name"
  269. name: "Human Readable Name"
  270. description: "Clear action description"
  271. prompt:
  272. system: |
  273. # IDENTITY and PURPOSE
  274. You are an expert assistant...
  275. user: |-
  276. {% if textSelection %}
  277. Selected text: {{ textSelection }}
  278. {% endif %}
  279. ```
  280.  
  281. ### Naming Conventions
  282.  
  283. - **Action IDs**: kebab-case (e.g., `explain-code`, `git-commit`)
  284. - **Categories**: lowercase single words (e.g., `code`, `git`, `translate`)
  285. - **Parameter names**: camelCase (e.g., `targetLanguage`, `includeComments`)
  286. - **Template variables**: camelCase in mustache syntax (e.g., `{{ textSelection }}`, `{{ selectedFiles }}`)
  287.  
  288.  
  289. ### Documentation Requirements
  290.  
  291. - Every Alter Action needs a clear description field
  292. - Complex actions should include usage examples in comments
  293. - Document parameter purposes and expected values
  294. - Include context requirements and application dependencies
  295.  
  296. ```yaml
  297. # Example: Well-documented action
  298. id: "explain-code"
  299. name: "Explain Code"
  300. description: "Provides detailed explanations of selected code, including purpose, functionality, and key concepts"
  301. category: "code"
  302. # Requires: Text selection in code editor
  303. # Usage: Select code in any editor and run action
  304. parameters:
  305. - name: detailLevel
  306. label: "Detail Level"
  307. type: select
  308. choices: ["basic", "detailed", "comprehensive"]
  309. default: "detailed"
  310. # Purpose: Controls depth of explanation
  311. ```
  312.  
  313. ### Security & Privacy
  314.  
  315. - Never include sensitive information in YAML files (API keys, personal data)
  316. - Validate all template variables and user inputs in prompts
  317. - Be cautious with actions that access system files or execute commands
  318. - Review generated prompts for potential injection vulnerabilities
  319. - Ensure context access is limited to what's necessary for the action
  320. - Document privacy implications of context usage (file access, clipboard, etc.)
  321. - Validate YAML structure to prevent malformed configurations
  322.  
  323. ### Error Handling
  324.  
  325. - Validate YAML syntax and required fields before processing
  326. - Provide clear error messages for malformed actions
  327. - Handle missing context gracefully with fallback behaviors
  328. - Test actions with various context scenarios (missing text selection, no files, etc.)
  329.  
  330. ### Action Design Principles
  331.  
  332. - Make actions context-aware and only appear when relevant
  333. - Design prompts to be robust against edge cases
  334. - Provide clear user feedback through descriptions and parameter labels
  335. - Test actions across different macOS applications and scenarios
  336. - Keep action scope focused and avoid feature creep
  337. - Design for internationalization when creating user-facing text
  338.  
  339. ### Template Best Practices
  340.  
  341. - Use conditional blocks to handle optional context (`{% if textSelection %}`)
  342. - Provide fallback prompts when expected context is missing
  343. - Structure system prompts with clear sections (IDENTITY, PURPOSE, STEPS, OUTPUT)
  344. - Make user prompts concise but include necessary context
  345. - Test template rendering with various input combinations
  346.  
  347.  
  348. ## 5. Multi-Agent Workflows & Context Injection
  349.  
  350. ### Automatic Context Injection for Sub-Agents
  351.  
  352. When using the Task tool to spawn sub-agents, the core project context (CLAUDE.md, project-structure.md, docs-overview.md) is automatically injected into their prompts via the subagent-context-injector hook. This ensures all sub-agents have immediate access to essential project documentation without the need of manual specification in each Task prompt.
  353.  
  354.  
  355. ## 6. MCP Server Integrations
  356.  
  357. ### Gemini Consultation Server
  358.  
  359. **When to use:**
  360.  
  361. - Complex coding problems requiring deep analysis or multiple approaches
  362. - Code reviews and architecture discussions
  363. - Debugging complex issues across multiple files
  364. - Performance optimization and refactoring guidance
  365. - Detailed explanations of complex implementations
  366. - Highly security relevant tasks
  367.  
  368. **Automatic Context Injection:**
  369.  
  370. - The kit's `gemini-context-injector.sh` hook automatically includes two key files for new sessions:
  371. - `/docs/ai-context/project-structure.md` - Complete project structure and tech stack
  372. - `/MCP-ASSISTANT-RULES.md` - Your project-specific coding standards and guidelines
  373. - This ensures Gemini always has comprehensive understanding of your technology stack, architecture, and project standards
  374.  
  375. **Usage patterns:**
  376.  
  377. ```python
  378. # New consultation session (project structure auto-attached by hooks)
  379. mcp__gemini__consult_gemini(
  380. specific_question="How should I optimize this voice pipeline?",
  381. problem_description="Need to reduce latency in real-time audio processing",
  382. code_context="Current pipeline processes audio sequentially...",
  383. attached_files=[
  384. "src/core/pipelines/voice_pipeline.py" # Your specific files
  385. ],
  386. preferred_approach="optimize"
  387. )
  388.  
  389. # Follow-up in existing session
  390. mcp__gemini__consult_gemini(
  391. specific_question="What about memory usage?",
  392. session_id="session_123",
  393. additional_context="Implemented your suggestions, now seeing high memory usage"
  394. )
  395. ```
  396.  
  397. **Key capabilities:**
  398.  
  399. - Persistent conversation sessions with context retention
  400. - File attachment and caching for multi-file analysis
  401. - Specialized assistance modes (solution, review, debug, optimize, explain)
  402. - Session management for complex, multi-step problems
  403.  
  404. **Important:** Treat Gemini's responses as advisory feedback. Evaluate the suggestions critically, incorporate valuable insights into your solution, then proceed with your implementation.
  405.  
  406. ### Context7 Documentation Server
  407.  
  408. **Repository**: [Context7 MCP Server](https://github.com/upstash/context7)
  409.  
  410. **When to use:**
  411.  
  412. - Working with external libraries/frameworks (React, FastAPI, Next.js, etc.)
  413. - Need current documentation beyond training cutoff
  414. - Implementing new integrations or features with third-party tools
  415. - Troubleshooting library-specific issues
  416.  
  417. **Usage patterns:**
  418.  
  419. ```python
  420. # Resolve library name to Context7 ID
  421. mcp__context7__resolve_library_id(libraryName="react")
  422.  
  423. # Fetch focused documentation
  424. mcp__context7__get_library_docs(
  425. context7CompatibleLibraryID="/facebook/react",
  426. topic="hooks",
  427. tokens=8000
  428. )
  429. ```
  430.  
  431. **Key capabilities:**
  432.  
  433. - Up-to-date library documentation access
  434. - Topic-focused documentation retrieval
  435. - Support for specific library versions
  436. - Integration with current development practices
  437.  
  438.  
  439.  
  440. ## 7. Post-Task Completion Protocol
  441.  
  442. After completing any coding task, follow this checklist:
  443.  
  444. ### 1. YAML Validation & Quality Checks
  445.  
  446. After creating or modifying Alter Actions:
  447.  
  448. - **YAML Syntax**: Validate YAML structure and indentation
  449. - **Required Fields**: Ensure all required fields (id, name, prompt) are present
  450. - **Template Syntax**: Verify Stencil template variables are properly formatted
  451. - **Context Dependencies**: Check that required applications and context are documented
  452.  
  453. ### 2. Action Testing & Verification
  454.  
  455. - Test actions with various context scenarios (with/without text selection, different apps)
  456. - Verify prompt templates render correctly with sample data
  457. - Ensure action appears in appropriate contexts and is hidden when irrelevant
  458. - Test parameter inputs if the action includes interactive forms
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement