seren-margin 5.1.2__tar.gz → 5.2.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 (56) hide show
  1. {seren_margin-5.1.2 → seren_margin-5.2.0}/PKG-INFO +1 -1
  2. {seren_margin-5.1.2 → seren_margin-5.2.0}/seren_margin/_version.py +3 -3
  3. {seren_margin-5.1.2 → seren_margin-5.2.0}/seren_margin/app.py +6 -4
  4. {seren_margin-5.1.2 → seren_margin-5.2.0}/seren_margin/mcp/tools.py +13 -5
  5. {seren_margin-5.1.2 → seren_margin-5.2.0}/seren_margin/mcp-manifest.yaml +10 -3
  6. {seren_margin-5.1.2 → seren_margin-5.2.0}/seren_margin/store.py +35 -11
  7. {seren_margin-5.1.2 → seren_margin-5.2.0}/seren_margin/viewer/ui/styles.css +1 -1
  8. {seren_margin-5.1.2 → seren_margin-5.2.0}/seren_margin.egg-info/PKG-INFO +1 -1
  9. {seren_margin-5.1.2 → seren_margin-5.2.0}/seren_margin.egg-info/SOURCES.txt +1 -0
  10. {seren_margin-5.1.2 → seren_margin-5.2.0}/seren_margin.egg-info/scm_file_list.json +1 -0
  11. seren_margin-5.2.0/seren_margin.egg-info/scm_version.json +8 -0
  12. seren_margin-5.2.0/tests/test_letters_off_the_board.py +80 -0
  13. seren_margin-5.1.2/seren_margin.egg-info/scm_version.json +0 -8
  14. {seren_margin-5.1.2 → seren_margin-5.2.0}/LICENSE +0 -0
  15. {seren_margin-5.1.2 → seren_margin-5.2.0}/README.md +0 -0
  16. {seren_margin-5.1.2 → seren_margin-5.2.0}/SerenMargin.pyproj +0 -0
  17. {seren_margin-5.1.2 → seren_margin-5.2.0}/pyproject.toml +0 -0
  18. {seren_margin-5.1.2 → seren_margin-5.2.0}/seren-margin.service.sample +0 -0
  19. {seren_margin-5.1.2 → seren_margin-5.2.0}/seren-margin.yaml.sample +0 -0
  20. {seren_margin-5.1.2 → seren_margin-5.2.0}/seren_margin/__init__.py +0 -0
  21. {seren_margin-5.1.2 → seren_margin-5.2.0}/seren_margin/__main__.py +0 -0
  22. {seren_margin-5.1.2 → seren_margin-5.2.0}/seren_margin/_diag.py +0 -0
  23. {seren_margin-5.1.2 → seren_margin-5.2.0}/seren_margin/bookmark.py +0 -0
  24. {seren_margin-5.1.2 → seren_margin-5.2.0}/seren_margin/config.py +0 -0
  25. {seren_margin-5.1.2 → seren_margin-5.2.0}/seren_margin/keepsakes.py +0 -0
  26. {seren_margin-5.1.2 → seren_margin-5.2.0}/seren_margin/mcp/__init__.py +0 -0
  27. {seren_margin-5.1.2 → seren_margin-5.2.0}/seren_margin/mcp/server.py +0 -0
  28. {seren_margin-5.1.2 → seren_margin-5.2.0}/seren_margin/models.py +0 -0
  29. {seren_margin-5.1.2 → seren_margin-5.2.0}/seren_margin/viewer/ui/body.html +0 -0
  30. {seren_margin-5.1.2 → seren_margin-5.2.0}/seren_margin/viewer/ui/header_aside.html +0 -0
  31. {seren_margin-5.1.2 → seren_margin-5.2.0}/seren_margin/viewer/ui/scripts.js +0 -0
  32. {seren_margin-5.1.2 → seren_margin-5.2.0}/seren_margin/viewer/ui/tabs.html +0 -0
  33. {seren_margin-5.1.2 → seren_margin-5.2.0}/seren_margin.egg-info/dependency_links.txt +0 -0
  34. {seren_margin-5.1.2 → seren_margin-5.2.0}/seren_margin.egg-info/entry_points.txt +0 -0
  35. {seren_margin-5.1.2 → seren_margin-5.2.0}/seren_margin.egg-info/requires.txt +0 -0
  36. {seren_margin-5.1.2 → seren_margin-5.2.0}/seren_margin.egg-info/top_level.txt +0 -0
  37. {seren_margin-5.1.2 → seren_margin-5.2.0}/setup.cfg +0 -0
  38. {seren_margin-5.1.2 → seren_margin-5.2.0}/tests/__init__.py +0 -0
  39. {seren_margin-5.1.2 → seren_margin-5.2.0}/tests/conftest.py +0 -0
  40. {seren_margin-5.1.2 → seren_margin-5.2.0}/tests/test_amend_and_topics.py +0 -0
  41. {seren_margin-5.1.2 → seren_margin-5.2.0}/tests/test_bookmark_and_letters.py +0 -0
  42. {seren_margin-5.1.2 → seren_margin-5.2.0}/tests/test_config.py +0 -0
  43. {seren_margin-5.1.2 → seren_margin-5.2.0}/tests/test_exposure_is_wired.py +0 -0
  44. {seren_margin-5.1.2 → seren_margin-5.2.0}/tests/test_keepsakes.py +0 -0
  45. {seren_margin-5.1.2 → seren_margin-5.2.0}/tests/test_manifest_parity.py +0 -0
  46. {seren_margin-5.1.2 → seren_margin-5.2.0}/tests/test_mcp_fallback.py +0 -0
  47. {seren_margin-5.1.2 → seren_margin-5.2.0}/tests/test_mcp_mount.py +0 -0
  48. {seren_margin-5.1.2 → seren_margin-5.2.0}/tests/test_mcp_tools.py +0 -0
  49. {seren_margin-5.1.2 → seren_margin-5.2.0}/tests/test_optional_bearer.py +0 -0
  50. {seren_margin-5.1.2 → seren_margin-5.2.0}/tests/test_reads_stay_private.py +0 -0
  51. {seren_margin-5.1.2 → seren_margin-5.2.0}/tests/test_search.py +0 -0
  52. {seren_margin-5.1.2 → seren_margin-5.2.0}/tests/test_smoke.py +0 -0
  53. {seren_margin-5.1.2 → seren_margin-5.2.0}/tests/test_stats_content_blind.py +0 -0
  54. {seren_margin-5.1.2 → seren_margin-5.2.0}/tests/test_stores_snapshot.py +0 -0
  55. {seren_margin-5.1.2 → seren_margin-5.2.0}/tests/test_updates_contract.py +0 -0
  56. {seren_margin-5.1.2 → seren_margin-5.2.0}/tests/test_viewer.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: seren-margin
