pocketshell 0.4.14__tar.gz → 0.4.18__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.
- {pocketshell-0.4.14 → pocketshell-0.4.18}/PKG-INFO +1 -1
- {pocketshell-0.4.14 → pocketshell-0.4.18}/pyproject.toml +1 -1
- pocketshell-0.4.18/src/pocketshell/agent_card_push.py +263 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/src/pocketshell/cards.py +135 -1
- pocketshell-0.4.18/tests/test_agent_card_push.py +279 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/tests/test_cards.py +136 -0
- pocketshell-0.4.18/tests/test_watch_ci.py +600 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/uv.lock +3 -2
- {pocketshell-0.4.14 → pocketshell-0.4.18}/.gitignore +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/README.md +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/scheduler/README.md +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/scheduler/pocketshell-usage-capture.service +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/scheduler/pocketshell-usage-capture.timer +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/src/pocketshell/__init__.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/src/pocketshell/__main__.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/src/pocketshell/agent_log.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/src/pocketshell/agents.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/src/pocketshell/agents_kind.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/src/pocketshell/cgroup_agents.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/src/pocketshell/cli.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/src/pocketshell/daemon.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/src/pocketshell/env.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/src/pocketshell/github.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/src/pocketshell/hooks.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/src/pocketshell/jobs.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/src/pocketshell/logs.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/src/pocketshell/profiles.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/src/pocketshell/prune_attachments.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/src/pocketshell/push.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/src/pocketshell/qr_share.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/src/pocketshell/repos.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/src/pocketshell/resume.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/src/pocketshell/sessions.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/src/pocketshell/tree.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/src/pocketshell/usage.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/src/pocketshell/usage_capture.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/src/pocketshell/usage_reset.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/tests/__init__.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/tests/test_agent_log.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/tests/test_agents.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/tests/test_agents_kind.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/tests/test_cgroup_agents.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/tests/test_cli.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/tests/test_daemon.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/tests/test_env.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/tests/test_github.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/tests/test_hooks.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/tests/test_jobs.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/tests/test_logs.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/tests/test_profiles.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/tests/test_prune_attachments.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/tests/test_push.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/tests/test_qr_share.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/tests/test_repos.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/tests/test_resume.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/tests/test_sessions.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/tests/test_tree.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/tests/test_usage.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/tests/test_usage_capture.py +0 -0
- {pocketshell-0.4.14 → pocketshell-0.4.18}/tests/test_usage_reset.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pocketshell
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.18
|
|
4
4
|
Summary: Unified server-side Python utility for the PocketShell Android client.
|
|
5
5
|
Project-URL: Homepage, https://github.com/alexeygrigorev/pocketshell
|
|
6
6
|
Project-URL: Issues, https://github.com/alexeygrigorev/pocketshell/issues
|
|
@@ -8,7 +8,7 @@ name = "pocketshell"
|
|
|
8
8
|
# scripts/check-pypi-version.sh enforces this; .github/workflows/build.yml
|
|
9
9
|
# runs that check before publishing to PyPI. See
|
|
10
10
|
# tools/pocketshell/README.md ("Release flow") for the bump procedure.
|
|
11
|
-
version = "0.4.
|
|
11
|
+
version = "0.4.18"
|
|
12
12
|
description = "Unified server-side Python utility for the PocketShell Android client."
|
|
13
13
|
readme = "README.md"
|
|
14
14
|
requires-python = ">=3.11"
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
"""Server-side FCM push when an agent posts a typed card (epic #859, Slice D).
|
|
2
|
+
|
|
3
|
+
This is the card sibling of :mod:`pocketshell.push` (which owns the usage-reset
|
|
4
|
+
FCM path, #690). When a running agent calls ``pocketshell push checklist`` the
|
|
5
|
+
host writes/updates a per-session card (:mod:`pocketshell.cards`); this module
|
|
6
|
+
fires a best-effort FCM **data** push so the phone surfaces a heads-up
|
|
7
|
+
notification that opens the session's card feed.
|
|
8
|
+
|
|
9
|
+
Why a separate module (not inside :mod:`pocketshell.cards`)
|
|
10
|
+
----------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
The card store and the FCM device token live in **two different state homes**
|
|
13
|
+
(the #859 research spike's risk #1): cards under ``~/.pocketshell/cards/`` and
|
|
14
|
+
the registered device token under the usage state dir
|
|
15
|
+
(``$XDG_STATE_HOME/pocketshell/usage/push-token.json``). Rather than have
|
|
16
|
+
:mod:`pocketshell.cards` import the token storage directly, the bridge lives
|
|
17
|
+
here: it reads the token via :func:`pocketshell.push.read_token` and sends via
|
|
18
|
+
:class:`pocketshell.push.FcmSender` — the exact same sender/credential the
|
|
19
|
+
usage-reset path uses. Adding a second card type later (``note``) reuses this
|
|
20
|
+
verbatim.
|
|
21
|
+
|
|
22
|
+
Hard-cut (D22): the app receive path adds a NEW ``type=agent_card`` payload
|
|
23
|
+
sibling to ``usage_reset`` — this module never emits ``usage_reset``.
|
|
24
|
+
|
|
25
|
+
Fail-soft (matches :func:`pocketshell.push.push_reset_events`): no registered
|
|
26
|
+
token, no service-account credential, or no :mod:`google.auth` installed → the
|
|
27
|
+
trigger no-ops and returns ``None`` WITHOUT raising. ``pocketshell push
|
|
28
|
+
checklist`` must never break because Firebase isn't set up.
|
|
29
|
+
|
|
30
|
+
De-dup
|
|
31
|
+
------
|
|
32
|
+
|
|
33
|
+
A successful send records a deterministic **content key** under the cards dir
|
|
34
|
+
(``push-sent.jsonl``) so re-pushing the *same* card (an agent re-runs the same
|
|
35
|
+
``push checklist``) does not re-POST, while an *updated* card (different items /
|
|
36
|
+
title) produces a new key and DOES push. The app's ``PushDedupStore`` is a
|
|
37
|
+
second line of defence on the device; this is the server-side primary guard.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
from __future__ import annotations
|
|
41
|
+
|
|
42
|
+
import hashlib
|
|
43
|
+
import json
|
|
44
|
+
import socket
|
|
45
|
+
from pathlib import Path
|
|
46
|
+
from typing import Any, Optional
|
|
47
|
+
|
|
48
|
+
from pocketshell import push as push_mod
|
|
49
|
+
from pocketshell.cards import CardPaths
|
|
50
|
+
from pocketshell.usage_capture import _append_history, resolve_paths as resolve_usage_paths
|
|
51
|
+
|
|
52
|
+
# The app contract: an agent-card push is a `type=agent_card` FCM data message.
|
|
53
|
+
AGENT_CARD_PUSH_TYPE = "agent_card"
|
|
54
|
+
|
|
55
|
+
# Per-session content-key log so a re-push of an unchanged card never re-POSTs.
|
|
56
|
+
# Lives under the cards dir (NOT the usage dir) — co-located with the cards it
|
|
57
|
+
# de-dups. One small file is plenty: cards are rare and bounded.
|
|
58
|
+
SENT_LOG_FILENAME = "push-sent.jsonl"
|
|
59
|
+
DEFAULT_SENT_LOG_MAX_LINES = 1000
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def sent_log_file(paths: CardPaths) -> Path:
|
|
63
|
+
"""Return the per-content-key already-pushed log path for ``paths``."""
|
|
64
|
+
return paths.cards_dir / SENT_LOG_FILENAME
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def sent_card_keys(paths: CardPaths) -> set[str]:
|
|
68
|
+
"""Return the set of card content keys already successfully pushed."""
|
|
69
|
+
path = sent_log_file(paths)
|
|
70
|
+
if not path.exists():
|
|
71
|
+
return set()
|
|
72
|
+
keys: set[str] = set()
|
|
73
|
+
try:
|
|
74
|
+
text = path.read_text(encoding="utf-8")
|
|
75
|
+
except OSError:
|
|
76
|
+
return set()
|
|
77
|
+
for line in text.splitlines():
|
|
78
|
+
if not line.strip():
|
|
79
|
+
continue
|
|
80
|
+
try:
|
|
81
|
+
parsed = json.loads(line)
|
|
82
|
+
except json.JSONDecodeError:
|
|
83
|
+
continue
|
|
84
|
+
if isinstance(parsed, dict):
|
|
85
|
+
key = parsed.get("card_key")
|
|
86
|
+
if isinstance(key, str) and key:
|
|
87
|
+
keys.add(key)
|
|
88
|
+
return keys
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _mark_sent(
|
|
92
|
+
card_key: str,
|
|
93
|
+
*,
|
|
94
|
+
paths: CardPaths,
|
|
95
|
+
sent_log_max_lines: int = DEFAULT_SENT_LOG_MAX_LINES,
|
|
96
|
+
) -> None:
|
|
97
|
+
"""Record ``card_key`` as successfully pushed so it never re-POSTs."""
|
|
98
|
+
_append_history(
|
|
99
|
+
sent_log_file(paths),
|
|
100
|
+
{"card_key": card_key},
|
|
101
|
+
history_max_lines=sent_log_max_lines,
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _summarise(card: dict[str, Any]) -> str:
|
|
106
|
+
"""One-line human summary of a card via its registered type, fail-soft.
|
|
107
|
+
|
|
108
|
+
Reuses the same per-type ``summarise`` the CLI's ``push status`` uses so the
|
|
109
|
+
notification body matches what the agent sees. Falls back to a generic line
|
|
110
|
+
for an unknown type (forward-compatible).
|
|
111
|
+
"""
|
|
112
|
+
from pocketshell.cards import get_card_type
|
|
113
|
+
|
|
114
|
+
card_type = card.get("type", "")
|
|
115
|
+
handler = get_card_type(card_type) if isinstance(card_type, str) else None
|
|
116
|
+
body = card.get("body", {})
|
|
117
|
+
state = card.get("state", {})
|
|
118
|
+
if handler is not None and isinstance(body, dict) and isinstance(state, dict):
|
|
119
|
+
try:
|
|
120
|
+
return handler.summarise(dict(body), dict(state))
|
|
121
|
+
except Exception:
|
|
122
|
+
pass
|
|
123
|
+
return f"{card_type or 'card'} updated"
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _host_alias() -> str:
|
|
127
|
+
"""Best-effort host identifier for the deep-link, never raising.
|
|
128
|
+
|
|
129
|
+
The host CLI does NOT know the app's host alias (the #859 research spike's
|
|
130
|
+
risk #2). The most reliable thing it can emit is its own resolvable
|
|
131
|
+
hostname, which the app matches against ``HostEntity.hostname`` /
|
|
132
|
+
``HostEntity.name`` to route the tap to the right host's session feed. When
|
|
133
|
+
the match is ambiguous or absent the app falls back to its home screen — it
|
|
134
|
+
never opens the WRONG host.
|
|
135
|
+
"""
|
|
136
|
+
try:
|
|
137
|
+
fqdn = socket.getfqdn().strip()
|
|
138
|
+
if fqdn and fqdn.lower() != "localhost":
|
|
139
|
+
return fqdn
|
|
140
|
+
except Exception:
|
|
141
|
+
pass
|
|
142
|
+
try:
|
|
143
|
+
return socket.gethostname().strip()
|
|
144
|
+
except Exception:
|
|
145
|
+
return ""
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def card_to_data(
|
|
149
|
+
session: str,
|
|
150
|
+
card: dict[str, Any],
|
|
151
|
+
*,
|
|
152
|
+
host: Optional[str] = None,
|
|
153
|
+
) -> dict[str, str]:
|
|
154
|
+
"""Map a card + its session to the app's ``agent_card`` data-message keys.
|
|
155
|
+
|
|
156
|
+
Keys (mirrors the app's ``AgentCardPushPayload`` contract):
|
|
157
|
+
|
|
158
|
+
- ``type`` = ``agent_card``
|
|
159
|
+
- ``session`` = the tmux session the card belongs to (deep-link target)
|
|
160
|
+
- ``host`` = best-effort host hostname for host resolution (may be empty)
|
|
161
|
+
- ``card_id`` = the card id
|
|
162
|
+
- ``card_type`` = e.g. ``checklist``
|
|
163
|
+
- ``title`` = the card title (falls back to a type-derived label)
|
|
164
|
+
- ``summary`` = the per-type one-line summary (e.g. ``checklist 1/3 checked``)
|
|
165
|
+
- ``card_key`` = the content-hash de-dup identity (also the app dedup key)
|
|
166
|
+
"""
|
|
167
|
+
card_type = str(card.get("type", "") or "")
|
|
168
|
+
card_id = str(card.get("id", "") or "")
|
|
169
|
+
title = card.get("title")
|
|
170
|
+
title_str = title.strip() if isinstance(title, str) and title.strip() else _default_title(card_type)
|
|
171
|
+
summary = _summarise(card)
|
|
172
|
+
resolved_host = host if host is not None else _host_alias()
|
|
173
|
+
card_key = content_key(session, card)
|
|
174
|
+
return {
|
|
175
|
+
"type": AGENT_CARD_PUSH_TYPE,
|
|
176
|
+
"session": session,
|
|
177
|
+
"host": resolved_host or "",
|
|
178
|
+
"card_id": card_id,
|
|
179
|
+
"card_type": card_type,
|
|
180
|
+
"title": title_str,
|
|
181
|
+
"summary": summary,
|
|
182
|
+
"card_key": card_key,
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def _default_title(card_type: str) -> str:
|
|
187
|
+
if card_type == "checklist":
|
|
188
|
+
return "Checklist"
|
|
189
|
+
if card_type:
|
|
190
|
+
return card_type[:1].upper() + card_type[1:]
|
|
191
|
+
return "Card"
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
def content_key(session: str, card: dict[str, Any]) -> str:
|
|
195
|
+
"""Deterministic content key for a card (drives server-side de-dup).
|
|
196
|
+
|
|
197
|
+
Hashes the session + card id + type + title + body + state — NOT
|
|
198
|
+
``updated_at`` (which changes on every push) — so an identical re-push
|
|
199
|
+
yields the SAME key (suppressed) while any content/state change yields a NEW
|
|
200
|
+
key (pushed). Stable across processes (``sort_keys``).
|
|
201
|
+
"""
|
|
202
|
+
payload = {
|
|
203
|
+
"session": session,
|
|
204
|
+
"id": card.get("id"),
|
|
205
|
+
"type": card.get("type"),
|
|
206
|
+
"title": card.get("title"),
|
|
207
|
+
"body": card.get("body"),
|
|
208
|
+
"state": card.get("state"),
|
|
209
|
+
}
|
|
210
|
+
blob = json.dumps(payload, sort_keys=True, ensure_ascii=False)
|
|
211
|
+
digest = hashlib.sha256(blob.encode("utf-8")).hexdigest()[:16]
|
|
212
|
+
return f"{session}|{card.get('id')}|{digest}"
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def notify_card_pushed(
|
|
216
|
+
session: str,
|
|
217
|
+
card: dict[str, Any],
|
|
218
|
+
*,
|
|
219
|
+
card_paths: CardPaths,
|
|
220
|
+
host: Optional[str] = None,
|
|
221
|
+
sender: Optional["push_mod.FcmSender"] = None,
|
|
222
|
+
env: Optional[dict[str, str]] = None,
|
|
223
|
+
sent_log_max_lines: int = DEFAULT_SENT_LOG_MAX_LINES,
|
|
224
|
+
) -> Optional[str]:
|
|
225
|
+
"""Best-effort FCM push for a freshly upserted ``card``. Fail-soft.
|
|
226
|
+
|
|
227
|
+
Returns the ``card_key`` actually pushed this call, or ``None`` when push
|
|
228
|
+
isn't configured / nothing new was sent. NEVER raises — the ``push
|
|
229
|
+
checklist`` CLI call must succeed even when Firebase isn't set up.
|
|
230
|
+
|
|
231
|
+
Guards, in order (mirroring :func:`pocketshell.push.push_reset_events`):
|
|
232
|
+
|
|
233
|
+
1. No registered device token -> ``None``.
|
|
234
|
+
2. No service-account credential / no ``google.auth`` -> ``None`` (pre-S0).
|
|
235
|
+
3. Already pushed this exact content (de-dup) -> ``None``.
|
|
236
|
+
4. On a successful send: record the content key so it never re-POSTs.
|
|
237
|
+
On a failed send: leave it un-recorded so the next push RETRIES.
|
|
238
|
+
"""
|
|
239
|
+
try:
|
|
240
|
+
usage_paths = resolve_usage_paths(env=env)
|
|
241
|
+
token = push_mod.read_token(usage_paths)
|
|
242
|
+
if token is None:
|
|
243
|
+
return None
|
|
244
|
+
|
|
245
|
+
if sender is None:
|
|
246
|
+
sa_path = push_mod._resolve_service_account_path(usage_paths, env=env)
|
|
247
|
+
if sa_path is None:
|
|
248
|
+
return None
|
|
249
|
+
sender = push_mod.FcmSender.from_service_account(sa_path)
|
|
250
|
+
if sender is None:
|
|
251
|
+
return None
|
|
252
|
+
|
|
253
|
+
data = card_to_data(session, card, host=host)
|
|
254
|
+
card_key = data["card_key"]
|
|
255
|
+
if card_key in sent_card_keys(card_paths):
|
|
256
|
+
return None
|
|
257
|
+
if sender.send_data_message(token=token, data=data):
|
|
258
|
+
_mark_sent(card_key, paths=card_paths, sent_log_max_lines=sent_log_max_lines)
|
|
259
|
+
return card_key
|
|
260
|
+
return None
|
|
261
|
+
except Exception:
|
|
262
|
+
# Absolute fail-soft backstop: a card push must never wedge the CLI.
|
|
263
|
+
return None
|
|
@@ -360,6 +360,62 @@ register_card_type(
|
|
|
360
360
|
)
|
|
361
361
|
|
|
362
362
|
|
|
363
|
+
# ---------------------------------------------------------------------------
|
|
364
|
+
# note card type (#859 Slice B — proves the registry is genuinely generic)
|
|
365
|
+
# ---------------------------------------------------------------------------
|
|
366
|
+
#
|
|
367
|
+
# A ``note`` is a non-interactive message the agent hands the human ("deploy
|
|
368
|
+
# finished", "found a flaky test"). Its only interaction is mark-as-read, so the
|
|
369
|
+
# agent can tell from ``push status`` whether the human has seen it. Registering
|
|
370
|
+
# it is exactly one ``register_card_type`` call + a ``push note`` verb — no new
|
|
371
|
+
# transport, no change to the store/read/write/upsert path. That is the whole
|
|
372
|
+
# point of the registry: a second real type is additive.
|
|
373
|
+
|
|
374
|
+
# Default note card id used when ``--id`` is omitted (one default note per
|
|
375
|
+
# session unless the agent names them — mirrors DEFAULT_CHECKLIST_ID).
|
|
376
|
+
DEFAULT_NOTE_ID = "note"
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
def _note_build_body(*, text: str, **_: Any) -> dict[str, Any]:
|
|
380
|
+
"""Build the note ``body`` — ``{"text": <message>}``."""
|
|
381
|
+
return {"text": text}
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
def _note_initial_state(_body: dict[str, Any]) -> dict[str, Any]:
|
|
385
|
+
"""A fresh note is unread."""
|
|
386
|
+
return {"read": False, "read_at": None}
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
def _note_apply_interaction(
|
|
390
|
+
body: dict[str, Any],
|
|
391
|
+
state: dict[str, Any],
|
|
392
|
+
interaction: Mapping[str, Any],
|
|
393
|
+
) -> dict[str, Any]:
|
|
394
|
+
"""Mark a note read/unread.
|
|
395
|
+
|
|
396
|
+
``interaction = {"read": bool}``. ``read`` defaults to True (mark read).
|
|
397
|
+
``read_at`` records when it was first read (cleared on unread) so the agent
|
|
398
|
+
can see acknowledgement timing via ``push status``.
|
|
399
|
+
"""
|
|
400
|
+
read = bool(interaction.get("read", True))
|
|
401
|
+
return {"read": read, "read_at": _now_iso() if read else None}
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
def _note_summarise(body: dict[str, Any], state: dict[str, Any]) -> str:
|
|
405
|
+
return "note: read" if state.get("read") else "note: unread"
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
register_card_type(
|
|
409
|
+
CardType(
|
|
410
|
+
name="note",
|
|
411
|
+
build_body=_note_build_body,
|
|
412
|
+
initial_state=_note_initial_state,
|
|
413
|
+
apply_interaction=_note_apply_interaction,
|
|
414
|
+
summarise=_note_summarise,
|
|
415
|
+
)
|
|
416
|
+
)
|
|
417
|
+
|
|
418
|
+
|
|
363
419
|
# ---------------------------------------------------------------------------
|
|
364
420
|
# Store read/write
|
|
365
421
|
# ---------------------------------------------------------------------------
|
|
@@ -576,7 +632,17 @@ def register_push_card_commands(push_group: click.Group) -> None:
|
|
|
576
632
|
build_kwargs={"items": parsed},
|
|
577
633
|
preset_checked=preset_checked,
|
|
578
634
|
)
|
|
579
|
-
|
|
635
|
+
card_paths = resolve_paths()
|
|
636
|
+
path = upsert_card(target, card, paths=card_paths)
|
|
637
|
+
# Slice D (#859): fire a best-effort FCM push so the phone surfaces a
|
|
638
|
+
# heads-up notification opening this session's card feed. Fail-soft —
|
|
639
|
+
# imported lazily so a host without the push deps still pushes the card.
|
|
640
|
+
try:
|
|
641
|
+
from pocketshell.agent_card_push import notify_card_pushed
|
|
642
|
+
|
|
643
|
+
notify_card_pushed(target, card, card_paths=card_paths)
|
|
644
|
+
except Exception:
|
|
645
|
+
pass
|
|
580
646
|
click.echo(
|
|
581
647
|
f"checklist {card_id!r} ({len(parsed)} items) -> session {target!r} ({path})"
|
|
582
648
|
)
|
|
@@ -661,3 +727,71 @@ def register_push_card_commands(push_group: click.Group) -> None:
|
|
|
661
727
|
state = card.get("state", {}) if isinstance(card.get("state"), Mapping) else {}
|
|
662
728
|
summary = handler.summarise(dict(body), dict(state)) if handler else ""
|
|
663
729
|
click.echo(f"{card_id}: {summary}")
|
|
730
|
+
|
|
731
|
+
@push_group.command("note")
|
|
732
|
+
@click.option("--title", "title", default=None, help="Human title for the note card.")
|
|
733
|
+
@click.option(
|
|
734
|
+
"--id",
|
|
735
|
+
"card_id",
|
|
736
|
+
default=DEFAULT_NOTE_ID,
|
|
737
|
+
help=f"Card id (default {DEFAULT_NOTE_ID!r}; one default note per session).",
|
|
738
|
+
)
|
|
739
|
+
@click.option(
|
|
740
|
+
"--text",
|
|
741
|
+
"text",
|
|
742
|
+
default=None,
|
|
743
|
+
help="The note body. Alternative to piping the message on stdin.",
|
|
744
|
+
)
|
|
745
|
+
@click.option("--session", "session", default=None, help="Override the auto-detected tmux session.")
|
|
746
|
+
def push_note(
|
|
747
|
+
title: Optional[str],
|
|
748
|
+
card_id: str,
|
|
749
|
+
text: Optional[str],
|
|
750
|
+
session: Optional[str],
|
|
751
|
+
) -> None:
|
|
752
|
+
"""Create/replace the session's note card from --text or piped stdin.
|
|
753
|
+
|
|
754
|
+
A note is a non-interactive message the human marks read (``push read``).
|
|
755
|
+
The session is auto-detected from ``$TMUX`` (override with ``--session``).
|
|
756
|
+
A re-push fully replaces the card of that id (hard-cut, D22).
|
|
757
|
+
"""
|
|
758
|
+
target = _require_session(session)
|
|
759
|
+
if text is not None and text.strip():
|
|
760
|
+
body_text = text.strip()
|
|
761
|
+
else:
|
|
762
|
+
stdin_text = "" if sys.stdin is None or sys.stdin.isatty() else sys.stdin.read()
|
|
763
|
+
body_text = stdin_text.strip()
|
|
764
|
+
if not body_text:
|
|
765
|
+
raise click.ClickException(
|
|
766
|
+
"empty note: pass --text or pipe the message on stdin."
|
|
767
|
+
)
|
|
768
|
+
card = build_card(
|
|
769
|
+
card_type="note",
|
|
770
|
+
card_id=card_id,
|
|
771
|
+
title=title,
|
|
772
|
+
build_kwargs={"text": body_text},
|
|
773
|
+
)
|
|
774
|
+
path = upsert_card(target, card, paths=resolve_paths())
|
|
775
|
+
click.echo(f"note {card_id!r} -> session {target!r} ({path})")
|
|
776
|
+
|
|
777
|
+
@push_group.command("read")
|
|
778
|
+
@click.option("--id", "card_id", required=True, help="The note card id.")
|
|
779
|
+
@click.option("--read/--unread", "read", default=True, help="Mark read (default) or unread.")
|
|
780
|
+
@click.option("--session", "session", default=None, help="Override the auto-detected tmux session.")
|
|
781
|
+
def push_read(card_id: str, read: bool, session: Optional[str]) -> None:
|
|
782
|
+
"""Set a note's read state (this is what the app's "mark read" calls)."""
|
|
783
|
+
target = _require_session(session)
|
|
784
|
+
try:
|
|
785
|
+
card = apply_interaction(
|
|
786
|
+
target,
|
|
787
|
+
card_id,
|
|
788
|
+
{"read": read},
|
|
789
|
+
paths=resolve_paths(),
|
|
790
|
+
)
|
|
791
|
+
except ValueError as exc:
|
|
792
|
+
raise click.ClickException(str(exc))
|
|
793
|
+
handler = get_card_type(card.get("type", ""))
|
|
794
|
+
body = card.get("body", {}) if isinstance(card.get("body"), Mapping) else {}
|
|
795
|
+
state = card.get("state", {}) if isinstance(card.get("state"), Mapping) else {}
|
|
796
|
+
summary = handler.summarise(dict(body), dict(state)) if handler else ""
|
|
797
|
+
click.echo(f"{card_id}: {summary}")
|