pi-sleep-agent 0.8.10 → 0.8.11

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
@@ -140,7 +140,7 @@ Use `--agents oh-my-pi` for Oh My Pi. `--extension` remains an alias for selecti
140
140
 
141
141
  The extension loads on the next Pi or OmO session and performs three jobs:
142
142
 
143
- - captures user messages and relevant tool activity into T0,
143
+ - captures user messages and relevant tool activity into T0, recording which tool ran and whether it succeeded,
144
144
  - injects matching T1 provisional memory into the agent context,
145
145
  - wakes the sleep policy after the agent settles.
146
146
 
@@ -382,6 +382,11 @@ Sleep separates memory into three tiers:
382
382
  | Tier | Meaning | Who writes it |
383
383
  |---|---|---|
384
384
  | T0 | Temporary session observations | Hooks, extension, or `capture` |
385
+
386
+ A tool event records the tool and its outcome (`Bash failed`, `Edit ok`) on the
387
+ record's `evidence` line, so a "fact" that came out of a failed command is
388
+ visible as such in review. A call with no file path keeps the tool and outcome
389
+ too (and claims no path it does not have).
385
390
  | T1 | Provisional memory shown as unverified background | Consolidation and `mine` |
386
391
  | T2 | Permanent memory | Only an explicit `promote` command |
387
392
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-sleep-agent",
3
- "version": "0.8.10",
3
+ "version": "0.8.11",
4
4
  "description": "A reviewable sleep and dream cycle for Pi agent memory.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -110,6 +110,28 @@ def capture_from_stdin(stdin=None, kind: str = "preference",
110
110
  _PATH_KEYS = ("file_path", "path", "notebook_path", "filePath")
111
111
 
112
112
 
113
+ def tool_outcome(payload: dict) -> str:
114
+ """'ok' or 'failed' for a finished tool call.
115
+
116
+ Claude reports a failed call on the response (`is_error`) and on the process
117
+ (`interrupted`); an explicit success flag is trusted when present. When the
118
+ payload carries neither signal the answer is "ok", because a PostToolUse event
119
+ is delivered for a call that ran, and claiming a failure we cannot see would be
120
+ worse than the weaker true statement.
121
+ """
122
+ resp = payload.get("tool_response") or payload.get("toolResponse") or {}
123
+ if isinstance(resp, dict):
124
+ if resp.get("is_error") or resp.get("isError"):
125
+ return "failed"
126
+ if resp.get("interrupted"):
127
+ return "failed"
128
+ if resp.get("success") is False:
129
+ return "failed"
130
+ if payload.get("is_error") or payload.get("isError"):
131
+ return "failed"
132
+ return "ok"
133
+
134
+
113
135
  def tool_event(payload: dict) -> tuple[str, str]:
114
136
  """(tool_name, path) from a PostToolUse payload, or ("", "")."""
115
137
  name = str(payload.get("tool_name") or payload.get("toolName") or "")
@@ -135,13 +157,21 @@ def capture_tool_from_stdin(stdin=None) -> tuple[str, str]:
135
157
  if not isinstance(payload, dict):
136
158
  return "ignored", "hook payload not an object"
137
159
  name, path = tool_event(payload)
138
- if not path:
139
- return "ignored", "no path in tool event"
140
- text = "session touched %s via %s" % (path, name or "tool")
160
+ tool = name or "tool"
161
+ outcome = tool_outcome(payload)
162
+ # A call without a path (Bash, Grep, and every command-shaped tool) still says
163
+ # something worth keeping: which tool ran and whether it worked. Dropping those
164
+ # events meant the failure that produced a wrong "fact" left no trace at all.
165
+ if path:
166
+ text = "session touched %s via %s (%s)" % (path, tool, outcome)
167
+ evidence = [path, "%s %s" % (tool, outcome)]
168
+ else:
169
+ text = "session ran %s (%s)" % (tool, outcome)
170
+ evidence = ["%s %s" % (tool, outcome)]
141
171
  ok, detail = store.capture(text, kind="fact", source="agent",
142
172
  session=str(payload.get("session_id") or ""),
143
173
  cwd=str(payload.get("cwd") or ""),
144
- evidence=[path], tags=["hook:posttool"])
174
+ evidence=evidence, tags=["hook:posttool"])
145
175
  return ("captured" if ok else "refused"), detail
146
176
 
147
177