memory-cli 0.1.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 (128) hide show
  1. memory_cli/__init__.py +1 -0
  2. memory_cli/__main__.py +49 -0
  3. memory_cli/capture/__init__.py +7 -0
  4. memory_cli/capture/codex_rollout.py +164 -0
  5. memory_cli/capture/event_lines.py +66 -0
  6. memory_cli/capture/extract.py +458 -0
  7. memory_cli/capture/state.py +183 -0
  8. memory_cli/commands/__init__.py +21 -0
  9. memory_cli/commands/admin.py +363 -0
  10. memory_cli/commands/common.py +609 -0
  11. memory_cli/commands/curate.py +1189 -0
  12. memory_cli/commands/diagnostics.py +126 -0
  13. memory_cli/commands/edit.py +1282 -0
  14. memory_cli/commands/hooks.py +730 -0
  15. memory_cli/commands/import_recovery.py +45 -0
  16. memory_cli/commands/install.py +152 -0
  17. memory_cli/commands/integrate.py +480 -0
  18. memory_cli/commands/memory.py +2152 -0
  19. memory_cli/commands/read.py +1290 -0
  20. memory_cli/commands/sources.py +766 -0
  21. memory_cli/commands/split.py +97 -0
  22. memory_cli/commands/split_plan.py +196 -0
  23. memory_cli/commands/split_transaction.py +230 -0
  24. memory_cli/commands/synthesis.py +1122 -0
  25. memory_cli/core/__init__.py +16 -0
  26. memory_cli/core/auto_state.py +30 -0
  27. memory_cli/core/codex_pass.py +109 -0
  28. memory_cli/core/config.py +87 -0
  29. memory_cli/core/file_journal.py +163 -0
  30. memory_cli/core/headless.py +130 -0
  31. memory_cli/core/jobs.py +130 -0
  32. memory_cli/core/resources.py +57 -0
  33. memory_cli/core/runner.py +398 -0
  34. memory_cli/core/safe_io.py +155 -0
  35. memory_cli/core/store_git.py +407 -0
  36. memory_cli/core/yaml_load.py +14 -0
  37. memory_cli/corroborate/__init__.py +11 -0
  38. memory_cli/corroborate/cli.py +267 -0
  39. memory_cli/corroborate/decide.py +893 -0
  40. memory_cli/corroborate/digest.py +425 -0
  41. memory_cli/corroborate/fill.py +744 -0
  42. memory_cli/corroborate/job.py +15 -0
  43. memory_cli/corroborate/reword.py +446 -0
  44. memory_cli/corroborate/run.py +1142 -0
  45. memory_cli/corroborate/state.py +300 -0
  46. memory_cli/digest/__init__.py +4 -0
  47. memory_cli/digest/lessons.py +483 -0
  48. memory_cli/entry/__init__.py +12 -0
  49. memory_cli/entry/auto.py +660 -0
  50. memory_cli/entry/capture.py +1403 -0
  51. memory_cli/entry/corroborate.py +214 -0
  52. memory_cli/entry/integrate.py +684 -0
  53. memory_cli/entry/integrate_self_check.py +203 -0
  54. memory_cli/entry/research.py +9 -0
  55. memory_cli/entry/settle.py +614 -0
  56. memory_cli/entry/split_auto.py +460 -0
  57. memory_cli/entry/synthesize.py +22 -0
  58. memory_cli/integrate/__init__.py +9 -0
  59. memory_cli/integrate/answers.py +42 -0
  60. memory_cli/integrate/briefs/check-brief.md +16 -0
  61. memory_cli/integrate/briefs/place-brief.md +26 -0
  62. memory_cli/integrate/log.py +43 -0
  63. memory_cli/integrate/plan.py +125 -0
  64. memory_cli/integrate/rows.py +99 -0
  65. memory_cli/integrate/state.py +158 -0
  66. memory_cli/integrate/undo.py +143 -0
  67. memory_cli/mem.py +1180 -0
  68. memory_cli/memories/__init__.py +16 -0
  69. memory_cli/memories/fingerprints.py +51 -0
  70. memory_cli/memories/journal.py +93 -0
  71. memory_cli/memories/locations.py +282 -0
  72. memory_cli/memories/matching.py +451 -0
  73. memory_cli/memories/model.py +205 -0
  74. memory_cli/memories/parse.py +237 -0
  75. memory_cli/memories/records.py +266 -0
  76. memory_cli/memories/rules.py +291 -0
  77. memory_cli/memories/sightings.py +314 -0
  78. memory_cli/memories/terms.py +148 -0
  79. memory_cli/memories/write.py +358 -0
  80. memory_cli/notes/__init__.py +13 -0
  81. memory_cli/notes/check.py +806 -0
  82. memory_cli/notes/due.py +260 -0
  83. memory_cli/notes/fields.py +217 -0
  84. memory_cli/notes/index.py +230 -0
  85. memory_cli/notes/links.py +170 -0
  86. memory_cli/notes/note.py +222 -0
  87. memory_cli/notes/search.py +391 -0
  88. memory_cli/notes/split_candidates.py +72 -0
  89. memory_cli/research/__init__.py +5 -0
  90. memory_cli/research/checks.py +1065 -0
  91. memory_cli/research/pipeline.py +952 -0
  92. memory_cli/session/__init__.py +5 -0
  93. memory_cli/session/handoff.py +139 -0
  94. memory_cli/session/notices.py +111 -0
  95. memory_cli/settle/__init__.py +5 -0
  96. memory_cli/settle/state.py +111 -0
  97. memory_cli/settle/verdicts.py +693 -0
  98. memory_cli/split/briefs/checker-brief.md +5 -0
  99. memory_cli/split/briefs/editor-brief.md +20 -0
  100. memory_cli/syntheses/__init__.py +8 -0
  101. memory_cli/syntheses/document.py +400 -0
  102. memory_cli/syntheses/edit.py +581 -0
  103. memory_cli/syntheses/project.py +384 -0
  104. memory_cli/syntheses/split_conservation.py +50 -0
  105. memory_cli/syntheses/units.py +427 -0
  106. memory_cli/synthesize/__init__.py +9 -0
  107. memory_cli/synthesize/backfill.py +431 -0
  108. memory_cli/synthesize/briefs/backfill-brief.md +26 -0
  109. memory_cli/synthesize/briefs/checker-brief.md +13 -0
  110. memory_cli/synthesize/briefs/fixer-brief.md +19 -0
  111. memory_cli/synthesize/briefs/memory-brief.md +30 -0
  112. memory_cli/synthesize/briefs/settle-brief.md +32 -0
  113. memory_cli/synthesize/briefs/verdict-brief.md +50 -0
  114. memory_cli/synthesize/briefs/web-brief.md +33 -0
  115. memory_cli/synthesize/cli.py +311 -0
  116. memory_cli/synthesize/pipeline.py +764 -0
  117. memory_cli/synthesize/references.py +164 -0
  118. memory_cli/synthesize/run.py +150 -0
  119. memory_cli/synthesize/topics.py +528 -0
  120. memory_cli/templates/knowledge.md +23 -0
  121. memory_cli/templates/literature.md +25 -0
  122. memory_cli/templates/research.md +23 -0
  123. memory_cli/templates/synthesis.md +6 -0
  124. memory_cli-0.1.0.dist-info/METADATA +102 -0
  125. memory_cli-0.1.0.dist-info/RECORD +128 -0
  126. memory_cli-0.1.0.dist-info/WHEEL +4 -0
  127. memory_cli-0.1.0.dist-info/entry_points.txt +9 -0
  128. memory_cli-0.1.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,214 @@
