shotgun-sh 0.1.0.dev22__py3-none-any.whl → 0.1.0.dev23__py3-none-any.whl

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.

Potentially problematic release.


This version of shotgun-sh might be problematic. Click here for more details.

Files changed (51) hide show
  1. shotgun/agents/agent_manager.py +95 -15
  2. shotgun/agents/common.py +139 -24
  3. shotgun/agents/conversation_history.py +56 -0
  4. shotgun/agents/conversation_manager.py +105 -0
  5. shotgun/agents/export.py +5 -2
  6. shotgun/agents/models.py +16 -7
  7. shotgun/agents/plan.py +2 -1
  8. shotgun/agents/research.py +2 -1
  9. shotgun/agents/specify.py +2 -1
  10. shotgun/agents/tasks.py +5 -2
  11. shotgun/agents/tools/file_management.py +67 -2
  12. shotgun/main.py +9 -1
  13. shotgun/prompts/agents/export.j2 +14 -11
  14. shotgun/prompts/agents/partials/common_agent_system_prompt.j2 +6 -9
  15. shotgun/prompts/agents/plan.j2 +9 -13
  16. shotgun/prompts/agents/research.j2 +11 -14
  17. shotgun/prompts/agents/specify.j2 +9 -12
  18. shotgun/prompts/agents/state/system_state.j2 +27 -5
  19. shotgun/prompts/agents/tasks.j2 +12 -12
  20. shotgun/sdk/services.py +0 -14
  21. shotgun/tui/app.py +9 -4
  22. shotgun/tui/screens/chat.py +57 -8
  23. shotgun/tui/screens/chat_screen/command_providers.py +1 -1
  24. shotgun/tui/screens/chat_screen/history.py +6 -0
  25. shotgun/tui/utils/mode_progress.py +111 -78
  26. {shotgun_sh-0.1.0.dev22.dist-info → shotgun_sh-0.1.0.dev23.dist-info}/METADATA +8 -9
  27. {shotgun_sh-0.1.0.dev22.dist-info → shotgun_sh-0.1.0.dev23.dist-info}/RECORD +30 -49
  28. shotgun/agents/artifact_state.py +0 -58
  29. shotgun/agents/tools/artifact_management.py +0 -481
  30. shotgun/artifacts/__init__.py +0 -17
  31. shotgun/artifacts/exceptions.py +0 -89
  32. shotgun/artifacts/manager.py +0 -530
  33. shotgun/artifacts/models.py +0 -334
  34. shotgun/artifacts/service.py +0 -463
  35. shotgun/artifacts/templates/__init__.py +0 -10
  36. shotgun/artifacts/templates/loader.py +0 -252
  37. shotgun/artifacts/templates/models.py +0 -136
  38. shotgun/artifacts/templates/plan/delivery_and_release_plan.yaml +0 -66
  39. shotgun/artifacts/templates/research/market_research.yaml +0 -585
  40. shotgun/artifacts/templates/research/sdk_comparison.yaml +0 -257
  41. shotgun/artifacts/templates/specify/prd.yaml +0 -331
  42. shotgun/artifacts/templates/specify/product_spec.yaml +0 -301
  43. shotgun/artifacts/utils.py +0 -76
  44. shotgun/prompts/agents/partials/artifact_system.j2 +0 -32
  45. shotgun/prompts/agents/state/artifact_templates_available.j2 +0 -20
  46. shotgun/prompts/agents/state/existing_artifacts_available.j2 +0 -25
  47. shotgun/sdk/artifact_models.py +0 -186
  48. shotgun/sdk/artifacts.py +0 -448
  49. {shotgun_sh-0.1.0.dev22.dist-info → shotgun_sh-0.1.0.dev23.dist-info}/WHEEL +0 -0
  50. {shotgun_sh-0.1.0.dev22.dist-info → shotgun_sh-0.1.0.dev23.dist-info}/entry_points.txt +0 -0
  51. {shotgun_sh-0.1.0.dev22.dist-info → shotgun_sh-0.1.0.dev23.dist-info}/licenses/LICENSE +0 -0
@@ -8,12 +8,76 @@ from typing import Literal
8
8
 
9
9
  from pydantic_ai import RunContext
10
10
 
11
- from shotgun.agents.models import AgentDeps, FileOperationType
11
+ from shotgun.agents.models import AgentDeps, AgentType, FileOperationType
12
12
  from shotgun.logging_config import get_logger
13
13
  from shotgun.utils.file_system_utils import get_shotgun_base_path
14
14
 
15
15
  logger = get_logger(__name__)
16
16
 
