### Python: Create a Storytelling Prompt Source: https://llms.jgwill.com/llms-claude-agent-sdk-v2 Shows an example of crafting a prompt for the Claude Agent SDK focused on creative output, specifically storytelling. It contrasts problem-fixing language with creation-focused language and demonstrates initializing the client with project context. ```python # NOT: "Help me fix my plot holes" # YES: "Help me create a cohesive plot structure" prompt = """I want to create a compelling narrative where: - A reluctant hero discovers hidden power - They must choose between personal desire and community need - The resolution honors both the external quest and internal transformation What structural elements will strengthen this vision?""" async with ClaudeSDKClient(options=ClaudeAgentOptions( system_prompt=storytelling_system_prompt, setting_sources=["project"] # Load project context )) as client: await client.query(prompt) ``` -------------------------------- ### Storytelling Application CLI Usage Example Source: https://llms.jgwill.com/llms-coaiapy-cli-guide This example demonstrates a typical CLI usage pattern for a storytelling application integrating the 'fuse' command. It shows the sequence of commands for initializing a session, creating a trace, and documenting major story milestones with observations. ```bash # Initialize storytelling session coaia fuse sessions create story_session_2025_09_08 # Create trace for the narrative journey coaia fuse traces create narrative_trace_001 # Document major story milestones coaia fuse traces add-observation outline_created narrative_trace_001 coaia fuse traces add-observation chapter1_drafted narrative_trace_001 coaia fuse traces add-observation revision_complete narrative_trace_001 ``` -------------------------------- ### Basic UI Structure using ui.View in Python Source: https://llms.jgwill.com/llms-pythonista-full.gemini.txt Illustrates the fundamental structure for creating a visual application by subclassing `ui.View`. UI setup code should typically reside within the `__init__` method of such a subclass. ```python import ui class MyView(ui.View): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # Add UI elements and setup here self.label = ui.Label() self.label.text = 'Hello, World!' self.add_subview(self.label) def layout(self): # Define layout for subviews self.label.frame = self.bounds if __name__ == '__main__': # Example of how to present the view (context dependent) # For Pythonista, you might use: # v = MyView() # v.present('sheet') pass ``` -------------------------------- ### Storytelling Pipeline Usage Example Source: https://llms.jgwill.com/llms-coaiapy-cli-guide Provides examples of using the storytelling pipeline via CLI and Python library integration for creating and evaluating story content. ```APIDOC ## Example: Storytelling Pipeline Usage ### Scenario Story development with automated quality assessment. ### CLI Usage #### Create story development pipeline with judge evaluation ```bash coaia pipeline create llm-chain \ --var chain_name="story_chapter_1" \ --var model_name="claude-3" \ --var initial_prompt="Write opening chapter of sci-fi novel" \ --var enable_judge_evaluation=true \ --var judge_model="gpt-4" \ --var evaluation_criteria="creativity" ``` #### Evaluate existing story content ```bash coaia pipeline create judge-evaluation \ --var content_name="chapter_draft" \ --var content_to_evaluate="$(cat chapter1.txt)" \ --var evaluation_criteria="narrative_quality" ``` ### Library Integration ```python from coaiapy.pipeline import TemplateLoader, TemplateRenderer from coaiapy.cofuse import create_trace # Load storytelling template loader = TemplateLoader() template = loader.load_template("llm-chain") # Render with story-specific variables renderer = TemplateRenderer() observations = renderer.render_template(template, { "chain_name": "story_development", "initial_prompt": "Develop character backstory", "enable_judge_evaluation": True }) # Execute rendered observations through cofuse for obs in observations: create_observation(obs) ``` ### Environment Management (`env`) - Manage creative context variables. - Persist and manipulate workflow environment. - Enable dynamic, adaptive creative ecosystems. ``` -------------------------------- ### MCP Usage Example in Claude Code (Python) Source: https://llms.jgwill.com/llms-coaiapy-cli-guide Demonstrates how to create traces, add comments, and list comments using MCP within Claude Code. This example requires the 'mcp__coaiapy' library and assumes an active MCP client session. ```python # Create trace with observation await mcp__coaiapy__coaia_fuse_trace_create({ "trace_id": "story-trace-001", "name": "Creative Writing Session" }) # Add comment to trace await mcp__coaiapy__coaia_fuse_comments_create({ "text": "Excellent character development in chapter 3", "object_type": "trace", "object_id": "story-trace-001", "author_user_id": "editor-jane" }) # List all comments for the trace comments = await mcp__coaiapy__coaia_fuse_comments_list({ "object_type": "trace", "object_id": "story-trace-001" }) ``` -------------------------------- ### Cross-Repository Tracking Example Source: https://llms.jgwill.com/llms-rise-framework.txt Demonstrates how to track code changes across different repositories. It involves checking the git log in the source code repository and comparing timestamps of files in the rispec repository. ```bash # In source repo cd /path/to/source-code git log --since="2025-12-15" # In rispec repo cd /path/to/rispecs-repo ls -ltra ./rispecs/ # Compare timestamps across repos ``` -------------------------------- ### Python: Configure Model Context Protocol (MCP) Integration Source: https://llms.jgwill.com/llms-claude-agent-sdk-v2 Provides an example of configuring the Claude Agent SDK to integrate with external tools and services using the Model Context Protocol (MCP). It shows how to define MCP servers and specify allowed tools for agent interaction. ```python options = ClaudeAgentOptions( mcp_servers={ "my_database": { "type": "stdio", "command": "python", "args": ["/path/to/database_mcp.py"] } }, allowed_tools=["custom_db_query", "custom_db_write"] ) ``` -------------------------------- ### Configure Agent Options with Plugins (Python) Source: https://llms.jgwill.com/llms-claude-agent-sdk-v2 Shows how to configure `ClaudeAgentOptions` to utilize plugins, specifically referencing the 'storytelling-agents' plugin. It also demonstrates how to specify agent-specific configurations, such as descriptions and allowed tools, within the options. ```python options = ClaudeAgentOptions( plugins=["jgwill/storytelling-agents"], agents={ "story-architect": { "description": "Create story structure", "tools": ["Read", "Write"] } } ) ``` -------------------------------- ### Example of Correct jq Usage (After ETL) Source: https://llms.jgwill.com/llms-jgwill-miadi-issue-115-github-hooks-issues-subissues This Bash snippet demonstrates the correct usage of jq after the ETL transformation. It accesses the `issue.number` field (which remains the same) and the transformed `subIssues.parentIssue.number` field. ```bash ISSUE_NUMBER=$(echo "$PAYLOAD" | jq -r '.issue.number') # ← Still works, issue is same PARENT=$(echo "$PAYLOAD" | jq -r '.subIssues.parentIssue.number') # ← ETL transformed ``` -------------------------------- ### Loading Settings Sources in Claude Agent SDK (Python) Source: https://llms.jgwill.com/llms-claude-agent-sdk-v2 Shows how to explicitly define which settings sources to load when initializing the Claude SDK client in Python v2. This replaces the old behavior of auto-loading from various filesystem locations. ```python # OLD - Auto-loaded all settings # async with ClaudeSDKClient() as client: # await client.query("Analyze this") # # Would read: ~/.claude/settings.json, CLAUDE.md, custom commands, etc. # NEW - Must specify which sources to load async with ClaudeSDKClient(options=ClaudeAgentOptions( setting_sources=["user", "project", "local"] )) as client: await client.query("Analyze this") # Or load only specific sources async with ClaudeSDKClient(options=ClaudeAgentOptions( setting_sources=["project"] # Only project-level settings )) as client: await client.query("Analyze this") ``` -------------------------------- ### Configure Tool Permissions (Claude Agent SDK) Source: https://llms.jgwill.com/llms-claude-agent-sdk-v2 Demonstrates how to configure tool permissions for an agent using Claude Agent SDK. This allows for fine-grained control over which tools the agent can access, using either an allowlist, blocklist, or both. ```python options = ClaudeAgentOptions( # Explicit tool allowlist allowed_tools=["Read", "Write", "Grep"], # Or use allowlist + blocklist disallowed_tools=["ExecuteRemoteCode"], # Permission strategy: "acceptEdits" or "plan" permission_mode="acceptEdits" ) ``` -------------------------------- ### Install Claude Agent SDK (TypeScript/JavaScript) Source: https://llms.jgwill.com/llms-claude-agent-sdk-v2 Installs the latest version of the Claude Agent SDK for TypeScript/JavaScript using npm. This is the current package name, replacing the deprecated '@anthropic-ai/claude-code'. ```bash npm install @anthropic-ai/claude-agent-sdk ``` -------------------------------- ### System Configuration CLI Command Source: https://llms.jgwill.com/llms-coaiapy-cli-guide The 'init' command is used to initialize the creative ecosystem. It sets up the foundational configuration required for creative workflows and prepares the environment for intelligent automation. This is a crucial first step for utilizing the system. ```bash # Example usage for init (conceptual) coaia init --config-file setup.yaml ``` -------------------------------- ### Install Claude Agent SDK (Python) Source: https://llms.jgwill.com/llms-claude-agent-sdk-v2 Installs the latest version of the Claude Agent SDK for Python using pip. This is the current package name, replacing the deprecated 'claude-code-sdk'. ```bash pip install claude-agent-sdk ``` -------------------------------- ### GET /api/hooks/list Source: https://llms.jgwill.com/llms-jgwill-miadi-issue-115-github-hooks-issues-subissues Retrieves a list of all installed GitHub hooks and information about the hooks directory. ```APIDOC ## GET /api/hooks/list ### Description Retrieves a list of all installed GitHub hooks and information about the hooks directory. This endpoint is useful for understanding which event types are configured to trigger specific hook logic. ### Method GET ### Endpoint /api/hooks/list ### Response #### Success Response (200) - **hooksDirectory** (string) - The file system path to the directory where custom hooks are stored. - **installedHooks** (array) - A list of strings, where each string represents an event type for which a hook is installed. - **count** (integer) - The total number of installed hooks. - **description** (string) - A brief explanation of what hooks are and their purpose. #### Response Example ```json { "hooksDirectory": "/a/src/Miadi-18/.github-hooks", "installedHooks": ["push", "issues", "issue_comment", "sub_issues"], "count": 4, "description": "Hooks are executed when matching GitHub webhook events are received" } ``` ``` -------------------------------- ### Using Context Managers for Resource Management in Python Source: https://llms.jgwill.com/llms-claude-sdk.gemini Demonstrates the idiomatic use of context managers (`async with`) in the Python SDK for proper resource management and session handling with `ClaudeSDKClient`. This ensures that resources are correctly initialized and cleaned up. ```python import asyncio from anthropic import Anthropic async def main(): # Use 'async with' for proper resource management async with Anthropic() as client: try: message = await client.messages.create( model="claude-3-opus-20240229", max_tokens=100, messages=[ {"role": "user", "content": "Hello!"} ] ) print(message) except Exception as e: print(f"An error occurred: {e}") if __name__ == "__main__": asyncio.run(main()) ``` -------------------------------- ### Hooks List API Endpoint Source: https://llms.jgwill.com/llms-jgwill-miadi-issue-115-github-hooks-issues-subissues This defines the GET endpoint for retrieving a list of installed hooks. The response includes the directory where hooks are located, a list of hook event types, and a count of the installed hooks, along with a description of their purpose. ```http GET /api/hooks/list **Response**: ```json { "hooksDirectory": "/a/src/Miadi-18/.github-hooks", "installedHooks": ["push", "issues", "issue_comment", "sub_issues"], "count": 4, "description": "Hooks are executed when matching GitHub webhook events are received" } ``` ``` -------------------------------- ### Restrict Agent Tools Based on Permissions (Python) Source: https://llms.jgwill.com/llms-claude-agent-sdk-v2 Demonstrates how to restrict the tools available to agents based on their required permission levels. It provides examples for a read-only agent with limited tools and a creation agent with broader execution capabilities, using `allowed_tools` and `permission_mode`. ```python # Different permission levels for different agents read_only_agent = ClaudeAgentOptions( allowed_tools=["Read", "Grep"], permission_mode="plan" # Only propose, don't execute ) creation_agent = ClaudeAgentOptions( allowed_tools=["Read", "Write", "Execute"], permission_mode="acceptEdits" # Execute immediately ) ``` -------------------------------- ### Testing Narrative Remixing Understanding with LLM Prompts Source: https://llms.jgwill.com/llms-narrative-remixing.txt These bash commands demonstrate how to use an LLM to test various aspects of narrative remixing and contextual transposition. They cover analyzing domain adaptation, identifying transformations, assessing emotional architecture, planning story adaptations, and mapping character archetypes. ```bash # Test contextual transposition analysis llm prompt -m [model] "Apply the three-layer contextual transposition model to analyze how [source story] could be adapted for [target domain]" # Test harmonic relationship mapping llm prompt -m [model] "Identify Parallel, Leading-Tone Exchange, and Relative transformations needed to adapt [character/object/theme] from [source context] to [target context]" # Test story analysis capability llm prompt -m [model] "Analyze the emotional architecture of [story] and identify elements that could be preserved during domain transformation" # Test transformation planning llm prompt -m [model] "Create a transformation plan to adapt [original story] for [target domain] while preserving character dynamics and learning progression" # Test character archetype mapping llm prompt -m [model] "Map the character archetypes in [source narrative] to equivalent roles in [target domain] while preserving relationship dynamics" ``` -------------------------------- ### Pipeline CLI for Template Management Source: https://llms.jgwill.com/llms-coaiapy-cli-guide This section outlines the command-line interface (CLI) for the 'pipeline' system, which is used for managing workflow templates. It covers commands for listing, inspecting, creating, and initializing templates, demonstrating how users can interact with the template engine. ```shell # Explore available templates with descriptions pipeline list # Inspect template structure and variables pipeline show