- task schema: optional session (named id) -> persistent session dir at dataRoot/sessions/<name>, isolated per name - pi adapter: --session-dir when declared (ephemeral --no-session stays the default otherwise); -c resumes the most recent session when present - compose passthrough; result.json records session - fixtures: tasks/session-demo-1.json (teach) + session-demo-2.json (recall) - E2E: teach -> REMEMBERED + host-side session JSONL; resume -> recalled 'mosaico' exactly; single continued session file Closes #22, closes #23
56 lines
2.1 KiB
Bash
56 lines
2.1 KiB
Bash
#!/bin/sh
|
|
# Pi adapter: implements the Mosaic adapter contract for the pinned
|
|
# @earendil-works/pi-coding-agent CLI.
|
|
#
|
|
# Contract: see /opt/mosaic/adapters/README.md. stdout = response only.
|
|
set -eu
|
|
|
|
[ -n "${MOSAIC_SYSTEM_PROMPT_FILE:-}" ] || { echo "pi adapter: MOSAIC_SYSTEM_PROMPT_FILE is required" >&2; exit 2; }
|
|
[ -n "${MOSAIC_REQUEST:-}" ] || { echo "pi adapter: MOSAIC_REQUEST is required" >&2; exit 2; }
|
|
[ -r "$MOSAIC_SYSTEM_PROMPT_FILE" ] || { echo "pi adapter: system prompt not readable: $MOSAIC_SYSTEM_PROMPT_FILE" >&2; exit 2; }
|
|
|
|
: "${PI_PROVIDER:?pi adapter: PI_PROVIDER is required}"
|
|
: "${PI_MODEL:?pi adapter: PI_MODEL is required}"
|
|
|
|
# Workspace (M5): run inside the provided workspace when present.
|
|
if [ -n "${MOSAIC_WORKSPACE:-}" ]; then
|
|
mkdir -p "$MOSAIC_WORKSPACE"
|
|
cd "$MOSAIC_WORKSPACE"
|
|
fi
|
|
|
|
# Session (M6): persistent named session directory; resume the most recent
|
|
# session in that directory when one exists (pi documented flags).
|
|
# Default remains ephemeral (--no-session) when no session is declared.
|
|
SESSION_FLAGS="--no-session"
|
|
if [ -n "${MOSAIC_SESSION_DIR:-}" ]; then
|
|
mkdir -p "$MOSAIC_SESSION_DIR"
|
|
SESSION_FLAGS="--session-dir $MOSAIC_SESSION_DIR"
|
|
if [ -n "$(ls -A "$MOSAIC_SESSION_DIR" 2>/dev/null)" ]; then
|
|
SESSION_FLAGS="$SESSION_FLAGS -c"
|
|
fi
|
|
fi
|
|
|
|
# Capabilities (M5): explicit allowlist or no tools.
|
|
TOOLS_FLAG="--no-tools"
|
|
[ -n "${MOSAIC_TOOLS:-}" ] && TOOLS_FLAG="--tools $MOSAIC_TOOLS"
|
|
|
|
# All flags documented in the pi package README (CLI Reference):
|
|
# -p/--print noninteractive: print the response and exit
|
|
# --system-prompt replace the default prompt with the generated one
|
|
# --no-* no ambient context/skills/extensions/templates/themes
|
|
# --no-session ephemeral; TOOLS_FLAG per capabilities
|
|
# --offline no startup network operations (update checks/telemetry)
|
|
exec pi \
|
|
--offline \
|
|
--no-extensions \
|
|
--no-skills \
|
|
--no-prompt-templates \
|
|
--no-themes \
|
|
--no-context-files \
|
|
$TOOLS_FLAG \
|
|
$SESSION_FLAGS \
|
|
--provider "$PI_PROVIDER" \
|
|
--model "$PI_MODEL" \
|
|
--system-prompt "$(cat "$MOSAIC_SYSTEM_PROMPT_FILE")" \
|
|
-p "$MOSAIC_REQUEST"
|