17
+ # Map agent modes to their allowed directories/files (in workflow order)
18
+ AGENT_DIRECTORIES = {
19
+ AgentType.RESEARCH: "research.md",
20
+ AgentType.SPECIFY: "specification.md",
21
+ AgentType.PLAN: "plan.md",
22
+ AgentType.TASKS: "tasks.md",
23
+ AgentType.EXPORT: "exports/",
24
+ }
25
+
26
+
27
+ def _validate_agent_scoped_path(filename: str, agent_mode: AgentType | None) -> Path:
28
+ """Validate and resolve a file path within the agent's scoped directory.
29
+
30
+ Args:
31
+ filename: Relative filename
32
+ agent_mode: The current agent mode
33
+
34
+ Returns:
35
+ Absolute path to the file within the agent's scoped directory
36
+
37
+ Raises:
38
+ ValueError: If the path attempts to access files outside the agent's scope
39
+ """
40
+ base_path = get_shotgun_base_path()
41
+
42
+ if agent_mode and agent_mode in AGENT_DIRECTORIES:
43
+ # For export mode, allow writing to any file in exports/ directory
44
+ if agent_mode == AgentType.EXPORT:
45
+ # Ensure the filename starts with exports/ or is being written to exports/
46
+ if not filename.startswith("exports/"):
47
+ filename = f"exports/{filename}"
48
+ full_path = (base_path / filename).resolve()
49
+
50
+ # Ensure it's within .shotgun/exports/
51
+ exports_dir = base_path / "exports"
52
+ try:
53
+ full_path.relative_to(exports_dir.resolve())
54
+ except ValueError as e:
55
+ raise ValueError(
56
+ f"Export agent can only write to exports/ directory. Path '{filename}' is not allowed"
57
+ ) from e
58
+ else:
59
+ # For other agents, only allow writing to their specific file
60
+ allowed_file = AGENT_DIRECTORIES[agent_mode]
61
+ if filename != allowed_file:
62
+ raise ValueError(
63
+ f"{agent_mode.value.capitalize()} agent can only write to '{allowed_file}'. "
64
+ f"Attempted to write to '{filename}'"
65
+ )
66
+ full_path = (base_path / filename).resolve()
67
+ else:
68
+ # No agent mode specified, fall back to old validation
69
+ full_path = (base_path / filename).resolve()
70
+
71
+ # Ensure the resolved path is within the .shotgun directory
72
+ try:
73
+ full_path.relative_to(base_path.resolve())
74
+ except ValueError as e:
75
+ raise ValueError(
76
+ f"Access denied: Path '{filename}' is outside .shotgun directory"
77
+ ) from e
78
+
79
+ return full_path
80
+
17
81
 
18
82
  def _validate_shotgun_path(filename: str) -> Path:
19
83
  """Validate and resolve a file path within the .shotgun directory.
@@ -99,7 +163,8 @@ async def write_file(
99
163
  raise ValueError(f"Invalid mode '{mode}'. Use 'w' for write or 'a' for append")
100
164
 
101
165
  try:
102
- file_path = _validate_shotgun_path(filename)
166
+ # Use agent-scoped validation for write operations
167
+ file_path = _validate_agent_scoped_path(filename, ctx.deps.agent_mode)
103
168
 
104
169
  # Determine operation type
105
170
  if mode == "a":
shotgun/main.py CHANGED
@@ -100,6 +100,14 @@ def main(
100
100
  help="Disable automatic update checks",
101
101
  ),
102
102
  ] = False,
103
+ continue_session: Annotated[
104
+ bool,
105
+ typer.Option(
106
+ "--continue",
107
+ "-c",
108
+ help="Continue previous TUI conversation",
109
+ ),
110
+ ] = False,
103
111
  ) -> None:
104
112
  """Shotgun - AI-powered CLI tool."""
105
113
  logger.debug("Starting shotgun CLI application")
@@ -112,7 +120,7 @@ def main(
112
120
 
113
121
  if ctx.invoked_subcommand is None and not ctx.resilient_parsing:
114
122
  logger.debug("Launching shotgun TUI application")
115
- tui_app.run(no_update_check=no_update_check)
123
+ tui_app.run(no_update_check=no_update_check, continue_session=continue_session)
116
124
 
117
125
  # Show update notification after TUI exits
118
126
  if _update_notification:
@@ -1,31 +1,32 @@
1
1
  You are an experienced Export Specialist and Data Transformation Expert.
2
2
 
3
- Your job is to help export artifacts, research findings, plans, and other project data to various formats and destinations.
3
+ Your job is to help export project documentation and findings to various formats and destinations in the exports/ folder.
4
4
 
5
5
  {% include 'agents/partials/common_agent_system_prompt.j2' %}
6
6
 
7
7
  ## EXPORT WORKFLOW
8
8
 
9
9
  For export tasks:
10
- 1. **Check existing artifacts**: See the "## Existing Artifacts" section to see what content is available to export.
11
- 2. **Understand the export requirements**: Understand what the user wants to export, assuming that's everything - but always confirm. For example some research might not be relevant for export. Priority: Tasks, Plan, Specify, Research.
10
+ 1. **Check existing files**: Read `research.md`, `plan.md`, `tasks.md`, and `specification.md` to see what content is available
11
+ 2. **Understand the export requirements**: Understand what the user wants to export, assuming that's everything - but always confirm. Priority: Tasks, Plan, Specify, Research.
12
12
  3. **Analyze export requirements**: Understand the requested format, destination, and scope
13
- 4. **Read source content**: Read the content of all the relevant artifacts.
13
+ 4. **Read source content**: Read the content of all the relevant files
14
14
  5. **Transform and format**: Convert content to the requested format
15
- 5. **Create export artifacts**: Use write_file with BOTH "filename" AND "content" parameters:
16
- 6. **Validate output**: Ensure the export meets requirements and is properly formatted using read_file()
15
+ 6. **Create export files**: Use write_file with path like "exports/filename.ext" to save in exports folder
16
+ 7. **Validate output**: Ensure the export meets requirements and is properly formatted using read_file()
17
17
 
18
18
  ## SUPPORTED EXPORT FORMATS
19
19
 
20
20
  - **AGENTS.md**: See below
21
21
  - **Markdown (.md)**: Nicely formatted Markdown file with everything the user wants to export
22
+ - **Multiple files**: Can create multiple export files in the exports/ folder as needed
22
23
 
23
24
  ### AGENTS.md
24
25
 
25
26
  Your task: generate an **AGENTS.md** file (in Markdown) for a project based on the provided documentation, specification files, and any context I supply.
26
27
 
27
28
  **Instructions / constraints**:
28
- - Use clear headings (e.g. Architecture & Structure”, Setup / Prerequisites”, Build & Test”, Coding Conventions”, etc.).
29
+ - Use clear headings (e.g. "Architecture & Structure", "Setup / Prerequisites", "Build & Test", "Coding Conventions", etc.).
29
30
  - For sections with commands, wrap them in backticks so they can be executed directly.
30
31
  - Provide enough detail so that an AI coding agent can understand how to build, test, validate, deploy, and work with the project, without needing to hunt in scattered docs.
31
32
  - Link or refer to deeper docs (README, design docs) rather than duplicating large content.
@@ -45,6 +46,7 @@ Your task: generate an **AGENTS.md** file (in Markdown) for a project based on t
45
46
  - Validate exported content is properly formatted and complete
46
47
  - Handle missing or incomplete source data gracefully
47
48
  - Consider target audience and use case for formatting decisions
49
+ - Always save exports in the exports/ folder
48
50
 
49
51
  {% if interactive_mode %}
50
52
  USER INTERACTION - CLARIFY EXPORT REQUIREMENTS:
@@ -53,9 +55,9 @@ USER INTERACTION - CLARIFY EXPORT REQUIREMENTS:
53
55
  - Use ask_user tool to gather specific details about:
54
56
  - Target format and file type preferences
55
57
  - Intended use case and audience for the export
56
- - Specific content sections or artifacts to include/exclude
58
+ - Specific content sections to include/exclude from files
57
59
  - Output structure and organization preferences
58
- - Destination (where to save the file)
60
+ - Destination filename(s) in the exports/ folder
59
61
  - Ask follow-up questions to ensure exports meet exact needs
60
62
  - Confirm export scope and format before proceeding with large exports
61
63
  - Better to ask 2-3 targeted questions than create generic exports
@@ -71,13 +73,14 @@ NON-INTERACTIVE MODE - MAKE REASONABLE EXPORT DECISIONS:
71
73
  {% endif %}
72
74
 
73
75
  IMPORTANT RULES:
74
- - Always verify source content exists before attempting export
76
+ - Always verify source files exist before attempting export
75
77
  - Preserve all critical information during format conversion
76
78
  - Include source attribution and export metadata
77
79
  - Create well-structured, properly formatted output
80
+ - Always save exports in the exports/ folder (create if needed)
78
81
  {% if interactive_mode %}
79
82
  - When export requirements are ambiguous, ASK before proceeding
80
83
  {% else %}
81
84
  - When requirements are unclear, use industry standard practices
82
85
  {% endif %}
83
- - Ensure exported content is self-contained and usable
86
+ - Ensure exported content is self-contained and usable
@@ -1,4 +1,3 @@
1
-
2
1
  Your extensive expertise spans, among other things:
3
2
  * Business Analysis
4
3
  * Product Management
@@ -8,16 +7,16 @@ Your extensive expertise spans, among other things:
8
7
  ## KEY RULES
9
8
 
10
9
  {% if interactive_mode %}
11
- 0. Always ask for the review and go ahead to move forward after using write_artifact_section().
10
+ 0. Always ask for review and go ahead to move forward after writing files.
12
11
  {% endif %}
13
12
  1. Above all, prefer using tools to do the work and NEVER respond with text.
14
- 2. IMPORTANT: Always ask for the review and go ahead to move forward after using write_artifact_section().
15
- 3. **Be Detailed**: Write meticulously detailed documents in artifacts, but when communicating with the users, please respond with a paragraph at most.
13
+ 2. IMPORTANT: Always ask for review and go ahead to move forward after using write_file().
14
+ 3. **Be Detailed**: Write meticulously detailed documents in files, but when communicating with users, please respond with a paragraph at most.
16
15
  4. **Be Helpful**: Always prioritize user needs and provide actionable assistance
17
16
  5. **Be Precise**: Provide specific, detailed responses rather than vague generalities
18
17
  6. **Be Collaborative**: Work effectively with other agents when needed
19
18
  7. **Be Transparent**: Let the user know what you're going to do before getting to work.
20
- 8. **Be Efficient**: Avoid redundant work - check existing artifacts and agent outputs
19
+ 8. **Be Efficient**: Avoid redundant work - check existing files and agent outputs
21
20
  9. **Be Creative**: If the user seems not to know something, always be creative and come up with ideas that fit their thinking.
22
21
  10. Greet the user when you're just starting to work.
23
22
  11. DO NOT repeat yourself.
@@ -29,12 +28,10 @@ Your extensive expertise spans, among other things:
29
28
  - Provide complete, actionable outputs rather than partial solutions
30
29
  - Consider user experience and business context in recommendations
31
30
  - Maintain consistency with existing project patterns and conventions
32
- - Always then informing the user of the result of your work, suggest best next steps so it's easy for the user to continue.
33
-
34
- {% include 'agents/partials/artifact_system.j2' %}
31
+ - Always when informing the user of the result of your work, suggest best next steps so it's easy for the user to continue.
35
32
 
36
33
  {% include 'agents/partials/codebase_understanding.j2' %}
37
34
 
38
35
  {% include 'agents/partials/content_formatting.j2' %}
39
36
 
40
- {% include 'agents/partials/interactive_mode.j2' %}
37
+ {% include 'agents/partials/interactive_mode.j2' %}
@@ -1,22 +1,17 @@
1
1
  You are an experienced Project Manager and Strategic Planner.
2
2
 
3
- Your job is to help create comprehensive, actionable plans for software projects.
3
+ Your job is to help create comprehensive, actionable plans for software projects and maintain the plan.md file.
4
4
 
5
5
  {% include 'agents/partials/common_agent_system_prompt.j2' %}
6
6
 
7
7
  ## PLANNING WORKFLOW
8
8
 
9
9
  For PLANNING tasks:
10
- 0. **Check specify**, if any - Consider Existing Artifacts available in specify mode.
11
- 1. **Check existing work**: Consider Existing Artifacts available in plan mode already.
12
- IF NO SUITABLE ARTIFACT ALREADY EXISTS:
13
- 2. **Look for suitable artifact template**: Consider Available Artifact Templates available in plan mode.
14
- 3. **Create new artifact**: Use `create_artifact()` to create a new artifact with the appropriate template or without if you can't find any relevant enough.
15
- 4. **Analyze requirements**: Consider Existing Artifacts available in specify and research modes already.
16
- 5. **Define specifications**: Create detailed technical and functional plans
17
- 6. **Structure documentation**: Use `write_artifact_section()` to organize plans
18
-
19
- Use meaningful artifact IDs like: "mvp-roadmap", "migration-strategy", "product-launch"
10
+ 1. **Load existing plan**: ALWAYS first use `read_file("plan.md")` to see what plans already exist (if the file exists)
11
+ 2. **Check related files**: Read `specification.md` and `research.md` if they exist to understand context
12
+ 3. **Analyze requirements**: Understand project goals and constraints from available documentation
13
+ 4. **Define specifications**: Create detailed technical and functional plans
14
+ 5. **Structure documentation**: Use `write_file("plan.md", content)` to save the comprehensive plan
20
15
 
21
16
  ## PLANNING PRINCIPLES
22
17
 
@@ -27,6 +22,8 @@ Use meaningful artifact IDs like: "mvp-roadmap", "migration-strategy", "product-
27
22
  - Include resource requirements and success criteria
28
23
  - Focus on actionable, specific steps rather than vague suggestions
29
24
  - Consider feasibility and prioritize high-impact actions
25
+ - Keep plan.md as the single source of truth
26
+ - Organize plans by phases, milestones, or components
30
27
 
31
28
  IMPORTANT RULES:
32
29
  - Make at most 1 plan file write per request
@@ -51,5 +48,4 @@ NON-INTERACTIVE MODE - MAKE REASONABLE ASSUMPTIONS:
51
48
  - Focus on creating a practical, actionable plan
52
49
  - Include common project phases and considerations
53
50
  - Assume standard timelines and resource allocations
54
- {% endif %}
55
-
51
+ {% endif %}
@@ -1,24 +1,19 @@
1
1
  You are an experienced Research Assistant.
2
2
 
3
- Your job is to help the user research various subjects related to their software project.
3
+ Your job is to help the user research various subjects related to their software project and keep the research.md file up to date.
4
4
 
5
5
  {% include 'agents/partials/common_agent_system_prompt.j2' %}
6
6
 
7
7
  ## RESEARCH WORKFLOW
8
8
 
9
9
  For research tasks:
10
- 1. **Check existing work**: Consider "Existing Artifacts" available in research mode already.
11
- IF NO SUITABLE ARTIFACT ALREADY EXISTS:
12
- 2. **Look for suitable artifact template**: Consider "Available Artifact Templates" available in research mode.
13
- 3. **Create new artifact**: Use `create_artifact()` to create a new artifact with the appropriate template or without if you can't find any relevant enough.
14
- 4. **Analyze previous work**: Consider "Existing Artifacts" available in research mode already.
15
- 5. **Identify gaps**: Determine what additional research is needed
16
- 6. DO NOT ASSUME YOU KNOW THE ANSWER TO THE QUERY. ALWAYS START WITH GENERIC SEARCHES FIRST, NOT USING NAMES OF THINGS SUGGESTIVE OF THE ANSWER.
17
- 7. **Search strategically**: Use web search to fill knowledge gaps (max 3 searches per session)
18
- 8. **Synthesize findings**: Combine existing and new information
19
- 9. **Create structured artifacts**: Use `write_artifact_section()` to organize findings
20
-
21
- Use meaningful artifact IDs like: "api-design-patterns", "microservices-study", "database-comparison"
10
+ 1. **Load previous research**: ALWAYS first use `read_file("research.md")` to see what research already exists (if the file exists)
11
+ 2. **Analyze existing work**: Understand what has been researched previously
12
+ 3. **Identify gaps**: Determine what additional research is needed
13
+ 4. DO NOT ASSUME YOU KNOW THE ANSWER TO THE QUERY. ALWAYS START WITH GENERIC SEARCHES FIRST, NOT USING NAMES OF THINGS SUGGESTIVE OF THE ANSWER.
14
+ 5. **Search strategically**: Use web search to fill knowledge gaps (max 3 searches per session)
15
+ 6. **Synthesize findings**: Combine existing and new information
16
+ 7. **Update research.md**: Use `write_file("research.md", content)` to save comprehensive, organized research
22
17
 
23
18
  ## RESEARCH PRINCIPLES
24
19
 
@@ -31,11 +26,13 @@ Use meaningful artifact IDs like: "api-design-patterns", "microservices-study",
31
26
  - Validate information from multiple sources
32
27
  - Document assumptions and limitations
33
28
  - Avoid analysis paralysis - be decisive with available information
34
- - Multi-Source Research - Cross-reference multiple sources for accuracy and completeness
29
+ - Multi-Source Research - Cross-reference multiple sources for accuracy and completeness
35
30
  - Critical Analysis - Evaluate trade-offs, limitations, and real-world applicability
36
31
  - Actionable Insights - Provide concrete recommendations and next steps when you're done
37
32
  - Comprehensive Citations - Include detailed source citations for verification
38
33
  - AVOID combining multiple topics into single search query. In fact, try similar queries across different providers/tools.
34
+ - Keep research.md as the single source of truth
35
+ - Organize findings by topic/category for easy reference
39
36
 
40
37
  ## Response Standards
41
38
  Your responses should always be:
@@ -1,6 +1,6 @@
1
1
  You are an experienced Specification Analyst.
2
2
 
3
- Your job is to help the user create comprehensive software specifications for their projects.
3
+ Your job is to help the user create comprehensive software specifications for their projects and maintain the specification.md file.
4
4
 
5
5
  Transform requirements into detailed, actionable specifications that development teams can implement.
6
6
 
@@ -9,16 +9,11 @@ Transform requirements into detailed, actionable specifications that development
9
9
  ## SPECIFICATION WORKFLOW
10
10
 
11
11
  For specification tasks:
12
- 0. **Check research**, if any - Consider Existing Artifacts available in research mode already.
13
- 1. **Check existing work**: Consider Existing Artifacts available in specify mode already.
14
- IF NO SUITABLE ARTIFACT ALREADY EXISTS:
15
- 2. **Look for suitable artifact template**: Consider Available Artifact Templates available in specify mode.
16
- 3. **Create new artifact**: Use `create_artifact()` to create a new artifact with the appropriate template or without if you can't find any relevant enough.
17
- 4. **Analyze requirements**: Understand the functional and non-functional requirements
18
- 5. **Define specifications**: Create detailed technical and functional specifications
19
- 6. **Structure documentation**: Use `write_artifact_section()` to organize specifications
20
-
21
- Use meaningful artifact IDs like: "user-auth-spec", "api-gateway-spec", "data-model-spec"
12
+ 1. **Load existing specifications**: ALWAYS first use `read_file("specification.md")` to see what specifications already exist (if the file exists)
13
+ 2. **Check research**: Read `research.md` if it exists to understand technical context and findings
14
+ 3. **Analyze requirements**: Understand the functional and non-functional requirements
15
+ 4. **Define specifications**: Create detailed technical and functional specifications
16
+ 5. **Structure documentation**: Use `write_file("specification.md", content)` to save comprehensive specifications
22
17
 
23
18
  ## SPECIFICATION PRINCIPLES
24
19
 
@@ -28,4 +23,6 @@ Use meaningful artifact IDs like: "user-auth-spec", "api-gateway-spec", "data-mo
28
23
  - **Traceability**: Link specifications back to original requirements and business needs
29
24
  - **Testability**: Define clear acceptance criteria and testing approaches
30
25
  - **Maintainability**: Structure specifications for easy updates and modifications
31
- - **Stakeholder Focus**: Consider different audiences (developers, testers, business users)
26
+ - **Stakeholder Focus**: Consider different audiences (developers, testers, business users)
27
+ - Keep specification.md as the single source of truth
28
+ - Organize specifications by features, components, or user stories
@@ -1,9 +1,31 @@
1
- {% if current_date %}
2
1
  ## System Status
3
2
 
4
- Today's date: {{ current_date }}
3
+ {% include 'agents/state/codebase/codebase_graphs_available.j2' %}
4
+
5
+ ## Available Files
5
6
 
7
+ {% if existing_files %}
8
+ The following files already exist in the .shotgun/ directory.
9
+ Before doing a web search check the information information in these files before continuing.
10
+ Your working files are:
11
+ {% for file in existing_files %}
12
+ - `{{ file }}`
13
+ {% endfor %}
14
+ {% else %}
15
+ No files currently exist in your allowed directories. You can create:
16
+ - `research.md` - Research findings and analysis
17
+ - `plan.md` - Project plans and roadmaps
18
+ - `tasks.md` - Task lists and management
19
+ - `specification.md` - Technical specifications
20
+ - `exports/` folder - For exported documents
6
21
  {% endif %}
7
- {% include 'agents/state/codebase/codebase_graphs_available.j2' %}
8
- {% include 'agents/state/existing_artifacts_available.j2' %}
9
- {% include 'agents/state/artifact_templates_available.j2' %}
22
+
23
+ {% if markdown_toc %}
24
+ ## Document Structure
25
+
26
+ The current document contains the following sections:
27
+ ```
28
+ {{ markdown_toc }}
29
+ ```
30
+ Review these existing sections before adding new content to avoid duplication.
31
+ {% endif %}
@@ -1,27 +1,25 @@
1
1
  You are an experienced Project Manager and Task Coordinator.
2
2
 
3
- Your job is to help create and manage actionable tasks for software projects.
3
+ Your job is to help create and manage actionable tasks for software projects and maintain the tasks.md file.
4
4
 
5
5
  {% include 'agents/partials/common_agent_system_prompt.j2' %}
6
6
 
7
7
  ## TASK MANAGEMENT WORKFLOW
8
8
 
9
9
  For task management:
10
- 1. **Check existing work**: Use `list_artifacts("tasks")` to see what tasks already exist
11
- 2. **Review context**: Use `list_artifacts("plan")` and `list_artifacts("specify")` to understand project context
10
+ 1. **Load existing tasks**: ALWAYS first use `read_file("tasks.md")` to see what tasks already exist (if the file exists)
11
+ 2. **Review context**: Read `plan.md` and `specification.md` if they exist to understand project context
12
12
  3. **Analyze requirements**: Understand the current situation and user's task requirements
13
- 4. **Create structured tasks**: Use `write_artifact_section()` to organize task output
13
+ 4. **Create structured tasks**: Use `write_file("tasks.md", content)` to save organized tasks
14
14
  5. **Build incrementally**: Update and refine tasks based on new information
15
15
 
16
- ## TASK ARTIFACT STRUCTURE
16
+ ## TASK FILE STRUCTURE
17
17
 
18
- Organize tasks into logical sections:
19
- - **Section 1: Backlog** - Prioritized list of tasks to be done
20
- - **Section 2: In Progress** - Current active tasks and status
21
- - **Section 3: Done** - Completed tasks for reference
22
- - **Section 4: Blocked** - Tasks waiting on dependencies or decisions
23
-
24
- Use meaningful artifact IDs like: "feature-development", "migration-tasks", "testing-checklist"
18
+ Organize tasks into logical sections in tasks.md:
19
+ - **Backlog** - Prioritized list of tasks to be done
20
+ - **In Progress** - Current active tasks and status
21
+ - **Done** - Completed tasks for reference
22
+ - **Blocked** - Tasks waiting on dependencies or decisions
25
23
 
26
24
  ## TASK CREATION PRINCIPLES
27
25
 
@@ -33,6 +31,8 @@ Use meaningful artifact IDs like: "feature-development", "migration-tasks", "tes
33
31
  - Align with goals and steps from project plans
34
32
  - Include both development and testing/validation tasks
35
33
  - Break down complex work into manageable chunks
34
+ - Keep tasks.md as the single source of truth
35
+ - Use clear task IDs or numbers for tracking
36
36
 
37
37
  {% if interactive_mode %}
38
38
  USER INTERACTION - ASK CLARIFYING QUESTIONS:
shotgun/sdk/services.py CHANGED
@@ -2,7 +2,6 @@
2
2
 
3
3
  from pathlib import Path
4
4
 
5
- from shotgun.artifacts.service import ArtifactService
6
5
  from shotgun.codebase.service import CodebaseService
7
6
  from shotgun.utils import get_shotgun_home
8
7
 
@@ -22,16 +21,3 @@ def get_codebase_service(storage_dir: Path | str | None = None) -> CodebaseServi
22
21
  elif isinstance(storage_dir, str):
23
22
  storage_dir = Path(storage_dir)
24
23
  return CodebaseService(storage_dir)
25
-
26
-
27
- def get_artifact_service(base_path: Path | None = None) -> ArtifactService:
28
- """Get ArtifactService instance with configurable base path.
29
-
30
- Args:
31
- base_path: Optional base path for artifacts.
32
- Defaults to .shotgun in current directory.
33
-
34
- Returns:
35
- Configured ArtifactService instance
36
- """
37
- return ArtifactService(base_path)
shotgun/tui/app.py CHANGED
@@ -29,10 +29,13 @@ class ShotgunApp(App[None]):
29
29
  ]
30
30
  CSS_PATH = "styles.tcss"
31
31
 
32
- def __init__(self, no_update_check: bool = False) -> None:
32
+ def __init__(
33
+ self, no_update_check: bool = False, continue_session: bool = False
34
+ ) -> None:
33
35
  super().__init__()
34
36
  self.config_manager: ConfigManager = get_config_manager()
35
37
  self.no_update_check = no_update_check
38
+ self.continue_session = continue_session
36
39
  self.update_notification: str | None = None
37
40
 
38
41
  # Start async update check
@@ -77,7 +80,8 @@ class ShotgunApp(App[None]):
77
80
 
78
81
  if isinstance(self.screen, ChatScreen):
79
82
  return
80
- self.push_screen("chat")
83
+ # Pass continue_session flag to ChatScreen
84
+ self.push_screen(ChatScreen(continue_session=self.continue_session))
81
85
 
82
86
  def check_local_shotgun_directory_exists(self) -> bool:
83
87
  shotgun_dir = get_shotgun_base_path()
@@ -97,13 +101,14 @@ class ShotgunApp(App[None]):
97
101
  return [] # we don't want any system commands
98
102
 
99
103
 
100
- def run(no_update_check: bool = False) -> None:
104
+ def run(no_update_check: bool = False, continue_session: bool = False) -> None:
101
105
  """Run the TUI application.
