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.
Files changed (97) hide show
  1. backlog_mcp/__init__.py +29 -0
  2. backlog_mcp/__main__.py +10 -0
  3. backlog_mcp/auth.py +199 -0
  4. backlog_mcp/backlog.py +696 -0
  5. backlog_mcp/cli.py +2046 -0
  6. backlog_mcp/client.py +320 -0
  7. backlog_mcp/computer.py +33 -0
  8. backlog_mcp/database.py +80 -0
  9. backlog_mcp/embeddings.py +900 -0
  10. backlog_mcp/global_rules.md +126 -0
  11. backlog_mcp/guidance.py +11 -0
  12. backlog_mcp/guide/index.md +11 -0
  13. backlog_mcp/guide/memory.md +27 -0
  14. backlog_mcp/guide/projects.md +16 -0
  15. backlog_mcp/guide/search.md +72 -0
  16. backlog_mcp/guide/tasks.md +40 -0
  17. backlog_mcp/guide/workflow.md +22 -0
  18. backlog_mcp/httpd.py +270 -0
  19. backlog_mcp/migrate.py +113 -0
  20. backlog_mcp/migrations/0001-initial.sql +194 -0
  21. backlog_mcp/migrations/0002-task-assignment.sql +2 -0
  22. backlog_mcp/migrations/0003-task-edit-claims.sql +5 -0
  23. backlog_mcp/migrations/0004-memory-visibility.sql +42 -0
  24. backlog_mcp/model/CITATION.bib +9 -0
  25. backlog_mcp/model/LICENSE +202 -0
  26. backlog_mcp/model/README.md +12 -0
  27. backlog_mcp/model/UPSTREAM.md +2053 -0
  28. backlog_mcp/model/config.json +12 -0
  29. backlog_mcp/model/model.safetensors +4 -0
  30. backlog_mcp/model/modules.json +14 -0
  31. backlog_mcp/model/provenance.json +16 -0
  32. backlog_mcp/model/tokenizer.json +1 -0
  33. backlog_mcp/models.py +581 -0
  34. backlog_mcp/names.py +35 -0
  35. backlog_mcp/paths.py +53 -0
  36. backlog_mcp/protocol_storage.py +104 -0
  37. backlog_mcp/queries.py +7 -0
  38. backlog_mcp/queries.sql +531 -0
  39. backlog_mcp/records.py +215 -0
  40. backlog_mcp/render.py +479 -0
  41. backlog_mcp/server.py +2864 -0
  42. backlog_mcp/skills/autopilot/SKILL.md +96 -0
  43. backlog_mcp/skills/planning/SKILL.md +106 -0
  44. backlog_mcp/skills/planning/references/splitting.md +45 -0
  45. backlog_mcp/skills/triage/SKILL.md +104 -0
  46. backlog_mcp/skills/triage/references/conventions.md +43 -0
  47. backlog_mcp/skills.py +56 -0
  48. backlog_mcp/static/agent-config.js +20 -0
  49. backlog_mcp/static/app.css +1950 -0
  50. backlog_mcp/static/app.js +1301 -0
  51. backlog_mcp/static/assignments.js +96 -0
  52. backlog_mcp/static/breadcrumbs.js +54 -0
  53. backlog_mcp/static/comment-composer.js +95 -0
  54. backlog_mcp/static/connect.css +98 -0
  55. backlog_mcp/static/connect.html +74 -0
  56. backlog_mcp/static/connect.js +160 -0
  57. backlog_mcp/static/credentials.js +72 -0
  58. backlog_mcp/static/diagrams.js +128 -0
  59. backlog_mcp/static/dom.js +162 -0
  60. backlog_mcp/static/editor-claim.js +104 -0
  61. backlog_mcp/static/editor.js +355 -0
  62. backlog_mcp/static/index.html +137 -0
  63. backlog_mcp/static/markdown.css +33 -0
  64. backlog_mcp/static/markdown.js +72 -0
  65. backlog_mcp/static/mcp.js +177 -0
  66. backlog_mcp/static/memory-append.js +34 -0
  67. backlog_mcp/static/memory-editor.js +173 -0
  68. backlog_mcp/static/memory.js +279 -0
  69. backlog_mcp/static/package.json +1 -0
  70. backlog_mcp/static/project-form.js +71 -0
  71. backlog_mcp/static/project-settings.js +225 -0
  72. backlog_mcp/static/scope.js +90 -0
  73. backlog_mcp/static/statistics.js +87 -0
  74. backlog_mcp/static/task-browser.js +100 -0
  75. backlog_mcp/static/task-pagination.js +94 -0
  76. backlog_mcp/static/task-picker.js +164 -0
  77. backlog_mcp/static/task-table.js +74 -0
  78. backlog_mcp/static/vendor/README.md +12 -0
  79. backlog_mcp/static/vendor/dompurify-LICENSE +202 -0
  80. backlog_mcp/static/vendor/highlight-LICENSE +29 -0
  81. backlog_mcp/static/vendor/highlight-dark.css +118 -0
  82. backlog_mcp/static/vendor/highlight-light.css +118 -0
  83. backlog_mcp/static/vendor/highlight.min.js +1262 -0
  84. backlog_mcp/static/vendor/marked-LICENSE +44 -0
  85. backlog_mcp/static/vendor/marked.esm.js +80 -0
  86. backlog_mcp/static/vendor/marked.esm.js.map +7 -0
  87. backlog_mcp/static/vendor/mermaid-LICENSE +21 -0
  88. backlog_mcp/static/vendor/mermaid.min.js +4376 -0
  89. backlog_mcp/static/vendor/purify.es.mjs +2722 -0
  90. backlog_mcp/static/vendor/purify.es.mjs.map +1 -0
  91. backlog_mcp/transaction.py +47 -0
  92. backlog_mcp/version.py +79 -0
  93. backlog_mcp/webui.py +63 -0
  94. backlog_tiny_mcp-0.34.2.dist-info/METADATA +84 -0
  95. backlog_tiny_mcp-0.34.2.dist-info/RECORD +97 -0
  96. backlog_tiny_mcp-0.34.2.dist-info/WHEEL +4 -0
  97. backlog_tiny_mcp-0.34.2.dist-info/entry_points.txt +4 -0
