pi-sleep-agent 0.8.3 → 0.8.4

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 CHANGED
@@ -275,7 +275,7 @@ A dream pass performs four steps:
275
275
 
276
276
  1. **Mine.** Find instructions you repeated across separate sessions in the same project. This step is deterministic and makes no model call.
277
277
  2. **Consolidate.** When the sleep gate passes, ask the configured model to turn recent T0 observations into provisional T1 candidates.
278
- 3. **Hygiene.** Run the read-only `doctor` scan and fold any findings (duplicate headings, near-duplicate candidates, records parked in quarantine awaiting review, or stale values when you pass `--stale <value>`) into the night's report.
278
+ 3. **Hygiene.** Run the read-only `doctor` scan and fold any findings (duplicate headings, near-duplicate or contradicting candidates, records parked in quarantine awaiting review, or stale values when you pass `--stale <value>`) into the night's report.
279
279
  4. **Replay.** When replay is due, run selected tasks with provisional memory off and on, then write a comparison report.
280
280
 
281
281
  Every result stays reviewable. Candidates remain in T1 until you explicitly run `promote`.
@@ -319,8 +319,9 @@ Run the two dream components separately when you want more control:
319
319
  | `./sleep.py replay --run --limit 3` | Compare selected tasks with memory off and on |
320
320
  | `./sleep.py mine --dry-run` | Find preferences repeated across sessions |
321
321
  | `./sleep.py nightly --dry-run` | Preview the unattended nightly workflow |
322
- | `./sleep.py doctor` | Find duplicate or overlapping memory records, flag provisional candidates not rediscovered for 4+ weeks, and report records parked in quarantine awaiting a human (report only, never dropped or un-parked) |
322
+ | `./sleep.py doctor` | Find duplicate or overlapping memory records, flag contradicting candidates (same subject, one side carries a correction marker), flag provisional candidates not rediscovered for 4+ weeks, and report records parked in quarantine awaiting a human (report only, never dropped, merged or un-parked) |
323
323
  | `./sleep.py doctor --stale <value>` | Show which approved records still hold a stale value (e.g. a changed URL) |
324
+ | `./sleep.py supersede <old> <new>` | Mark `<old>` invalid as of now and `<new>` valid as of now (`valid_until` / `valid_from`), so the window a memory was true is readable from the files |
324
325
  | `./sleep.py inject --project "$PWD"` | Print provisional context for the current project, newest first, each line dated |
325
326
  | `./sleep.py inject --project "$PWD" --query "..."` | Same, but rank records by overlap with the live request so the most relevant survive `--max` |
326
327
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-sleep-agent",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
4
4
  "description": "A reviewable sleep and dream cycle for Pi agent memory.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/sleepkit/store.py CHANGED
@@ -47,7 +47,8 @@ IDX_END = "<!-- sleep:end -->"
47
47
  # ------------------------------------------------------------- frontmatter --
48
48
  def emit(record: dict, body: str = "") -> str:
49
49
  order = ["id", "ts", "source", "trust", "kind", "status", "session", "cwd",
50
- "tags", "evidence", "supersedes", "superseded_by", "redacted", "notes"]
50
+ "tags", "evidence", "supersedes", "superseded_by",
51
+ "valid_from", "valid_until", "redacted", "notes"]
51
52
  # Known fields first in a stable order, then anything else the record carries.
52
53
  # Dropping the remainder silently used to eat the review audit trail: `reviewed`
53
54
  # and `promoted_to`/`promoted_at` are written by set_status and are not in `order`,
@@ -174,6 +175,16 @@ def buffer_counts() -> dict:
174
175
  # already judged and rejected, so colliding with it should refuse the write.
175
176
  REFUSED_DUP_THRESHOLD = 0.42
176
177
 
178
+ # A contradiction is not a synonym for "similar": near-duplicates restate the same
179
+ # fact, contradicting records assert opposite things about the same subject. Only
180
+ # pairs that share most of their wording AND carry an explicit correction marker on
181
+ # one side are reported, so the doctor stays a signal rather than a guess.
182
+ CONTRADICTION_OVERLAP = 0.5
183
+ _CORRECTION = re.compile(
184
+ r"\b(?:no longer|not any ?more|instead of|rather than|replaced|deprecated|"
185
+ r"obsolete|stopped? (?:using|working)|used to|previously|but now|do(?:es)? not|"
186
+ r"don't|doesn't|isn't|aren't|wasn't|weren't)\b", re.I)
187
+
177
188
  _WORD = re.compile(r"[a-z0-9_]+")
178
189
 
179
190
 
@@ -426,6 +437,9 @@ def promote(cid: str, memory_dir: str | None = None, dry_run: bool = False) -> t
426
437
  out_meta = {k: v for k, v in meta.items() if not k.startswith("_")}
427
438
  out_meta["status"] = "promoted"
428
439
  out_meta["promoted_at"] = when
440
+ # The permanent copy's validity starts when the human approved it: a memory that
441
+ # outlives the record it came from needs its own start date, not the capture ts.
442
+ out_meta.setdefault("valid_from", when)
429
443
  with open(dest, "w", encoding="utf-8") as fh:
430
444
  fh.write(emit(out_meta, body))
431
445
  ok, why = append_index_line(mdir, line)
@@ -552,8 +566,17 @@ def demote(cid: str, memory_dir: str | None = None, dry_run: bool = False,
552
566
  + (" (T2 default not found)" if not t2_ok else ""))
553
567
 
554
568
  def supersede(old_id: str, new_id: str) -> bool:
555
- return (set_status(old_id, "superseded", {"superseded_by": new_id})
556
- and set_status(new_id, "provisional", {"supersedes": old_id}))
569
+ """Mark old_id invalid as of now and new_id valid as of now.
570
+
571
+ A bare superseded_by pointer says *which* record replaced this one; it does not
572
+ say *when* the old value stopped being true. That window is what a temporal
573
+ question actually asks ("what did we believe before the change?"), so both ends
574
+ are written here. The stamp is the review clock set_status already writes, so a
575
+ supersede and a refusal carry the same time vocabulary.
576
+ """
577
+ now = paths.now()
578
+ return (set_status(old_id, "superseded", {"superseded_by": new_id, "valid_until": now})
579
+ and set_status(new_id, "provisional", {"supersedes": old_id, "valid_from": now}))
557
580
 
558
581
 
559
582
  # ------------------------------------------------------------ pruning -------
@@ -626,6 +649,15 @@ def doctor(memory_dir: str | None = None, targets: list[str] | None = None,
626
649
  if sim >= 0.75:
627
650
  out.append({"issue": "near-duplicate-candidates",
628
651
  "pair": [pool[i][0], pool[j][0]], "similarity": round(sim, 2)})
652
+ # Overlapping wording with a correction marker on exactly one side: the two
653
+ # records are about the same thing but disagree, which is the state a person
654
+ # has to resolve (refuse one, or supersede). Report-only; nothing is merged,
655
+ # reordered or dropped, and a marker on BOTH sides is only a shared theme.
656
+ elif sim >= CONTRADICTION_OVERLAP:
657
+ mi, mj = bool(_CORRECTION.search(pool[i][1])), bool(_CORRECTION.search(pool[j][1]))
658
+ if mi != mj:
659
+ out.append({"issue": "contradicting-candidates",
660
+ "pair": [pool[i][0], pool[j][0]], "similarity": round(sim, 2)})
629
661
  cutoff_hours = STALE_CANDIDATE_WEEKS * 7 * 24
630
662
  for c in list_candidates():
631
663
  if c.get("status") != "provisional":