pi-sleep-agent 0.8.9 → 0.8.10

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
@@ -29,7 +29,7 @@ Sleep adds a reviewable memory cycle to nine selectable coding-agent targets. It
29
29
  - **Budgeted consolidation.** Sleep runs only after the record and time gates pass.
30
30
  - **Review before permanence.** New memories stay provisional until you promote or refuse them.
31
31
  - **Nightly dream cycle.** Mine repeated preferences, consolidate recent observations, and measure memory effects while you are away.
32
- - **Measured replay.** Run the same task with memory off and on before deciding whether a memory helps.
32
+ - **Measured replay.** Run the same task with memory off and on before deciding whether a memory helps. Each completed pass leaves a one-line quality summary (`helps / hurts / ties`) in `status` and in the nightly report, so the question stays answerable between passes; a pass whose two arms ran the same prompt says it measured nothing instead of reporting zeros.
33
33
  - **Repeated preference detection.** `mine` finds instructions you gave in multiple sessions without a model call.
34
34
  - **Project isolation.** A project's provisional memory is injected only into that project.
35
35
  - **Reviewable permanence.** Each approved memory in your index carries its review date and source, so you can tell when a saved instruction was pinned.
@@ -317,6 +317,7 @@ Run the two dream components separately when you want more control:
317
317
  | `./sleep.py demote <id> --note "..."` | Un-approve a promoted memory: mark the approved record as retracted (kept on record, not deleted) and reopen the candidate as refused. Also accepts a permanent record's filename slug or the `id:` it carries, so a memory whose candidate record is gone is still reversible |
318
318
  | `./sleep.py refuse <id> --note "..."` | Record that a candidate is incorrect |
319
319
  | `./sleep.py replay --run --limit 3` | Compare selected tasks with memory off and on |
320
+ | `./sleep.py status -v` | ... and the last measured memory quality (`3 helps / 1 hurts / 4 ties from 8 samples`, or "no replay measurement has run yet") |
320
321
  | `./sleep.py mine --dry-run` | Find preferences repeated across sessions |
321
322
  | `./sleep.py nightly --dry-run` | Preview the unattended nightly workflow |
322
323
  | `./sleep.py doctor` | Find duplicate or overlapping memory records, flag contradicting candidates (same subject, one side carries a correction marker) and print the `supersede <older> <newer>` command to run, flag provisional candidates not rediscovered for 4+ weeks, flag supersede pointers that name a record no longer in the store, and report records parked in quarantine awaiting a human (report only: it never supersedes, drops, merges or un-parks anything itself) |
@@ -404,7 +405,7 @@ candidates/ provisional T1 records
404
405
  reports/ replay reports
405
406
  logs/ hook and nightly logs
406
407
  .quarantine/ rejected unsafe input
407
- state.json sleep and replay timestamps
408
+ state.json sleep and replay timestamps, and the last measured memory-quality summary
408
409
  env optional scheduled-run environment
