Skip to content

Commit 2edb418

Browse files
committed
docs(session-logs): scope nullglob and use while-read in helper
Address Greptile review feedback on PR #71537: * nullglob is now saved and restored inside list_session_transcripts so the helper does not change the caller shell environment when sourced. * Replace 'for f in $(list_session_transcripts)' tip with a 'while IFS= read -r' loop so paths with spaces or other IFS characters are handled correctly. Include a worked example using the same date+size listing the surrounding section already documents. Doc only, no runtime behavior change.
1 parent c68e417 commit 2edb418

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

skills/session-logs/SKILL.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,19 @@ Each `.jsonl` file contains messages with:
6868

6969
```bash
7070
# Bash helper that emits every searchable transcript path — active and archived.
71+
# Saves and restores `nullglob` locally so callers' shell options aren't disturbed.
7172
AGENT_ID="<agentId>"
7273
SESSION_DIR="${OPENCLAW_STATE_DIR:-$HOME/.openclaw}/agents/$AGENT_ID/sessions"
73-
shopt -s nullglob
7474
list_session_transcripts() {
75+
local _nullglob_state
76+
_nullglob_state=$(shopt -p nullglob 2>/dev/null)
77+
shopt -s nullglob
7578
for f in "$SESSION_DIR"/*.jsonl \
7679
"$SESSION_DIR"/*.jsonl.reset.*Z \
7780
"$SESSION_DIR"/*.jsonl.deleted.*Z; do
7881
[ -f "$f" ] && printf '%s\n' "$f"
7982
done
83+
eval "$_nullglob_state"
8084
}
8185
```
8286

@@ -100,9 +104,18 @@ for f in "$SESSION_DIR"/*.jsonl; do
100104
done | sort -r
101105
```
102106

103-
_Tip:_ swap the `for f in ...` line for `for f in $(list_session_transcripts); do`
104-
(see snippet above) when you also want archived `.reset` / `.deleted` files in the
105-
listing.
107+
_Tip:_ swap the `for f in ...` line for a `while`-read over
108+
`list_session_transcripts` (see snippet above) when you also want archived
109+
`.reset` / `.deleted` files in the listing. The `while`-read pattern is safe
110+
for paths with spaces or other IFS characters:
111+
112+
```bash
113+
while IFS= read -r f; do
114+
date=$(head -1 "$f" | jq -r '.timestamp' | cut -dT -f1)
115+
size=$(ls -lh "$f" | awk '{print $5}')
116+
echo "$date $size $(basename "$f")"
117+
done < <(list_session_transcripts) | sort -r
118+
```
106119

107120
### Find sessions from a specific day
108121

0 commit comments

Comments
 (0)