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.
- flowstate/__init__.py +34 -0
- flowstate/__main__.py +7 -0
- flowstate/activity.py +224 -0
- flowstate/agent_guide.py +251 -0
- flowstate/app_keys.py +141 -0
- flowstate/approvals.py +974 -0
- flowstate/approve_page.py +565 -0
- flowstate/ask.py +107 -0
- flowstate/autosession.py +480 -0
- flowstate/backup.py +201 -0
- flowstate/brief.py +420 -0
- flowstate/card_offer.py +208 -0
- flowstate/card_taps.py +165 -0
- flowstate/card_trust.py +127 -0
- flowstate/claims.py +461 -0
- flowstate/cleanup.py +619 -0
- flowstate/cli.py +728 -0
- flowstate/cli_data.py +434 -0
- flowstate/cli_more.py +302 -0
- flowstate/cli_review.py +459 -0
- flowstate/cloudflared_check.py +49 -0
- flowstate/conflict_card_ui.py +286 -0
- flowstate/conflict_cards.py +1193 -0
- flowstate/conflict_reopen.py +320 -0
- flowstate/conflicts.py +420 -0
- flowstate/connections.py +33 -0
- flowstate/database.py +2191 -0
- flowstate/dbconn.py +308 -0
- flowstate/deletes.py +860 -0
- flowstate/embeddings.py +354 -0
- flowstate/erase.py +1047 -0
- flowstate/extras.py +71 -0
- flowstate/git_capture.py +157 -0
- flowstate/guard.py +224 -0
- flowstate/handoffs.py +168 -0
- flowstate/history.py +755 -0
- flowstate/history_page.py +276 -0
- flowstate/http_app.py +204 -0
- flowstate/identity.py +387 -0
- flowstate/install_name.py +140 -0
- flowstate/ledger.py +272 -0
- flowstate/legacy_args.py +65 -0
- flowstate/links.py +609 -0
- flowstate/markdown_io.py +242 -0
- flowstate/meaning.py +398 -0
- flowstate/memory_import.py +92 -0
- flowstate/migrations/001_auto_sessions.sql +16 -0
- flowstate/migrations/002_review_queue.sql +33 -0
- flowstate/migrations/003_links.sql +47 -0
- flowstate/migrations/004_review_mode.sql +24 -0
- flowstate/migrations/005_history.sql +21 -0
- flowstate/migrations/006_activity.sql +26 -0
- flowstate/migrations/007_meaning_index.sql +16 -0
- flowstate/migrations/008_git_capture.sql +12 -0
- flowstate/migrations/009_hard_rules.sql +13 -0
- flowstate/migrations/010_handoffs.sql +14 -0
- flowstate/migrations/011_record_meta.sql +13 -0
- flowstate/migrations/012_accountability.sql +71 -0
- flowstate/migrations/013_todo_claims.sql +36 -0
- flowstate/migrations/014_decision_conflicts.sql +41 -0
- flowstate/migrations/015_session_runs.sql +17 -0
- flowstate/migrations/016_write_receipts.sql +35 -0
- flowstate/migrations/017_run_views.sql +26 -0
- flowstate/migrations/018_run_views_upto.sql +4 -0
- flowstate/migrations/019_approvals.sql +47 -0
- flowstate/migrations/020_source_stamps.sql +10 -0
- flowstate/migrations/021_review_links.sql +11 -0
- flowstate/migrations/022_review_start_tickets.sql +10 -0
- flowstate/migrations/023_conflict_cards.sql +68 -0
- flowstate/migrations/024_rule_confirmations.sql +7 -0
- flowstate/migrations/025_confirmed_hash.sql +7 -0
- flowstate/migrations/__init__.py +149 -0
- flowstate/models.py +307 -0
- flowstate/names.py +157 -0
- flowstate/offsite.py +386 -0
- flowstate/offsite_crypto.py +272 -0
- flowstate/paths.py +265 -0
- flowstate/popup.py +238 -0
- flowstate/priority.py +66 -0
- flowstate/privatefs.py +476 -0
- flowstate/project_history.py +710 -0
- flowstate/provenance.py +696 -0
- flowstate/receipts.py +377 -0
- flowstate/relay/__init__.py +72 -0
- flowstate/relay/acme.py +271 -0
- flowstate/relay/api.py +164 -0
- flowstate/relay/cli.py +344 -0
- flowstate/relay/crypto.py +137 -0
- flowstate/relay/ct.py +118 -0
- flowstate/relay/runner.py +177 -0
- flowstate/relay/store.py +191 -0
- flowstate/relay/tunnel.py +413 -0
- flowstate/release_signers +14 -0
- flowstate/remote_auth.py +1219 -0
- flowstate/review.py +320 -0
- flowstate/review_apply.py +140 -0
- flowstate/review_card_ui.py +241 -0
- flowstate/review_cards.py +564 -0
- flowstate/review_mode.py +274 -0
- flowstate/review_page.py +1361 -0
- flowstate/review_phone.py +465 -0
- flowstate/review_tunnel.py +338 -0
- flowstate/routing.py +392 -0
- flowstate/rules.py +418 -0
- flowstate/safety.py +98 -0
- flowstate/saves.py +83 -0
- flowstate/scheduler.py +160 -0
- flowstate/schema.sql +713 -0
- flowstate/search.py +355 -0
- flowstate/secret_store.py +271 -0
- flowstate/secrets_scan.py +135 -0
- flowstate/selfupdate.py +1020 -0
- flowstate/server.py +1299 -0
- flowstate/session_contents.py +382 -0
- flowstate/session_records.py +629 -0
- flowstate/site_style.py +46 -0
- flowstate/stored.py +158 -0
- flowstate/story.py +442 -0
- flowstate/surface.py +173 -0
- flowstate/tasks.py +231 -0
- flowstate/term.py +40 -0
- flowstate/tool_labels.py +104 -0
- flowstate/tooldefs.py +383 -0
- flowstate/tools/__init__.py +118 -0
- flowstate/tools/core.py +545 -0
- flowstate/tools/files.py +416 -0
- flowstate/tools/git_ops.py +1081 -0
- flowstate/tools/intelligence.py +376 -0
- flowstate/tools/learning.py +282 -0
- flowstate/tools/problems.py +159 -0
- flowstate/tools/sessions.py +266 -0
- flowstate/tools/story.py +48 -0
- flowstate/tools/todos.py +79 -0
- flowstate/tools/utils.py +71 -0
- flowstate/tools/variables.py +345 -0
- flowstate/updates.py +482 -0
- flowstate/urls.py +7 -0
- flowstate/waiting.py +828 -0
- flowstate/who.py +302 -0
- flowstatemcp-2.5.0.dist-info/METADATA +88 -0
- flowstatemcp-2.5.0.dist-info/RECORD +143 -0
- flowstatemcp-2.5.0.dist-info/WHEEL +4 -0
- flowstatemcp-2.5.0.dist-info/entry_points.txt +3 -0
flowstate/review_mode.py
ADDED
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
"""Review mode (v2 Phase D, migration 004): which writes wait in the review queue.
|
|
2
|
+
|
|
3
|
+
off nothing waits: suggested=true saves directly, auto summaries are kept as is
|
|
4
|
+
auto_only only auto-captured session summaries and suggested=true items (default)
|
|
5
|
+
types also every new record of the chosen kinds (e.g. decision, todo)
|
|
6
|
+
everything every new record waits for the user's OK
|
|
7
|
+
|
|
8
|
+
Set per install, with an optional per-project override. Only the user changes it (an AI
|
|
9
|
+
must quote the user's request); every change is logged. With approvals on (approvals.py),
|
|
10
|
+
turning review off waits for the user's own click or key: queue_if_off queues it as a review
|
|
11
|
+
item of kind `setting`, and apply_queued makes the change once the user approves it.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import json
|
|
15
|
+
import sqlite3
|
|
16
|
+
from datetime import datetime, timezone
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
from typing import Optional
|
|
19
|
+
|
|
20
|
+
from . import dbconn
|
|
21
|
+
from . import identity
|
|
22
|
+
|
|
23
|
+
MODES = ("off", "auto_only", "types", "everything")
|
|
24
|
+
DEFAULT = "auto_only"
|
|
25
|
+
KINDS = ("decision", "change", "problem", "learning", "todo")
|
|
26
|
+
|
|
27
|
+
_TEXT = {
|
|
28
|
+
"off": "nothing waits for review",
|
|
29
|
+
"auto_only": "only auto-captured items wait for review",
|
|
30
|
+
"everything": "every new record waits for the user's OK",
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class ModeError(Exception):
|
|
35
|
+
def __init__(self, code: str, message: str):
|
|
36
|
+
super().__init__(message)
|
|
37
|
+
self.payload = {"error": code, "message": message}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _conn(db_path: Path) -> sqlite3.Connection:
|
|
41
|
+
conn = dbconn.connect(str(db_path), timeout=5.0)
|
|
42
|
+
conn.row_factory = sqlite3.Row
|
|
43
|
+
conn.execute("PRAGMA busy_timeout = 5000")
|
|
44
|
+
return conn
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def available(conn) -> bool:
|
|
48
|
+
return conn.execute("SELECT 1 FROM sqlite_master WHERE type='table' "
|
|
49
|
+
"AND name='review_settings'").fetchone() is not None
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _scope(project_id: Optional[int]) -> str:
|
|
53
|
+
return "install" if project_id is None else f"project:{int(project_id)}"
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _row(conn, scope: str) -> Optional[dict]:
|
|
57
|
+
r = conn.execute("SELECT * FROM review_settings WHERE scope = ?", (scope,)).fetchone()
|
|
58
|
+
if not r:
|
|
59
|
+
return None
|
|
60
|
+
d = dict(r)
|
|
61
|
+
try:
|
|
62
|
+
d["kinds"] = [k for k in json.loads(d["kinds"] or "[]") if k in KINDS]
|
|
63
|
+
except ValueError:
|
|
64
|
+
d["kinds"] = []
|
|
65
|
+
return d
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def get(db_path: Path, project_id: Optional[int] = None) -> dict:
|
|
69
|
+
"""Effective mode for a project (override, else install-wide, else the default)."""
|
|
70
|
+
conn = _conn(db_path)
|
|
71
|
+
try:
|
|
72
|
+
return get_with(conn, project_id)
|
|
73
|
+
finally:
|
|
74
|
+
conn.close()
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def get_with(conn, project_id: Optional[int] = None) -> dict:
|
|
78
|
+
if not available(conn):
|
|
79
|
+
return {"mode": DEFAULT, "kinds": [], "source": "default", "available": False}
|
|
80
|
+
if project_id is not None:
|
|
81
|
+
r = _row(conn, _scope(project_id))
|
|
82
|
+
if r:
|
|
83
|
+
return {"mode": r["mode"], "kinds": r["kinds"], "source": "project",
|
|
84
|
+
"updated_at": r["updated_at"], "updated_by": r["updated_by"]}
|
|
85
|
+
r = _row(conn, "install")
|
|
86
|
+
if r:
|
|
87
|
+
return {"mode": r["mode"], "kinds": r["kinds"], "source": "install",
|
|
88
|
+
"updated_at": r["updated_at"], "updated_by": r["updated_by"]}
|
|
89
|
+
return {"mode": DEFAULT, "kinds": [], "source": "default"}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def describe(m: dict) -> str:
|
|
93
|
+
if m["mode"] == "types":
|
|
94
|
+
return (f"{', '.join(m['kinds']) or 'no kinds'} and auto-captured items wait for review")
|
|
95
|
+
return _TEXT[m["mode"]]
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def brief_line(db_path: Path, project_id: int) -> str:
|
|
99
|
+
m = get(db_path, project_id)
|
|
100
|
+
where = " (this project)" if m.get("source") == "project" else ""
|
|
101
|
+
return (f"Review mode: {m['mode']}{where}, {describe(m)}. Only the user may change it.")
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def should_queue(db_path: Path, project_id: int, kind: str, suggested: bool = False,
|
|
105
|
+
auto: bool = False) -> bool:
|
|
106
|
+
"""Does a new record of this kind go to the review queue instead of being saved?"""
|
|
107
|
+
m = get(db_path, project_id)
|
|
108
|
+
mode = m["mode"]
|
|
109
|
+
if mode == "off":
|
|
110
|
+
return False
|
|
111
|
+
if suggested or auto:
|
|
112
|
+
return True
|
|
113
|
+
if mode == "everything":
|
|
114
|
+
return True
|
|
115
|
+
if mode == "types":
|
|
116
|
+
return kind in m["kinds"]
|
|
117
|
+
return False
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def queues_auto_summaries(db_path: Path, project_id: int) -> bool:
|
|
121
|
+
return get(db_path, project_id)["mode"] != "off"
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def set_mode(db_path: Path, mode: Optional[str], kinds=None, project_id: Optional[int] = None,
|
|
125
|
+
user_request: str = "", client: str = "unknown", caller: str = "stdio",
|
|
126
|
+
clear: bool = False) -> dict:
|
|
127
|
+
"""Change the mode (or clear a project override). Logged with the user's words."""
|
|
128
|
+
user_request = (user_request or "").strip()
|
|
129
|
+
if not user_request:
|
|
130
|
+
raise ModeError("user_request_required",
|
|
131
|
+
"Only the user can change the review mode. Ask them; pass their words "
|
|
132
|
+
"as user_request.")
|
|
133
|
+
if clear:
|
|
134
|
+
if project_id is None:
|
|
135
|
+
raise ModeError("bad_request", "clear removes a project override; name the project.")
|
|
136
|
+
else:
|
|
137
|
+
if mode not in MODES:
|
|
138
|
+
raise ModeError("bad_mode", f"mode must be one of: {', '.join(MODES)}.")
|
|
139
|
+
kinds = [k for k in (kinds or []) if k]
|
|
140
|
+
bad = [k for k in kinds if k not in KINDS]
|
|
141
|
+
if bad:
|
|
142
|
+
raise ModeError("bad_kinds", f"kinds must be from: {', '.join(KINDS)}.")
|
|
143
|
+
if mode == "types" and not kinds:
|
|
144
|
+
raise ModeError("kinds_required", "mode 'types' needs kinds, e.g. [\"decision\"].")
|
|
145
|
+
if mode != "types":
|
|
146
|
+
kinds = []
|
|
147
|
+
scope = _scope(project_id)
|
|
148
|
+
now = datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S")
|
|
149
|
+
conn = _conn(db_path)
|
|
150
|
+
try:
|
|
151
|
+
if not available(conn):
|
|
152
|
+
raise ModeError("review_mode_unavailable",
|
|
153
|
+
"Review mode isn't set up in this database yet (migration 004).")
|
|
154
|
+
conn.execute("BEGIN IMMEDIATE")
|
|
155
|
+
old = _row(conn, scope)
|
|
156
|
+
if clear:
|
|
157
|
+
conn.execute("DELETE FROM review_settings WHERE scope = ?", (scope,))
|
|
158
|
+
new_mode, new_kinds = None, None
|
|
159
|
+
else:
|
|
160
|
+
conn.execute(
|
|
161
|
+
"""INSERT INTO review_settings (scope, mode, kinds, updated_at, updated_by)
|
|
162
|
+
VALUES (?, ?, ?, ?, ?) ON CONFLICT(scope) DO UPDATE SET mode = excluded.mode,
|
|
163
|
+
kinds = excluded.kinds, updated_at = excluded.updated_at,
|
|
164
|
+
updated_by = excluded.updated_by""",
|
|
165
|
+
(scope, mode, json.dumps(kinds), now, client[:80]))
|
|
166
|
+
new_mode, new_kinds = mode, json.dumps(kinds)
|
|
167
|
+
log_id = identity.insert(conn, "review_mode_log", {
|
|
168
|
+
"scope": scope, "old_mode": old["mode"] if old else None,
|
|
169
|
+
"old_kinds": json.dumps(old["kinds"]) if old else None, "new_mode": new_mode,
|
|
170
|
+
"new_kinds": new_kinds, "client": client[:80], "caller": (caller or "")[:80],
|
|
171
|
+
"user_request": user_request[:500], "changed_at": now}, client).lastrowid
|
|
172
|
+
conn.commit()
|
|
173
|
+
except Exception:
|
|
174
|
+
conn.rollback()
|
|
175
|
+
raise
|
|
176
|
+
finally:
|
|
177
|
+
conn.close()
|
|
178
|
+
eff = get(db_path, project_id)
|
|
179
|
+
return {"scope": scope, "old": ({"mode": old["mode"], "kinds": old["kinds"]} if old else None),
|
|
180
|
+
"now": eff, "text": describe(eff), "logged": True, "log_id": log_id}
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
def history(db_path: Path, limit: int = 20) -> list[dict]:
|
|
184
|
+
conn = _conn(db_path)
|
|
185
|
+
try:
|
|
186
|
+
if not available(conn):
|
|
187
|
+
return []
|
|
188
|
+
return [dict(r) for r in conn.execute(
|
|
189
|
+
"SELECT * FROM review_mode_log ORDER BY id DESC LIMIT ?", (limit,))]
|
|
190
|
+
finally:
|
|
191
|
+
conn.close()
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def turns_off(db_path: Path, mode: Optional[str], project_id: Optional[int],
|
|
195
|
+
clear: bool = False) -> list:
|
|
196
|
+
"""Which scopes this change turns review off for (their effective mode goes from something
|
|
197
|
+
else to off): None for the install itself, plus each affected project id. Mode off for a
|
|
198
|
+
project; mode off install-wide (every project without its own setting follows it);
|
|
199
|
+
clearing a project's own setting while the install is off."""
|
|
200
|
+
conn = _conn(db_path)
|
|
201
|
+
try:
|
|
202
|
+
if not available(conn):
|
|
203
|
+
return []
|
|
204
|
+
install = get_with(conn, None)["mode"]
|
|
205
|
+
if clear:
|
|
206
|
+
if project_id is None or install != "off":
|
|
207
|
+
return []
|
|
208
|
+
return [int(project_id)] if get_with(conn, project_id)["mode"] != "off" else []
|
|
209
|
+
if mode != "off":
|
|
210
|
+
return []
|
|
211
|
+
if project_id is not None:
|
|
212
|
+
return [int(project_id)] if get_with(conn, project_id)["mode"] != "off" else []
|
|
213
|
+
if install == "off":
|
|
214
|
+
return []
|
|
215
|
+
own = {r[0] for r in conn.execute("SELECT scope FROM review_settings "
|
|
216
|
+
"WHERE scope LIKE 'project:%'")}
|
|
217
|
+
return [None] + [r[0] for r in conn.execute("SELECT id FROM projects ORDER BY id")
|
|
218
|
+
if f"project:{r[0]}" not in own]
|
|
219
|
+
finally:
|
|
220
|
+
conn.close()
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def off_needs_user(db_path: Path, mode: Optional[str], project_id: Optional[int],
|
|
224
|
+
clear: bool = False) -> bool:
|
|
225
|
+
"""Approvals on for any scope this change turns review off for (turns_off): then only the
|
|
226
|
+
user's own click or key may make it."""
|
|
227
|
+
from . import approvals
|
|
228
|
+
return any(approvals.is_on(db_path, pid) for pid in turns_off(db_path, mode, project_id, clear))
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
def queue_if_off(db_path: Path, mode: Optional[str], kinds, project_id: Optional[int],
|
|
232
|
+
user_request: str, client: str, clear: bool = False) -> Optional[int]:
|
|
233
|
+
"""Approvals on: a change that turns review off (mode off, or clearing a project's
|
|
234
|
+
override when the install is off) becomes a user-only review item. Returns its id, or
|
|
235
|
+
None when the change may go ahead as usual."""
|
|
236
|
+
if not (user_request or "").strip():
|
|
237
|
+
return None # set_mode refuses it as before
|
|
238
|
+
if clear:
|
|
239
|
+
if project_id is None or get(db_path, None)["mode"] != "off":
|
|
240
|
+
return None
|
|
241
|
+
elif mode != "off":
|
|
242
|
+
return None
|
|
243
|
+
if get(db_path, project_id)["mode"] == "off":
|
|
244
|
+
return None # already off: nothing to turn off
|
|
245
|
+
from . import review
|
|
246
|
+
pid = project_id
|
|
247
|
+
if pid is None: # an install-wide change is filed under the most recently updated project
|
|
248
|
+
conn = _conn(db_path)
|
|
249
|
+
try:
|
|
250
|
+
row = conn.execute("SELECT id FROM projects ORDER BY COALESCE(updated_at, created_at) "
|
|
251
|
+
"DESC, id DESC LIMIT 1").fetchone()
|
|
252
|
+
finally:
|
|
253
|
+
conn.close()
|
|
254
|
+
if row is None:
|
|
255
|
+
return None
|
|
256
|
+
pid = row[0]
|
|
257
|
+
where = "the whole install" if project_id is None else "this project"
|
|
258
|
+
return review.add_item(db_path, pid, "setting", f"Turn review off for {where}",
|
|
259
|
+
"Approve to turn review off (nothing waits for review then); reject to "
|
|
260
|
+
"keep it as it is.",
|
|
261
|
+
{"scope": _scope(project_id), "mode": None if clear else mode,
|
|
262
|
+
"kinds": [], "clear": bool(clear), "user_request": user_request[:500]},
|
|
263
|
+
client)
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
def apply_queued(db_path: Path, item: dict, client: str) -> tuple[str, int]:
|
|
267
|
+
"""Make a review-setting change the user approved (queue_if_off)."""
|
|
268
|
+
p = json.loads(item.get("payload") or "{}")
|
|
269
|
+
scope = p.get("scope") or "install"
|
|
270
|
+
pid = None if scope == "install" else int(scope.split(":", 1)[1])
|
|
271
|
+
out = set_mode(db_path, p.get("mode"), p.get("kinds"), pid,
|
|
272
|
+
p.get("user_request") or "approved by the user", client, "user approval",
|
|
273
|
+
clear=bool(p.get("clear")))
|
|
274
|
+
return "review_mode_log", out["log_id"]
|