mcp-ticketer 0.4.11__py3-none-any.whl → 2.0.1__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 mcp-ticketer might be problematic. Click here for more details.
- mcp_ticketer/__init__.py +10 -10
- mcp_ticketer/__version__.py +3 -3
- mcp_ticketer/adapters/__init__.py +2 -0
- mcp_ticketer/adapters/aitrackdown.py +394 -9
- mcp_ticketer/adapters/asana/__init__.py +15 -0
- mcp_ticketer/adapters/asana/adapter.py +1416 -0
- mcp_ticketer/adapters/asana/client.py +292 -0
- mcp_ticketer/adapters/asana/mappers.py +348 -0
- mcp_ticketer/adapters/asana/types.py +146 -0
- mcp_ticketer/adapters/github.py +836 -105
- mcp_ticketer/adapters/hybrid.py +47 -5
- mcp_ticketer/adapters/jira.py +772 -1
- mcp_ticketer/adapters/linear/adapter.py +2293 -108
- mcp_ticketer/adapters/linear/client.py +146 -12
- mcp_ticketer/adapters/linear/mappers.py +105 -11
- mcp_ticketer/adapters/linear/queries.py +168 -1
- mcp_ticketer/adapters/linear/types.py +80 -4
- mcp_ticketer/analysis/__init__.py +56 -0
- mcp_ticketer/analysis/dependency_graph.py +255 -0
- mcp_ticketer/analysis/health_assessment.py +304 -0
- mcp_ticketer/analysis/orphaned.py +218 -0
- mcp_ticketer/analysis/project_status.py +594 -0
- mcp_ticketer/analysis/similarity.py +224 -0
- mcp_ticketer/analysis/staleness.py +266 -0
- mcp_ticketer/automation/__init__.py +11 -0
- mcp_ticketer/automation/project_updates.py +378 -0
- mcp_ticketer/cache/memory.py +3 -3
- mcp_ticketer/cli/adapter_diagnostics.py +4 -2
- mcp_ticketer/cli/auggie_configure.py +18 -6
- mcp_ticketer/cli/codex_configure.py +175 -60
- mcp_ticketer/cli/configure.py +884 -146
- mcp_ticketer/cli/cursor_configure.py +314 -0
- mcp_ticketer/cli/diagnostics.py +31 -28
- mcp_ticketer/cli/discover.py +293 -21
- mcp_ticketer/cli/gemini_configure.py +18 -6
- mcp_ticketer/cli/init_command.py +880 -0
- mcp_ticketer/cli/instruction_commands.py +435 -0
- mcp_ticketer/cli/linear_commands.py +99 -15
- mcp_ticketer/cli/main.py +109 -2055
- mcp_ticketer/cli/mcp_configure.py +673 -99
- mcp_ticketer/cli/mcp_server_commands.py +415 -0
- mcp_ticketer/cli/migrate_config.py +12 -8
- mcp_ticketer/cli/platform_commands.py +6 -6
- mcp_ticketer/cli/platform_detection.py +477 -0
- mcp_ticketer/cli/platform_installer.py +536 -0
- mcp_ticketer/cli/project_update_commands.py +350 -0
- mcp_ticketer/cli/queue_commands.py +15 -15
- mcp_ticketer/cli/setup_command.py +639 -0
- mcp_ticketer/cli/simple_health.py +13 -11
- mcp_ticketer/cli/ticket_commands.py +277 -36
- mcp_ticketer/cli/update_checker.py +313 -0
- mcp_ticketer/cli/utils.py +45 -41
- mcp_ticketer/core/__init__.py +35 -1
- mcp_ticketer/core/adapter.py +170 -5
- mcp_ticketer/core/config.py +38 -31
- mcp_ticketer/core/env_discovery.py +33 -3
- mcp_ticketer/core/env_loader.py +7 -6
- mcp_ticketer/core/exceptions.py +10 -4
- mcp_ticketer/core/http_client.py +10 -10
- mcp_ticketer/core/instructions.py +405 -0
- mcp_ticketer/core/label_manager.py +732 -0
- mcp_ticketer/core/mappers.py +32 -20
- mcp_ticketer/core/models.py +136 -1
- mcp_ticketer/core/onepassword_secrets.py +379 -0
- mcp_ticketer/core/priority_matcher.py +463 -0
- mcp_ticketer/core/project_config.py +148 -14
- mcp_ticketer/core/registry.py +1 -1
- mcp_ticketer/core/session_state.py +171 -0
- mcp_ticketer/core/state_matcher.py +592 -0
- mcp_ticketer/core/url_parser.py +425 -0
- mcp_ticketer/core/validators.py +69 -0
- mcp_ticketer/defaults/ticket_instructions.md +644 -0
- mcp_ticketer/mcp/__init__.py +2 -2
- mcp_ticketer/mcp/server/__init__.py +2 -2
- mcp_ticketer/mcp/server/diagnostic_helper.py +175 -0
- mcp_ticketer/mcp/server/main.py +187 -93
- mcp_ticketer/mcp/server/routing.py +655 -0
- mcp_ticketer/mcp/server/server_sdk.py +58 -0
- mcp_ticketer/mcp/server/tools/__init__.py +37 -9
- mcp_ticketer/mcp/server/tools/analysis_tools.py +854 -0
- mcp_ticketer/mcp/server/tools/attachment_tools.py +65 -20
- mcp_ticketer/mcp/server/tools/bulk_tools.py +259 -202
- mcp_ticketer/mcp/server/tools/comment_tools.py +74 -12
- mcp_ticketer/mcp/server/tools/config_tools.py +1429 -0
- mcp_ticketer/mcp/server/tools/diagnostic_tools.py +211 -0
- mcp_ticketer/mcp/server/tools/hierarchy_tools.py +878 -319
- mcp_ticketer/mcp/server/tools/instruction_tools.py +295 -0
- mcp_ticketer/mcp/server/tools/label_tools.py +942 -0
- mcp_ticketer/mcp/server/tools/pr_tools.py +3 -7
- mcp_ticketer/mcp/server/tools/project_status_tools.py +158 -0
- mcp_ticketer/mcp/server/tools/project_update_tools.py +473 -0
- mcp_ticketer/mcp/server/tools/search_tools.py +180 -97
- mcp_ticketer/mcp/server/tools/session_tools.py +308 -0
- mcp_ticketer/mcp/server/tools/ticket_tools.py +1182 -82
- mcp_ticketer/mcp/server/tools/user_ticket_tools.py +364 -0
- mcp_ticketer/queue/health_monitor.py +1 -0
- mcp_ticketer/queue/manager.py +4 -4
- mcp_ticketer/queue/queue.py +3 -3
- mcp_ticketer/queue/run_worker.py +1 -1
- mcp_ticketer/queue/ticket_registry.py +2 -2
- mcp_ticketer/queue/worker.py +15 -13
- mcp_ticketer/utils/__init__.py +5 -0
- mcp_ticketer/utils/token_utils.py +246 -0
- mcp_ticketer-2.0.1.dist-info/METADATA +1366 -0
- mcp_ticketer-2.0.1.dist-info/RECORD +122 -0
- mcp_ticketer-0.4.11.dist-info/METADATA +0 -496
- mcp_ticketer-0.4.11.dist-info/RECORD +0 -77
- {mcp_ticketer-0.4.11.dist-info → mcp_ticketer-2.0.1.dist-info}/WHEEL +0 -0
- {mcp_ticketer-0.4.11.dist-info → mcp_ticketer-2.0.1.dist-info}/entry_points.txt +0 -0
- {mcp_ticketer-0.4.11.dist-info → mcp_ticketer-2.0.1.dist-info}/licenses/LICENSE +0 -0
- {mcp_ticketer-0.4.11.dist-info → mcp_ticketer-2.0.1.dist-info}/top_level.txt +0 -0
|
@@ -6,6 +6,7 @@ environment files, including:
|
|
|
6
6
|
- Support for multiple naming conventions
|
|
7
7
|
- Project information extraction
|
|
8
8
|
- Security validation
|
|
9
|
+
- 1Password CLI integration for secret references
|
|
9
10
|
"""
|
|
10
11
|
|
|
11
12
|
import logging
|
|
@@ -15,6 +16,7 @@ from typing import Any
|
|
|
15
16
|
|
|
16
17
|
from dotenv import dotenv_values
|
|
17
18
|
|
|
19
|
+
from .onepassword_secrets import OnePasswordConfig, OnePasswordSecretsLoader
|
|
18
20
|
from .project_config import AdapterType
|
|
19
21
|
|
|
20
22
|
logger = logging.getLogger(__name__)
|
|
@@ -155,14 +157,27 @@ class EnvDiscovery:
|
|
|
155
157
|
".env.development",
|
|
156
158
|
]
|
|
157
159
|
|
|
158
|
-
def __init__(
|
|
160
|
+
def __init__(
|
|
161
|
+
self,
|
|
162
|
+
project_path: Path | None = None,
|
|
163
|
+
enable_1password: bool = True,
|
|
164
|
+
onepassword_config: OnePasswordConfig | None = None,
|
|
165
|
+
):
|
|
159
166
|
"""Initialize discovery.
|
|
160
167
|
|
|
161
168
|
Args:
|
|
162
169
|
project_path: Path to project root (defaults to cwd)
|
|
170
|
+
enable_1password: Enable 1Password CLI integration for secret resolution
|
|
171
|
+
onepassword_config: Configuration for 1Password integration
|
|
163
172
|
|
|
164
173
|
"""
|
|
165
174
|
self.project_path = project_path or Path.cwd()
|
|
175
|
+
self.enable_1password = enable_1password
|
|
176
|
+
self.op_loader = (
|
|
177
|
+
OnePasswordSecretsLoader(onepassword_config or OnePasswordConfig())
|
|
178
|
+
if enable_1password
|
|
179
|
+
else None
|
|
180
|
+
)
|
|
166
181
|
|
|
167
182
|
def discover(self) -> DiscoveryResult:
|
|
168
183
|
"""Discover adapter configurations from environment files.
|
|
@@ -241,7 +256,22 @@ class EnvDiscovery:
|
|
|
241
256
|
file_path = self.project_path / env_file
|
|
242
257
|
if file_path.exists():
|
|
243
258
|
try:
|
|
244
|
-
|
|
259
|
+
# Check if file contains 1Password references and use op loader if available
|
|
260
|
+
if self.op_loader and self.enable_1password:
|
|
261
|
+
content = file_path.read_text(encoding="utf-8")
|
|
262
|
+
if "op://" in content:
|
|
263
|
+
logger.info(
|
|
264
|
+
f"Detected 1Password references in {env_file}, "
|
|
265
|
+
"attempting to resolve..."
|
|
266
|
+
)
|
|
267
|
+
env_vars = self.op_loader.load_secrets_from_env_file(
|
|
268
|
+
file_path
|
|
269
|
+
)
|
|
270
|
+
else:
|
|
271
|
+
env_vars = dotenv_values(file_path)
|
|
272
|
+
else:
|
|
273
|
+
env_vars = dotenv_values(file_path)
|
|
274
|
+
|
|
245
275
|
# Filter out None values
|
|
246
276
|
env_vars = {k: v for k, v in env_vars.items() if v is not None}
|
|
247
277
|
merged_env.update(env_vars)
|
|
@@ -623,7 +653,7 @@ class EnvDiscovery:
|
|
|
623
653
|
|
|
624
654
|
|
|
625
655
|
def discover_config(project_path: Path | None = None) -> DiscoveryResult:
|
|
626
|
-
"""
|
|
656
|
+
"""Discover configuration from environment files.
|
|
627
657
|
|
|
628
658
|
Args:
|
|
629
659
|
project_path: Path to project root (defaults to cwd)
|
mcp_ticketer/core/env_loader.py
CHANGED
|
@@ -29,8 +29,9 @@ class EnvKeyConfig:
|
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
class UnifiedEnvLoader:
|
|
32
|
-
"""Unified environment loader that handles multiple naming conventions
|
|
33
|
-
|
|
32
|
+
"""Unified environment loader that handles multiple naming conventions.
|
|
33
|
+
|
|
34
|
+
Provides consistent environment loading across all contexts.
|
|
34
35
|
"""
|
|
35
36
|
|
|
36
37
|
# Define key aliases for all adapters
|
|
@@ -131,7 +132,7 @@ class UnifiedEnvLoader:
|
|
|
131
132
|
# Fallback to current directory
|
|
132
133
|
return Path.cwd()
|
|
133
134
|
|
|
134
|
-
def _load_env_files(self):
|
|
135
|
+
def _load_env_files(self) -> None:
|
|
135
136
|
"""Load environment variables from .env files."""
|
|
136
137
|
env_files = [
|
|
137
138
|
self.project_root / ".env.local",
|
|
@@ -144,7 +145,7 @@ class UnifiedEnvLoader:
|
|
|
144
145
|
logger.debug(f"Loading environment from: {env_file}")
|
|
145
146
|
self._load_env_file(env_file)
|
|
146
147
|
|
|
147
|
-
def _load_env_file(self, env_file: Path):
|
|
148
|
+
def _load_env_file(self, env_file: Path) -> None:
|
|
148
149
|
"""Load variables from a single .env file."""
|
|
149
150
|
try:
|
|
150
151
|
with open(env_file) as f:
|
|
@@ -321,7 +322,7 @@ def get_env_loader() -> UnifiedEnvLoader:
|
|
|
321
322
|
def load_adapter_config(
|
|
322
323
|
adapter_name: str, base_config: dict[str, Any] | None = None
|
|
323
324
|
) -> dict[str, Any]:
|
|
324
|
-
"""
|
|
325
|
+
"""Load adapter configuration with environment variables.
|
|
325
326
|
|
|
326
327
|
Args:
|
|
327
328
|
adapter_name: Name of the adapter ('linear', 'jira', 'github')
|
|
@@ -335,7 +336,7 @@ def load_adapter_config(
|
|
|
335
336
|
|
|
336
337
|
|
|
337
338
|
def validate_adapter_config(adapter_name: str, config: dict[str, Any]) -> list[str]:
|
|
338
|
-
"""
|
|
339
|
+
"""Validate adapter configuration.
|
|
339
340
|
|
|
340
341
|
Args:
|
|
341
342
|
adapter_name: Name of the adapter
|
mcp_ticketer/core/exceptions.py
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
"""Exception classes for MCP Ticketer.
|
|
1
|
+
"""Exception classes for MCP Ticketer.
|
|
2
|
+
|
|
3
|
+
Error Severity Classification:
|
|
4
|
+
CRITICAL - System-level issues (auth, config, network) → Always suggest diagnostics
|
|
5
|
+
MEDIUM - Resource issues (not found, permissions) → Suggest diagnostics
|
|
6
|
+
LOW - User input errors (validation, state transitions) → No diagnostics
|
|
7
|
+
"""
|
|
2
8
|
|
|
3
9
|
from __future__ import annotations
|
|
4
10
|
|
|
@@ -35,7 +41,7 @@ class AdapterError(MCPTicketerError):
|
|
|
35
41
|
self.original_error = original_error
|
|
36
42
|
|
|
37
43
|
def __str__(self) -> str:
|
|
38
|
-
"""
|
|
44
|
+
"""Return string representation of the error."""
|
|
39
45
|
base_msg = f"[{self.adapter_name}] {super().__str__()}"
|
|
40
46
|
if self.original_error:
|
|
41
47
|
base_msg += f" (caused by: {self.original_error})"
|
|
@@ -88,7 +94,7 @@ class ValidationError(MCPTicketerError):
|
|
|
88
94
|
self.value = value
|
|
89
95
|
|
|
90
96
|
def __str__(self) -> str:
|
|
91
|
-
"""
|
|
97
|
+
"""Return string representation of the error."""
|
|
92
98
|
base_msg = super().__str__()
|
|
93
99
|
if self.field:
|
|
94
100
|
base_msg += f" (field: {self.field})"
|
|
@@ -126,7 +132,7 @@ class StateTransitionError(MCPTicketerError):
|
|
|
126
132
|
self.to_state = to_state
|
|
127
133
|
|
|
128
134
|
def __str__(self) -> str:
|
|
129
|
-
"""
|
|
135
|
+
"""Return string representation of the error."""
|
|
130
136
|
return f"{super().__str__()} ({self.from_state} -> {self.to_state})"
|
|
131
137
|
|
|
132
138
|
|
mcp_ticketer/core/http_client.py
CHANGED
|
@@ -206,7 +206,7 @@ class BaseHTTPClient:
|
|
|
206
206
|
headers: dict[str, str] | None = None,
|
|
207
207
|
timeout: float | None = None,
|
|
208
208
|
retry_count: int = 0,
|
|
209
|
-
**kwargs,
|
|
209
|
+
**kwargs: Any,
|
|
210
210
|
) -> httpx.Response:
|
|
211
211
|
"""Make HTTP request with retry and rate limiting.
|
|
212
212
|
|
|
@@ -293,27 +293,27 @@ class BaseHTTPClient:
|
|
|
293
293
|
# No more retries, re-raise the exception
|
|
294
294
|
raise
|
|
295
295
|
|
|
296
|
-
async def get(self, endpoint: str, **kwargs) -> httpx.Response:
|
|
296
|
+
async def get(self, endpoint: str, **kwargs: Any) -> httpx.Response:
|
|
297
297
|
"""Make GET request."""
|
|
298
298
|
return await self.request(HTTPMethod.GET, endpoint, **kwargs)
|
|
299
299
|
|
|
300
|
-
async def post(self, endpoint: str, **kwargs) -> httpx.Response:
|
|
300
|
+
async def post(self, endpoint: str, **kwargs: Any) -> httpx.Response:
|
|
301
301
|
"""Make POST request."""
|
|
302
302
|
return await self.request(HTTPMethod.POST, endpoint, **kwargs)
|
|
303
303
|
|
|
304
|
-
async def put(self, endpoint: str, **kwargs) -> httpx.Response:
|
|
304
|
+
async def put(self, endpoint: str, **kwargs: Any) -> httpx.Response:
|
|
305
305
|
"""Make PUT request."""
|
|
306
306
|
return await self.request(HTTPMethod.PUT, endpoint, **kwargs)
|
|
307
307
|
|
|
308
|
-
async def patch(self, endpoint: str, **kwargs) -> httpx.Response:
|
|
308
|
+
async def patch(self, endpoint: str, **kwargs: Any) -> httpx.Response:
|
|
309
309
|
"""Make PATCH request."""
|
|
310
310
|
return await self.request(HTTPMethod.PATCH, endpoint, **kwargs)
|
|
311
311
|
|
|
312
|
-
async def delete(self, endpoint: str, **kwargs) -> httpx.Response:
|
|
312
|
+
async def delete(self, endpoint: str, **kwargs: Any) -> httpx.Response:
|
|
313
313
|
"""Make DELETE request."""
|
|
314
314
|
return await self.request(HTTPMethod.DELETE, endpoint, **kwargs)
|
|
315
315
|
|
|
316
|
-
async def get_json(self, endpoint: str, **kwargs) -> dict[str, Any]:
|
|
316
|
+
async def get_json(self, endpoint: str, **kwargs: Any) -> dict[str, Any]:
|
|
317
317
|
"""Make GET request and return JSON response."""
|
|
318
318
|
response = await self.get(endpoint, **kwargs)
|
|
319
319
|
|
|
@@ -323,7 +323,7 @@ class BaseHTTPClient:
|
|
|
323
323
|
|
|
324
324
|
return response.json()
|
|
325
325
|
|
|
326
|
-
async def post_json(self, endpoint: str, **kwargs) -> dict[str, Any]:
|
|
326
|
+
async def post_json(self, endpoint: str, **kwargs: Any) -> dict[str, Any]:
|
|
327
327
|
"""Make POST request and return JSON response."""
|
|
328
328
|
response = await self.post(endpoint, **kwargs)
|
|
329
329
|
|
|
@@ -333,7 +333,7 @@ class BaseHTTPClient:
|
|
|
333
333
|
|
|
334
334
|
return response.json()
|
|
335
335
|
|
|
336
|
-
async def put_json(self, endpoint: str, **kwargs) -> dict[str, Any]:
|
|
336
|
+
async def put_json(self, endpoint: str, **kwargs: Any) -> dict[str, Any]:
|
|
337
337
|
"""Make PUT request and return JSON response."""
|
|
338
338
|
response = await self.put(endpoint, **kwargs)
|
|
339
339
|
|
|
@@ -343,7 +343,7 @@ class BaseHTTPClient:
|
|
|
343
343
|
|
|
344
344
|
return response.json()
|
|
345
345
|
|
|
346
|
-
async def patch_json(self, endpoint: str, **kwargs) -> dict[str, Any]:
|
|
346
|
+
async def patch_json(self, endpoint: str, **kwargs: Any) -> dict[str, Any]:
|
|
347
347
|
"""Make PATCH request and return JSON response."""
|
|
348
348
|
response = await self.patch(endpoint, **kwargs)
|
|
349
349
|
|
|
@@ -0,0 +1,405 @@
|
|
|
1
|
+
"""Ticket writing instructions management.
|
|
2
|
+
|
|
3
|
+
This module provides a unified interface for managing ticket writing instructions
|
|
4
|
+
that guide AI agents and users in creating well-structured, consistent tickets.
|
|
5
|
+
|
|
6
|
+
The instructions can be:
|
|
7
|
+
- Default (embedded in the package)
|
|
8
|
+
- Custom (project-specific, stored in .mcp-ticketer/instructions.md)
|
|
9
|
+
|
|
10
|
+
Example:
|
|
11
|
+
>>> from mcp_ticketer.core.instructions import get_instructions
|
|
12
|
+
>>> instructions = get_instructions()
|
|
13
|
+
>>> print(instructions)
|
|
14
|
+
|
|
15
|
+
>>> # For project-specific management
|
|
16
|
+
>>> from mcp_ticketer.core.instructions import TicketInstructionsManager
|
|
17
|
+
>>> manager = TicketInstructionsManager(project_dir="/path/to/project")
|
|
18
|
+
>>> manager.set_instructions("Custom instructions here...")
|
|
19
|
+
>>> if manager.has_custom_instructions():
|
|
20
|
+
... print("Using custom instructions")
|
|
21
|
+
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
from __future__ import annotations
|
|
25
|
+
|
|
26
|
+
import logging
|
|
27
|
+
from pathlib import Path
|
|
28
|
+
|
|
29
|
+
from .exceptions import MCPTicketerError
|
|
30
|
+
|
|
31
|
+
logger = logging.getLogger(__name__)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class InstructionsError(MCPTicketerError):
|
|
35
|
+
"""Base exception for instructions-related errors.
|
|
36
|
+
|
|
37
|
+
Raised when there are issues loading, saving, or validating ticket
|
|
38
|
+
writing instructions.
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
pass
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class InstructionsNotFoundError(InstructionsError):
|
|
45
|
+
"""Exception raised when instructions file cannot be found.
|
|
46
|
+
|
|
47
|
+
This typically occurs when trying to load custom instructions from a
|
|
48
|
+
file path that doesn't exist, or when the default instructions file
|
|
49
|
+
is missing from the package.
|
|
50
|
+
"""
|
|
51
|
+
|
|
52
|
+
pass
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class InstructionsValidationError(InstructionsError):
|
|
56
|
+
"""Exception raised when instructions content is invalid.
|
|
57
|
+
|
|
58
|
+
Raised when instructions content fails validation rules such as:
|
|
59
|
+
- Empty content
|
|
60
|
+
- Content too short (< 100 characters)
|
|
61
|
+
- Invalid encoding
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
pass
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
class TicketInstructionsManager:
|
|
68
|
+
"""Manages ticket writing instructions for a project.
|
|
69
|
+
|
|
70
|
+
This class handles loading, saving, and validating ticket writing instructions.
|
|
71
|
+
It supports both default (embedded) instructions and custom project-specific
|
|
72
|
+
instructions.
|
|
73
|
+
|
|
74
|
+
The default instructions are embedded in the package at:
|
|
75
|
+
src/mcp_ticketer/defaults/ticket_instructions.md
|
|
76
|
+
|
|
77
|
+
Custom instructions are stored in the project directory at:
|
|
78
|
+
{project_dir}/.mcp-ticketer/instructions.md
|
|
79
|
+
|
|
80
|
+
Attributes:
|
|
81
|
+
project_dir: Path to the project root directory
|
|
82
|
+
|
|
83
|
+
Example:
|
|
84
|
+
>>> manager = TicketInstructionsManager("/path/to/project")
|
|
85
|
+
>>> instructions = manager.get_instructions()
|
|
86
|
+
>>> print(f"Using {'custom' if manager.has_custom_instructions() else 'default'}")
|
|
87
|
+
|
|
88
|
+
>>> # Set custom instructions
|
|
89
|
+
>>> manager.set_instructions("My custom guidelines...")
|
|
90
|
+
>>> assert manager.has_custom_instructions()
|
|
91
|
+
|
|
92
|
+
>>> # Revert to defaults
|
|
93
|
+
>>> manager.delete_instructions()
|
|
94
|
+
>>> assert not manager.has_custom_instructions()
|
|
95
|
+
|
|
96
|
+
"""
|
|
97
|
+
|
|
98
|
+
# Class-level constant for custom instructions filename
|
|
99
|
+
INSTRUCTIONS_FILENAME = "instructions.md"
|
|
100
|
+
DEFAULT_INSTRUCTIONS_FILENAME = "ticket_instructions.md"
|
|
101
|
+
CONFIG_DIR = ".mcp-ticketer"
|
|
102
|
+
|
|
103
|
+
def __init__(self, project_dir: str | Path | None = None):
|
|
104
|
+
"""Initialize the instructions manager.
|
|
105
|
+
|
|
106
|
+
Args:
|
|
107
|
+
project_dir: Path to the project root directory. If None, uses current
|
|
108
|
+
working directory. The project directory is where the .mcp-ticketer
|
|
109
|
+
folder will be created for custom instructions.
|
|
110
|
+
|
|
111
|
+
Raises:
|
|
112
|
+
InstructionsError: If project_dir is invalid or inaccessible
|
|
113
|
+
|
|
114
|
+
"""
|
|
115
|
+
if project_dir is None:
|
|
116
|
+
project_dir = Path.cwd()
|
|
117
|
+
else:
|
|
118
|
+
project_dir = Path(project_dir)
|
|
119
|
+
|
|
120
|
+
if not project_dir.exists():
|
|
121
|
+
raise InstructionsError(f"Project directory does not exist: {project_dir}")
|
|
122
|
+
|
|
123
|
+
if not project_dir.is_dir():
|
|
124
|
+
raise InstructionsError(f"Project path is not a directory: {project_dir}")
|
|
125
|
+
|
|
126
|
+
self.project_dir = project_dir.resolve()
|
|
127
|
+
logger.debug(f"Initialized TicketInstructionsManager for: {self.project_dir}")
|
|
128
|
+
|
|
129
|
+
def get_instructions(self) -> str:
|
|
130
|
+
"""Get the current ticket writing instructions.
|
|
131
|
+
|
|
132
|
+
Returns custom instructions if they exist, otherwise returns the default
|
|
133
|
+
embedded instructions.
|
|
134
|
+
|
|
135
|
+
Returns:
|
|
136
|
+
The ticket writing instructions as a string
|
|
137
|
+
|
|
138
|
+
Raises:
|
|
139
|
+
InstructionsError: If instructions cannot be loaded
|
|
140
|
+
InstructionsNotFoundError: If default instructions are missing (package error)
|
|
141
|
+
|
|
142
|
+
Example:
|
|
143
|
+
>>> manager = TicketInstructionsManager()
|
|
144
|
+
>>> instructions = manager.get_instructions()
|
|
145
|
+
>>> # Use instructions to guide ticket creation
|
|
146
|
+
>>> print(instructions[:100])
|
|
147
|
+
|
|
148
|
+
"""
|
|
149
|
+
if self.has_custom_instructions():
|
|
150
|
+
logger.debug("Loading custom instructions")
|
|
151
|
+
custom_path = self.get_instructions_path()
|
|
152
|
+
try:
|
|
153
|
+
return custom_path.read_text(encoding="utf-8")
|
|
154
|
+
except Exception as e:
|
|
155
|
+
raise InstructionsError(
|
|
156
|
+
f"Failed to read custom instructions from {custom_path}: {e}"
|
|
157
|
+
) from e
|
|
158
|
+
else:
|
|
159
|
+
logger.debug("Loading default instructions")
|
|
160
|
+
return self.get_default_instructions()
|
|
161
|
+
|
|
162
|
+
def get_default_instructions(self) -> str:
|
|
163
|
+
"""Get the default embedded ticket writing instructions.
|
|
164
|
+
|
|
165
|
+
The default instructions are shipped with the package and provide
|
|
166
|
+
comprehensive guidelines for ticket creation.
|
|
167
|
+
|
|
168
|
+
Returns:
|
|
169
|
+
The default ticket writing instructions as a string
|
|
170
|
+
|
|
171
|
+
Raises:
|
|
172
|
+
InstructionsNotFoundError: If the default instructions file is missing
|
|
173
|
+
from the package (indicates package corruption or installation issue)
|
|
174
|
+
|
|
175
|
+
Example:
|
|
176
|
+
>>> manager = TicketInstructionsManager()
|
|
177
|
+
>>> defaults = manager.get_default_instructions()
|
|
178
|
+
>>> # Always returns the same content regardless of project
|
|
179
|
+
|
|
180
|
+
"""
|
|
181
|
+
# Get the path to the defaults directory (sibling to core)
|
|
182
|
+
package_root = Path(__file__).parent.parent
|
|
183
|
+
default_path = package_root / "defaults" / self.DEFAULT_INSTRUCTIONS_FILENAME
|
|
184
|
+
|
|
185
|
+
if not default_path.exists():
|
|
186
|
+
raise InstructionsNotFoundError(
|
|
187
|
+
f"Default instructions file not found at: {default_path}. "
|
|
188
|
+
"This indicates a package installation issue."
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
try:
|
|
192
|
+
content = default_path.read_text(encoding="utf-8")
|
|
193
|
+
logger.debug(f"Loaded default instructions from {default_path}")
|
|
194
|
+
return content
|
|
195
|
+
except Exception as e:
|
|
196
|
+
raise InstructionsError(
|
|
197
|
+
f"Failed to read default instructions from {default_path}: {e}"
|
|
198
|
+
) from e
|
|
199
|
+
|
|
200
|
+
def set_instructions(self, content: str) -> None:
|
|
201
|
+
r"""Set custom ticket writing instructions for the project.
|
|
202
|
+
|
|
203
|
+
Creates or overwrites the custom instructions file in the project's
|
|
204
|
+
.mcp-ticketer directory. The content is validated before saving.
|
|
205
|
+
|
|
206
|
+
Args:
|
|
207
|
+
content: The custom instructions content to save
|
|
208
|
+
|
|
209
|
+
Raises:
|
|
210
|
+
InstructionsValidationError: If content fails validation
|
|
211
|
+
InstructionsError: If instructions cannot be written to disk
|
|
212
|
+
|
|
213
|
+
Example:
|
|
214
|
+
>>> manager = TicketInstructionsManager()
|
|
215
|
+
>>> custom = "# My Team's Ticket Guidelines\n\n..."
|
|
216
|
+
>>> manager.set_instructions(custom)
|
|
217
|
+
>>> assert manager.has_custom_instructions()
|
|
218
|
+
|
|
219
|
+
"""
|
|
220
|
+
# Validate content
|
|
221
|
+
self._validate_instructions(content)
|
|
222
|
+
|
|
223
|
+
# Ensure config directory exists
|
|
224
|
+
config_dir = self.project_dir / self.CONFIG_DIR
|
|
225
|
+
config_dir.mkdir(exist_ok=True, parents=True)
|
|
226
|
+
|
|
227
|
+
# Write instructions file
|
|
228
|
+
instructions_path = self.get_instructions_path()
|
|
229
|
+
try:
|
|
230
|
+
instructions_path.write_text(content, encoding="utf-8")
|
|
231
|
+
logger.info(f"Saved custom instructions to {instructions_path}")
|
|
232
|
+
except Exception as e:
|
|
233
|
+
raise InstructionsError(
|
|
234
|
+
f"Failed to write instructions to {instructions_path}: {e}"
|
|
235
|
+
) from e
|
|
236
|
+
|
|
237
|
+
def set_instructions_from_file(self, file_path: str | Path) -> None:
|
|
238
|
+
"""Load and set custom instructions from a file.
|
|
239
|
+
|
|
240
|
+
Reads instructions from the specified file and sets them as custom
|
|
241
|
+
instructions for the project. The file content is validated before saving.
|
|
242
|
+
|
|
243
|
+
Args:
|
|
244
|
+
file_path: Path to the file containing instructions
|
|
245
|
+
|
|
246
|
+
Raises:
|
|
247
|
+
InstructionsNotFoundError: If the source file doesn't exist
|
|
248
|
+
InstructionsValidationError: If file content fails validation
|
|
249
|
+
InstructionsError: If instructions cannot be loaded or saved
|
|
250
|
+
|
|
251
|
+
Example:
|
|
252
|
+
>>> manager = TicketInstructionsManager()
|
|
253
|
+
>>> manager.set_instructions_from_file("team_guidelines.md")
|
|
254
|
+
>>> assert manager.has_custom_instructions()
|
|
255
|
+
|
|
256
|
+
"""
|
|
257
|
+
source_path = Path(file_path)
|
|
258
|
+
|
|
259
|
+
if not source_path.exists():
|
|
260
|
+
raise InstructionsNotFoundError(
|
|
261
|
+
f"Instructions file not found: {source_path}"
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
if not source_path.is_file():
|
|
265
|
+
raise InstructionsError(f"Path is not a file: {source_path}")
|
|
266
|
+
|
|
267
|
+
try:
|
|
268
|
+
content = source_path.read_text(encoding="utf-8")
|
|
269
|
+
logger.debug(f"Read instructions from {source_path}")
|
|
270
|
+
except Exception as e:
|
|
271
|
+
raise InstructionsError(
|
|
272
|
+
f"Failed to read instructions from {source_path}: {e}"
|
|
273
|
+
) from e
|
|
274
|
+
|
|
275
|
+
# Use set_instructions to validate and save
|
|
276
|
+
self.set_instructions(content)
|
|
277
|
+
|
|
278
|
+
def delete_instructions(self) -> bool:
|
|
279
|
+
"""Delete custom instructions and revert to defaults.
|
|
280
|
+
|
|
281
|
+
Removes the custom instructions file if it exists. After deletion,
|
|
282
|
+
get_instructions() will return the default instructions.
|
|
283
|
+
|
|
284
|
+
Returns:
|
|
285
|
+
True if custom instructions were deleted, False if they didn't exist
|
|
286
|
+
|
|
287
|
+
Raises:
|
|
288
|
+
InstructionsError: If instructions file cannot be deleted
|
|
289
|
+
|
|
290
|
+
Example:
|
|
291
|
+
>>> manager = TicketInstructionsManager()
|
|
292
|
+
>>> manager.set_instructions("Custom instructions")
|
|
293
|
+
>>> assert manager.delete_instructions() # Returns True
|
|
294
|
+
>>> assert not manager.has_custom_instructions()
|
|
295
|
+
>>> assert not manager.delete_instructions() # Returns False
|
|
296
|
+
|
|
297
|
+
"""
|
|
298
|
+
instructions_path = self.get_instructions_path()
|
|
299
|
+
|
|
300
|
+
if not instructions_path.exists():
|
|
301
|
+
logger.debug("No custom instructions to delete")
|
|
302
|
+
return False
|
|
303
|
+
|
|
304
|
+
try:
|
|
305
|
+
instructions_path.unlink()
|
|
306
|
+
logger.info(f"Deleted custom instructions at {instructions_path}")
|
|
307
|
+
return True
|
|
308
|
+
except Exception as e:
|
|
309
|
+
raise InstructionsError(
|
|
310
|
+
f"Failed to delete instructions at {instructions_path}: {e}"
|
|
311
|
+
) from e
|
|
312
|
+
|
|
313
|
+
def has_custom_instructions(self) -> bool:
|
|
314
|
+
"""Check if custom instructions exist for this project.
|
|
315
|
+
|
|
316
|
+
Returns:
|
|
317
|
+
True if custom instructions file exists, False otherwise
|
|
318
|
+
|
|
319
|
+
Example:
|
|
320
|
+
>>> manager = TicketInstructionsManager()
|
|
321
|
+
>>> if manager.has_custom_instructions():
|
|
322
|
+
... print("Using project-specific guidelines")
|
|
323
|
+
... else:
|
|
324
|
+
... print("Using default guidelines")
|
|
325
|
+
|
|
326
|
+
"""
|
|
327
|
+
return self.get_instructions_path().exists()
|
|
328
|
+
|
|
329
|
+
def get_instructions_path(self) -> Path:
|
|
330
|
+
"""Get the path to the custom instructions file.
|
|
331
|
+
|
|
332
|
+
Returns:
|
|
333
|
+
Path object pointing to where custom instructions are (or would be) stored
|
|
334
|
+
|
|
335
|
+
Note:
|
|
336
|
+
This returns the path even if the file doesn't exist yet. Use
|
|
337
|
+
has_custom_instructions() to check if the file exists.
|
|
338
|
+
|
|
339
|
+
Example:
|
|
340
|
+
>>> manager = TicketInstructionsManager("/path/to/project")
|
|
341
|
+
>>> path = manager.get_instructions_path()
|
|
342
|
+
>>> print(path) # /path/to/project/.mcp-ticketer/instructions.md
|
|
343
|
+
|
|
344
|
+
"""
|
|
345
|
+
return self.project_dir / self.CONFIG_DIR / self.INSTRUCTIONS_FILENAME
|
|
346
|
+
|
|
347
|
+
def _validate_instructions(self, content: str) -> None:
|
|
348
|
+
"""Validate instructions content.
|
|
349
|
+
|
|
350
|
+
Performs validation checks on instructions content:
|
|
351
|
+
- Not empty
|
|
352
|
+
- Minimum length (100 characters)
|
|
353
|
+
- Contains markdown headers (warning only)
|
|
354
|
+
|
|
355
|
+
Args:
|
|
356
|
+
content: The instructions content to validate
|
|
357
|
+
|
|
358
|
+
Raises:
|
|
359
|
+
InstructionsValidationError: If content fails validation
|
|
360
|
+
|
|
361
|
+
"""
|
|
362
|
+
if not content or not content.strip():
|
|
363
|
+
raise InstructionsValidationError("Instructions content cannot be empty")
|
|
364
|
+
|
|
365
|
+
if len(content.strip()) < 100:
|
|
366
|
+
raise InstructionsValidationError(
|
|
367
|
+
f"Instructions content too short ({len(content)} characters). "
|
|
368
|
+
"Minimum 100 characters required for meaningful guidelines."
|
|
369
|
+
)
|
|
370
|
+
|
|
371
|
+
# Warn if no markdown headers (not an error, just a quality check)
|
|
372
|
+
if not any(line.strip().startswith("#") for line in content.split("\n")):
|
|
373
|
+
logger.warning(
|
|
374
|
+
"Instructions don't contain markdown headers. "
|
|
375
|
+
"Consider using headers for better structure."
|
|
376
|
+
)
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
def get_instructions(project_dir: str | Path | None = None) -> str:
|
|
380
|
+
"""Get ticket writing instructions for a project.
|
|
381
|
+
|
|
382
|
+
This is a shorthand for creating a TicketInstructionsManager and calling
|
|
383
|
+
get_instructions(). Useful for simple cases where you just need the content.
|
|
384
|
+
|
|
385
|
+
Args:
|
|
386
|
+
project_dir: Path to the project root directory. If None, uses current
|
|
387
|
+
working directory.
|
|
388
|
+
|
|
389
|
+
Returns:
|
|
390
|
+
The ticket writing instructions (custom if available, otherwise default)
|
|
391
|
+
|
|
392
|
+
Raises:
|
|
393
|
+
InstructionsError: If instructions cannot be loaded
|
|
394
|
+
|
|
395
|
+
Example:
|
|
396
|
+
>>> from mcp_ticketer.core.instructions import get_instructions
|
|
397
|
+
>>> instructions = get_instructions()
|
|
398
|
+
>>> # Use instructions to guide ticket creation
|
|
399
|
+
|
|
400
|
+
>>> # For specific project
|
|
401
|
+
>>> instructions = get_instructions("/path/to/project")
|
|
402
|
+
|
|
403
|
+
"""
|
|
404
|
+
manager = TicketInstructionsManager(project_dir)
|
|
405
|
+
return manager.get_instructions()
|