8888 fi
8989 expected_title="Assist ${TARGET_REPO}#${ITEM_NUMBER} [${DISPATCH_KEY}]"
9090 owner="$(bash scripts/dispatch-receipt-owner.sh \
91- assist.yml "$expected_title" "$GITHUB_RUN_ID" assist)"
91+ assist.yml "$expected_title" "$GITHUB_RUN_ID" \
92+ "Publish trusted assist comment" "Revalidate and publish assist comment")"
9293 if [ "$owner" = "owner" ]; then
9394 echo "proceed=false" >> "$GITHUB_OUTPUT"
9495 echo "An older active or successfully executed command dispatch already exists; skipping duplicate assist."
@@ -176,6 +177,9 @@ jobs:
176177 filter : blob:none
177178 persist-credentials : false
178179
180+ - uses : ./.github/actions/setup-action-ledger
181+ id : assist-action-ledger
182+
179183 - uses : ./.github/actions/setup-pnpm
180184 with :
181185 build-script : build
@@ -246,6 +250,7 @@ jobs:
246250 echo "generation_attempt=$GITHUB_RUN_ATTEMPT" >> "$GITHUB_OUTPUT"
247251
248252 - name : Upload assist artifact
253+ if : ${{ steps.generate.outcome == 'success' }}
249254 uses : actions/upload-artifact@v7
250255 with :
251256 name : clawsweeper-assist-${{ github.run_id }}-${{ steps.generate.outputs.generation_attempt }}
@@ -254,10 +259,20 @@ jobs:
254259 if-no-files-found : error
255260 retention-days : 1
256261
262+ - name : Upload assist generation action ledger
263+ if : ${{ always() && steps.assist-action-ledger.outcome == 'success' }}
264+ uses : actions/upload-artifact@v7
265+ with :
266+ name : action-ledger-assist-${{ github.run_id }}-${{ github.run_attempt }}
267+ path : ${{ steps.assist-action-ledger.outputs.output-root }}/**
268+ include-hidden-files : true
269+ if-no-files-found : warn
270+ retention-days : 90
271+
257272 publish :
258273 name : Publish trusted assist comment
259274 needs : assist
260- if : ${{ needs.assist.result == 'success ' }}
275+ if : ${{ always() && needs.assist.result != 'skipped ' }}
261276 runs-on : ubuntu-latest
262277 timeout-minutes : 5
263278 steps :
@@ -267,15 +282,33 @@ jobs:
267282 filter : blob:none
268283 persist-credentials : false
269284
285+ - uses : ./.github/actions/setup-action-ledger
286+ id : publish-action-ledger
287+
288+ - name : Create state token
289+ id : state-token
290+ uses : ./.github/actions/create-state-token
291+ with :
292+ client-id : ${{ env.CLAWSWEEPER_APP_CLIENT_ID }}
293+ private-key : ${{ secrets.CLAWSWEEPER_APP_PRIVATE_KEY }}
294+
295+ - uses : ./.github/actions/setup-state
296+ id : setup-state
297+ with :
298+ token : ${{ steps.state-token.outputs.token }}
299+
270300 - uses : ./.github/actions/setup-pnpm
301+ id : setup-pnpm
271302 with :
272303 build-script : build
273304
274305 - name : Verify exact workflow source
306+ if : ${{ needs.assist.result == 'success' }}
275307 run : test "$(git rev-parse HEAD)" = "$GITHUB_SHA"
276308
277309 - name : Resolve validated target repository
278310 id : target
311+ if : ${{ needs.assist.result == 'success' }}
279312 env :
280313 TARGET_REPO : ${{ github.event.client_payload.target_repo || inputs.target_repo }}
281314 run : |
@@ -288,12 +321,22 @@ jobs:
288321 } >> "$GITHUB_OUTPUT"
289322
290323 - name : Download assist artifact
324+ if : ${{ needs.assist.result == 'success' }}
291325 uses : actions/download-artifact@v8
292326 with :
293327 name : clawsweeper-assist-${{ github.run_id }}-${{ needs.assist.outputs.generation_attempt }}
294328 path : .artifacts/publish
295329
330+ - name : Download assist generation action ledger
331+ id : download-assist-action-ledger
332+ continue-on-error : true
333+ uses : actions/download-artifact@v8
334+ with :
335+ name : action-ledger-assist-${{ github.run_id }}-${{ needs.assist.outputs.generation_attempt }}
336+ path : .clawsweeper-repair/action-ledger-download/assist
337+
296338 - name : Validate untrusted assist artifact
339+ if : ${{ needs.assist.result == 'success' }}
297340 env :
298341 TARGET_REPO : ${{ steps.target.outputs.target_repo }}
299342 ITEM_NUMBER : ${{ github.event.client_payload.item_number || inputs.item_number }}
@@ -323,6 +366,7 @@ jobs:
323366
324367 - name : Create narrow GitHub App write token
325368 id : write_token
369+ if : ${{ needs.assist.result == 'success' }}
326370 uses : actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
327371 with :
328372 client-id : ${{ env.CLAWSWEEPER_APP_CLIENT_ID }}
@@ -333,6 +377,8 @@ jobs:
333377 permission-pull-requests : write
334378
335379 - name : Revalidate and publish assist comment
380+ id : publish-comment
381+ if : ${{ needs.assist.result == 'success' }}
336382 env :
337383 GH_TOKEN : ${{ steps.write_token.outputs.token }}
338384 TARGET_REPO : ${{ steps.target.outputs.target_repo }}
@@ -361,3 +407,45 @@ jobs:
361407 --codex-reasoning-effort "$REASONING_EFFORT" \
362408 --run-id "$GITHUB_RUN_ID" \
363409 --run-attempt "$GENERATION_ATTEMPT"
410+
411+ - name : Publish immutable assist action ledger
412+ if : ${{ always() && steps.setup-state.outcome == 'success' && steps.setup-pnpm.outcome == 'success' && steps.publish-action-ledger.outcome == 'success' }}
413+ env :
414+ GENERATION_ATTEMPT : ${{ needs.assist.outputs.generation_attempt }}
415+ GENERATION_LEDGER_OUTCOME : ${{ steps.download-assist-action-ledger.outcome }}
416+ run : |
417+ set -euo pipefail
418+ test -n "${CLAWSWEEPER_STATE_DIR:-}"
419+ test -n "$GENERATION_ATTEMPT"
420+ event_paths_file=".artifacts/assist-action-ledger-paths.txt"
421+ mkdir -p .artifacts
422+ : > "$event_paths_file"
423+ if [ "$GENERATION_LEDGER_OUTCOME" = "success" ]; then
424+ pnpm run --silent publish-action-events -- \
425+ --source-root .clawsweeper-repair/action-ledger-download/assist \
426+ --state-root "$CLAWSWEEPER_STATE_DIR" \
427+ --expected-run-attempt "$GENERATION_ATTEMPT" \
428+ --expected-producer-job assist |
429+ jq -r '.paths[]?' >> "$event_paths_file"
430+ fi
431+ if [ -d "$CLAWSWEEPER_ACTION_LEDGER_OUTPUT_ROOT/ledger" ]; then
432+ pnpm run --silent publish-action-events -- \
433+ --source-root "$CLAWSWEEPER_ACTION_LEDGER_OUTPUT_ROOT" \
434+ --state-root "$CLAWSWEEPER_STATE_DIR" \
435+ --expected-producer-job "$GITHUB_JOB" |
436+ jq -r '.paths[]?' >> "$event_paths_file"
437+ fi
438+ sort -u -o "$event_paths_file" "$event_paths_file"
439+ if [ ! -s "$event_paths_file" ]; then
440+ echo "No immutable assist action events to publish."
441+ exit 0
442+ fi
443+ while IFS= read -r event_path; do
444+ durable_event_path="$CLAWSWEEPER_STATE_DIR/$event_path"
445+ test -f "$durable_event_path"
446+ mkdir -p "$(dirname "$event_path")"
447+ cp "$durable_event_path" "$event_path"
448+ done < "$event_paths_file"
449+ node dist/clawsweeper.js publish-action-event-paths \
450+ --paths-file "$event_paths_file" \
451+ --message "chore: append assist action ledger"
0 commit comments