3
- Version: 5.1.2
3
+ Version: 5.2.0
4
4
  Summary: Private notes-to-self for an AI assistant. Standalone, opt-in, opinionated.
5
5
  Author: Chad Roesler
6
6
  License-Expression: AGPL-3.0-or-later
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '5.1.2'
22
- __version_tuple__ = version_tuple = (5, 1, 2)
21
+ __version__ = version = '5.2.0'
22
+ __version_tuple__ = version_tuple = (5, 2, 0)
23
23
 
24
- __commit_id__ = commit_id = 'gb4a355434'
24
+ __commit_id__ = commit_id = 'g7efa1e7a3'
@@ -342,9 +342,9 @@ def create_app(config: Optional[MarginConfig] = None) -> FastAPI:
342
342
  return {"ok": True, "id": saved.id}
343
343
 
344
344
  @app.get("/notes")
345
- async def list_notes(limit: int = 100, topic: Optional[str] = None):
345
+ async def list_notes(limit: int = 100, topic: Optional[str] = None, letters: bool = False):
346
346
  _content_over_http()
347
- notes = store.list_all(limit=limit, topic=topic or None)
347
+ notes = store.list_all(limit=limit, topic=topic or None, letters=letters)
348
348
  return {
349
349
  "entries": [n.model_dump() for n in notes],
350
350
  "count": len(notes),
@@ -375,9 +375,11 @@ def create_app(config: Optional[MarginConfig] = None) -> FastAPI:
375
375
  hat. It stays off /notes/stats for exactly that reason.
376
376
  """
377
377
  _content_over_http()
378
- topics = store.list_topics()
378
+ topics = store.list_topics(letters=False)
379
+ count, unread = store.letter_counts()
379
380
  return {"count": len(topics),
380
- "topics": [t.model_dump() for t in topics]}
381
+ "topics": [t.model_dump() for t in topics],
382
+ "letters": {"count": count, "unread": unread}}
381
383
  @app.get("/notes/search")
382
384
  async def search_notes(q: str, limit: int = 20):
383
385
  """Full-text search over content + topic.
@@ -235,11 +235,15 @@ class MarginToolImpl:
235
235
 
236
236
  # -- read (recency) ---------------------------------------------------
237
237
  def list_my_notes(self, limit: int = 50,
238
- topic: Optional[str] = None) -> dict:
238
+ topic: Optional[str] = None,
239
+ include_letters: bool = False) -> dict:
239
240
  """Read your notes back, newest first.
240
241
 
241
242
  The whole board - there's no active/done split, because notes here
242
- aren't tasks. Everything you've written and not retracted is here.
243
+ aren't tasks. Everything you've written and not retracted is here,
244
+ except letters: those are mail to the next session, not notes you
245
+ keep, and they have their own door (read_letters, include_read=True
246
+ for old ones). `include_letters=True` puts them back on the board.
243
247
 
244
248
  Pass `topic` to pull a single thread instead of the whole board. Get
245
249
  the available labels from `list_my_topics`; matching ignores case and
@@ -254,7 +258,7 @@ class MarginToolImpl:
254
258
  Every note comes back with `age` in plain words ("3 days ago") as well
255
259
  as the raw `ts`, and `amended_age` if you've added to it since.
256
260
  """
