backlog-tiny-mcp 0.34.2__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.
- backlog_mcp/__init__.py +29 -0
- backlog_mcp/__main__.py +10 -0
- backlog_mcp/auth.py +199 -0
- backlog_mcp/backlog.py +696 -0
- backlog_mcp/cli.py +2046 -0
- backlog_mcp/client.py +320 -0
- backlog_mcp/computer.py +33 -0
- backlog_mcp/database.py +80 -0
- backlog_mcp/embeddings.py +900 -0
- backlog_mcp/global_rules.md +126 -0
- backlog_mcp/guidance.py +11 -0
- backlog_mcp/guide/index.md +11 -0
- backlog_mcp/guide/memory.md +27 -0
- backlog_mcp/guide/projects.md +16 -0
- backlog_mcp/guide/search.md +72 -0
- backlog_mcp/guide/tasks.md +40 -0
- backlog_mcp/guide/workflow.md +22 -0
- backlog_mcp/httpd.py +270 -0
- backlog_mcp/migrate.py +113 -0
- backlog_mcp/migrations/0001-initial.sql +194 -0
- backlog_mcp/migrations/0002-task-assignment.sql +2 -0
- backlog_mcp/migrations/0003-task-edit-claims.sql +5 -0
- backlog_mcp/migrations/0004-memory-visibility.sql +42 -0
- backlog_mcp/model/CITATION.bib +9 -0
- backlog_mcp/model/LICENSE +202 -0
- backlog_mcp/model/README.md +12 -0
- backlog_mcp/model/UPSTREAM.md +2053 -0
- backlog_mcp/model/config.json +12 -0
- backlog_mcp/model/model.safetensors +4 -0
- backlog_mcp/model/modules.json +14 -0
- backlog_mcp/model/provenance.json +16 -0
- backlog_mcp/model/tokenizer.json +1 -0
- backlog_mcp/models.py +581 -0
- backlog_mcp/names.py +35 -0
- backlog_mcp/paths.py +53 -0
- backlog_mcp/protocol_storage.py +104 -0
- backlog_mcp/queries.py +7 -0
- backlog_mcp/queries.sql +531 -0
- backlog_mcp/records.py +215 -0
- backlog_mcp/render.py +479 -0
- backlog_mcp/server.py +2864 -0
- backlog_mcp/skills/autopilot/SKILL.md +96 -0
- backlog_mcp/skills/planning/SKILL.md +106 -0
- backlog_mcp/skills/planning/references/splitting.md +45 -0
- backlog_mcp/skills/triage/SKILL.md +104 -0
- backlog_mcp/skills/triage/references/conventions.md +43 -0
- backlog_mcp/skills.py +56 -0
- backlog_mcp/static/agent-config.js +20 -0
- backlog_mcp/static/app.css +1950 -0
- backlog_mcp/static/app.js +1301 -0
- backlog_mcp/static/assignments.js +96 -0
- backlog_mcp/static/breadcrumbs.js +54 -0
- backlog_mcp/static/comment-composer.js +95 -0
- backlog_mcp/static/connect.css +98 -0
- backlog_mcp/static/connect.html +74 -0
- backlog_mcp/static/connect.js +160 -0
- backlog_mcp/static/credentials.js +72 -0
- backlog_mcp/static/diagrams.js +128 -0
- backlog_mcp/static/dom.js +162 -0
- backlog_mcp/static/editor-claim.js +104 -0
- backlog_mcp/static/editor.js +355 -0
- backlog_mcp/static/index.html +137 -0
- backlog_mcp/static/markdown.css +33 -0
- backlog_mcp/static/markdown.js +72 -0
- backlog_mcp/static/mcp.js +177 -0
- backlog_mcp/static/memory-append.js +34 -0
- backlog_mcp/static/memory-editor.js +173 -0
- backlog_mcp/static/memory.js +279 -0
- backlog_mcp/static/package.json +1 -0
- backlog_mcp/static/project-form.js +71 -0
- backlog_mcp/static/project-settings.js +225 -0
- backlog_mcp/static/scope.js +90 -0
- backlog_mcp/static/statistics.js +87 -0
- backlog_mcp/static/task-browser.js +100 -0
- backlog_mcp/static/task-pagination.js +94 -0
- backlog_mcp/static/task-picker.js +164 -0
- backlog_mcp/static/task-table.js +74 -0
- backlog_mcp/static/vendor/README.md +12 -0
- backlog_mcp/static/vendor/dompurify-LICENSE +202 -0
- backlog_mcp/static/vendor/highlight-LICENSE +29 -0
- backlog_mcp/static/vendor/highlight-dark.css +118 -0
- backlog_mcp/static/vendor/highlight-light.css +118 -0
- backlog_mcp/static/vendor/highlight.min.js +1262 -0
- backlog_mcp/static/vendor/marked-LICENSE +44 -0
- backlog_mcp/static/vendor/marked.esm.js +80 -0
- backlog_mcp/static/vendor/marked.esm.js.map +7 -0
- backlog_mcp/static/vendor/mermaid-LICENSE +21 -0
- backlog_mcp/static/vendor/mermaid.min.js +4376 -0
- backlog_mcp/static/vendor/purify.es.mjs +2722 -0
- backlog_mcp/static/vendor/purify.es.mjs.map +1 -0
- backlog_mcp/transaction.py +47 -0
- backlog_mcp/version.py +79 -0
- backlog_mcp/webui.py +63 -0
- backlog_tiny_mcp-0.34.2.dist-info/METADATA +84 -0
- backlog_tiny_mcp-0.34.2.dist-info/RECORD +97 -0
- backlog_tiny_mcp-0.34.2.dist-info/WHEEL +4 -0
- backlog_tiny_mcp-0.34.2.dist-info/entry_points.txt +4 -0
backlog_mcp/models.py
ADDED
|
@@ -0,0 +1,581 @@
|
|
|
1
|
+
"""What the tools accept and return: the server's public shape."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
from enum import StrEnum, unique
|
|
7
|
+
from typing import Annotated, Any, Literal
|
|
8
|
+
from urllib.parse import unquote
|
|
9
|
+
|
|
10
|
+
from pydantic import (
|
|
11
|
+
AfterValidator,
|
|
12
|
+
BaseModel,
|
|
13
|
+
Field,
|
|
14
|
+
PlainSerializer,
|
|
15
|
+
SerializationInfo,
|
|
16
|
+
SerializerFunctionWrapHandler,
|
|
17
|
+
WithJsonSchema,
|
|
18
|
+
field_serializer,
|
|
19
|
+
field_validator,
|
|
20
|
+
model_serializer,
|
|
21
|
+
model_validator,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
from .names import principal_label
|
|
25
|
+
|
|
26
|
+
# Publish the json shape: whole seconds, not the stored float.
|
|
27
|
+
Seconds = Annotated[
|
|
28
|
+
float,
|
|
29
|
+
PlainSerializer(round, return_type=int, when_used="json"),
|
|
30
|
+
WithJsonSchema({"type": "integer"}),
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
ASSIGNMENT_PATTERN = (
|
|
34
|
+
r"^(?:[A-Za-z0-9_.~-]|%[0-9A-Fa-f]{2})+"
|
|
35
|
+
r"@(?:[A-Za-z0-9_.~-]|%[0-9A-Fa-f]{2})+:[A-Za-z0-9_-]{1,64}$"
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def check_assignment(value: str) -> str:
|
|
40
|
+
"""Validate a principal label followed by an agent's URL-safe marker."""
|
|
41
|
+
if re.fullmatch(ASSIGNMENT_PATTERN, value) is None:
|
|
42
|
+
raise ValueError(
|
|
43
|
+
"assignment must be username@computer:marker; "
|
|
44
|
+
"marker must contain 1–64 letters, digits, underscores or hyphens"
|
|
45
|
+
)
|
|
46
|
+
return value
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
Assignment = Annotated[str, Field(pattern=ASSIGNMENT_PATTERN), AfterValidator(check_assignment)]
|
|
50
|
+
# Keep explicit null values in the published schema on every supported MCP adapter.
|
|
51
|
+
NullableAssignment = Annotated[
|
|
52
|
+
Assignment | None,
|
|
53
|
+
WithJsonSchema({"type": ["string", "null"], "pattern": ASSIGNMENT_PATTERN}),
|
|
54
|
+
]
|
|
55
|
+
NullableString = Annotated[str | None, WithJsonSchema({"type": ["string", "null"]})]
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class Status(StrEnum):
|
|
59
|
+
"""Where a task stands. Only `DONE`, `CANCELLED` and `DELETED` close it."""
|
|
60
|
+
|
|
61
|
+
TODO = "todo"
|
|
62
|
+
DOING = "doing"
|
|
63
|
+
BLOCKED = "blocked"
|
|
64
|
+
DONE = "done"
|
|
65
|
+
CANCELLED = "cancelled"
|
|
66
|
+
DELETED = "deleted"
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
@unique
|
|
70
|
+
class Relation(StrEnum):
|
|
71
|
+
"""A relation read from the source task toward the target task."""
|
|
72
|
+
|
|
73
|
+
PART_OF = "part_of"
|
|
74
|
+
CONTAINS = "contains"
|
|
75
|
+
DEPENDS_ON = "depends_on"
|
|
76
|
+
BLOCKS = "blocks"
|
|
77
|
+
CAUSED_BY = "caused_by"
|
|
78
|
+
CAUSES = "causes"
|
|
79
|
+
RELATED_TO = "related_to"
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
RELATIONS: dict[Relation, Relation] = {
|
|
83
|
+
Relation.PART_OF: Relation.CONTAINS,
|
|
84
|
+
Relation.CONTAINS: Relation.PART_OF,
|
|
85
|
+
Relation.DEPENDS_ON: Relation.BLOCKS,
|
|
86
|
+
Relation.BLOCKS: Relation.DEPENDS_ON,
|
|
87
|
+
Relation.CAUSED_BY: Relation.CAUSES,
|
|
88
|
+
Relation.CAUSES: Relation.CAUSED_BY,
|
|
89
|
+
Relation.RELATED_TO: Relation.RELATED_TO,
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def relation(value: str | Relation) -> tuple[Relation, Relation]:
|
|
94
|
+
"""Return the relation and its inverse."""
|
|
95
|
+
if isinstance(value, str):
|
|
96
|
+
value = Relation[value.upper()]
|
|
97
|
+
return value, RELATIONS[value]
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
class Priority(StrEnum):
|
|
101
|
+
URGENT = "urgent"
|
|
102
|
+
HIGH = "high"
|
|
103
|
+
NORMAL = "normal"
|
|
104
|
+
LOW = "low"
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
OPEN_STATUSES: tuple[Status, ...] = (Status.TODO, Status.DOING, Status.BLOCKED)
|
|
108
|
+
CLOSED_STATUSES: tuple[Status, ...] = (Status.DONE, Status.CANCELLED, Status.DELETED)
|
|
109
|
+
|
|
110
|
+
#: Priorities are stored as a rank so SQL can order by them.
|
|
111
|
+
RANKS: dict[Priority, int] = {
|
|
112
|
+
Priority.URGENT: 0,
|
|
113
|
+
Priority.HIGH: 1,
|
|
114
|
+
Priority.NORMAL: 2,
|
|
115
|
+
Priority.LOW: 3,
|
|
116
|
+
}
|
|
117
|
+
PRIORITIES: dict[int, Priority] = {rank: name for name, rank in RANKS.items()}
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
class Origin(StrEnum):
|
|
121
|
+
"""How the current project was chosen."""
|
|
122
|
+
|
|
123
|
+
ARGUMENT = "argument"
|
|
124
|
+
DIRECTORY = "directory"
|
|
125
|
+
CREATED = "created"
|
|
126
|
+
#: A computer with no project chosen: nothing named, no directory here.
|
|
127
|
+
NONE = "none"
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def principal_schema(schema: dict[str, Any]) -> None:
|
|
131
|
+
properties = schema.get("properties", {})
|
|
132
|
+
if "computers" in properties:
|
|
133
|
+
properties["principals"] = {"type": "array", "items": {"type": "string"}}
|
|
134
|
+
if "this_computer" in properties:
|
|
135
|
+
properties["this_principal"] = {"type": "string"}
|
|
136
|
+
for key in ("computer", "computers", "this_computer"):
|
|
137
|
+
schema.get("properties", {}).pop(key, None)
|
|
138
|
+
if key in schema.get("required", []):
|
|
139
|
+
schema["required"].remove(key)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
class Actor(BaseModel):
|
|
143
|
+
model_config = {"json_schema_extra": principal_schema}
|
|
144
|
+
|
|
145
|
+
principal: str
|
|
146
|
+
computer: str | None = None
|
|
147
|
+
|
|
148
|
+
@model_validator(mode="before")
|
|
149
|
+
@classmethod
|
|
150
|
+
def parse_principal(cls, value: Any) -> Any:
|
|
151
|
+
if (
|
|
152
|
+
isinstance(value, dict)
|
|
153
|
+
and "computer" not in value
|
|
154
|
+
and "@" in value.get("principal", "")
|
|
155
|
+
):
|
|
156
|
+
value = dict(value)
|
|
157
|
+
user, _, computer = value["principal"].rpartition("@")
|
|
158
|
+
value["principal"] = unquote(user)
|
|
159
|
+
value["computer"] = (
|
|
160
|
+
None
|
|
161
|
+
if computer == "unknown" and cls.model_fields["computer"].annotation is not str
|
|
162
|
+
else unquote(computer)
|
|
163
|
+
)
|
|
164
|
+
if "principals" in value:
|
|
165
|
+
value["computers"] = [
|
|
166
|
+
unquote(item.rpartition("@")[2]) for item in value["principals"]
|
|
167
|
+
]
|
|
168
|
+
if "this_principal" in value:
|
|
169
|
+
value["this_computer"] = unquote(value["this_principal"].rpartition("@")[2])
|
|
170
|
+
return value
|
|
171
|
+
|
|
172
|
+
@model_serializer(mode="wrap")
|
|
173
|
+
# No return annotation: preserve the model schema for the wrapping serializer.
|
|
174
|
+
def actor_output( # type: ignore[no-untyped-def]
|
|
175
|
+
self, handler: SerializerFunctionWrapHandler, info: SerializationInfo
|
|
176
|
+
):
|
|
177
|
+
output: dict[str, Any] = handler(self)
|
|
178
|
+
if info.mode == "json":
|
|
179
|
+
output["principal"] = principal_label(self.principal, self.computer)
|
|
180
|
+
output.pop("computer", None)
|
|
181
|
+
if "computers" in output:
|
|
182
|
+
output["principals"] = [
|
|
183
|
+
principal_label(self.principal, item) for item in output.pop("computers")
|
|
184
|
+
]
|
|
185
|
+
if "this_computer" in output:
|
|
186
|
+
output["this_principal"] = principal_label(
|
|
187
|
+
self.principal, output.pop("this_computer")
|
|
188
|
+
)
|
|
189
|
+
return output
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
class Identity(Actor):
|
|
193
|
+
assigned_tasks: int = Field(
|
|
194
|
+
default=0,
|
|
195
|
+
description="Accessible tasks assigned to this user@computer, across all statuses.",
|
|
196
|
+
)
|
|
197
|
+
auth_type: Literal["basic", "jwt", "none"] = Field(
|
|
198
|
+
description="Authentication used by this connection."
|
|
199
|
+
)
|
|
200
|
+
handle: str = Field(description="Owner handle used in qualified project names.")
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
# Publish the json shape: attribution serializes to a user@computer label.
|
|
204
|
+
ActorLabel = Annotated[
|
|
205
|
+
Actor | None, WithJsonSchema({"anyOf": [{"type": "string"}, {"type": "null"}]})
|
|
206
|
+
]
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
class Attributed(BaseModel):
|
|
210
|
+
created_by: ActorLabel = None
|
|
211
|
+
updated_by: ActorLabel = None
|
|
212
|
+
|
|
213
|
+
@field_serializer("created_by", "updated_by", when_used="json")
|
|
214
|
+
def actor_text(self, value: Actor | None) -> str | None:
|
|
215
|
+
return principal_label(value.principal, value.computer) if value is not None else None
|
|
216
|
+
|
|
217
|
+
@field_validator("created_by", "updated_by", mode="before")
|
|
218
|
+
@classmethod
|
|
219
|
+
def parse_actor(cls, value: Any) -> Any:
|
|
220
|
+
if isinstance(value, str):
|
|
221
|
+
return Actor.model_validate({"principal": value})
|
|
222
|
+
return value
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
class ProjectRootOut(BaseModel):
|
|
226
|
+
principal: str = Field(description="User this binding belongs to.")
|
|
227
|
+
computer: str = Field(description="Computer this binding belongs to.")
|
|
228
|
+
root: str = Field(description="Root directory; empty when the project has no files here.")
|
|
229
|
+
|
|
230
|
+
@model_serializer(when_used="json")
|
|
231
|
+
def root_text(self) -> str:
|
|
232
|
+
return f"{principal_label(self.principal, self.computer)}:{self.root}"
|
|
233
|
+
|
|
234
|
+
@model_validator(mode="before")
|
|
235
|
+
@classmethod
|
|
236
|
+
def parse_root(cls, value: object) -> object:
|
|
237
|
+
if isinstance(value, str):
|
|
238
|
+
actor, separator, root = value.partition(":")
|
|
239
|
+
principal, at, computer = actor.rpartition("@")
|
|
240
|
+
if not separator or not at or not principal or not computer:
|
|
241
|
+
raise ValueError("root must use user@computer:path format")
|
|
242
|
+
return {"principal": unquote(principal), "computer": unquote(computer), "root": root}
|
|
243
|
+
return value
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
# Publish the json shape: a binding serializes to user@computer:path text.
|
|
247
|
+
ProjectRoot = Annotated[ProjectRootOut, WithJsonSchema({"type": "string"})]
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
class ProjectOut(Attributed):
|
|
251
|
+
"""A project with its task counts."""
|
|
252
|
+
|
|
253
|
+
id: int
|
|
254
|
+
slug: str
|
|
255
|
+
full_name: str = Field(description="Stable owner/slug project reference.")
|
|
256
|
+
name: str
|
|
257
|
+
owner: str
|
|
258
|
+
role: str
|
|
259
|
+
|
|
260
|
+
@field_serializer("owner", when_used="json")
|
|
261
|
+
def owner_text(self, value: str) -> str:
|
|
262
|
+
return principal_label(value)
|
|
263
|
+
|
|
264
|
+
roots: list[ProjectRoot] = Field(default_factory=list)
|
|
265
|
+
here: bool = Field(
|
|
266
|
+
description=("True when this computer has a non-empty filesystem binding for the project.")
|
|
267
|
+
)
|
|
268
|
+
description: str = ""
|
|
269
|
+
preferred_language: str | None = Field(
|
|
270
|
+
default=None,
|
|
271
|
+
description="Language to use for project work and task text; null means no preference.",
|
|
272
|
+
)
|
|
273
|
+
archived: bool = False
|
|
274
|
+
open_tasks: int = 0
|
|
275
|
+
total_tasks: int = 0
|
|
276
|
+
created_at: Seconds
|
|
277
|
+
updated_at: Seconds
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
class CommentOut(Actor):
|
|
281
|
+
id: int = Field(description="Stable comment id.")
|
|
282
|
+
task_id: int
|
|
283
|
+
task_assigned: NullableAssignment = Field(
|
|
284
|
+
default=None,
|
|
285
|
+
description="Current task assignment, not a historical snapshot.",
|
|
286
|
+
)
|
|
287
|
+
project: str
|
|
288
|
+
body: str
|
|
289
|
+
kind: Literal["comment", "status", "move"] = "comment"
|
|
290
|
+
created_at: Seconds
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
class Comments(Actor):
|
|
294
|
+
items: list[CommentOut]
|
|
295
|
+
task_id: int
|
|
296
|
+
count: int = Field(description="Total number of comments and history entries.")
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
class TaskOut(Attributed):
|
|
300
|
+
id: int
|
|
301
|
+
project: str = Field(description="Owner-qualified name of the owning project.")
|
|
302
|
+
title: str
|
|
303
|
+
body: str = ""
|
|
304
|
+
status: Status
|
|
305
|
+
assigned: NullableAssignment = Field(
|
|
306
|
+
default=None, description="Current username@computer:marker, or null when unassigned."
|
|
307
|
+
)
|
|
308
|
+
priority: Priority
|
|
309
|
+
tags: list[str] = Field(default_factory=list)
|
|
310
|
+
created_at: Seconds
|
|
311
|
+
updated_at: Seconds
|
|
312
|
+
closed_at: Seconds | None = None
|
|
313
|
+
snippet: str | None = Field(default=None, description="Matched text, search results only.")
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
class TaskLinkOut(BaseModel):
|
|
317
|
+
task: int = Field(description="The linked task id.")
|
|
318
|
+
project: str
|
|
319
|
+
relation: Relation = Field(description="Relation from the requested task to this task.")
|
|
320
|
+
title: str
|
|
321
|
+
status: Status
|
|
322
|
+
reason: str = ""
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
class LinkChange(BaseModel):
|
|
326
|
+
task: int
|
|
327
|
+
relation: Relation
|
|
328
|
+
target: int
|
|
329
|
+
changed: bool
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
class TaskDetails(TaskOut):
|
|
333
|
+
comments: list[CommentOut] = Field(default_factory=list)
|
|
334
|
+
links: list[TaskLinkOut] = Field(default_factory=list)
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
class TaskListItem(Attributed):
|
|
338
|
+
"""Compact task metadata for listings; retrieve the task for its full body."""
|
|
339
|
+
|
|
340
|
+
id: int
|
|
341
|
+
project: str = Field(description="Owner-qualified name of the owning project.")
|
|
342
|
+
title: str
|
|
343
|
+
status: Status
|
|
344
|
+
assigned: NullableAssignment = None
|
|
345
|
+
priority: Priority
|
|
346
|
+
tags: list[str] = Field(default_factory=list)
|
|
347
|
+
created_at: Seconds
|
|
348
|
+
updated_at: Seconds
|
|
349
|
+
closed_at: Seconds | None = None
|
|
350
|
+
snippet: str = Field(
|
|
351
|
+
description="First meaningful body paragraph, shortened to 150 characters."
|
|
352
|
+
)
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
class NoteOut(Attributed):
|
|
356
|
+
"""A piece of knowledge about a project: a titled markdown text, addressed by id."""
|
|
357
|
+
|
|
358
|
+
id: int
|
|
359
|
+
project: str = Field(description="Owner-qualified name of the owning project.")
|
|
360
|
+
title: str
|
|
361
|
+
body: str = ""
|
|
362
|
+
tags: list[str] = Field(default_factory=list)
|
|
363
|
+
global_scope: bool = Field(
|
|
364
|
+
default=False, description="Visible in all projects, to the same audience."
|
|
365
|
+
)
|
|
366
|
+
shared: bool = Field(
|
|
367
|
+
default=False,
|
|
368
|
+
description="True: project members can read it. False: only the entry author can read it.",
|
|
369
|
+
)
|
|
370
|
+
created_at: Seconds
|
|
371
|
+
updated_at: Seconds
|
|
372
|
+
snippet: str | None = Field(default=None, description="Matched text, search results only.")
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
class NoteListItem(Attributed):
|
|
376
|
+
"""Compact note metadata for listings; retrieve the note for its full body."""
|
|
377
|
+
|
|
378
|
+
id: int
|
|
379
|
+
project: str = Field(description="Owner-qualified name of the owning project.")
|
|
380
|
+
title: str
|
|
381
|
+
tags: list[str] = Field(default_factory=list)
|
|
382
|
+
global_scope: bool = Field(
|
|
383
|
+
default=False, description="Visible in all projects, to the same audience."
|
|
384
|
+
)
|
|
385
|
+
shared: bool = Field(
|
|
386
|
+
default=False,
|
|
387
|
+
description="True: project members can read it. False: only the entry author can read it.",
|
|
388
|
+
)
|
|
389
|
+
created_at: Seconds
|
|
390
|
+
updated_at: Seconds
|
|
391
|
+
snippet: str = Field(
|
|
392
|
+
description="First meaningful body paragraph, shortened to 150 characters."
|
|
393
|
+
)
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
class Projects(Actor):
|
|
397
|
+
items: list[ProjectOut]
|
|
398
|
+
count: int
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
class Tasks(Actor):
|
|
402
|
+
items: list[TaskListItem]
|
|
403
|
+
count: int
|
|
404
|
+
project: str | None = Field(
|
|
405
|
+
default=None, description="Owner-qualified project searched, absent when global."
|
|
406
|
+
)
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
class Notes(Actor):
|
|
410
|
+
items: list[NoteListItem]
|
|
411
|
+
count: int
|
|
412
|
+
project: str | None = Field(
|
|
413
|
+
default=None, description="Owner-qualified project searched, absent when global."
|
|
414
|
+
)
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
class FullTasks(Actor):
|
|
418
|
+
"""Task listing with complete task bodies."""
|
|
419
|
+
|
|
420
|
+
items: list[TaskOut]
|
|
421
|
+
count: int
|
|
422
|
+
project: str | None = Field(
|
|
423
|
+
default=None, description="Owner-qualified project searched, absent when global."
|
|
424
|
+
)
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
class FullNotes(Actor):
|
|
428
|
+
"""Note listing with complete note bodies."""
|
|
429
|
+
|
|
430
|
+
items: list[NoteOut]
|
|
431
|
+
count: int
|
|
432
|
+
project: str | None = Field(
|
|
433
|
+
default=None, description="Owner-qualified project searched, absent when global."
|
|
434
|
+
)
|
|
435
|
+
|
|
436
|
+
|
|
437
|
+
class BoardProject(BaseModel):
|
|
438
|
+
id: int
|
|
439
|
+
full_name: str
|
|
440
|
+
name: str
|
|
441
|
+
description: str
|
|
442
|
+
preferred_language: str | None
|
|
443
|
+
role: str
|
|
444
|
+
archived: bool
|
|
445
|
+
roots: list[ProjectRoot]
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
class BoardCounts(BaseModel):
|
|
449
|
+
total: int = Field(description="All project tasks, including closed and deleted tasks.")
|
|
450
|
+
open: int
|
|
451
|
+
claimed: int = Field(description="Open tasks with an assignment.")
|
|
452
|
+
unclaimed: int = Field(description="Open tasks without an assignment.")
|
|
453
|
+
blocked: int = Field(description="Open tasks blocked by status or dependencies.")
|
|
454
|
+
done: int
|
|
455
|
+
cancelled: int
|
|
456
|
+
deleted: int
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
class BoardTask(BaseModel):
|
|
460
|
+
id: int
|
|
461
|
+
title: str
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
class BoardSection(BaseModel):
|
|
465
|
+
count: int
|
|
466
|
+
items: list[BoardTask]
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
class ProjectBoard(Actor):
|
|
470
|
+
project: BoardProject
|
|
471
|
+
tasks: BoardCounts
|
|
472
|
+
global_memory: list[NoteOut] = Field(
|
|
473
|
+
default_factory=list, description="All visible global memory entries with full bodies."
|
|
474
|
+
)
|
|
475
|
+
memory: int = Field(
|
|
476
|
+
description="Personal and project-shared memory, plus visible global entries."
|
|
477
|
+
)
|
|
478
|
+
ready: BoardSection = Field(description="Unassigned, unblocked tasks; up to ten by priority.")
|
|
479
|
+
claimed: BoardSection = Field(
|
|
480
|
+
description="Open tasks assigned to this principal and computer, across all markers."
|
|
481
|
+
)
|
|
482
|
+
|
|
483
|
+
|
|
484
|
+
class Stats(Actor):
|
|
485
|
+
project: str | None = None
|
|
486
|
+
this_computer: str = Field(description="Computer this session works from.")
|
|
487
|
+
total: int = 0
|
|
488
|
+
open: int = Field(default=0, description="Tasks with status todo, doing, or blocked.")
|
|
489
|
+
closed: int = Field(default=0, description="Tasks with status done or cancelled.")
|
|
490
|
+
by_status: dict[str, int] = Field(default_factory=dict)
|
|
491
|
+
by_priority: dict[str, int] = Field(default_factory=dict)
|
|
492
|
+
tags: list[str] = Field(default_factory=list)
|
|
493
|
+
memory: int = Field(default=0, description="Memory entries in scope, including shared entries.")
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+
class Deleted(Actor):
|
|
497
|
+
id: int
|
|
498
|
+
title: str
|
|
499
|
+
deleted: bool
|
|
500
|
+
detail: str = ""
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
class ProjectDeleted(Actor):
|
|
504
|
+
"""What `project_delete` found on the board, and whether the project is gone."""
|
|
505
|
+
|
|
506
|
+
id: int
|
|
507
|
+
slug: str
|
|
508
|
+
full_name: str
|
|
509
|
+
name: str
|
|
510
|
+
tasks: int = Field(description="Tasks the project held, deleted ones included.")
|
|
511
|
+
memory: int = Field(description="Memory entries the project held, including shared entries.")
|
|
512
|
+
shared_notes: int = Field(
|
|
513
|
+
title="Shared memory", description="Shared memory entries the project held."
|
|
514
|
+
)
|
|
515
|
+
deleted: bool
|
|
516
|
+
detail: str = ""
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
__all__ = [
|
|
520
|
+
"RELATIONS",
|
|
521
|
+
"Relation",
|
|
522
|
+
"relation",
|
|
523
|
+
"TaskLinkOut",
|
|
524
|
+
"LinkChange",
|
|
525
|
+
"CLOSED_STATUSES",
|
|
526
|
+
"OPEN_STATUSES",
|
|
527
|
+
"PRIORITIES",
|
|
528
|
+
"RANKS",
|
|
529
|
+
"Deleted",
|
|
530
|
+
"CommentOut",
|
|
531
|
+
"Comments",
|
|
532
|
+
"TaskDetails",
|
|
533
|
+
"NoteOut",
|
|
534
|
+
"Notes",
|
|
535
|
+
"Origin",
|
|
536
|
+
"Priority",
|
|
537
|
+
"ProjectDeleted",
|
|
538
|
+
"ProjectOut",
|
|
539
|
+
"ProjectRoot",
|
|
540
|
+
"ProjectRootOut",
|
|
541
|
+
"Projects",
|
|
542
|
+
"ProjectBoard",
|
|
543
|
+
"Stats",
|
|
544
|
+
"Status",
|
|
545
|
+
"TaskOut",
|
|
546
|
+
"Tasks",
|
|
547
|
+
]
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
EVENT_KEY = "backlog/event"
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
class Kind(StrEnum):
|
|
554
|
+
TASK = "task"
|
|
555
|
+
NOTE = "memory"
|
|
556
|
+
PROJECT = "project"
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
class Action(StrEnum):
|
|
560
|
+
ADDED = "added"
|
|
561
|
+
UPDATED = "updated"
|
|
562
|
+
MOVED = "moved"
|
|
563
|
+
DELETED = "deleted"
|
|
564
|
+
|
|
565
|
+
|
|
566
|
+
class Event(Actor):
|
|
567
|
+
"""What a write did.
|
|
568
|
+
|
|
569
|
+
Travels in `_meta["backlog/event"]` of each `notifications/resources/updated`.
|
|
570
|
+
"""
|
|
571
|
+
|
|
572
|
+
principal: str
|
|
573
|
+
project_id: int | None = None
|
|
574
|
+
kind: Kind
|
|
575
|
+
action: Action
|
|
576
|
+
id: int
|
|
577
|
+
project: str = Field(description="Owner-qualified project name after the write.")
|
|
578
|
+
title: str
|
|
579
|
+
status: Status | None = Field(default=None, description="Tasks only.")
|
|
580
|
+
priority: Priority | None = Field(default=None, description="Tasks only.")
|
|
581
|
+
computer: str = Field(description="Computer the writing client works from.")
|
backlog_mcp/names.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""Stable project owner names, separate from display names and filesystem paths."""
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
from urllib.parse import quote, unquote
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def owner_name(identity: str) -> str:
|
|
8
|
+
"""Escape usernames for unambiguous owner/project names."""
|
|
9
|
+
handle = quote(identity, safe="")
|
|
10
|
+
if handle.startswith((".", "~")):
|
|
11
|
+
handle = f"%{ord(handle[0]):02X}" + handle[1:]
|
|
12
|
+
return handle
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def project_name(identity: str, slug: str) -> str:
|
|
16
|
+
return f"{owner_name(identity)}/{slug}"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def default_user(value: str | None = None) -> str:
|
|
20
|
+
"""Resolve the default username for transports without an authorizer."""
|
|
21
|
+
username = value if value is not None else os.environ.get("USER", "")
|
|
22
|
+
if not username.strip() or username != username.strip() or ":" in username:
|
|
23
|
+
raise ValueError("set --default-user or a valid USER environment variable")
|
|
24
|
+
return username
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def principal_label(user: str, computer: str | None = None) -> str:
|
|
28
|
+
"""Display an account with its computer context; escape separators in either part."""
|
|
29
|
+
return f"{quote(user, safe='')}@{quote(computer or 'unknown', safe='')}"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def principal_user(value: str) -> str:
|
|
33
|
+
"""Accept a tool's user@computer label or a plain username without an @ sign."""
|
|
34
|
+
user, separator, _computer = value.rpartition("@")
|
|
35
|
+
return unquote(user) if separator else value
|
backlog_mcp/paths.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""XDG base directories for the database and the config files.
|
|
2
|
+
|
|
3
|
+
Environment overrides are not read here. `argclass` binds `BACKLOG_MCP_*` variables to the
|
|
4
|
+
command-line arguments, so every override arrives through one path.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import os
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
APP = "backlog-mcp"
|
|
13
|
+
|
|
14
|
+
#: Read as TOML, lowest priority first. A missing file is skipped.
|
|
15
|
+
SYSTEM_CONFIG = Path("/etc") / APP / "config.toml"
|
|
16
|
+
LOCAL_CONFIG = Path(".") / f".{APP}.toml"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def base(variable: str, fallback: str) -> Path:
|
|
20
|
+
"""An XDG base directory. The specification says to ignore a relative value."""
|
|
21
|
+
value = os.environ.get(variable, "")
|
|
22
|
+
if value and os.path.isabs(value):
|
|
23
|
+
return Path(value)
|
|
24
|
+
return Path.home() / fallback
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def data_home() -> Path:
|
|
28
|
+
return base("XDG_DATA_HOME", ".local/share")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def config_home() -> Path:
|
|
32
|
+
return base("XDG_CONFIG_HOME", ".config")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def database_path() -> Path:
|
|
36
|
+
"""Where the tasks live."""
|
|
37
|
+
return data_home() / APP / "backlog.sqlite3"
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def config_files() -> list[Path]:
|
|
41
|
+
"""The config search list: system, then user, then the current directory."""
|
|
42
|
+
return [SYSTEM_CONFIG, config_home() / APP / "config.toml", LOCAL_CONFIG]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
__all__ = [
|
|
46
|
+
"APP",
|
|
47
|
+
"LOCAL_CONFIG",
|
|
48
|
+
"SYSTEM_CONFIG",
|
|
49
|
+
"config_files",
|
|
50
|
+
"config_home",
|
|
51
|
+
"data_home",
|
|
52
|
+
"database_path",
|
|
53
|
+
]
|