pi-sleep-agent 0.5.0 → 0.6.0

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
@@ -32,6 +32,8 @@ Sleep adds a reviewable memory cycle to Pi, OmO, and Claude Code. It records use
32
32
  - **Measured replay.** Run the same task with memory off and on before deciding whether a memory helps.
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
+ - **Reviewable permanence.** Each approved memory in your index carries its review date and source, so you can tell when a saved instruction was pinned.
36
+ - **Stale-value scan.** `doctor --stale <value>` finds which approved records still hold a value you know has changed (for example a deployment URL).
35
37
  - **Safety gates.** Secrets are redacted, hostile text is quarantined, and machine-generated prompts cannot claim user provenance.
36
38
 
37
39
  ## Install
@@ -196,11 +198,12 @@ session activity -> T0 buffer -> gated sleep -> T1 provisional memory
196
198
 
197
199
  Dream is Sleep's unattended reflection phase. It does not update model weights and it never writes permanent memory on its own.
198
200
 
199
- A dream pass performs three steps:
201
+ A dream pass performs four steps:
200
202
 
201
203
  1. **Mine.** Find instructions you repeated across separate sessions in the same project. This step is deterministic and makes no model call.
202
204
  2. **Consolidate.** When the sleep gate passes, ask the configured model to turn recent T0 observations into provisional T1 candidates.
203
- 3. **Replay.** When replay is due, run selected tasks with provisional memory off and on, then write a comparison report.
205
+ 3. **Hygiene.** Run the read-only `doctor` scan and fold any findings (duplicate headings, near-duplicate candidates, or stale values when you pass `--stale <value>`) into the night's report.
206
+ 4. **Replay.** When replay is due, run selected tasks with provisional memory off and on, then write a comparison report.
204
207
 
205
208
  Every result stays reviewable. Candidates remain in T1 until you explicitly run `promote`.
206
209
 
@@ -208,6 +211,7 @@ Preview the complete dream pass without model calls or writes:
208
211
 
209
212
  ```bash
210
213
  ./sleep.py nightly --dry-run
214
+ ./sleep.py nightly --dry-run --stale https://old.internal/app # also scan approved memory for a changed value
211
215
  ```
212
216
 
213
217
  Run it now:
@@ -242,6 +246,7 @@ Run the two dream components separately when you want more control:
242
246
  | `./sleep.py mine --dry-run` | Find preferences repeated across sessions |
243
247
  | `./sleep.py nightly --dry-run` | Preview the unattended nightly workflow |
244
248
  | `./sleep.py doctor` | Find duplicate or overlapping memory records |
249
+ | `./sleep.py doctor --stale <value>` | Show which approved records still hold a stale value (e.g. a changed URL) |
245
250
  | `./sleep.py inject --project "$PWD"` | Print provisional context for the current project |
246
251
 
247
252
  Run `./sleep.py <command> --help` for command-specific options.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-sleep-agent",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
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
@@ -61,7 +61,8 @@ def cmd_status(a) -> int:
61
61
  q = [f for f in os.listdir(paths.quarantine_dir()) if f.endswith(".json")]
62
62
  mdir = paths.memory_dir(a.cwd or None)
63
63
  try:
64
- permanent = [f for f in os.listdir(mdir) if f.endswith(".md")]
64
+ permanent = [f for f in os.listdir(mdir)
65
+ if f.endswith(".md") and f != "MEMORY.md"]
65
66
  except OSError:
66
67
  permanent = []
67
68
  _p("sleep memory: T0=disposable captures, T1=provisional awaiting review, T2=permanent (promote-only)")
@@ -69,6 +70,19 @@ def cmd_status(a) -> int:
69
70
  _p("T1 candidates %d provisional, %d refused, %d total (distilled, shown as unverified context)" % (len(prov), len(ref), len(cands)))
70
71
  _p(" quarantine %d parked (needs human eyes) (held out until you review)" % len(q))
71
72
  _p("T2 canonical %s (%d permanent records; only you can promote)" % (mdir, len(permanent)))
73
+ if permanent:
74
+ _p("")
75
+ _p("permanent (last 5, promoted with review date + source):")
76
+ for f in permanent[-5:]:
77
+ try:
78
+ with open(os.path.join(mdir, f), encoding="utf-8") as fh:
79
+ m, b = store.parse(fh.read())
80
+ except (OSError, ValueError):
81
+ m, b = {}, ""
82
+ when = m.get("promoted_at", "?")[:10]
83
+ src = m.get("source", "?")
84
+ _p(" %-10s %-10s %-8s %s" % (f[:-3][:10], when, src,
85
+ b.replace("\n", " ")[:88]))
72
86
  if prov:
73
87
  _p("")
74
88
  _p("provisional (context only, never directives):")
@@ -140,7 +154,7 @@ def cmd_prune(a) -> int:
140
154
 
141
155
 
142
156
  def cmd_doctor(a) -> int:
143
- issues = store.doctor()
157
+ issues = store.doctor(needle=a.stale)
144
158
  if a.json:
145
159
  _p(json.dumps(issues, indent=2, sort_keys=True, default=str))
146
160
  elif not issues:
@@ -206,6 +220,10 @@ def cmd_nightly(a) -> int:
206
220
  rep: dict = {"ts": paths.now()} # heterogeneous on purpose: three reports, one JSON
207
221
  rep["mine"] = ({"skipped": "--no-mine"} if a.no_mine
208
222
  else mine.mine(min_sessions=a.mine_min_sessions, dry_run=a.dry_run))
223
+ # The hygiene report lands in the night regardless of the gates: it is
224
+ # read-only, so the worst an unattended pass can do is surface a stale
225
+ # value (e.g. a changed deployment URL) for a person to act on later.
226
+ rep["doctor"] = {"issues": store.doctor(needle=a.stale)}
209
227
  rep["sleep"] = consolidate.run_sleep(session=a.session, model=a.model,
210
228
  budget_usd=a.budget,
211
229
  min_records=a.min_records,
@@ -339,6 +357,9 @@ def main(argv=None) -> int:
339
357
 
340
358
  dc = sub.add_parser("doctor", help="read-only hygiene report")
341
359
  dc.add_argument("--json", action="store_true")
360
+ dc.add_argument("--stale", default=None,
361
+ help="value (e.g. a URL) to scan approved T2 memory for; "
362
+ "reports which permanent records still hold it")
342
363
  dc.set_defaults(fn=cmd_doctor)
343
364
 
344
365
  rp = sub.add_parser("replay", help="layer 3: A/B measure provisional memory, report-only")
@@ -352,6 +373,8 @@ def main(argv=None) -> int:
352
373
 
353
374
  nt = sub.add_parser("nightly",
354
375
  help="unattended pass: gated consolidation + replay when due")
376
+ nt.add_argument("--stale", default=None,
377
+ help="value (e.g. a URL) to scan approved T2 memory for each night")
355
378
  nt.add_argument("--session")
356
379
  nt.add_argument("--model", default=None)
357
380
  nt.add_argument("--budget", type=float, default=1.00)
package/sleepkit/store.py CHANGED
@@ -337,9 +337,11 @@ def promote(cid: str, memory_dir: str | None = None, dry_run: bool = False) -> t
337
337
  # Expansion-only: if the name is taken, open a new file rather than merging.
338
338
  if os.path.exists(dest):
339
339
  dest = os.path.join(mdir, "%s-%s.md" % (slugify(body.split(".")[0][:60]), cid[-4:]))
340
- line = "- **%s**: [detail](%s). %s" % (
340
+ when = paths.now()
341
+ src = meta.get("source", "?")
342
+ line = "- **%s**: [detail](%s). %s _(promoted %s, source=%s)_" % (
341
343
  os.path.basename(dest)[:-3], os.path.basename(dest),
342
- body.replace("\n", " ")[:220])
344
+ body.replace("\n", " ")[:160], when[:10], src)
343
345
  if dry_run:
344
346
  return True, "would write %s (+ index line)" % dest
345
347
  os.makedirs(mdir, exist_ok=True)
@@ -350,7 +352,7 @@ def promote(cid: str, memory_dir: str | None = None, dry_run: bool = False) -> t
350
352
  # reader inside the memory store never sees a record claiming to be provisional.
351
353
  out_meta = {k: v for k, v in meta.items() if not k.startswith("_")}
352
354
  out_meta["status"] = "promoted"
353
- out_meta["promoted_at"] = paths.now()
355
+ out_meta["promoted_at"] = when
354
356
  with open(dest, "w", encoding="utf-8") as fh:
355
357
  fh.write(emit(out_meta, body))
356
358
  ok, why = append_index_line(mdir, line)
@@ -425,7 +427,8 @@ def prune_buffer(older_than_hours: float = 0.0, session: str | None = None) -> d
425
427
  return {"moved": moved, "remaining": buffer_counts()}
426
428
 
427
429
 
428
- def doctor(memory_dir: str | None = None, targets: list[str] | None = None) -> list[dict]:
430
+ def doctor(memory_dir: str | None = None, targets: list[str] | None = None,
431
+ needle: str | None = None) -> list[dict]:
429
432
  """Read-only hygiene report.
430
433
 
431
434
  Two checks, both about content rather than formatting:
@@ -455,6 +458,17 @@ def doctor(memory_dir: str | None = None, targets: list[str] | None = None) -> l
455
458
  if n > 1:
456
459
  out.append({"issue": "duplicate-heading-in-file", "heading": h,
457
460
  "count": n, "file": p})
461
+ if needle:
462
+ nlow = needle.strip().lower()
463
+ if nlow:
464
+ for p, text in bodies.items():
465
+ if os.path.basename(p) == "MEMORY.md":
466
+ # The index only points at detail files; flagging it re-reports
467
+ # every hit once for the detail file it names, so skip it.
468
+ continue
469
+ if nlow in text.lower():
470
+ out.append({"issue": "stale-value-in-memory", "file": p,
471
+ "value": needle})
458
472
  pool = [(c["id"], c.get("_body", "")) for c in list_candidates(with_body=True)]
459
473
  for i in range(len(pool)):
460
474
  for j in range(i + 1, len(pool)):