feat(templates): add isolated agentTurn and systemEvent cron templates
This commit is contained in:
parent
195fcc2517
commit
51371b18ce
3 changed files with 236 additions and 0 deletions
42
scripts/templates/cron/system-event.sh
Normal file
42
scripts/templates/cron/system-event.sh
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#!/bin/bash
|
||||
# System Event: Inject a text event into an existing Claude Code session.
|
||||
# Lighter than agentTurn — does not create a new session.
|
||||
#
|
||||
# Bash 3.2 compatible.
|
||||
#
|
||||
# Usage: ./system-event.sh "session-name" "Event text to inject"
|
||||
#
|
||||
# Placeholders:
|
||||
# {{WORKING_DIR}} - absolute path to project directory
|
||||
|
||||
WORKING_DIR="{{WORKING_DIR}}"
|
||||
SESSION_NAME="${1:-}"
|
||||
EVENT_TEXT="${2:-}"
|
||||
|
||||
if [ -z "$SESSION_NAME" ] || [ -z "$EVENT_TEXT" ]; then
|
||||
echo "Usage: $0 <session-name> <event-text>"
|
||||
echo "Example: $0 'agent:researcher:turn' 'New data available in /data/inbox'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
LOG_DIR="$WORKING_DIR/logs"
|
||||
mkdir -p "$LOG_DIR"
|
||||
|
||||
TIMESTAMP=$(date -u +%Y-%m-%dT%H:%M:%SZ)
|
||||
echo "$TIMESTAMP | system-event | INJECT: $SESSION_NAME -- $EVENT_TEXT" >> "$LOG_DIR/system-event.log"
|
||||
|
||||
cd "$WORKING_DIR"
|
||||
|
||||
# Resume the named session and inject the event
|
||||
OUTPUT=$(claude --resume "$SESSION_NAME" -p "$EVENT_TEXT" \
|
||||
--output-format text \
|
||||
--max-turns 3 2>&1)
|
||||
|
||||
EXIT_CODE=$?
|
||||
TIMESTAMP=$(date -u +%Y-%m-%dT%H:%M:%SZ)
|
||||
|
||||
if [ "$EXIT_CODE" -eq 0 ]; then
|
||||
echo "$TIMESTAMP | system-event | DELIVERED: $SESSION_NAME (exit $EXIT_CODE)" >> "$LOG_DIR/system-event.log"
|
||||
else
|
||||
echo "$TIMESTAMP | system-event | FAILED: $SESSION_NAME (exit $EXIT_CODE)" >> "$LOG_DIR/system-event.log"
|
||||
fi
|
||||
Loading…
Add table
Add a link
Reference in a new issue