Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions .github/actions/pm-dispatch-queue/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: pm-dispatch-queue
description: >-
Enqueue work via pm-dispatch (POST /v1/tasks), optionally tracked by a
GitHub issue. The calling job MUST grant `permissions: id-token: write` —
this action mints a GitHub Actions OIDC token (audience pm-dispatch) to
authenticate.
inputs:
repo:
description: "Target repo (owner/name). Any allowlisted repo may target any allowlisted repo."
required: false
default: ${{ github.repository }}
title:
description: "Queue task title."
required: true
prompt:
description: "The work text (sent as the task prompt/body)."
required: true
model:
description: 'Optional model hint, "provider/model" (stored as the payload model hint only).'
required: false
default: ""
priority:
description: "Optional priority: 10-90 or critical|high|normal|low."
required: false
default: ""
kind:
description: "Optional task kind: triage|small_fix|pr_shepherd|ci_investigation."
required: false
default: ""
issue:
description: '"true" to create a tracking issue in the target repo (ignored when issue_number is set).'
required: false
default: "true"
issue_number:
description: "Optional existing issue number in the target repo to attach to instead of creating an issue. Takes precedence over issue."
required: false
default: ""
outputs:
task_id:
description: "pm-dispatch queue task id."
value: ${{ steps.dispatch.outputs.task_id }}
issue_number:
description: "Tracking/attached issue number (empty when no issue is involved)."
value: ${{ steps.dispatch.outputs.issue_number }}
issue_url:
description: "Issue URL (empty when no issue is involved)."
value: ${{ steps.dispatch.outputs.issue_url }}
runs:
using: composite
steps:
- name: Enqueue work via pm-dispatch
id: dispatch
shell: bash
env:
INPUT_REPO: ${{ inputs.repo }}
INPUT_TITLE: ${{ inputs.title }}
INPUT_PROMPT: ${{ inputs.prompt }}
INPUT_MODEL: ${{ inputs.model }}
INPUT_PRIORITY: ${{ inputs.priority }}
INPUT_KIND: ${{ inputs.kind }}
INPUT_ISSUE: ${{ inputs.issue }}
INPUT_ISSUE_NUMBER: ${{ inputs.issue_number }}
run: |
set -euo pipefail
if [ -z "${ACTIONS_ID_TOKEN_REQUEST_URL:-}" ] || [ -z "${ACTIONS_ID_TOKEN_REQUEST_TOKEN:-}" ]; then
echo "::error::pm-dispatch-queue: ACTIONS_ID_TOKEN_REQUEST_URL / ACTIONS_ID_TOKEN_REQUEST_TOKEN are not set. The calling job must grant 'permissions: id-token: write' so this action can mint an OIDC token." >&2
exit 1
fi
case "$INPUT_ISSUE" in
true|false) ;;
*) echo "::error::pm-dispatch-queue: issue must be \"true\" or \"false\", got: $INPUT_ISSUE" >&2; exit 1 ;;
esac
oidc_token="$(curl -sS -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
"${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=pm-dispatch" | jq -r '.value // empty')"
if [ -z "$oidc_token" ]; then
echo "::error::pm-dispatch-queue: failed to mint a GitHub Actions OIDC token (audience pm-dispatch)." >&2
exit 1
fi
payload="$(jq -n \
--arg repo "$INPUT_REPO" \
--arg title "$INPUT_TITLE" \
--arg prompt "$INPUT_PROMPT" \
--arg model "$INPUT_MODEL" \
--arg priority "$INPUT_PRIORITY" \
--arg kind "$INPUT_KIND" \
--argjson issue "$INPUT_ISSUE" \
'{repo: $repo, title: $title, prompt: $prompt, issue: $issue}
+ (if $model != "" then {model: $model} else {} end)
+ (if $priority != "" then {priority: $priority} else {} end)
+ (if $kind != "" then {kind: $kind} else {} end)')"
if [ -n "$INPUT_ISSUE_NUMBER" ]; then
payload="$(printf '%s' "$payload" | jq --argjson issue_number "$INPUT_ISSUE_NUMBER" '. + {issue_number: $issue_number}')"
fi
response="$(curl -sS -w $'\n%{http_code}' -X POST "https://dispatch.security.cab/v1/tasks" \
-H "Authorization: Bearer $oidc_token" \
-H "Content-Type: application/json" \
-d "$payload")"
http_code="${response##*$'\n'}"
body="${response%$'\n'*}"
if [ "$http_code" -lt 200 ] || [ "$http_code" -ge 300 ]; then
echo "::error::pm-dispatch-queue: pm-dispatch POST /v1/tasks failed (HTTP $http_code):" >&2
echo "$body" >&2
exit 1
fi
echo "$body"
task_id="$(printf '%s' "$body" | jq -r '.task_id // empty')"
issue_number="$(printf '%s' "$body" | jq -r '.issue_number // empty')"
issue_url="$(printf '%s' "$body" | jq -r '.issue_url // empty')"
if [ -z "$issue_url" ] && [ -n "$issue_number" ]; then
issue_url="https://github.com/${INPUT_REPO}/issues/${issue_number}"
fi
{
echo "task_id=$task_id"
echo "issue_number=$issue_number"
echo "issue_url=$issue_url"
} >> "$GITHUB_OUTPUT"
112 changes: 112 additions & 0 deletions .github/actions/pm-dispatch-start/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
name: pm-dispatch-start
description: >-
Launch a tracked OpenCode session via pm-dispatch (POST /v1/sessions).
The calling job MUST grant `permissions: id-token: write` — this action
mints a GitHub Actions OIDC token (audience pm-dispatch) to authenticate.
inputs:
repo:
description: "Target repo (owner/name). Any allowlisted repo may target any allowlisted repo."
required: false
default: ${{ github.repository }}
title:
description: "Session / tracking-issue title."
required: true
prompt:
description: "Work for the OpenCode session."
required: true
model:
description: 'Optional model hint, "provider/model".'
required: false
default: ""
priority:
description: "Optional priority: 10-90 or critical|high|normal|low."
required: false
default: ""
kind:
description: "Optional task kind hint (passed through to pm-dispatch)."
required: false
default: ""
wait:
description: '"true" to wait for the launch, "false" to return after the enqueue.'
required: false
default: "true"
outputs:
task_id:
description: "pm-dispatch queue task id."
value: ${{ steps.dispatch.outputs.task_id }}
session_id:
description: "OpenCode session id (empty when wait is false)."
value: ${{ steps.dispatch.outputs.session_id }}
issue_number:
description: "Tracking issue number (empty when no issue was created)."
value: ${{ steps.dispatch.outputs.issue_number }}
issue_url:
description: "Tracking issue URL (empty when no issue was created)."
value: ${{ steps.dispatch.outputs.issue_url }}
runs:
using: composite
steps:
- name: Launch a tracked OpenCode session via pm-dispatch
id: dispatch
shell: bash
env:
INPUT_REPO: ${{ inputs.repo }}
INPUT_TITLE: ${{ inputs.title }}
INPUT_PROMPT: ${{ inputs.prompt }}
INPUT_MODEL: ${{ inputs.model }}
INPUT_PRIORITY: ${{ inputs.priority }}
INPUT_KIND: ${{ inputs.kind }}
INPUT_WAIT: ${{ inputs.wait }}
run: |
set -euo pipefail
if [ -z "${ACTIONS_ID_TOKEN_REQUEST_URL:-}" ] || [ -z "${ACTIONS_ID_TOKEN_REQUEST_TOKEN:-}" ]; then
echo "::error::pm-dispatch-start: ACTIONS_ID_TOKEN_REQUEST_URL / ACTIONS_ID_TOKEN_REQUEST_TOKEN are not set. The calling job must grant 'permissions: id-token: write' so this action can mint an OIDC token." >&2
exit 1
fi
case "$INPUT_WAIT" in
true|false) ;;
*) echo "::error::pm-dispatch-start: wait must be \"true\" or \"false\", got: $INPUT_WAIT" >&2; exit 1 ;;
esac
oidc_token="$(curl -sS -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
"${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=pm-dispatch" | jq -r '.value // empty')"
if [ -z "$oidc_token" ]; then
echo "::error::pm-dispatch-start: failed to mint a GitHub Actions OIDC token (audience pm-dispatch)." >&2
exit 1
fi
payload="$(jq -n \
--arg repo "$INPUT_REPO" \
--arg title "$INPUT_TITLE" \
--arg prompt "$INPUT_PROMPT" \
--arg model "$INPUT_MODEL" \
--arg priority "$INPUT_PRIORITY" \
--arg kind "$INPUT_KIND" \
--argjson wait "$INPUT_WAIT" \
'{repo: $repo, title: $title, prompt: $prompt, wait: $wait}
+ (if $model != "" then {model: $model} else {} end)
+ (if $priority != "" then {priority: $priority} else {} end)
+ (if $kind != "" then {kind: $kind} else {} end)')"
response="$(curl -sS -w $'\n%{http_code}' -X POST "https://dispatch.security.cab/v1/sessions" \
-H "Authorization: Bearer $oidc_token" \
-H "Content-Type: application/json" \
-d "$payload")"
http_code="${response##*$'\n'}"
body="${response%$'\n'*}"
if [ "$http_code" -lt 200 ] || [ "$http_code" -ge 300 ]; then
echo "::error::pm-dispatch-start: pm-dispatch POST /v1/sessions failed (HTTP $http_code):" >&2
echo "$body" >&2
exit 1
fi
echo "$body"
task_id="$(printf '%s' "$body" | jq -r '.task_id // empty')"
session_id="$(printf '%s' "$body" | jq -r '.session_id // empty')"
issue_number="$(printf '%s' "$body" | jq -r '.issue_number // empty')"
issue_url=""
if [ -n "$issue_number" ]; then
issue_url="https://github.com/${INPUT_REPO}/issues/${issue_number}"
fi
{
echo "task_id=$task_id"
echo "session_id=$session_id"
echo "issue_number=$issue_number"
echo "issue_url=$issue_url"
} >> "$GITHUB_OUTPUT"
65 changes: 61 additions & 4 deletions pm-stack/dispatch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,28 @@ for a session that launched, nor `claimed` without a session id.
"priority": 40, // optional, same mapping as above
"model": "deepseek/deepseek-chat", // optional; stored as payload.model_hint only
"issue": false, // optional; default false
"dedupe_key": "…" // optional; default: canonical key from the
"dedupe_key": "…", // optional; default: canonical key from the
// created issue, else a unique dispatch key
"issue_number": 123 // optional; attach to this existing issue
// in repo instead of creating one (see below)
}
```
Returns `201 {task_id, issue_number|null, queue}`. With `issue: true`
the issue is created first (labels `queue/queued` + `source/dispatch`)
and gets an agent-note comment naming the task id.

With `issue_number` set, no issue is created: the task attaches to
that existing issue in `repo` — the canonical dedupe key is derived
from it, and after the enqueue the issue gets the same agent-note
comment naming the task id plus the `queue/queued` and
`source/dispatch` labels. The response is `201 {task_id,
issue_number, issue_url, queue}`, where `issue_url` is
`https://github.com/<repo>/issues/<issue_number>`. `issue_number`
takes precedence over `issue` when both are sent. For dezren39/nix,
where the GitHub App is not installed, the attach is skipped with a
`warnings` entry; the task is still enqueued and `issue_number` is
still returned.

