mirror of
https://github.com/harivansh-afk/nix.git
synced 2026-04-17 03:03:47 +00:00
sync/search agent history (#40)
This commit is contained in:
parent
1860fa6dcb
commit
320ae1332e
4 changed files with 115 additions and 0 deletions
6
justfile
6
justfile
|
|
@ -31,5 +31,11 @@ secrets-sync:
|
||||||
sync-browser-auth:
|
sync-browser-auth:
|
||||||
./scripts/sync-bw-browser-auth.sh
|
./scripts/sync-bw-browser-auth.sh
|
||||||
|
|
||||||
|
sync-agent-history:
|
||||||
|
./scripts/sync-agent-history.sh
|
||||||
|
|
||||||
|
search-agent-history query='':
|
||||||
|
./scripts/search-agent-history.sh "{{query}}"
|
||||||
|
|
||||||
switch-netty:
|
switch-netty:
|
||||||
ssh root@netty "nixos-rebuild switch --flake github:harivansh-afk/nix#netty --refresh"
|
ssh root@netty "nixos-rebuild switch --flake github:harivansh-afk/nix#netty --refresh"
|
||||||
|
|
|
||||||
61
scripts/search-agent-history-remote.sh
Executable file
61
scripts/search-agent-history-remote.sh
Executable file
|
|
@ -0,0 +1,61 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
root="${AGENT_HISTORY_ROOT:-$HOME/.local/share/agent-history/raw}"
|
||||||
|
initial_query="${INITIAL_QUERY:-}"
|
||||||
|
|
||||||
|
if [[ ! -d "$root" ]]; then
|
||||||
|
printf 'Agent history root not found: %s\n' "$root" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
search_script="$(mktemp)"
|
||||||
|
cleanup() {
|
||||||
|
rm -f "$search_script"
|
||||||
|
}
|
||||||
|
trap cleanup EXIT
|
||||||
|
|
||||||
|
cat > "$search_script" <<'EOF'
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
root="${AGENT_HISTORY_ROOT:?}"
|
||||||
|
query="${1:-}"
|
||||||
|
|
||||||
|
if [[ -z "$query" ]]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
rg --json --line-number --smart-case --glob '*.jsonl' -- "$query" "$root" 2>/dev/null \
|
||||||
|
| jq -r '
|
||||||
|
select(.type == "match")
|
||||||
|
| [
|
||||||
|
.data.path.text,
|
||||||
|
(.data.line_number | tostring),
|
||||||
|
(.data.lines.text | gsub("[\r\n\t]+"; " "))
|
||||||
|
]
|
||||||
|
| @tsv
|
||||||
|
'
|
||||||
|
EOF
|
||||||
|
|
||||||
|
chmod +x "$search_script"
|
||||||
|
export AGENT_HISTORY_ROOT="$root"
|
||||||
|
|
||||||
|
fzf --phony --ansi --disabled \
|
||||||
|
--query "$initial_query" \
|
||||||
|
--prompt 'history> ' \
|
||||||
|
--delimiter $'\t' \
|
||||||
|
--with-nth=1,2,3 \
|
||||||
|
--preview '
|
||||||
|
file=$(printf "%s" {} | cut -f1)
|
||||||
|
line=$(printf "%s" {} | cut -f2)
|
||||||
|
[[ -n "$file" ]] || exit 0
|
||||||
|
[[ "$line" =~ ^[0-9]+$ ]] || line=1
|
||||||
|
start=$(( line > 20 ? line - 20 : 1 ))
|
||||||
|
end=$(( line + 20 ))
|
||||||
|
sed -n "${start},${end}p" "$file"
|
||||||
|
' \
|
||||||
|
--preview-window=right:70%:wrap \
|
||||||
|
--header 'Type to search archived Claude and Codex logs on netty' \
|
||||||
|
--bind "start:reload:$search_script {q} || true" \
|
||||||
|
--bind "change:reload:sleep 0.1; $search_script {q} || true"
|
||||||
12
scripts/search-agent-history.sh
Executable file
12
scripts/search-agent-history.sh
Executable file
|
|
@ -0,0 +1,12 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
remote="${AGENT_HISTORY_REMOTE:-netty}"
|
||||||
|
remote_root="${AGENT_HISTORY_REMOTE_ROOT:-/home/rathi/.local/share/agent-history/raw}"
|
||||||
|
initial_query="${1:-}"
|
||||||
|
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
|
||||||
|
remote_root_q="$(printf '%q' "$remote_root")"
|
||||||
|
initial_query_q="$(printf '%q' "$initial_query")"
|
||||||
|
|
||||||
|
ssh -t "$remote" "AGENT_HISTORY_ROOT=${remote_root_q} INITIAL_QUERY=${initial_query_q} bash -s" < "${script_dir}/search-agent-history-remote.sh"
|
||||||
36
scripts/sync-agent-history.sh
Executable file
36
scripts/sync-agent-history.sh
Executable file
|
|
@ -0,0 +1,36 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
remote="${AGENT_HISTORY_REMOTE:-netty}"
|
||||||
|
remote_root="${AGENT_HISTORY_REMOTE_ROOT:-/home/rathi/.local/share/agent-history/raw/darwin}"
|
||||||
|
|
||||||
|
remote_root_q="$(printf '%q' "$remote_root")"
|
||||||
|
|
||||||
|
ssh "$remote" "mkdir -p \
|
||||||
|
${remote_root_q}/claude \
|
||||||
|
${remote_root_q}/claude/transcripts \
|
||||||
|
${remote_root_q}/claude/projects \
|
||||||
|
${remote_root_q}/codex \
|
||||||
|
${remote_root_q}/codex/sessions"
|
||||||
|
|
||||||
|
sync_path() {
|
||||||
|
local src="$1"
|
||||||
|
local dest="$2"
|
||||||
|
|
||||||
|
if [[ ! -e "$src" ]]; then
|
||||||
|
printf 'Skipping missing path: %s\n' "$src"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf 'Syncing %s -> %s:%s\n' "$src" "$remote" "$dest"
|
||||||
|
rsync -az "$src" "$remote:$dest"
|
||||||
|
}
|
||||||
|
|
||||||
|
sync_path "$HOME/.claude/history.jsonl" "${remote_root}/claude/"
|
||||||
|
sync_path "$HOME/.claude/transcripts/" "${remote_root}/claude/transcripts/"
|
||||||
|
sync_path "$HOME/.claude/projects/" "${remote_root}/claude/projects/"
|
||||||
|
sync_path "$HOME/.codex/history.jsonl" "${remote_root}/codex/"
|
||||||
|
sync_path "$HOME/.codex/session_index.jsonl" "${remote_root}/codex/"
|
||||||
|
sync_path "$HOME/.codex/sessions/" "${remote_root}/codex/sessions/"
|
||||||
|
|
||||||
|
printf 'Agent history sync complete.\n'
|
||||||
Loading…
Add table
Add a link
Reference in a new issue