UNRELEASED DEVELOPMENT SNAPSHOT · READ-ONLY EXCERPT
bin/_context.sh
This is the cited technical source at local revision 275a354, inspected on 22 September 2026. It differs from the public release. This reference publishes only the cited sections, not an installable release or the development branch.
Line numbers refer to the complete recorded file. Uncited lines are omitted. Full-file SHA-256: 89badb35e12cb79b49c29834774033e30a89b9317c2213d10264f7d92e4c012b.
1
#!/usr/bin/env bash2
# component: lintel-context3
# implements: ADR-00064
# intent: docs/concepts/memory-v2.md5
# constraints: helpers own paths/naming/discovery; content stays LLM-written6
# last_intent_review: 2026-06-127
#8
# bin/_context.sh — mechanical core for the context-save/restore family.9
# Closes the prose-only gap: 5 context skills shipped with zero bash. The10
# LLM still writes/reads the checkpoint CONTENT; these helpers make the11
# path handling, naming and discovery deterministic.12
#13
# context_save_path [label] → echoes the canonical new checkpoint path14
# (creates the directory; caller writes the file)15
# context_list [branch] → all checkpoints newest-first (new + legacy dirs)16
# context_latest [branch] → newest checkpoint path (empty if none)… omitted uncited lines …
18
# Scope: checkpoints live in <repo>/.claude/runtime/sessions/<branch>/ (v5,19
# ADR-0005); the legacy ~/.lintel/sessions/<branch>/ is read-only fallback20
# until the grace window closes (2026-09-12).22
_CONTEXT_BIN_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"23
# shellcheck disable=SC109124
command -v lintel_sessions_dir >/dev/null 2>&1 || source "$_CONTEXT_BIN_DIR/../lib/paths.sh"26
LINTEL_HOME="${LINTEL_HOME:-$HOME/.lintel}"28
_context_branch() {29
git rev-parse --abbrev-ref HEAD 2>/dev/null || printf 'no-branch'30
}32
_context_repo_slug() {33
basename "$(lintel_repo_root 2>/dev/null || pwd)"34
}36
# Canonical path for a NEW checkpoint. Caller writes content to it.37
# Args: [label]38
context_save_path() {39
local label="${1:-}"40
local branch dir ts slug41
branch="$(_context_branch)"42
dir="$(lintel_sessions_dir 2>/dev/null)" || dir="$LINTEL_HOME/sessions"43
dir="$dir/$branch"44
mkdir -p "$dir" 2>/dev/null || true45
ts=$(date +"%Y%m%d-%H%M%S")46
slug="$(_context_repo_slug)"47
# slugify the label: separators/spaces → '-', keep it filename-safe48
label=$(printf '%s' "$label" | tr ' /\\' '---' | tr -cd 'A-Za-z0-9._-')49
if [ -n "$label" ]; then50
printf '%s/%s-%s-%s-context-save.md' "$dir" "$ts" "$slug" "$label"51
else52
printf '%s/%s-%s-context-save.md' "$dir" "$ts" "$slug"53
fi54
}56
# All checkpoints for a branch, newest first. Includes the legacy global dir57
# (read-only) during the grace window.58
# Args: [branch] (default: current)59
context_list() {60
local branch="${1:-$(_context_branch)}"61
local newdir62
newdir="$(lintel_sessions_dir 2>/dev/null)" || newdir=""63
{64
[ -n "$newdir" ] && [ -d "$newdir/$branch" ] && \65
find "$newdir/$branch" -maxdepth 1 -name '*-context-save.md' 2>/dev/null66
# Legacy dir only when it is NOT what lintel_sessions_dir already resolved67
# to (un-migrated repos resolve THERE — listing it twice double-counts).68
if [ "$newdir" != "$LINTEL_HOME/sessions" ] && [ -d "$LINTEL_HOME/sessions/$branch" ]; then69
find "$LINTEL_HOME/sessions/$branch" -maxdepth 1 -name '*-context-save.md' 2>/dev/null # legacy-fallback-ok70
fi71
} | while IFS= read -r f; do72
# prefix with basename for chronological sort (timestamps lead the name)73
printf '%s\t%s\n' "$(basename "$f")" "$f"74
done | sort -r | cut -f2 | awk '!seen[$0]++'