257
- notes = self.store.list_all(limit=limit, topic=topic)
261
+ notes = self.store.list_all(limit=limit, topic=topic, letters=include_letters)
258
262
  return {
259
263
  "count": len(notes),
260
264
  "topic": topic,
@@ -276,12 +280,16 @@ class MarginToolImpl:
276
280
  looking for. This needs neither. Pick a thread, then pull it with
277
281
  `list_my_notes(topic=...)`.
278
282
 
279
- Untopiced notes come back as a single row with `topic: null`.
283
+ Untopiced notes come back as a single row with `topic: null`. Letters
284
+ are not a thread: they are counted on their own line, `letters`
285
+ (how many, how many unread), and read_letters opens them.
280
286
  """
281
- topics = self.store.list_topics()
287
+ topics = self.store.list_topics(letters=False)
288
+ count, unread = self.store.letter_counts()
282
289
  return {
283
290
  "count": len(topics),
284
291
  "topics": [t.model_dump() for t in topics],
292
+ "letters": {"count": count, "unread": unread},
285
293
  }
286
294
 
287
295
  # -- read (search) ----------------------------------------------------
@@ -106,7 +106,10 @@ tools:
106
106
  Read your notes back, newest first.
107
107
 
108
108
  The whole board - there's no active/done split, because notes here
109
- aren't tasks. Everything you've written and not retracted is here.
109
+ aren't tasks. Everything you've written and not retracted is here,
110
+ except letters: those are mail to the next session, not notes you
111
+ keep, and they have their own door (read_letters, include_read=true
112
+ for old ones). include_letters=true puts them back on the board.
110
113
 
111
114
  Pass `topic` to pull a single thread instead of the whole board. Get
112
115
  the available labels from list_my_topics; matching ignores case and
@@ -124,10 +127,12 @@ tools:
124
127
  kind: web
125
128
  method: GET
126
129
  # Same query-string caveat as search_my_notes below.
127
- path: /notes?topic={topic}
130
+ path: /notes?topic={topic}&letters={include_letters}
128
131
  parameters:
129
132
  - { name: topic, type: string, required: false, default: "",
130
133
  description: "Narrow to one thread. Empty means the whole board." }
134
+ - { name: include_letters, type: boolean, required: false, default: false,
135
+ description: "true puts letters (mail between sessions) back on the board." }
131
136
 
132
137
  # ─── 3. READ (orientation) ────────────────────────────────────────────
133
138
  - name: list_my_topics
@@ -145,7 +150,9 @@ tools:
145
150
  looking for. This needs neither. Pick a thread, then pull it with
146
151
  list_my_notes(topic=...).
147
152
 
148
- Untopiced notes come back as a single row with `topic: null`.
153
+ Untopiced notes come back as a single row with `topic: null`. Letters
154
+ are not a thread: they are counted on their own line, `letters` (how
155
+ many, how many unread), and read_letters opens them.
149
156
  invoke:
150
157
  kind: web
151
158
  method: GET
@@ -420,7 +420,7 @@ class MarginStore:
420
420
  return notes
421
421
 
422
422
  def list_all(self, limit: int = 200,
423
- topic: Optional[str] = None) -> list[MarginNote]:
423
+ topic: Optional[str] = None, letters: bool = True) -> list[MarginNote]:
424
424
  """Notes, newest first. They live until retracted, so there's no
425
425
  active/done distinction to filter on - this is the whole board.
426
426
 
@@ -428,18 +428,29 @@ class MarginStore:
428
428
  surrounding whitespace trimmed, because "Alice" and "alice " are the same
429
429
  thread to whoever typed them and a filter that disagrees is just a
430
430
  silent empty result.
431
+
432
+ `letters=False` leaves the mail out (kind "letter"). Letters are notes
433
+ underneath, but they are written to the next session, not kept: on
434
+ 18 Oct 2026 they were 100 of 112 rows, and the dozen that were the
435
+ writer's own were lost among them. letters() is their door.
431
436
  """
432
- sql = "SELECT * FROM notes"
437
+ clauses: list = []
433
438
  params: list = []
434
439
  if topic is not None:
435
- sql += " WHERE LOWER(TRIM(COALESCE(topic,''))) = ?"
440
+ clauses.append("LOWER(TRIM(COALESCE(topic,''))) = ?")
436
441
  params.append(topic.strip().lower())
442
+ if not letters:
443
+ clauses.append("LOWER(TRIM(COALESCE(kind,''))) != ?")
444
+ params.append(LETTER_KIND)
445
+ sql = "SELECT * FROM notes"
446
+ if clauses:
447
+ sql += " WHERE " + " AND ".join(clauses)
437
448
  sql += " ORDER BY ts DESC LIMIT ?"
438
449
  params.append(limit)
439
450
  with self._conn() as conn:
440
451
  return self._notes(conn, conn.execute(sql, params).fetchall())
441
452
 
442
- def list_topics(self) -> list[TopicSummary]:
453
+ def list_topics(self, letters: bool = True) -> list[TopicSummary]:
443
454
  """Every thread on the board: label, note count, last-touched time.
444
455
 
445
456
  The cheap-orientation surface. Reading the whole board to find out what
@@ -454,16 +465,21 @@ class MarginStore:
454
465
 
455
466
  Untopiced notes are collected under a single `topic: null` row rather
456
467
  than dropped, so the counts always reconcile against /notes/stats.
468
+ `letters=False` leaves the mail out, as list_all does; letter_counts()
469
+ then makes up the difference, so they still reconcile.
457
470
  """
471
+ where = "" if letters else "WHERE LOWER(TRIM(COALESCE(kind,''))) != ?"
458
472
  with self._conn() as conn:
459
473
  rows = conn.execute(
460
- """SELECT CASE WHEN TRIM(COALESCE(topic,'')) = '' THEN NULL
461
- ELSE TRIM(topic) END AS t,
462
- COUNT(*) AS c,
463
- MAX(COALESCE(amended_at, ts)) AS latest
464
- FROM notes
465
- GROUP BY t
466
- ORDER BY latest DESC""",
474
+ f"""SELECT CASE WHEN TRIM(COALESCE(topic,'')) = '' THEN NULL
475
+ ELSE TRIM(topic) END AS t,
476
+ COUNT(*) AS c,
477
+ MAX(COALESCE(amended_at, ts)) AS latest
478
+ FROM notes
479
+ {where}
480
+ GROUP BY t
481
+ ORDER BY latest DESC""",
482
+ () if letters else (LETTER_KIND,),
467
483
  ).fetchall()
468
484
  return [
469
485
  TopicSummary(topic=r["t"], count=r["c"],
@@ -548,6 +564,14 @@ class MarginStore:
548
564
  [(stamp, i) for i in ids])
549
565
  conn.commit()
550
566
 
567
+ def letter_counts(self) -> tuple[int, int]:
568
+ """(all letters, unread ones) - counts only, no text."""
569
+ with self._conn() as conn:
570
+ row = conn.execute(
571
+ "SELECT COUNT(*) AS c, SUM(CASE WHEN read_at IS NULL THEN 1 ELSE 0 END) AS u "
572
+ "FROM notes WHERE LOWER(TRIM(COALESCE(kind,''))) = ?", (LETTER_KIND,)).fetchone()
573
+ return int(row["c"]), int(row["u"] or 0)
574
+
551
575
  def unread_letters(self) -> tuple[int, Optional[float]]:
552
576
  """(how many, when the oldest was written) - the bookmark's count. No text."""
553
577
  with self._conn() as conn:
@@ -25,8 +25,8 @@ body {
25
25
  font-size: 14px;
26
26
  }
27
27
 
28
+ /* page padding is the shell's .view (22px), the same on every viewer (20 Oct 2026) */
28
29
  main {
29
- padding: 20px 24px 60px;
30
30
  max-width: 1100px;
31
31
  }
32
32
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: seren-margin
3
- Version: 5.1.2
3
+ Version: 5.2.0
4
4
  Summary: Private notes-to-self for an AI assistant. Standalone, opt-in, opinionated.
5
5
  Author: Chad Roesler
6
6
  License-Expression: AGPL-3.0-or-later
@@ -38,6 +38,7 @@ tests/test_bookmark_and_letters.py
38
38
  tests/test_config.py
39
39
  tests/test_exposure_is_wired.py
40
40
  tests/test_keepsakes.py
41
+ tests/test_letters_off_the_board.py
41
42
  tests/test_manifest_parity.py
42
43
  tests/test_mcp_fallback.py
43
44
  tests/test_mcp_mount.py
@@ -31,6 +31,7 @@
31
31
  "tests/test_config.py",
32
32
  "tests/test_exposure_is_wired.py",
33
33
  "tests/test_keepsakes.py",
34
+ "tests/test_letters_off_the_board.py",
34
35
  "tests/test_manifest_parity.py",
35
36
  "tests/test_mcp_fallback.py",
36
37
  "tests/test_mcp_mount.py",
@@ -0,0 +1,8 @@
1
+ {
2
+ "tag": "5.2.0",
3
+ "distance": 0,
4
+ "node": "g7efa1e7a3ad6775392ed352946a551fa033346f4",
5
+ "dirty": false,
6
+ "branch": "HEAD",
7
+ "node_date": "2026-10-20"
8
+ }
@@ -0,0 +1,80 @@
1
+ """
2
+ Letters are mail, not the board (18 Oct 2026).
3
+
4
+ Pinned here:
5
+ - list_my_notes leaves letters out unless asked (include_letters=True);
6
+ read_letters is their door, and opening the board never marks one read
7
+ - list_my_topics counts letters on their own line, not in the `null` thread,
8
+ and topics + letters still reconcile with the store's total
9
+ - search still finds a letter: it is a note underneath
10
+ - the same over HTTP: GET /notes (letters=true to include them) and
11
+ GET /notes/topics
12
+ """
13
+ from __future__ import annotations
14
+
15
+ import pytest
16
+ from fastapi.testclient import TestClient
17
+
18
+ from seren_margin.app import create_app
19
+ from seren_margin.config import MarginConfig
20
+ from seren_margin.models import MarginNote
21
+ from seren_margin.store import MarginStore
22
+
23
+
24
+ @pytest.fixture
25
+ def impl(tmp_path):
26
+ pytest.importorskip("mcp")
27
+ from seren_margin.mcp.tools import MarginToolImpl
28
+ cfg = MarginConfig(db_path=str(tmp_path / "notes.db"))
29
+ return MarginToolImpl(MarginStore(cfg.resolved_db_path()), cfg)
30
+
31
+
32
+ def _fill(impl):
33
+ impl.note_to_self("a thought of my own", topic="the room")
34
+ impl.note_to_self("an untopiced one")
35
+ impl.write_letter("to the next me: the draft review went fine")
36
+ impl.write_letter("to the next me: watch the port")
37
+
38
+
39
+ def test_the_board_is_the_notes_and_the_mail_is_apart(impl):
40
+ _fill(impl)
41
+ board = impl.list_my_notes()
42
+ assert board["count"] == 2
43
+ assert all(n["kind"] != "letter" for n in board["notes"])
44
+ everything = impl.list_my_notes(include_letters=True)
45
+ assert everything["count"] == 4
46
+ # looking at the board opened nothing: both letters still wait
47
+ assert impl.read_letters()["count"] == 2
48
+
49
+
50
+ def test_a_topic_filter_still_leaves_the_mail_out_unless_asked(impl):
51
+ impl.note_to_self("kept", topic="t")
52
+ impl.store.add(MarginNote(content="mail", kind="letter", topic="t"))
53
+ assert [n["content"] for n in impl.list_my_notes(topic="t")["notes"]] == ["kept"]
54
+ assert len(impl.list_my_notes(topic="t", include_letters=True)["notes"]) == 2
55
+
56
+
57
+ def test_topics_count_letters_on_their_own_line_and_still_reconcile(impl):
58
+ _fill(impl)
59
+ impl.read_letters(limit=1) # one opened, one waiting
60
+ r = impl.list_my_topics()
61
+ assert {t["topic"]: t["count"] for t in r["topics"]} == {"the room": 1, None: 1}
62
+ assert r["letters"] == {"count": 2, "unread": 1}
63
+ assert sum(t["count"] for t in r["topics"]) + r["letters"]["count"] == impl.store.stats().total
64
+
65
+
66
+ def test_search_still_finds_a_letter(impl):
67
+ _fill(impl)
68
+ hits = impl.search_my_notes("port")
69
+ assert hits["count"] == 1 and hits["notes"][0]["kind"] == "letter"
70
+
71
+
72
+ def test_over_http_the_same(tmp_path):
73
+ with TestClient(create_app(MarginConfig(db_path=str(tmp_path / "notes.db"), http_reads=True))) as c:
74
+ c.post("/notes", json={"content": "mine"})
75
+ c.post("/letters", json={"content": "mail"})
76
+ assert [n["content"] for n in c.get("/notes").json()["entries"]] == ["mine"]
77
+ assert len(c.get("/notes?letters=true").json()["entries"]) == 2
78
+ topics = c.get("/notes/topics").json()
79
+ assert topics["letters"] == {"count": 1, "unread": 1}
80
+ assert sum(t["count"] for t in topics["topics"]) == 1
@@ -1,8 +0,0 @@
1
- {
2
- "tag": "5.1.2",
3
- "distance": 0,
4
- "node": "gb4a35543474e4379819ded2618d8d17f5198e2f1",
5
- "dirty": false,
6
- "branch": "HEAD",
7
- "node_date": "2026-10-16"
8
- }
File without changes
File without changes
File without changes