flowstatemcp 2.5.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 (143) hide show
  1. flowstate/__init__.py +34 -0
  2. flowstate/__main__.py +7 -0
  3. flowstate/activity.py +224 -0
  4. flowstate/agent_guide.py +251 -0
  5. flowstate/app_keys.py +141 -0
  6. flowstate/approvals.py +974 -0
  7. flowstate/approve_page.py +565 -0
  8. flowstate/ask.py +107 -0
  9. flowstate/autosession.py +480 -0
  10. flowstate/backup.py +201 -0
  11. flowstate/brief.py +420 -0
  12. flowstate/card_offer.py +208 -0
  13. flowstate/card_taps.py +165 -0
  14. flowstate/card_trust.py +127 -0
  15. flowstate/claims.py +461 -0
  16. flowstate/cleanup.py +619 -0
  17. flowstate/cli.py +728 -0
  18. flowstate/cli_data.py +434 -0
  19. flowstate/cli_more.py +302 -0
  20. flowstate/cli_review.py +459 -0
  21. flowstate/cloudflared_check.py +49 -0
  22. flowstate/conflict_card_ui.py +286 -0
  23. flowstate/conflict_cards.py +1193 -0
  24. flowstate/conflict_reopen.py +320 -0
  25. flowstate/conflicts.py +420 -0
  26. flowstate/connections.py +33 -0
  27. flowstate/database.py +2191 -0
  28. flowstate/dbconn.py +308 -0
  29. flowstate/deletes.py +860 -0
  30. flowstate/embeddings.py +354 -0
  31. flowstate/erase.py +1047 -0
  32. flowstate/extras.py +71 -0
  33. flowstate/git_capture.py +157 -0
  34. flowstate/guard.py +224 -0
  35. flowstate/handoffs.py +168 -0
  36. flowstate/history.py +755 -0
  37. flowstate/history_page.py +276 -0
  38. flowstate/http_app.py +204 -0
  39. flowstate/identity.py +387 -0
  40. flowstate/install_name.py +140 -0
  41. flowstate/ledger.py +272 -0
  42. flowstate/legacy_args.py +65 -0
  43. flowstate/links.py +609 -0
  44. flowstate/markdown_io.py +242 -0
  45. flowstate/meaning.py +398 -0
  46. flowstate/memory_import.py +92 -0
  47. flowstate/migrations/001_auto_sessions.sql +16 -0
  48. flowstate/migrations/002_review_queue.sql +33 -0
  49. flowstate/migrations/003_links.sql +47 -0
  50. flowstate/migrations/004_review_mode.sql +24 -0
  51. flowstate/migrations/005_history.sql +21 -0
  52. flowstate/migrations/006_activity.sql +26 -0
  53. flowstate/migrations/007_meaning_index.sql +16 -0
  54. flowstate/migrations/008_git_capture.sql +12 -0
  55. flowstate/migrations/009_hard_rules.sql +13 -0
  56. flowstate/migrations/010_handoffs.sql +14 -0
  57. flowstate/migrations/011_record_meta.sql +13 -0
  58. flowstate/migrations/012_accountability.sql +71 -0
  59. flowstate/migrations/013_todo_claims.sql +36 -0
  60. flowstate/migrations/014_decision_conflicts.sql +41 -0
  61. flowstate/migrations/015_session_runs.sql +17 -0
  62. flowstate/migrations/016_write_receipts.sql +35 -0
  63. flowstate/migrations/017_run_views.sql +26 -0
  64. flowstate/migrations/018_run_views_upto.sql +4 -0
  65. flowstate/migrations/019_approvals.sql +47 -0
  66. flowstate/migrations/020_source_stamps.sql +10 -0
  67. flowstate/migrations/021_review_links.sql +11 -0
  68. flowstate/migrations/022_review_start_tickets.sql +10 -0
  69. flowstate/migrations/023_conflict_cards.sql +68 -0
  70. flowstate/migrations/024_rule_confirmations.sql +7 -0
  71. flowstate/migrations/025_confirmed_hash.sql +7 -0
  72. flowstate/migrations/__init__.py +149 -0
  73. flowstate/models.py +307 -0
  74. flowstate/names.py +157 -0
  75. flowstate/offsite.py +386 -0
  76. flowstate/offsite_crypto.py +272 -0
  77. flowstate/paths.py +265 -0
  78. flowstate/popup.py +238 -0
  79. flowstate/priority.py +66 -0
  80. flowstate/privatefs.py +476 -0
  81. flowstate/project_history.py +710 -0
  82. flowstate/provenance.py +696 -0
  83. flowstate/receipts.py +377 -0
  84. flowstate/relay/__init__.py +72 -0
  85. flowstate/relay/acme.py +271 -0
  86. flowstate/relay/api.py +164 -0
  87. flowstate/relay/cli.py +344 -0
  88. flowstate/relay/crypto.py +137 -0
  89. flowstate/relay/ct.py +118 -0
  90. flowstate/relay/runner.py +177 -0
  91. flowstate/relay/store.py +191 -0
  92. flowstate/relay/tunnel.py +413 -0
  93. flowstate/release_signers +14 -0
  94. flowstate/remote_auth.py +1219 -0
  95. flowstate/review.py +320 -0
  96. flowstate/review_apply.py +140 -0
  97. flowstate/review_card_ui.py +241 -0
  98. flowstate/review_cards.py +564 -0
  99. flowstate/review_mode.py +274 -0
  100. flowstate/review_page.py +1361 -0
  101. flowstate/review_phone.py +465 -0
  102. flowstate/review_tunnel.py +338 -0
  103. flowstate/routing.py +392 -0
  104. flowstate/rules.py +418 -0
  105. flowstate/safety.py +98 -0
  106. flowstate/saves.py +83 -0
  107. flowstate/scheduler.py +160 -0
  108. flowstate/schema.sql +713 -0
  109. flowstate/search.py +355 -0
  110. flowstate/secret_store.py +271 -0
  111. flowstate/secrets_scan.py +135 -0
  112. flowstate/selfupdate.py +1020 -0
  113. flowstate/server.py +1299 -0
  114. flowstate/session_contents.py +382 -0
  115. flowstate/session_records.py +629 -0
  116. flowstate/site_style.py +46 -0
  117. flowstate/stored.py +158 -0
  118. flowstate/story.py +442 -0
  119. flowstate/surface.py +173 -0
  120. flowstate/tasks.py +231 -0
  121. flowstate/term.py +40 -0
  122. flowstate/tool_labels.py +104 -0
  123. flowstate/tooldefs.py +383 -0
  124. flowstate/tools/__init__.py +118 -0
  125. flowstate/tools/core.py +545 -0
  126. flowstate/tools/files.py +416 -0
  127. flowstate/tools/git_ops.py +1081 -0
  128. flowstate/tools/intelligence.py +376 -0
  129. flowstate/tools/learning.py +282 -0
  130. flowstate/tools/problems.py +159 -0
  131. flowstate/tools/sessions.py +266 -0
  132. flowstate/tools/story.py +48 -0
  133. flowstate/tools/todos.py +79 -0
  134. flowstate/tools/utils.py +71 -0
  135. flowstate/tools/variables.py +345 -0
  136. flowstate/updates.py +482 -0
  137. flowstate/urls.py +7 -0
  138. flowstate/waiting.py +828 -0
  139. flowstate/who.py +302 -0
  140. flowstatemcp-2.5.0.dist-info/METADATA +88 -0
  141. flowstatemcp-2.5.0.dist-info/RECORD +143 -0
  142. flowstatemcp-2.5.0.dist-info/WHEEL +4 -0
  143. flowstatemcp-2.5.0.dist-info/entry_points.txt +3 -0
