memcal 0.8.0__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 (92) hide show
  1. memcal/__init__.py +6 -0
  2. memcal/__main__.py +3 -0
  3. memcal/actions.py +230 -0
  4. memcal/activity.py +447 -0
  5. memcal/archive.py +540 -0
  6. memcal/brief.py +818 -0
  7. memcal/calls.py +247 -0
  8. memcal/cli.py +2547 -0
  9. memcal/config.py +271 -0
  10. memcal/dates.py +242 -0
  11. memcal/db.py +426 -0
  12. memcal/detail.py +343 -0
  13. memcal/dream/__init__.py +7 -0
  14. memcal/dream/affinity.py +282 -0
  15. memcal/dream/apply.py +1292 -0
  16. memcal/dream/bundle.py +366 -0
  17. memcal/dream/instructions.py +127 -0
  18. memcal/dream/merge.py +1128 -0
  19. memcal/dream/propose.py +1607 -0
  20. memcal/dream/resolve.py +7 -0
  21. memcal/dream/retry.py +60 -0
  22. memcal/dream/run.py +677 -0
  23. memcal/dream/stages.py +96 -0
  24. memcal/dream/sweep.py +180 -0
  25. memcal/dream/wakes.py +274 -0
  26. memcal/events.py +1492 -0
  27. memcal/gate.py +400 -0
  28. memcal/harness.py +163 -0
  29. memcal/identity.py +592 -0
  30. memcal/legacy.py +109 -0
  31. memcal/live.py +790 -0
  32. memcal/llm.py +1090 -0
  33. memcal/lock.py +99 -0
  34. memcal/macos/icon.png +0 -0
  35. memcal/macos/launcher.c +51 -0
  36. memcal/mcp_server.py +956 -0
  37. memcal/pending.py +232 -0
  38. memcal/presentation.py +55 -0
  39. memcal/questions.py +149 -0
  40. memcal/schedule.py +926 -0
  41. memcal/schema.sql +637 -0
  42. memcal/series.py +396 -0
  43. memcal/settings.py +594 -0
  44. memcal/sources/__init__.py +204 -0
  45. memcal/sources/base.py +389 -0
  46. memcal/sources/bluebubbles.py +196 -0
  47. memcal/sources/groupme.py +666 -0
  48. memcal/sources/ical.py +2544 -0
  49. memcal/sources/imessage.py +301 -0
  50. memcal/sources/polled.py +386 -0
  51. memcal/sources/proton.py +693 -0
  52. memcal/sources/providers/__init__.py +68 -0
  53. memcal/sources/providers/partiful.py +312 -0
  54. memcal/sources/signal.py +278 -0
  55. memcal/sources/slack.py +502 -0
  56. memcal/sources/spec.py +106 -0
  57. memcal/sources/telegram.py +314 -0
  58. memcal/sources/whatsapp.py +403 -0
  59. memcal/static/app.js +15 -0
  60. memcal/static/chats.js +139 -0
  61. memcal/static/core.js +134 -0
  62. memcal/static/dream.js +496 -0
  63. memcal/static/gate.js +268 -0
  64. memcal/static/icon.png +0 -0
  65. memcal/static/jobs.js +160 -0
  66. memcal/static/memory.js +527 -0
  67. memcal/static/runs.js +330 -0
  68. memcal/static/senders.js +76 -0
  69. memcal/static/settings.js +709 -0
  70. memcal/static/styles.css +737 -0
  71. memcal/static/trace.js +210 -0
  72. memcal/static/wiki.js +57 -0
  73. memcal/textclean.py +179 -0
  74. memcal/threads.py +642 -0
  75. memcal/todos.py +1047 -0
  76. memcal/trace.py +528 -0
  77. memcal/web.py +104 -0
  78. memcal/web_dream.py +205 -0
  79. memcal/web_jobs.py +447 -0
  80. memcal/web_memory.py +670 -0
  81. memcal/web_queue.py +516 -0
  82. memcal/web_server.py +455 -0
  83. memcal/web_settings.py +250 -0
  84. memcal/webui.html +333 -0
  85. memcal/whois.py +452 -0
  86. memcal/wiki.py +1002 -0
  87. memcal-0.8.0.dist-info/METADATA +66 -0
  88. memcal-0.8.0.dist-info/RECORD +92 -0
  89. memcal-0.8.0.dist-info/WHEEL +5 -0
  90. memcal-0.8.0.dist-info/entry_points.txt +2 -0
  91. memcal-0.8.0.dist-info/licenses/LICENSE +21 -0
  92. memcal-0.8.0.dist-info/top_level.txt +1 -0
