blob: 670a61076f55c5443ef68939ca91589fd547b3a3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
#!/usr/bin/env bash
# session-context-path — print the active session-context path for this agent.
#
# Single-agent (AI_AGENT_ID unset or empty): .ai/session-context.org — the
# historical singleton path, unchanged, so one-agent-per-project sessions
# behave exactly as before (Codex spec's compatibility rule).
#
# Multi-agent (AI_AGENT_ID set): .ai/session-context.d/<id>.org, so two agents
# running in the same project at the same time keep separate session logs
# instead of clobbering the singleton. The id is sanitized to filename-safe
# characters so a stray value can't escape the .d/ directory.
#
# The id must be unique per run; the spawner appends an epoch on the tail
# (recommended shape host.project.runtime.<epoch>) so a re-run of the same
# logical agent gets a fresh anchor instead of resolving to a prior run's
# leftover. The epoch is never minted here: this resolver is called many times
# per session and must return the same path each call, so it can't generate a
# new value. See protocols.org "Agent-scoped path". A bare, reused id (just
# "codex") is the bug that motivated this note.
#
# Workflows call this to resolve the path; both startup (existence check) and
# wrap-up (rename source) read/write through it. Callers should fall back to
# .ai/session-context.org if this script isn't present yet (older checkouts
# mid-sync).
set -euo pipefail
id="${AI_AGENT_ID:-}"
if [ -n "$id" ]; then
safe=$(printf '%s' "$id" | tr -c 'A-Za-z0-9._-' '_')
printf '.ai/session-context.d/%s.org\n' "$safe"
else
printf '.ai/session-context.org\n'
fi
|