flowstate/scheduler.py ADDED
@@ -0,0 +1,160 @@
1
+ """`flowstate schedule-backups`: run `flowstate backup` every night.
2
+
3
+ Windows: Task Scheduler (schtasks) running a small .cmd wrapper. macOS: a launchd agent
4
+ in ~/Library/LaunchAgents. Linux: a systemd user timer, or a crontab line when systemd
5
+ isn't available. `--remove` undoes exactly what was added. Commands go through `run`,
6
+ so tests use a fake runner and a fake home folder.
7
+ """
8
+
9
+ import platform
10
+ import shlex
11
+ import shutil
12
+ import subprocess
13
+ from pathlib import Path
14
+ from typing import Callable, Optional
15
+
16
+ from . import paths
17
+
18
+ TASK_NAME = "FlowState Nightly Backup"
19
+ LAUNCHD_LABEL = "com.flowstate.backup"
20
+ UNIT = "flowstate-backup"
21
+ CRON_MARK = "# flowstate-backup"
22
+ SERVER_DIR = Path(__file__).resolve().parents[1]
23
+
24
+
25
+ def _hhmm(at: str) -> tuple[int, int]:
26
+ try:
27
+ h, m = (int(x) for x in at.split(":"))
28
+ except ValueError:
29
+ raise ValueError(f"--time must be HH:MM, not {at!r}") from None
30
+ if not (0 <= h < 24 and 0 <= m < 60):
31
+ raise ValueError(f"--time must be HH:MM, not {at!r}")
32
+ return h, m
33
+
34
+
35
+ def backup_args(python: str, db: str, offsite: bool, backup_dir: Optional[str]) -> list[str]:
36
+ args = [python, "-m", "flowstate", "backup", "--db", db]
37
+ if backup_dir:
38
+ args += ["--dir", backup_dir]
39
+ if offsite:
40
+ args.append("--offsite")
41
+ return args
42
+
43
+
44
+ def schedule(python: str, db: str, at: str = "02:30", offsite: bool = False,
45
+ remove: bool = False, dry_run: bool = False, backup_dir: Optional[str] = None,
46
+ system: Optional[str] = None, home: Optional[Path] = None,
47
+ run: Callable = subprocess.run, which: Callable = shutil.which) -> dict:
48
+ system = system or platform.system()
49
+ h, m = _hhmm(at)
50
+ log_dir = Path(backup_dir) if backup_dir else paths.backup_dir(home, system)
51
+ log = log_dir / "backup.log"
52
+ args = backup_args(python, db, offsite, backup_dir)
53
+ env = {"FLOWSTATE_DB": db, "PYTHONPATH": str(SERVER_DIR)}
54
+ files: dict[Path, Optional[str]] = {} # path -> content (None = delete)
55
+ cmds: list[tuple[list, Optional[str]]] = [] # (argv, stdin)
56
+
57
+ if system == "Windows":
58
+ wrapper = paths.config_dir(home, system) / "flowstate-backup.cmd"
59
+ if remove:
60
+ cmds.append((["schtasks", "/Delete", "/TN", TASK_NAME, "/F"], None))
61
+ files[wrapper] = None
62
+ else:
63
+ line = " ".join(f'"{a}"' for a in args)
64
+ files[wrapper] = ("@echo off\r\n"
65
+ + "".join(f'set "{k}={v}"\r\n' for k, v in env.items())
66
+ + f'if not exist "{log_dir}" mkdir "{log_dir}"\r\n'
67
+ + f'{line} >> "{log}" 2>&1\r\n')
68
+ cmds.append((["schtasks", "/Create", "/TN", TASK_NAME, "/TR", f'"{wrapper}"',
69
+ "/SC", "DAILY", "/ST", f"{h:02d}:{m:02d}", "/F"], None))
70
+ how = "Windows Task Scheduler"
71
+ elif system == "Darwin":
72
+ home_ = Path(home) if home else Path.home()
73
+ plist = home_ / "Library" / "LaunchAgents" / f"{LAUNCHD_LABEL}.plist"
74
+ cmds.append((["launchctl", "unload", "-w", str(plist)], None))
75
+ if remove:
76
+ files[plist] = None
77
+ else:
78
+ files[plist] = _plist(args, env, h, m, log)
79
+ cmds.append((["launchctl", "load", "-w", str(plist)], None))
80
+ how = "launchd (LaunchAgents)"
81
+ else:
82
+ home_ = Path(home) if home else Path.home()
83
+ if which("systemctl"):
84
+ unit_dir = home_ / ".config" / "systemd" / "user"
85
+ svc, tmr = unit_dir / f"{UNIT}.service", unit_dir / f"{UNIT}.timer"
86
+ if remove:
87
+ cmds.append((["systemctl", "--user", "disable", "--now", f"{UNIT}.timer"], None))
88
+ files[svc] = files[tmr] = None
89
+ cmds.append((["systemctl", "--user", "daemon-reload"], None))
90
+ else:
91
+ files[svc] = ("[Unit]\nDescription=FlowState nightly backup\n\n[Service]\n"
92
+ "Type=oneshot\n"
93
+ + "".join(f'Environment="{k}={v}"\n' for k, v in env.items())
94
+ + "ExecStart=" + " ".join(shlex.quote(a) for a in args) + "\n")
95
+ files[tmr] = ("[Unit]\nDescription=FlowState nightly backup\n\n[Timer]\n"
96
+ f"OnCalendar=*-*-* {h:02d}:{m:02d}:00\nPersistent=true\n\n"
97
+ "[Install]\nWantedBy=timers.target\n")
98
+ cmds.append((["systemctl", "--user", "daemon-reload"], None))
99
+ cmds.append((["systemctl", "--user", "enable", "--now", f"{UNIT}.timer"], None))
100
+ how = "systemd user timer"
101
+ else:
102
+ current = ""
103
+ if not dry_run:
104
+ r = run(["crontab", "-l"], capture_output=True, text=True)
105
+ current = r.stdout if r.returncode == 0 else ""
106
+ kept = [l for l in current.splitlines() if CRON_MARK not in l]
107
+ if not remove:
108
+ envs = " ".join(f"{k}={shlex.quote(v)}" for k, v in env.items())
109
+ kept.append(f"{m} {h} * * * {envs} " + " ".join(shlex.quote(a) for a in args)
110
+ + f" >> {shlex.quote(str(log))} 2>&1 {CRON_MARK}")
111
+ cmds.append((["crontab", "-"], "\n".join(kept) + ("\n" if kept else "")))
112
+ how = "crontab"
113
+
114
+ plan = {"scheduler": how, "time": f"{h:02d}:{m:02d}", "removed": remove,
115
+ "command": " ".join(args), "files": [str(p) for p in files],
116
+ "commands": [" ".join(c) for c, _i in cmds], "dry_run": dry_run}
117
+ if dry_run:
118
+ return plan
119
+ for p, content in files.items():
120
+ if content is None:
121
+ p.unlink(missing_ok=True)
122
+ for p, content in files.items():
123
+ if content is not None:
124
+ p.parent.mkdir(parents=True, exist_ok=True)
125
+ p.write_text(content, encoding="utf-8", newline="")
126
+ if not remove:
127
+ log_dir.mkdir(parents=True, exist_ok=True)
128
+ errors = []
129
+ for argv, stdin in cmds:
130
+ r = run(argv, input=stdin, capture_output=True, text=True)
131
+ tolerated = argv[:2] == ["launchctl", "unload"] or (remove and r.returncode != 0)
132
+ if r.returncode != 0 and not tolerated:
133
+ errors.append(f"{argv[0]} failed: {(r.stderr or r.stdout or '').strip()[:200]}")
134
+ plan["errors"] = errors
135
+ return plan
136
+
137
+
138
+ def _plist(args: list, env: dict, h: int, m: int, log: Path) -> str:
139
+ from xml.sax.saxutils import escape
140
+ arr = "".join(f"\n <string>{escape(a)}</string>" for a in args)
141
+ envs = "".join(f"\n <key>{escape(k)}</key><string>{escape(v)}</string>"
142
+ for k, v in env.items())
143
+ return f"""<?xml version="1.0" encoding="UTF-8"?>
144
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
145
+ <plist version="1.0">
146
+ <dict>
147
+ <key>Label</key><string>{LAUNCHD_LABEL}</string>
148
+ <key>ProgramArguments</key>
149
+ <array>{arr}
150
+ </array>
151
+ <key>EnvironmentVariables</key>
152
+ <dict>{envs}
153
+ </dict>
154
+ <key>StartCalendarInterval</key>
155
+ <dict><key>Hour</key><integer>{h}</integer><key>Minute</key><integer>{m}</integer></dict>
156
+ <key>StandardOutPath</key><string>{escape(str(log))}</string>
157
+ <key>StandardErrorPath</key><string>{escape(str(log))}</string>
158
+ </dict>
159
+ </plist>
160
+ """