feat: --goal launch receipts for ccx session attribution - #516
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a94fcaaf22
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| printf '{"ts":"%s","goal":"%s","agent":"%s","cwd":"%s","container":"%s","source":"deva"}\n' \ | ||
| "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$GOAL" "${ACTIVE_AGENT:-}" "$(pwd)" "$CONTAINER_NAME" \ |
There was a problem hiding this comment.
Escape cwd before writing the JSONL receipt
When the workspace's absolute path contains a double quote, backslash, or newline—each valid in a Linux filename—$(pwd) is interpolated directly into the JSON string without escaping. This produces malformed or split JSONL records, so ccx cannot parse the receipt and the new session-attribution feature silently fails for that workspace; serialize these fields with a JSON encoder rather than printf interpolation.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Pull request overview
Adds “launch receipts” to deva.sh so a launch can be attributed to a goal in downstream ccx session reporting. This introduces a new --goal SLUG flag that validates a slug and stamps the launch both in-container (DEVA_GOAL) and host-side (JSONL receipt under the ccx data directory), with documentation updates in the changelog and dev logs.
Changes:
- Add
--goal SLUGparsing/validation and exportDEVA_GOALinto the container (create-time and optional attach-time restamp). - Append a host-side JSONL launch receipt to
$XDG_DATA_HOME/ccx/launches/YYYY-MM-DD.jsonlafter the--dry-rungate, warning-only on failure. - Document the feature in
CHANGELOG.mdandDEV-LOGS.md.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| deva.sh | Implements --goal, exports DEVA_GOAL, and writes host-side JSONL launch receipts. |
| DEV-LOGS.md | Adds a dev log entry describing the new --goal launch receipt behavior. |
| CHANGELOG.md | Notes the new feature under Unreleased. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| write_launch_receipt() { | ||
| [ -n "$GOAL" ] || return 0 | ||
| local dir="${XDG_DATA_HOME:-$HOME/.local/share}/ccx/launches" | ||
| if ! mkdir -p "$dir" 2>/dev/null; then | ||
| echo "warning: cannot create $dir; skipping launch receipt" >&2 | ||
| return 0 | ||
| fi | ||
| printf '{"ts":"%s","goal":"%s","agent":"%s","cwd":"%s","container":"%s","source":"deva"}\n' \ | ||
| "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$GOAL" "${ACTIVE_AGENT:-}" "$(pwd)" "$CONTAINER_NAME" \ | ||
| >>"$dir/$(date -u +%Y-%m-%d).jsonl" 2>/dev/null || | ||
| echo "warning: failed to write launch receipt" >&2 | ||
| } |
| if [ "$AUTH_PROVISION_MODE" = true ]; then | ||
| docker exec -e "$_trace_env" "${DOCKER_TERMINAL_ARGS[@]}" "$CONTAINER_NAME" /usr/local/bin/docker-entrypoint.sh "${AGENT_COMMAND[@]}" || true | ||
| docker exec -e "$_trace_env" ${_goal_env[@]+"${_goal_env[@]}"} "${DOCKER_TERMINAL_ARGS[@]}" "$CONTAINER_NAME" /usr/local/bin/docker-entrypoint.sh "${AGENT_COMMAND[@]}" || true | ||
| finish_auth_provision | ||
| else | ||
| exec docker exec -e "$_trace_env" "${DOCKER_TERMINAL_ARGS[@]}" "$CONTAINER_NAME" /usr/local/bin/docker-entrypoint.sh "${AGENT_COMMAND[@]}" | ||
| exec docker exec -e "$_trace_env" ${_goal_env[@]+"${_goal_env[@]}"} "${DOCKER_TERMINAL_ARGS[@]}" "$CONTAINER_NAME" /usr/local/bin/docker-entrypoint.sh "${AGENT_COMMAND[@]}" |
| --goal) | ||
| if [ $((i + 1)) -ge ${#incoming[@]} ]; then | ||
| echo "error: --goal requires a slug" >&2 | ||
| exit 1 | ||
| fi |
| write_launch_receipt() { | ||
| [ -n "$GOAL" ] || return 0 | ||
| local dir="${XDG_DATA_HOME:-$HOME/.local/share}/ccx/launches" | ||
| if ! mkdir -p "$dir" 2>/dev/null; then | ||
| echo "warning: cannot create $dir; skipping launch receipt" >&2 |
- validate slug, export DEVA_GOAL (create env; attach restamps on fresh --goal only) - append JSONL receipt to $XDG_DATA_HOME/ccx/launches/ after the DRY_RUN gate; warning-only on failure, never blocks a launch - receipts are evidence: ccx data dir, not the ops ledger; ccx joins receipt->session by cwd+time (ccx side ships separately) Refs #499 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
a94fcaa to
01dec9e
Compare
|
Claude encountered an error after 1s —— View job I'll analyze this and get back to you. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (3)
deva.sh:4242
- The launch receipt is formatted as JSON but values like
cwd(and potentially agent/container) are not JSON-escaped, so paths containing quotes/backslashes/newlines will produce invalid JSON. Also,dateis called twice, which can put a receipt into a different YYYY-MM-DD file than itstsif the call crosses midnight UTC.
printf '{"ts":"%s","goal":"%s","agent":"%s","cwd":"%s","container":"%s","source":"deva"}\n' \
"$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$GOAL" "${ACTIVE_AGENT:-}" "$(pwd)" "$CONTAINER_NAME" \
>>"$dir/$(date -u +%Y-%m-%d).jsonl" 2>/dev/null ||
echo "warning: failed to write launch receipt" >&2
deva.sh:4329
- The optional
_goal_envarray is expanded unquoted in thedocker execcalls. Even thoughGOALis currently validated, quoting the array expansion avoids accidental word-splitting/globbing if this is refactored later.
docker exec -e "$_trace_env" ${_goal_env[@]+"${_goal_env[@]}"} "${DOCKER_TERMINAL_ARGS[@]}" "$CONTAINER_NAME" /usr/local/bin/docker-entrypoint.sh "${AGENT_COMMAND[@]}" || true
finish_auth_provision
else
exec docker exec -e "$_trace_env" ${_goal_env[@]+"${_goal_env[@]}"} "${DOCKER_TERMINAL_ARGS[@]}" "$CONTAINER_NAME" /usr/local/bin/docker-entrypoint.sh "${AGENT_COMMAND[@]}"
deva.sh:161
- The help text for
--goaladvertises the slug pattern as([a-z0-9-]), but the parser enforces^[a-z0-9][a-z0-9-]*$. Updating the usage text to match the actual validation avoids confusing users.
--goal SLUG Stamp this launch with a goal slug ([a-z0-9-]):
Launch receipts (#499): stamp intent at launch so ccx sessions stop
being born orphans.
--goal SLUGvalidates[a-z0-9][a-z0-9-]*, exportsDEVA_GOALinto the container (create-time env; attach restamps only when a
fresh
--goalis given)$XDG_DATA_HOME/ccx/launches/YYYY-MM-DD.jsonlwith ts, goal, agent,cwd, container, source; ccx joins receipt->session by cwd+time
it never blocks a launch; no
--goal= zero behavior changeccx-side join ships separately. CHANGELOG and DEV-LOGS included.
Closes #499
🤖 Generated with Claude Code