Skip to content

Commit 47bc55e

Browse files
authored
Merge pull request #18 from d3cker/codex/pr-completion-summary
Publish final session summaries in PR descriptions
2 parents d4187c6 + 21a07be commit 47bc55e

15 files changed

Lines changed: 425 additions & 31 deletions

‎AGENTS.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ the installation block without making remote writes. Keep its markers intact.
6666
`src/scheduler.ts` owns interval jobs; `src/state.ts` owns persistence and locks.
6767
- `src/executor.ts` owns analysis, base selection, worktrees, session execution,
6868
verification, and pushing. `src/analysis.ts` and `src/branch.ts` validate model
69-
decisions. `src/github.ts` implements GitHub calls; `src/approval.ts` evaluates
69+
decisions. `src/pr-description.ts` extracts final public reports and renders and
70+
reconciles managed PR descriptions. `src/github.ts` implements GitHub calls; `src/approval.ts` evaluates
7071
approval candidates.
7172
- `src/runtime.ts`, `src/worker.ts`, and `src/bridge.ts` implement worker hooks,
7273
runtime installation, and communication with the owner. `src/prompt.ts` loads

‎CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ include the full version, for example `## 0.7.0-beta.1`.
1818

1919
### Fixed
2020

21+
- Use the successful session's final completion report as the PR description instead
22+
of its initial acknowledgement. Persist reports across restarts, retain the
23+
original summary plus the latest follow-up, distinguish dispatcher checks from
24+
agent-reported tests, and preserve manual notes outside the managed section.
25+
2126
- Reconcile timed-out or interrupted sessions completed manually after a blocked
2227
task or service restart. Verify and publish through the dispatcher, then process
2328
queued issue feedback on the same branch and PR, including legacy checkpoints.