102
106
 
103
107
  Args:
104
108
  no_update_check: If True, disable automatic update checks.
109
+ continue_session: If True, continue from previous conversation.
105
110
  """
106
- app = ShotgunApp(no_update_check=no_update_check)
111
+ app = ShotgunApp(no_update_check=no_update_check, continue_session=continue_session)
107
112
  app.run(inline_no_clear=True)
108
113
 
109
114
 
@@ -22,13 +22,18 @@ from textual.widgets import Button, DirectoryTree, Input, Label, Markdown, Stati
22
22
 
23
23
  from shotgun.agents.agent_manager import (
24
24
  AgentManager,
25
- AgentType,
26
25
  MessageHistoryUpdated,
27
26
  PartialResponseMessage,
28
27
  )
29
28
  from shotgun.agents.config import get_provider_model
29
+ from shotgun.agents.conversation_history import (
30
+ ConversationHistory,
31
+ ConversationState,
32
+ )
33
+ from shotgun.agents.conversation_manager import ConversationManager
30
34
  from shotgun.agents.models import (
31
35
  AgentDeps,
36
+ AgentType,
32
37
  FileOperationTracker,
33
38
  UserAnswer,
34
39
  UserQuestion,
@@ -36,7 +41,7 @@ from shotgun.agents.models import (
36
41
  from shotgun.codebase.core.manager import CodebaseAlreadyIndexedError
37
42
  from shotgun.sdk.codebase import CodebaseSDK
38
43
  from shotgun.sdk.exceptions import CodebaseNotFoundError, InvalidPathError
39
- from shotgun.sdk.services import get_artifact_service, get_codebase_service
44
+ from shotgun.sdk.services import get_codebase_service
40
45
  from shotgun.tui.commands import CommandHandler
41
46
  from shotgun.tui.screens.chat_screen.history import ChatHistory
42
47
 
@@ -323,12 +328,11 @@ class ChatScreen(Screen[None]):
323
328
  indexing_job: reactive[CodebaseIndexSelection | None] = reactive(None)
324
329
  partial_message: reactive[ModelMessage | None] = reactive(None)
325
330
 
326
- def __init__(self) -> None:
331
+ def __init__(self, continue_session: bool = False) -> None:
327
332
  super().__init__()
328
333
  # Get the model configuration and services
329
334
  model_config = get_provider_model()
330
335
  codebase_service = get_codebase_service()
331
- artifact_service = get_artifact_service()
332
336
  self.codebase_sdk = CodebaseSDK()
333
337
 
334
338
  # Create shared deps without system_prompt_fn (agents provide their own)
@@ -343,17 +347,23 @@ class ChatScreen(Screen[None]):
343
347
  is_tui_context=True,
344
348
  llm_model=model_config,
345
349
  codebase_service=codebase_service,
346
- artifact_service=artifact_service,
347
350
  system_prompt_fn=_placeholder_system_prompt_fn,
348
351
  )
349
352
  self.agent_manager = AgentManager(deps=self.deps, initial_type=self.mode)
350
353
  self.command_handler = CommandHandler()
351
354
  self.placeholder_hints = PlaceholderHints()
355
+ self.conversation_manager = ConversationManager()
356
+ self.continue_session = continue_session
352
357
 
353
358
  def on_mount(self) -> None:
354
359
  self.query_one(PromptInput).focus(scroll_visible=True)
355
360
  # Hide spinner initially
356
361
  self.query_one("#spinner").display = False
362
+
363
+ # Load conversation history if --continue flag was provided
364
+ if self.continue_session and self.conversation_manager.exists():
365
+ self._load_conversation()
366
+
357
367
  self.call_later(self.check_if_codebase_is_indexed)
358
368
  # Start the question listener worker to handle ask_user interactions
359
369
  self.call_later(self.add_question_listener)
@@ -478,6 +488,10 @@ class ChatScreen(Screen[None]):
478
488
  if not chat_history.vertical_tail:
479
489
  return
480
490
  chat_history.vertical_tail.mount(Markdown(markdown))
491
+ # Scroll to bottom after mounting hint
492
+ chat_history.vertical_tail.call_after_refresh(
493
+ chat_history.vertical_tail.scroll_end, animate=False
494
+ )
481
495
 
482
496
  @on(PartialResponseMessage)
483
497
  def handle_partial_response(self, event: PartialResponseMessage) -> None:
@@ -590,9 +604,7 @@ class ChatScreen(Screen[None]):
590
604
  Returns:
591
605
  Dynamic placeholder hint based on mode and progress.
592
606
  """
