pi-sleep-agent 0.8.14 → 0.8.15
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 +5 -0
- package/package.json +1 -1
- package/prompts/consolidate.md +6 -0
- package/sleepkit/cli.py +4 -0
- package/sleepkit/consolidate.py +8 -4
- package/sleepkit/store.py +45 -3
package/README.md
CHANGED
|
@@ -34,6 +34,11 @@ Sleep adds a reviewable memory cycle to nine selectable coding-agent targets. It
|
|
|
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.
|
|
36
36
|
- **Relevance-ranked injection.** With a query, provisional memory is ordered by overlap with the live request and each line carries its age, so the most relevant record survives the `--max` cut and stale facts read as stale.
|
|
37
|
+
- **Two clocks per record.** `ts` is when the record was written; `event_at` is when
|
|
38
|
+
the thing it describes actually happened, and it is written **only when the record
|
|
39
|
+
states a date** (a date equal to the capture day is not a second clock). An empty
|
|
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.
|
|
37
42
|
- **Tagged records.** Consolidation writes 1-4 lowercase topic tags per record (`deploy|aws`),
|
|
38
43
|
normalized and capped in `store`, and `inject --topic` selects on them. A tag is a
|
|
39
44
|
hint a model proposed, so a wrong tag costs a missing filter hit, never a wrong fact.
|
package/package.json
CHANGED
package/prompts/consolidate.md
CHANGED
|
@@ -19,6 +19,8 @@ Each proposal is header fields, a blank line, then the observation:
|
|
|
19
19
|
kind: fact | preference | procedure | warning
|
|
20
20
|
trust: verified | observed | speculative
|
|
21
21
|
tags: <1-4 pipe-separated lowercase topics, e.g. deploy|aws or gitlab|auth>
|
|
22
|
+
event_at: <optional YYYY-MM-DD, ONLY when the observation itself states a date for
|
|
23
|
+
the thing you are describing; omit the line when it does not>
|
|
22
24
|
evidence: <optional, comma separated file paths or session refs>
|
|
23
25
|
|
|
24
26
|
<one observation, 1-3 sentences, written so a reader in a future session can
|
|
@@ -56,5 +58,9 @@ here.
|
|
|
56
58
|
- The `tags` line is the only index a future session can filter on: use the
|
|
57
59
|
topic words a person would search for (deploy, gitlab, auth), not the
|
|
58
60
|
sentence's verbs. Never repeat the kind as a tag.
|
|
61
|
+
- `event_at` is only for a date the observation already states about the thing it
|
|
62
|
+
describes ("on 2026-10-14 the staging host moved"). Never derive it from what you
|
|
63
|
+
know, never write the session's own date, and omit the line otherwise: the record
|
|
64
|
+
keeps two separate clocks and an empty `event_at` means "the record does not say".
|
|
59
65
|
- Proposals are cheap and refusals are cheap; a poisoned memory store is not. When
|
|
60
66
|
in doubt, emit fewer and mark the remainder `speculative`.
|
package/sleepkit/cli.py
CHANGED
|
@@ -155,6 +155,10 @@ def cmd_show(a) -> int:
|
|
|
155
155
|
return 2
|
|
156
156
|
meta, body = got
|
|
157
157
|
_p(store.emit(meta, body))
|
|
158
|
+
event_at = str(meta.get("event_at") or "").strip()
|
|
159
|
+
if event_at:
|
|
160
|
+
_p("# two clocks: recorded %s, the recorded event happened %s"
|
|
161
|
+
% (str(meta.get("ts", "?"))[:10], event_at))
|
|
158
162
|
# Show the supersede chain: with only the two pointer fields visible, answering
|
|
159
163
|
# "which record is current, and what did it replace?" means reading other files.
|
|
160
164
|
chain = store.supersession_chain(a.id)
|
package/sleepkit/consolidate.py
CHANGED
|
@@ -15,7 +15,7 @@ from datetime import datetime
|
|
|
15
15
|
|
|
16
16
|
from . import llm, paths, safety, store
|
|
17
17
|
|
|
18
|
-
_HDR = re.compile(r"^(source|kind|trust|tags|evidence)\s*:\s*(.+)$", re.M)
|
|
18
|
+
_HDR = re.compile(r"^(source|kind|trust|tags|event_at|evidence)\s*:\s*(.+)$", re.M)
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
def pending_dir() -> str:
|
|
@@ -191,7 +191,7 @@ def distill(session: str | None = None, model: str | None = None,
|
|
|
191
191
|
def parse_proposal(text: str) -> dict:
|
|
192
192
|
"""Split one proposal into header fields + body. Headers are optional."""
|
|
193
193
|
fields = {"source": "agent", "kind": "fact", "trust": "observed",
|
|
194
|
-
"tags": "", "evidence": ""}
|
|
194
|
+
"tags": "", "event_at": "", "evidence": ""}
|
|
195
195
|
for m in _HDR.finditer(text):
|
|
196
196
|
fields[m.group(1)] = m.group(2).strip()
|
|
197
197
|
body = _HDR.sub("", text).strip()
|
|
@@ -205,7 +205,7 @@ def parse_proposal(text: str) -> dict:
|
|
|
205
205
|
# fallback. Neither decides what becomes memory: every block still goes through
|
|
206
206
|
# ingest_records(), which is where the gates live.
|
|
207
207
|
_SEP_LINE = re.compile(r"^[^A-Za-z0-9\n]*PROPOSAL[^A-Za-z0-9\n]*$", re.I | re.M)
|
|
208
|
-
_HDR_LINE = re.compile(r"^(source|kind|trust|tags|evidence)\s*:.*$", re.M)
|
|
208
|
+
_HDR_LINE = re.compile(r"^(source|kind|trust|tags|event_at|evidence)\s*:.*$", re.M)
|
|
209
209
|
|
|
210
210
|
|
|
211
211
|
def split_blocks(text: str) -> tuple:
|
|
@@ -310,7 +310,11 @@ def ingest_records(parsed: list, session: str = "", cwd: str = "",
|
|
|
310
310
|
evidence=[x for x in f.get("evidence", "").split(",") if x],
|
|
311
311
|
# The proposal's own tag line is a hint, never authority: store.add_candidate
|
|
312
312
|
# normalizes and caps it, and a wrong tag only costs a bad topic filter.
|
|
313
|
-
tags=[x for x in str(f.get("tags", "")).split("|") if x.strip()]
|
|
313
|
+
tags=[x for x in str(f.get("tags", "")).split("|") if x.strip()],
|
|
314
|
+
# The model may state when the described thing happened. add_candidate
|
|
315
|
+
# validates it and keeps the two clocks apart; a date the record does not
|
|
316
|
+
# state stays empty rather than being backfilled from the capture time.
|
|
317
|
+
event_at=f.get("event_at", ""))
|
|
314
318
|
(accepted if ok else refused).append({"body": item["body"][:60], "result": out})
|
|
315
319
|
return {"proposals": len(parsed), "accepted": len(accepted), "refused": refused,
|
|
316
320
|
"accepted_ids": [a["result"] for a in accepted]}
|
package/sleepkit/store.py
CHANGED
|
@@ -53,7 +53,7 @@ IDX_END = "<!-- sleep:end -->"
|
|
|
53
53
|
|
|
54
54
|
# ------------------------------------------------------------- frontmatter --
|
|
55
55
|
def emit(record: dict, body: str = "") -> str:
|
|
56
|
-
order = ["id", "ts", "source", "trust", "kind", "status", "session", "cwd",
|
|
56
|
+
order = ["id", "ts", "event_at", "source", "trust", "kind", "status", "session", "cwd",
|
|
57
57
|
"tags", "evidence", "supersedes", "superseded_by",
|
|
58
58
|
"valid_from", "valid_until", "redacted", "notes"]
|
|
59
59
|
# Known fields first in a stable order, then anything else the record carries.
|
|
@@ -324,7 +324,8 @@ def record_injection(ids: list[str]) -> int:
|
|
|
324
324
|
def add_candidate(text: str, kind: str = "fact", source: str = "agent",
|
|
325
325
|
trust: str = "observed", session: str = "", cwd: str = "",
|
|
326
326
|
evidence: list[str] | None = None, supersedes: list[str] | None = None,
|
|
327
|
-
notes: str = "", tags: list[str] | None = None
|
|
327
|
+
notes: str = "", tags: list[str] | None = None,
|
|
328
|
+
event_at: str = "") -> tuple[bool, str]:
|
|
328
329
|
"""T1: distilled, provisional. Never injected as a directive."""
|
|
329
330
|
text = (text or "").strip()
|
|
330
331
|
if not text:
|
|
@@ -360,13 +361,19 @@ def add_candidate(text: str, kind: str = "fact", source: str = "agent",
|
|
|
360
361
|
return False, "duplicate of earlier refusal %s (%.2f); this idea was judged and rejected" % (
|
|
361
362
|
ref_id, ref_score)
|
|
362
363
|
|
|
364
|
+
ts = paths.now()
|
|
365
|
+
# Trust the caller's own statement when it gives one; otherwise read a date out of
|
|
366
|
+
# the record's own wording. Never invent: an empty event_at means the record does
|
|
367
|
+
# not say when the described thing happened, which is a different fact from ts.
|
|
368
|
+
event_at = _valid_event_at(event_at, ts) or stated_event_at(red, ts)
|
|
363
369
|
rec = {
|
|
364
370
|
"id": paths.new_id("c"),
|
|
365
|
-
"ts":
|
|
371
|
+
"ts": ts,
|
|
366
372
|
"source": source if source in safety.SOURCES else "inferred",
|
|
367
373
|
"trust": safety.cap_trust(source, trust),
|
|
368
374
|
"kind": kind if kind in KINDS else "fact",
|
|
369
375
|
"status": "provisional",
|
|
376
|
+
"event_at": event_at,
|
|
370
377
|
"session": session or os.environ.get("SLEEP_SESSION", ""),
|
|
371
378
|
"cwd": cwd or os.getcwd(),
|
|
372
379
|
"tags": "|".join(_clean_tags(tags)),
|
|
@@ -824,6 +831,41 @@ MAX_TAGS = 6
|
|
|
824
831
|
MAX_TAG_CHARS = 32
|
|
825
832
|
|
|
826
833
|
|
|
834
|
+
# The two clocks are separate: `ts` is when the record was written (always set), and
|
|
835
|
+
# `event_at` is when the thing being described actually happened (only set when the
|
|
836
|
+
# record states it). Backfilling event_at from ts would manufacture a fact nobody
|
|
837
|
+
# recorded, and every later "where was X in October" question would answer with the
|
|
838
|
+
# capture date. Empty means unknown, and unknown is reported as unknown.
|
|
839
|
+
_DATE_RE = re.compile(r"\b(\d{4}-\d{2}-\d{2})\b")
|
|
840
|
+
|
|
841
|
+
|
|
842
|
+
def _valid_event_at(value: str, ts: str = "") -> str:
|
|
843
|
+
"""Accept a caller-stated event date only in YYYY-MM-DD form, never the capture day."""
|
|
844
|
+
m = _DATE_RE.fullmatch(str(value or "").strip())
|
|
845
|
+
if not m:
|
|
846
|
+
return ""
|
|
847
|
+
if ts and m.group(1) in ts[:10]:
|
|
848
|
+
return ""
|
|
849
|
+
return m.group(1)
|
|
850
|
+
|
|
851
|
+
|
|
852
|
+
def stated_event_at(text: str, fallback_ts: str = "") -> str:
|
|
853
|
+
"""Return a date the record's own wording states, else "".
|
|
854
|
+
|
|
855
|
+
Deliberately a literal match, not an inference: a relative phrasing ("last week")
|
|
856
|
+
is left to the model that reads the record, and this only accepts a date the text
|
|
857
|
+
spells out. A date equal to the capture day is not an event time either - it is
|
|
858
|
+
the same clock, and writing it twice would invent a distinction.
|
|
859
|
+
"""
|
|
860
|
+
m = _DATE_RE.search(text or "")
|
|
861
|
+
if not m:
|
|
862
|
+
return ""
|
|
863
|
+
value = m.group(1)
|
|
864
|
+
if fallback_ts and value in fallback_ts[:10]:
|
|
865
|
+
return ""
|
|
866
|
+
return value
|
|
867
|
+
|
|
868
|
+
|
|
827
869
|
def _clean_tags(tags) -> list:
|
|
828
870
|
out, seen = [], set()
|
|
829
871
|
for raw in tags or []:
|