backlog-tiny-mcp 0.35.1__tar.gz → 0.36.0__tar.gz

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 (107) hide show
  1. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/PKG-INFO +1 -1
  2. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/pyproject.toml +1 -1
  3. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/pyproject.toml.orig +1 -1
  4. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/cli.py +102 -3
  5. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/db/__init__.py +28 -0
  6. backlog_tiny_mcp-0.36.0/src/backlog_mcp/db/backup.py +154 -0
  7. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/db/postgres/__init__.py +66 -1
  8. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/db/sqlite/__init__.py +33 -1
  9. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/model/model.safetensors +1 -1
  10. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/README.md +0 -0
  11. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/__init__.py +0 -0
  12. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/__main__.py +0 -0
  13. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/auth.py +0 -0
  14. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/backlog.py +0 -0
  15. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/client.py +0 -0
  16. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/computer.py +0 -0
  17. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/db/migrations.py +0 -0
  18. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/db/postgres/migrate.py +0 -0
  19. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/db/postgres/migrations/0001-initial.sql +0 -0
  20. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/db/postgres/migrations/0002-trigram-search.sql +0 -0
  21. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/db/postgres/queries.sql +0 -0
  22. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/db/postgres/transaction.py +0 -0
  23. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/db/sqlite/migrate.py +0 -0
  24. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/db/sqlite/migrations/0001-initial.sql +0 -0
  25. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/db/sqlite/migrations/0002-task-assignment.sql +0 -0
  26. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/db/sqlite/migrations/0003-task-edit-claims.sql +0 -0
  27. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/db/sqlite/migrations/0004-memory-visibility.sql +0 -0
  28. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/db/sqlite/migrations/0005-trigram-search.sql +0 -0
  29. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/db/sqlite/protocol.py +0 -0
  30. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/db/sqlite/queries.sql +0 -0
  31. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/db/sqlite/transaction.py +0 -0
  32. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/embeddings.py +0 -0
  33. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/global_rules.md +0 -0
  34. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/guidance.py +0 -0
  35. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/guide/index.md +0 -0
  36. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/guide/memory.md +0 -0
  37. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/guide/projects.md +0 -0
  38. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/guide/search.md +0 -0
  39. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/guide/tasks.md +0 -0
  40. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/guide/workflow.md +0 -0
  41. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/httpd.py +0 -0
  42. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/model/CITATION.bib +0 -0
  43. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/model/LICENSE +0 -0
  44. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/model/README.md +0 -0
  45. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/model/UPSTREAM.md +0 -0
  46. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/model/config.json +0 -0
  47. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/model/modules.json +0 -0
  48. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/model/provenance.json +0 -0
  49. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/model/tokenizer.json +0 -0
  50. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/models.py +0 -0
  51. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/names.py +0 -0
  52. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/paths.py +0 -0
  53. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/records.py +0 -0
  54. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/render.py +0 -0
  55. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/server.py +0 -0
  56. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/skills/autopilot/SKILL.md +0 -0
  57. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/skills/planning/SKILL.md +0 -0
  58. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/skills/planning/references/splitting.md +0 -0
  59. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/skills/triage/SKILL.md +0 -0
  60. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/skills/triage/references/conventions.md +0 -0
  61. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/skills.py +0 -0
  62. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/agent-config.js +0 -0
  63. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/app.css +0 -0
  64. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/app.js +0 -0
  65. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/assignments.js +0 -0
  66. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/breadcrumbs.js +0 -0
  67. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/comment-composer.js +0 -0
  68. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/connect.css +0 -0
  69. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/connect.html +0 -0
  70. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/connect.js +0 -0
  71. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/credentials.js +0 -0
  72. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/diagrams.js +0 -0
  73. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/dom.js +0 -0
  74. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/editor-claim.js +0 -0
  75. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/editor.js +0 -0
  76. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/index.html +0 -0
  77. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/markdown.css +0 -0
  78. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/markdown.js +0 -0
  79. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/mcp.js +0 -0
  80. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/memory-append.js +0 -0
  81. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/memory-editor.js +0 -0
  82. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/memory.js +0 -0
  83. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/package.json +0 -0
  84. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/project-form.js +0 -0
  85. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/project-settings.js +0 -0
  86. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/scope.js +0 -0
  87. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/statistics.js +0 -0
  88. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/task-browser.js +0 -0
  89. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/task-pagination.js +0 -0
  90. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/task-picker.js +0 -0
  91. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/task-table.js +0 -0
  92. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/vendor/README.md +0 -0
  93. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/vendor/dompurify-LICENSE +0 -0
  94. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/vendor/highlight-LICENSE +0 -0
  95. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/vendor/highlight-dark.css +0 -0
  96. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/vendor/highlight-light.css +0 -0
  97. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/vendor/highlight.min.js +0 -0
  98. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/vendor/marked-LICENSE +0 -0
  99. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/vendor/marked.esm.js +0 -0
  100. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/vendor/marked.esm.js.map +0 -0
  101. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/vendor/mermaid-LICENSE +0 -0
  102. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/vendor/mermaid.min.js +0 -0
  103. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/vendor/purify.es.mjs +0 -0
  104. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/static/vendor/purify.es.mjs.map +0 -0
  105. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/textsearch.py +0 -0
  106. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/version.py +0 -0
  107. {backlog_tiny_mcp-0.35.1 → backlog_tiny_mcp-0.36.0}/src/backlog_mcp/webui.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: backlog-tiny-mcp
