pi-sleep-agent 0.8.16 → 0.8.17
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/README.md +7 -1
- package/docs/EVIDENCE.md +29 -0
- package/package.json +1 -1
- package/sleepkit/cli.py +46 -6
- package/sleepkit/store.py +50 -7
package/README.md
CHANGED
|
@@ -38,7 +38,13 @@ Sleep adds a reviewable memory cycle to nine selectable coding-agent targets. It
|
|
|
38
38
|
the thing it describes actually happened, and it is written **only when the record
|
|
39
39
|
states a date** (a date equal to the capture day is not a second clock). An empty
|
|
40
40
|
`event_at` means the record does not say, never a guess, so `show` can answer
|
|
41
|
-
"when was this true" without inventing an event time.
|
|
41
|
+
"when was this true" without inventing an event time. Both clocks are read, not just
|
|
42
|
+
stored: when `doctor` flags a contradicting pair it names the older side as the claim
|
|
43
|
+
on the pair's `event_at` (falling back to `ts` when neither record states a date), so
|
|
44
|
+
a fact you file today about a state that was already superseded is not handed back as
|
|
45
|
+
the newer claim; injection appends `(described a state Nd old)` when the two clocks
|
|
46
|
+
differ, and the adjudicator model is shown both, named as older or newer than the
|
|
47
|
+
capture.
|
|
42
48
|
- **Tagged records.** Consolidation writes 1-4 lowercase topic tags per record (`deploy|aws`),
|
|
43
49
|
normalized and capped in `store`, and `inject --topic` selects on them. A tag is a
|
|
44
50
|
hint a model proposed, so a wrong tag costs a missing filter hit, never a wrong fact.
|
package/docs/EVIDENCE.md
CHANGED
|
@@ -467,3 +467,32 @@ used `===PROPOSAL===` only as a closing marker. The parser discarded everything
|
|
|
467
467
|
marker. `sleepkit.consolidate.split_blocks()` now preserves a leading contract-shaped proposal while
|
|
468
468
|
still discarding ordinary preamble, pinned by
|
|
469
469
|
`test_closing_proposal_marker_preserves_leading_proposal`.
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
## 2026-11-03: world-time ordering for contradicting records
|
|
473
|
+
|
|
474
|
+
`doctor` named the older side of a contradicting pair by capture time (`ts`), which is the
|
|
475
|
+
store's clock and not the claim's. An agent that files an old fact today - a document quote
|
|
476
|
+
saying the deploy host is X, recorded yesterday, while a person corrected it in the store a week
|
|
477
|
+
ago - therefore looked like the *newer* claim, and the suggested command
|
|
478
|
+
(`supersede <older> <newer>`) pointed the wrong way.
|
|
479
|
+
|
|
480
|
+
The pair now carries both clocks as `(ts, event_at)`, in the T1 shortlist and in
|
|
481
|
+
`permanent_records`, and one axis decides each comparison: `event_at` when both records state a
|
|
482
|
+
date, the `ts` pair otherwise, the id when neither does. Each comparison runs on a single axis
|
|
483
|
+
because the first version preferred each record's own clock (`ta or ea`), which is just `ts`
|
|
484
|
+
again for any record carrying both, and it reproduced the inverted advice the change exists to
|
|
485
|
+
fix. `inject` appends `(described a state Nd old)` only when the two clocks differ, and the
|
|
486
|
+
adjudicator prompt now shows both clocks with their relation
|
|
487
|
+
(`event_at=2026-10-01 (older state, recorded 2026-11-02)`).
|
|
488
|
+
|
|
489
|
+
Pinned by `test_a_late_note_about_an_old_state_is_named_the_claim_not_the_correction`,
|
|
490
|
+
`test_without_a_stated_date_the_capture_order_still_decides`,
|
|
491
|
+
`test_the_adjudicator_is_shown_both_clocks_and_their_relation` (all in `tests/test_cli.py`,
|
|
492
|
+
crossing a process boundary with a prompt-recording fake model),
|
|
493
|
+
`test_permanent_records_carry_both_clocks_not_a_bare_ts` and
|
|
494
|
+
`test_ordering_prefers_the_stated_date_and_falls_back_to_capture_time` (`tests/test_core.py`).
|
|
495
|
+
|
|
496
|
+
Not changed, and named here so the leftover is not mistaken for coverage: `candidate_pairs()`
|
|
497
|
+
still orders by `ts` and still makes one model call per pair, and `cmd_doctor` does not call it.
|
|
498
|
+
It is a duplicate of the ordering rule with a per-pair cost, left alone deliberately.
|
package/package.json
CHANGED
package/sleepkit/cli.py
CHANGED
|
@@ -208,10 +208,16 @@ def cmd_prune(a) -> int:
|
|
|
208
208
|
|
|
209
209
|
|
|
210
210
|
def _doctor_shortlist() -> list:
|
|
211
|
-
"""(id, body, ts) for
|
|
211
|
+
"""(id, body, (ts, event_at)) for provisional records, the input to candidate_pairs.
|
|
212
|
+
|
|
213
|
+
Both clocks travel: `ts` is when the store first held the claim, `event_at` is when
|
|
214
|
+
the record says the described thing was true. Deciding which of two records is the
|
|
215
|
+
older claim is a world-time question, and a session that files an old fact today
|
|
216
|
+
makes ts alone pick the wrong side."""
|
|
212
217
|
out = []
|
|
213
218
|
for c in store.list_candidates(status="provisional", with_body=True):
|
|
214
|
-
out.append((c["id"], c.get("_body", "") or "",
|
|
219
|
+
out.append((c["id"], c.get("_body", "") or "",
|
|
220
|
+
(str(c.get("ts", "")), str(c.get("event_at", "")))))
|
|
215
221
|
return out
|
|
216
222
|
|
|
217
223
|
|
|
@@ -248,8 +254,18 @@ def _llm_contradictions(pairs: list, budget: float, model: str | None,
|
|
|
248
254
|
lines.append("Pair %d:" % i)
|
|
249
255
|
for cid in (older, newer):
|
|
250
256
|
meta, body = seen.get(cid, ({}, ""))
|
|
251
|
-
|
|
252
|
-
|
|
257
|
+
# Both clocks and the relation between them: a record learned long after the
|
|
258
|
+
# state it describes is the late note here, and a model shown only `ts` would
|
|
259
|
+
# read it as the newer claim and propose superseding the true memory.
|
|
260
|
+
ts = str(meta.get("ts", "?"))
|
|
261
|
+
event_at = str(meta.get("event_at", "") or "")
|
|
262
|
+
if event_at and event_at[:10] != ts[:10]:
|
|
263
|
+
when = "ts=%s event_at=%s (%s state, recorded %s)" % (
|
|
264
|
+
ts, event_at, "older" if event_at < ts else "newer", ts[:10])
|
|
265
|
+
else:
|
|
266
|
+
when = "ts=%s event_at=%s" % (ts, event_at or "unknown")
|
|
267
|
+
lines.append(" id=%s %s body=%s" % (cid, when,
|
|
268
|
+
(body or "").replace("\n", " ").strip()))
|
|
253
269
|
if tier in ("t2", "both"):
|
|
254
270
|
user = ("Memory records, grouped into candidate pairs. Some are unreviewed "
|
|
255
271
|
"provisional candidates; some are permanent memories a human already "
|
|
@@ -321,7 +337,7 @@ def _llm_contradictions(pairs: list, budget: float, model: str | None,
|
|
|
321
337
|
|
|
322
338
|
|
|
323
339
|
def _doctor_memory_shortlist(memory_dir: str | None = None) -> list:
|
|
324
|
-
"""(id, body, ts) for
|
|
340
|
+
"""(id, body, (ts, event_at)) for active permanent T2 records, same two clocks as T1."""
|
|
325
341
|
return store.permanent_records(memory_dir)
|
|
326
342
|
|
|
327
343
|
|
|
@@ -329,7 +345,8 @@ def _memory_records(memory_dir: str | None = None) -> dict:
|
|
|
329
345
|
"""id -> (meta, body) for active permanent records, the lookup the adjudicator needs."""
|
|
330
346
|
out = {}
|
|
331
347
|
for cid, body, ts in store.permanent_records(memory_dir):
|
|
332
|
-
|
|
348
|
+
ts, event_at = ts if isinstance(ts, (tuple, list)) else (ts, "")
|
|
349
|
+
out[cid] = ({"id": cid, "ts": ts, "event_at": event_at}, body)
|
|
333
350
|
return out
|
|
334
351
|
|
|
335
352
|
|
|
@@ -491,6 +508,23 @@ def _age_label(ts: str):
|
|
|
491
508
|
return "%dd ago" % int(hours // 24)
|
|
492
509
|
|
|
493
510
|
|
|
511
|
+
def _world_age_label(ts: str, event_at: str):
|
|
512
|
+
"""Age of the state a record describes, in days, when that differs from `ts`.
|
|
513
|
+
|
|
514
|
+
Two clocks, and the gap between them is the point: `ts` says when this store first
|
|
515
|
+
held the claim, `event_at` says when the record itself says the thing was true. A
|
|
516
|
+
fact read out of a six-month-old document yesterday carries both, and a model told
|
|
517
|
+
only "recorded 1d ago" reads it as current. Returns None when the two agree to the
|
|
518
|
+
day, because saying the same thing twice is noise, and None on an unparseable value
|
|
519
|
+
rather than a guessed number.
|
|
520
|
+
"""
|
|
521
|
+
a = store._hours_since(ts) if ts else None
|
|
522
|
+
b = store._hours_since(event_at) if event_at else None
|
|
523
|
+
if a is None or b is None or int(a // 24) == int(b // 24):
|
|
524
|
+
return None
|
|
525
|
+
return int(b // 24)
|
|
526
|
+
|
|
527
|
+
|
|
494
528
|
def _inject_rank(records: list, query: str) -> list:
|
|
495
529
|
"""Order records by overlap with ``query``, newest first as the tie-break.
|
|
496
530
|
|
|
@@ -570,6 +604,12 @@ def cmd_inject(a) -> int:
|
|
|
570
604
|
age = _age_label(c.get("ts", ""))
|
|
571
605
|
if age:
|
|
572
606
|
line += " (recorded %s)" % age
|
|
607
|
+
# Separately, and only when it differs: how old the state the record describes
|
|
608
|
+
# is. "recorded 1d ago, true 180d ago" is a late note about an old world, and a
|
|
609
|
+
# reader that only sees the first half takes it for current.
|
|
610
|
+
world = _world_age_label(c.get("ts", ""), c.get("event_at", ""))
|
|
611
|
+
if world is not None:
|
|
612
|
+
line += " (described a state %dd old)" % world
|
|
573
613
|
recs.append(line)
|
|
574
614
|
served.append(c.get("id", ""))
|
|
575
615
|
if not recs:
|
package/sleepkit/store.py
CHANGED
|
@@ -720,7 +720,12 @@ def permanent_records(memory_dir: str | None = None) -> list:
|
|
|
720
720
|
if meta.get("status") == "retracted":
|
|
721
721
|
continue
|
|
722
722
|
ref = str(meta.get("id") or name[:-3]).strip()
|
|
723
|
-
|
|
723
|
+
# The recorded claim time, not the promotion date: a memory written down long after
|
|
724
|
+
# the fact is a late note about an old state. Carried as (claim_time, event_at) so
|
|
725
|
+
# _older_newer can read the same two clocks the T1 shortlist carries.
|
|
726
|
+
out.append((ref, body or "",
|
|
727
|
+
(str(meta.get("ts") or meta.get("promoted_at") or ""),
|
|
728
|
+
str(meta.get("event_at") or ""))))
|
|
724
729
|
return out
|
|
725
730
|
|
|
726
731
|
|
|
@@ -921,12 +926,43 @@ def candidate_pairs(recs: list, limit: int = CONTRADICTION_MAX_PAIRS) -> list:
|
|
|
921
926
|
return [(o, n) for _s, o, n in scored[:limit]]
|
|
922
927
|
|
|
923
928
|
|
|
929
|
+
def _clock(entry) -> tuple[str, str]:
|
|
930
|
+
"""Accept either the old bare-ts map value or this module's (ts, event_at) pair."""
|
|
931
|
+
if isinstance(entry, (tuple, list)):
|
|
932
|
+
ts = str(entry[0] or "") if len(entry) > 0 else ""
|
|
933
|
+
ev = str(entry[1] or "") if len(entry) > 1 else ""
|
|
934
|
+
return ts, ev
|
|
935
|
+
return str(entry or ""), ""
|
|
936
|
+
|
|
937
|
+
|
|
924
938
|
def _older_newer(a: str, b: str, ts_by_id: dict) -> tuple[str, str]:
|
|
925
|
-
"""Order two candidate ids by
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
939
|
+
"""Order two candidate ids by the claim's own time, oldest first.
|
|
940
|
+
|
|
941
|
+
Which side is the claim and which is the correction is a statement about the world,
|
|
942
|
+
not about this store, so the ordering reads both clocks the record carries:
|
|
943
|
+
|
|
944
|
+
- ts is when the store first held the claim, event_at is when the record says the
|
|
945
|
+
described thing was true. A session can file an old fact today, so ts alone
|
|
946
|
+
would name a document quote recorded this morning as "the newer claim" and hand
|
|
947
|
+
back a supersede command pointing the wrong way.
|
|
948
|
+
- event_at wins whenever the pair can be compared on it at all, for BOTH sides.
|
|
949
|
+
Mixing the clocks (one side's ts against the other's event_at) compares two
|
|
950
|
+
different axes and just relocates the bug: the documented late note carries both,
|
|
951
|
+
so its ts would still be what the comparison read.
|
|
952
|
+
- With no stated date on either side, or on only one, the capture ts pair decides
|
|
953
|
+
and, when those tie or are missing, the id does. A pair is always returned, so
|
|
954
|
+
`supersede <older> <newer>` is always a runnable command.
|
|
955
|
+
|
|
956
|
+
Values may be a bare timestamp (older callers) or a (ts, event_at) pair.
|
|
957
|
+
"""
|
|
958
|
+
ta, ea = _clock(ts_by_id.get(a, ""))
|
|
959
|
+
tb, eb = _clock(ts_by_id.get(b, ""))
|
|
960
|
+
# One axis per comparison: event_at when both records state one, capture ts otherwise.
|
|
961
|
+
ca, cb = (ea, eb) if (ea and eb) else (ta, tb)
|
|
962
|
+
if ca and cb and ca != cb:
|
|
963
|
+
return (a, b) if ca < cb else (b, a)
|
|
964
|
+
if ca != cb:
|
|
965
|
+
return (a, b) if not ca else (b, a)
|
|
930
966
|
return (a, b) if a <= b else (b, a)
|
|
931
967
|
|
|
932
968
|
|
|
@@ -974,7 +1010,12 @@ def doctor(memory_dir: str | None = None, targets: list[str] | None = None,
|
|
|
974
1010
|
"value": needle})
|
|
975
1011
|
pool_records = list_candidates(with_body=True)
|
|
976
1012
|
pool = [(c["id"], c.get("_body", "")) for c in pool_records]
|
|
977
|
-
|
|
1013
|
+
# Two clocks per record: ts is when this store first held the claim, event_at is when
|
|
1014
|
+
# the record itself says the described thing was true. A session can learn an old fact
|
|
1015
|
+
# today (ts new, event_at old), so "which side is the older claim" is a world-time
|
|
1016
|
+
# question and cannot be answered from ts alone. The pair is (ts, event_at) and the
|
|
1017
|
+
# ordering rule lives in _older_newer.
|
|
1018
|
+
pool_ts = {c["id"]: (str(c.get("ts", "")), str(c.get("event_at", ""))) for c in pool_records}
|
|
978
1019
|
for i in range(len(pool)):
|
|
979
1020
|
for j in range(i + 1, len(pool)):
|
|
980
1021
|
sim = similarity(pool[i][1], pool[j][1])
|
|
@@ -990,6 +1031,8 @@ def doctor(memory_dir: str | None = None, targets: list[str] | None = None,
|
|
|
990
1031
|
if mi != mj:
|
|
991
1032
|
# Name the older/newer side so a person does not diff two timestamps by
|
|
992
1033
|
# eye: the older record is the claim, the newer one is the correction.
|
|
1034
|
+
# "Older" is world time (_older_newer), so a record learned late about an
|
|
1035
|
+
# old state is still named as the claim and not as the fix.
|
|
993
1036
|
# The suggestion is a command to RUN, never one this code runs -
|
|
994
1037
|
# superseding on a keyword match could kill a true memory, so the gate
|
|
995
1038
|
# stays human.
|