backlog_mcp/records.py ADDED
@@ -0,0 +1,215 @@
1
+ """Internal records, row conversion and input normalization."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+ from collections.abc import Iterable
7
+ from dataclasses import dataclass, field
8
+ from enum import Enum
9
+ from typing import Literal
10
+
11
+ import aiosqlite
12
+
13
+ from .models import PRIORITIES, Actor, Priority, Status
14
+ from .names import project_name
15
+
16
+ LOCAL_PRINCIPAL = "local"
17
+
18
+ #: A note is a short fact, not a page; the body stops here, in characters.
19
+ NOTE_LIMIT = 1024
20
+
21
+
22
+ def clean_tags(tags: Iterable[str]) -> list[str]:
23
+ """Tags are lower-case, unique and sorted, so listings and completion are stable."""
24
+ return sorted({tag.strip().lower() for tag in tags if tag.strip()})
25
+
26
+
27
+ def join_tags(tags: Iterable[str]) -> str:
28
+ return ",".join(clean_tags(tags))
29
+
30
+
31
+ def split_tags(text: str) -> list[str]:
32
+ return [tag for tag in text.split(",") if tag]
33
+
34
+
35
+ def check_note(body: str) -> None:
36
+ """Refuse a body longer than `NOTE_LIMIT`, before anything is written."""
37
+ if len(body) > NOTE_LIMIT:
38
+ raise ValueError(f"a note holds at most {NOTE_LIMIT} characters, this one has {len(body)}")
39
+
40
+
41
+ def match_query(text: str) -> str:
42
+ """Turn user text into an FTS5 prefix query where every token must match.
43
+
44
+ Quoting each token keeps FTS5 operators out of the query, so no input is a syntax error.
45
+ """
46
+ return " ".join(f'"{token}"*' for token in re.findall(r"\w+", text))
47
+
48
+
49
+ def assignment_pattern(prefix: str) -> str:
50
+ """Escape a literal assignment prefix for LIKE."""
51
+ return prefix.replace("\\", "\\\\").replace("%", "\\%").replace("_", "\\_") + "%"
52
+
53
+
54
+ class Unset(Enum):
55
+ """An omitted update field; None explicitly clears a nullable value."""
56
+
57
+ VALUE = 0
58
+
59
+
60
+ class AssignmentConflict(ValueError):
61
+ """The current assignment did not match the caller's expected value."""
62
+
63
+ def __init__(self, task_id: int, expected: str | None, assigned: str | None) -> None:
64
+ self.assigned = assigned
65
+ super().__init__(
66
+ f"assignment conflict for task #{task_id}: expected {expected!r}, current {assigned!r}"
67
+ )
68
+
69
+
70
+ @dataclass(slots=True)
71
+ class Comment:
72
+ id: int
73
+ task_id: int
74
+ project_id: int
75
+ project: str
76
+ body: str
77
+ kind: Literal["comment", "status", "move"]
78
+ created_at: float
79
+ task_assigned: str | None = None
80
+ principal: str = LOCAL_PRINCIPAL
81
+ computer: str = ""
82
+ snippet: str | None = None
83
+
84
+
85
+ @dataclass(slots=True)
86
+ class Project:
87
+ id: int
88
+ slug: str
89
+ name: str
90
+ description: str
91
+ archived: bool
92
+ created_at: float
93
+ updated_at: float
94
+ total_tasks: int = 0
95
+ open_tasks: int = 0
96
+ roots: list[ProjectRoot] = field(default_factory=list)
97
+ preferred_language: str | None = None
98
+ owner: str = LOCAL_PRINCIPAL
99
+ role: str = "owner"
100
+ created_by: Actor | None = None
101
+ updated_by: Actor | None = None
102
+
103
+ @property
104
+ def full_name(self) -> str:
105
+ return project_name(self.owner, self.slug)
106
+
107
+
108
+ @dataclass(frozen=True, slots=True)
109
+ class ProjectRoot:
110
+ computer: str
111
+ root: str
112
+
113
+
114
+ @dataclass(frozen=True, slots=True)
115
+ class ProjectContents:
116
+ """What a project holds, counted before it is deleted."""
117
+
118
+ tasks: int
119
+ notes: int
120
+ shared_notes: int
121
+
122
+
123
+ @dataclass(slots=True)
124
+ class Task:
125
+ id: int
126
+ project_id: int
127
+ project: str
128
+ title: str
129
+ body: str
130
+ status: Status
131
+ priority: Priority
132
+ tags: list[str]
133
+ created_at: float
134
+ updated_at: float
135
+ assigned: str | None = None
136
+ closed_at: float | None = None
137
+ snippet: str | None = None
138
+ created_by: Actor | None = None
139
+ updated_by: Actor | None = None
140
+
141
+
142
+ @dataclass(slots=True)
143
+ class Note:
144
+ id: int
145
+ project_id: int
146
+ project: str
147
+ title: str
148
+ body: str
149
+ tags: list[str]
150
+ shared: bool
151
+ created_at: float
152
+ updated_at: float
153
+ global_scope: bool = False
154
+ snippet: str | None = None
155
+ created_by: Actor | None = None
156
+ updated_by: Actor | None = None
157
+
158
+
159
+ def to_project(row: aiosqlite.Row) -> Project:
160
+ keys = row.keys()
161
+ return Project(
162
+ id=row["id"],
163
+ created_by=Actor(principal=row["created_principal"], computer=row["created_computer"]),
164
+ updated_by=Actor(principal=row["updated_principal"], computer=row["updated_computer"]),
165
+ slug=row["slug"],
166
+ owner=row["owner"],
167
+ name=row["name"],
168
+ description=row["description"],
169
+ preferred_language=row["preferred_language"],
170
+ archived=bool(row["archived"]),
171
+ created_at=row["created_at"],
172
+ updated_at=row["updated_at"],
173
+ total_tasks=row["total_tasks"] if "total_tasks" in keys else 0,
174
+ open_tasks=row["open_tasks"] if "open_tasks" in keys else 0,
175
+ )
176
+
177
+
178
+ def to_task(row: aiosqlite.Row) -> Task:
179
+ keys = row.keys()
180
+ return Task(
181
+ id=row["id"],
182
+ created_by=Actor(principal=row["created_principal"], computer=row["created_computer"]),
183
+ updated_by=Actor(principal=row["updated_principal"], computer=row["updated_computer"]),
184
+ project_id=row["project_id"],
185
+ project=row["project"],
186
+ title=row["title"],
187
+ body=row["body"],
188
+ status=Status(row["status"]),
189
+ assigned=row["assigned"],
190
+ priority=PRIORITIES.get(row["priority"], Priority.NORMAL),
191
+ tags=split_tags(row["tags"]),
192
+ created_at=row["created_at"],
193
+ updated_at=row["updated_at"],
194
+ closed_at=row["closed_at"],
195
+ snippet=row["snippet"] if "snippet" in keys else None,
196
+ )
197
+
198
+
199
+ def to_note(row: aiosqlite.Row) -> Note:
200
+ keys = row.keys()
201
+ return Note(
202
+ id=row["id"],
203
+ created_by=Actor(principal=row["created_principal"], computer=row["created_computer"]),
204
+ updated_by=Actor(principal=row["updated_principal"], computer=row["updated_computer"]),
205
+ project_id=row["project_id"],
206
+ project=row["project"],
207
+ title=row["title"],
208
+ body=row["body"],
209
+ tags=split_tags(row["tags"]),
210
+ shared=bool(row["shared"]),
211
+ global_scope=bool(row["global_scope"]) if "global_scope" in keys else False,
212
+ created_at=row["created_at"],
213
+ updated_at=row["updated_at"],
214
+ snippet=row["snippet"] if "snippet" in keys else None,
215
+ )
backlog_mcp/render.py ADDED
@@ -0,0 +1,479 @@
1
+ """Terminal output: tables, panels and colours for the command line."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import sys
6
+ import time
7
+ from collections.abc import Sequence
8
+ from datetime import datetime
9
+
10
+ from rich.box import ROUNDED
11
+ from rich.console import Console, Group, RenderableType
12
+ from rich.markdown import Markdown
13
+ from rich.panel import Panel
14
+ from rich.rule import Rule
15
+ from rich.table import Table
16
+ from rich.text import Text
17
+
18
+ from .client import RemoteSkill
19
+ from .models import (
20
+ Action,
21
+ CommentOut,
22
+ Event,
23
+ NoteOut,
24
+ Priority,
25
+ ProjectBoard,
26
+ ProjectOut,
27
+ Stats,
28
+ Status,
29
+ TaskDetails,
30
+ TaskOut,
31
+ )
32
+ from .names import principal_label
33
+
34
+ STATUS_STYLE = {
35
+ Status.TODO: "white",
36
+ Status.DOING: "bold cyan",
37
+ Status.BLOCKED: "bold red",
38
+ Status.DONE: "green",
39
+ Status.CANCELLED: "dim strike",
40
+ Status.DELETED: "dim red strike",
41
+ }
42
+
43
+ PRIORITY_STYLE = {
44
+ Priority.URGENT: "bold red",
45
+ Priority.HIGH: "yellow",
46
+ Priority.NORMAL: "default",
47
+ Priority.LOW: "dim",
48
+ }
49
+
50
+ UNITS = ((86400.0, "d"), (3600.0, "h"), (60.0, "m"))
51
+
52
+
53
+ def terminal(*, stderr: bool = False) -> Console:
54
+ """A console that colours a terminal only.
55
+
56
+ Rich obeys `FORCE_COLOR` even on a pipe or a file. A stream that is not a TTY gets no
57
+ control codes at all, so captured output stays plain text.
58
+ """
59
+ stream = sys.stderr if stderr else sys.stdout
60
+ return Console(stderr=stderr, force_terminal=None if stream.isatty() else False)
61
+
62
+
63
+ console = terminal()
64
+ errors = terminal(stderr=True)
65
+
66
+
67
+ def age(moment: float) -> str:
68
+ """How long ago, in one or two characters plus a unit."""
69
+ passed = max(time.time() - moment, 0.0)
70
+ for size, unit in UNITS:
71
+ if passed >= size:
72
+ return f"{int(passed // size)}{unit}"
73
+ return "now"
74
+
75
+
76
+ def since(moment: float) -> str:
77
+ """How long ago, as a phrase."""
78
+ passed = age(moment)
79
+ return "just now" if passed == "now" else f"{passed} ago"
80
+
81
+
82
+ def titled(title: str) -> Table:
83
+ """An empty table wide enough for its own title, so the heading never wraps."""
84
+ return Table(
85
+ box=ROUNDED,
86
+ title=title,
87
+ title_justify="left",
88
+ expand=False,
89
+ min_width=min(len(title) + 4, console.width),
90
+ )
91
+
92
+
93
+ def excerpt(snippet: str | None) -> str:
94
+ """A body excerpt on one line, so a match never breaks the row apart."""
95
+ return " ".join((snippet or "").split())
96
+
97
+
98
+ def status_text(status: Status) -> Text:
99
+ return Text(status.value, style=STATUS_STYLE[status])
100
+
101
+
102
+ def priority_text(priority: Priority) -> Text:
103
+ return Text(priority.value, style=PRIORITY_STYLE[priority])
104
+
105
+
106
+ def tasks_table(
107
+ items: Sequence[TaskOut], *, title: str, wide: bool = False, computer: str | None = None
108
+ ) -> Table:
109
+ """One row per task. `wide` adds the project column, for listings across projects.
110
+
111
+ `computer` is the one the command runs on: a column names the computer of the tasks that
112
+ are on another one.
113
+ """
114
+ #: Search results carry an excerpt of the body; a plain listing has none, so no column.
115
+ matched = any(item.snippet for item in items)
116
+ table = titled(title)
117
+ table.add_column("id", justify="right", style="bold")
118
+ if wide:
119
+ table.add_column("project", style="magenta")
120
+ table.add_column("status")
121
+ table.add_column("pri")
122
+ table.add_column("title", overflow="fold")
123
+ assigned = any(item.assigned is not None for item in items)
124
+ if assigned:
125
+ table.add_column("assigned", overflow="fold")
126
+ if matched:
127
+ table.add_column("match", overflow="fold", style="dim italic")
128
+ table.add_column("tags", style="blue")
129
+ table.add_column("age", justify="right", style="dim")
130
+ for item in items:
131
+ row = [str(item.id)]
132
+ if wide:
133
+ row.append(item.project)
134
+ cells: list[str | Text] = [
135
+ *row,
136
+ status_text(item.status),
137
+ priority_text(item.priority),
138
+ Text(item.title),
139
+ ]
140
+ if assigned:
141
+ cells.append(Text(item.assigned or "—"))
142
+ if matched:
143
+ cells.append(Text(excerpt(item.snippet)))
144
+ cells.extend([", ".join(item.tags), age(item.updated_at)])
145
+ table.add_row(*cells)
146
+ return table
147
+
148
+
149
+ def notes_table(
150
+ items: Sequence[NoteOut], *, title: str, wide: bool = False, computer: str | None = None
151
+ ) -> Table:
152
+ """One row per note. `wide` adds the project column, for listings that cross projects."""
153
+ matched = any(item.snippet for item in items)
154
+ shared = any(item.shared for item in items)
155
+ table = titled(title)
156
+ table.add_column("id", justify="right", style="bold")
157
+ if wide:
158
+ table.add_column("project", style="magenta")
159
+ table.add_column("title", overflow="fold")
160
+ if matched:
161
+ table.add_column("match", overflow="fold", style="dim italic")
162
+ if shared:
163
+ table.add_column("shared")
164
+ table.add_column("tags", style="blue")
165
+ table.add_column("age", justify="right", style="dim")
166
+ for item in items:
167
+ cells: list[str | Text] = [str(item.id)]
168
+ if wide:
169
+ cells.append(item.project)
170
+ cells.append(Text(item.title))
171
+ if matched:
172
+ cells.append(Text(excerpt(item.snippet)))
173
+ if shared:
174
+ cells.append(Text("yes", style="green") if item.shared else "")
175
+ cells.extend([", ".join(item.tags), age(item.updated_at)])
176
+ table.add_row(*cells)
177
+ return table
178
+
179
+
180
+ def projects_table(items: Sequence[ProjectOut], *, computer: str | None = None) -> Table:
181
+ """One row per logical project, with all its path bindings."""
182
+ table = titled("projects")
183
+ table.add_column("slug", style="bold magenta")
184
+ table.add_column("open", justify="right")
185
+ table.add_column("total", justify="right", style="dim")
186
+ table.add_column("root", overflow="fold")
187
+ table.add_column("name", overflow="fold", style="dim")
188
+ table.add_column("language")
189
+ for item in items:
190
+ slug = Text(item.full_name, style="dim strike" if item.archived else "bold magenta")
191
+ cells: list[str | Text] = [slug]
192
+ root = Text(", ".join(root.root_text() for root in item.roots))
193
+ cells.extend(
194
+ [
195
+ str(item.open_tasks),
196
+ str(item.total_tasks),
197
+ root,
198
+ item.name,
199
+ Text(item.preferred_language if item.preferred_language is not None else "—"),
200
+ ]
201
+ )
202
+ table.add_row(*cells)
203
+ return table
204
+
205
+
206
+ def skills_table(items: Sequence[RemoteSkill]) -> Table:
207
+ """One row per skill: what it is called, what it is for, how many files it carries."""
208
+ table = titled("skills")
209
+ table.add_column("name", style="bold magenta")
210
+ table.add_column("description", overflow="fold")
211
+ table.add_column("files", justify="right", style="dim")
212
+ for item in items:
213
+ table.add_row(item.name, item.description, str(len(item.files)))
214
+ return table
215
+
216
+
217
+ def fields(rows: Sequence[tuple[str, RenderableType]]) -> Table:
218
+ """A two-column grid: the label dim on the left, the value on the right."""
219
+ grid = Table.grid(padding=(0, 2))
220
+ grid.add_column(style="dim", justify="right", no_wrap=True)
221
+ grid.add_column(overflow="fold")
222
+ for label, value in rows:
223
+ grid.add_row(label, value)
224
+ return grid
225
+
226
+
227
+ def width() -> int:
228
+ """Wide enough for a sentence, never wider than the terminal."""
229
+ return min(console.width, 88)
230
+
231
+
232
+ def owner(item: TaskOut | NoteOut, computer: str | None) -> Text:
233
+ """The logical project that owns a record."""
234
+ return Text(item.project, style="magenta")
235
+
236
+
237
+ def task_panel(task: TaskOut, *, computer: str | None = None) -> Panel:
238
+ """One task in full: the id and title name the panel, the Markdown body follows the fields."""
239
+ rows: list[tuple[str, RenderableType]] = [
240
+ ("status", status_text(task.status)),
241
+ ("assigned", Text(task.assigned or "—")),
242
+ ("priority", priority_text(task.priority)),
243
+ ]
244
+ if task.tags:
245
+ rows.append(("tags", Text(", ".join(task.tags), style="blue")))
246
+ rows.append(("created", Text(since(task.created_at), style="dim")))
247
+ if task.updated_at > task.created_at:
248
+ rows.append(("changed", Text(since(task.updated_at), style="dim")))
249
+ if task.closed_at:
250
+ rows.append(("closed", Text(since(task.closed_at), style="dim")))
251
+ body = task.body.strip()
252
+ parts: list[RenderableType] = [fields(rows), Rule(style="dim")]
253
+ parts.append(Markdown(body) if body else Text("no description", style="dim italic"))
254
+ if isinstance(task, TaskDetails) and task.links:
255
+ parts.append(Rule(f"links ({len(task.links)})", style="dim"))
256
+ for link in task.links:
257
+ parts.append(Text(f"{link.relation} → #{link.task} {link.title} [{link.status}]"))
258
+ parts.append(Text(link.project, style="magenta"))
259
+ if link.reason:
260
+ parts.append(Text(link.reason))
261
+ if isinstance(task, TaskDetails) and task.comments:
262
+ parts.append(Rule(f"comments and history ({len(task.comments)})", style="dim"))
263
+ parts.extend(comment_panel(item) for item in task.comments)
264
+ return Panel(
265
+ Group(*parts),
266
+ box=ROUNDED,
267
+ title=Text.assemble((f"#{task.id}", "bold cyan"), " ", (task.title, "bold")),
268
+ title_align="left",
269
+ subtitle=owner(task, computer),
270
+ subtitle_align="right",
271
+ padding=(1, 2),
272
+ width=width(),
273
+ )
274
+
275
+
276
+ def comment_panel(comment: CommentOut) -> Panel:
277
+ when = datetime.fromtimestamp(comment.created_at).astimezone().isoformat(timespec="seconds")
278
+ return Panel(
279
+ Markdown(comment.body) if comment.body.strip() else Text("empty comment", style="dim"),
280
+ title=Text(f"{comment.kind} #{comment.id} · {when}"),
281
+ title_align="left",
282
+ box=ROUNDED,
283
+ subtitle=Text(
284
+ f"{principal_label(comment.principal, comment.computer)} · task #{comment.task_id}"
285
+ f" · assigned: {comment.task_assigned or '—'}"
286
+ ),
287
+ width=width(),
288
+ )
289
+
290
+
291
+ def comments_table(items: Sequence[CommentOut], *, title: str) -> Table:
292
+ table = titled(title)
293
+ for label in ("comment", "task", "project", "task_assigned", "kind", "match"):
294
+ table.add_column(label, overflow="fold")
295
+ for item in items:
296
+ snippet = getattr(item, "snippet", None) or item.body[:200]
297
+ table.add_row(
298
+ str(item.id),
299
+ str(item.task_id),
300
+ Text(item.project),
301
+ Text(item.task_assigned or "—"),
302
+ item.kind,
303
+ Text(snippet),
304
+ )
305
+ return table
306
+
307
+
308
+ def note_panel(item: NoteOut, *, computer: str | None = None) -> Panel:
309
+ """One note in full: the id and title name the panel, the markdown body follows the fields."""
310
+ rows: list[tuple[str, RenderableType]] = []
311
+ if item.tags:
312
+ rows.append(("tags", Text(", ".join(item.tags), style="blue")))
313
+ if item.shared:
314
+ rows.append(("shared", Text("yes, project members", style="green")))
315
+ if item.global_scope:
316
+ rows.append(("scope", Text("all projects", style="green")))
317
+ rows.append(("created", Text(since(item.created_at), style="dim")))
318
+ if item.updated_at > item.created_at:
319
+ rows.append(("changed", Text(since(item.updated_at), style="dim")))
320
+ body = item.body.strip()
321
+ parts: list[RenderableType] = [fields(rows), Rule(style="dim")]
322
+ parts.append(Markdown(body) if body else Text("no content", style="dim italic"))
323
+ return Panel(
324
+ Group(*parts),
325
+ box=ROUNDED,
326
+ title=Text.assemble((f"note #{item.id}", "bold cyan"), " ", (item.title, "bold")),
327
+ title_align="left",
328
+ subtitle=owner(item, computer),
329
+ subtitle_align="right",
330
+ padding=(1, 2),
331
+ width=width(),
332
+ )
333
+
334
+
335
+ def skill_panel(skill: RemoteSkill) -> Panel:
336
+ """One skill in full: what it is for, what it is made of, then the instructions."""
337
+ rows: list[tuple[str, RenderableType]] = [
338
+ ("description", Text(skill.description)),
339
+ ("uri", Text(skill.uri, style="dim")),
340
+ ]
341
+ for item in skill.references:
342
+ rows.append(("cites", Text(f"{item.uri} ({item.size} bytes)", style="dim")))
343
+ parts: list[RenderableType] = [
344
+ fields(rows),
345
+ Rule(style="dim"),
346
+ Markdown(skill.instructions),
347
+ ]
348
+ return Panel(
349
+ Group(*parts),
350
+ box=ROUNDED,
351
+ title=Text(skill.name, style="bold magenta"),
352
+ title_align="left",
353
+ subtitle=Text("instructions for an MCP client", style="dim"),
354
+ subtitle_align="right",
355
+ padding=(1, 2),
356
+ width=width(),
357
+ )
358
+
359
+
360
+ def stats_view(stats: Stats, *, where: str) -> Table:
361
+ table = titled(f"backlog of {where}")
362
+ table.add_column("bucket", style="bold")
363
+ table.add_column("count", justify="right")
364
+ table.add_row(Text("open tasks", style="bold"), str(stats.open))
365
+ table.add_row(Text("closed tasks", style="bold"), str(stats.closed))
366
+ table.add_row(Text("total tasks", style="bold"), str(stats.total))
367
+ table.add_row(Text("memory", style="bold"), str(stats.memory))
368
+ table.add_section()
369
+ for status in Status:
370
+ table.add_row(status_text(status), str(stats.by_status.get(status.value, 0)))
371
+ table.add_section()
372
+ for priority in Priority:
373
+ table.add_row(priority_text(priority), str(stats.by_priority.get(priority.value, 0)))
374
+ table.add_section()
375
+ if stats.tags:
376
+ table.add_row(Text("tags", style="blue"), Text(", ".join(stats.tags), style="blue"))
377
+ table.add_row(
378
+ Text("principal", style="dim"),
379
+ Text(principal_label(stats.principal, stats.this_computer), style="yellow"),
380
+ )
381
+ return table
382
+
383
+
384
+ def board_panel(board: ProjectBoard) -> Panel:
385
+ project = board.project
386
+ rows: list[tuple[str, RenderableType]] = [
387
+ ("project", Text(project.full_name, style="bold magenta")),
388
+ ("principal", Text(principal_label(board.principal, board.computer))),
389
+ ("role", Text(project.role)),
390
+ ("roots", Text(", ".join(root.root_text() for root in project.roots))),
391
+ ("preferred language", Text(project.preferred_language or "none")),
392
+ ("tasks", Text(f"{board.tasks.open} open of {board.tasks.total}")),
393
+ ("claimed", Text(str(board.tasks.claimed))),
394
+ ("unclaimed", Text(str(board.tasks.unclaimed))),
395
+ ("blocked", Text(str(board.tasks.blocked))),
396
+ ("done", Text(str(board.tasks.done))),
397
+ ("cancelled", Text(str(board.tasks.cancelled))),
398
+ ("deleted", Text(str(board.tasks.deleted))),
399
+ ("memory", Text(str(board.memory))),
400
+ ]
401
+ if project.archived:
402
+ rows.append(("archived", Text("yes")))
403
+ parts: list[RenderableType] = [fields(rows)]
404
+ if project.description:
405
+ parts.append(Markdown(project.description))
406
+ if board.global_memory:
407
+ parts.append(Rule("Global memory"))
408
+ parts.extend(note_panel(entry) for entry in board.global_memory)
409
+ for name, section in (("ready", board.ready), ("claimed", board.claimed)):
410
+ tasks = Table("id", "title", title=f"{name} · {section.count} total · top 10")
411
+ for task in section.items:
412
+ tasks.add_row(str(task.id), Text(task.title))
413
+ parts.append(tasks)
414
+ return Panel(Group(*parts), title=Text(project.name), width=width(), padding=(1, 2))
415
+
416
+
417
+ ACTION_STYLES = {
418
+ Action.ADDED: "green",
419
+ Action.UPDATED: "cyan",
420
+ Action.MOVED: "yellow",
421
+ Action.DELETED: "red",
422
+ }
423
+ STATUS_STYLES = {
424
+ Status.DONE: "green",
425
+ Status.DOING: "cyan",
426
+ Status.BLOCKED: "red",
427
+ Status.CANCELLED: "dim",
428
+ Status.DELETED: "dim",
429
+ }
430
+
431
+
432
+ def event_line(event: Event, *, at: datetime | None = None) -> Text:
433
+ """One event of the backlog as `backlog watch` prints it, stamped with the local time."""
434
+ when = (at or datetime.now()).strftime("%H:%M:%S")
435
+ line = Text(f"{when} ", style="dim")
436
+ line.append(f"{event.kind.value} #{event.id} ", style="bold")
437
+ line.append(event.action.value, style=ACTION_STYLES.get(event.action, ""))
438
+ if event.status is not None:
439
+ line.append(f" {event.status.value}", style=STATUS_STYLES.get(event.status, ""))
440
+ line.append(f" {event.title!r} ")
441
+ line.append(f"[{event.project}] ", style="magenta")
442
+ line.append(f"from {principal_label(event.principal, event.computer)}", style="dim")
443
+ return line
444
+
445
+
446
+ def note(message: str) -> None:
447
+ console.print(Text(message, style="green"))
448
+
449
+
450
+ def warn(message: str) -> None:
451
+ errors.print(Text(message, style="yellow"))
452
+
453
+
454
+ def fail(message: str) -> None:
455
+ errors.print(Text(message, style="bold red"))
456
+
457
+
458
+ __all__ = [
459
+ "age",
460
+ "event_line",
461
+ "excerpt",
462
+ "titled",
463
+ "fields",
464
+ "since",
465
+ "console",
466
+ "errors",
467
+ "fail",
468
+ "note",
469
+ "note_panel",
470
+ "notes_table",
471
+ "projects_table",
472
+ "board_panel",
473
+ "skill_panel",
474
+ "skills_table",
475
+ "stats_view",
476
+ "task_panel",
477
+ "tasks_table",
478
+ "warn",
479
+ ]