keepfold 0.6.4__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 (148) hide show
  1. keepfold/__init__.py +1 -0
  2. keepfold/_proc.py +102 -0
  3. keepfold/access.py +154 -0
  4. keepfold/agent_eval.py +162 -0
  5. keepfold/agent_text.py +56 -0
  6. keepfold/anki.py +285 -0
  7. keepfold/app/__init__.py +5 -0
  8. keepfold/app/actions.py +690 -0
  9. keepfold/app/desktop.py +677 -0
  10. keepfold/app/exports.py +254 -0
  11. keepfold/app/hello.py +79 -0
  12. keepfold/app/launch.py +114 -0
  13. keepfold/app/news.py +60 -0
  14. keepfold/app/server.py +3142 -0
  15. keepfold/app/status.py +811 -0
  16. keepfold/app/targets.py +1374 -0
  17. keepfold/app/winpath.py +54 -0
  18. keepfold/app/wizard.py +506 -0
  19. keepfold/ask.py +475 -0
  20. keepfold/askfile.py +322 -0
  21. keepfold/assets/LICENSE-d3.txt +13 -0
  22. keepfold/assets/agent_eval.json +235 -0
  23. keepfold/assets/app/app.css +611 -0
  24. keepfold/assets/app/app.js +2712 -0
  25. keepfold/assets/app/capture.html +16 -0
  26. keepfold/assets/app/capture.js +91 -0
  27. keepfold/assets/app/index.html +149 -0
  28. keepfold/assets/brain3d.js +3730 -0
  29. keepfold/assets/chat_eval.json +454 -0
  30. keepfold/assets/d3.v7.min.js +2 -0
  31. keepfold/assets/dashboard.css +774 -0
  32. keepfold/assets/dashboard.html.tmpl +170 -0
  33. keepfold/assets/dashboard.js +4262 -0
  34. keepfold/assets/help/GUIDE.md +544 -0
  35. keepfold/assets/help/help.md +83 -0
  36. keepfold/assets/keepfold.ico +0 -0
  37. keepfold/assets/whats_new.json +162 -0
  38. keepfold/backup.py +100 -0
  39. keepfold/brainmap.py +1382 -0
  40. keepfold/browse/__init__.py +10 -0
  41. keepfold/browse/build.py +1320 -0
  42. keepfold/browse/forget.py +510 -0
  43. keepfold/browse/legacy.py +95 -0
  44. keepfold/browse/lists.py +285 -0
  45. keepfold/browse/privacy.py +391 -0
  46. keepfold/browse/selftest.py +166 -0
  47. keepfold/browse/sites.py +1068 -0
  48. keepfold/browse/sources.py +329 -0
  49. keepfold/browse/store.py +991 -0
  50. keepfold/browse/takeout.py +312 -0
  51. keepfold/browse/titles.py +127 -0
  52. keepfold/browse/vectors.py +326 -0
  53. keepfold/browse_serve.py +332 -0
  54. keepfold/catalog.py +564 -0
  55. keepfold/chat.py +1464 -0
  56. keepfold/chat_archive.py +165 -0
  57. keepfold/chat_eval.py +583 -0
  58. keepfold/chat_facts.py +721 -0
  59. keepfold/chat_import.py +1045 -0
  60. keepfold/chat_pages.py +291 -0
  61. keepfold/chat_study.py +371 -0
  62. keepfold/chats.py +669 -0
  63. keepfold/claims.py +650 -0
  64. keepfold/cli.py +3254 -0
  65. keepfold/clients.py +96 -0
  66. keepfold/cloudllm.py +135 -0
  67. keepfold/contract.py +43 -0
  68. keepfold/corrections.py +134 -0
  69. keepfold/dashboard.py +959 -0
  70. keepfold/dates.py +202 -0
  71. keepfold/delta.py +146 -0
  72. keepfold/digest.py +72 -0
  73. keepfold/doctor.py +565 -0
  74. keepfold/duplicates.py +145 -0
  75. keepfold/egress.py +68 -0
  76. keepfold/eval_history.py +109 -0
  77. keepfold/events.py +554 -0
  78. keepfold/export_context.py +109 -0
  79. keepfold/fact_harvest.py +578 -0
  80. keepfold/forget.py +720 -0
  81. keepfold/harvest.py +334 -0
  82. keepfold/home.py +714 -0
  83. keepfold/importers.py +627 -0
  84. keepfold/index.py +733 -0
  85. keepfold/know.py +40 -0
  86. keepfold/learning_eval.py +261 -0
  87. keepfold/levels.py +595 -0
  88. keepfold/life_sources.py +747 -0
  89. keepfold/lint.py +241 -0
  90. keepfold/localllm.py +699 -0
  91. keepfold/loops.py +316 -0
  92. keepfold/mcp_server.py +4464 -0
  93. keepfold/migrate.py +552 -0
  94. keepfold/more_sources.py +709 -0
  95. keepfold/packs.py +148 -0
  96. keepfold/people.py +99 -0
  97. keepfold/planner.py +819 -0
  98. keepfold/prime.py +630 -0
  99. keepfold/prime_hook.py +265 -0
  100. keepfold/profiles.py +118 -0
  101. keepfold/quarantine.py +123 -0
  102. keepfold/recall_log.py +93 -0
  103. keepfold/redteam.py +393 -0
  104. keepfold/reflect.py +164 -0
  105. keepfold/relink.py +477 -0
  106. keepfold/render.py +406 -0
  107. keepfold/review.py +1181 -0
  108. keepfold/rollups.py +412 -0
  109. keepfold/safety_net.py +571 -0
  110. keepfold/sample.py +103 -0
  111. keepfold/sample_vault/areas/programming.algorithms.md +11 -0
  112. keepfold/sample_vault/areas/programming.basics.md +11 -0
  113. keepfold/sample_vault/concepts/big-o-notation.md +13 -0
  114. keepfold/sample_vault/concepts/functions.md +13 -0
  115. keepfold/sample_vault/concepts/loops.md +14 -0
  116. keepfold/sample_vault/concepts/recursion.md +13 -0
  117. keepfold/sample_vault/domains/programming.md +10 -0
  118. keepfold/sample_vault/journal/2026-01-12.md +9 -0
  119. keepfold/sample_vault/me/goals.md +17 -0
  120. keepfold/sample_vault/me/profile.md +19 -0
  121. keepfold/sample_vault/mistakes/programming.off-by-one-loop.md +16 -0
  122. keepfold/sample_vault/notes/recursion-needs-a-base-case.md +18 -0
  123. keepfold/sample_vault/problems/fizzbuzz.md +12 -0
  124. keepfold/sample_vault/projects/text-adventure.md +15 -0
  125. keepfold/sample_vault/resources/python-tutorial.md +16 -0
  126. keepfold/semantic.py +1254 -0
  127. keepfold/session.py +764 -0
  128. keepfold/share.py +69 -0
  129. keepfold/sources.py +612 -0
  130. keepfold/sync_copies.py +83 -0
  131. keepfold/tags.py +230 -0
  132. keepfold/taint.py +301 -0
  133. keepfold/tonight.py +195 -0
  134. keepfold/topics.py +1072 -0
  135. keepfold/update.py +300 -0
  136. keepfold/vault.py +942 -0
  137. keepfold/vecstore.py +218 -0
  138. keepfold/voice.py +260 -0
  139. keepfold/voice_memos.py +280 -0
  140. keepfold/watch.py +303 -0
  141. keepfold/where.py +119 -0
  142. keepfold/xray.py +516 -0
  143. keepfold/zotero.py +303 -0
  144. keepfold-0.6.4.dist-info/METADATA +644 -0
  145. keepfold-0.6.4.dist-info/RECORD +148 -0
  146. keepfold-0.6.4.dist-info/WHEEL +4 -0
  147. keepfold-0.6.4.dist-info/entry_points.txt +6 -0
  148. keepfold-0.6.4.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,165 @@
