Skip to content

Commit df7501d

Browse files
tarasclaude
andcommitted
Watch pull request checks from a REPL entry
`<PullRequest.Checks watch timeoutSeconds={…} as=…/>` waits until every reported check run and commit status for the pinned head settles and binds { outcome, reason?, headSha, checks }. Omitting `watch` keeps the snapshot array. The REPL entry host retains the deadline, pinned head and result so an unfinished watch continues and a completed one restores without polling; workflow and ordinary runs refuse `watch` before any request. Adds the owning spec (§7.7.1), REPL spec, DEC-019, component reference and the Sidekick `<Guide.CI />` chapter. Refs #1459. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 464b186 commit df7501d

24 files changed

Lines changed: 2742 additions & 23 deletions
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# CI
2+
3+
Read this when you need to wait for pull request checks or verify a specific
4+
workflow attempt after merge.
5+
6+
## Applies to
7+
8+
Sidekick responses and the REPL entries they submit.
9+
10+
## Instructions
11+
12+
- Read `<Guide.Entries />` first. Use the task's canonical pull request URL and
13+
choose a time budget. Put the entire wait in one ordinary entry.
14+
- `<PullRequest.Checks url=… watch timeoutSeconds={…} as="checkResult" />`
15+
watches every reported check run and commit status for the head it first
16+
observes, and binds `{ outcome, reason?, headSha, checks }`. It waits for
17+
every reported check to settle, even after one has failed.
18+
- Successful, skipped and neutral results pass. Failure, error, cancellation,
19+
timeout and action-required results fail. A pull request that reports no
20+
checks yet keeps the watch waiting.
21+
- Submit the entry, read the receipt, and then read that exact entry's output,
22+
for example with `<REPL.Entry.Output entry={2} />` when the receipt names
23+
entry 2. Read further pages as needed. A completed entry can report any CI
24+
outcome; use the watch result from that entry for the next action.
25+
- Decide from `outcome`, never from a filtered array: a list of failed records
26+
can be empty while CI is still pending.
27+
- `success`: report that the watched checks passed for `headSha`.
28+
- `failure`: inspect the failed records and their links. The query shows
29+
failed rows across the full collection.
30+
- `incomplete` with `reason: "timeout"`: report what was still pending and
31+
decide whether to wait again.
32+
- `incomplete` with `reason: "head-changed"`: report the watched `headSha`
33+
and confirm the intended revision before starting another watch.
34+
- `incomplete` with `reason: "read-error"`: report that the outcome could not
35+
be established.
36+
- While the entry runs, the person can read its **Output · live** for the short
37+
head and the passed, failed and pending counts. Draft **Stop** ends the watch
38+
and binds nothing. Sidekick **Stop** ends the Send and leaves an admitted
39+
entry running; read that exact entry when you resume.
40+
- Keep compact derived values in root bindings and put large reports or
41+
separately collected progress histories in files.
42+
43+
## Example
44+
45+
This response submits an entry that renders the result and uses `Query` to show
46+
failed rows only once the outcome is known to be `failure`.
47+
48+
`````xmd
49+
<Let as="code" select="code">
50+
````xmd
51+
<PullRequest.Checks url="https://github.com/taras/executable.md/pull/123"
52+
watch timeoutSeconds={600} as="checkResult" />
53+
54+
<Output>
55+
<Json value={checkResult} />
56+
57+
<If condition={checkResult.outcome === "failure"}>
58+
### Failed check records
59+
60+
<Query value={checkResult.checks}
61+
yq='[.[] | select((.kind == "check-run" and .status == "completed" and (.conclusion == "failure" or .conclusion == "cancelled" or .conclusion == "timed_out" or .conclusion == "action_required")) or (.kind == "commit-status" and (.state == "failure" or .state == "error")))]' />
62+
</If>
63+
</Output>
64+
````
65+
</Let>
66+
<REPL.EntryInput>{code}</REPL.EntryInput>
67+
<REPL.Submit />
68+
`````
69+
70+
If the 600-second budget expires while a check is pending, the entry renders:
71+
72+
```json
73+
{
74+
"outcome": "incomplete",
75+
"reason": "timeout",
76+
"headSha": "0123456789abcdef0123456789abcdef01234567",
77+
"checks": [
78+
{
79+
"kind": "commit-status",
80+
"id": "42",
81+
"headSha": "0123456789abcdef0123456789abcdef01234567",
82+
"name": "green",
83+
"state": "pending",
84+
"description": "CI is running",
85+
"url": "https://github.com/taras/executable.md/actions/runs/45030887260",
86+
"createdAt": "2026-11-23T12:00:00Z",
87+
"updatedAt": "2026-11-23T12:00:00Z"
88+
}
89+
]
90+
}
91+
```
92+
93+
## Verify a workflow attempt after merge
94+
95+
`<PullRequest.Checks>` watches a pull request's head, not a workflow run. For a
96+
specific attempt after merge, use `gh` with the repository, workflow, intended
97+
merge SHA, run ID and attempt number. Identify the run by workflow and merge
98+
SHA, then inspect the requested attempt:
99+
100+
```sh
101+
gh run view 45030887260 --repo taras/executable.md --attempt 1
102+
gh api repos/taras/executable.md/actions/runs/45030887260/attempts/1 --jq '{runId: .id, attempt: .run_attempt, headSha: .head_sha, status, conclusion}'
103+
```
104+
105+
Replace the example identifiers with the task's own. Compare the returned head
106+
SHA with the intended merge SHA before reporting the result. If the attempt is
107+
still active, repeat the same attempt-scoped read within the task's time budget.
108+
Use `status` and `conclusion` to report how that attempt ended. A retry has a
109+
different attempt number; keep the original attempt in the command when the
110+
task asks about its outcome.
111+
112+
## Common mistake
113+
114+
Treating an empty failed-records query as success. Query only selects from the
115+
records the watch returned; it says nothing about whether the watch settled.
116+
Branch on `outcome` first.
117+
118+
## Read next
119+
120+
`<Guide.Lifetimes />` for cancellation and `<Guide.Bindings />` for published
121+
values.

