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/tools/core.py
ADDED
|
@@ -0,0 +1,545 @@
|
|
|
1
|
+
"""Core project and component tools."""
|
|
2
|
+
|
|
3
|
+
from typing import Optional
|
|
4
|
+
from .utils import get_db, _compact_list
|
|
5
|
+
from .files import get_attachments
|
|
6
|
+
|
|
7
|
+
def list_projects(status: Optional[str] = None) -> list[dict]:
|
|
8
|
+
"""
|
|
9
|
+
List all projects with their status and stats.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
status: Optional filter ('active', 'paused', 'completed', 'archived')
|
|
13
|
+
|
|
14
|
+
Returns:
|
|
15
|
+
List of projects with basic info
|
|
16
|
+
"""
|
|
17
|
+
db = get_db()
|
|
18
|
+
projects = db.list_projects(status)
|
|
19
|
+
return [p.model_dump() for p in projects]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def create_project(name: str, description: Optional[str] = None) -> dict:
|
|
23
|
+
"""
|
|
24
|
+
Create a new project.
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
name: Project name (must be unique)
|
|
28
|
+
description: Optional description
|
|
29
|
+
|
|
30
|
+
Returns:
|
|
31
|
+
The created project
|
|
32
|
+
"""
|
|
33
|
+
db = get_db()
|
|
34
|
+
project = db.create_project(name, description)
|
|
35
|
+
return project.model_dump()
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def get_project(project_id: int) -> Optional[dict]:
|
|
39
|
+
"""
|
|
40
|
+
Get project details by ID.
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
project_id: The project ID
|
|
44
|
+
|
|
45
|
+
Returns:
|
|
46
|
+
Project details or None if not found
|
|
47
|
+
"""
|
|
48
|
+
db = get_db()
|
|
49
|
+
project = db.get_project(project_id)
|
|
50
|
+
return project.model_dump() if project else None
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def update_project(
|
|
54
|
+
project_id: int,
|
|
55
|
+
name: Optional[str] = None,
|
|
56
|
+
description: Optional[str] = None,
|
|
57
|
+
status: Optional[str] = None
|
|
58
|
+
) -> Optional[dict]:
|
|
59
|
+
"""
|
|
60
|
+
Update project fields.
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
project_id: The project ID
|
|
64
|
+
name: New name (optional)
|
|
65
|
+
description: New description (optional)
|
|
66
|
+
status: New status (optional)
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
Updated project or None if not found
|
|
70
|
+
"""
|
|
71
|
+
db = get_db()
|
|
72
|
+
project = db.update_project(project_id, name=name, description=description, status=status)
|
|
73
|
+
return project.model_dump() if project else None
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def get_project_context(project_name: str, hours: int = 48, include_files: bool = True) -> Optional[dict]:
|
|
77
|
+
"""
|
|
78
|
+
THE KILLER TOOL: Get everything needed to work on a project.
|
|
79
|
+
|
|
80
|
+
Returns:
|
|
81
|
+
- Project details
|
|
82
|
+
- All components
|
|
83
|
+
- Active problems (open, investigating)
|
|
84
|
+
- Recent changes (last 24-48 hours)
|
|
85
|
+
- High-priority todos
|
|
86
|
+
- Recent learnings
|
|
87
|
+
- Current session if any
|
|
88
|
+
- File attachments with content locations (v1.1)
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
project_name: Name of the project
|
|
92
|
+
hours: How many hours back to look for changes (default 48)
|
|
93
|
+
include_files: Include file attachments in context (default True)
|
|
94
|
+
|
|
95
|
+
Returns:
|
|
96
|
+
Full project context or None if project not found
|
|
97
|
+
"""
|
|
98
|
+
db = get_db()
|
|
99
|
+
ctx = db.get_project_context(project_name, hours)
|
|
100
|
+
if ctx is None:
|
|
101
|
+
return None
|
|
102
|
+
|
|
103
|
+
result = {
|
|
104
|
+
"project": ctx.project.model_dump(),
|
|
105
|
+
"components": [c.model_dump() for c in ctx.components],
|
|
106
|
+
"open_problems": [p.model_dump() for p in ctx.open_problems],
|
|
107
|
+
"recent_changes": [c.model_dump() for c in ctx.recent_changes],
|
|
108
|
+
"high_priority_todos": [t.model_dump() for t in ctx.high_priority_todos],
|
|
109
|
+
"recent_learnings": [l.model_dump() for l in ctx.recent_learnings],
|
|
110
|
+
"current_session": ctx.current_session.model_dump() if ctx.current_session else None
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
# Add file attachments if requested (v1.1)
|
|
114
|
+
if include_files:
|
|
115
|
+
attachments = get_attachments(project_id=ctx.project.id)
|
|
116
|
+
result["attachments"] = attachments
|
|
117
|
+
|
|
118
|
+
# Get content locations for attachments
|
|
119
|
+
conn = db._conn()
|
|
120
|
+
try:
|
|
121
|
+
for att in attachments:
|
|
122
|
+
locations = conn.execute(
|
|
123
|
+
"SELECT * FROM content_locations WHERE attachment_id = ?",
|
|
124
|
+
(att['id'],)
|
|
125
|
+
).fetchall()
|
|
126
|
+
att['content_locations'] = [dict(l) for l in locations]
|
|
127
|
+
finally:
|
|
128
|
+
conn.close()
|
|
129
|
+
|
|
130
|
+
return result
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def create_component(
|
|
134
|
+
project_id: int,
|
|
135
|
+
name: str,
|
|
136
|
+
description: Optional[str] = None,
|
|
137
|
+
parent_component_id: Optional[int] = None
|
|
138
|
+
) -> dict:
|
|
139
|
+
"""
|
|
140
|
+
Create a new component in a project.
|
|
141
|
+
|
|
142
|
+
Args:
|
|
143
|
+
project_id: The project ID
|
|
144
|
+
name: Component name
|
|
145
|
+
description: Optional description
|
|
146
|
+
parent_component_id: Optional parent for nesting
|
|
147
|
+
|
|
148
|
+
Returns:
|
|
149
|
+
The created component
|
|
150
|
+
"""
|
|
151
|
+
db = get_db()
|
|
152
|
+
component = db.create_component(project_id, name, description, parent_component_id)
|
|
153
|
+
return component.model_dump()
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def list_components(project_id: int) -> list[dict]:
|
|
157
|
+
"""
|
|
158
|
+
List all components in a project.
|
|
159
|
+
|
|
160
|
+
Args:
|
|
161
|
+
project_id: The project ID
|
|
162
|
+
|
|
163
|
+
Returns:
|
|
164
|
+
List of components
|
|
165
|
+
"""
|
|
166
|
+
db = get_db()
|
|
167
|
+
components = db.list_components(project_id)
|
|
168
|
+
return [c.model_dump() for c in components]
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def update_component(
|
|
172
|
+
component_id: int,
|
|
173
|
+
name: Optional[str] = None,
|
|
174
|
+
description: Optional[str] = None,
|
|
175
|
+
status: Optional[str] = None
|
|
176
|
+
) -> Optional[dict]:
|
|
177
|
+
"""
|
|
178
|
+
Update component fields.
|
|
179
|
+
|
|
180
|
+
Args:
|
|
181
|
+
component_id: The component ID
|
|
182
|
+
name: New name (optional)
|
|
183
|
+
description: New description (optional)
|
|
184
|
+
status: New status (optional)
|
|
185
|
+
|
|
186
|
+
Returns:
|
|
187
|
+
Updated component or None
|
|
188
|
+
"""
|
|
189
|
+
db = get_db()
|
|
190
|
+
component = db.update_component(component_id, name=name, description=description, status=status)
|
|
191
|
+
return component.model_dump() if component else None
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def log_change(
|
|
195
|
+
component_id: int,
|
|
196
|
+
field_name: str,
|
|
197
|
+
old_value: Optional[str] = None,
|
|
198
|
+
new_value: Optional[str] = None,
|
|
199
|
+
change_type: str = "code",
|
|
200
|
+
reason: Optional[str] = None
|
|
201
|
+
) -> dict:
|
|
202
|
+
"""
|
|
203
|
+
Log a change to a component.
|
|
204
|
+
|
|
205
|
+
Args:
|
|
206
|
+
component_id: The component that changed
|
|
207
|
+
field_name: What field/aspect changed
|
|
208
|
+
old_value: Previous value
|
|
209
|
+
new_value: New value
|
|
210
|
+
change_type: Type of change ('config', 'code', 'architecture', 'dependency', 'documentation', 'other')
|
|
211
|
+
reason: Why the change was made
|
|
212
|
+
|
|
213
|
+
Returns:
|
|
214
|
+
The logged change
|
|
215
|
+
"""
|
|
216
|
+
db = get_db()
|
|
217
|
+
change = db.log_change(component_id, field_name, old_value, new_value, change_type, reason)
|
|
218
|
+
|
|
219
|
+
# Index for search
|
|
220
|
+
search_text = f"{field_name} {old_value or ''} {new_value or ''} {reason or ''}"
|
|
221
|
+
component = db.get_component(component_id)
|
|
222
|
+
if component:
|
|
223
|
+
db.index_for_search("change", change.id, component.project_id, search_text)
|
|
224
|
+
|
|
225
|
+
return change.model_dump()
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def get_recent_changes(
|
|
229
|
+
project_id: Optional[int] = None,
|
|
230
|
+
component_id: Optional[int] = None,
|
|
231
|
+
hours: int = 24,
|
|
232
|
+
compact: bool = False
|
|
233
|
+
) -> list[dict]:
|
|
234
|
+
"""
|
|
235
|
+
Get recent changes.
|
|
236
|
+
|
|
237
|
+
Args:
|
|
238
|
+
project_id: Filter by project (optional)
|
|
239
|
+
component_id: Filter by component (optional)
|
|
240
|
+
hours: How far back to look (default 24)
|
|
241
|
+
compact: Return minimal fields to save tokens (default False)
|
|
242
|
+
|
|
243
|
+
Returns:
|
|
244
|
+
List of recent changes
|
|
245
|
+
"""
|
|
246
|
+
db = get_db()
|
|
247
|
+
changes = db.get_recent_changes(project_id, component_id, hours)
|
|
248
|
+
result = [c.model_dump() for c in changes]
|
|
249
|
+
return _compact_list(result) if compact else result
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def search(
|
|
253
|
+
query: str,
|
|
254
|
+
project_id: Optional[int] = None,
|
|
255
|
+
content_types: Optional[list[str]] = None,
|
|
256
|
+
limit: int = 10
|
|
257
|
+
) -> list[dict]:
|
|
258
|
+
"""
|
|
259
|
+
Search across all content.
|
|
260
|
+
|
|
261
|
+
Args:
|
|
262
|
+
query: Search query
|
|
263
|
+
project_id: Optional project filter
|
|
264
|
+
content_types: Optional list of types to search ('problem', 'solution', 'learning', 'change')
|
|
265
|
+
limit: Max results (default 10)
|
|
266
|
+
|
|
267
|
+
Returns:
|
|
268
|
+
List of search results with snippets
|
|
269
|
+
"""
|
|
270
|
+
db = get_db()
|
|
271
|
+
return db.search(query, project_id, content_types, limit)
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def get_component_history(
|
|
275
|
+
component_id: int,
|
|
276
|
+
days: int = 30
|
|
277
|
+
) -> dict:
|
|
278
|
+
"""
|
|
279
|
+
Get full history for a component over time.
|
|
280
|
+
|
|
281
|
+
Args:
|
|
282
|
+
component_id: The component ID
|
|
283
|
+
days: How many days back to look (default 30)
|
|
284
|
+
|
|
285
|
+
Returns:
|
|
286
|
+
Component with all changes, problems, solutions, learnings
|
|
287
|
+
"""
|
|
288
|
+
db = get_db()
|
|
289
|
+
return db.get_component_history(component_id, days)
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
def link_items(
|
|
293
|
+
source_type: str,
|
|
294
|
+
source_id: int,
|
|
295
|
+
target_type: str,
|
|
296
|
+
target_id: int,
|
|
297
|
+
relationship: str,
|
|
298
|
+
source_project_id: Optional[int] = None,
|
|
299
|
+
target_project_id: Optional[int] = None,
|
|
300
|
+
notes: Optional[str] = None
|
|
301
|
+
) -> dict:
|
|
302
|
+
"""
|
|
303
|
+
Create a cross-reference between items.
|
|
304
|
+
|
|
305
|
+
Args:
|
|
306
|
+
source_type: Type of source item ('problem', 'solution', 'learning', 'component', 'change')
|
|
307
|
+
source_id: ID of source item
|
|
308
|
+
target_type: Type of target item
|
|
309
|
+
target_id: ID of target item
|
|
310
|
+
relationship: How they're related ('similar_to', 'derived_from', 'contradicts', 'depends_on', 'supersedes', 'related_to')
|
|
311
|
+
source_project_id: Project ID of source (auto-detected if not provided)
|
|
312
|
+
target_project_id: Project ID of target (auto-detected if not provided)
|
|
313
|
+
notes: Optional notes about the relationship
|
|
314
|
+
|
|
315
|
+
Returns:
|
|
316
|
+
The created cross-reference
|
|
317
|
+
"""
|
|
318
|
+
db = get_db()
|
|
319
|
+
|
|
320
|
+
# Auto-detect project IDs if not provided
|
|
321
|
+
if source_project_id is None:
|
|
322
|
+
source_project_id = _get_project_id_for_item(db, source_type, source_id)
|
|
323
|
+
if target_project_id is None:
|
|
324
|
+
target_project_id = _get_project_id_for_item(db, target_type, target_id)
|
|
325
|
+
|
|
326
|
+
return db.link_items(
|
|
327
|
+
source_project_id, source_type, source_id,
|
|
328
|
+
target_project_id, target_type, target_id,
|
|
329
|
+
relationship, notes
|
|
330
|
+
)
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
def _get_project_id_for_item(db, item_type: str, item_id: int) -> int:
|
|
334
|
+
"""Helper to get project_id for any item type."""
|
|
335
|
+
if item_type == 'component':
|
|
336
|
+
comp = db.get_component(item_id)
|
|
337
|
+
return comp.project_id if comp else 0
|
|
338
|
+
elif item_type == 'problem':
|
|
339
|
+
prob = db.get_problem(item_id)
|
|
340
|
+
if prob:
|
|
341
|
+
comp = db.get_component(prob.component_id)
|
|
342
|
+
return comp.project_id if comp else 0
|
|
343
|
+
elif item_type == 'solution':
|
|
344
|
+
sol = db.get_solution(item_id)
|
|
345
|
+
if sol:
|
|
346
|
+
prob = db.get_problem(sol.problem_id)
|
|
347
|
+
if prob:
|
|
348
|
+
comp = db.get_component(prob.component_id)
|
|
349
|
+
return comp.project_id if comp else 0
|
|
350
|
+
elif item_type == 'learning':
|
|
351
|
+
learnings = db.get_learnings()
|
|
352
|
+
for l in learnings:
|
|
353
|
+
if l.id == item_id:
|
|
354
|
+
return l.project_id
|
|
355
|
+
elif item_type == 'change':
|
|
356
|
+
# Need to trace through component
|
|
357
|
+
pass
|
|
358
|
+
return 0
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
def find_related(
|
|
362
|
+
item_type: str,
|
|
363
|
+
item_id: int
|
|
364
|
+
) -> list[dict]:
|
|
365
|
+
"""
|
|
366
|
+
Find all items related to this one.
|
|
367
|
+
|
|
368
|
+
Args:
|
|
369
|
+
item_type: Type of item ('problem', 'solution', 'learning', 'component', 'change')
|
|
370
|
+
item_id: ID of the item
|
|
371
|
+
|
|
372
|
+
Returns:
|
|
373
|
+
List of cross-references (both incoming and outgoing)
|
|
374
|
+
"""
|
|
375
|
+
db = get_db()
|
|
376
|
+
return db.find_related(item_type, item_id)
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
def get_cross_references(
|
|
380
|
+
project_id: Optional[int] = None,
|
|
381
|
+
source_type: Optional[str] = None,
|
|
382
|
+
source_id: Optional[int] = None
|
|
383
|
+
) -> list[dict]:
|
|
384
|
+
"""
|
|
385
|
+
Get cross-references (links between items).
|
|
386
|
+
|
|
387
|
+
Args:
|
|
388
|
+
project_id: Optional filter by project
|
|
389
|
+
source_type: Optional filter by source type ('problem', 'solution', etc.)
|
|
390
|
+
source_id: Optional filter by specific source item
|
|
391
|
+
|
|
392
|
+
Returns:
|
|
393
|
+
List of cross-references
|
|
394
|
+
"""
|
|
395
|
+
db = get_db()
|
|
396
|
+
conn = db._conn()
|
|
397
|
+
try:
|
|
398
|
+
query = "SELECT * FROM cross_references WHERE 1=1"
|
|
399
|
+
params = []
|
|
400
|
+
if project_id:
|
|
401
|
+
query += " AND (source_project_id = ? OR target_project_id = ?)"
|
|
402
|
+
params.extend([project_id, project_id])
|
|
403
|
+
if source_type:
|
|
404
|
+
query += " AND source_type = ?"
|
|
405
|
+
params.append(source_type)
|
|
406
|
+
if source_id:
|
|
407
|
+
query += " AND source_id = ?"
|
|
408
|
+
params.append(source_id)
|
|
409
|
+
query += " ORDER BY created_at DESC"
|
|
410
|
+
|
|
411
|
+
rows = conn.execute(query, params).fetchall()
|
|
412
|
+
return [dict(r) for r in rows]
|
|
413
|
+
finally:
|
|
414
|
+
conn.close()
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
def get_project_context_v11(
|
|
418
|
+
project_name: str,
|
|
419
|
+
hours: int = 48,
|
|
420
|
+
include_files: bool = True
|
|
421
|
+
) -> Optional[dict]:
|
|
422
|
+
"""
|
|
423
|
+
v1.1 KILLER TOOL: Get everything needed to work on a project.
|
|
424
|
+
Now includes file attachments!
|
|
425
|
+
|
|
426
|
+
Returns:
|
|
427
|
+
- Project details
|
|
428
|
+
- All components
|
|
429
|
+
- Active problems (open, investigating)
|
|
430
|
+
- Recent changes (last 24-48 hours)
|
|
431
|
+
- High-priority todos
|
|
432
|
+
- Recent learnings
|
|
433
|
+
- Current session if any
|
|
434
|
+
- File attachments with key locations (NEW in v1.1)
|
|
435
|
+
|
|
436
|
+
Args:
|
|
437
|
+
project_name: Name of the project
|
|
438
|
+
hours: How many hours back to look for changes (default 48)
|
|
439
|
+
include_files: Include file attachments in context (default True)
|
|
440
|
+
|
|
441
|
+
Returns:
|
|
442
|
+
Full project context or None if project not found
|
|
443
|
+
"""
|
|
444
|
+
db = get_db()
|
|
445
|
+
ctx = db.get_project_context(project_name, hours)
|
|
446
|
+
if ctx is None:
|
|
447
|
+
return None
|
|
448
|
+
|
|
449
|
+
result = {
|
|
450
|
+
"project": ctx.project.model_dump(),
|
|
451
|
+
"components": [c.model_dump() for c in ctx.components],
|
|
452
|
+
"open_problems": [p.model_dump() for p in ctx.open_problems],
|
|
453
|
+
"recent_changes": [c.model_dump() for c in ctx.recent_changes],
|
|
454
|
+
"high_priority_todos": [t.model_dump() for t in ctx.high_priority_todos],
|
|
455
|
+
"recent_learnings": [l.model_dump() for l in ctx.recent_learnings],
|
|
456
|
+
"current_session": ctx.current_session.model_dump() if ctx.current_session else None
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
# Add file attachments if requested (v1.1)
|
|
460
|
+
if include_files:
|
|
461
|
+
attachments = get_attachments(project_id=ctx.project.id)
|
|
462
|
+
result["attachments"] = attachments
|
|
463
|
+
|
|
464
|
+
# Get content locations for attachments
|
|
465
|
+
conn = db._conn()
|
|
466
|
+
try:
|
|
467
|
+
for att in attachments:
|
|
468
|
+
locations = conn.execute(
|
|
469
|
+
"SELECT * FROM content_locations WHERE attachment_id = ?",
|
|
470
|
+
(att['id'],)
|
|
471
|
+
).fetchall()
|
|
472
|
+
att['content_locations'] = [dict(l) for l in locations]
|
|
473
|
+
finally:
|
|
474
|
+
conn.close()
|
|
475
|
+
|
|
476
|
+
return result
|
|
477
|
+
|
|
478
|
+
|
|
479
|
+
def get_project_context_lean(
|
|
480
|
+
project_name: str,
|
|
481
|
+
hours: int = 48
|
|
482
|
+
) -> Optional[dict]:
|
|
483
|
+
"""
|
|
484
|
+
LEAN VERSION: Get project context with minimal token footprint.
|
|
485
|
+
|
|
486
|
+
Returns summary stats instead of full objects. Use this at session start
|
|
487
|
+
to avoid context overflow. Call specific tools (get_open_problems, etc.)
|
|
488
|
+
only when you need full details.
|
|
489
|
+
|
|
490
|
+
Args:
|
|
491
|
+
project_name: Name of the project
|
|
492
|
+
hours: How many hours back for changes (default 48)
|
|
493
|
+
|
|
494
|
+
Returns:
|
|
495
|
+
Compact context with:
|
|
496
|
+
- project: id, name, status only
|
|
497
|
+
- stats: counts of components, problems, todos, etc.
|
|
498
|
+
- recent_focus: last problem/component worked on
|
|
499
|
+
- blocking: any critical/high priority open items
|
|
500
|
+
- quick_todos: up to 3 pending todo titles
|
|
501
|
+
"""
|
|
502
|
+
db = get_db()
|
|
503
|
+
ctx = db.get_project_context(project_name, hours)
|
|
504
|
+
if ctx is None:
|
|
505
|
+
return None
|
|
506
|
+
|
|
507
|
+
# Build lean response
|
|
508
|
+
project = ctx.project
|
|
509
|
+
|
|
510
|
+
# Get blocking items (high/critical open problems)
|
|
511
|
+
blocking = [
|
|
512
|
+
{"id": p.id, "title": p.title[:60]}
|
|
513
|
+
for p in ctx.open_problems
|
|
514
|
+
if p.severity in ('critical', 'high')
|
|
515
|
+
][:3]
|
|
516
|
+
|
|
517
|
+
# Get top 3 pending todos (title only)
|
|
518
|
+
quick_todos = [
|
|
519
|
+
t.title[:50] for t in ctx.high_priority_todos[:3]
|
|
520
|
+
]
|
|
521
|
+
|
|
522
|
+
# Get recent focus from changes
|
|
523
|
+
recent_focus = None
|
|
524
|
+
if ctx.recent_changes:
|
|
525
|
+
last_change = ctx.recent_changes[0]
|
|
526
|
+
recent_focus = f"Component {last_change.component_id}: {last_change.field_name}"
|
|
527
|
+
|
|
528
|
+
return {
|
|
529
|
+
"project": {
|
|
530
|
+
"id": project.id,
|
|
531
|
+
"name": project.name,
|
|
532
|
+
"status": project.status
|
|
533
|
+
},
|
|
534
|
+
"stats": {
|
|
535
|
+
"components": len(ctx.components),
|
|
536
|
+
"open_problems": len(ctx.open_problems),
|
|
537
|
+
"pending_todos": len(ctx.high_priority_todos),
|
|
538
|
+
"recent_changes": len(ctx.recent_changes),
|
|
539
|
+
"learnings": len(ctx.recent_learnings)
|
|
540
|
+
},
|
|
541
|
+
"blocking": blocking,
|
|
542
|
+
"quick_todos": quick_todos,
|
|
543
|
+
"recent_focus": recent_focus,
|
|
544
|
+
"has_active_session": ctx.current_session is not None
|
|
545
|
+
}
|