pi-sleep-agent 0.8.22 → 0.8.23
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 +26 -2
- package/docs/EVIDENCE.md +24 -8
- package/package.json +1 -1
- package/sleepkit/cli.py +8 -0
- package/sleepkit/paths.py +65 -14
package/README.md
CHANGED
|
@@ -468,11 +468,12 @@ All runtime data lives under `$SLEEP_HOME`, which defaults to `~/.sleep`:
|
|
|
468
468
|
```text
|
|
469
469
|
buffer/ temporary T0 records
|
|
470
470
|
candidates/ provisional T1 records
|
|
471
|
+
memory/ permanent T2 memory: one file per record plus its MEMORY.md index
|
|
471
472
|
reports/ replay reports
|
|
472
473
|
logs/ hook and nightly logs
|
|
473
474
|
.quarantine/ rejected unsafe input
|
|
474
475
|
state.json sleep and replay timestamps, and the last measured memory-quality summary
|
|
475
|
-
env optional scheduled-run environment
|
|
476
|
+
env optional scheduled-run environment (also where SLEEP_MEMORY_DIR is read from)
|
|
476
477
|
```
|
|
477
478
|
|
|
478
479
|
Useful logs:
|
|
@@ -489,6 +490,29 @@ Use another home for testing or for a separate memory pool:
|
|
|
489
490
|
SLEEP_HOME=/tmp/my-sleep ./sleep.py status -v
|
|
490
491
|
```
|
|
491
492
|
|
|
493
|
+
### Where permanent memory is written
|
|
494
|
+
|
|
495
|
+
T2 lives in one fixed place: `$SLEEP_HOME/memory` (`~/.sleep/memory` by default).
|
|
496
|
+
It is sleep's own store and not a host's project memory, so it does not move with the
|
|
497
|
+
directory a hook happened to run in and it cannot collide with the agent host's own
|
|
498
|
+
memory files. `status` prints the path it resolved, on the `T2 canonical` line.
|
|
499
|
+
|
|
500
|
+
`SLEEP_MEMORY_DIR` overrides it. Set it in `~/.sleep/env` for a scheduled run that
|
|
501
|
+
has no shell of its own:
|
|
502
|
+
|
|
503
|
+
```text
|
|
504
|
+
SLEEP_MEMORY_DIR=/path/to/another/store
|
|
505
|
+
```
|
|
506
|
+
|
|
507
|
+
The two keys sleep reads from that file are `SLEEP_MEMORY_DIR` and `SLEEP_MODEL`;
|
|
508
|
+
a value exported in the environment always wins over the file. Every `promote` and
|
|
509
|
+
`demote` names the store it wrote, so a pass that landed somewhere unexpected says so
|
|
510
|
+
rather than looking successful.
|
|
511
|
+
|
|
512
|
+
An install that predates this keeps reading the project memory directory its records
|
|
513
|
+
actually sit in, because a store has an external reader worth more than a tidy path.
|
|
514
|
+
Run `./sleep.py status` to see which one is in force before moving records by hand.
|
|
515
|
+
|
|
492
516
|
## Troubleshooting
|
|
493
517
|
|
|
494
518
|
**Nothing was captured**
|
|
@@ -512,7 +536,7 @@ Use `--force` only when you intentionally want a model call.
|
|
|
512
536
|
|
|
513
537
|
**The scheduled pass cannot reach the model**
|
|
514
538
|
|
|
515
|
-
Confirm that `~/.sleep/env` exists, has mode `0600`, and contains the same provider settings used by your interactive shell. Then run `./sleep.py sleep --force` before relying on the scheduled pass (launchd / cron / Task Scheduler).
|
|
539
|
+
Confirm that `~/.sleep/env` exists, has mode `0600`, and contains the same provider settings used by your interactive shell. A `SLEEP_MEMORY_DIR` line in that same file is honoured by scheduled runs; see [Where permanent memory is written](#where-permanent-memory-is-written). Then run `./sleep.py sleep --force` before relying on the scheduled pass (launchd / cron / Task Scheduler).
|
|
516
540
|
|
|
517
541
|
**A candidate appears in the wrong context**
|
|
518
542
|
|
package/docs/EVIDENCE.md
CHANGED
|
@@ -7,14 +7,12 @@ ever exercised.
|
|
|
7
7
|
|
|
8
8
|
## Ran
|
|
9
9
|
|
|
10
|
-
**Unit tests.** `
|
|
11
|
-
`tests/test_core.py` (hook parsing, the proposal parser, the gate arithmetic,
|
|
12
|
-
|
|
13
|
-
`tests/test_cli.py`, where every call is a real
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
asserts a promoted file carries the memory text and not only frontmatter, one asserts the index is copied
|
|
17
|
-
before it is rewritten. Both were checked load-bearing: with the fix removed, each one fails.
|
|
10
|
+
**Unit tests.** `npm run validate` -> `Ran 261 tests ... OK` (plus `ruff` clean and the package
|
|
11
|
+
smoke): 87 in-process tests in `tests/test_core.py` (hook parsing, the proposal parser, the gate arithmetic,
|
|
12
|
+
the provenance ceiling, redaction, the kind-lifetime floor, and the answer scorer's verdict branches) plus 174
|
|
13
|
+
in `tests/test_cli.py`, where every call is a real subprocess of `sleep.py`, `tools/wire.py`, `install.sh` or
|
|
14
|
+
`uninstall.sh` against a throwaway `$SLEEP_HOME`. No test reaches the network or a model. The counts in this
|
|
15
|
+
paragraph are the ones the run above printed; when they disagree with the suite, the suite is right.
|
|
18
16
|
|
|
19
17
|
**One real sleep cycle, end to end** (`~/.sleep/reports/2026-10-31-163914-replay.md`; the report filename
|
|
20
18
|
format is `<utc>-replay.md`, the `A` in a filename like `...-16A-replay.md` in an older note was my mistake):
|
|
@@ -395,6 +393,24 @@ records and hit sentences that merely mention a constant. End-anchoring it - a p
|
|
|
395
393
|
back - dropped the count to 17 and, on a hand-built set, kept 6/6 probe phrasings flagged and 4/4 human phrasings
|
|
396
394
|
clean, including `never return MEMORY.md as a raw string, parse it first`.
|
|
397
395
|
|
|
396
|
+
|
|
397
|
+
**T2 happened to be the wrong directory, and one env line was a no-op** (2026-11-06). Two defects with the
|
|
398
|
+
same shape: a stored path that nothing checked and a documented key that nothing read. Measured on this laptop:
|
|
399
|
+
|
|
400
|
+
| claim | measurement |
|
|
401
|
+
|---|---|
|
|
402
|
+
| the project key sleep built was never the one Claude Code builds | sleep's rule kept `.` and `-` (`Users-yunus.aydin-Research-sleep`, no such directory) while the host's own key folded the dot (`-Users-yunus-aydin-Research-sleep`), so resolution fell through to a hard-coded fallback on every call |
|
|
403
|
+
| where T2 actually was | `~/.claude-work/projects/-Users-yunus-aydin/memory`, 107 records, shared with the host's own project memory |
|
|
404
|
+
| a `SLEEP_MEMORY_DIR` line in `~/.sleep/env` | read by nothing that decided a path: `llm.auth_env()` only ever passed the file to `subprocess.run(env=...)`, so `paths.memory_dir()` used its fallback instead |
|
|
405
|
+
| the fixed location after the change | `./sleep.py status` prints `T2 canonical /Users/yunus.aydin/.sleep/memory (11 permanent records)` |
|
|
406
|
+
| the env line after the change | in a throwaway `SLEEP_HOME`, a `promote` with `SLEEP_MEMORY_DIR` only in the env file wrote `<from-file>/the-staging-gateway-needs-a-ten-minute-timeout.md` and created nothing under the fallback |
|
|
407
|
+
| precedence | the same `promote` with the value exported in the environment used the exported store and never created the file's |
|
|
408
|
+
|
|
409
|
+
Eleven records that `confirmed_by` or `promoted_at` shows were written by this tool were copied to the new
|
|
410
|
+
store; the old directory was left intact and no file was deleted. `promote` and `demote` already printed the
|
|
411
|
+
path they wrote, which is what makes a pass that lands somewhere unexpected detectable rather than silent.
|
|
412
|
+
|
|
413
|
+
|
|
398
414
|
## Did not run
|
|
399
415
|
|
|
400
416
|
- **Compaction triggered by size.** Three measurements, and none of them is a proof of the reprint path:
|
package/package.json
CHANGED
package/sleepkit/cli.py
CHANGED
|
@@ -828,6 +828,14 @@ def main(argv=None) -> int:
|
|
|
828
828
|
ij.set_defaults(fn=cmd_inject)
|
|
829
829
|
|
|
830
830
|
a = ap.parse_args(argv)
|
|
831
|
+
# The env file carries what an unattended run needs and the shell did not export.
|
|
832
|
+
# Only the two keys memory_dir() itself reads are adopted here: a headless pass has
|
|
833
|
+
# no interactive shell to set them, and reading that file for the model transport
|
|
834
|
+
# alone (llm.auth_env) left SLEEP_MEMORY_DIR a silent no-op. The real environment
|
|
835
|
+
# still wins, so a one-off shell or a test is never overridden by a stale value.
|
|
836
|
+
for k, v in llm.env_overrides(paths.env_file()).items():
|
|
837
|
+
if k in ("SLEEP_MEMORY_DIR", "SLEEP_MODEL"):
|
|
838
|
+
os.environ.setdefault(k, v)
|
|
831
839
|
if hasattr(a, "model"):
|
|
832
840
|
a.model = llm.resolve_model(getattr(a, "model", None))
|
|
833
841
|
paths.home()
|
package/sleepkit/paths.py
CHANGED
|
@@ -60,25 +60,76 @@ def env_file() -> str:
|
|
|
60
60
|
|
|
61
61
|
|
|
62
62
|
# --- memory repo resolution ------------------------------------------------
|
|
63
|
-
#
|
|
64
|
-
#
|
|
65
|
-
#
|
|
63
|
+
# T2 is sleep's own store, not a host's project memory. The host's own store is
|
|
64
|
+
# written under its own rule, and the writer here could not know a store's rule
|
|
65
|
+
# ahead of a switch on an unset var in an env file, so the directory it picked was
|
|
66
|
+
# always the fallback; it also gave one path a store that named another. T2 therefore
|
|
67
|
+
# has one home of its own. It used to be the project memory directory of whichever
|
|
68
|
+
# agent cwd was current, and that directory is NOT written to any more: promote
|
|
69
|
+
# creates its target if it is missing, so the location must not depend on which
|
|
70
|
+
# project a hook happened to run in.
|
|
66
71
|
|
|
67
|
-
|
|
72
|
+
SLEEP_MEMORY_ENV = "SLEEP_MEMORY_DIR"
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def memory_dir_home() -> str:
|
|
76
|
+
return os.path.join(home(), "memory")
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def memory_dir_env() -> str | None:
|
|
80
|
+
"""The one override that is honoured, read from the process environment (and
|
|
81
|
+
adopted from the env file by the CLI before any command runs)."""
|
|
82
|
+
value = (os.environ.get(SLEEP_MEMORY_ENV) or "").strip()
|
|
83
|
+
return os.path.expanduser(value) if value else None
|
|
68
84
|
|
|
69
85
|
|
|
70
86
|
def memory_dir(cwd: str | None = None) -> str:
|
|
71
|
-
|
|
87
|
+
"""Where T2 lives: the override, else sleep's own home, else what already exists.
|
|
88
|
+
|
|
89
|
+
``cwd`` is kept in the signature because callers still pass it, and it stays
|
|
90
|
+
meaningful only for the last branch: an install that has been running since
|
|
91
|
+
before this change keeps reading the project memory directory its records
|
|
92
|
+
actually sit in, instead of one that reads empty and looks like data loss. A
|
|
93
|
+
directory that has never been written to therefore resolves to sleep's own home
|
|
94
|
+
and not to a path built from the caller's cwd. Callers that must inspect a
|
|
95
|
+
*specific* store keep passing it explicitly (store.* all take memory_dir=...).
|
|
96
|
+
"""
|
|
97
|
+
env = memory_dir_env()
|
|
72
98
|
if env:
|
|
73
|
-
return
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
99
|
+
return env
|
|
100
|
+
ours = memory_dir_home()
|
|
101
|
+
if os.path.isdir(ours) and any(fn.endswith(".md") for fn in os.listdir(ours)):
|
|
102
|
+
return ours
|
|
103
|
+
legacy = _legacy_project_memory_dir(cwd)
|
|
104
|
+
if legacy:
|
|
105
|
+
return legacy
|
|
106
|
+
return ours
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _legacy_project_memory_dir(cwd: str | None) -> str | None:
|
|
110
|
+
"""The pre-0.8.23 location, only when it actually holds records.
|
|
111
|
+
|
|
112
|
+
Reads the old project key so records promoted before the move are still found;
|
|
113
|
+
returns None (so the caller keeps sleep's own home) when nothing with a body is
|
|
114
|
+
there.
|
|
115
|
+
"""
|
|
116
|
+
base = os.environ.get("CLAUDE_CONFIG_DIR") or os.path.expanduser("~/.claude-work")
|
|
117
|
+
cands = []
|
|
118
|
+
if cwd:
|
|
119
|
+
cands.append(os.path.join(base, "projects", _project_key(cwd), "memory"))
|
|
120
|
+
cands.append(os.path.join(base, "projects", _project_key(os.getcwd()), "memory"))
|
|
121
|
+
for cand in cands:
|
|
122
|
+
try:
|
|
123
|
+
names = os.listdir(cand)
|
|
124
|
+
except OSError:
|
|
125
|
+
continue
|
|
126
|
+
if any(fn.endswith(".md") and fn != "MEMORY.md" for fn in names):
|
|
127
|
+
return cand
|
|
128
|
+
return None
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def _project_key(cwd: str) -> str:
|
|
132
|
+
return re.sub(r"[^A-Za-z0-9._-]", "-", os.path.abspath(cwd)).strip("-")
|
|
82
133
|
|
|
83
134
|
|
|
84
135
|
def new_id(prefix: str = "s") -> str:
|