sessionpulse 0.2.0__tar.gz → 0.3.0__tar.gz
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.
- {sessionpulse-0.2.0/src/sessionpulse.egg-info → sessionpulse-0.3.0}/PKG-INFO +15 -12
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/README.md +14 -11
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/pyproject.toml +1 -1
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/src/sessionpulse/__init__.py +1 -1
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/src/sessionpulse/cli.py +5 -4
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/src/sessionpulse/config.py +1 -0
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/src/sessionpulse/followups.py +121 -15
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/src/sessionpulse/hook.py +22 -0
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/src/sessionpulse/reader.py +48 -22
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/src/sessionpulse/server.py +4 -1
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/src/sessionpulse/static/dashboard.html +580 -170
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/src/sessionpulse/todos.py +19 -3
- {sessionpulse-0.2.0 → sessionpulse-0.3.0/src/sessionpulse.egg-info}/PKG-INFO +15 -12
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/tests/test_sessionpulse.py +91 -4
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/LICENSE +0 -0
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/setup.cfg +0 -0
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/src/sessionpulse/__main__.py +0 -0
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/src/sessionpulse/icons/sessionpulse-busy.svg +0 -0
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/src/sessionpulse/icons/sessionpulse-idle.svg +0 -0
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/src/sessionpulse/icons/sessionpulse-none.svg +0 -0
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/src/sessionpulse/install.py +0 -0
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/src/sessionpulse/learn.py +0 -0
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/src/sessionpulse/static/brand/favicon.svg +0 -0
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/src/sessionpulse/static/brand/session-pulse-idle-animated.svg +0 -0
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/src/sessionpulse/static/brand/session-pulse-idle-static.svg +0 -0
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/src/sessionpulse/static/brand/session-pulse-none-animated.svg +0 -0
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/src/sessionpulse/static/brand/session-pulse-none-static.svg +0 -0
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/src/sessionpulse/static/brand/session-pulse-working-animated.svg +0 -0
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/src/sessionpulse/static/brand/session-pulse-working-static.svg +0 -0
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/src/sessionpulse/status.py +0 -0
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/src/sessionpulse/tray.py +0 -0
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/src/sessionpulse.egg-info/SOURCES.txt +0 -0
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/src/sessionpulse.egg-info/dependency_links.txt +0 -0
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/src/sessionpulse.egg-info/entry_points.txt +0 -0
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/src/sessionpulse.egg-info/requires.txt +0 -0
- {sessionpulse-0.2.0 → sessionpulse-0.3.0}/src/sessionpulse.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sessionpulse
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: A quiet instrument panel for Claude Code: live sessions, usage, and a to-do board that fills itself from your sessions. Local only.
|
|
5
5
|
Author: Vijay Shukla
|
|
6
6
|
License-Expression: MIT
|
|
@@ -69,30 +69,32 @@ It reads the files Claude Code already writes under `~/.claude`. **Nothing leave
|
|
|
69
69
|
|
|
70
70
|
## Screenshots
|
|
71
71
|
|
|
72
|
-
<p align="center"><img src="https://raw.githubusercontent.com/vijayshuklaHL/sessionpulse/main/docs/images/overview.jpg" width="900" alt="Overview:
|
|
72
|
+
<p align="center"><img src="https://raw.githubusercontent.com/vijayshuklaHL/sessionpulse/main/docs/images/overview.jpg" width="900" alt="Overview: Needs you (decisions, blockers, old waits, follow-ups to review) beside the live sessions, then handoffs from ended sessions and an activity feed"></p>
|
|
73
73
|
|
|
74
|
-
|
|
|
74
|
+
| A page for every session | New follow-ups wait for your review |
|
|
75
75
|
|---|---|
|
|
76
|
-
| <img src="https://raw.githubusercontent.com/vijayshuklaHL/sessionpulse/main/docs/images/
|
|
76
|
+
| <img src="https://raw.githubusercontent.com/vijayshuklaHL/sessionpulse/main/docs/images/session.jpg" alt="Session page: the session's summary as a handoff, the resume command, its tasks, token use and details"> | <img src="https://raw.githubusercontent.com/vijayshuklaHL/sessionpulse/main/docs/images/board.jpg" alt="Board by status: Detected (with Accept and Not useful), To do, Doing, On hold, Done and Archived columns"> |
|
|
77
77
|
|
|
78
|
-
|
|
|
78
|
+
| Analytics | Light theme |
|
|
79
79
|
|---|---|
|
|
80
|
-
| <img src="https://raw.githubusercontent.com/vijayshuklaHL/sessionpulse/main/docs/images/
|
|
80
|
+
| <img src="https://raw.githubusercontent.com/vijayshuklaHL/sessionpulse/main/docs/images/analytics.jpg" alt="Analytics: totals, a 26-week activity heatmap, the last 30 days, tokens per day by model and active hours per day"> | <img src="https://raw.githubusercontent.com/vijayshuklaHL/sessionpulse/main/docs/images/overview-light.jpg" alt="The overview in the light theme"> |
|
|
81
81
|
|
|
82
82
|
*All screenshots use made-up data (`tools/showcase/`).*
|
|
83
83
|
|
|
84
84
|
## Features
|
|
85
85
|
|
|
86
|
+
- **Needs you:** the Overview opens with what is waiting on you: open decisions, things you've waited on for more than 3 days, blockers named in each project's latest session summary, and new follow-ups to review.
|
|
87
|
+
- **Pick up where you left off:** a summary of each session (goal, done, open, blocked on, next step), on its own page with the resume command and the tasks it left.
|
|
86
88
|
- **Live sessions:** working or idle, running time, last change, tokens, model. The panel icon shows the count and turns orange while Claude is working.
|
|
87
|
-
- **Follow-ups (optional):** Claude reads each session after 20 quiet minutes and adds what was left open to your to-do list, linked back to the session, with a one-click resume command. A later session that finishes an item closes it automatically.
|
|
89
|
+
- **Follow-ups (optional):** Claude reads each session after 20 quiet minutes and adds what was left open to your to-do list, linked back to the session, with a one-click resume command. New items wait in **Detected** until you **Accept** them or mark them **Not useful**, which steers later reads. A later session that finishes an item closes it automatically.
|
|
88
90
|
- **Why is this here?** Each follow-up keeps a short quote from the session, checked against the transcript; **Why?** shows it in context. The same work showing up in another project is flagged, with **Merge** and **Not the same**.
|
|
89
|
-
- **Board:** every to-do as a card, colour-coded by kind (Decide, Outside work, Waiting on, Checklist, Later), or by status (To do, Doing, Done). Drag and drop, project filter, search.
|
|
91
|
+
- **Board:** every to-do as a card, colour-coded by kind (Decide, Outside work, Waiting on, Checklist, Later), or by status (Detected, To do, Doing, On hold, Done, Archived). Drag and drop, project filter, search, export to Markdown, CSV or JSON.
|
|
90
92
|
- **Your own to-dos too:** add them on the dashboard or with `sessionpulse todo add "…"`.
|
|
91
|
-
- **
|
|
93
|
+
- **Analytics:** a 26-week activity heatmap, the last 30 days at a glance, input, output and cache tokens per day by model, active hours per day, busiest projects.
|
|
92
94
|
- **Starts and exits:** when each session started and ended, and why (`/clear`, Ctrl+D, logout…).
|
|
93
|
-
- **
|
|
95
|
+
- **Sessions:** every session, searchable; each opens its own page with a copyable `claude --resume` command.
|
|
94
96
|
- **Get better at Claude Code:** suggestions picked from how you actually work (no `CLAUDE.md` in busy projects, very long sessions, features you haven't tried), with free official docs and Anthropic Academy courses.
|
|
95
|
-
- **Small and private:** standard library only, listens on `127.0.0.1`, needs a token,
|
|
97
|
+
- **Small and private:** standard library only, listens on `127.0.0.1`, needs a token, dark and light themes, works on a phone screen (bottom tab bar).
|
|
96
98
|
|
|
97
99
|
## Install
|
|
98
100
|
|
|
@@ -209,6 +211,7 @@ followups_model = "haiku"
|
|
|
209
211
|
followups_idle_minutes = 20
|
|
210
212
|
followups_days = 30
|
|
211
213
|
followups_parallel = 3
|
|
214
|
+
followups_review = true # new follow-ups wait in Detected until you accept them
|
|
212
215
|
claude_command = "" # path to `claude` if it isn't on PATH
|
|
213
216
|
```
|
|
214
217
|
|
|
@@ -216,7 +219,7 @@ claude_command = "" # path to `claude` if it isn't on PATH
|
|
|
216
219
|
|
|
217
220
|
Off by default, because it uses Claude. When on, the dashboard server checks every 5 minutes for sessions that have been quiet for 20 minutes and changed since it last read them. It sends their prompts and Claude's replies to `claude -p` (Haiku by default) and asks only for what's still open. That counts toward your Claude usage: roughly one small Haiku request per session.
|
|
218
221
|
|
|
219
|
-
The request runs with all hooks disabled and `--no-session-persistence`, so it never shows up as a session, in this dashboard or in any hook of yours. Items you dismiss are remembered and not picked up again.
|
|
222
|
+
The request runs with all hooks disabled and `--no-session-persistence`, so it never shows up as a session, in this dashboard or in any hook of yours. New follow-ups wait in the board's **Detected** column until you **Accept** them or mark them **Not useful**; set `followups_review = false` to add them straight to the list. Items you dismiss are remembered and not picked up again.
|
|
220
223
|
|
|
221
224
|
## Privacy and security
|
|
222
225
|
|
|
@@ -41,30 +41,32 @@ It reads the files Claude Code already writes under `~/.claude`. **Nothing leave
|
|
|
41
41
|
|
|
42
42
|
## Screenshots
|
|
43
43
|
|
|
44
|
-
<p align="center"><img src="https://raw.githubusercontent.com/vijayshuklaHL/sessionpulse/main/docs/images/overview.jpg" width="900" alt="Overview:
|
|
44
|
+
<p align="center"><img src="https://raw.githubusercontent.com/vijayshuklaHL/sessionpulse/main/docs/images/overview.jpg" width="900" alt="Overview: Needs you (decisions, blockers, old waits, follow-ups to review) beside the live sessions, then handoffs from ended sessions and an activity feed"></p>
|
|
45
45
|
|
|
46
|
-
|
|
|
46
|
+
| A page for every session | New follow-ups wait for your review |
|
|
47
47
|
|---|---|
|
|
48
|
-
| <img src="https://raw.githubusercontent.com/vijayshuklaHL/sessionpulse/main/docs/images/
|
|
48
|
+
| <img src="https://raw.githubusercontent.com/vijayshuklaHL/sessionpulse/main/docs/images/session.jpg" alt="Session page: the session's summary as a handoff, the resume command, its tasks, token use and details"> | <img src="https://raw.githubusercontent.com/vijayshuklaHL/sessionpulse/main/docs/images/board.jpg" alt="Board by status: Detected (with Accept and Not useful), To do, Doing, On hold, Done and Archived columns"> |
|
|
49
49
|
|
|
50
|
-
|
|
|
50
|
+
| Analytics | Light theme |
|
|
51
51
|
|---|---|
|
|
52
|
-
| <img src="https://raw.githubusercontent.com/vijayshuklaHL/sessionpulse/main/docs/images/
|
|
52
|
+
| <img src="https://raw.githubusercontent.com/vijayshuklaHL/sessionpulse/main/docs/images/analytics.jpg" alt="Analytics: totals, a 26-week activity heatmap, the last 30 days, tokens per day by model and active hours per day"> | <img src="https://raw.githubusercontent.com/vijayshuklaHL/sessionpulse/main/docs/images/overview-light.jpg" alt="The overview in the light theme"> |
|
|
53
53
|
|
|
54
54
|
*All screenshots use made-up data (`tools/showcase/`).*
|
|
55
55
|
|
|
56
56
|
## Features
|
|
57
57
|
|
|
58
|
+
- **Needs you:** the Overview opens with what is waiting on you: open decisions, things you've waited on for more than 3 days, blockers named in each project's latest session summary, and new follow-ups to review.
|
|
59
|
+
- **Pick up where you left off:** a summary of each session (goal, done, open, blocked on, next step), on its own page with the resume command and the tasks it left.
|
|
58
60
|
- **Live sessions:** working or idle, running time, last change, tokens, model. The panel icon shows the count and turns orange while Claude is working.
|
|
59
|
-
- **Follow-ups (optional):** Claude reads each session after 20 quiet minutes and adds what was left open to your to-do list, linked back to the session, with a one-click resume command. A later session that finishes an item closes it automatically.
|
|
61
|
+
- **Follow-ups (optional):** Claude reads each session after 20 quiet minutes and adds what was left open to your to-do list, linked back to the session, with a one-click resume command. New items wait in **Detected** until you **Accept** them or mark them **Not useful**, which steers later reads. A later session that finishes an item closes it automatically.
|
|
60
62
|
- **Why is this here?** Each follow-up keeps a short quote from the session, checked against the transcript; **Why?** shows it in context. The same work showing up in another project is flagged, with **Merge** and **Not the same**.
|
|
61
|
-
- **Board:** every to-do as a card, colour-coded by kind (Decide, Outside work, Waiting on, Checklist, Later), or by status (To do, Doing, Done). Drag and drop, project filter, search.
|
|
63
|
+
- **Board:** every to-do as a card, colour-coded by kind (Decide, Outside work, Waiting on, Checklist, Later), or by status (Detected, To do, Doing, On hold, Done, Archived). Drag and drop, project filter, search, export to Markdown, CSV or JSON.
|
|
62
64
|
- **Your own to-dos too:** add them on the dashboard or with `sessionpulse todo add "…"`.
|
|
63
|
-
- **
|
|
65
|
+
- **Analytics:** a 26-week activity heatmap, the last 30 days at a glance, input, output and cache tokens per day by model, active hours per day, busiest projects.
|
|
64
66
|
- **Starts and exits:** when each session started and ended, and why (`/clear`, Ctrl+D, logout…).
|
|
65
|
-
- **
|
|
67
|
+
- **Sessions:** every session, searchable; each opens its own page with a copyable `claude --resume` command.
|
|
66
68
|
- **Get better at Claude Code:** suggestions picked from how you actually work (no `CLAUDE.md` in busy projects, very long sessions, features you haven't tried), with free official docs and Anthropic Academy courses.
|
|
67
|
-
- **Small and private:** standard library only, listens on `127.0.0.1`, needs a token,
|
|
69
|
+
- **Small and private:** standard library only, listens on `127.0.0.1`, needs a token, dark and light themes, works on a phone screen (bottom tab bar).
|
|
68
70
|
|
|
69
71
|
## Install
|
|
70
72
|
|
|
@@ -181,6 +183,7 @@ followups_model = "haiku"
|
|
|
181
183
|
followups_idle_minutes = 20
|
|
182
184
|
followups_days = 30
|
|
183
185
|
followups_parallel = 3
|
|
186
|
+
followups_review = true # new follow-ups wait in Detected until you accept them
|
|
184
187
|
claude_command = "" # path to `claude` if it isn't on PATH
|
|
185
188
|
```
|
|
186
189
|
|
|
@@ -188,7 +191,7 @@ claude_command = "" # path to `claude` if it isn't on PATH
|
|
|
188
191
|
|
|
189
192
|
Off by default, because it uses Claude. When on, the dashboard server checks every 5 minutes for sessions that have been quiet for 20 minutes and changed since it last read them. It sends their prompts and Claude's replies to `claude -p` (Haiku by default) and asks only for what's still open. That counts toward your Claude usage: roughly one small Haiku request per session.
|
|
190
193
|
|
|
191
|
-
The request runs with all hooks disabled and `--no-session-persistence`, so it never shows up as a session, in this dashboard or in any hook of yours. Items you dismiss are remembered and not picked up again.
|
|
194
|
+
The request runs with all hooks disabled and `--no-session-persistence`, so it never shows up as a session, in this dashboard or in any hook of yours. New follow-ups wait in the board's **Detected** column until you **Accept** them or mark them **Not useful**; set `followups_review = false` to add them straight to the list. Items you dismiss are remembered and not picked up again.
|
|
192
195
|
|
|
193
196
|
## Privacy and security
|
|
194
197
|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "sessionpulse"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.3.0"
|
|
8
8
|
description = "A quiet instrument panel for Claude Code: live sessions, usage, and a to-do board that fills itself from your sessions. Local only."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
license = "MIT"
|
|
@@ -179,7 +179,7 @@ def cmd_todo(cfg, args):
|
|
|
179
179
|
try:
|
|
180
180
|
if args.action == "add":
|
|
181
181
|
todos.apply(cfg, {"op": "add", "text": " ".join(args.text), "project": args.project})
|
|
182
|
-
elif args.action in ("done", "undo", "delete"):
|
|
182
|
+
elif args.action in ("done", "undo", "delete", "accept"):
|
|
183
183
|
for i in args.text:
|
|
184
184
|
todos.apply(cfg, {"op": args.action, "id": i})
|
|
185
185
|
except ValueError as exc:
|
|
@@ -190,7 +190,8 @@ def cmd_todo(cfg, args):
|
|
|
190
190
|
for i in show:
|
|
191
191
|
tag = f" [{i['project']}]" if i.get("project") else ""
|
|
192
192
|
when = f" done {i['done_at'][:10]}" if i["done_at"] else ""
|
|
193
|
-
|
|
193
|
+
review = " (to review)" if i.get("status") == todos.DETECTED else ""
|
|
194
|
+
print(f"{i['id']} {i['text']}{tag}{when}{review}")
|
|
194
195
|
parked = [i for i in items if not i["done_at"] and i.get("status") in todos.STATUSES]
|
|
195
196
|
if parked and args.action != "list-done":
|
|
196
197
|
held = sum(i["status"] == "hold" for i in parked)
|
|
@@ -323,8 +324,8 @@ def main(argv=None):
|
|
|
323
324
|
sub.add_parser("snapshot", help="print the dashboard data as JSON")
|
|
324
325
|
t = sub.add_parser("todo", help="your to-do list: add, done, undo, delete, list, list-done, export")
|
|
325
326
|
t.add_argument("action", nargs="?", default="list",
|
|
326
|
-
choices=["list", "list-done", "add", "done", "undo", "delete", "export"])
|
|
327
|
-
t.add_argument("text", nargs="*", help="the to-do text (add) or item ids (done/undo/delete)")
|
|
327
|
+
choices=["list", "list-done", "add", "done", "undo", "delete", "accept", "export"])
|
|
328
|
+
t.add_argument("text", nargs="*", help="the to-do text (add) or item ids (done/undo/delete/accept)")
|
|
328
329
|
t.add_argument("-p", "--project", help="tag the new to-do with a project (export: only this project)")
|
|
329
330
|
t.add_argument("--format", choices=todos.FORMATS, default="md", help="export: md (default), csv or json")
|
|
330
331
|
t.add_argument("--status", choices=["open", "all"], default="open",
|
|
@@ -46,6 +46,7 @@ class Config:
|
|
|
46
46
|
followups_every_minutes: int = 5
|
|
47
47
|
followups_batch: int = 5 # sessions read per round
|
|
48
48
|
followups_parallel: int = 3 # sessions read at the same time
|
|
49
|
+
followups_review: bool = True # new follow-ups wait in Detected until you accept them
|
|
49
50
|
claude_command: str = "" # path to `claude`, if it isn't on PATH
|
|
50
51
|
|
|
51
52
|
@property
|
|
@@ -33,6 +33,8 @@ MAX_ITEMS = 12
|
|
|
33
33
|
MAX_OPEN = 150 # open to-dos shown to the model per project
|
|
34
34
|
MAX_RELATED = 60 # and from the projects linked to it
|
|
35
35
|
NOT_USEFUL = 10 # recent "not useful" dismissals shown as examples of noise
|
|
36
|
+
MAX_WINDOWS = 4 # a long first read is split into windows of DIGEST_CHARS; beyond this many, the middle is left out
|
|
37
|
+
BRIEF_ITEMS = 5 # points per list in a session brief
|
|
36
38
|
QUOTE_CHARS = 160
|
|
37
39
|
EXCERPT_CHARS = 4000 # per turn, in the dashboard's transcript excerpt
|
|
38
40
|
TIMEOUT = 180
|
|
@@ -73,6 +75,11 @@ in different words: if an open to-do already covers the work, leave it out. Do n
|
|
|
73
75
|
under "dismissed". Items listed under "not useful" were dismissed by the user as noise: \
|
|
74
76
|
don't add items of that sort.
|
|
75
77
|
|
|
78
|
+
Also return `brief`, a short summary of the whole session so far for someone coming back to it: `goal` (one \
|
|
79
|
+
sentence), `done` and `open` (up to 5 short points each), `blocked` (what it is waiting on, or empty) and `next` (the \
|
|
80
|
+
next step, or empty). When you are given the earlier summary and only the newer turns, update that summary with \
|
|
81
|
+
them, and list only follow-ups that the newer turns show.
|
|
82
|
+
|
|
76
83
|
Turns are numbered (### #12 USER ...). For every item, set `quote` to a short passage copied exactly, word for \
|
|
77
84
|
word, from one turn (max 160 characters) that shows the item is still open, preferring the user's own words, and \
|
|
78
85
|
`ref` to that turn's number. Give each `resolved` to-do the same way: its id, and a `quote` and `ref` showing it \
|
|
@@ -91,8 +98,14 @@ SCHEMA = {
|
|
|
91
98
|
"type": "object",
|
|
92
99
|
"properties": {"id": {"type": "string"}, "quote": {"type": "string"}, "ref": {"type": "integer"}},
|
|
93
100
|
"required": ["id"]}},
|
|
101
|
+
"brief": {"type": "object", "properties": {
|
|
102
|
+
"goal": {"type": "string"},
|
|
103
|
+
"done": {"type": "array", "maxItems": BRIEF_ITEMS, "items": {"type": "string"}},
|
|
104
|
+
"open": {"type": "array", "maxItems": BRIEF_ITEMS, "items": {"type": "string"}},
|
|
105
|
+
"blocked": {"type": "string"}, "next": {"type": "string"}},
|
|
106
|
+
"required": ["goal", "done", "open", "blocked", "next"]},
|
|
94
107
|
},
|
|
95
|
-
"required": ["items", "resolved"],
|
|
108
|
+
"required": ["items", "resolved", "brief"],
|
|
96
109
|
}
|
|
97
110
|
|
|
98
111
|
_state_lock = threading.Lock()
|
|
@@ -126,16 +139,22 @@ def conversation(path):
|
|
|
126
139
|
return out
|
|
127
140
|
|
|
128
141
|
|
|
142
|
+
def _render(n, t):
|
|
143
|
+
"""One turn as the model reads it: numbered, long ones cut in the middle. Returns (text, body)."""
|
|
144
|
+
body, cap = t["text"], USER_CHARS if t["role"] == "user" else CLAUDE_CHARS
|
|
145
|
+
if len(body) > cap:
|
|
146
|
+
body = body[:cap // 2] + "\n[…]\n" + body[-cap // 2:]
|
|
147
|
+
when = str(t["at"] or "")[:16].replace("T", " ")
|
|
148
|
+
return f"### #{n} {'USER' if t['role'] == 'user' else 'CLAUDE'} {when}\n{body}", body
|
|
149
|
+
|
|
150
|
+
|
|
129
151
|
def digest(path, project="", limit=DIGEST_CHARS, turns=None):
|
|
130
152
|
"""The conversation as the model reads it, turns numbered #1.., trimmed to fit.
|
|
131
153
|
If `turns` is a list, each numbered turn is added to it (with the text the model saw)."""
|
|
132
154
|
parts = []
|
|
133
155
|
for n, t in enumerate(conversation(path), 1):
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
body = body[:cap // 2] + "\n[…]\n" + body[-cap // 2:]
|
|
137
|
-
when = str(t["at"] or "")[:16].replace("T", " ")
|
|
138
|
-
parts.append(f"### #{n} {'USER' if t['role'] == 'user' else 'CLAUDE'} {when}\n{body}")
|
|
156
|
+
part, body = _render(n, t)
|
|
157
|
+
parts.append(part)
|
|
139
158
|
if turns is not None:
|
|
140
159
|
turns.append({**t, "n": n, "text": body})
|
|
141
160
|
text = "\n\n".join(parts)
|
|
@@ -145,6 +164,59 @@ def digest(path, project="", limit=DIGEST_CHARS, turns=None):
|
|
|
145
164
|
return f"Project: {project}\n\n{text}"
|
|
146
165
|
|
|
147
166
|
|
|
167
|
+
def windows(conv, start=0, limit=DIGEST_CHARS, most=MAX_WINDOWS):
|
|
168
|
+
"""The turns from `start` on, numbered, in windows that each fit `limit`:
|
|
169
|
+
[[{**turn, "n", "text", "part"}]]. With more than `most`, the first and the newest are kept."""
|
|
170
|
+
out, size = [[]], 0
|
|
171
|
+
for n, t in enumerate(conv[start:], start + 1):
|
|
172
|
+
part, body = _render(n, t)
|
|
173
|
+
if out[-1] and size + len(part) > limit:
|
|
174
|
+
out.append([])
|
|
175
|
+
size = 0
|
|
176
|
+
out[-1].append({**t, "n": n, "text": body, "part": part})
|
|
177
|
+
size += len(part) + 2
|
|
178
|
+
out = [w for w in out if w]
|
|
179
|
+
if len(out) <= most:
|
|
180
|
+
return out
|
|
181
|
+
return [out[-1]] if most == 1 else [out[0]] + out[-(most - 1):]
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
# ---------- session briefs ----------
|
|
185
|
+
def _briefs_path(cfg):
|
|
186
|
+
return cfg.data / "briefs.json"
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def load_briefs(cfg):
|
|
190
|
+
"""Per session: {"brief": {...}, "turns": how many were read, "at", "model", "project"}."""
|
|
191
|
+
try:
|
|
192
|
+
b = json.loads(_briefs_path(cfg).read_text())
|
|
193
|
+
return b if isinstance(b, dict) else {}
|
|
194
|
+
except (OSError, ValueError):
|
|
195
|
+
return {}
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
def _clean_brief(b):
|
|
199
|
+
if not isinstance(b, dict):
|
|
200
|
+
return None
|
|
201
|
+
text = lambda v, n=300: todos.redact(" ".join(str(v or "").split()))[:n] # noqa: E731
|
|
202
|
+
points = lambda v: [text(x, 200) for x in v if isinstance(x, str) and x.strip()][:BRIEF_ITEMS] \
|
|
203
|
+
if isinstance(v, list) else [] # noqa: E731
|
|
204
|
+
out = {"goal": text(b.get("goal")), "done": points(b.get("done")), "open": points(b.get("open")),
|
|
205
|
+
"blocked": text(b.get("blocked")), "next": text(b.get("next"))}
|
|
206
|
+
return out if any(out.values()) else None
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
def _save_brief(cfg, sess, brief, turns):
|
|
210
|
+
with _state_lock:
|
|
211
|
+
b = load_briefs(cfg)
|
|
212
|
+
b[sess["id"]] = {"brief": brief, "turns": turns, "project": sess.get("project"), "model": cfg.followups_model,
|
|
213
|
+
"at": datetime.now().astimezone().isoformat(timespec="seconds")}
|
|
214
|
+
cfg.data.mkdir(parents=True, exist_ok=True)
|
|
215
|
+
tmp = _briefs_path(cfg).with_suffix(".tmp")
|
|
216
|
+
tmp.write_text(json.dumps(b, indent=1))
|
|
217
|
+
os.replace(tmp, _briefs_path(cfg))
|
|
218
|
+
|
|
219
|
+
|
|
148
220
|
def _plain(text):
|
|
149
221
|
"""Text reduced for quote matching: lower case, straight quotes, single spaces."""
|
|
150
222
|
text = str(text or "").lower().translate(str.maketrans("‘’“”–—", "''\"\"--"))
|
|
@@ -201,6 +273,9 @@ def claude_bin(cfg):
|
|
|
201
273
|
return None
|
|
202
274
|
|
|
203
275
|
|
|
276
|
+
NESTED_ENV = ("CLAUDECODE", "CLAUDE_CODE_ENTRYPOINT")
|
|
277
|
+
|
|
278
|
+
|
|
204
279
|
def ask_claude(cfg, prompt, system=SYSTEM, schema=SCHEMA, usage=None):
|
|
205
280
|
"""Run `claude -p` and return its structured output. What the call used is added to the daily
|
|
206
281
|
totals and, if given, to the `usage` dict."""
|
|
@@ -212,7 +287,9 @@ def ask_claude(cfg, prompt, system=SYSTEM, schema=SCHEMA, usage=None):
|
|
|
212
287
|
cmd = [exe, "-p", "--model", cfg.followups_model, "--no-session-persistence", "--tools", "",
|
|
213
288
|
"--settings", json.dumps({"disableAllHooks": True}), "--system-prompt", system,
|
|
214
289
|
"--output-format", "json", "--json-schema", json.dumps(schema)]
|
|
215
|
-
|
|
290
|
+
# Started from a terminal inside Claude Code, the tray inherits CLAUDECODE, and claude refuses to run
|
|
291
|
+
# "inside another session". This call is its own short-lived session, so drop those markers.
|
|
292
|
+
env = {k: v for k, v in os.environ.items() if k not in NESTED_ENV} | {"SESSIONPULSE_CHILD": "1"}
|
|
216
293
|
r = subprocess.run(cmd, input=prompt, capture_output=True, text=True, cwd=work, env=env, timeout=TIMEOUT)
|
|
217
294
|
try:
|
|
218
295
|
out = json.loads(r.stdout)
|
|
@@ -352,8 +429,27 @@ def checked(out, shown):
|
|
|
352
429
|
return items[:MAX_ITEMS], resolved
|
|
353
430
|
|
|
354
431
|
|
|
355
|
-
def process(cfg, sess, path, usage=None):
|
|
356
|
-
"""Extract follow-ups from one session and merge them into the to-do list.
|
|
432
|
+
def process(cfg, sess, path, usage=None, fresh=False):
|
|
433
|
+
"""Extract follow-ups from one session and merge them into the to-do list. Returns (added, closed).
|
|
434
|
+
|
|
435
|
+
Only the turns since the last read are sent, with the brief written then; a session read
|
|
436
|
+
for the first time (or with `fresh`) is read from the start, in windows if it is long."""
|
|
437
|
+
conv = conversation(path)
|
|
438
|
+
prev = {} if fresh else load_briefs(cfg).get(sess["id"]) or {}
|
|
439
|
+
start = prev.get("turns") if isinstance(prev.get("turns"), int) and 0 < prev["turns"] <= len(conv) else 0
|
|
440
|
+
brief = prev.get("brief") if start else None
|
|
441
|
+
added = closed = 0
|
|
442
|
+
parts = windows(conv, start)
|
|
443
|
+
for n, window in enumerate(parts, 1):
|
|
444
|
+
a, c, brief = _read(cfg, sess, window, brief, usage, more=n < len(parts))
|
|
445
|
+
added += a
|
|
446
|
+
closed += c
|
|
447
|
+
_save_brief(cfg, sess, brief, window[-1]["n"])
|
|
448
|
+
return added, closed
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
def _read(cfg, sess, window, brief, usage, more=False):
|
|
452
|
+
"""One model call on a window of turns (`more`: later turns follow). Returns (added, closed, brief)."""
|
|
357
453
|
items = todos.load(cfg)
|
|
358
454
|
project = sess.get("project") or ""
|
|
359
455
|
linked = todos.related(cfg, project)
|
|
@@ -367,8 +463,17 @@ def process(cfg, sess, path, usage=None):
|
|
|
367
463
|
gone = [d for d in todos.dismissed(cfg) if d.get("project") == project]
|
|
368
464
|
dismissed = gone[-40:]
|
|
369
465
|
noise = [d for d in gone if d.get("reason") == "not_useful"][-NOT_USEFUL:]
|
|
370
|
-
|
|
371
|
-
|
|
466
|
+
prompt = f"Project: {project}\n\n"
|
|
467
|
+
if brief:
|
|
468
|
+
prompt += ("## Earlier in this session (your summary from then; the turns before "
|
|
469
|
+
f"#{window[0]['n']} are not repeated)\n{json.dumps(brief, ensure_ascii=False)}\n\n"
|
|
470
|
+
f"## Newer turns\n\n")
|
|
471
|
+
elif window[0]["n"] > 1:
|
|
472
|
+
prompt += f"[… turns #1 to #{window[0]['n'] - 1} left out …]\n\n"
|
|
473
|
+
prompt += "\n\n".join(t["part"] for t in window)
|
|
474
|
+
if more:
|
|
475
|
+
prompt += ("\n\n[… the session goes on after this; you will see the rest next. Don't list the work that is "
|
|
476
|
+
"simply in progress here, only what is clearly left for later …]")
|
|
372
477
|
prompt += "\n\n## Open to-dos for this project\n" + (
|
|
373
478
|
"\n".join(f"- [{i['id']}] {i['text']}" for i in open_) or "(none)")
|
|
374
479
|
if others:
|
|
@@ -378,10 +483,11 @@ def process(cfg, sess, path, usage=None):
|
|
|
378
483
|
"\n".join(f"- {d['text']}" for d in dismissed) or "(none)")
|
|
379
484
|
if noise:
|
|
380
485
|
prompt += "\n\n## Not useful (don't add things like these)\n" + "\n".join(f"- {d['text']}" for d in noise)
|
|
381
|
-
|
|
486
|
+
out = ask_claude(cfg, prompt, usage=usage)
|
|
487
|
+
found, resolved = checked(out, {i["id"] for i in open_ + others})
|
|
382
488
|
for r in found + resolved:
|
|
383
|
-
r["evidence"] = evidence(r,
|
|
384
|
-
return todos.merge_followups(cfg, sess, found, resolved)
|
|
489
|
+
r["evidence"] = evidence(r, window)
|
|
490
|
+
return (*todos.merge_followups(cfg, sess, found, resolved), _clean_brief(out.get("brief")) or brief)
|
|
385
491
|
|
|
386
492
|
|
|
387
493
|
# ---------- one-off cleanup ----------
|
|
@@ -532,7 +638,7 @@ def _scan(cfg, limit, days, idle_minutes, session, force, log):
|
|
|
532
638
|
return 0, 0
|
|
533
639
|
use = {}
|
|
534
640
|
try:
|
|
535
|
-
a, c = process(cfg, s, s["transcript"], use)
|
|
641
|
+
a, c = process(cfg, s, s["transcript"], use, fresh=force)
|
|
536
642
|
except NotReady as exc: # a usage limit or outage: stop the round, blame no session
|
|
537
643
|
halt.set()
|
|
538
644
|
errors.append(str(exc))
|
|
@@ -8,10 +8,31 @@ import os
|
|
|
8
8
|
import socket
|
|
9
9
|
import sys
|
|
10
10
|
from datetime import datetime, timezone
|
|
11
|
+
from pathlib import Path
|
|
11
12
|
|
|
12
13
|
from . import config
|
|
13
14
|
|
|
14
15
|
|
|
16
|
+
def _find_claude_pid():
|
|
17
|
+
"""Walk up the process tree to find the ancestor 'claude' (node) process."""
|
|
18
|
+
try:
|
|
19
|
+
pid = os.getppid()
|
|
20
|
+
for _ in range(10): # at most 10 levels up
|
|
21
|
+
stat = Path(f"/proc/{pid}/stat").read_text()
|
|
22
|
+
comm = stat.split(")")[0].split("(")[-1]
|
|
23
|
+
if comm in ("claude", "node"):
|
|
24
|
+
return pid
|
|
25
|
+
# read ppid (field 4, 0-indexed after splitting on ") ")
|
|
26
|
+
fields = stat.split(") ", 1)[1].split()
|
|
27
|
+
ppid = int(fields[1]) # ppid is field index 1 after comm
|
|
28
|
+
if ppid <= 1:
|
|
29
|
+
break
|
|
30
|
+
pid = ppid
|
|
31
|
+
except (OSError, ValueError, IndexError):
|
|
32
|
+
pass
|
|
33
|
+
return None
|
|
34
|
+
|
|
35
|
+
|
|
15
36
|
def run(stdin=sys.stdin):
|
|
16
37
|
cfg = config.load()
|
|
17
38
|
try:
|
|
@@ -25,6 +46,7 @@ def run(stdin=sys.stdin):
|
|
|
25
46
|
# SessionEnd sends "reason" (clear, logout, prompt_input_exit, other);
|
|
26
47
|
# SessionStart sends "source" (startup, resume, clear, compact).
|
|
27
48
|
"reason": hook.get("reason") or hook.get("source"),
|
|
49
|
+
"pid": _find_claude_pid(),
|
|
28
50
|
}
|
|
29
51
|
cfg.data.mkdir(parents=True, exist_ok=True)
|
|
30
52
|
with open(cfg.events_file, "a") as f:
|
|
@@ -178,29 +178,55 @@ def pid_alive(pid):
|
|
|
178
178
|
return False
|
|
179
179
|
|
|
180
180
|
|
|
181
|
-
def read_live(claude: Path, health):
|
|
181
|
+
def read_live(claude: Path, health, events=None):
|
|
182
182
|
live = {}
|
|
183
183
|
d = claude / "sessions"
|
|
184
|
-
if
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
j
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
184
|
+
if d.is_dir():
|
|
185
|
+
for p in d.glob("*.json"):
|
|
186
|
+
try:
|
|
187
|
+
j = json.loads(p.read_text())
|
|
188
|
+
except (OSError, ValueError):
|
|
189
|
+
continue
|
|
190
|
+
if not isinstance(j, dict) or any(k not in j for k in LIVE_KEYS):
|
|
191
|
+
health["live_unrecognised"] += 1
|
|
192
|
+
continue
|
|
193
|
+
if not pid_alive(j.get("pid")):
|
|
194
|
+
continue
|
|
195
|
+
live[j["sessionId"]] = {
|
|
196
|
+
"pid": j.get("pid"), "status": j.get("status"), "name": j.get("name"),
|
|
197
|
+
"kind": j.get("kind"), "entrypoint": j.get("entrypoint"),
|
|
198
|
+
"startedAt": j.get("startedAt"),
|
|
199
|
+
"updatedAt": j.get("statusUpdatedAt") or j.get("updatedAt"),
|
|
200
|
+
}
|
|
201
|
+
# Fallback: if sessions/ yielded nothing, infer live sessions from events.
|
|
202
|
+
# A session is live if its most recent event is a SessionStart (not an End)
|
|
203
|
+
# and the captured pid is still running.
|
|
204
|
+
if not live and events:
|
|
205
|
+
latest = {} # sid -> most recent event
|
|
206
|
+
for e in events:
|
|
207
|
+
sid = e.get("session")
|
|
208
|
+
ev = e.get("event")
|
|
209
|
+
if sid and ev in ("SessionStart", "SessionEnd"):
|
|
210
|
+
latest[sid] = e
|
|
211
|
+
for sid, e in latest.items():
|
|
212
|
+
if e.get("event") != "SessionStart":
|
|
213
|
+
continue
|
|
214
|
+
pid = e.get("pid")
|
|
215
|
+
if pid and pid_alive(pid):
|
|
216
|
+
# Convert ISO timestamp to epoch (float) to match sessions/*.json format
|
|
217
|
+
ts = e.get("ts")
|
|
218
|
+
epoch = None
|
|
219
|
+
if ts:
|
|
220
|
+
try:
|
|
221
|
+
epoch = datetime.fromisoformat(ts).timestamp()
|
|
222
|
+
except (ValueError, OSError):
|
|
223
|
+
pass
|
|
224
|
+
live[sid] = {
|
|
225
|
+
"pid": pid, "status": "running", "name": None,
|
|
226
|
+
"kind": None, "entrypoint": None,
|
|
227
|
+
"startedAt": epoch,
|
|
228
|
+
"updatedAt": epoch,
|
|
229
|
+
}
|
|
204
230
|
return live
|
|
205
231
|
|
|
206
232
|
|
|
@@ -306,8 +332,8 @@ def snapshot(cfg: Config):
|
|
|
306
332
|
f"was tested with ({'.'.join(map(str, TESTED_CLI))}). "
|
|
307
333
|
"Check the numbers look right.")
|
|
308
334
|
|
|
309
|
-
live = read_live(claude, health)
|
|
310
335
|
events = read_events(cfg.events_file)
|
|
336
|
+
live = read_live(claude, health, events)
|
|
311
337
|
exits = {e.get("session"): e for e in events if e.get("event") == "SessionEnd"}
|
|
312
338
|
for sid, s in sessions.items():
|
|
313
339
|
if sid in live:
|
|
@@ -17,7 +17,7 @@ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
|
|
17
17
|
from importlib import resources
|
|
18
18
|
from urllib.parse import parse_qs, urlparse
|
|
19
19
|
|
|
20
|
-
from . import config, followups, reader, todos
|
|
20
|
+
from . import __version__, config, followups, reader, todos
|
|
21
21
|
|
|
22
22
|
COOKIE = "sessionpulse"
|
|
23
23
|
|
|
@@ -85,6 +85,9 @@ def make_handler(cfg: config.Config, tok: str):
|
|
|
85
85
|
data = reader.snapshot(cfg)
|
|
86
86
|
data["followups"] = {"enabled": cfg.followups, **followups.status,
|
|
87
87
|
"week": followups.usage_totals(cfg, 7), "failing": len(followups.failing(cfg))}
|
|
88
|
+
ids = {s["id"] for s in data["sessions"]}
|
|
89
|
+
data["briefs"] = {k: v for k, v in followups.load_briefs(cfg).items() if k in ids}
|
|
90
|
+
data["version"] = __version__
|
|
88
91
|
return self.send(200, json.dumps(data).encode(), "application/json")
|
|
89
92
|
if url.path == "/api/excerpt":
|
|
90
93
|
return self.excerpt(parse_qs(url.query))
|