‎packages/cli/src/repl/repositories/deno/provider.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ function replPullRequestOperations(
184184
): BindOperations<PullRequestOperationsApi> {
185185
const upsert = replPullRequestPolicy(owner, access, pullRequests);
186186
const read = replPullRequestReadPolicy(owner, pullRequests);
187-
return (site: string) => ({ read: read(site), upsert: upsert(site) });
187+
return (site: string) => ({ read: read(site).read, upsert: upsert(site) });
188188
}
189189

190190
export function useReplRepositoryRecording(options: ReplRecordingOptions = {}): Operation<void> {

‎packages/cli/src/repl/repositories/deno/pull-request-reads.ts‎

Lines changed: 202 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,21 @@
3535
*/
3636

3737
import { createApi } from "@effectionx/context-api";
38-
import { scoped } from "effection";
39-
import type { Operation } from "effection";
40-
import { getExpansion } from "@executablemd/core";
38+
import { Err, Ok, scoped } from "effection";
39+
import type { Operation, Result } from "effection";
40+
import { DocumentOutput, getExpansion } from "@executablemd/core";
4141
import type { JournalAdmission } from "@executablemd/core/host";
4242
import type { DurableEvent } from "@executablemd/durable-streams";
4343
import { StaleInputError } from "@executablemd/durable-streams";
44-
import type { BindOperations } from "@executablemd/git";
44+
import type { BindOperations, PullRequestReadOperations } from "@executablemd/git";
45+
import { PULL_REQUEST_CHECKS_WATCH } from "@executablemd/git/api";
46+
import type {
47+
CheckWatchInvocation,
48+
CheckWatchResult,
49+
PullRequestChecksWatchApi,
50+
} from "@executablemd/git/api";
51+
import { parseCheckWatchResult } from "@executablemd/git";
52+
import type { CheckWatchReads } from "@executablemd/git";
4553
import { PULL_REQUEST_API } from "@executablemd/git/api";
4654
import type {
4755
PullRequestApi,
@@ -68,6 +76,17 @@ import type { PullRequestResult } from "@executablemd/git";
6876
import { canonicalPullRequestUrl, pullRequestProviderName } from "@executablemd/git";
6977
import type { DenoPullRequestOperations } from "@executablemd/git/deno";
7078
import { PULL_REQUEST_READ, retainPullRequestRead } from "@executablemd/git/deno";
79+
import {
80+
checksWatchConfiguration,
81+
checksWatchRequest,
82+
parseChecksWatchDeadline,
83+
parseChecksWatchHead,
84+
parseChecksWatchRequest,
85+
PULL_REQUEST_CHECKS_WATCH_DEADLINE,
86+
PULL_REQUEST_CHECKS_WATCH_EFFECTS,
87+
PULL_REQUEST_CHECKS_WATCH_HEAD,
88+
retainPullRequestChecksWatch,
89+
} from "@executablemd/git/deno";
7190
import { gitOperationFingerprint } from "@executablemd/git/deno";
7291

7392
/** Why a retained read history cannot be continued. */
@@ -130,6 +149,13 @@ function* admitReplPullRequestReads(
130149
retained: readonly DurableEvent[],
131150
): Operation<void> {
132151
for (const event of retained) {
152+
if (
153+
event.type === "yield" &&
154+
PULL_REQUEST_CHECKS_WATCH_EFFECTS.includes(event.description.type)
155+
) {
156+
admitRetainedWatch(owner, event);
157+
continue;
158+
}
133159
if (event.type !== "yield" || event.description.type !== PULL_REQUEST_READ) {
134160
continue;
135161
}
@@ -172,6 +198,60 @@ function* admitReplPullRequestReads(
172198
}
173199
}
174200

201+
/**
202+
* Hold one retained watch checkpoint to the question it was made under.
203+
*
204+
* The same four refusals an evidence read has: the record states its complete
205+
* question, names this entry's owner, is journaled under the name that question
206+
* produces, and — when it succeeded — holds the checkpoint its type retains.
207+
*/
208+
function admitRetainedWatch(owner: string, event: Extract<DurableEvent, { type: "yield" }>): void {
209+
const question = parseChecksWatchRequest(event.description.input);
210+
if (question === undefined) {
211+
throw new ReplPullRequestReadHistoryError(
212+
"malformed-record",
213+
"a retained pull-request checks watch in this entry's history does not state the " +
214+
"complete question it was made under.",
215+
);
216+
}
217+
if (question.runId !== owner) {
218+
throw new ReplPullRequestReadHistoryError(
219+
"foreign-owner",
220+
"a retained pull-request checks watch in this entry's history was made under another " +
221+
"owner.",
222+
);
223+
}
224+
const configuration = checksWatchConfiguration(question);
225+
if (
226+
event.description.configuration !== configuration ||
227+
event.description.name !== `${question.expansionId}:${configuration}`
228+
) {
229+
throw new ReplPullRequestReadHistoryError(
230+
"request-fingerprint",
231+
"a retained pull-request checks watch is journaled under a name its own question does " +
232+
"not produce.",
233+
);
234+
}
235+
if (event.result.status !== "ok") {
236+
return;
237+
}
238+
const value = event.result.value;
239+
const type = event.description.type;
240+
const valid =
241+
type === PULL_REQUEST_CHECKS_WATCH_DEADLINE
242+
? parseChecksWatchDeadline(value) !== undefined
243+
: type === PULL_REQUEST_CHECKS_WATCH_HEAD
244+
? parseChecksWatchHead(value) !== undefined
245+
: parseCheckWatchResult(value) !== undefined;
246+
if (!valid) {
247+
throw new ReplPullRequestReadHistoryError(
248+
"malformed-evidence",
249+
"a retained pull-request checks watch holds a value that is not the checkpoint its " +
250+
"record type retains.",
251+
);
252+
}
253+
}
254+
175255
/**
176256
* The exact configuration fingerprint one question produces.
177257
*
@@ -234,9 +314,124 @@ function parseRetainedQuestion(value: unknown): RetainedReadQuestion | undefined
234314
export function replPullRequestReadPolicy(
235315
owner: string,
236316
pullRequests: () => DenoPullRequestOperations,
237-
): BindOperations<PullRequestOperationsApi["read"]> {
238-
return (site: string) => (invocation: PullRequestReadInvocation) =>
239-
read(owner, site, pullRequests, invocation);
317+
): BindOperations<PullRequestReadOperations> {
318+
return (site: string) => ({
319+
read: (invocation: PullRequestReadInvocation) => read(owner, site, pullRequests, invocation),
320+
watch: (invocation: CheckWatchInvocation) => watch(owner, site, pullRequests, invocation),
321+
});
322+
}
323+
324+
/**
325+
* One checks watch, through the semantic watch chain and this invocation's own
326+
* retention.
327+
*
328+
* The same layering a read has: a document's watch middleware composes around
329+
* an invocation-local terminal, and only that terminal reaches the transport.
330+
*/
331+
function watch(
332+
owner: string,
333+
site: string,
334+
pullRequests: () => DenoPullRequestOperations,
335+
invocation: CheckWatchInvocation,
336+
): Operation<CheckWatchResult> {
337+
return scoped(function* (): Operation<CheckWatchResult> {
338+
const local = createApi<PullRequestChecksWatchApi>(PULL_REQUEST_CHECKS_WATCH, {
339+
watch: (request: CheckWatchInvocation) => watched(owner, site, pullRequests, request),
340+
});
341+
return yield* local.operations.watch(invocation);
342+
});
343+
}
344+
345+
/**
346+
* The watch the semantic chain delegated, retained under this entry's owner and
347+
* this invocation's site.
348+
*
349+
* Each cycle is an ordinary read through this invocation's transport chain, so
350+
* matching and target parsing are the snapshot's and are decided live on every
351+
* cycle. What differs is what happens once a cycle is admitted: it is performed
352+
* afresh rather than retained, because the watch retains its checkpoints and its
353+
* result rather than each poll.
354+
*/
355+
function* watched(
356+
owner: string,
357+
site: string,
358+
pullRequests: () => DenoPullRequestOperations,
359+
invocation: CheckWatchInvocation,
360+
): Operation<CheckWatchResult> {
361+
const domain = pullRequests();
362+
const expansion = yield* getExpansion();
363+
const reads: CheckWatchReads = {
364+
read: (kind) => cycleRead(domain, invocation, kind),
365+
};
366+
return yield* retainPullRequestChecksWatch(
367+
checksWatchRequest(invocation.url, invocation.provider, invocation.timeoutSeconds, owner, site),
368+
expansion.position,
369+
reads,
370+
(line) => DocumentOutput.operations.output(`${line}\n`),
371+
);
372+
}
373+
374+
/**
375+
* What an admitted cycle raised, kept apart from a refusal made before admission.
376+
*
377+
* A failure after admission is a read the watch may retry; one before it is a
378+
* question this host will not ask, which waiting does not change.
379+
*/
380+
class WatchReadFailure extends Error {
381+
override name = "WatchReadFailure";
382+
383+
readonly failure: Error;
384+
385+
constructor(failure: Error) {
386+
super(failure.message);
387+
this.failure = failure;
388+
}
389+
}
390+
391+
/** One live cycle read, in a scope of its own so its session closes with it. */
392+
function cycleRead(
393+
domain: DenoPullRequestOperations,
394+
invocation: CheckWatchInvocation,
395+
kind: "checks" | "details",
396+
): Operation<Result<PullRequestReadResult>> {
397+
return scoped(function* (): Operation<Result<PullRequestReadResult>> {
398+
const local = createApi<PullRequestApi>(PULL_REQUEST_API, {
399+
read: (url: string, options: PullRequestReadOptions) =>
400+
domain.read(url, options, liveAttempt, declinedRead),
401+
upsert: refusingUpsert(),
402+
});
403+
let answered: PullRequestReadResult;
404+
try {
405+
answered = yield* local.operations.read(invocation.url, {
406+
kind,
407+
...(invocation.provider === undefined ? {} : { provider: invocation.provider }),
408+
});
409+
} catch (error) {
410+
if (error instanceof WatchReadFailure) {
411+
return Err(error.failure);
412+
}
413+
throw error;
414+
}
415+
const complete = parseCompletePullRequestReadResult(answered, kind);
416+
if (complete === undefined) {
417+
return Err(
418+
new Error("a watch cycle was answered with something other than the read it asked for."),
419+
);
420+
}
421+
return Ok(complete);
422+
});
423+
}
424+
425+
/** Perform an admitted cycle afresh, marking what it raised as a read failure. */
426+
function* liveAttempt(
427+
_admitted: unknown,
428+
perform: () => Operation<PullRequestReadResult>,
429+
): Operation<PullRequestReadResult> {
430+
try {
431+
return yield* perform();
432+
} catch (error) {
433+
throw new WatchReadFailure(error instanceof Error ? error : new Error(String(error)));
434+
}
240435
}
241436

242437
/**

‎packages/cli/src/repl/sidekick/controls.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ const SYNTAX_NAMES_PROPS = {
105105
additionalProperties: false,
106106
} as const;
107107

108-
/** The six guide chapters, which are the whole of the teaching a reply can read. */
108+
/** The guide chapters, which are the whole of the teaching a reply can read. */
109109
export const GUIDE_CHAPTERS = [
110110
"Entries",
111111
"Bindings",
@@ -114,6 +114,7 @@ export const GUIDE_CHAPTERS = [
114114
"Recovery",
115115
"Environment",
116116
"Children",
117+
"CI",
117118
] as const;
118119

119120
export type GuideChapter = (typeof GUIDE_CHAPTERS)[number];

0 commit comments

Comments
 (0)