memcal/__init__.py ADDED
@@ -0,0 +1,6 @@
1
+ """memcal — a calendar and a to-do list that live in context.
2
+
3
+ Entry point: memcal.cli:main.
4
+ """
5
+
6
+ __version__ = "0.1.0"
memcal/__main__.py ADDED
@@ -0,0 +1,3 @@
1
+ from .cli import main
2
+
3
+ raise SystemExit(main())
memcal/actions.py ADDED
@@ -0,0 +1,230 @@
1
+ """Completed typed actions for replay safety and nightly context.
2
+
3
+ Each record identifies the operation, its stable target, changed fields, source message
4
+ ids, and the state version it acted on. This lets a retry remain a no-op and prevents a
5
+ nightly reread from duplicating or undoing a daytime correction. Surfaces pass `Origin`
6
+ explicitly because concurrent sessions make global "latest message" state ambiguous.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ import hashlib
12
+ import json
13
+ import sqlite3
14
+ from dataclasses import dataclass, field
15
+
16
+ from . import db
17
+
18
+ #: Recorded when a caller supplies no originating turn. The operation still happens; the
19
+ #: limitation is written down rather than left for a reader to mistake for "no cause".
20
+ NO_SOURCE_NOTE = "caller supplied no originating turn"
21
+
22
+
23
+ @dataclass(frozen=True)
24
+ class Origin:
25
+ """Where a typed write came from, and what evidence it considered.
26
+
27
+ `archive_ids` is authorship: the turn behind this call. `cited` is review:
28
+ activity lines the caller opened and is answering with. The two ride
29
+ together for provenance but only `cited` acknowledges reviewed
30
+ observations — a newer user question must never mark older unread source
31
+ messages as considered.
32
+ """
33
+
34
+ surface: str = "unknown"
35
+ #: Archive ids of the turn behind this call. Empty is allowed and recorded.
36
+ archive_ids: tuple[int, ...] = ()
37
+ #: Archive ids of opened evidence this write answers with. Validated and
38
+ #: reviewed at the write; unknown ids are dropped, never stored.
39
+ cited: tuple[int, ...] = ()
40
+ session: str = ""
41
+ note: str = ""
42
+ #: The caller's own idempotency key for this operation, when it has one. A client
43
+ #: retrying a call whose answer it never saw supplies the same key, and the retry
44
+ #: becomes a no-op instead of a second instruction.
45
+ op_id: str = ""
46
+
47
+ @classmethod
48
+ def of(cls, surface: str, archive_ids=None, *, cited=None, session: str = "",
49
+ note: str = "", op_id: str = "") -> "Origin":
50
+ ids = tuple(int(i) for i in (archive_ids or ()) if i)
51
+ cites = tuple(int(i) for i in (cited or ()) if i)
52
+ return cls(surface=surface or "unknown", archive_ids=ids, cited=cites,
53
+ session=session, op_id=op_id,
54
+ note=note or ("" if (ids or cites) else NO_SOURCE_NOTE))
55
+
56
+ @property
57
+ def sourced(self) -> bool:
58
+ return bool(self.archive_ids or self.cited)
59
+
60
+
61
+ #: The default for a caller that has not been taught to supply context yet. Callers
62
+ #: without source context must still work; this is what "and record that limitation"
63
+ #: looks like in practice.
64
+ UNKNOWN = Origin.of("unknown")
65
+
66
+
67
+ @dataclass
68
+ class Action:
69
+ op_id: str
70
+ kind: str
71
+ ref: str
72
+ verb: str
73
+ surface: str
74
+ fields: dict = field(default_factory=dict)
75
+ source_ids: list[int] = field(default_factory=list)
76
+ source_note: str = ""
77
+ based_on: str = ""
78
+ session: str = ""
79
+ at: str = ""
80
+
81
+ @classmethod
82
+ def from_row(cls, row: sqlite3.Row) -> "Action":
83
+ return cls(
84
+ op_id=row["op_id"], kind=row["kind"], ref=row["ref"], verb=row["verb"],
85
+ surface=row["surface"], fields=db.jload(row["fields"], {}),
86
+ source_ids=db.jload(row["source_ids"], []),
87
+ source_note=row["source_note"] or "", based_on=row["based_on"] or "",
88
+ session=row["session"] or "", at=row["at"])
89
+
90
+ @property
91
+ def changed(self) -> list[str]:
92
+ return sorted(self.fields)
93
+
94
+ def one_line(self) -> str:
95
+ """"11:04 · moved date 2026-09-18 → 2026-09-19" — enough to recognise it."""
96
+ parts = []
97
+ for name in self.changed:
98
+ pair = self.fields.get(name)
99
+ if isinstance(pair, (list, tuple)) and len(pair) == 2:
100
+ old, new = pair
101
+ parts.append(f"{name} {old or '(none)'} → {new or '(none)'}"
102
+ if str(old) != str(new) else f"{name} {new}")
103
+ else:
104
+ parts.append(f"{name} {pair}")
105
+ detail = "; ".join(parts) if parts else "no field changed"
106
+ return f"{str(self.at)[11:16]} · {self.verb} · {detail}"
107
+
108
+
109
+ def plan(*, kind: str, ref: str, verb: str, origin: Origin, request: dict,
110
+ at: str) -> str:
111
+ """Identify an operation from its request before state changes.
112
+
113
+ A caller key wins. Otherwise the digest covers the target, verb, supplied fields,
114
+ and source turn—not mutable before-values—so retries keep one identity. With no
115
+ attributable turn, the timestamp keeps identical unknown calls distinct.
116
+ """
117
+ if origin.op_id:
118
+ return str(origin.op_id)[:64]
119
+ seed = json.dumps({
120
+ "kind": kind, "ref": ref, "verb": verb,
121
+ "surface": origin.surface, "session": origin.session,
122
+ "sources": sorted(origin.archive_ids),
123
+ "cited": sorted(origin.cited),
124
+ "request": {k: request[k] for k in sorted(request)},
125
+ "at": "" if origin.sourced else at,
126
+ }, sort_keys=True, default=str)
127
+ return hashlib.sha1(seed.encode()).hexdigest()[:20]
128
+
129
+
130
+ def seen(conn: sqlite3.Connection, identifier: str) -> bool:
131
+ """Has this exact operation already been carried out?
132
+
133
+ Called inside the transaction that is about to mutate, so the answer cannot go stale
134
+ between the check and the write.
135
+ """
136
+ if not identifier:
137
+ return False
138
+ return conn.execute("SELECT 1 FROM actions WHERE op_id = ? LIMIT 1",
139
+ (identifier,)).fetchone() is not None
140
+
141
+
142
+ def record(conn: sqlite3.Connection, *, kind: str, ref: str, verb: str,
143
+ origin: Origin = UNKNOWN, fields: dict | None = None,
144
+ based_on: str | None = None, at: str | None = None,
145
+ op_id: str = "", commit: bool = False) -> str:
146
+ """Write one completed operation. Returns its id; a repeat is a no-op.
147
+
148
+ `op_id` is the identity `plan()` computed before the change was made. Deliberately
149
+ never commits by default: the caller commits the state change and this record
150
+ together, or neither happens.
151
+ """
152
+ if not ref:
153
+ return ""
154
+ fields = {k: v for k, v in (fields or {}).items()}
155
+ stamp = at or db.now()
156
+ identifier = op_id or plan(kind=kind, ref=ref, verb=verb, origin=origin,
157
+ request=fields, at=stamp)
158
+ conn.execute(
159
+ """INSERT INTO actions(op_id, kind, ref, verb, surface, session, fields,
160
+ source_ids, source_note, based_on, at)
161
+ VALUES(?,?,?,?,?,?,?,?,?,?,?) ON CONFLICT(op_id) DO NOTHING""",
162
+ (identifier, kind, ref, verb, origin.surface, origin.session or None,
163
+ db.jdump(fields), db.jdump(list(origin.archive_ids)),
164
+ origin.note or (None if origin.sourced else NO_SOURCE_NOTE),
165
+ based_on or None, stamp),
166
+ )
167
+ if commit:
168
+ conn.commit()
169
+ return identifier
170
+
171
+
172
+ def for_refs(conn: sqlite3.Connection, kind: str, refs, *,
173
+ limit: int = 12) -> list[Action]:
174
+ """Completed operations against these targets, newest last."""
175
+ keys = [str(ref) for ref in refs if ref]
176
+ if not keys:
177
+ return []
178
+ holes = ",".join("?" for _ in keys)
179
+ rows = conn.execute(
180
+ f"SELECT * FROM actions WHERE kind = ? AND ref IN ({holes})"
181
+ f" ORDER BY at DESC, id DESC LIMIT ?", (kind, *keys, limit)).fetchall()
182
+ return [Action.from_row(row) for row in reversed(rows)]
183
+
184
+
185
+ def for_archive(conn: sqlite3.Connection, archive_ids, *,
186
+ limit: int = 12) -> list[Action]:
187
+ """Operations whose originating turn includes any of these archive lines.
188
+
189
+ This is the half that makes a *statement* recognisable as already acted on, rather
190
+ than only a row recognisable as already touched.
191
+ """
192
+ wanted = {int(i) for i in (archive_ids or ()) if i}
193
+ if not wanted:
194
+ return []
195
+ out: list[Action] = []
196
+ for row in conn.execute(
197
+ "SELECT * FROM actions ORDER BY at DESC, id DESC LIMIT 400"):
198
+ action = Action.from_row(row)
199
+ if wanted & set(action.source_ids):
200
+ out.append(action)
201
+ if len(out) >= limit:
202
+ break
203
+ return list(reversed(out))
204
+
205
+
206
+ def latest_for(conn: sqlite3.Connection, kind: str, ref: str) -> Action | None:
207
+ row = conn.execute(
208
+ "SELECT * FROM actions WHERE kind = ? AND ref = ? ORDER BY at DESC, id DESC"
209
+ " LIMIT 1", (kind, ref)).fetchone()
210
+ return Action.from_row(row) if row else None
211
+
212
+
213
+ def render(actions: list[Action]) -> str:
214
+ """The block a bundle shows the model. Says what was done and what it was reading."""
215
+ if not actions:
216
+ return ""
217
+ lines = [
218
+ "ALREADY DONE FOR THIS CONVERSATION BY THE ASSISTANT'S TYPED TOOLS.",
219
+ "These changes are already in the store. A line here that only restates one of",
220
+ "them is not news: do not propose it again, and do not create a second row for",
221
+ "it. The rest of the message may still contain facts nothing has acted on.",
222
+ ]
223
+ for action in actions:
224
+ bits = [action.ref, action.one_line()]
225
+ if action.source_ids:
226
+ bits.append("from line(s) " + ", ".join(str(i) for i in action.source_ids))
227
+ elif action.source_note:
228
+ bits.append(f"({action.source_note})")
229
+ lines.append(" " + " | ".join(bits))
230
+ return "\n".join(lines)