409
410
  ```
410
411
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-sleep-agent",
3
- "version": "0.8.9",
3
+ "version": "0.8.10",
4
4
  "description": "A reviewable sleep and dream cycle for Pi agent memory.",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/sleepkit/cli.py CHANGED
@@ -66,6 +66,10 @@ def cmd_status(a) -> int:
66
66
  except OSError:
67
67
  permanent = []
68
68
  _p("sleep memory: T0=disposable captures, T1=provisional awaiting review, T2=permanent (promote-only)")
69
+ try:
70
+ _p(replay_mod.quality_line())
71
+ except Exception:
72
+ pass
69
73
  _p("T0 buffer %d records / %d files / %d bytes (captured while you worked)" % (bc["records"], bc["files"], bc["bytes"]))
70
74
  _p("T1 candidates %d provisional, %d refused, %d total (distilled, shown as unverified context)" % (len(prov), len(ref), len(cands)))
71
75
  _p(" quarantine %d parked (needs human eyes) (held out until you review)" % len(q))
@@ -430,7 +434,14 @@ def cmd_nightly(a) -> int:
430
434
  limit=a.replay_limit,
431
435
  interval_hours=a.replay_interval,
432
436
  dry_run=a.dry_run)
437
+ # The report is machine-read (launchd tails it, tests parse it), so stdout stays a
438
+ # single JSON document. The human-readable line rides inside it and is echoed as
439
+ # PLAIN TEXT only on a terminal, where a person is the one reading the night.
440
+ qline = rep["replay"].get("quality_line") or replay_mod.quality_line()
441
+ rep["replay"]["quality_line"] = qline
433
442
  _p(json.dumps(rep, indent=2, sort_keys=True, default=str))
443
+ if sys.stdout.isatty():
444
+ _p(qline)
434
445
  # "ran" only means the gate let the pass through. If the model call itself failed,
435
446
  # the night produced nothing and must not report success to launchd.
436
447
  slept = rep["sleep"].get("action") in ("skipped", "would-run") or (
@@ -283,6 +283,49 @@ def replay_due(interval_hours: float) -> tuple:
283
283
  return False, "%.1f of %.1f h since the last pass" % (elapsed, interval_hours)
284
284
 
285
285
 
286
+ def record_quality(rep: dict) -> dict:
287
+ """Persist the memory-quality summary of a completed replay pass.
288
+
289
+ The dated report file holds the detail, but a skipped night leaves no trace at all,
290
+ so "is my memory actually helping?" had no answer between runs. A small rolling
291
+ summary in state.json keeps the last real measurement readable from `status` and
292
+ the nightly report without parsing report files.
293
+ """
294
+ tally = rep.get("verdict_tally") or {}
295
+ summary = {"ran": paths.now(), "tally": tally,
296
+ "helpful": tally.get("helps", 0),
297
+ "harmed": tally.get("hurts", 0),
298
+ "tie": tally.get("tie", 0),
299
+ "samples": rep.get("samples", 0),
300
+ "answered": rep.get("answered", 0),
301
+ "treatment_delivered": bool(rep.get("treatment_delivered"))}
302
+ paths.write_state({"replay_quality": summary})
303
+ return summary
304
+
305
+
306
+ def quality_line(state: dict | None = None) -> str:
307
+ """One line for the nightly report: what the last real measurement said.
308
+
309
+ A skip is not a quality signal, so the line states the last measurement that
310
+ actually happened and how long ago, instead of pretending the skip measured
311
+ anything. Never-run is reported as such rather than as a zero score.
312
+ """
313
+ from . import consolidate # lazy: hours_since lives there
314
+ st = state if state is not None else paths.read_state()
315
+ q = st.get("replay_quality") or {}
316
+ if not q or not q.get("ran"):
317
+ return "memory quality: no replay measurement has run yet"
318
+ age = consolidate.hours_since(q.get("ran"))
319
+ when = "just now" if age is None or age < 1 else (
320
+ "%.0fh ago" % age if age < 48 else "%.0fd ago" % (age / 24.0))
321
+ if not q.get("treatment_delivered"):
322
+ return ("memory quality: last pass (%s) delivered no treatment, so it measured "
323
+ "nothing" % when)
324
+ return ("memory quality: %d helps / %d hurts / %d ties from %d samples (last pass %s)"
325
+ % (q.get("helpful", 0), q.get("harmed", 0), q.get("tie", 0),
326
+ q.get("samples", 0), when))
327
+
328
+
286
329
  def mark_replayed() -> str:
287
330
  """Stamp last_replay so the next nightly pass waits out its interval."""
288
331
  ts = paths.now()
@@ -302,9 +345,10 @@ def nightly(tasks_path: str = DEFAULT_TASKS, model: str | None = None, budget: f
302
345
  """
303
346
  due, why = replay_due(interval_hours)
304
347
  if dry_run:
305
- return {"skipped": True, "reason": "dry run", "due": due, "detail": why}
348
+ return {"skipped": True, "reason": "dry run", "due": due, "detail": why,
349
+ "quality_line": quality_line()}
306
350
  if not due:
307
- return {"skipped": True, "reason": why}
351
+ return {"skipped": True, "reason": why, "quality_line": quality_line()}
308
352
  try:
309
353
  rep = run_suite(tasks_path=tasks_path, limit=limit, model=model, budget=budget)
310
354
  report = write_report(rep)
@@ -319,9 +363,11 @@ def nightly(tasks_path: str = DEFAULT_TASKS, model: str | None = None, budget: f
319
363
  return {"failed": True, "attempted": paths.now(), "report": report,
320
364
  "reason": "no model call answered: 0/%d samples exited 0; first answer "
321
365
  "began %r" % (rep["samples"], (first.get("answer") or "")[:80])}
366
+ summary = record_quality(rep)
322
367
  return {"ran": True, "report": report, "clock": mark_replayed(),
323
368
  "treatment_delivered": rep.get("treatment_delivered"),
324
- "verdict_tally": rep.get("verdict_tally")}
369
+ "verdict_tally": rep.get("verdict_tally"),
370
+ "quality": summary, "quality_line": quality_line()}
325
371
 
326
372
 
327
373
  def write_report(rep: dict) -> str: