Skip to content

Commit 7ef2d0a

Browse files
authored
fix: isolate assist publication credentials (#479)
* fix: isolate assist publication credentials * test: pin assist reasoning binding * fix: grant assist publisher pull request writes * fix: stabilize assist retry identity * fix: block generated webhook commands
1 parent eac6206 commit 7ef2d0a

11 files changed

Lines changed: 1631 additions & 105 deletions

‎.github/workflows/assist.yml‎

Lines changed: 160 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ on:
4949
permissions:
5050
actions: read
5151
contents: read
52-
issues: write
52+
issues: read
5353
pull-requests: read
5454

5555
env:
@@ -58,7 +58,7 @@ env:
5858
CLAWSWEEPER_MODEL: internal
5959

6060
concurrency:
61-
group: ${{ format('clawsweeper-assist-{0}-{1}-{2}', github.event.client_payload.target_repo || inputs.target_repo || 'openclaw/openclaw', github.event.client_payload.item_number || inputs.item_number || github.run_id, github.event.client_payload.comment_id || inputs.comment_id || github.run_id) }}
61+
group: ${{ format('clawsweeper-assist-{0}-{1}-{2}', github.event.client_payload.target_repo || inputs.target_repo || 'openclaw/openclaw', github.event.client_payload.item_number || inputs.item_number || 'unknown', github.event.client_payload.comment_id || inputs.comment_id || 'manual') }}
6262
cancel-in-progress: false
6363

6464
jobs:
@@ -72,6 +72,7 @@ jobs:
7272
with:
7373
sparse-checkout: scripts/dispatch-receipt-owner.sh
7474
sparse-checkout-cone-mode: false
75+
persist-credentials: false
7576

7677
- id: receipt
7778
env:
@@ -117,6 +118,7 @@ jobs:
117118
tsconfig.json
118119
tsconfig.repair.json
119120
sparse-checkout-cone-mode: false
121+
persist-credentials: false
120122

121123
- uses: ./.github/actions/setup-pnpm
122124
with:
@@ -147,7 +149,7 @@ jobs:
147149
printf '%s' "$total"
148150
}
149151
150-
for attempt in $(seq 1 80); do
152+
for _ in $(seq 1 80); do
151153
active="$(active_assist_jobs)"
152154
if [ "$active" -lt "$cap" ]; then
153155
echo "proceed=true" >> "$GITHUB_OUTPUT"
@@ -165,34 +167,53 @@ jobs:
165167
if: ${{ needs.capacity.outputs.proceed == 'true' }}
166168
runs-on: ${{ vars.CLAWSWEEPER_WORKER_RUNNER || 'blacksmith-4vcpu-ubuntu-2404' }}
167169
timeout-minutes: 8
170+
outputs:
171+
generation_attempt: ${{ steps.generate.outputs.generation_attempt }}
168172
steps:
169173
- uses: actions/checkout@v7
170174
with:
175+
ref: ${{ github.sha }}
171176
filter: blob:none
177+
persist-credentials: false
178+
179+
- uses: ./.github/actions/setup-pnpm
180+
with:
181+
build-script: build
172182

173-
- name: Create GitHub App token
174-
id: app_token
183+
- name: Resolve validated target repository
184+
id: target
185+
env:
186+
TARGET_REPO: ${{ github.event.client_payload.target_repo || inputs.target_repo }}
187+
run: |
188+
set -euo pipefail
189+
resolved="$(node dist/clawsweeper.js assist-target --target-repo "$TARGET_REPO")"
190+
{
191+
echo "target_repo=$(jq -er '.repo' <<< "$resolved")"
192+
echo "target_repo_owner=$(jq -er '.owner' <<< "$resolved")"
193+
echo "target_repo_name=$(jq -er '.repository' <<< "$resolved")"
194+
} >> "$GITHUB_OUTPUT"
195+
196+
- name: Create read-only GitHub App token
197+
id: read_token
175198
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
176199
with:
177200
client-id: ${{ env.CLAWSWEEPER_APP_CLIENT_ID }}
178201
private-key: ${{ secrets.CLAWSWEEPER_APP_PRIVATE_KEY }}
179-
owner: ${{ vars.CLAWSWEEPER_ALLOWED_OWNER || github.repository_owner }}
180-
permission-issues: write
181-
permission-pull-requests: write
182-
183-
- uses: ./.github/actions/setup-pnpm
184-
with:
185-
build-script: build
202+
owner: ${{ steps.target.outputs.target_repo_owner }}
203+
repositories: ${{ steps.target.outputs.target_repo_name }}
204+
permission-issues: read
205+
permission-pull-requests: read
186206

187207
- uses: ./.github/actions/setup-codex
188208
env:
189209
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
190210
CLAWSWEEPER_INTERNAL_MODEL: ${{ secrets.CLAWSWEEPER_MODEL }}
191211

192-
- name: Answer maintainer question
212+
- name: Generate bounded assist artifact
213+
id: generate
193214
env:
194-
GH_TOKEN: ${{ steps.app_token.outputs.token }}
195-
TARGET_REPO: ${{ github.event.client_payload.target_repo || inputs.target_repo }}
215+
GH_TOKEN: ${{ steps.read_token.outputs.token }}
216+
TARGET_REPO: ${{ steps.target.outputs.target_repo }}
196217
ITEM_NUMBER: ${{ github.event.client_payload.item_number || inputs.item_number }}
197218
QUESTION: ${{ github.event.client_payload.question || inputs.question }}
198219
MODE: ${{ github.event.client_payload.assist.mode || github.event.client_payload.mode || inputs.mode || 'assist' }}
@@ -205,7 +226,8 @@ jobs:
205226
TIMEOUT_MS: ${{ github.event.client_payload.assist.timeout_ms || github.event.client_payload.timeout_ms || '120000' }}
206227
run: |
207228
set -euo pipefail
208-
node dist/clawsweeper.js assist \
229+
test -n "$GH_TOKEN"
230+
node dist/clawsweeper.js assist-generate \
209231
--target-repo "$TARGET_REPO" \
210232
--item-number "$ITEM_NUMBER" \
211233
--question "$QUESTION" \
@@ -217,4 +239,125 @@ jobs:
217239
--codex-model "$MODEL" \
218240
--codex-reasoning-effort "$REASONING_EFFORT" \
219241
--codex-sandbox read-only \
220-
--codex-timeout-ms "$TIMEOUT_MS"
242+
--codex-timeout-ms "$TIMEOUT_MS" \
243+
--run-id "$GITHUB_RUN_ID" \
244+
--run-attempt "$GITHUB_RUN_ATTEMPT" \
245+
--artifact .artifacts/assist-result.json
246+
echo "generation_attempt=$GITHUB_RUN_ATTEMPT" >> "$GITHUB_OUTPUT"
247+
248+
- name: Upload assist artifact
249+
uses: actions/upload-artifact@v7
250+
with:
251+
name: clawsweeper-assist-${{ github.run_id }}-${{ steps.generate.outputs.generation_attempt }}
252+
path: .artifacts/assist-result.json
253+
include-hidden-files: true
254+
if-no-files-found: error
255+
retention-days: 1
256+
257+
publish:
258+
name: Publish trusted assist comment
259+
needs: assist
260+
if: ${{ needs.assist.result == 'success' }}
261+
runs-on: ubuntu-latest
262+
timeout-minutes: 5
263+
steps:
264+
- uses: actions/checkout@v7
265+
with:
266+
ref: ${{ github.sha }}
267+
filter: blob:none
268+
persist-credentials: false
269+
270+
- uses: ./.github/actions/setup-pnpm
271+
with:
272+
build-script: build
273+
274+
- name: Verify exact workflow source
275+
run: test "$(git rev-parse HEAD)" = "$GITHUB_SHA"
276+
277+
- name: Resolve validated target repository
278+
id: target
279+
env:
280+
TARGET_REPO: ${{ github.event.client_payload.target_repo || inputs.target_repo }}
281+
run: |
282+
set -euo pipefail
283+
resolved="$(node dist/clawsweeper.js assist-target --target-repo "$TARGET_REPO")"
284+
{
285+
echo "target_repo=$(jq -er '.repo' <<< "$resolved")"
286+
echo "target_repo_owner=$(jq -er '.owner' <<< "$resolved")"
287+
echo "target_repo_name=$(jq -er '.repository' <<< "$resolved")"
288+
} >> "$GITHUB_OUTPUT"
289+
290+
- name: Download assist artifact
291+
uses: actions/download-artifact@v8
292+
with:
293+
name: clawsweeper-assist-${{ github.run_id }}-${{ needs.assist.outputs.generation_attempt }}
294+
path: .artifacts/publish
295+
296+
- name: Validate untrusted assist artifact
297+
env:
298+
TARGET_REPO: ${{ steps.target.outputs.target_repo }}
299+
ITEM_NUMBER: ${{ github.event.client_payload.item_number || inputs.item_number }}
300+
QUESTION: ${{ github.event.client_payload.question || inputs.question }}
301+
MODE: ${{ github.event.client_payload.assist.mode || github.event.client_payload.mode || inputs.mode || 'assist' }}
302+
LENS: ${{ github.event.client_payload.assist.lens || github.event.client_payload.lens || inputs.lens || 'auto' }}
303+
COMMENT_ID: ${{ github.event.client_payload.comment_id || inputs.comment_id || '' }}
304+
COMMENT_URL: ${{ github.event.client_payload.comment_url || inputs.comment_url || '' }}
305+
AUTHOR: ${{ github.event.client_payload.author || inputs.author || '' }}
306+
REASONING_EFFORT: high
307+
GENERATION_ATTEMPT: ${{ needs.assist.outputs.generation_attempt }}
308+
run: |
309+
set -euo pipefail
310+
node dist/clawsweeper.js assist-validate \
311+
--artifact .artifacts/publish/assist-result.json \
312+
--target-repo "$TARGET_REPO" \
313+
--item-number "$ITEM_NUMBER" \
314+
--question "$QUESTION" \
315+
--mode "$MODE" \
316+
--lens "$LENS" \
317+
--comment-id "$COMMENT_ID" \
318+
--comment-url "$COMMENT_URL" \
319+
--author "$AUTHOR" \
320+
--codex-reasoning-effort "$REASONING_EFFORT" \
321+
--run-id "$GITHUB_RUN_ID" \
322+
--run-attempt "$GENERATION_ATTEMPT"
323+
324+
- name: Create narrow GitHub App write token
325+
id: write_token
326+
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
327+
with:
328+
client-id: ${{ env.CLAWSWEEPER_APP_CLIENT_ID }}
329+
private-key: ${{ secrets.CLAWSWEEPER_APP_PRIVATE_KEY }}
330+
owner: ${{ steps.target.outputs.target_repo_owner }}
331+
repositories: ${{ steps.target.outputs.target_repo_name }}
332+
permission-issues: write
333+
permission-pull-requests: write
334+
335+
- name: Revalidate and publish assist comment
336+
env:
337+
GH_TOKEN: ${{ steps.write_token.outputs.token }}
338+
TARGET_REPO: ${{ steps.target.outputs.target_repo }}
339+
ITEM_NUMBER: ${{ github.event.client_payload.item_number || inputs.item_number }}
340+
QUESTION: ${{ github.event.client_payload.question || inputs.question }}
341+
MODE: ${{ github.event.client_payload.assist.mode || github.event.client_payload.mode || inputs.mode || 'assist' }}
342+
LENS: ${{ github.event.client_payload.assist.lens || github.event.client_payload.lens || inputs.lens || 'auto' }}
343+
COMMENT_ID: ${{ github.event.client_payload.comment_id || inputs.comment_id || '' }}
344+
COMMENT_URL: ${{ github.event.client_payload.comment_url || inputs.comment_url || '' }}
345+
AUTHOR: ${{ github.event.client_payload.author || inputs.author || '' }}
346+
REASONING_EFFORT: high
347+
GENERATION_ATTEMPT: ${{ needs.assist.outputs.generation_attempt }}
348+
run: |
349+
set -euo pipefail
350+
test -n "$GH_TOKEN"
351+
node dist/clawsweeper.js assist-publish \
352+
--artifact .artifacts/publish/assist-result.json \
353+
--target-repo "$TARGET_REPO" \
354+
--item-number "$ITEM_NUMBER" \
355+
--question "$QUESTION" \
356+
--mode "$MODE" \
357+
--lens "$LENS" \
358+
--comment-id "$COMMENT_ID" \
359+
--comment-url "$COMMENT_URL" \
360+
--author "$AUTHOR" \
361+
--codex-reasoning-effort "$REASONING_EFFORT" \
362+
--run-id "$GITHUB_RUN_ID" \
363+
--run-attempt "$GENERATION_ATTEMPT"

