kijito-tools 0.2.2 → 0.2.3
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.
- package/package.json +1 -1
- package/providers/_shared/wake-core.mjs +4 -2
- package/providers/claude/scripts/heartbeat-watchdog.sh +1 -1
- package/providers/claude/scripts/session-catchup-hint.sh +3 -3
- package/providers/claude/skills/kijito-start/SKILL.md +1 -1
- package/providers/codex/release-manifest.json +2 -2
- package/providers/codex/skills/kijito-start/SKILL.md +1 -1
- package/providers/codex/wake-helper/kijito-wake-helper.test.mjs +1 -1
- package/providers/monitor/CHANGELOG.md +13 -0
- package/providers/monitor/README.md +1 -0
- package/providers/monitor/UPSTREAM +10 -10
- package/providers/monitor/docs/DESIGN.md +1 -0
- package/providers/monitor/kijito_inbox_monitor.py +96 -1
- package/providers/monitor/package.json +1 -1
- package/providers/monitor/pyproject.toml +1 -1
- package/providers/monitor/test_kijito_monitor.py +119 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kijito-tools",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "Installer for kijito-tools: copies the context-tracking, session catch-up, and self-clear scripts plus the Kijito skills into ~/.claude.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -52,12 +52,14 @@ function requirePersona(persona) {
|
|
|
52
52
|
// silently — measured live 2026-08-15: a real corrupt-state producer emitted baseline_skipped
|
|
53
53
|
// into an armed stream and the helper ignored it, the exact "a diagnostic added to kill a
|
|
54
54
|
// silent failure is itself silent unless the consumer's filter learned its name" class the
|
|
55
|
-
// monitor documents. This is now the certified NEW_LENIENT 8-kind set
|
|
55
|
+
// monitor documents. This is now the certified NEW_LENIENT 8-kind set plus `still_unread` (row
|
|
56
|
+
// M229, monitor v0.5.5: the bounded reminder for mail announced once and still unread; a
|
|
57
|
+
// diagnostics-only batch already carries the reconcile-inbox peek below). `armed` and `heartbeat`
|
|
56
58
|
// stay EXCLUDED deliberately — liveness kinds must never wake (heartbeat fires every 900s, and
|
|
57
59
|
// armed's exclusion is why "I was not woken" does not mean "nothing arrived").
|
|
58
60
|
const MAIL_KINDS = Object.freeze(["new"]);
|
|
59
61
|
const DIAGNOSTIC_KINDS = Object.freeze([
|
|
60
|
-
"alert", "recovered", "state_corrupt", "baseline_skipped", "seed_ahead", "replay_capped", "persona_added",
|
|
62
|
+
"alert", "recovered", "state_corrupt", "baseline_skipped", "seed_ahead", "replay_capped", "persona_added", "still_unread",
|
|
61
63
|
]);
|
|
62
64
|
|
|
63
65
|
export function parseEventLine(line, persona) {
|
|
@@ -74,7 +74,7 @@ _pane_hash() { tmux capture-pane -p -t "$1" 2>/dev/null | tail -40 | cksum | awk
|
|
|
74
74
|
# SURFACED AS: an `HEARTBEAT_UNCONSUMED_STREAM` lifecycle-log line, a flag file the status line shows
|
|
75
75
|
# (`unconsumed.<pane>`), and a nudge prompt that says to re-arm the consumer FIRST. Cleared (with a
|
|
76
76
|
# `HEARTBEAT_STREAM_CONSUMED` line) the moment a consumer is attached again.
|
|
77
|
-
WAKE_EVENTS='"event": ?"(new|alert|recovered|state_corrupt|baseline_skipped|seed_ahead|replay_capped|persona_added)"'
|
|
77
|
+
WAKE_EVENTS='"event": ?"(new|alert|recovered|state_corrupt|baseline_skipped|seed_ahead|replay_capped|persona_added|still_unread)"'
|
|
78
78
|
UNCONSUMED_FLAG="$KIJITO_LC_DIR/unconsumed.$PANE"
|
|
79
79
|
st_missing_since=""; st_offset=""; st_alerted=0; st_path=""
|
|
80
80
|
|
|
@@ -297,7 +297,7 @@ task list:
|
|
|
297
297
|
all but one.
|
|
298
298
|
• You have NO inbox Monitor (brand-new session; the tail is a sibling's or a leaked orphan that will
|
|
299
299
|
NOT wake YOU) → arm exactly one for yourself:
|
|
300
|
-
Monitor(command="tail -n 0 -F $_events | grep --line-buffered -E '\"event\": ?\"(new|alert|recovered|state_corrupt|baseline_skipped|seed_ahead|replay_capped|persona_added)\"'", persistent=true)
|
|
300
|
+
Monitor(command="tail -n 0 -F $_events | grep --line-buffered -E '\"event\": ?\"(new|alert|recovered|state_corrupt|baseline_skipped|seed_ahead|replay_capped|persona_added|still_unread)\"'", persistent=true)
|
|
301
301
|
Dedupe with TaskStop (agent-scoped), NOT \`pkill -f …events…\` (that can kill a sibling's or your own live consumer). $_prod
|
|
302
302
|
EOF
|
|
303
303
|
elif [ -n "$_safe" ]; then
|
|
@@ -308,7 +308,7 @@ background \`tail\` is CAPTURE-ONLY (it writes to a file and never re-invokes yo
|
|
|
308
308
|
woken). Arm the wake-capable consumer with the Monitor TOOL (persistent) — it streams each event
|
|
309
309
|
as a live notification. Your persona for this project is "$_persona":
|
|
310
310
|
|
|
311
|
-
Monitor(command="tail -n 0 -F $_events | grep --line-buffered -E '\"event\": ?\"(new|alert|recovered|state_corrupt|baseline_skipped|seed_ahead|replay_capped|persona_added)\"'", persistent=true)
|
|
311
|
+
Monitor(command="tail -n 0 -F $_events | grep --line-buffered -E '\"event\": ?\"(new|alert|recovered|state_corrupt|baseline_skipped|seed_ahead|replay_capped|persona_added|still_unread)\"'", persistent=true)
|
|
312
312
|
|
|
313
313
|
First confirm nothing is already monitoring that stream this session (avoid double-arming). $_prod
|
|
314
314
|
EOF
|
|
@@ -320,7 +320,7 @@ background \`tail\` is CAPTURE-ONLY (it writes to a file and never re-invokes yo
|
|
|
320
320
|
woken). Arm the wake-capable consumer for YOUR persona with the Monitor TOOL (persistent) — it
|
|
321
321
|
streams each event as a live notification. Substitute your persona name for <persona>:
|
|
322
322
|
|
|
323
|
-
Monitor(command="tail -n 0 -F $_events_tmpl | grep --line-buffered -E '\"event\": ?\"(new|alert|recovered|state_corrupt|baseline_skipped|seed_ahead|replay_capped|persona_added)\"'", persistent=true)
|
|
323
|
+
Monitor(command="tail -n 0 -F $_events_tmpl | grep --line-buffered -E '\"event\": ?\"(new|alert|recovered|state_corrupt|baseline_skipped|seed_ahead|replay_capped|persona_added|still_unread)\"'", persistent=true)
|
|
324
324
|
|
|
325
325
|
(No .kijito_persona marker found in this project — add a one-line \`.kijito_persona\` file with your
|
|
326
326
|
persona name in the project root so this resolves automatically next session.) $_prod
|
|
@@ -57,7 +57,7 @@ Run `kijito_startup(persona="<P>", project="<J>")` with the persona/project your
|
|
|
57
57
|
"you already hit the trap" — and the remedy it prescribed would have killed a **working**
|
|
58
58
|
inbox. Anchoring on `^tail` excludes the shell and returns exactly one line per monitor.
|
|
59
59
|
- **prints nothing →** arm exactly ONE, wake-capable, via the Monitor tool (persistent):
|
|
60
|
-
`Monitor(command="tail -n 0 -F $STREAM | grep --line-buffered -E '\"event\": ?\"(new|alert|recovered|state_corrupt|baseline_skipped|seed_ahead|replay_capped|persona_added)\"'", persistent=true)`
|
|
60
|
+
`Monitor(command="tail -n 0 -F $STREAM | grep --line-buffered -E '\"event\": ?\"(new|alert|recovered|state_corrupt|baseline_skipped|seed_ahead|replay_capped|persona_added|still_unread)\"'", persistent=true)`
|
|
61
61
|
- **prints one line →** already armed by a prior (pre-`/clear`) session; **STOP — do not start another.**
|
|
62
62
|
- **prints two or more lines →** genuinely stacked; keep the newest, kill the rest:
|
|
63
63
|
```bash
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
"verify": "node providers/codex/install.mjs (default action; also runs before any skills deploy)"
|
|
14
14
|
},
|
|
15
15
|
"artifacts": {
|
|
16
|
-
"wakeCoreSha256": "
|
|
16
|
+
"wakeCoreSha256": "f6ca4f88841b371409dfb4946e3b427e83150bd511f38068b364de1090c5cd35",
|
|
17
17
|
"workflowSha256": "ec6a65c095e7011c3100c2a804e23c1dee1a63cfba0fb79f1b872aee91dd3b2d",
|
|
18
18
|
"planSha256": "d9d666b86ac06414f6e6a13a3e3e2115983a1dad44fcfded7eccc51b191fb451",
|
|
19
19
|
"wakeHelperSha256": "838f6b4462ba037a23a14b6fdb8dc34ee8b8f4a7df258b428832bc092fac3ea4",
|
|
20
20
|
"wsUdsSha256": "4da13eef89b572fb735e756cb06846a021919dec7f91c6d07989377944cc776c",
|
|
21
|
-
"wakeHelperTestsSha256": "
|
|
21
|
+
"wakeHelperTestsSha256": "c5b6ec88eef8d84195e6c7eaa71cfb78dd6e2f743622caaa2b97a6d087718dd1",
|
|
22
22
|
"wakeHelperIntegrationTestsSha256": "48f565dfe7e5b719903cd24b12ddfb3f17e1a16c532af397bfffcb39e4bfbe9b",
|
|
23
23
|
"wakeHelperMockDaemonSha256": "3406bcd46d913071c0ee293e30f46b42ad5cf8c5c77f70c4000d9bb37854dd0c"
|
|
24
24
|
},
|
|
@@ -111,7 +111,7 @@ session please") works with no flags and outranks this default.
|
|
|
111
111
|
```
|
|
112
112
|
If nothing prints, arm exactly ONE persistent Monitor:
|
|
113
113
|
```
|
|
114
|
-
Monitor(command="tail -n 0 -F $STREAM | grep --line-buffered -E '\"event\": ?\"(new|alert|recovered|state_corrupt|baseline_skipped|seed_ahead|replay_capped|persona_added)\"'", persistent=true)
|
|
114
|
+
Monitor(command="tail -n 0 -F $STREAM | grep --line-buffered -E '\"event\": ?\"(new|alert|recovered|state_corrupt|baseline_skipped|seed_ahead|replay_capped|persona_added|still_unread)\"'", persistent=true)
|
|
115
115
|
```
|
|
116
116
|
Report **armed-live (Claude Code fallback)**. This is not an ad-hoc
|
|
117
117
|
watcher — it is the standard, battle-tested Claude Code wake path.
|
|
@@ -84,7 +84,7 @@ test("R2: the armed-record byte stamps equal the sha256 of the files actually lo
|
|
|
84
84
|
// ── Gate-7 seam extension (argus 7819 conditions a/b): the NEW_LENIENT 8-kind set ──
|
|
85
85
|
|
|
86
86
|
test("seam: every diagnostic kind wakes with a lifecycle key; armed/heartbeat provably never wake", () => {
|
|
87
|
-
const DIAG = ["alert", "recovered", "state_corrupt", "baseline_skipped", "seed_ahead", "replay_capped", "persona_added"];
|
|
87
|
+
const DIAG = ["alert", "recovered", "state_corrupt", "baseline_skipped", "seed_ahead", "replay_capped", "persona_added", "still_unread"];
|
|
88
88
|
for (const kind of DIAG) {
|
|
89
89
|
const parsed = parseEventLine(JSON.stringify({ source: "kijito-inbox", persona: "codex", event: kind, ts: "2026-08-15T08:04:46.059708+00:00" }), "codex");
|
|
90
90
|
assert.equal(parsed.event?.trigger, "lifecycle", `${kind} must wake as lifecycle`);
|
|
@@ -3,6 +3,19 @@
|
|
|
3
3
|
All notable changes to kijito-inbox-monitor are documented in this file.
|
|
4
4
|
The format is based on Keep a Changelog, and this project follows Semantic Versioning.
|
|
5
5
|
|
|
6
|
+
## [0.5.5] - 2026-09-24
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
- **`still_unread`: a bounded reminder for mail that was announced and then left unread (row M229).**
|
|
10
|
+
The watcher announces each message once (`new`), so a message an agent looked at without marking it
|
|
11
|
+
read used to sit unread forever with nothing to bring it back. Now, when already-announced mail is still
|
|
12
|
+
unread `--still-unread-after` seconds after it was sent (default 7200; `0` turns it off), ONE
|
|
13
|
+
`still_unread` event per poll lists those messages. Each message is reminded at most once per window
|
|
14
|
+
and at most `--still-unread-max` times (default 3); retired, reserved and write_only inboxes are never
|
|
15
|
+
reminded; the first poll after a restart only takes note, so restarts do not produce a burst. It never
|
|
16
|
+
moves the cursor. Its `wake_class` is `diagnostic` (it wakes; `new` remains the only `mail`). Consumers
|
|
17
|
+
that filter by event name should add `still_unread` to their list.
|
|
18
|
+
|
|
6
19
|
## [0.5.4] - 2026-09-24
|
|
7
20
|
|
|
8
21
|
### Fixed
|
|
@@ -297,6 +297,7 @@ Each line of the events file (and each `exec-per-event` invocation) is one event
|
|
|
297
297
|
| `new` | a new inbox message | `KIJITOMON_ID`, `KIJITOMON_FROM`, `KIJITOMON_CONTENT`, `KIJITOMON_CREATED`, `KIJITOMON_PERSONA` |
|
|
298
298
|
| `alert` | the source has been unreachable for `--alert-after` polls (dead-man), **or** mail is stranded in an inbox nobody watches, **or** the server holds unread mail this window did not show (all below) | `KIJITOMON_REASON`, `KIJITOMON_FAILURES`, `KIJITOMON_STRANDED` |
|
|
299
299
|
| `recovered` | the source came back after an `alert` | `KIJITOMON_CURSOR` |
|
|
300
|
+
| `still_unread` | mail already announced as `new` is still **unread** `--still-unread-after` seconds (default 2 h) after it was sent. One event per poll names every such message; each message is reminded at most once per window and at most `--still-unread-max` (default 3) times; never for retired, reserved or write_only inboxes; nothing on the first poll after a restart. Read what you have handled with `mark_read=true` and it stops. | `KIJITOMON_IDS`, `KIJITOMON_OLDEST_AGE`, `KIJITOMON_REASON` |
|
|
300
301
|
| `heartbeat` | optional liveness tick (`--heartbeat N`) | `KIJITOMON_CURSOR` |
|
|
301
302
|
|
|
302
303
|
Every event also carries `KIJITOMON_EVENT`, `KIJITOMON_SOURCE`, `KIJITOMON_TS`, `KIJITOMON_EVENT_ID`,
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
# The upstream release providers/monitor is a byte-exact copy of (row M314).
|
|
2
2
|
# Written by scripts/import-monitor.sh; verified by tests/vendored_monitor_test.sh. Never hand-edit.
|
|
3
3
|
repo=KijitoAI/kijito-inbox-monitor
|
|
4
|
-
sha=
|
|
5
|
-
tree=
|
|
6
|
-
tag=v0.5.
|
|
4
|
+
sha=35b2fe6688b2f2f536a98952f40816c96057c69f
|
|
5
|
+
tree=994bb014166bb65b57223a524bbb0673f57ce22d
|
|
6
|
+
tag=v0.5.5
|
|
7
7
|
file=100644 8d88ccb0fd09b9144505f985b4f882db278fac1f .github/workflows/publish-npm.yml
|
|
8
8
|
file=100644 19ce3471a2cffa689be9d261049c1e74e3e7a25e .github/workflows/publish-pypi.yml
|
|
9
9
|
file=100644 4534290a5dd36d18d07a782b784b6b0ad5ee38fc .gitignore
|
|
10
|
-
file=100644
|
|
10
|
+
file=100644 9e7c054bccb95cbcb42ea8642eb1fab76e5863d5 CHANGELOG.md
|
|
11
11
|
file=100644 d645695673349e3947e8e5ae42332d0ac3164cd7 LICENSE
|
|
12
12
|
file=100644 f6b0e5634f3fd4156c1c000efb31578bfb068cf3 NOTICE
|
|
13
|
-
file=100644
|
|
13
|
+
file=100644 fa81d2fc2645a5503117825b714200e0ae642cc4 README.md
|
|
14
14
|
file=100644 72f0c148f1e721ac1bb4a38e5cae690355774314 RELEASING.md
|
|
15
15
|
file=100755 fca1203267cb726736b0c8f239e2d74c40a7a895 arm-hive-monitor.sh
|
|
16
16
|
file=100755 bbe3f07de13dab8a8a7a4798481156ae4a46ab8f bin/cli.js
|
|
17
17
|
file=100644 23e088613c314bf86b384640639b545de60ea9d0 com.kijito.inbox-monitor.plist.template
|
|
18
|
-
file=100644
|
|
18
|
+
file=100644 30519b1ad6098541083648392f344da68e688246 docs/DESIGN.md
|
|
19
19
|
file=100644 4f5e53a8633e60e6c57c451e28546f8af8783fe8 kijito-inbox-monitor@.service.template
|
|
20
|
-
file=100644
|
|
21
|
-
file=100644
|
|
22
|
-
file=100644
|
|
20
|
+
file=100644 a88a59eb52d45918794b46d54de826617d977ff2 kijito_inbox_monitor.py
|
|
21
|
+
file=100644 8c2d292152fbe752d5ebf3445141a9d7df5576e5 package.json
|
|
22
|
+
file=100644 199474330b420fa514378ab0c1211e21db9c6c41 pyproject.toml
|
|
23
23
|
file=100755 b34a5c775385ecfaefd4b374c1fc1aa082a85d14 scripts/migrate-systemd-unit.sh
|
|
24
24
|
file=100755 22acef6d6875395a81c701eb535030d0a78b0df1 scripts/mutation-check.py
|
|
25
25
|
file=100755 acba6196213736922fc4f7135749386d85d172a6 scripts/prepublish-gate.sh
|
|
26
|
-
file=100644
|
|
26
|
+
file=100644 8745e5bfe9573b9e85dd4e10f8904273d1dff864 test_kijito_monitor.py
|
|
@@ -293,6 +293,7 @@ One object per line; every event carries `event`, `source`, `ts` (emit-time UTC
|
|
|
293
293
|
{"event":"armed", "source":"kijito-inbox","ts":"<iso>","cursor":250}
|
|
294
294
|
{"event":"alert", "source":"kijito-inbox","ts":"<iso>","reason":"unreachable","consecutive_failures":3,"seconds":180}
|
|
295
295
|
{"event":"recovered", "source":"kijito-inbox","ts":"<iso>","cursor":250}
|
|
296
|
+
{"event":"still_unread","source":"kijito-inbox","ts":"<iso>","ids":[240,246],"senders":["river"],"oldest_age_seconds":9000,"after_seconds":7200,"reason":"..."} # M229 backstop, bounded
|
|
296
297
|
{"event":"heartbeat", "source":"kijito-inbox","ts":"<iso>","cursor":250} # only if --heartbeat; cursor may be null
|
|
297
298
|
{"event":"seed_ahead", "source":"kijito-inbox","ts":"<iso>","seeded":600,"current_max":539} # seed > reality (§7.0)
|
|
298
299
|
{"event":"replay_capped","source":"kijito-inbox","ts":"<iso>","capped_to":539,"dropped":389} # backlog > --max-replay (§7.0)
|
|
@@ -33,7 +33,7 @@ try:
|
|
|
33
33
|
except ImportError: # pragma: no cover - Windows
|
|
34
34
|
fcntl = None
|
|
35
35
|
|
|
36
|
-
__version__ = "0.5.
|
|
36
|
+
__version__ = "0.5.5"
|
|
37
37
|
SOURCE = "kijito-inbox"
|
|
38
38
|
# A named User-Agent is REQUIRED: api.kijito.ai is fronted by a WAF that 403s the default Python-urllib UA.
|
|
39
39
|
USER_AGENT = "kijito-inbox-monitor/%s" % __version__
|
|
@@ -952,6 +952,11 @@ _LIVENESS_KINDS = frozenset({"heartbeat", "armed"})
|
|
|
952
952
|
# liveness is a diagnostic, INCLUDING kinds absent from this table (see _wake_class).
|
|
953
953
|
_WAKE_CLASS_BY_KIND = {
|
|
954
954
|
"new": WAKE_CLASS_MAIL,
|
|
955
|
+
# Row M229: a reminder ABOUT mail (already-notified messages still unread past the threshold), not a
|
|
956
|
+
# message itself - one event names several ids and carries no body, so it is NOT `mail` (`new` stays
|
|
957
|
+
# the only mail, pinned by a test). As a diagnostic it WAKES, which is its whole job. Bounded by
|
|
958
|
+
# construction; see WatchTarget._resurface_still_unread.
|
|
959
|
+
"still_unread": WAKE_CLASS_DIAGNOSTIC,
|
|
955
960
|
"alert": WAKE_CLASS_DIAGNOSTIC,
|
|
956
961
|
"recovered": WAKE_CLASS_DIAGNOSTIC,
|
|
957
962
|
"state_corrupt": WAKE_CLASS_DIAGNOSTIC,
|
|
@@ -1181,6 +1186,7 @@ class Emitter:
|
|
|
1181
1186
|
"capped_to": "KIJITOMON_CAPPED_TO", "dropped": "KIJITOMON_DROPPED",
|
|
1182
1187
|
"stranded_inboxes": "KIJITOMON_STRANDED",
|
|
1183
1188
|
"dormant_inboxes": "KIJITOMON_DORMANT",
|
|
1189
|
+
"ids": "KIJITOMON_IDS", "oldest_age_seconds": "KIJITOMON_OLDEST_AGE",
|
|
1184
1190
|
}
|
|
1185
1191
|
for k, envname in keymap.items():
|
|
1186
1192
|
if k in event and event[k] is not None:
|
|
@@ -1852,6 +1858,20 @@ def _persona_path(template, persona):
|
|
|
1852
1858
|
return template.replace("{persona}", _state_safe_persona(persona))
|
|
1853
1859
|
|
|
1854
1860
|
|
|
1861
|
+
def _created_epoch(created):
|
|
1862
|
+
"""A message's `created` as epoch seconds, or None if it cannot be read. The server writes naive UTC
|
|
1863
|
+
('2026-09-24 21:34:24.943580'); an explicit offset or 'Z' is honoured when present."""
|
|
1864
|
+
if not isinstance(created, str) or not created:
|
|
1865
|
+
return None
|
|
1866
|
+
try:
|
|
1867
|
+
dt = datetime.datetime.fromisoformat(created.strip().replace("Z", "+00:00"))
|
|
1868
|
+
except ValueError:
|
|
1869
|
+
return None
|
|
1870
|
+
if dt.tzinfo is None:
|
|
1871
|
+
dt = dt.replace(tzinfo=datetime.timezone.utc)
|
|
1872
|
+
return dt.timestamp()
|
|
1873
|
+
|
|
1874
|
+
|
|
1855
1875
|
def _state_path_for_persona(base_path, persona):
|
|
1856
1876
|
if not base_path or not persona:
|
|
1857
1877
|
return base_path
|
|
@@ -2154,6 +2174,69 @@ class WatchTarget:
|
|
|
2154
2174
|
"cursor below it so it is re-delivered rather than skipped (further reports "
|
|
2155
2175
|
"suppressed until delivery recovers)\n" % (mid, self.persona))
|
|
2156
2176
|
|
|
2177
|
+
def _resurface_still_unread(self, items, now=None):
|
|
2178
|
+
"""Row M229 BACKSTOP: re-surface mail that was notified once and then left UNREAD.
|
|
2179
|
+
|
|
2180
|
+
The producer is edge-triggered per id - it emits `new` exactly once per message - so a message the
|
|
2181
|
+
agent peeked at (mark_read=false), acted on or meant to, and never consumed sits unread and INERT:
|
|
2182
|
+
never notified again, visible only to a staleness alarm. The ROOT fix is the consumer's (read
|
|
2183
|
+
what you handled with mark_read=true, shipped as wake-workflow doctrine 2026-08-12); this is the
|
|
2184
|
+
bounded backstop for what still slips through, and it is built so it cannot become a storm:
|
|
2185
|
+
* only for ids AT OR BELOW the cursor (already notified) whose server `read` flag is False and
|
|
2186
|
+
whose `created` is at least --still-unread-after seconds old;
|
|
2187
|
+
* at most once per id per window (--still-unread-after), and at most --still-unread-max times per
|
|
2188
|
+
id in this process - deliberately deferred mail is reminded a few times, not forever;
|
|
2189
|
+
* ONE summarising `still_unread` event per poll however many ids are due (one wake, not N);
|
|
2190
|
+
* never for debris (retired/reserved, row M332) or a write_only inbox;
|
|
2191
|
+
* the FIRST full poll of a process only notes what is already aged and emits nothing, so every
|
|
2192
|
+
restart (a deploy, a reboot) does not replay a burst of reminders.
|
|
2193
|
+
The ledger is per process: a restart can remind again, at most --still-unread-max times per id.
|
|
2194
|
+
It never touches the cursor - a reminder is not a delivery, and failing to emit one loses nothing.
|
|
2195
|
+
"""
|
|
2196
|
+
after = getattr(self.args, "still_unread_after", 0) or 0
|
|
2197
|
+
if after <= 0 or _is_debris(self.persona) or _PERSONA_WRITE_ONLY.get(self.persona) is True:
|
|
2198
|
+
return []
|
|
2199
|
+
cap = max(1, getattr(self.args, "still_unread_max", 3) or 1)
|
|
2200
|
+
now = time.time() if now is None else now
|
|
2201
|
+
ledger = self.__dict__.setdefault("still_unread_seen", {}) # id -> (times reminded, last at)
|
|
2202
|
+
primed = self.__dict__.get("still_unread_primed", False)
|
|
2203
|
+
cursor = self.cursor if isinstance(self.cursor, int) else -1
|
|
2204
|
+
due, visible = [], set()
|
|
2205
|
+
for m in items:
|
|
2206
|
+
mid = m.get("id")
|
|
2207
|
+
if not isinstance(mid, int) or isinstance(mid, bool) or mid > cursor or m.get("read") is not False:
|
|
2208
|
+
continue
|
|
2209
|
+
visible.add(mid)
|
|
2210
|
+
born = _created_epoch(m.get("created"))
|
|
2211
|
+
if born is None or now - born < after:
|
|
2212
|
+
continue
|
|
2213
|
+
n, last = ledger.get(mid, (0, None))
|
|
2214
|
+
if not primed:
|
|
2215
|
+
ledger[mid] = (n, now) # restart: note it, remind one full window from now
|
|
2216
|
+
continue
|
|
2217
|
+
if n >= cap or (last is not None and now - last < after):
|
|
2218
|
+
continue
|
|
2219
|
+
due.append((mid, m, now - born, n))
|
|
2220
|
+
for mid in list(ledger): # read, or gone from the window: forget it
|
|
2221
|
+
if mid not in visible:
|
|
2222
|
+
del ledger[mid]
|
|
2223
|
+
self.still_unread_primed = True
|
|
2224
|
+
if not due:
|
|
2225
|
+
return []
|
|
2226
|
+
oldest = max(age for _, _, age, _ in due)
|
|
2227
|
+
ok = self.emitter.lifecycle(
|
|
2228
|
+
"still_unread", persona=self.persona,
|
|
2229
|
+
ids=[mid for mid, _, _, _ in due],
|
|
2230
|
+
senders=sorted({m.get("from") for _, m, _, _ in due if m.get("from")}),
|
|
2231
|
+
oldest_age_seconds=int(oldest), after_seconds=int(after),
|
|
2232
|
+
reason=("still-unread: %d message(s) in this inbox were notified and are still UNREAD after "
|
|
2233
|
+
"%ds or more (oldest %ds). Read what you have handled with mark_read=true; this "
|
|
2234
|
+
"reminder repeats at most %d time(s) per message." % (len(due), after, int(oldest), cap)))
|
|
2235
|
+
if ok is True:
|
|
2236
|
+
for mid, _, _, n in due:
|
|
2237
|
+
ledger[mid] = (n + 1, now)
|
|
2238
|
+
return [mid for mid, _, _, _ in due]
|
|
2239
|
+
|
|
2157
2240
|
def _delivery_recovered(self):
|
|
2158
2241
|
if not self.delivery_blocked:
|
|
2159
2242
|
return
|
|
@@ -2579,6 +2662,7 @@ class WatchTarget:
|
|
|
2579
2662
|
delivered = set()
|
|
2580
2663
|
if blocked_at is None:
|
|
2581
2664
|
self._delivery_recovered()
|
|
2665
|
+
self._resurface_still_unread(items)
|
|
2582
2666
|
|
|
2583
2667
|
# §5.2 UNREAD MAIL WE CANNOT SEE. Fires on the FALSE->TRUE edge and releases itself when
|
|
2584
2668
|
# the condition clears, so it needs no ack: an ack would let someone silence "there is
|
|
@@ -3655,6 +3739,13 @@ def build_parser():
|
|
|
3655
3739
|
"Mutually exclusive with --token-file.")
|
|
3656
3740
|
p.add_argument("--no-fast-path", action="store_true",
|
|
3657
3741
|
help="Disable the /api/notify/pending unread pre-check; always full-poll the inbox list.")
|
|
3742
|
+
p.add_argument("--still-unread-after", type=int, default=7200, metavar="SECONDS",
|
|
3743
|
+
help="Row M229: emit ONE `still_unread` event per poll for mail that was already notified and "
|
|
3744
|
+
"is still unread this many seconds after it was sent (default 7200; 0 disables). At most "
|
|
3745
|
+
"once per message per window, capped by --still-unread-max; never for retired/reserved or "
|
|
3746
|
+
"write_only inboxes.")
|
|
3747
|
+
p.add_argument("--still-unread-max", type=int, default=3, metavar="N",
|
|
3748
|
+
help="How many times one message may be re-surfaced as still_unread per process (default 3).")
|
|
3658
3749
|
p.add_argument("--resync-every", type=int, default=10,
|
|
3659
3750
|
help="Fast-path safety floor: force a full inbox poll after at most N consecutive cheap "
|
|
3660
3751
|
"skips, so a stale/wrong unread count can never blind the watcher (default 10, min 1).")
|
|
@@ -3688,6 +3779,10 @@ def validate_args(args):
|
|
|
3688
3779
|
raise FatalConfig("--max-replay must be >= 0")
|
|
3689
3780
|
if args.keep_logs < 1:
|
|
3690
3781
|
raise FatalConfig("--keep-logs must be >= 1")
|
|
3782
|
+
if args.still_unread_after < 0:
|
|
3783
|
+
raise FatalConfig("--still-unread-after must be >= 0 (0 disables)")
|
|
3784
|
+
if args.still_unread_max < 1:
|
|
3785
|
+
raise FatalConfig("--still-unread-max must be >= 1")
|
|
3691
3786
|
if args.events_file and args.events_file_template:
|
|
3692
3787
|
raise FatalConfig("--events-file and --events-file-template are mutually exclusive")
|
|
3693
3788
|
if args.events_file_template and "{persona}" not in args.events_file_template:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kijito-inbox-monitor",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.5",
|
|
4
4
|
"description": "Pointer to the Python package kijito-inbox-monitor. A zero-dependency watcher that wakes a running agent when new Kijito inbox mail arrives. Install the real tool with pipx/uv/pip.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
|
|
|
7
7
|
|
|
8
8
|
[project]
|
|
9
9
|
name = "kijito-inbox-monitor"
|
|
10
|
-
version = "0.5.
|
|
10
|
+
version = "0.5.5"
|
|
11
11
|
description = "Zero-dependency watcher that wakes a running agent when new Kijito inbox mail arrives."
|
|
12
12
|
readme = "README.md"
|
|
13
13
|
requires-python = ">=3.9"
|
|
@@ -5995,3 +5995,122 @@ class SystemdUnitMigrationRewriteTest(unittest.TestCase):
|
|
|
5995
5995
|
r = self._run(fh.read())
|
|
5996
5996
|
self.assertIn("already migrated", r.stdout)
|
|
5997
5997
|
self.assertNotIn("ExecStart after:", r.stdout)
|
|
5998
|
+
|
|
5999
|
+
|
|
6000
|
+
class StillUnreadBackstopTest(unittest.TestCase):
|
|
6001
|
+
"""Row M229: mail that was notified once and then left UNREAD is re-surfaced - boundedly. The producer
|
|
6002
|
+
is edge-triggered per id, so without this such a message sits inert forever. These pin the bounds that
|
|
6003
|
+
keep a reminder from becoming a storm: priming on start, once per id per window, a per-id cap, one
|
|
6004
|
+
event per poll, and silence for debris and write_only inboxes."""
|
|
6005
|
+
|
|
6006
|
+
E2E = BoundedWindowEndToEndTest
|
|
6007
|
+
T0 = km._created_epoch("2026-09-24 00:00:00")
|
|
6008
|
+
H = 3600
|
|
6009
|
+
|
|
6010
|
+
def setUp(self):
|
|
6011
|
+
self._saved = [dict(d) for d in (km._PERSONA_RETIRED, km._PERSONA_RESERVED, km._PERSONA_WRITE_ONLY)]
|
|
6012
|
+
for d in (km._PERSONA_RETIRED, km._PERSONA_RESERVED, km._PERSONA_WRITE_ONLY):
|
|
6013
|
+
d.clear()
|
|
6014
|
+
|
|
6015
|
+
def tearDown(self):
|
|
6016
|
+
for d, keep in zip((km._PERSONA_RETIRED, km._PERSONA_RESERVED, km._PERSONA_WRITE_ONLY), self._saved):
|
|
6017
|
+
d.clear()
|
|
6018
|
+
d.update(keep)
|
|
6019
|
+
|
|
6020
|
+
def _target(self, after=7200, cap=3, cursor=10, em=None):
|
|
6021
|
+
em = em or self.E2E.RecordingEmitter()
|
|
6022
|
+
t = self.E2E()._target(cursor=cursor, emitter=em)
|
|
6023
|
+
t.args.still_unread_after, t.args.still_unread_max = after, cap
|
|
6024
|
+
return t, em
|
|
6025
|
+
|
|
6026
|
+
def _alerts(self, em):
|
|
6027
|
+
return [f for e, f in em.events if e == "still_unread"]
|
|
6028
|
+
|
|
6029
|
+
ITEMS = [{"id": 5, "from": "river", "read": False, "created": "2026-09-24 00:00:00"},
|
|
6030
|
+
{"id": 6, "from": "river", "read": True, "created": "2026-09-24 00:00:00"}, # already read
|
|
6031
|
+
{"id": 11, "from": "river", "read": False, "created": "2026-09-24 00:00:00"}] # not yet notified
|
|
6032
|
+
|
|
6033
|
+
def test_primes_on_start_then_reminds_once_per_window_up_to_the_cap(self):
|
|
6034
|
+
t, em = self._target()
|
|
6035
|
+
now = self.T0 + 3 * self.H
|
|
6036
|
+
self.assertEqual(t._resurface_still_unread(self.ITEMS, now), [], "a restart must not burst")
|
|
6037
|
+
self.assertEqual(t._resurface_still_unread(self.ITEMS, now + 60), [], "not before a full window")
|
|
6038
|
+
seen = [t._resurface_still_unread(self.ITEMS, now + k * 7200) for k in range(1, 6)]
|
|
6039
|
+
self.assertEqual(seen, [[5], [5], [5], [], []], "once per window, capped at 3")
|
|
6040
|
+
self.assertEqual(len(self._alerts(em)), 3)
|
|
6041
|
+
self.assertEqual(self._alerts(em)[0]["ids"], [5])
|
|
6042
|
+
self.assertEqual(self._alerts(em)[0]["senders"], ["river"])
|
|
6043
|
+
|
|
6044
|
+
def test_young_mail_is_not_reminded(self):
|
|
6045
|
+
t, em = self._target()
|
|
6046
|
+
t.still_unread_primed = True
|
|
6047
|
+
self.assertEqual(t._resurface_still_unread(self.ITEMS, self.T0 + 3000), [])
|
|
6048
|
+
|
|
6049
|
+
def test_several_due_messages_are_ONE_event(self):
|
|
6050
|
+
items = [dict(self.ITEMS[0]), dict(self.ITEMS[0], id=7, **{"from": "assay"})]
|
|
6051
|
+
t, em = self._target()
|
|
6052
|
+
t.still_unread_primed = True
|
|
6053
|
+
self.assertEqual(t._resurface_still_unread(items, self.T0 + 3 * self.H), [5, 7])
|
|
6054
|
+
self.assertEqual(len(self._alerts(em)), 1)
|
|
6055
|
+
self.assertEqual(self._alerts(em)[0]["senders"], ["assay", "river"])
|
|
6056
|
+
|
|
6057
|
+
def test_read_mail_leaves_the_ledger(self):
|
|
6058
|
+
t, _ = self._target()
|
|
6059
|
+
t.still_unread_primed = True
|
|
6060
|
+
t._resurface_still_unread(self.ITEMS, self.T0 + 3 * self.H)
|
|
6061
|
+
self.assertIn(5, t.still_unread_seen)
|
|
6062
|
+
t._resurface_still_unread([dict(self.ITEMS[0], read=True)], self.T0 + 4 * self.H)
|
|
6063
|
+
self.assertNotIn(5, t.still_unread_seen)
|
|
6064
|
+
|
|
6065
|
+
def test_a_failed_emit_is_retried_not_counted(self):
|
|
6066
|
+
class Refusing(self.E2E.RecordingEmitter):
|
|
6067
|
+
def lifecycle(self, event, **f):
|
|
6068
|
+
self.events.append((event, f))
|
|
6069
|
+
return False
|
|
6070
|
+
t, em = self._target(em=Refusing())
|
|
6071
|
+
t.still_unread_primed = True
|
|
6072
|
+
now = self.T0 + 3 * self.H
|
|
6073
|
+
t._resurface_still_unread(self.ITEMS, now)
|
|
6074
|
+
self.assertEqual(t._resurface_still_unread(self.ITEMS, now + 1), [5], "undelivered = not reminded yet")
|
|
6075
|
+
|
|
6076
|
+
def test_debris_and_write_only_inboxes_are_never_reminded(self):
|
|
6077
|
+
for flag in (km._PERSONA_RETIRED, km._PERSONA_RESERVED, km._PERSONA_WRITE_ONLY):
|
|
6078
|
+
with self.subTest(flag=flag):
|
|
6079
|
+
self.setUp()
|
|
6080
|
+
flag["argus"] = True
|
|
6081
|
+
t, em = self._target()
|
|
6082
|
+
t.still_unread_primed = True
|
|
6083
|
+
self.assertEqual(t._resurface_still_unread(self.ITEMS, self.T0 + 9 * self.H), [])
|
|
6084
|
+
self.assertEqual(self._alerts(em), [])
|
|
6085
|
+
|
|
6086
|
+
def test_zero_disables(self):
|
|
6087
|
+
t, em = self._target(after=0)
|
|
6088
|
+
t.still_unread_primed = True
|
|
6089
|
+
self.assertEqual(t._resurface_still_unread(self.ITEMS, self.T0 + 99 * self.H), [])
|
|
6090
|
+
|
|
6091
|
+
def test_it_is_wired_into_the_full_poll(self):
|
|
6092
|
+
t, em = self._target(after=1, cursor=10)
|
|
6093
|
+
t.still_unread_primed = True
|
|
6094
|
+
old = [{"id": 5, "from": "river", "read": False, "created": "2020-01-01 00:00:00"}]
|
|
6095
|
+
self.E2E()._run(t, self.E2E()._fetch(old, 0))
|
|
6096
|
+
alerts = self._alerts(em)
|
|
6097
|
+
self.assertEqual(len(alerts), 1)
|
|
6098
|
+
self.assertEqual(alerts[0]["ids"], [5])
|
|
6099
|
+
self.assertEqual(t.cursor, 10, "a reminder never moves the cursor")
|
|
6100
|
+
self.assertEqual(em.new_ids, [], "and is never re-emitted as `new`")
|
|
6101
|
+
|
|
6102
|
+
def test_created_parsing(self):
|
|
6103
|
+
self.assertEqual(km._created_epoch("2026-09-24 00:00:00"), km._created_epoch("2026-09-24T00:00:00Z"))
|
|
6104
|
+
self.assertEqual(km._created_epoch("2026-09-24T02:00:00+02:00"), self.T0)
|
|
6105
|
+
for junk in (None, "", "yesterday", 17):
|
|
6106
|
+
self.assertIsNone(km._created_epoch(junk))
|
|
6107
|
+
|
|
6108
|
+
def test_flags_are_validated(self):
|
|
6109
|
+
def err(argv):
|
|
6110
|
+
try:
|
|
6111
|
+
km.validate_args(km.build_parser().parse_args(argv))
|
|
6112
|
+
except km.FatalConfig as e:
|
|
6113
|
+
return str(e)
|
|
6114
|
+
self.assertIn(">= 0", err(["--persona", "a", "--still-unread-after", "-1"]))
|
|
6115
|
+
self.assertIn(">= 1", err(["--persona", "a", "--still-unread-max", "0"]))
|
|
6116
|
+
self.assertIsNone(err(["--persona", "a", "--still-unread-after", "0"]))
|