pi-sleep-agent 0.7.0 → 0.8.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-sleep-agent",
3
- "version": "0.7.0",
3
+ "version": "0.8.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
@@ -115,9 +115,11 @@ def cmd_status(a) -> int:
115
115
  _p("")
116
116
  _p("provisional (context only, never directives):")
117
117
  for c in prov[-12:]:
118
- _p(" %-10s %-8s %-11s %s" % (c["id"], c.get("source", "?"),
119
- c.get("trust", "?"),
120
- c.get("_body", "").replace("\n", " ")[:88]))
118
+ rd = c.get("rediscovered")
119
+ tag = (" [rediscovered x%s in %s sessions]" % (rd, c.get("rediscovered_in", "").strip("|")) if rd else "")
120
+ _p(" %-10s %-8s %-11s %s%s" % (c["id"], c.get("source", "?"),
121
+ c.get("trust", "?"),
122
+ c.get("_body", "").replace("\n", " ")[:88], tag))
121
123
  if ref:
122
124
  _p("")
123
125
  _p("refused (last 5, earlier rejections stay on record):")
package/sleepkit/store.py CHANGED
@@ -213,6 +213,44 @@ def refused_collision(text: str, threshold: float = REFUSED_DUP_THRESHOLD) -> tu
213
213
 
214
214
 
215
215
  # ------------------------------------------------------------- candidates ---
216
+ def _record_rediscovery(cid: str, session: str) -> str | None:
217
+ """Record that an agent re-learned an existing candidate in another session.
218
+
219
+ Returns a human message when the session differs from the ones already recorded
220
+ (a genuine cross-session rediscovery), or None when it is the same session again
221
+ (that is a repeat, not a pattern, and the plain duplicate message applies).
222
+ """
223
+ got = get_candidate(cid)
224
+ if not got:
225
+ return None
226
+ meta, body = got
227
+ # The record's own session is the baseline: a repeat from the same session the
228
+ # fact was first filed in is a repeat, not a rediscovery. Only a *different*
229
+ # session counts.
230
+ sessions = [s for s in meta.get("rediscovered_in", "").split("|") if s]
231
+ own = (meta.get("session", "") or "").strip()
232
+ if own and own not in sessions:
233
+ sessions.append(own)
234
+ this = (session or "").strip()
235
+ if not this:
236
+ return None
237
+ if this in sessions:
238
+ return None
239
+ sessions.append(this)
240
+ n = int(meta.get("rediscovered", 0) or 0) + 1
241
+ meta["rediscovered"] = str(n)
242
+ meta["rediscovered_in"] = "|".join(sessions)
243
+ loc = paths.candidates_dir()
244
+ if not os.path.isfile(os.path.join(loc, cid + ".md")):
245
+ p = os.path.join(paths.archive_dir("candidates"), cid + ".md")
246
+ if os.path.isfile(p):
247
+ loc = paths.archive_dir("candidates")
248
+ with open(os.path.join(loc, cid + ".md"), "w", encoding="utf-8") as fh:
249
+ fh.write(emit(meta, body))
250
+ return "duplicate of %s (rediscovered in a later session: %d distinct sessions now; use `sleepctl show %s` to review)" % (
251
+ cid, n, cid)
252
+
253
+
216
254
  def add_candidate(text: str, kind: str = "fact", source: str = "agent",
217
255
  trust: str = "observed", session: str = "", cwd: str = "",
218
256
  evidence: list[str] | None = None, supersedes: list[str] | None = None,
@@ -237,6 +275,14 @@ def add_candidate(text: str, kind: str = "fact", source: str = "agent",
237
275
  pool = [(m["id"], m.get("_body", "")) for m in list_candidates(with_body=True)]
238
276
  dup, score = nearest(red, pool)
239
277
  if dup:
278
+ if source == "agent":
279
+ note = _record_rediscovery(dup, session)
280
+ if note:
281
+ # The agent independently re-learned a fact it already holds as a
282
+ # provisional candidate. It stays provisional (not a directive) and
283
+ # is not auto-kept; this just marks the cross-session rediscovery so
284
+ # the reviewer can weigh it. trust stays cap_trust(source) unchanged.
285
+ return False, note
240
286
  return False, "duplicate of %s (%.2f); use `sleepctl supersede %s %s`" % (
241
287
  dup, score, dup, "new-text")
242
288
  ref_id, ref_score = refused_collision(red)