‎README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ Common commands:
233233
a 120-second per-item timeout, and its own five-job cap. It posts a separate
234234
non-durable answer comment and never edits the durable ClawSweeper review
235235
comment, closes, merges, labels, pushes, repairs, or emits review/apply
236-
markers.
236+
markers. The model job has read-only GitHub access and emits a bounded artifact;
237+
a fresh trusted publisher validates its workflow request, target revision, PR
238+
head, and source comment before minting a narrow comment-write token.
237239
- `visualize [lens]` dispatches the read-only visual assist lane and posts or
238240
updates a marker-backed visual brief comment for the requested lens.
239241
- `fix ci`, `address review`, and `rebase` dispatch the repair worker only for

‎schema/assist-artifact.schema.json‎

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
"$schema": "https://json-schema.org/draft/2020-12/schema",
3+
"$id": "https://clawsweeper.openclaw.ai/schema/assist-artifact.schema.json",
4+
"title": "ClawSweeper assist generation artifact",
5+
"type": "object",
6+
"additionalProperties": false,
7+
"required": [
8+
"schema_version",
9+
"generated_at",
10+
"workflow",
11+
"target",
12+
"source",
13+
"request",
14+
"output",
15+
"idempotency_key"
16+
],
17+
"properties": {
18+
"schema_version": { "const": 1 },
19+
"generated_at": { "type": "string", "format": "date-time", "maxLength": 64 },
20+
"workflow": {
21+
"type": "object",
22+
"additionalProperties": false,
23+
"required": ["run_id", "run_attempt"],
24+
"properties": {
25+
"run_id": { "type": "string", "pattern": "^[0-9]{1,30}$" },
26+
"run_attempt": { "type": "integer", "minimum": 1 }
27+
}
28+
},
29+
"target": {
30+
"type": "object",
31+
"additionalProperties": false,
32+
"required": [
33+
"repo",
34+
"item_number",
35+
"item_kind",
36+
"source_revision",
37+
"context_digest",
38+
"pull_head_sha"
39+
],
40+
"properties": {
41+
"repo": {
42+
"type": "string",
43+
"pattern": "^[A-Za-z0-9_.-]{1,100}/[A-Za-z0-9_.-]{1,100}$"
44+
},
45+
"item_number": { "type": "integer", "minimum": 1 },
46+
"item_kind": { "enum": ["issue", "pull_request"] },
47+
"source_revision": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
48+
"context_digest": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
49+
"pull_head_sha": {
50+
"oneOf": [{ "type": "null" }, { "type": "string", "pattern": "^[0-9a-f]{40}$" }]
51+
}
52+
}
53+
},
54+
"source": {
55+
"type": "object",
56+
"additionalProperties": false,
57+
"required": ["comment_id", "comment_url", "author", "digest"],
58+
"properties": {
59+
"comment_id": { "type": "string", "pattern": "^(?:|[0-9]{1,30})$" },
60+
"comment_url": { "type": "string", "maxLength": 1000 },
61+
"author": { "type": "string", "maxLength": 100 },
62+
"digest": {
63+
"oneOf": [{ "type": "null" }, { "type": "string", "pattern": "^[0-9a-f]{64}$" }]
64+
}
65+
}
66+
},
67+
"request": {
68+
"type": "object",
69+
"additionalProperties": false,
70+
"required": ["sha256", "mode", "lens", "reasoning_effort"],
71+
"properties": {
72+
"sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
73+
"mode": { "enum": ["assist", "visual"] },
74+
"lens": {
75+
"enum": ["auto", "ux", "flow", "state", "data", "proof", "risk", "maintainer"]
76+
},
77+
"reasoning_effort": { "enum": ["low", "medium", "high", "xhigh"] }
78+
}
79+
},
80+
"output": {
81+
"type": "object",
82+
"additionalProperties": false,
83+
"required": ["answer"],
84+
"properties": {
85+
"answer": { "type": "string", "minLength": 1, "maxLength": 60000 }
86+
}
87+
},
88+
"idempotency_key": { "type": "string", "pattern": "^[0-9a-f]{64}$" }
89+
}
90+
}

0 commit comments

Comments
 (0)