Source index · Technical reference · Home

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 bash
2# component: lintel-context
3# implements: ADR-0006
4# intent: docs/concepts/memory-v2.md
5# constraints: helpers own paths/naming/discovery; content stays LLM-written
6# last_intent_review: 2026-06-12
7#
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. The
10# LLM still writes/reads the checkpoint CONTENT; these helpers make the
11# path handling, naming and discovery deterministic.
13# context_save_path [label] → echoes the canonical new checkpoint path
14# (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 fallback
20# until the grace window closes (2026-09-12).
22_CONTEXT_BIN_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
23# shellcheck disable=SC1091
24command -v lintel_sessions_dir >/dev/null 2>&1 || source "$_CONTEXT_BIN_DIR/../lib/paths.sh"
26LINTEL_HOME="${LINTEL_HOME:-$HOME/.lintel}"
28_context_branch() {
29 git rev-parse --abbrev-ref HEAD 2>/dev/null || printf 'no-branch'
32_context_repo_slug() {
33 basename "$(lintel_repo_root 2>/dev/null || pwd)"
36# Canonical path for a NEW checkpoint. Caller writes content to it.
37# Args: [label]
38context_save_path() {
39 local label="${1:-}"
40 local branch dir ts slug
41 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 || true
45 ts=$(date +"%Y%m%d-%H%M%S")
46 slug="$(_context_repo_slug)"
47 # slugify the label: separators/spaces → '-', keep it filename-safe
48 label=$(printf '%s' "$label" | tr ' /\\' '---' | tr -cd 'A-Za-z0-9._-')
49 if [ -n "$label" ]; then
50 printf '%s/%s-%s-%s-context-save.md' "$dir" "$ts" "$slug" "$label"
51 else
52 printf '%s/%s-%s-context-save.md' "$dir" "$ts" "$slug"
53 fi
56# All checkpoints for a branch, newest first. Includes the legacy global dir
57# (read-only) during the grace window.
58# Args: [branch] (default: current)
59context_list() {
60 local branch="${1:-$(_context_branch)}"
61 local newdir
62 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/null
66 # Legacy dir only when it is NOT what lintel_sessions_dir already resolved
67 # to (un-migrated repos resolve THERE — listing it twice double-counts).
68 if [ "$newdir" != "$LINTEL_HOME/sessions" ] && [ -d "$LINTEL_HOME/sessions/$branch" ]; then
69 find "$LINTEL_HOME/sessions/$branch" -maxdepth 1 -name '*-context-save.md' 2>/dev/null # legacy-fallback-ok
70 fi
71 } | while IFS= read -r f; do
72 # 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]++'