593
- return self.placeholder_hints.get_placeholder_for_mode(
594
- mode, force_new=force_new
595
- )
607
+ return self.placeholder_hints.get_placeholder_for_mode(mode)
596
608
 
597
609
  def index_codebase_command(self) -> None:
598
610
  start_path = Path.cwd()
@@ -690,9 +702,46 @@ class ChatScreen(Screen[None]):
690
702
  )
691
703
  self.working = False
692
704
 
705
+ # Save conversation after each interaction
706
+ self._save_conversation()
707
+
693
708
  prompt_input = self.query_one(PromptInput)
694
709
  prompt_input.focus()
695
710
 
711
+ def _save_conversation(self) -> None:
712
+ """Save the current conversation to persistent storage."""
713
+ # Get conversation state from agent manager
714
+ state = self.agent_manager.get_conversation_state()
715
+
716
+ # Create conversation history object
717
+ conversation = ConversationHistory(
718
+ last_agent_model=state.agent_type,
719
+ )
720
+ conversation.set_agent_messages(state.agent_messages)
721
+
722
+ # Save to file
723
+ self.conversation_manager.save(conversation)
724
+
725
+ def _load_conversation(self) -> None:
726
+ """Load conversation from persistent storage."""
727
+ conversation = self.conversation_manager.load()
728
+ if conversation is None:
729
+ return
730
+
731
+ # Restore agent state
732
+ agent_messages = conversation.get_agent_messages()
733
+
734
+ # Create ConversationState for restoration
735
+ state = ConversationState(
736
+ agent_messages=agent_messages,
737
+ agent_type=conversation.last_agent_model,
738
+ )
739
+
740
+ self.agent_manager.restore_conversation_state(state)
741
+
742
+ # Update the current mode
743
+ self.mode = AgentType(conversation.last_agent_model)
744
+
696
745
 
697
746
  def codebase_indexed_hint(codebase_name: str) -> str:
698
747
  return (