1
+ """C5: imported AI chat pages live in archive/chats/ (vault.CHAT_ARCHIVE), a folder the vault's
2
+ .gitignore keeps out of git, so they are in no new commit and no push. They stay `resource`
3
+ pages (Vault.EXTRA_DIRS): iter_notes, the index, find, recall, Chat and the brain map read them
4
+ as before, a private one stays private, and ids (so `[[id]]` links) never change.
5
+
6
+ `move` takes the chat pages out of resources/ into the archive, through Vault.move (lock, temp
7
+ file, os.replace). A chat page is what chat_import calls one: a resource whose Timeline line
8
+ names its `Source:` app (topics.page_source, semantic.is_chat), or a page the automatic import
9
+ wrote (its `chat_saved` ledger, `auto: true`). In a git repo (git on in settings) their old
10
+ paths leave git's index (`git rm --cached`) in a commit of their own; history is never
11
+ rewritten. `undo` moves every page in the archive back and commits them.
12
+
13
+ `auto` runs the move once from the app's chat-import pass; MARKER records it. `--undo` clears
14
+ MARKER and sets `app.chats_archive: false`: the move never runs again, and new chat pages go to
15
+ resources/ until `keepfold chats archive` turns it back on.
16
+ """
17
+
18
+ from __future__ import annotations
19
+
20
+ from datetime import UTC, datetime
21
+
22
+ from keepfold import taint, topics
23
+ from keepfold.vault import CHAT_ARCHIVE, ID_RE, Vault, VaultError
24
+
25
+ MARKER = ".keepfold/chats-archived"
26
+ IGNORE = CHAT_ARCHIVE + "/"
27
+ MAIN = Vault.KIND_DIRS["resource"]
28
+ MESSAGE = "keepfold: chat pages leave git (moved to archive/chats/)"
29
+ UNDO_MESSAGE = "keepfold: chat pages back in resources/"
30
+
31
+
32
+ def enabled() -> bool:
33
+ """`app.chats_archive` in ~/.keepfold/config.yaml: on unless set to false (by `--undo`)."""
34
+ a = taint.config().get("app")
35
+ return not (isinstance(a, dict) and a.get("chats_archive") is False)
36
+
37
+
38
+ def folder() -> str | None:
39
+ """Where chat_import writes a new chat page: CHAT_ARCHIVE, or None (resources/)."""
40
+ return CHAT_ARCHIVE if enabled() else None
41
+
42
+
43
+ def _set(on: bool) -> None:
44
+ taint.write_config(lambda cfg: {"app": {
45
+ **(cfg["app"] if isinstance(cfg.get("app"), dict) else {}), "chats_archive": on}})
46
+
47
+
48
+ def ensure_ignored(vault: Vault) -> bool:
49
+ """Add the archive's .gitignore line when missing (an older vault), where there is a repo or
50
+ a .gitignore. True when added."""
51
+ ignore = vault.root / ".gitignore"
52
+ if not ((vault.root / ".git").exists() or ignore.is_file()):
53
+ return False
54
+ old = ignore.read_bytes().decode("utf-8") if ignore.is_file() else ""
55
+ if IGNORE in old.splitlines():
56
+ return False
57
+ vault.write_text(ignore, old + ("" if old.endswith("\n") or not old else "\n")
58
+ + IGNORE + "\n")
59
+ return True
60
+
61
+
62
+ def pages(vault: Vault, undo: bool = False) -> list[str]:
63
+ """Ids of the pages `move` moves: the chat pages in resources/, or (`undo`) every page in
64
+ the archive."""
65
+ if undo:
66
+ d = vault.root / CHAT_ARCHIVE
67
+ return sorted(p.stem for p in d.glob("*.md") if ID_RE.fullmatch(p.stem)) \
68
+ if d.is_dir() else []
69
+ from keepfold.chat_import import _ledger, _pid # lazy: chat_import imports this module
70
+ from keepfold.events import EventLog
71
+
72
+ auto = {_pid(e) for e in _ledger(EventLog(vault).iter_events()).values() if e.get("auto")}
73
+ main = vault.root / MAIN
74
+ return sorted(n.id for n in vault.iter_notes("resource") if n.path.parent == main
75
+ and (n.id in auto or topics.page_source(n.body)))
76
+
77
+
78
+ def move(vault: Vault, *, undo: bool = False, dry_run: bool = False) -> dict:
79
+ """Move the chat pages (module doc). {"ids": moved (or, dry, to move), "kept": ids left
80
+ where they are (the other folder holds a different page of that id, or the file is open
81
+ in another program), "git": a line saying what git did ('' for nothing)}.
82
+ VaultError("busy") while a chat import runs."""
83
+ from keepfold import chat_import
84
+
85
+ if dry_run:
86
+ return {"ids": pages(vault, undo), "kept": [], "git": ""}
87
+ src, dst = (CHAT_ARCHIVE, MAIN) if undo else (MAIN, CHAT_ARCHIVE)
88
+ with vault.job_lock(chat_import.LOCK, 5, chat_import.BUSY): # no import writes meanwhile
89
+ if not undo:
90
+ ensure_ignored(vault) # before the first page lands in the archive
91
+ moved, kept = [], []
92
+ for i in pages(vault, undo):
93
+ try:
94
+ vault.move(vault.root / src / f"{i}.md", vault.root / dst / f"{i}.md")
95
+ moved.append(i)
96
+ except VaultError:
97
+ kept.append(i)
98
+ git = _git(vault, moved, undo)
99
+ if undo:
100
+ vault.remove(vault.root / MARKER)
101
+ else: # when, and how many moved (R3-10: the app's Status line reads it)
102
+ vault.write_text(vault.root / MARKER,
103
+ f"{datetime.now(UTC).isoformat(timespec='seconds')} {len(moved)}\n")
104
+ _set(not undo)
105
+ return {"ids": moved, "kept": kept, "git": git}
106
+
107
+
108
+ def auto(vault: Vault) -> dict | None:
109
+ """The app's one-time move: None when it ran before (MARKER), or `--undo` turned it off."""
110
+ if (vault.root / MARKER).exists() or not enabled():
111
+ return None
112
+ return move(vault)
113
+
114
+
115
+ UNDO_HOW = "keepfold chats archive --undo"
116
+
117
+
118
+ def last_move(vault: Vault) -> dict | None:
119
+ """R3-10: the archive move's record from MARKER: {day, count, folder, undo}, or None when it
120
+ never ran, was undone, or moved nothing. A marker from before R3-10 holds only its time: the
121
+ count is then the pages in the archive now."""
122
+ try:
123
+ parts = (vault.root / MARKER).read_text(encoding="utf-8").split()
124
+ except OSError:
125
+ return None
126
+ if not parts:
127
+ return None
128
+ try:
129
+ n = int(parts[1])
130
+ except (IndexError, ValueError):
131
+ d = vault.root / CHAT_ARCHIVE
132
+ n = sum(1 for _ in d.glob("*.md")) if d.is_dir() else 0
133
+ return {"day": parts[0][:10], "count": n, "folder": IGNORE, "undo": UNDO_HOW} if n else None
134
+
135
+
136
+ def _git(vault: Vault, ids: list[str], undo: bool) -> str:
137
+ """Archive: `git rm --cached` of the moved pages' tracked old paths, committed alone (what
138
+ else is staged stays staged). Undo: the pages committed back. Only when the vault is a git
139
+ repo and git is on in settings."""
140
+ from keepfold import session
141
+
142
+ root = vault.root
143
+ if not ids or not (root / ".git").exists():
144
+ return ""
145
+ if not session.git_choice()[0]:
146
+ return "git is off in your settings: the vault's repo was left alone."
147
+ if busy := session.git_busy(root):
148
+ return f"git was left alone ({busy}); finish that in git, then commit the change."
149
+ if undo:
150
+ sha = session._commit(vault, UNDO_MESSAGE, [root / MAIN / f"{i}.md" for i in ids])
151
+ return f"git: committed them back into the vault's repo ({sha[:7]})." if sha else ""
152
+ with vault.lock():
153
+ tracked = set(session._gitz(root, "ls-files", "-z", "--", MAIN).stdout.split("\0"))
154
+ rels = [r for i in ids if (r := f"{MAIN}/{i}.md") in tracked]
155
+ if not rels:
156
+ return "git: none of them was tracked in the vault's repo."
157
+ spec = "\0".join(rels)
158
+ for args in (("rm", "--cached", "-q", "--ignore-unmatch"), ("commit", "-q", "-m", MESSAGE)):
159
+ r = session._gitz(root, *args, "--pathspec-from-file=-", "--pathspec-file-nul",
160
+ input=spec)
161
+ if r.returncode:
162
+ return f"git {args[0]} failed: {r.stderr.strip()[:200]}"
163
+ n = len(rels)
164
+ return (f"git: ran `git rm --cached` on {n} page{'s' * (n != 1)} in the vault's repo and "
165
+ f"committed it; older commits still hold them (history is never rewritten).")