1
+ """mem-corroborate: a background pass that matches lessons by meaning and keeps one general record of each.
2
+
3
+ `run` collects the active transcript lessons of the registered projects and of the global scope, writes them to a
4
+ lessons file (ids only, no project name or path) and starts two tool-less headless sessions: the first proposes
5
+ groups of lessons that state the same thing; the second, a fresh process that sees only the proposals, says for each
6
+ group whether it is the same lesson, faithfully worded and general. Code validates both answers (`corroborate`) and
7
+ applies only the groups that pass, always through `bin/mem` (a secret, a forbidden term or a refused merge is
8
+ counted, never forced). The claim of an existing record is never changed.
9
+
10
+ Undo works on file copies: before a run's first write to a record's file the file is copied to
11
+ `runs/<stamp>/before/`, and `journal.jsonl` holds each action, the file, whether the run created it and the hash of
12
+ the file afterwards. `undo <stamp>` restores or removes them, and refuses, changing nothing, when a file changed
13
+ since. The run folder is private and may hold memory text; `log.jsonl` holds counts only.
14
+
15
+ `auto` is what a hook starts when the plugin option `auto_capture` is exactly `true`: it never raises and never prints.
16
+
17
+ Usage: mem-corroborate run [--claude PATH] [--budget USD] [--dry-run --out FILE] [--groups FILE]
18
+ mem-corroborate auto [--claude PATH] | undo STAMP | status | ack | --self-check
19
+ mem-corroborate fill --dry-run --out FILE [--claude PATH] [--budget USD] | fill --items FILE
20
+
21
+ `fill` proposes the one-line short form and the topic of the lessons that could load as rules at session start but
22
+ lack them. Nothing writes a short form unread: `--dry-run --out FILE` only writes the proposal (one session of the
23
+ small model); the owner reads and edits FILE, and `--items FILE` applies it through `mem memory edit` (journaled:
24
+ `undo STAMP` puts the records back). Each item also carries `load`: `yes` (a rule), `index` (only counted by topic)
25
+ or `no` (never loaded); the owner may change it. `seen.json` and the status of the pass are not touched.
26
+ """
27
+
28
+ from __future__ import annotations
29
+
30
+ import argparse
31
+ import datetime
32
+ import logging
33
+ import os
34
+ import shutil
35
+ import sys
36
+ import time
37
+
38
+ from memory_cli.capture import state as cs
39
+ from memory_cli.core import runner as runners
40
+ from memory_cli.corroborate import state as corroborate_state
41
+
42
+ try: # `auto` must still be able to write a failed status when the engine cannot be imported (e.g. no yaml)
43
+ from memory_cli.corroborate import cli as corroborate_cli
44
+
45
+ IMPORT_ERROR: Exception | None = None
46
+ except Exception as _exc:
47
+ corroborate_cli = None
48
+ IMPORT_ERROR = _exc
49
+ logging.getLogger(__name__).debug("the engine cannot be loaded", exc_info=True)
50
+
51
+
52
+ def _no_engine(_args) -> int:
53
+ print(f"mem-corroborate: cannot load the engine: {IMPORT_ERROR}", file=sys.stderr)
54
+ return 1
55
+
56
+
57
+ def _failed_status_for_auto() -> None:
58
+ if os.environ.get(cs.OPTION) != "true":
59
+ return
60
+ start = time.time()
61
+ stamp = datetime.datetime.now(datetime.UTC).isoformat(timespec="seconds")
62
+ cdir = corroborate_state.corroborate_dir(corroborate_state.data_dir())
63
+ reason = "engine import error"
64
+ failure = {"at": time.time(), "reason": reason, "log": ""}
65
+ corroborate_state.save_status(cdir, state="failed", finished=time.time(), failure=failure)
66
+ counts = dict.fromkeys(("lessons", "groups", "proposed", "verified", "dropped", "written"), 0)
67
+ counts |= dict.fromkeys(
68
+ ("sightings", "links", "merges", "refused", "failed_actions", "cases"), 0
69
+ )
70
+ ms = int((time.time() - start) * 1000)
71
+ line = {"t": stamp, **counts, "skipped": None, "cost": 0.0, "failed": reason, "ms": ms}
72
+ corroborate_state.append_log(cdir, line)
73
+
74
+
75
+ def _auto_without_engine(_args) -> int:
76
+ """`auto` when the engine cannot load: the failed status and the log line `execute` wrote for it, nothing else;
77
+ never raises and never prints."""
78
+ try:
79
+ _failed_status_for_auto()
80
+ except BaseException:
81
+ logging.getLogger(__name__).debug("auto: the failed status was not written", exc_info=True)
82
+ return 0
83
+
84
+
85
+ def _command(name: str, without_engine=_no_engine):
86
+ """The engine's command, or `without_engine` when the engine cannot load (`status`, `ack` and `undo` never need it)."""
87
+ return without_engine if corroborate_cli is None else getattr(corroborate_cli, name)
88
+
89
+
90
+ def main(argv: list[str] | None = None) -> int:
91
+ parser = argparse.ArgumentParser(
92
+ prog="mem-corroborate", description=(__doc__ or "").splitlines()[0]
93
+ )
94
+ parser.add_argument(
95
+ "--self-check", action="store_true", help="no model: prove the briefs, gates, lock and undo"
96
+ )
97
+ commands = parser.add_subparsers(dest="command")
98
+ default_claude = os.environ.get("CLAUDE_CODE_EXECPATH") or shutil.which("claude")
99
+ run = commands.add_parser(
100
+ "run", help="match the lessons by meaning and apply the verified groups"
101
+ )
102
+ run.add_argument("--claude", default=default_claude)
103
+ runners.add_flag(run)
104
+ run.add_argument(
105
+ "--budget",
106
+ type=corroborate_state.budget_of,
107
+ default=corroborate_state.DEFAULT_BUDGET,
108
+ help=f"USD per session (default {corroborate_state.DEFAULT_BUDGET})",
109
+ )
110
+ run.add_argument(
111
+ "--dry-run",
112
+ action="store_true",
113
+ help="run both sessions; write the plan to --out and change nothing else",
114
+ )
115
+ run.add_argument(
116
+ "--out",
117
+ help="with --dry-run: the file for the proposal, the verdicts and the planned actions",
118
+ )
119
+ run.add_argument(
120
+ "--groups", help="apply a reviewed file in the model's format; starts no model session"
121
+ )
122
+ run.set_defaults(func=_command("cmd_run"))
123
+ fill = commands.add_parser(
124
+ "fill",
125
+ help="propose the short form and topic of lessons for the owner to read, or apply that file",
126
+ )
127
+ fill.add_argument("--claude", default=default_claude)
128
+ runners.add_flag(fill)
129
+ fill.add_argument(
130
+ "--budget",
131
+ type=corroborate_state.budget_of,
132
+ default=corroborate_state.DEFAULT_BUDGET,
133
+ help=f"USD for the session (default {corroborate_state.DEFAULT_BUDGET})",
134
+ )
135
+ fill.add_argument(
136
+ "--dry-run",
137
+ action="store_true",
138
+ help="one session; write the proposal to --out and change no record",
139
+ )
140
+ fill.add_argument("--out", help="with --dry-run: the file for the proposal")
141
+ fill.add_argument(
142
+ "--items",
143
+ help="apply a proposal file, as read and edited by the owner; starts no model session",
144
+ )
145
+ fill.set_defaults(func=_command("cmd_fill"))
146
+ reword = commands.add_parser(
147
+ "reword", help="write a new short form for loaded lessons that got worse, as the pass does"
148
+ )
149
+ reword.add_argument("--claude", default=default_claude)
150
+ runners.add_flag(reword)
151
+ reword.add_argument(
152
+ "--budget",
153
+ type=corroborate_state.budget_of,
154
+ default=corroborate_state.DEFAULT_BUDGET,
155
+ help=f"USD per session (default {corroborate_state.DEFAULT_BUDGET})",
156
+ )
157
+ reword.add_argument(
158
+ "--every", action="store_true", help="take loaded lessons that did not get worse too"
159
+ )
160
+ reword.add_argument(
161
+ "--limit", type=int, default=30, help="with --every: at most this many lessons (default 30)"
162
+ )
163
+ reword.add_argument(
164
+ "--dry-run",
165
+ action="store_true",
166
+ help="run both sessions; change no record and save no state",
167
+ )
168
+ reword.add_argument(
169
+ "--sheet", help="write a Markdown table of every candidate and its outcome to this file"
170
+ )
171
+ reword.set_defaults(func=_command("cmd_reword"))
172
+ digest_cmd = commands.add_parser(
173
+ "digest",
174
+ help="write the heading and the lines of the loaded lessons' digest, as the pass does",
175
+ )
176
+ digest_cmd.add_argument("--claude", default=default_claude)
177
+ runners.add_flag(digest_cmd)
178
+ digest_cmd.add_argument(
179
+ "--budget",
180
+ type=corroborate_state.budget_of,
181
+ default=corroborate_state.DEFAULT_BUDGET,
182
+ help=f"USD per session (default {corroborate_state.DEFAULT_BUDGET})",
183
+ )
184
+ digest_cmd.add_argument(
185
+ "--dry-run",
186
+ action="store_true",
187
+ help="run both sessions; write no digest and save no state",
188
+ )
189
+ digest_cmd.add_argument(
190
+ "--sheet", help="write a Markdown table of every line judged and its outcome to this file"
191
+ )
192
+ digest_cmd.set_defaults(func=_command("cmd_digest"))
193
+ auto = commands.add_parser(
194
+ "auto", help="what a hook starts: one run when the option is on; silent"
195
+ )
196
+ auto.add_argument("--claude", default=default_claude)
197
+ runners.add_flag(auto)
198
+ auto.set_defaults(func=_command("cmd_auto", _auto_without_engine))
199
+ undo = commands.add_parser("undo", help="put back the files a run changed")
200
+ undo.add_argument("stamp")
201
+ undo.set_defaults(func=corroborate_state.cmd_undo)
202
+ commands.add_parser("status", help="the last run").set_defaults(
203
+ func=lambda _a: corroborate_state.cmd_status()
204
+ )
205
+ commands.add_parser("ack", help="clear the failure line").set_defaults(
206
+ func=lambda _a: corroborate_state.cmd_ack()
207
+ )
208
+ args = parser.parse_args(argv)
209
+ if args.self_check:
210
+ return _no_engine(args) if corroborate_cli is None else corroborate_cli.self_check()
211
+ if not args.command:
212
+ parser.error("a command is required")
213
+ runners.pin_flag(getattr(args, "runner", None))
214
+ return args.func(args)