### Why assignment is a direct PATCH
The queue's `claim_repo_task` RPC claims the *next* task in a queue —
it cannot claim a specific row. A dispatch launch knows exactly which
Expand All @@ -101,16 +115,59 @@ Every endpoint except `GET /health` requires `Authorization: Bearer …`:
- **GitHub Actions OIDC** (preferred): a JWT from
`token.actions.githubusercontent.com`, RS256-verified against GitHub's
JWKS (cached), `aud` = `pm-dispatch` (env `DISPATCH_OIDC_AUDIENCE`).
The token's `repository` claim must be in the allowlist **and equal
the request body's `repo`** — a workflow can only dispatch for its own
repo. See `examples/dispatch-workflow.yml`.
The token's `repository` claim must be in the allowlist. **Grants
mesh:** every allowlisted repo may target every allowlisted repo —
the claim need not equal the request body's `repo`. Repos outside
the allowlist can neither call nor be targeted. Bearer callers are
bound only by the allowlist on the target.
See `examples/dispatch-workflow.yml`.
- **Static bearer secret**: `DISPATCH_API_TOKEN` (in the laptop's
`~/secrets/dispatch.env`), compared in constant time — the shape a
repo stores as a GitHub Actions secret.

The caller identity (`{type:"bearer"}` or `{type:"oidc", repository,
actor, workflow_ref}`) is recorded in the task payload.

