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
9 changes: 6 additions & 3 deletions apps/server/src/mcp/toolkits/pullRequests/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import {
PullRequestsToolkit,
type ThreadPullRequestEntry,
alreadyEndedWatchNext,
CHECKS_ALREADY_PASSED_WATCH_NEXT,
CHILD_PULL_REQUEST_REPORT_NEXT,
} from "./tools.ts";

Expand Down Expand Up @@ -333,9 +334,11 @@ const make = Effect.gen(function* () {
.setWatching({ threadId, target: input, watching, until: input.until })
.pipe(
Effect.map((result) =>
result.state === undefined
? result
: { ...result, next: alreadyEndedWatchNext(result.state) },
result.state !== undefined
? { ...result, next: alreadyEndedWatchNext(result.state) }
: result.checksState === "passing"
? { ...result, next: CHECKS_ALREADY_PASSED_WATCH_NEXT }
: result,
),
Effect.catchTags({
PullRequestWatchThreadNotFoundError: (error) =>
Expand Down
4 changes: 4 additions & 0 deletions apps/server/src/mcp/toolkits/pullRequests/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,17 @@ export const WatchPullRequestResult = Schema.Struct({
description: "The PR already ended, so nothing was watched.",
}),
),
checksState: Schema.optional(PullRequestChecksState),
next: Schema.optional(Schema.String),
});
export type WatchPullRequestResult = typeof WatchPullRequestResult.Type;

export const alreadyEndedWatchNext = (state: "merged" | "closed") =>
`This PR is already ${state}, so there is nothing to watch. Report that and end your turn.`;

export const CHECKS_ALREADY_PASSED_WATCH_NEXT =
"Checks already pass on this head, so no wake will come for them. Act on that now; the watch still wakes you on later changes.";

export const ThreadPullRequestEntry = Schema.Struct({
...PullRequestIdentity,
source: ThreadPullRequestLinkSource,
Expand Down
10 changes: 10 additions & 0 deletions apps/server/src/pullRequest/PullRequestWatchService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,16 @@ describe("PullRequestWatchService", () => {
}),
);

it.effect("tells the caller when the checks already passed, since no wake will report it", () =>
Effect.gen(function* () {
const harness = yield* makeHarness({ readChecksState: "passing" });
const result = yield* harness.setWatching(true, {
url: "https://github.com/t3tools/t3code/pull/9",
});
expect(result).toMatchObject({ wasWatching: false, checksState: "passing" });
}),
);

it.effect("reports a missing hosting CLI before saving a watch and still allows unwatch", () =>
Effect.gen(function* () {
const missing = new PullRequestUnavailableError({
Expand Down
6 changes: 6 additions & 0 deletions apps/server/src/pullRequest/PullRequestWatchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
CommandId,
ThreadId,
type OrchestrationV2ThreadShell,
type PullRequestChecksState,
type PullRequestUnavailableError,
type PullRequestWatchUntil,
} from "@t3tools/contracts";
Expand Down Expand Up @@ -68,6 +69,8 @@ export class PullRequestWatchService extends Context.Service<
readonly wasWatching: boolean;
/** Set when the PR already ended, so no watch was registered. */
readonly state?: "merged" | "closed";
/** CI as the start read saw it. Checks that already passed never wake the watch. */
readonly checksState?: PullRequestChecksState;
},
| PullRequestWatchFailedError
| PullRequestWatchFromSubagentError
Expand Down Expand Up @@ -130,6 +133,7 @@ const make = Effect.gen(function* () {
if (watching && before?.snapshot?.state === "merged") return alreadyEnded("merged");
// A pending rollup has no failure yet, so any failure the first read finds is news.
let checksPendingAtStart: boolean | undefined;
let checksStateAtStart: PullRequestChecksState | undefined;
if (watching && !wasWatching) {
const read = yield* pullRequests
.summary(
Expand All @@ -151,6 +155,7 @@ const make = Effect.gen(function* () {
);
if (read?.state === "merged" || read?.state === "closed") return alreadyEnded(read.state);
checksPendingAtStart = read === undefined ? undefined : read.checksState === "pending";
checksStateAtStart = read?.checksState ?? undefined;
}
const uuid = yield* random.uuidV4().pipe(Effect.orDie);
yield* engine
Expand Down Expand Up @@ -180,6 +185,7 @@ const make = Effect.gen(function* () {
...target,
watching: watchedLink(after)?.watch !== undefined,
wasWatching,
...(checksStateAtStart !== undefined && { checksState: checksStateAtStart }),
};
});

Expand Down
Loading