session-trail 0.2.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.
@@ -0,0 +1,307 @@
1
+ :root {
2
+ --paper: #f3f1ea;
3
+ --paper-deep: #eae8df;
4
+ --card: #fbfaf6;
5
+ --ink: #20332d;
6
+ --muted: #6f776f;
7
+ --line: #d5d8ce;
8
+ --forest: #294c40;
9
+ --rust: #c95532;
10
+ --rust-dark: #a94024;
11
+ --white: #fffef9;
12
+ --font-display: "Noto Serif CJK SC", "Source Han Serif SC", "Songti SC", serif;
13
+ --font-body: "Noto Sans CJK SC", "PingFang SC", "Microsoft YaHei", sans-serif;
14
+ --font-mono: "JetBrains Mono", "Cascadia Mono", "SFMono-Regular", monospace;
15
+ }
16
+
17
+ * { box-sizing: border-box; }
18
+ html { scroll-behavior: smooth; }
19
+ body {
20
+ margin: 0;
21
+ min-width: 320px;
22
+ color: var(--ink);
23
+ background: var(--paper);
24
+ font-family: var(--font-body);
25
+ font-size: 14px;
26
+ line-height: 1.6;
27
+ -webkit-font-smoothing: antialiased;
28
+ }
29
+ body::before {
30
+ position: fixed;
31
+ inset: 0;
32
+ z-index: -1;
33
+ content: "";
34
+ pointer-events: none;
35
+ background-image: linear-gradient(rgba(41, 76, 64, .035) 1px, transparent 1px), linear-gradient(90deg, rgba(41, 76, 64, .035) 1px, transparent 1px);
36
+ background-size: 32px 32px;
37
+ }
38
+ button, input, select { font: inherit; }
39
+ button, select { cursor: pointer; }
40
+ button { color: inherit; }
41
+ button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible, a:focus-visible {
42
+ outline: 3px solid rgba(201, 85, 50, .35);
43
+ outline-offset: 3px;
44
+ }
45
+ button:disabled { cursor: not-allowed; opacity: .5; }
46
+ [hidden] { display: none !important; }
47
+ .skip-link {
48
+ position: fixed;
49
+ top: -80px;
50
+ left: 16px;
51
+ z-index: 20;
52
+ padding: 8px 16px;
53
+ color: var(--white);
54
+ background: var(--forest);
55
+ }
56
+ .skip-link:focus { top: 12px; }
57
+ .topbar {
58
+ min-height: 78px;
59
+ padding: 0 4vw;
60
+ border-top: 4px solid var(--forest);
61
+ border-bottom: 1px solid var(--line);
62
+ display: flex;
63
+ align-items: center;
64
+ justify-content: space-between;
65
+ gap: 24px;
66
+ background: rgba(243, 241, 234, .95);
67
+ }
68
+ .brand { display: flex; align-items: center; gap: 13px; }
69
+ .brand-mark {
70
+ width: 38px;
71
+ height: 38px;
72
+ display: grid;
73
+ place-items: center;
74
+ color: var(--white);
75
+ background: var(--rust);
76
+ font-family: var(--font-mono);
77
+ font-size: 13px;
78
+ font-weight: 700;
79
+ letter-spacing: -.5px;
80
+ transform: rotate(-3deg);
81
+ }
82
+ .brand-name { font-family: var(--font-mono); font-size: 13px; letter-spacing: 1.6px; }
83
+ .brand-name strong { margin-left: 5px; font-family: var(--font-body); font-size: 16px; letter-spacing: 2px; }
84
+ .topbar-actions { display: flex; align-items: center; gap: 24px; }
85
+ .local-label { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
86
+ .status-dot { width: 7px; height: 7px; border-radius: 50%; background: #4c8569; box-shadow: 0 0 0 4px rgba(76, 133, 105, .1); }
87
+ .last-scan { color: var(--muted); font-family: var(--font-mono); font-size: 11px; }
88
+ .button {
89
+ min-height: 42px;
90
+ padding: 10px 18px;
91
+ border: 1px solid transparent;
92
+ border-radius: 3px;
93
+ font-weight: 650;
94
+ letter-spacing: .3px;
95
+ transition: background .18s, transform .18s, box-shadow .18s;
96
+ }
97
+ .button:hover:not(:disabled) { transform: translateY(-1px); }
98
+ .button-dark { color: var(--white); background: var(--forest); }
99
+ .button-dark:hover:not(:disabled) { background: #1d3c32; box-shadow: 0 4px 14px rgba(32, 51, 45, .16); }
100
+ .button-accent { color: var(--white); background: var(--rust); }
101
+ .button-accent:hover:not(:disabled) { background: var(--rust-dark); box-shadow: 0 4px 14px rgba(169, 64, 36, .18); }
102
+ .refresh-symbol { display: inline-block; margin-right: 7px; font-size: 17px; }
103
+ .is-refreshing .refresh-symbol { animation: spin .8s linear infinite; }
104
+ .shell {
105
+ width: min(1480px, 92vw);
106
+ margin: 0 auto;
107
+ display: grid;
108
+ grid-template-columns: 270px minmax(0, 1fr);
109
+ gap: clamp(40px, 6vw, 90px);
110
+ }
111
+ .sidebar { padding: 56px 0 40px; align-self: start; position: sticky; top: 0; }
112
+ .eyebrow { margin: 0 0 14px; color: var(--rust); font-family: var(--font-mono); font-size: 10px; font-weight: 700; letter-spacing: 1.7px; }
113
+ .intro { padding-bottom: 35px; border-bottom: 1px solid var(--line); }
114
+ .intro h1 {
115
+ margin: 0;
116
+ font-family: var(--font-display);
117
+ font-size: clamp(38px, 3.6vw, 52px);
118
+ font-weight: 700;
119
+ line-height: 1.25;
120
+ letter-spacing: 1px;
121
+ }
122
+ .intro-copy { margin: 20px 0 0; color: var(--muted); font-size: 13px; line-height: 1.9; }
123
+ .filters { padding: 29px 0 24px; }
124
+ .section-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
125
+ .section-heading h2 { margin: 0; font-size: 13px; letter-spacing: 1px; }
126
+ .text-button { padding: 4px; border: 0; color: var(--muted); background: none; font-size: 12px; text-decoration: underline; text-underline-offset: 3px; }
127
+ .text-button:hover { color: var(--rust); }
128
+ .period-filter { display: grid; grid-template-columns: repeat(4, 1fr); margin-bottom: 22px; border: 1px solid var(--line); border-radius: 3px; overflow: hidden; }
129
+ .period-filter button { min-height: 34px; padding: 4px 2px; border: 0; border-right: 1px solid var(--line); background: transparent; color: var(--muted); font-size: 11px; white-space: nowrap; }
130
+ .period-filter button:last-child { border-right: 0; }
131
+ .period-filter button[aria-pressed="true"] { color: var(--white); background: var(--forest); }
132
+ .field { display: block; margin-top: 17px; }
133
+ .field > span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 11px; font-weight: 650; letter-spacing: .5px; }
134
+ .field select, .field input {
135
+ width: 100%;
136
+ height: 41px;
137
+ padding: 8px 10px;
138
+ border: 1px solid var(--line);
139
+ border-radius: 3px;
140
+ color: var(--ink);
141
+ background: var(--card);
142
+ font-size: 12px;
143
+ }
144
+ .field select { text-overflow: ellipsis; }
145
+ .field input::placeholder { color: #999e95; }
146
+ .filter-note { margin: 8px 0 0; color: var(--muted); font-size: 10px; }
147
+ .toggle-row { margin-top: 24px; display: flex; align-items: center; justify-content: space-between; gap: 14px; cursor: pointer; }
148
+ .toggle-row strong { display: block; font-size: 12px; }
149
+ .toggle-row small { display: block; color: var(--muted); font-size: 9px; }
150
+ .toggle-row input {
151
+ appearance: none;
152
+ flex: 0 0 auto;
153
+ width: 36px;
154
+ height: 20px;
155
+ margin: 0;
156
+ border: 1px solid #a7aea4;
157
+ border-radius: 12px;
158
+ background: #d9ddd4;
159
+ transition: background .2s;
160
+ }
161
+ .toggle-row input::before {
162
+ display: block;
163
+ width: 14px;
164
+ height: 14px;
165
+ margin: 2px;
166
+ border-radius: 50%;
167
+ background: var(--white);
168
+ content: "";
169
+ transition: transform .2s;
170
+ }
171
+ .toggle-row input:checked { border-color: var(--forest); background: var(--forest); }
172
+ .toggle-row input:checked::before { transform: translateX(16px); }
173
+ .source-panel { border-top: 1px solid var(--line); padding-top: 16px; }
174
+ .source-panel summary { display: flex; justify-content: space-between; cursor: pointer; font-size: 12px; font-weight: 650; list-style: none; }
175
+ .source-panel summary::-webkit-details-marker { display: none; }
176
+ .source-panel summary::after { content: "+"; color: var(--muted); }
177
+ .source-panel[open] summary::after { content: "−"; }
178
+ .source-summary { margin-left: auto; margin-right: 12px; color: var(--muted); font-size: 10px; font-weight: 400; }
179
+ .source-list { margin-top: 15px; }
180
+ .source-status { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 9px 0; border-bottom: 1px solid rgba(213, 216, 206, .65); font-size: 11px; }
181
+ .source-status:last-child { border: 0; }
182
+ .source-state { color: var(--muted); font-size: 10px; }
183
+ .source-error { grid-column: 1 / -1; color: var(--rust-dark); font-size: 9px; }
184
+ .timeline-area { min-width: 0; padding: 57px 0 30px; border-left: 1px solid var(--line); padding-left: clamp(28px, 4vw, 58px); }
185
+ .timeline-header { display: flex; align-items: end; justify-content: space-between; gap: 24px; padding-bottom: 28px; border-bottom: 1px solid var(--line); }
186
+ .timeline-header h2 { margin: 0; font-family: var(--font-display); font-size: 34px; line-height: 1.2; }
187
+ .result-meta { display: flex; align-items: baseline; gap: 7px; color: var(--muted); font-size: 11px; }
188
+ .result-meta strong { color: var(--ink); font-family: var(--font-display); font-size: 29px; }
189
+ .loading { min-height: 300px; padding: 60px 0; }
190
+ .loading-line { display: block; width: 90%; height: 12px; margin-bottom: 16px; background: #e0e1d8; animation: pulse 1.3s ease-in-out infinite alternate; }
191
+ .loading-line:nth-child(2) { width: 65%; }
192
+ .loading-line:nth-child(3) { width: 78%; }
193
+ .loading p { margin-top: 28px; color: var(--muted); font-size: 12px; }
194
+ .timeline { padding-top: 9px; }
195
+ .date-block { display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 20px; padding: 30px 0 17px; animation: enter .35s ease-out both; }
196
+ .date-heading { padding-top: 3px; }
197
+ .date-heading time { display: block; font-family: var(--font-display); font-size: 17px; font-weight: 700; }
198
+ .date-heading span { display: block; margin-top: 4px; color: var(--muted); font-family: var(--font-mono); font-size: 9px; letter-spacing: .6px; }
199
+ .date-items { min-width: 0; }
200
+ .session-entry { position: relative; display: grid; grid-template-columns: 63px minmax(0, 1fr); gap: 16px; }
201
+ .session-entry + .session-entry { margin-top: 15px; }
202
+ .time-rail { position: relative; padding-top: 20px; text-align: right; color: var(--muted); font-family: var(--font-mono); font-size: 10px; }
203
+ .time-rail::before { position: absolute; top: 26px; right: -21px; width: 7px; height: 7px; border: 2px solid var(--paper); border-radius: 50%; background: var(--forest); box-shadow: 0 0 0 1px var(--forest); content: ""; }
204
+ .time-rail::after { position: absolute; top: 38px; right: -17px; bottom: -30px; width: 1px; background: var(--line); content: ""; }
205
+ .session-entry:last-child .time-rail::after { bottom: 8px; }
206
+ .session-card { min-width: 0; border: 1px solid var(--line); border-radius: 4px; background: var(--card); transition: border-color .18s, box-shadow .18s, transform .18s; }
207
+ .session-card:hover { border-color: #b8beb3; box-shadow: 0 7px 22px rgba(32, 51, 45, .06); transform: translateY(-1px); }
208
+ .session-main { width: 100%; padding: 19px 21px; border: 0; text-align: left; background: transparent; }
209
+ .session-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
210
+ .source-badge { display: inline-flex; align-items: center; min-height: 21px; padding: 2px 7px; border: 1px solid #cdd5ca; border-radius: 2px; color: var(--forest); background: #edf0e8; font-family: var(--font-mono); font-size: 9px; font-weight: 700; letter-spacing: .4px; }
211
+ .segment-badge, .missing-badge { padding: 1px 6px; border-radius: 2px; color: var(--rust-dark); background: #f5e4db; font-size: 9px; }
212
+ .session-title { display: block; margin: 10px 0 7px; overflow-wrap: anywhere; font-family: var(--font-display); font-size: 17px; font-weight: 700; line-height: 1.55; }
213
+ .session-path { display: block; margin: 0; overflow: hidden; color: var(--muted); font-family: var(--font-mono); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; direction: rtl; text-align: left; }
214
+ .session-footer { margin-top: 13px; display: flex; align-items: center; justify-content: space-between; gap: 16px; color: var(--muted); font-size: 10px; }
215
+ .change-stats { font-family: var(--font-mono); }
216
+ .change-stats .additions { color: #3c7557; }
217
+ .change-stats .deletions { color: var(--rust-dark); }
218
+ .open-hint { color: var(--forest); opacity: 0; transform: translateX(-4px); transition: opacity .18s, transform .18s; }
219
+ .session-card:hover .open-hint, .session-main:focus-visible .open-hint { opacity: 1; transform: translateX(0); }
220
+ .segment-children { padding: 0 14px 13px; border-top: 1px solid var(--line); background: #f3f3eb; }
221
+ .segment-children .session-main { padding: 14px 8px; border-bottom: 1px solid var(--line); }
222
+ .segment-children .session-main:last-child { border: 0; }
223
+ .segment-children .session-title { margin: 5px 0; font-size: 14px; }
224
+ .segment-children .session-path { font-size: 9px; }
225
+ .child-time { color: var(--muted); font-family: var(--font-mono); font-size: 9px; }
226
+ [data-source="kimi-code"] .time-rail::before { background: #486f62; }
227
+ [data-source="codebuddy"] .time-rail::before { background: #447b91; }
228
+ [data-source="minimax-code"] .time-rail::before { background: #c46a3c; }
229
+ [data-source="zcode"] .time-rail::before { background: #75658b; }
230
+ [data-source="deepseek-harness"] .time-rail::before { background: #496e9a; }
231
+ [data-source="pi"] .time-rail::before { background: #99833f; }
232
+ [data-source="opencode"] .time-rail::before { background: #65754b; }
233
+ [data-source="codex"] .time-rail::before { background: #3e6660; }
234
+ [data-source="claude-code"] .time-rail::before { background: #b36d47; }
235
+ .empty-state { padding: 90px 20px; text-align: center; }
236
+ .empty-mark { display: block; color: #a9afa3; font-family: var(--font-display); font-size: 46px; }
237
+ .empty-state h3 { margin: 15px 0 5px; font-family: var(--font-display); font-size: 22px; }
238
+ .empty-state p { color: var(--muted); font-size: 12px; }
239
+ .privacy-note { margin-top: 45px; padding-top: 20px; border-top: 1px solid var(--line); display: flex; align-items: center; justify-content: center; gap: 9px; color: var(--muted); font-size: 10px; }
240
+ .privacy-note span { color: #73917c; font-size: 8px; }
241
+ .notice { margin: 16px 0; padding: 12px 14px; border-left: 3px solid #ad8542; color: #705626; background: #f4ebd9; font-size: 12px; }
242
+ .notice-error { border-color: var(--rust); color: var(--rust-dark); background: #f6e7de; }
243
+ .session-dialog { width: min(660px, calc(100vw - 32px)); max-height: 88vh; padding: 30px; border: 1px solid var(--line); border-top: 4px solid var(--forest); border-radius: 4px; color: var(--ink); background: var(--card); box-shadow: 0 30px 100px rgba(23, 38, 33, .25); }
244
+ .session-dialog::backdrop { background: rgba(23, 38, 33, .48); backdrop-filter: blur(3px); }
245
+ .dialog-topline { display: flex; align-items: center; justify-content: space-between; margin-bottom: 25px; }
246
+ .session-dialog h2 { margin: 0 0 12px; overflow-wrap: anywhere; font-family: var(--font-display); font-size: 26px; line-height: 1.45; }
247
+ .detail-workdir { margin: 0 0 25px; overflow-wrap: anywhere; color: var(--muted); font-family: var(--font-mono); font-size: 11px; }
248
+ .detail-grid { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 20px 28px; }
249
+ .detail-grid div { min-width: 0; }
250
+ .detail-grid dt { margin-bottom: 4px; color: var(--muted); font-size: 10px; letter-spacing: .5px; }
251
+ .detail-grid dd { margin: 0; overflow-wrap: anywhere; font-size: 12px; }
252
+ .detail-grid code { font-family: var(--font-mono); font-size: 10px; }
253
+ .detail-wide { grid-column: 1 / -1; }
254
+ .resume-area { margin-top: 28px; padding-top: 22px; border-top: 1px solid var(--line); }
255
+ .resume-area p { margin: 10px 0 0; color: var(--muted); font-size: 10px; }
256
+ .toast { position: fixed; right: 25px; bottom: 25px; z-index: 30; max-width: min(400px, calc(100vw - 40px)); padding: 13px 18px; border: 1px solid #47685b; border-radius: 3px; color: var(--white); background: var(--forest); box-shadow: 0 8px 30px rgba(32, 51, 45, .22); font-size: 12px; animation: enter .2s ease-out; }
257
+ @keyframes spin { to { transform: rotate(360deg); } }
258
+ @keyframes pulse { to { opacity: .45; } }
259
+ @keyframes enter { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: translateY(0); } }
260
+ @media (max-width: 1000px) {
261
+ .local-label { display: none; }
262
+ .shell { width: min(760px, 90vw); grid-template-columns: 1fr; gap: 0; }
263
+ .sidebar { position: static; padding-bottom: 10px; }
264
+ .intro { display: grid; grid-template-columns: 1fr 1fr; align-items: end; }
265
+ .intro .eyebrow { grid-column: 1 / -1; }
266
+ .intro-copy { margin: 0; text-align: right; }
267
+ .filters { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
268
+ .section-heading, .period-filter, .filter-note { grid-column: 1 / -1; }
269
+ .toggle-row { grid-column: 1 / -1; }
270
+ .timeline-area { padding-left: 0; border-left: 0; }
271
+ .source-panel { margin-top: 10px; }
272
+ }
273
+ @media (max-width: 620px) {
274
+ .topbar { padding: 13px 5vw; flex-wrap: wrap; gap: 10px; }
275
+ .topbar-actions { width: 100%; justify-content: space-between; gap: 10px; }
276
+ .last-scan { font-size: 9px; }
277
+ .button { min-height: 38px; padding: 8px 12px; font-size: 12px; }
278
+ .shell { width: 89vw; }
279
+ .sidebar { padding-top: 36px; }
280
+ .intro { display: block; }
281
+ .intro h1 br { display: none; }
282
+ .intro-copy { margin-top: 14px; text-align: left; }
283
+ .intro-copy br { display: none; }
284
+ .filters { display: block; }
285
+ .timeline-area { padding-top: 36px; }
286
+ .date-block { grid-template-columns: 1fr; gap: 15px; }
287
+ .date-heading { display: flex; align-items: baseline; gap: 10px; }
288
+ .date-heading span { margin: 0; }
289
+ .session-entry { grid-template-columns: 48px minmax(0, 1fr); gap: 12px; }
290
+ .time-rail { font-size: 9px; }
291
+ .time-rail::before { right: -17px; }
292
+ .time-rail::after { right: -13px; }
293
+ .session-main { padding: 15px; }
294
+ .session-title { font-size: 15px; }
295
+ .open-hint { display: none; }
296
+ .session-dialog { padding: 23px; }
297
+ .detail-grid { grid-template-columns: 1fr; }
298
+ .detail-wide { grid-column: auto; }
299
+ }
300
+ @media (prefers-reduced-motion: reduce) {
301
+ *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
302
+ }
303
+
304
+ .lang-switch { display: inline-flex; border: 1px solid var(--line); border-radius: 3px; overflow: hidden; }
305
+ .lang-switch button { padding: 4px 9px; border: 0; background: transparent; color: var(--muted); font-family: var(--font-mono); font-size: 10px; cursor: pointer; }
306
+ .lang-switch button + button { border-left: 1px solid var(--line); }
307
+ .lang-switch button.lang-active { color: var(--paper); background: var(--forest); }
agent_trail/store.py ADDED
@@ -0,0 +1,197 @@
1
+ from __future__ import annotations
2
+
3
+ import sqlite3
4
+ import threading
5
+ from pathlib import Path
6
+ from typing import Iterable
7
+
8
+ from .models import ActivitySession, SessionFilter
9
+
10
+ _COLUMNS = (
11
+ "source",
12
+ "session_id",
13
+ "workdir",
14
+ "workdir_normalized",
15
+ "title",
16
+ "title_source",
17
+ "created_at",
18
+ "updated_at",
19
+ "additions",
20
+ "deletions",
21
+ "files_changed",
22
+ "source_locator",
23
+ "resume_kind",
24
+ "resume_ref",
25
+ "source_missing",
26
+ "archived",
27
+ "adapter_version",
28
+ "source_fingerprint",
29
+ "last_scanned_at",
30
+ )
31
+
32
+
33
+ class LocalStore:
34
+ def __init__(self, path: str | Path) -> None:
35
+ self.path = Path(path)
36
+ self.path.parent.mkdir(parents=True, exist_ok=True)
37
+ self._lock = threading.RLock()
38
+ self._connection = sqlite3.connect(self.path, check_same_thread=False)
39
+ self._connection.row_factory = sqlite3.Row
40
+ self._connection.execute("PRAGMA foreign_keys = ON")
41
+ self._create_schema()
42
+
43
+ def _create_schema(self) -> None:
44
+ self._connection.execute(
45
+ """
46
+ CREATE TABLE IF NOT EXISTS sessions (
47
+ source TEXT NOT NULL,
48
+ session_id TEXT NOT NULL,
49
+ workdir TEXT NOT NULL,
50
+ workdir_normalized TEXT NOT NULL,
51
+ title TEXT,
52
+ title_source TEXT NOT NULL,
53
+ created_at TEXT,
54
+ updated_at TEXT NOT NULL,
55
+ additions INTEGER,
56
+ deletions INTEGER,
57
+ files_changed INTEGER,
58
+ source_locator TEXT NOT NULL,
59
+ resume_kind TEXT NOT NULL,
60
+ resume_ref TEXT,
61
+ source_missing INTEGER NOT NULL,
62
+ archived INTEGER NOT NULL,
63
+ adapter_version INTEGER NOT NULL,
64
+ source_fingerprint TEXT NOT NULL,
65
+ last_scanned_at TEXT NOT NULL,
66
+ PRIMARY KEY (source, session_id)
67
+ )
68
+ """
69
+ )
70
+ self._connection.execute(
71
+ """
72
+ CREATE TABLE IF NOT EXISTS adapter_state (
73
+ source TEXT PRIMARY KEY,
74
+ fingerprint TEXT,
75
+ last_scanned_at TEXT NOT NULL
76
+ )
77
+ """
78
+ )
79
+ self._connection.execute(
80
+ "CREATE INDEX IF NOT EXISTS sessions_updated_at ON sessions(updated_at DESC)"
81
+ )
82
+ self._connection.commit()
83
+
84
+ def close(self) -> None:
85
+ with self._lock:
86
+ self._connection.close()
87
+
88
+ def __enter__(self) -> LocalStore:
89
+ return self
90
+
91
+ def __exit__(self, *_: object) -> None:
92
+ self.close()
93
+
94
+ def replace_source(
95
+ self,
96
+ source: str,
97
+ sessions: Iterable[ActivitySession],
98
+ fingerprint: str | None,
99
+ scanned_at: str,
100
+ ) -> None:
101
+ records = list(sessions)
102
+ if any(record.source != source for record in records):
103
+ raise ValueError("session source does not match adapter")
104
+ placeholders = ",".join("?" for _ in _COLUMNS)
105
+ assignments = ",".join(f"{column}=excluded.{column}" for column in _COLUMNS[2:])
106
+ with self._lock, self._connection:
107
+ self._connection.execute(
108
+ "UPDATE sessions SET source_missing=1, resume_kind='none', "
109
+ "resume_ref=NULL, last_scanned_at=? WHERE source=?",
110
+ (scanned_at, source),
111
+ )
112
+ self._connection.executemany(
113
+ f"INSERT INTO sessions ({','.join(_COLUMNS)}) VALUES ({placeholders}) "
114
+ f"ON CONFLICT(source, session_id) DO UPDATE SET {assignments}",
115
+ [self._values(record) for record in records],
116
+ )
117
+ self._connection.execute(
118
+ "INSERT INTO adapter_state(source, fingerprint, last_scanned_at) VALUES(?,?,?) "
119
+ "ON CONFLICT(source) DO UPDATE SET fingerprint=excluded.fingerprint, "
120
+ "last_scanned_at=excluded.last_scanned_at",
121
+ (source, fingerprint, scanned_at),
122
+ )
123
+
124
+ def mark_unchanged(
125
+ self, source: str, fingerprint: str | None, scanned_at: str
126
+ ) -> None:
127
+ with self._lock, self._connection:
128
+ self._connection.execute(
129
+ "INSERT INTO adapter_state(source, fingerprint, last_scanned_at) VALUES(?,?,?) "
130
+ "ON CONFLICT(source) DO UPDATE SET fingerprint=excluded.fingerprint, "
131
+ "last_scanned_at=excluded.last_scanned_at",
132
+ (source, fingerprint, scanned_at),
133
+ )
134
+
135
+ def list_sessions(self, filters: SessionFilter) -> list[ActivitySession]:
136
+ clauses: list[str] = []
137
+ parameters: list[object] = []
138
+ if filters.since is not None:
139
+ clauses.append("updated_at >= ?")
140
+ parameters.append(filters.since)
141
+ if filters.until is not None:
142
+ clauses.append("updated_at < ?")
143
+ parameters.append(filters.until)
144
+ if filters.sources:
145
+ clauses.append(f"source IN ({','.join('?' for _ in filters.sources)})")
146
+ parameters.extend(filters.sources)
147
+ if filters.workdir is not None:
148
+ clauses.append("workdir_normalized = ?")
149
+ parameters.append(filters.workdir)
150
+ if filters.query:
151
+ escaped = self._escape_like(filters.query)
152
+ clauses.append("(title LIKE ? ESCAPE '\\' OR workdir LIKE ? ESCAPE '\\')")
153
+ pattern = f"%{escaped}%"
154
+ parameters.extend((pattern, pattern))
155
+ where = f"WHERE {' AND '.join(clauses)}" if clauses else ""
156
+ parameters.extend((filters.limit, filters.offset))
157
+ with self._lock:
158
+ rows = self._connection.execute(
159
+ f"SELECT {','.join(_COLUMNS)} FROM sessions {where} "
160
+ "ORDER BY updated_at DESC, source, session_id LIMIT ? OFFSET ?",
161
+ parameters,
162
+ ).fetchall()
163
+ return [self._record(row) for row in rows]
164
+
165
+ def get_session(self, source: str, session_id: str) -> ActivitySession | None:
166
+ with self._lock:
167
+ row = self._connection.execute(
168
+ f"SELECT {','.join(_COLUMNS)} FROM sessions WHERE source=? AND session_id=?",
169
+ (source, session_id),
170
+ ).fetchone()
171
+ return self._record(row) if row is not None else None
172
+
173
+ def get_fingerprint(self, source: str) -> str | None:
174
+ with self._lock:
175
+ row = self._connection.execute(
176
+ "SELECT fingerprint FROM adapter_state WHERE source=?", (source,)
177
+ ).fetchone()
178
+ return row[0] if row is not None else None
179
+
180
+ @staticmethod
181
+ def _escape_like(value: str) -> str:
182
+ return value.replace("\\", "\\\\").replace("%", "\\%").replace("_", "\\_")
183
+
184
+ @staticmethod
185
+ def _values(record: ActivitySession) -> tuple[object, ...]:
186
+ values: list[object] = []
187
+ for column in _COLUMNS:
188
+ value = getattr(record, column)
189
+ values.append(int(value) if isinstance(value, bool) else value)
190
+ return tuple(values)
191
+
192
+ @staticmethod
193
+ def _record(row: sqlite3.Row) -> ActivitySession:
194
+ values = dict(row)
195
+ values["source_missing"] = bool(values["source_missing"])
196
+ values["archived"] = bool(values["archived"])
197
+ return ActivitySession(**values)
@@ -0,0 +1,6 @@
1
+ """Agent 足迹 系统托盘(Linux/GI)。
2
+
3
+ app.py 是托盘主体(子进程管理 + GTK 窗口 + 菜单);sni.py 是原生
4
+ StatusNotifierItem 实现。托盘不 import 包内其他模块,因此可以由
5
+ cli 的重执行机制在带 GI 绑定的系统 Python 上运行。
6
+ """