## GitHub Actions (reusable)

Two composite actions in this repo wrap the dispatch endpoints so
call sites do not hand-roll the OIDC + curl plumbing:

- `.github/actions/pm-dispatch-start` ("the starter") — POSTs to
`/v1/sessions`; outputs `task_id`, `session_id`, `issue_number`
and `issue_url`.
- `.github/actions/pm-dispatch-queue` ("the queuer") — POSTs to
`/v1/tasks`, including the `issue` / `issue_number` inputs;
outputs `task_id`, `issue_number` and `issue_url`.

Usage, pinned to `@main` so fleet call sites pick up central updates:

```yaml
jobs:
dispatch:
runs-on: ubuntu-latest
permissions:
id-token: write # required — the actions mint an OIDC token (aud pm-dispatch)
contents: read
steps:
- uses: developing-today/code/.github/actions/pm-dispatch-start@main
with:
title: "fix(widget): flaky test"
prompt: "Fix the flaky widget test"
- uses: developing-today/code/.github/actions/pm-dispatch-queue@main
with:
title: "investigate the red build"
prompt: "…"
issue_number: "123" # optional: attach instead of creating
```

The calling job MUST grant `permissions: id-token: write`; without
it the OIDC token-request environment is absent and the actions fail
with a clear error. `repo` defaults to the caller's repository, and
under the grants mesh any allowlisted repo may target any
allowlisted repo. See `examples/dispatch-workflow.yml` for a
complete workflow.

## Configuration (env)
| Name | Default | Notes |
| --- | --- | --- |
Expand Down
Loading