3
- Version: 0.35.1
3
+ Version: 0.36.0
4
4
  Summary: A project backlog over MCP: projects scoped to directories, tasks scoped to projects
5
5
  Author: Dmitry Orlov
6
6
  Author-email: Dmitry Orlov <orlovdl@gmail.com>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "backlog-tiny-mcp"
3
- version = "0.35.1"
3
+ version = "0.36.0"
4
4
  description = "A project backlog over MCP: projects scoped to directories, tasks scoped to projects"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.14"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "backlog-tiny-mcp"
3
- version = "0.35.1"
3
+ version = "0.36.0"
4
4
  description = "A project backlog over MCP: projects scoped to directories, tasks scoped to projects"
5
5
  readme = "README.md"
6
6
  authors = [
@@ -6,6 +6,7 @@ import argparse
6
6
  import asyncio
7
7
  import contextlib
8
8
  import dataclasses
9
+ import gzip
9
10
  import json
10
11
  import logging
11
12
  import os
@@ -14,9 +15,9 @@ import shlex
14
15
  import subprocess
15
16
  import sys
16
17
  import tempfile
17
- from collections.abc import AsyncGenerator, Mapping, Sequence
18
+ from collections.abc import AsyncGenerator, Iterator, Mapping, Sequence
18
19
  from pathlib import Path
19
- from typing import Any, cast
20
+ from typing import Any, Literal, TextIO, cast
20
21
 
21
22
  import argclass
22
23
  import rtoml
@@ -36,6 +37,8 @@ from .auth import (
36
37
  )
37
38
  from .backlog import Backlog, UnknownProject, slugify
38
39
  from .client import Connection, Registration, ToolError, bind_directory, connect, directory_project
40
+ from .db import backup
41
+ from .db import connect as connect_database
39
42
  from .models import (
40
43
  OPEN_STATUSES,
41
44
  CommentOut,
@@ -319,6 +322,8 @@ class ConfigTemplate(argclass.TOMLConfigGenerator):
319
322
 
320
323
  #: The subcommands whose options a config file may set.
321
324
  TABLES = frozenset({"mcp"})
325
+ #: Commands under those subcommands that take their options on the command line only.
326
+ COMMAND_LINE = frozenset({("mcp", "db")})
322
327
 
323
328
  def render(self, fields: Sequence[argclass.ConfigField]) -> str:
324
329
  cost = validate_bcrypt_cost(
@@ -334,7 +339,8 @@ class ConfigTemplate(argclass.TOMLConfigGenerator):
334
339
  kept = [
335
340
  self.named(field, cost)
336
341
  for field in fields
337
- if not field.attr_path[:-1] or field.attr_path[0] in self.TABLES
342
+ if (not field.attr_path[:-1] or field.attr_path[0] in self.TABLES)
343
+ and field.attr_path[:2] not in self.COMMAND_LINE
338
344
  ]
339
345
  return super().render(kept)
340
346
 
@@ -512,6 +518,88 @@ class HashPassword(Command):
512
518
  return 0
513
519
 
514
520
 
521
+ class DbDump(Command):
522
+ """Write every project, task, comment and note of the database as JSON Lines."""
523
+
524
+ output: str = argclass.Argument(
525
+ "-o",
526
+ "--output",
527
+ default="-",
528
+ help="File to write; a name that ends with .gz is compressed; '-' is stdout",
529
+ )
530
+
531
+ async def __call__(self) -> int:
532
+ database = connect_database(self.options().database or paths.database_path())
533
+ with open_text(self.output, "w") as stream:
534
+ count = await backup.dump(database, stream.write)
535
+ errors.print(f"dumped {count} rows from {database.location}")
536
+ return 0
537
+
538
+
539
+ class DbRestore(Command):
540
+ """Load a dump with the same ids. Rows that are already there are skipped."""
541
+
542
+ source: str = argclass.Argument(
543
+ "-i",
544
+ "--input",
545
+ default="-",
546
+ help="File to read; a name that ends with .gz is compressed; '-' is stdin",
547
+ )
548
+
549
+ async def __call__(self) -> int:
550
+ database = connect_database(self.options().database or paths.database_path())
551
+ try:
552
+ with open_text(self.source, "r") as stream:
553
+ inserted, skipped = await backup.restore(database, stream)
554
+ except backup.BackupError as error:
555
+ fail(str(error))
556
+ return 1
557
+ errors.print(
558
+ f"restored {inserted} rows into {database.location}, "
559
+ f"skipped {skipped} rows that were already there"
560
+ )
561
+ return 0
562
+
563
+
564
+ class DbCommands(Command):
565
+ """Dump the database to a file, or restore a dump."""
566
+
567
+ dump = DbDump(
568
+ aliases=["du"],
569
+ help="Dump the database as JSON Lines",
570
+ description=(
571
+ "Write every project, task, comment and note as JSON Lines, ids included. MCP "
572
+ "sessions and the search index are not part of the dump."
573
+ ),
574
+ )
575
+ restore = DbRestore(
576
+ aliases=["rs"],
577
+ help="Restore a dump; rows that are already there are skipped",
578
+ description=(
579
+ "Load a dump into a database of either engine, in one transaction, with the same "
580
+ "ids. A row that is already there with the same values is skipped, so a restore "
581
+ "can run again. A row with the same key and other values stops the restore and "
582
+ "leaves the database unchanged."
583
+ ),
584
+ )
585
+
586
+ async def __call__(self) -> int:
587
+ return self.show_help()
588
+
589
+
590
+ @contextlib.contextmanager
591
+ def open_text(path: str, mode: Literal["r", "w"]) -> Iterator[TextIO]:
592
+ """A text stream for a path; '-' is stdin or stdout, and .gz is gzip."""
593
+ if path == "-":
594
+ yield sys.stdin if mode == "r" else sys.stdout
595
+ elif path.endswith(".gz"):
596
+ with gzip.open(path, mode + "t", encoding="utf-8") as stream:
597
+ yield cast(TextIO, stream)
598
+ else:
599
+ with open(path, mode, encoding="utf-8") as stream:
600
+ yield cast(TextIO, stream)
601
+
602
+
515
603
  class Serve(Command):
516
604
  """Run the MCP server: on stdio by default, or over HTTP with `--protocol=http`.
517
605
 
@@ -536,6 +624,14 @@ class Serve(Command):
536
624
  )
537
625
  http = HTTPOptions(title="HTTP transport")
538
626
  auth = AuthOptions(title="HTTP authentication")
627
+ db = DbCommands(
628
+ aliases=["da"],
629
+ help="Dump or restore the database",
630
+ description=(
631
+ "Open the database of --database directly, without a server, and dump it to "
632
+ "JSON Lines or restore a dump. The file may be gzip."
633
+ ),
634
+ )
539
635
  generate_config: str = argclass.Argument(
540
636
  action=argclass.GenerateConfigAction,
541
637
  generator=ConfigTemplate,
@@ -1966,6 +2062,9 @@ class CLI(argclass.Parser):
1966
2062
  self.print_help()
1967
2063
  return 0
1968
2064
  try:
2065
+ if isinstance(command, DbCommands | DbDump | DbRestore):
2066
+ # They open the database themselves and register nobody in it.
2067
+ return await command()
1969
2068
  if isinstance(command, Serve):
1970
2069
  backlog = build(self)
1971
2070
  use(backlog)
@@ -129,6 +129,34 @@ class Database(ABC):
129
129
  def translate(error: Exception) -> Exception | None:
130
130
  """Return the interface error for an engine error, or None to keep it."""
131
131
 
132
+ # Backup statements are an inline SQL exception, like the migrator: they work on every
133
+ # application table, and `backup.TABLES` gives the only table names they accept.
134
+ @abstractmethod
135
+ def table_rows(self, connection: Any, table: str) -> AsyncIterator[dict[str, Any]]:
136
+ """Every row of an application table, as column names and values."""
137
+
138
+ @abstractmethod
139
+ async def find_row(
140
+ self, connection: Any, table: str, key: dict[str, Any]
141
+ ) -> dict[str, Any] | None:
142
+ """The row of an application table with these key values, or None."""
143
+
144
+ @abstractmethod
145
+ async def table_columns(self, connection: Any, table: str) -> list[str]:
146
+ """The column names of an application table."""
147
+
148
+ @abstractmethod
149
+ async def insert_row(self, connection: Any, table: str, row: dict[str, Any]) -> None:
150
+ """Insert one row with its given values, the id included."""
151
+
152
+ @abstractmethod
153
+ async def update_row(self, connection: Any, table: str, row: dict[str, Any]) -> None:
154
+ """Set the given columns of the row with the given `id`."""
155
+
156
+ async def restored(self, connection: Any) -> None:
157
+ """Make the database ready after a restore inside the same transaction."""
158
+ return
159
+
132
160
  @abstractmethod
133
161
  def protocol(
134
162
  self, open: Callable[[], Awaitable[Connection]]
@@ -0,0 +1,154 @@
1
+ """Dump a database to JSON Lines and restore the lines into a database.
2
+
3
+ The dump and the restore use the engine of each database, so a SQLite dump restores into
4
+ PostgreSQL and back. The table names come from `TABLES` only; the engines put them into
5
+ their statements.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ import json
11
+ from collections.abc import Callable, Iterable
12
+ from typing import Any
13
+
14
+ from backlog_mcp.db import Database
15
+ from backlog_mcp.version import VERSION
16
+
17
+ FORMAT = "backlog-mcp"
18
+ #: The version of the line format. Restore refuses other versions.
19
+ FORMAT_VERSION = 1
20
+ #: The application tables, parents before children. Protocol state, migrations and the
21
+ #: change counter are not data: the target database makes its own.
22
+ TABLES = (
23
+ "principals",
24
+ "projects",
25
+ "project_members",
26
+ "project_roots",
27
+ "tasks",
28
+ "task_links",
29
+ "task_edit_claims",
30
+ "notes",
31
+ "task_comments",
32
+ )
33
+ #: The primary key of each table: restore finds an existing row by it.
34
+ KEYS = {
35
+ "principals": ("identity",),
36
+ "projects": ("id",),
37
+ "project_members": ("project_id", "principal"),
38
+ "project_roots": ("project_id", "principal", "computer", "root"),
39
+ "tasks": ("id",),
40
+ "task_links": ("task_id", "relation", "target_id"),
41
+ "task_edit_claims": ("task_id",),
42
+ "notes": ("id",),
43
+ "task_comments": ("id",),
44
+ }
45
+ #: Columns that a trigger changes when a comment is inserted. Restore writes them again.
46
+ TASK_CHANGE = ("updated_at", "updated_principal", "updated_computer")
47
+
48
+
49
+ class BackupError(ValueError):
50
+ """The dump cannot be restored into this database."""
51
+
52
+
53
+ async def dump(database: Database, write: Callable[[str], object]) -> int:
54
+ """Write the header and every row as JSON Lines. Return the number of rows."""
55
+ connection, transaction = await database.connect()
56
+ count = 0
57
+ try:
58
+ await database.migrate(connection, transaction)
59
+ write(header(database) + "\n")
60
+ # One transaction gives one consistent snapshot of all tables.
61
+ async with transaction:
62
+ for table in TABLES:
63
+ async for row in database.table_rows(connection, table):
64
+ write(json.dumps({"table": table, "row": row}, ensure_ascii=False) + "\n")
65
+ count += 1
66
+ finally:
67
+ await connection.close()
68
+ return count
69
+
70
+
71
+ def header(database: Database) -> str:
72
+ return json.dumps(
73
+ {
74
+ "format": FORMAT,
75
+ "version": FORMAT_VERSION,
76
+ "package": VERSION,
77
+ "engine": type(database).__name__,
78
+ }
79
+ )
80
+
81
+
82
+ async def restore(database: Database, lines: Iterable[str]) -> tuple[int, int]:
83
+ """Restore the rows of a dump. Return the numbers of inserted and skipped rows.
84
+
85
+ A row that is already there with the same values is skipped, so a restore can run again.
86
+ A row with the same key and other values is an error. All rows go in one transaction: an
87
+ error leaves the database as it was.
88
+ """
89
+ records = iter(lines)
90
+ check_header(next(records, ""))
91
+ connection, transaction = await database.connect()
92
+ inserted = skipped = 0
93
+ try:
94
+ await database.migrate(connection, transaction)
95
+ async with transaction:
96
+ columns = {table: await database.table_columns(connection, table) for table in TABLES}
97
+ changes: list[dict[str, Any]] = []
98
+ for number, line in enumerate(records, start=2):
99
+ if not line.strip():
100
+ continue
101
+ table, row = parse(line, number, columns)
102
+ key = {name: row[name] for name in KEYS[table]}
103
+ found = await database.find_row(connection, table, key)
104
+ if found is None:
105
+ await database.insert_row(connection, table, row)
106
+ inserted += 1
107
+ elif same(found, row):
108
+ skipped += 1
109
+ else:
110
+ raise BackupError(
111
+ f"line {number}: table {table} has another row with the key {key}"
112
+ )
113
+ if table == "tasks":
114
+ changes.append({"id": row["id"], **{name: row[name] for name in TASK_CHANGE}})
115
+ # A comment insert changes its task through a trigger; put the dumped values back.
116
+ for change in changes:
117
+ await database.update_row(connection, "tasks", change)
118
+ await database.restored(connection)
119
+ finally:
120
+ await connection.close()
121
+ return inserted, skipped
122
+
123
+
124
+ def same(found: dict[str, Any], row: dict[str, Any]) -> bool:
125
+ """True when the stored row has the dumped values; columns the dump lacks are ignored."""
126
+ return all(found.get(name) == value for name, value in row.items())
127
+
128
+
129
+ def check_header(line: str) -> None:
130
+ try:
131
+ found = json.loads(line)
132
+ except json.JSONDecodeError:
133
+ found = None
134
+ if not isinstance(found, dict) or found.get("format") != FORMAT:
135
+ raise BackupError("not a backlog-mcp dump: the first line is not its header")
136
+ if found.get("version") != FORMAT_VERSION:
137
+ raise BackupError(f"unsupported dump version {found.get('version')!r}")
138
+
139
+
140
+ def parse(line: str, number: int, columns: dict[str, list[str]]) -> tuple[str, dict[str, Any]]:
141
+ try:
142
+ record = json.loads(line)
143
+ table, row = record["table"], record["row"]
144
+ except (json.JSONDecodeError, KeyError, TypeError) as error:
145
+ raise BackupError(f"line {number}: not a dump record") from error
146
+ if table not in columns:
147
+ raise BackupError(f"line {number}: unknown table {table!r}")
148
+ unknown = set(row) - set(columns[table])
149
+ if unknown:
150
+ raise BackupError(f"line {number}: table {table} has no column {sorted(unknown)[0]!r}")
151
+ missing = set(KEYS[table]) - set(row)
152
+ if missing:
153
+ raise BackupError(f"line {number}: the row has no key column {sorted(missing)[0]!r}")
154
+ return table, row
@@ -17,7 +17,7 @@ from aiohttp_tiny_mcp.storage.hub import Hub
17
17
  from aiohttp_tiny_mcp.storage.postgres import PostgresHub, PostgresSessionStore, PostgresStorage
18
18
  from aiohttp_tiny_mcp.storage.sessions import SessionStore
19
19
  from aiosql.types import SQLOperationType
20
- from psycopg import AsyncConnection, AsyncCursor
20
+ from psycopg import AsyncConnection, AsyncCursor, sql
21
21
 
22
22
  from backlog_mcp.db import Connection, Database, IntegrityError, ProtocolStorage
23
23
  from backlog_mcp.db import Transaction as BaseTransaction
@@ -30,10 +30,19 @@ QUERIES = aiosql.from_path(Path(__file__).with_name("queries.sql"), "apsycopg")
30
30
  READS = frozenset(
31
31
  {SQLOperationType.SELECT, SQLOperationType.SELECT_ONE, SQLOperationType.SELECT_VALUE}
32
32
  )
33
+ #: Tables with an identity column `id`, and tables without one.
34
+ NUMBERED = ("projects", "tasks", "notes", "task_comments")
35
+ UNNUMBERED = frozenset(
36
+ {"principals", "project_members", "project_roots", "task_links", "task_edit_claims"}
37
+ )
33
38
  #: The change counter state of each open connection.
34
39
  REVISIONS: WeakKeyDictionary[AsyncConnection[Any], Revision] = WeakKeyDictionary()
35
40
 
36
41
 
42
+ def name(table: str) -> sql.Identifier:
43
+ return sql.Identifier(table)
44
+
45
+
37
46
  class Row(tuple[Any, ...]):
38
47
  """A result row. Read a column by name or by position; `dict(row)` gives a mapping."""
39
48
 
@@ -158,6 +167,62 @@ class PostgresDatabase(Database):
158
167
  return IntegrityError(str(error))
159
168
  return None
160
169
 
170
+ async def table_rows(self, connection: Any, table: str) -> AsyncIterator[dict[str, Any]]:
171
+ order = "" if table in UNNUMBERED else " ORDER BY id"
172
+ cursor = await connection.execute(sql.SQL("SELECT * FROM {}" + order).format(name(table)))
173
+ async for row in cursor:
174
+ yield dict(row)
175
+
176
+ async def find_row(
177
+ self, connection: Any, table: str, key: dict[str, Any]
178
+ ) -> dict[str, Any] | None:
179
+ query = sql.SQL("SELECT * FROM {} WHERE {}").format(
180
+ name(table),
181
+ sql.SQL(" AND ").join(
182
+ sql.SQL("{} = %s").format(sql.Identifier(column)) for column in key
183
+ ),
184
+ )
185
+ cursor = await connection.execute(query, tuple(key.values()))
186
+ row = await cursor.fetchone()
187
+ return None if row is None else dict(row)
188
+
189
+ async def table_columns(self, connection: Any, table: str) -> list[str]:
190
+ cursor = await connection.execute(
191
+ "SELECT column_name FROM information_schema.columns "
192
+ "WHERE table_schema = current_schema() AND table_name = %s ORDER BY ordinal_position",
193
+ (table,),
194
+ )
195
+ return [row[0] async for row in cursor]
196
+
197
+ async def insert_row(self, connection: Any, table: str, row: dict[str, Any]) -> None:
198
+ query = sql.SQL("INSERT INTO {} ({}) VALUES ({})").format(
199
+ name(table),
200
+ sql.SQL(", ").join(map(sql.Identifier, row)),
201
+ sql.SQL(", ").join(sql.Placeholder() * len(row)),
202
+ )
203
+ await connection.execute(query, tuple(row.values()))
204
+ # Other nodes must notice the restored data.
205
+ REVISIONS[connection].dirty = True
206
+
207
+ async def update_row(self, connection: Any, table: str, row: dict[str, Any]) -> None:
208
+ values = {key: value for key, value in row.items() if key != "id"}
209
+ query = sql.SQL("UPDATE {} SET {} WHERE id = %s").format(
210
+ name(table),
211
+ sql.SQL(", ").join(sql.SQL("{} = %s").format(sql.Identifier(key)) for key in values),
212
+ )
213
+ await connection.execute(query, (*values.values(), row["id"]))
214
+
215
+ async def restored(self, connection: Any) -> None:
216
+ # Restored rows keep their ids: move each identity past the largest one.
217
+ for table in NUMBERED:
218
+ await connection.execute(
219
+ sql.SQL(
220
+ "SELECT setval(pg_get_serial_sequence(%s, 'id'), "
221
+ "COALESCE((SELECT max(id) FROM {}), 0) + 1, false)"
222
+ ).format(name(table)),
223
+ (table,),
224
+ )
225
+
161
226
  def protocol(
162
227
  self, open: Callable[[], Awaitable[Connection]]
163
228
  ) -> tuple[ProtocolStorage, Hub, SessionStore]:
@@ -5,7 +5,7 @@ from __future__ import annotations
5
5
  import asyncio
6
6
  import re
7
7
  import sqlite3
8
- from collections.abc import Awaitable, Callable, Sequence
8
+ from collections.abc import AsyncIterator, Awaitable, Callable, Sequence
9
9
  from pathlib import Path
10
10
  from typing import Any, cast
11
11
 
@@ -116,6 +116,38 @@ class SqliteDatabase(Database):
116
116
  return SearchSyntaxError(str(error))
117
117
  return None
118
118
 
119
+ async def table_rows(self, connection: Any, table: str) -> AsyncIterator[dict[str, Any]]:
120
+ async with connection.execute(f"SELECT * FROM {table} ORDER BY rowid") as cursor:
121
+ async for row in cursor:
122
+ yield dict(row)
123
+
124
+ async def find_row(
125
+ self, connection: Any, table: str, key: dict[str, Any]
126
+ ) -> dict[str, Any] | None:
127
+ condition = " AND ".join(f"{name} = ?" for name in key)
128
+ sql = f"SELECT * FROM {table} WHERE {condition}"
129
+ async with connection.execute(sql, tuple(key.values())) as cursor:
130
+ row = await cursor.fetchone()
131
+ return None if row is None else dict(row)
132
+
133
+ async def table_columns(self, connection: Any, table: str) -> list[str]:
134
+ async with connection.execute(f"SELECT name FROM pragma_table_info('{table}')") as cursor:
135
+ return [row[0] async for row in cursor]
136
+
137
+ async def insert_row(self, connection: Any, table: str, row: dict[str, Any]) -> None:
138
+ names = ", ".join(row)
139
+ marks = ", ".join("?" for _ in row)
140
+ sql = f"INSERT INTO {table} ({names}) VALUES ({marks})"
141
+ async with connection.execute(sql, tuple(row.values())):
142
+ pass
143
+
144
+ async def update_row(self, connection: Any, table: str, row: dict[str, Any]) -> None:
145
+ values = {key: value for key, value in row.items() if key != "id"}
146
+ assignments = ", ".join(f"{key} = ?" for key in values)
147
+ sql = f"UPDATE {table} SET {assignments} WHERE id = ?"
148
+ async with connection.execute(sql, (*values.values(), row["id"])):
149
+ pass
150
+
119
151
  def protocol(self, open: Callable[[], Awaitable[Connection]]) -> tuple[Any, Hub, SessionStore]:
120
152
  from .protocol import ProtocolHub, ProtocolSessions, ProtocolStorage
121
153
 
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
- name: backlog_tiny_mcp-0.35.1/src/backlog_mcp/model/model.safetensors
2
+ name: backlog_tiny_mcp-0.36.0/src/backlog_mcp/model/model.safetensors
3
3
  size: 54210136 bytes
4
4
  sha256: 3c7e25896b83d1161c8df5a3c652aac41828313af0db90e1ae4586d1e508bf23