feat(forge): add the pull request panel and worktree Sessions
The forge panel shows the pull requests a Session created or pushed in a right-sidebar tab, with a Session header button and branch label, and lets a new Session start in its own Git worktree from the New Session options row. The forge bundle ships the panel with the forge registry, the GitHub provider, the Session bindings, and an isolated worktree service. The panel listens to the agent-controller/admission stage. It holds the first message of a Session with a worktree request while it creates and enters the worktree as Agent maintenance, and refuses messages while the worktree the Session works in is gone. A failed or stopped creation returns the message to the composer: the card above the composer shows the failure, sending again retries with a new branch name, and Continue without a worktree withdraws the request. A removed worktree can be checked out again or left for the source checkout. A message that enters without admission still gets its worktree at the first step proposal.
This commit is contained in:
1 parent
7c586e5b4c
commit
fc43a2d507
147 files changed
+12984
-135
No files matched your search
@@ -26,6 +26,11 @@ export interface GhConfig {
|
||||
readonly maxOutputBytes: number
|
||||
}
|
||||
|
||||
/** Thrown when the `gh` executable cannot start, for example because it is not installed. */
|
||||
export class GhUnavailableError extends Error {
|
||||
override name = 'GhUnavailableError'
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a runner for `gh` on the host. The child inherits the scrubbed parent
|
||||
* environment, so variables whose names contain KEY, PASSWORD, SECRET, or
|
||||
@@ -50,7 +55,7 @@ export function ghRunner(config: GhConfig): GhRunner {
|
||||
if (result.timedOut) throw new Error(`${command} timed out after ${config.timeoutMs}ms`)
|
||||
if (result.isMaxBuffer) throw new Error(`${command} output exceeds maxOutputBytes`)
|
||||
// A result without an exit code failed before the process ran; execa then always sets shortMessage.
|
||||
if (result.exitCode === undefined) throw new Error(`gh could not start: ${String(result.shortMessage)}`)
|
||||
if (result.exitCode === undefined) throw new GhUnavailableError(`gh could not start: ${String(result.shortMessage)}`)
|
||||
return { exitCode: result.exitCode, stdout: result.stdout, stderr: result.stderr }
|
||||
}
|
||||
}
|
||||
@@ -8,15 +8,15 @@ import type {
|
||||
import { z } from 'zod'
|
||||
import { isSegment } from './urls.ts'
|
||||
|
||||
const PULL_REQUEST_FIELDS = `number url title state isDraft updatedAt
|
||||
const PULL_REQUEST_FIELDS = `number url title state isDraft updatedAt closedAt
|
||||
author { login }
|
||||
headRefName headRefOid baseRefName mergeable reviewDecision
|
||||
headRefName headRefOid baseRefName additions deletions mergeable reviewDecision
|
||||
reviewThreads(first: 100) { nodes { isResolved } }
|
||||
commits(last: 1) { nodes { commit { statusCheckRollup { state contexts(first: 100) {
|
||||
pageInfo { hasNextPage }
|
||||
nodes {
|
||||
__typename
|
||||
... on CheckRun { name status conclusion detailsUrl checkSuite { workflowRun { workflow { name } } } }
|
||||
... on CheckRun { name status conclusion detailsUrl startedAt completedAt checkSuite { workflowRun { workflow { name } } } }
|
||||
... on StatusContext { context state targetUrl }
|
||||
}
|
||||
} } } } }`
|
||||
@@ -35,6 +35,8 @@ const checkRunSchema = z.object({
|
||||
status: z.string(),
|
||||
conclusion: z.string().nullable(),
|
||||
detailsUrl: z.string().nullable(),
|
||||
startedAt: z.string().nullable(),
|
||||
completedAt: z.string().nullable(),
|
||||
checkSuite: z.object({
|
||||
workflowRun: z.object({ workflow: z.object({ name: z.string() }) }).nullable(),
|
||||
}).nullable(),
|
||||
@@ -53,10 +55,13 @@ const pullRequestSchema = z.object({
|
||||
state: z.enum(['OPEN', 'CLOSED', 'MERGED']),
|
||||
isDraft: z.boolean(),
|
||||
updatedAt: z.string(),
|
||||
closedAt: z.string().nullable(),
|
||||
author: z.object({ login: z.string() }).nullable(),
|
||||
headRefName: z.string(),
|
||||
headRefOid: z.string(),
|
||||
baseRefName: z.string(),
|
||||
additions: z.number().int().nonnegative(),
|
||||
deletions: z.number().int().nonnegative(),
|
||||
mergeable: z.string(),
|
||||
reviewDecision: z.string().nullable(),
|
||||
reviewThreads: z.object({ nodes: z.array(z.object({ isResolved: z.boolean() })) }),
|
||||
@@ -193,12 +198,21 @@ function toSnapshot(ref: ChangeRequestRef, node: PullRequestNode): ChangeRequest
|
||||
state: checkRunState(run.data.status, run.data.conclusion),
|
||||
url: run.data.detailsUrl,
|
||||
workflow: run.data.checkSuite?.workflowRun?.workflow.name ?? null,
|
||||
startedAt: run.data.startedAt,
|
||||
completedAt: run.data.completedAt,
|
||||
})
|
||||
continue
|
||||
}
|
||||
const status = statusContextSchema.safeParse(context)
|
||||
if (status.success) {
|
||||
checks.push({ name: status.data.context, state: statusContextState(status.data.state), url: status.data.targetUrl, workflow: null })
|
||||
checks.push({
|
||||
name: status.data.context,
|
||||
state: statusContextState(status.data.state),
|
||||
url: status.data.targetUrl,
|
||||
workflow: null,
|
||||
startedAt: null,
|
||||
completedAt: null,
|
||||
})
|
||||
}
|
||||
}
|
||||
return {
|
||||
@@ -211,6 +225,8 @@ function toSnapshot(ref: ChangeRequestRef, node: PullRequestNode): ChangeRequest
|
||||
headBranch: node.headRefName,
|
||||
headSha: node.headRefOid,
|
||||
baseBranch: node.baseRefName,
|
||||
additions: node.additions,
|
||||
deletions: node.deletions,
|
||||
mergeability: mergeability(node.mergeable),
|
||||
reviewDecision: reviewDecision(node.reviewDecision),
|
||||
checks,
|
||||
@@ -218,6 +234,7 @@ function toSnapshot(ref: ChangeRequestRef, node: PullRequestNode): ChangeRequest
|
||||
checksTruncated: rollup?.contexts.pageInfo.hasNextPage ?? false,
|
||||
unresolvedThreads: node.reviewThreads.nodes.filter(thread => !thread.isResolved).length,
|
||||
updatedAt: node.updatedAt,
|
||||
closedAt: node.closedAt,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
|
||||
import { changeRequestKey } from '@deepseek-ai/dsh-experimental-forge'
|
||||
import type {
|
||||
ChangeRequestKey, ChangeRequestRef, ChangeRequestSnapshot, ForgeFailure, ForgeProvider, ForgeRepository,
|
||||
ChangeRequestKey, ChangeRequestRef, ChangeRequestSnapshot, ForgeFailure, ForgeProvider, ForgeReadiness, ForgeRepository,
|
||||
} from '@deepseek-ai/dsh-experimental-forge'
|
||||
import { GhUnavailableError } from './gh.ts'
|
||||
import type { GhRunner } from './gh.ts'
|
||||
import { HEAD_QUERY, mapHeadResponse, mapSnapshotResponse, snapshotQuery } from './graphql.ts'
|
||||
import { parsePullRequestUrl, parseRemoteUrl } from './urls.ts'
|
||||
@@ -67,6 +68,17 @@ export class GitHubProvider implements ForgeProvider {
|
||||
return mapHeadResponse(body, repository, branch)
|
||||
}
|
||||
|
||||
async readiness(host: string, signal: AbortSignal): Promise<ForgeReadiness> {
|
||||
try {
|
||||
const output = await this.gh(['auth', 'status', '--hostname', host], signal)
|
||||
if (output.exitCode === 0) return { state: 'ready', message: null }
|
||||
return { state: 'unauthenticated', message: firstLine(output.stderr) ?? firstLine(output.stdout) ?? `gh is not signed in to ${host}` }
|
||||
} catch (error) {
|
||||
if (error instanceof GhUnavailableError) return { state: 'unavailable', message: error.message }
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
private async fetchHost(
|
||||
host: string,
|
||||
refs: readonly ChangeRequestRef[],
|
||||
|
||||
Reference in new issue
Block a user