‎README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ installations are not removed by `npm uninstall --global`.
268268
`resume` commands from the target repository. Closing a PR closes its bot tabs
269269
while retaining session history. Authorized issue comments can continue work
270270
on an open PR without another mention, after the current round publishes.
271+
- **PR descriptions:** the successful session's final summary appears in the PR,
272+
with dispatcher checks listed separately. Follow-ups keep the original report
273+
and replace **Latest update**. Keep manual notes outside the managed HTML markers.
274+
See [PR descriptions](docs/runtime.md#pr-descriptions).
271275
- **Recovery:** completing a stopped bot session manually is detected by the
272276
dispatcher, which verifies and publishes before processing queued comments.
273277
Use `/restartworkflow` in the owner project's TUI or

‎docs/advanced.md‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ OpenCode service must be running for polling to work.
3030
| `stateDirectory` | Shared location for queues, locks, and worktrees. Keep it consistent across components and restarts. |
3131
| `repositories` | Repositories with existing local checkouts, default base branches, allowed authors, and checks. A natural-language request can override the base before work starts. |
3232
| `allowedAuthors` | GitHub users authorized to request work and approve merging. Merging also requires repository write access. |
33-
| `checks` | Arrays of executable arguments, e.g. `[["npm", "test"]]`. `[]` skips automated tests and reports that in the PR. No implicit shell. |
33+
| `checks` | Arrays of executable arguments, e.g. `[["npm", "test"]]`. `[]` skips dispatcher test commands; the PR distinguishes this from agent-reported tests. No implicit shell. |
3434
| `routes` | Maps full mentions to agents and models available in OpenCode. |
3535
| `routes[tag].capabilities` | Main model capabilities: `text`, `vision`, `audio`; omitted means text only. |
3636
| `routes[tag].mediaModel` | `{ model: { providerID, id }, capabilities: ["text", "vision"] }` for the media helper. |
@@ -232,3 +232,35 @@ See [runtime management](runtime.md#manage-tasks-from-bot) for the UI and limits
232232
While a closure is pending, the dispatcher does not start another worker pass.
233233
An unrelated already-running task can finish; scanning continues for other tasks.
234234
The monitor reports task maintenance until closure completes.
235+
236+
237+
## PR description recovery
238+
239+
Task state stores `completion` (final public text or an explicit unavailable
240+
reason, session, round, then verified commit and checks), `initialCompletion`,
241+
and `publishedBody` (the last acknowledged managed section). New rounds clear
242+
only the current completion. Older verifying/publishing tasks recover missing
243+
summaries from their saved sessions; this does not rerun the model. Missing or
244+
empty successful reports are marked unavailable, while transient reads retry.
245+
Already completed or closed tasks are not bulk rewritten on upgrade.
246+
247+
Publication reads the PR at the verified head and only replaces the managed HTML
248+
marker region. Notes outside it are preserved. An exact known legacy body can be
249+
replaced; unknown unmarked text is retained with the new section appended, since
250+
it might contain manual edits. A later legacy round may not have enough saved
251+
information to identify its old acknowledgement exactly.
252+
253+
An edited/removed managed section, changed PR head, closed follow-up PR, or oversized
254+
body blocks at `publishing`. Preserve your notes outside the markers and restore
255+
the previous managed section from `publishedBody` in the task checkpoint (or PR
256+
edit history), then use the normal workflow retry. Do not delete the queue or
257+
restart implementation just to retry a description update. If a PATCH succeeded
258+
but its response was lost, matching desired content is accepted without another
259+
write. Body and head are reread before PATCH; edits after that final read cannot
260+
be atomically excluded by this implementation.
261+
262+
Each rendered report is limited to 22,000 UTF-8 bytes with an explicit truncation
263+
notice; full saved text remains in task state and the session. Dispatcher check
264+
text is limited to 8,000 bytes. The complete description, including retained
265+
notes and signature, must fit within the automation limit of 60,000 bytes or
266+
publication blocks without dropping notes. Titles are not regenerated on updates.

‎docs/architecture.md‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,14 @@ loads a generic scheduler, a GitHub dispatcher, and a terminal UI component.
3131
3. Publish a signed acknowledgement, resolve the base branch, and pin that choice.
3232
4. Create or reuse the task worktree and checkpoint the session identity before
3333
prompting the executor. The executor must not publish directly.
34-
5. Validate session success, verify changes, then push and create or reconcile the
35-
PR. Generate its title only if creating a PR without an already-saved title.
34+
5. Validate session success and save the final public completion report. Verify
35+
changes, bind the report to the verified commit, then push and create or reconcile
36+
the PR with that report and separate dispatcher checks. Generate its title only
37+
if creating a PR without an already-saved title.
3638
6. After publication, process queued authorized issue comments as new rounds on
3739
the same worktree and branch, with a new main session and the existing open PR.
40+
Keep the original PR report and update its Latest update section after pushing;
41+
preserve manual notes outside the managed description.
3842
7. Merge only after eligible approval of the published head, repository permission
3943
checks, and GitHub merge readiness checks. Post a signed acknowledgement.
4044

‎docs/bot-workflow.md‎

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ flowchart TD
195195
Stopped -->|Manual continuation succeeds and probe passes| R
196196
Stopped -->|Explicit restartworkflow| Recover[Persist recovery intent, rejoin the same session]
197197
Recover --> R
198-
R -->|Validated success, no unresolved question| V[verifying: configured checks and commit]
198+
R -->|Validated success, no unresolved question| Report[Persist final public assistant summary with session and round]
199+
Report --> V[verifying: configured checks and commit]
199200
V --> P[publishing: reconcile or create PR, push when required]
200201
V -->|Failed check or Git consistency guard| VB[verifying / blocked]
201202
VB -->|Operator retries saved stage| V
@@ -311,6 +312,7 @@ sequenceDiagram
311312
else Wait completes
312313
D->>S: Read context and final outcome
313314
alt Valid task marker, admitted recovery marker if required, and successful final assistant
315+
D->>D: Save final public assistant text with session and round
314316
D->>D: Clear recovery state and advance to verifying
315317
else Unsuccessful final outcome or assistant
316318
D->>D: Save session-stop block for later reconciliation
@@ -415,7 +417,8 @@ Source: [runtime.ts — inspect_media](../src/runtime.ts).
415417

416418
```mermaid
417419
flowchart TD
418-
Start[Validated session success or retry of verifying phase] --> Identity[Require saved workspace and base, exact managed root, branch and shared repository]
420+
Start[Validated session success or retry of verifying phase] --> Report[Reuse saved completion summary or recover from saved session]
421+
Report --> Identity[Require saved workspace and base, exact managed root, branch and shared repository]
419422
Identity --> Base[Require baseSha ancestor of HEAD and no unresolved conflicts]
420423
Base --> Checks[Run configured checks sequentially, or none if list empty]
421424
Checks -->|Configured check fails| Block[blocked at saved phase, retain work]
@@ -426,22 +429,28 @@ flowchart TD
426429
Identity -->|Explicit consistency guard fails| Block
427430
Base -->|Unresolved conflicts| Block
428431
Validate -->|Explicit consistency guard fails| Block
429-
Validate -->|Pass| Save[Persist checks and exact commit SHA, phase publishing]
430-
Retry[Retry saved publishing phase] --> Find
431-
Save --> Find[Find branch PR including closed PRs]
432+
Validate -->|Pass| Save[Persist summary, checks and exact commit SHA, phase publishing]
433+
Retry[Retry saved publishing phase] --> Body
434+
Save --> Body[Recover missing legacy summary, save original report and render body]
435+
Body --> Find[Find branch PR including closed PRs]
432436
Find --> Follow{Follow-up round?}
433437
Follow -->|Yes| Open{Existing PR open?}
434438
Open -->|No| Block
435439
Open -->|Yes| Push[Validate origin, workspace, saved HEAD and clean tree, push exact SHA]
436440
Follow -->|No| Exists{PR already exists?}
437-
Exists -->|Yes| Done[Record PR and publication time, pr_opened / done]
441+
Exists -->|Yes| Closed{PR closed?}
442+
Closed -->|Yes| Done[Record PR and publication time, pr_opened / done]
443+
Closed -->|No| Description
438444
Exists -->|No| Title[Generate title only if no saved prTitle]
439445
Title --> Issue{Issue still open?}
440446
Issue -->|No| Block
441447
Issue -->|Yes| PushNew[Validate origin and workspace, push exact verified SHA]
442448
PushNew --> Create[Create or reconcile signed PR against pinned base]
443-
Create --> Done
444-
Push --> Done
449+
Create --> Description[Read open PR at verified SHA, reconcile managed description]
450+
Push --> Description
451+
Description -->|Edited managed block, changed head or oversized body| Block
452+
Description -->|Unchanged or update succeeds| Acknowledge[Persist published body checkpoint]
453+
Acknowledge --> Done
445454
Failure[Other command, model or transport error] --> Policy[Keep current phase and apply retry policy in section 8]
446455
Close[Operator closes task before publishing starts] --> Drain[Finish in-flight local operation, reject next checkpoint]
447456
Drain --> Preserve[Do not publish, preserve existing local changes]
@@ -455,23 +464,45 @@ pushed branch does not by itself make a task complete.
455464

456465
The configured checks are command argument arrays. A failing configured check
457466
produces `blocked`. With no configured checks, only Git consistency checks run;
458-
the PR explicitly states that automated tests were not run. Commit hooks changing
467+
the PR explicitly says the dispatcher did not independently rerun agent-reported
468+
tests. Commit hooks changing
459469
the recorded tree, a dirty worktree after commit, or no diff from the base block
460470
publication. Other command failures use the general error policy below.
461471

462-
The PR body contains the analysis, `Closes #N`, checks, session ID, and verified
463-
commit SHA. Push uses `COMMIT:refs/heads/TASK_BRANCH` without force. The first
464-
publication reconciles an existing branch PR by recording it without another
465-
push; follow-ups require an open PR and push the new verified commit. Follow-ups
466-
do not regenerate the existing PR title or body.
472+
The PR body uses the final public text of the successful assistant response,
473+
with its Markdown preserved, rather than the pre-work analysis acknowledgement.
474+
The executor saves it with the session and round before verification; verification
475+
adds the checks and exact commit to the same snapshot. No extra model call rewrites
476+
the report. Reasoning, tools, and failed or unfinished responses are excluded.
477+
Missing legacy snapshots are read from the saved session; a missing session or
478+
empty response produces an explicit summary-unavailable notice, never analysis
479+
as a fallback. Transport errors retain the stage for retry.
480+
481+
The body keeps the original report and replaces one **Latest update** section on
482+
follow-ups. Dispatcher checks appear separately from agent-reported tests, followed
483+
by `Closes #N`, session, round and verified commit. Push uses
484+
`COMMIT:refs/heads/TASK_BRANCH` without force. The first publication reconciles an
485+
existing branch PR without another push; follow-ups require an open PR and push
486+
the new verified commit before updating its description. The title is retained.
487+
An already closed first-round PR is recorded without editing its description.
488+
489+
A stable HTML marker pair encloses the bot-managed description. Notes outside
490+
it are preserved; an edited or removed managed section blocks publication rather
491+
than overwriting it. The last acknowledged body is checkpointed, so a lost update
492+
response can be reconciled without duplicate sections. Exact legacy descriptions
493+
can be replaced; otherwise unmarked content is retained and the managed section
494+
appended. GitHub is reread before writing to detect concurrent edits, although
495+
there is no atomic compare-and-swap across that read and write. See
496+
[publication recovery and limits](advanced.md#pr-description-recovery) for details.
467497

468498
Signed comments use stable `opencode2` markers; reconciliation looks for a marker
469499
posted by the authenticated account. This covers analysis acknowledgements,
470500
questions, and merge acknowledgements after a lost response.
471501

472502
Sources: [executor.ts — GitWorkspace.verify, push, title](../src/executor.ts),
473503
[dispatcher.ts — publishing](../src/dispatcher.ts),
474-
[github.ts — ensureComment, ensurePull](../src/github.ts).
504+
[github.ts — ensureComment, ensurePull, updatePullBody](../src/github.ts),
505+
[pr-description.ts — extraction, rendering and reconciliation](../src/pr-description.ts).
475506

476507
## 7. Feedback, merge approval, and tab closure
477508

@@ -482,7 +513,8 @@ flowchart TD
482513
Keep --> Recovery[Session recovery and publication must finish first]
483514
Recovery --> Done
484515
Done -->|Yes| Round[Next worker pass starts one new round on saved branch and worktree]
485-
Round --> Guard[Require open issue, open original PR and authorized feedback, then analyze again]
516+
Round --> Snapshot[Retain original report and published body, reset current completion]
517+
Snapshot --> Guard[Require open issue, open original PR and authorized feedback, then analyze again]
486518
Idle[Worker has no eligible execution task] --> Eligible{Auto-merge enabled and done task eligible?}
487519
Eligible -->|No| Later[Wait for a later worker pass]
488520
Eligible -->|Yes| Since{publishedAt exists?}
@@ -549,7 +581,8 @@ or a request failure records `mergeError`; error retries also respect GitHub tim
549581
An already-merged response can reconcile a previously lost merge response.
550582

551583
Follow-up rounds reset analysis, question, current session, session-stop/recovery
552-
state, checks, and commit; they retain the branch, worktree, pinned base, and previous session reference.
584+
state, current completion summary, checks, and commit; they retain the original
585+
report, last published body, branch, worktree, pinned base, and previous session reference.
553586
Preparation reuses the saved worktree path rather than deriving a new path from
554587
the branch name. A renamed branch can therefore retain its original directory.
555588
Preparation, verification, and push all check the managed path, exact Git root,
@@ -595,7 +628,7 @@ An error normally preserves the phase so retry continues from its checkpoint.
595628
| `ready` | Eligible for worker selection when due. |
596629
| `waiting` | Awaiting an issue answer; no implementation or publication while unresolved. |
597630
| `retry_wait` | Transient failure; automatic retry after `nextAt`. |
598-
| `blocked` | Explicit `Blocked` error or GitHub HTTP 401, 404, or 422; requires inspection/retry, except a stopped session completed manually is reconciled automatically. |
631+
| `blocked` | Explicit `Blocked` or PR-description conflict, or GitHub HTTP 401, 404, or 422; requires inspection/retry, except a stopped session completed manually is reconciled automatically. |
599632
| `failed` | Other errors reached `maxAttempts`; operator recovery/retry required unless the checkpoint also qualifies as a stopped-session recovery candidate. |
600633
| `done` | PR publication/reconciliation completed; feedback and merge monitoring remain possible. |
601634
| `closing` | Operator requested end of tracking; interrupt sessions and drain in-flight work, retaining errors for retry. |
@@ -606,7 +639,7 @@ flowchart TD
606639
Work[Execute saved phase] --> Result{Result?}
607640
Result -->|WaitingForAnswer| Wait[waiting, or ready if answer already arrived]
608641
Result -->|SessionStopped| Stop[running / blocked, sessionStopped true]
609-
Result -->|Other Blocked or GitHub 401, 404, 422| Block[blocked at saved phase]
642+
Result -->|Other Blocked, description conflict or GitHub 401, 404, 422| Block[blocked at saved phase]
610643
Result -->|Other failure below attempt limit| Retry[retry_wait at saved phase]
611644
Retry -->|nextAt elapsed| Work
612645
Result -->|Other failure at limit| Fail[failed at saved phase]

‎docs/runtime.md‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,28 @@ owner location and updated plugin are available there. Live worker/scan diagnost
378378
reset when the owner is recreated; task checkpoints and scheduler history remain
379379
durable as before.
380380

381+
## PR descriptions
382+
383+
The PR contains the agent's final completion summary from the successful session,
384+
with Markdown preserved, followed by dispatcher verification, the issue reference,
385+
session, round and verified commit. The initial issue acknowledgement is not a
386+
completion report. Agent-reported tests remain in the summary; the dispatcher
387+
lists only checks it actually ran. With no configured test command it explicitly
388+
states that agent-reported tests were not independently rerun.
389+
390+
Follow-up rounds keep the original summary and replace a single **Latest update**
391+
section after the new commit is pushed. The PR title stays unchanged. Reports are
392+
saved before publication so a restart or lost GitHub response can reuse them.
393+
If a legacy session is missing or has no successful final text, the description
394+
states that its summary is unavailable.
395+
396+
Put manual PR notes outside the `opencode2:pr-body` HTML markers (visible when
397+
editing the description). Edits inside that section or removal of the markers
398+
block further description updates to protect your changes. Inspect the task error,
399+
resolve the conflict and retry publication; see
400+
[description recovery](advanced.md#pr-description-recovery). Installing an update
401+
does not automatically rewrite already completed or closed PRs.
402+
381403
## Interrupted sessions and workflow recovery
382404

383405
If you manually continue a timed-out or interrupted bot session in the TUI,

‎prompts/bot.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ repository inspection in the implementation session.
184184

185185
## Final report
186186

187+
The dispatcher copies the final public text of a successfully completed session
188+
into the PR description with Markdown preserved. Write a review-ready report of
189+
completed work, not an acknowledgement or a promise to begin. On follow-ups, report
190+
what changed in this round; the original report remains in the PR and this report
191+
becomes its Latest update. Do not include private reasoning or raw tool transcripts.
192+
187193
Finish an implementation session with a concise English summary covering:
188194

189195
- The behavior delivered.

0 commit comments

Comments
 (0)