Merge remote-tracking branch 'origin/master' into feat/session-panel

This commit is contained in:
LegGasai committed 2026-11-10 11:50:13 +08:00
commit 4884003c4e
111 files changed
+6226 -604

No files matched your search

+3 -1
View File
@@ -1193,7 +1193,7 @@ export type SourceSigning = 'ad-hoc' | {
## `@deepseek-ai/dsh-experimental-forge`
- `source`: [`packages/experimental/forge/src/types.ts:432`](../packages/experimental/forge/src/types.ts)
- `source`: [`packages/experimental/forge/src/types.ts:588`](../packages/experimental/forge/src/types.ts)
```ts config-catalog
/** Poll cadence and fetch deadline for watched change requests. */
@@ -1236,6 +1236,8 @@ export interface Config {
maxReviewThreads?: number
/** Most commits one pull request commit listing returns; GitHub lists at most 250 commits of a pull request. */
maxCommits?: number
/** Most files whose viewed marks one read lists; GitHub lists at most 3,000 files of a pull request. */
maxViewedFiles?: number
}
```
<!-- END GENERATED config-catalog:@deepseek-ai/dsh-experimental-forge-github -->
+3 -1
View File
@@ -1195,7 +1195,7 @@ export type SourceSigning = 'ad-hoc' | {
## `@deepseek-ai/dsh-experimental-forge`
- `source`: [`packages/experimental/forge/src/types.ts:432`](../packages/experimental/forge/src/types.ts)
- `source`: [`packages/experimental/forge/src/types.ts:588`](../packages/experimental/forge/src/types.ts)
```ts config-catalog
/** Poll cadence and fetch deadline for watched change requests. */
@@ -1238,6 +1238,8 @@ export interface Config {
maxReviewThreads?: number
/** Most commits one pull request commit listing returns; GitHub lists at most 250 commits of a pull request. */
maxCommits?: number
/** Most files whose viewed marks one read lists; GitHub lists at most 3,000 files of a pull request. */
maxViewedFiles?: number
}
```
<!-- END GENERATED config-catalog:@deepseek-ai/dsh-experimental-forge-github -->
+1 -1
View File
@@ -47,7 +47,7 @@ Application listeners are outside this package matrix. Desktop Host subscribes t
| `deepseek-account/signed-out` | `emit` | [`packages/credentials/deepseek-account/src/index.ts:29`](../packages/credentials/deepseek-account/src/index.ts) | [`deepseek-account`](../packages/credentials/deepseek-account) (`emit`) | [`deepseek-account`](../packages/credentials/deepseek-account) |
| `domain/changed` | `emit` | [`packages/storage/storage-domain/src/events.ts:46`](../packages/storage/storage-domain/src/events.ts) | [`storage-domain`](../packages/storage/storage-domain) (`emit`) | `workspace-controller` |
| `feedback/committed` | `parallel` | [`packages/feedback/message-feedback/src/index.ts:58`](../packages/feedback/message-feedback/src/index.ts) | [`message-feedback`](../packages/feedback/message-feedback) (`parallel`) | [`session-telemetry-otel`](../packages/session/session-telemetry-otel) |
| `forge/providers-changed` | `parallel` | [`packages/experimental/forge/src/index.ts:28`](../packages/experimental/forge/src/index.ts) | `forge` (`parallel`) | `forge-session` |
| `forge/providers-changed` | `parallel` | [`packages/experimental/forge/src/index.ts:29`](../packages/experimental/forge/src/index.ts) | `forge` (`parallel`) | `forge-session` |
| `fs/delete-intent` | `waterfall` | [`packages/fs/fs/src/index.ts:83`](../packages/fs/fs/src/index.ts) | [`tool-fs`](../packages/fs/tool-fs) (`waterfall`) | [`fs-observation-policy`](../packages/fs/fs-observation-policy), [`workspace-changes`](../packages/deliverables/workspace-changes) |
| `fs/edit-intent` | `waterfall` | [`packages/fs/fs/src/index.ts:75`](../packages/fs/fs/src/index.ts) | `liveshare` (`waterfall`), [`tool-fs`](../packages/fs/tool-fs) (`waterfall`), [`tool-str-replace-editor`](../packages/fs/tool-str-replace-editor) (`waterfall`) | [`fs-observation-policy`](../packages/fs/fs-observation-policy), [`workspace-changes`](../packages/deliverables/workspace-changes) |
| `fs/observed` | `emit` | [`packages/fs/fs/src/index.ts:93`](../packages/fs/fs/src/index.ts) | `liveshare` (`emit`), [`tool-fs`](../packages/fs/tool-fs) (`emit`), [`tool-str-replace-editor`](../packages/fs/tool-str-replace-editor) (`emit`) | [`fs-observation-policy`](../packages/fs/fs-observation-policy), [`skill-filesystem`](../packages/skill/skill-filesystem), `workspace-files` |
+1 -1
View File
@@ -49,7 +49,7 @@
| `deepseek-account/signed-out` | `emit` | [`packages/credentials/deepseek-account/src/index.ts:29`](../packages/credentials/deepseek-account/src/index.ts) | [`deepseek-account`](../packages/credentials/deepseek-account) (`emit`) | [`deepseek-account`](../packages/credentials/deepseek-account) |
| `domain/changed` | `emit` | [`packages/storage/storage-domain/src/events.ts:46`](../packages/storage/storage-domain/src/events.ts) | [`storage-domain`](../packages/storage/storage-domain) (`emit`) | `workspace-controller` |
| `feedback/committed` | `parallel` | [`packages/feedback/message-feedback/src/index.ts:58`](../packages/feedback/message-feedback/src/index.ts) | [`message-feedback`](../packages/feedback/message-feedback) (`parallel`) | [`session-telemetry-otel`](../packages/session/session-telemetry-otel) |
| `forge/providers-changed` | `parallel` | [`packages/experimental/forge/src/index.ts:28`](../packages/experimental/forge/src/index.ts) | `forge` (`parallel`) | `forge-session` |
| `forge/providers-changed` | `parallel` | [`packages/experimental/forge/src/index.ts:29`](../packages/experimental/forge/src/index.ts) | `forge` (`parallel`) | `forge-session` |
| `fs/delete-intent` | `waterfall` | [`packages/fs/fs/src/index.ts:83`](../packages/fs/fs/src/index.ts) | [`tool-fs`](../packages/fs/tool-fs) (`waterfall`) | [`fs-observation-policy`](../packages/fs/fs-observation-policy), [`workspace-changes`](../packages/deliverables/workspace-changes) |
| `fs/edit-intent` | `waterfall` | [`packages/fs/fs/src/index.ts:75`](../packages/fs/fs/src/index.ts) | `liveshare` (`waterfall`), [`tool-fs`](../packages/fs/tool-fs) (`waterfall`), [`tool-str-replace-editor`](../packages/fs/tool-str-replace-editor) (`waterfall`) | [`fs-observation-policy`](../packages/fs/fs-observation-policy), [`workspace-changes`](../packages/deliverables/workspace-changes) |
| `fs/observed` | `emit` | [`packages/fs/fs/src/index.ts:93`](../packages/fs/fs/src/index.ts) | `liveshare` (`emit`), [`tool-fs`](../packages/fs/tool-fs) (`emit`), [`tool-str-replace-editor`](../packages/fs/tool-str-replace-editor) (`emit`) | [`fs-observation-policy`](../packages/fs/fs-observation-policy), [`skill-filesystem`](../packages/skill/skill-filesystem), `workspace-files` |
+6 -3
View File
@@ -16,10 +16,13 @@
zh: 9903fcc571104ad8
/forges/review-threads:
en: af729af6e59e915f
zh: 62ddae4cfcd4431f
zh: 1b7d7671ec36a5b2
/forges/overview-and-viewed-marks:
en: fd5928603c9375b1
zh: 1a3bca55344ff385
/forges/session-bindings:
en: 13dfd36f2166bba0
zh: a369434f52f04d57
/forges/panel:
en: 4020149c26661a2d
zh: 56842b057d4f662e
en: 0e0348e9a38215ed
zh: affcc0231e15d682
+338 -3
View File
@@ -101,6 +101,38 @@ interface ForgeProvider {
* with `a/` and `b/` path prefixes. Both are full object names; `head` descends from `base`.
*/
compare?(ref: ChangeRequestRef, base: string, head: string, signal: AbortSignal): Promise<string | ForgeFailure>
/**
* Read the signed-in user's viewed marks on the change request's files at head commit `headSha`. The marks are
* returned only when the read names `headSha` as the head; once the head is another commit, the read resolves to a
* `stale` failure. A provider implements `viewedFiles` and `setViewed` together; omitting either declares that the
* host keeps no viewed marks.
*/
viewedFiles?(ref: ChangeRequestRef, headSha: string, signal: AbortSignal): Promise<ForgeViewedFiles | ForgeFailure>
/**
* Set or clear the signed-in user's viewed mark on one file while the head is still `request.headSha`, resolving to
* undefined once the host saved it.
*/
setViewed?(ref: ChangeRequestRef, request: ForgeViewedRequest, signal: AbortSignal): Promise<ForgeActionFailure | undefined>
/**
* Rerun the failed checks of the head commit that name a `rerun` none of whose checks is pending, while the head is
* still `request.headSha`, resolving to undefined once the host accepted every rerun. Omission declares that the
* provider reruns no checks, and its snapshots then name none.
*/
rerunChecks?(ref: ChangeRequestRef, request: ForgeRerunRequest, signal: AbortSignal): Promise<ForgeActionFailure | undefined>
/**
* Request reviews from more reviewers, resolving to undefined once the host accepted the request. A provider implements
* `requestReviews` and `reviewerCandidates` together; omitting either declares that it requests no reviews, and its
* snapshots then deny `canRequestReviews`.
*/
requestReviews?(ref: ChangeRequestRef, request: ForgeReviewersRequest, signal: AbortSignal): Promise<ForgeActionFailure | undefined>
/** List accounts whose login or name matches `query`, the host's suggestions first, for a review request. */
reviewerCandidates?(ref: ChangeRequestRef, query: string, signal: AbortSignal): Promise<readonly ForgeReviewerCandidate[] | ForgeFailure>
/**
* Bring the base branch's new commits into the head branch while its head is still `request.headSha`, resolving to
* undefined once the host accepted the update. Omission declares that the provider updates no branches, and its
* snapshots then offer no `branchUpdates`.
*/
updateBranch?(ref: ChangeRequestRef, request: BranchUpdateRequest, signal: AbortSignal): Promise<ForgeActionFailure | undefined>
}
```
@@ -173,6 +205,11 @@ interface ChangeRequestCheck {
readonly startedAt: string | null
/** ISO 8601 time the check completed, or null while it runs and when the host reports none. */
readonly completedAt: string | null
/**
* Identity a rerun of this check names, or null when the provider cannot rerun it, as for a commit status. Checks that
* name one identity rerun together, and their failed checks can be rerun once none of them is pending.
*/
readonly rerun: ForgeCheckId | null
}
```
@@ -230,18 +267,36 @@ interface ChangeRequestSnapshot {
readonly mergeReady: boolean
/** Merge methods the repository accepts, the signed-in user's usual one first. */
readonly mergeMethods: readonly MergeMethod[]
/**
* Ways the signed-in user can bring the base branch's new commits into the head branch now; empty while the head is
* up to date, while the branches conflict, when the user cannot update the head branch, or when the provider cannot,
* so a head behind its base cannot be told apart from a current one for a user without the right to update it.
*/
readonly branchUpdates: readonly BranchUpdateMethod[]
/** Aggregate review outcome. */
readonly reviewDecision: ReviewDecision
/** Reviewers whose review is requested, in host order, then other accounts that reviewed, each once; the author is never listed. */
readonly reviewers: readonly ChangeRequestReviewer[]
/** Whether the host reported more review requests or reviews than the provider read, so `reviewers` may be incomplete. */
readonly reviewersTruncated: boolean
/** Whether the signed-in user may request reviews of the change request through its provider. */
readonly canRequestReviews: boolean
/** Checks on the head commit in host order. */
readonly checks: readonly ChangeRequestCheck[]
/** Combined check outcome. */
readonly checksRollup: ChecksRollup
/** Whether the host reported more checks than `checks` contains. */
readonly checksTruncated: boolean
/** Whether the signed-in user may rerun the failed checks that name a `rerun`. */
readonly canRerunChecks: boolean
/** Number of counted review threads that are not resolved. */
readonly unresolvedThreads: number
/** Whether the change request has more review threads than the provider counted, so `unresolvedThreads` is a lower bound. */
readonly threadsTruncated: boolean
/** Issues linked to the change request, which the host closes once it merges, in host order. */
readonly closingIssues: readonly ChangeRequestIssue[]
/** Whether the host reported more closing issues than `closingIssues` holds. */
readonly closingIssuesTruncated: boolean
/** ISO 8601 time of the host's last update to the change request. */
readonly updatedAt: string
/** ISO 8601 time the change request was merged or closed, or null while it is open. */
@@ -303,13 +358,15 @@ interface MergeRequest {
```
```ts type-equiv
/** Why a provider could not change a change request. */
/** Why a provider could not change a change request, or could not confirm that it did. */
interface ForgeActionFailure {
/**
* `unauthenticated`: credentials are missing or rejected; `stale`: the head
* moved past the confirmed commit; `failed`: the host refused or could not be reached.
* moved past the confirmed commit; `failed`: the host refused or could not be reached, so nothing changed;
* `unknown`: the request reached the host but its answer did not confirm the outcome, so the change may have been
* applied and must be checked on the host before it is tried again.
*/
readonly code: 'unauthenticated' | 'stale' | 'failed'
readonly code: 'unauthenticated' | 'stale' | 'failed' | 'unknown'
/** Human-readable cause, usually the host's own message. */
readonly message: string
}
@@ -517,6 +574,135 @@ type ForgeReviewWriteResult =
| { readonly ok: false; readonly code: 'unsupported' | 'stale' | 'failed' | 'unknown'; readonly message: string }
```
## Overview and viewed marks
A snapshot also carries the overview of a change request: its `reviewers` with each one's latest verdict, the `closingIssues` the host closes once it merges, the `branchUpdates` that would bring a head behind its base up to date, whether the signed-in user may request reviews or rerun checks, and the `rerun` each check names. `ctx.forge.rerunChecks`, `ctx.forge.requestReviews`, and `ctx.forge.updateBranch` act on it and resolve to a `ForgeActionFailure` as the actions above do, `unknown` when the host's answer did not confirm the outcome, polling a watched change request once the provider answered; a rerun and an update name the head commit the user saw and are refused with `stale` once the head moved. A provider implements `requestReviews` together with `reviewerCandidates`, which `ctx.forge.reviewerCandidates` uses to list the accounts a review can be requested from; an action the provider lacks fails with `failed`, and `reviewerCandidates` returns `unsupported`. The [GitHub provider README](../../packages/experimental/forge-github/README.md#use-this-package) owns how GitHub fills and acts on each field.
```ts type-equiv
/** Opaque host identity of a status check that a rerun names. */
type ForgeCheckId = Branded<'ForgeCheckId'>
```
```ts type-equiv
/** How an update brings the base branch's new commits into the head branch: a merge commit, or a rebase of the head's commits. */
type BranchUpdateMethod = 'merge' | 'rebase'
```
```ts type-equiv
/** Outcome of a reviewer's latest submitted review. */
type ReviewVerdict = 'approved' | 'changes-requested' | 'commented' | 'dismissed'
```
```ts type-equiv
/** An account or team asked to review a change request, or an account that reviewed it. */
interface ChangeRequestReviewer {
/** Whether the reviewer is a person's account, an app or bot account, or a team. */
readonly kind: 'user' | 'bot' | 'team'
/** Login, or `organization/slug` for a team. */
readonly login: string
/** Avatar image URL, or null when the host reports none. */
readonly avatarUrl: string | null
/** Whether a review from the reviewer is requested now. */
readonly requested: boolean
/** Whether the host requested the review because the reviewer owns changed paths. */
readonly codeOwner: boolean
/** Outcome of the reviewer's latest submitted review, or null before the first. */
readonly verdict: ReviewVerdict | null
/** Commit the latest submitted review was on, or null before the first or when the host reports none. */
readonly reviewedSha: string | null
}
```
```ts type-equiv
/** One issue linked to a change request, which the host closes once the change request merges. */
interface ChangeRequestIssue {
/** Repository that holds the issue. */
readonly repository: ForgeRepository
/** Host-assigned issue number. */
readonly number: number
/** Title as the author wrote it. */
readonly title: string
/** Whether the issue is still open. */
readonly state: 'open' | 'closed'
/** Web page of the issue. */
readonly url: string
}
```
```ts type-equiv
/** A rerun of the failed checks of the head commit whose checks the user saw. */
interface ForgeRerunRequest {
/** Head commit whose checks the user saw; the provider refuses with `stale` once the head is another commit. */
readonly headSha: string
}
```
```ts type-equiv
/** Reviewers to ask in addition to those whose review is requested now; one who already reviewed is asked again. */
interface ForgeReviewersRequest {
/** The reviewers by kind and login, a team by `organization/slug`. */
readonly reviewers: readonly Pick<ChangeRequestReviewer, 'kind' | 'login'>[]
}
```
```ts type-equiv
/** An account a review of the change request can be requested from. */
interface ForgeReviewerCandidate {
/** Login as the host spells it. */
readonly login: string
/** Display name, or null when the account shows none. */
readonly name: string | null
/** Avatar image URL, or null when the host reports none. */
readonly avatarUrl: string | null
/** Whether the host suggests the account for this change request, as from the history of its changed files. */
readonly suggested: boolean
}
```
```ts type-equiv
/** A branch update the user confirmed for the head commit they saw. */
interface BranchUpdateRequest {
/** How the base branch's new commits enter the head branch. */
readonly method: BranchUpdateMethod
/** Commit object name the head must still have; the update is refused once the head moves. */
readonly headSha: string
}
```
`ctx.forge.viewedFiles` and `ctx.forge.setViewed` read and change the signed-in user's viewed marks on the files of a change request at one head commit. A provider keeps viewed marks only when it implements both methods; otherwise `viewedFiles` returns undefined and `setViewed` fails, so a consumer keeps marks itself. A `stale` answer polls a watched change request as a stale diff read does.
```ts type-equiv
/**
* The signed-in user's review progress on one changed file: `viewed`, `unviewed`, or `dismissed` once the file
* changed after the user marked it viewed.
*/
type ForgeViewedState = 'viewed' | 'unviewed' | 'dismissed'
```
```ts type-equiv
/** The signed-in user's viewed marks on the files of a change request, read at one head commit. */
interface ForgeViewedFiles {
/** Head commit the marks were read at. */
readonly headSha: string
/** State of each changed file the host listed, by repository-relative path. */
readonly files: Readonly<Record<string, ForgeViewedState>>
/** Whether the change request has more files than `files` lists. */
readonly truncated: boolean
}
```
```ts type-equiv
/** A viewed mark the user set or cleared on a file of the head commit they saw. */
interface ForgeViewedRequest {
/** Repository-relative path of the changed file. */
readonly path: string
/** Whether the file is viewed. */
readonly viewed: boolean
/** Head commit whose changes the user saw; the provider refuses with `stale` once the head is another commit. */
readonly headSha: string
}
```
## Session bindings
`ctx.forgeSession` derives each Session's bindings from its own log: `gh pr create` results bind the URLs they print, `gh pr view`, `gh pr edit`, and `gh pr checkout` calls bind the change request they act on, and `git push` results trigger head-branch discovery through `ctx.forge`; the panel also reports the branch its checkout tracks for the same discovery. Track, dismiss, and discovery actions are `plugin:forge-session/binding` records, which stay outside the model-visible conversation. The `forgeChangeRequests` projection's client view, which the Session summary carries, lists the bindings without their status. The [Session binding README](../../packages/experimental/forge-session/README.md#use-this-package) owns the recognition and discovery rules.
@@ -808,6 +994,8 @@ The changes view reads through the same Remote. `localDiff` reads one `ForgeLoca
`changeRequestReview(session, url, headSha, fresh)` reads the threads of a bound change request at the head of the diff the view shows and refuses another head with `forgePanel/stale-head`, `forgePanel/review-unsupported` for a provider without review reads, and `forgePanel/review-failed` otherwise. It keeps one read per change request in memory, keyed by head commit and the status's update time and bounded by `maxCachedReviewBytes`, and reads again once the kept read is `reviewRefreshMs` old or when `fresh` asks for it, as the first read after the reader refreshes the view does: on GitHub a new comment or reply changes a pull request's update time, but resolving a thread does not. The changes view asks again at every status it receives while visible, and overlays the threads on the files the [panel README](../../packages/experimental/client-ui-forge/README.md#use-this-package) describes.
`changeRequestViewed(session, url, headSha)` reads the viewed marks of a bound change request at the head of the diff the view shows, returns null when the provider keeps none, and refuses another head with `forgePanel/stale-head` and any other failure with `forgePanel/viewed-failed`; `setFileViewed` saves one file's mark at that head. `rerunChecks`, `requestReviews`, and `updateBranch` act on a bound change request and refuse an outcome the host did not confirm with `forgePanel/action-unknown`, and `reviewerCandidates` lists accounts for a review request, refusing with `forgePanel/reviewers-failed` when the host lists none. The changes view reads the marks of a whole change request beside its diff and keeps the marks of local changes and chosen commits in the browser; the [panel README](../../packages/experimental/client-ui-forge/README.md#use-this-package) describes both and the card rows that offer the actions.
`changeRequestReviewWrite(session, url, write)` passes one `ForgeReviewWrite` for a bound change request to `ctx.forge.writeReview` after checking its head commit, ids, text, and line range, and returns the `ForgeReviewWriteResult`. Once the provider answers, whatever the answer, it drops the kept threads of that change request and every read that started before, so the next `changeRequestReview` reads the host; `submitReview` drops them as well. The changes view sends one write at a time and reads the threads again after each write that may have changed them.
```ts type-equiv
@@ -1086,6 +1274,49 @@ async markReady(ref: ChangeRequestRef, signal: AbortSignal): Promise<ForgeAction
*/
async merge(ref: ChangeRequestRef, request: MergeRequest, signal: AbortSignal): Promise<ForgeActionFailure | undefined>
/**
* Rerun the failed checks of a change request's head commit while the head is still `request.headSha`, then poll it
* at once when it is watched.
* @param ref - change request served by a registered provider.
* @param request - the head commit whose checks the user saw.
* @param signal - cancellation of the request.
* @returns undefined once the host accepted the rerun, or why it did not; a provider that reruns no checks fails.
* @throws when no provider serves the change request's forge, or with `signal.reason` when it aborts.
*/
async rerunChecks(ref: ChangeRequestRef, request: ForgeRerunRequest, signal: AbortSignal): Promise<ForgeActionFailure | undefined>
/**
* Request reviews of a change request from more reviewers, then poll it at once when it is watched.
* @param ref - change request served by a registered provider.
* @param request - the reviewers to ask.
* @param signal - cancellation of the request.
* @returns undefined once the host accepted the request, or why it did not; a provider that requests no reviews fails.
* @throws when no provider serves the change request's forge, or with `signal.reason` when it aborts.
*/
async requestReviews( ref: ChangeRequestRef, request: ForgeReviewersRequest, signal: AbortSignal, ): Promise<ForgeActionFailure | undefined>
/**
* List accounts a review of a change request can be requested from.
* @param ref - change request served by a registered provider.
* @param query - text the login or name contains; empty for the host's suggestions and first accounts.
* @param signal - cancellation of the read.
* @returns the accounts, the host's suggestions first, or why the host did not list them; a provider that requests no
* reviews returns `unsupported`.
* @throws when no provider serves the change request's forge, or with `signal.reason` when it aborts.
*/
async reviewerCandidates( ref: ChangeRequestRef, query: string, signal: AbortSignal, ): Promise<readonly ForgeReviewerCandidate[] | ForgeFailure>
/**
* Bring the base branch's new commits into a change request's head branch while its head is still
* `request.headSha`, then poll it at once when it is watched.
* @param ref - change request served by a registered provider.
* @param request - update method and the head commit the user confirmed.
* @param signal - cancellation of the request.
* @returns undefined once the host accepted the update, or why it did not; a provider that updates no branches fails.
* @throws when no provider serves the change request's forge, or with `signal.reason` when it aborts.
*/
async updateBranch(ref: ChangeRequestRef, request: BranchUpdateRequest, signal: AbortSignal): Promise<ForgeActionFailure | undefined>
/**
* Read complete check details independently of periodic polling.
* @param ref - change request served by a registered provider.
@@ -1134,6 +1365,29 @@ async readReview(ref: ChangeRequestRef, headSha: string, signal: AbortSignal): P
*/
async writeReview(ref: ChangeRequestRef, write: ForgeReviewWrite, signal: AbortSignal): Promise<ForgeReviewWriteResult>
/**
* Read the signed-in user's viewed marks on the files of a change request at one head commit. A `stale` failure
* polls a watched change request again as {@link ForgeService.diff} does.
* @param ref - change request served by a registered provider.
* @param headSha - head commit the marks must be read at, usually the head of the displayed diff.
* @param signal - cancellation of the read.
* @returns the marks read at `headSha`, why the host did not provide them, or undefined when the provider keeps no
* viewed marks.
* @throws when no provider serves the change request's forge, or with `signal.reason` when it aborts.
*/
async viewedFiles(ref: ChangeRequestRef, headSha: string, signal: AbortSignal): Promise<ForgeViewedFiles | ForgeFailure | undefined>
/**
* Set or clear the signed-in user's viewed mark on one file of a change request while its head is still
* `request.headSha`. A `stale` failure polls a watched change request again as {@link ForgeService.diff} does.
* @param ref - change request served by a registered provider.
* @param request - the file, its mark, and the head commit the user saw.
* @param signal - cancellation of the request.
* @returns undefined once the host saved the mark, or why it did not; a provider that keeps no viewed marks fails.
* @throws when no provider serves the change request's forge, or with `signal.reason` when it aborts.
*/
async setViewed(ref: ChangeRequestRef, request: ForgeViewedRequest, signal: AbortSignal): Promise<ForgeActionFailure | undefined>
/**
* List the commits of a change request at its current head.
* @param ref - change request served by a registered provider.
@@ -1404,6 +1658,33 @@ Serves the forge panel. Following a Session inspects the checkout of its current
*/
@Remote async changeRequestText(session: Session, url: string, commit: string, path: string, signal: AbortSignal): Promise<string>
/**
* Read the signed-in user's viewed marks on the files of a change request of a Session, which the host keeps for the
* whole change request.
* @param session - Session the change request is bound to.
* @param url - binding URL of the change request.
* @param headSha - head commit of the shown diff; marks read at another head are refused.
* @param signal - request cancellation.
* @returns the marks at `headSha`, or null when the provider keeps no viewed marks.
* @throws `forgePanel/not-bound` unless the URL is a visible binding of the Session that a provider serves;
* `forgePanel/stale-head` when the head moved past `headSha`, which is then polled again; `forgePanel/viewed-failed`
* when the host does not provide the marks otherwise.
*/
@Remote async changeRequestViewed(session: Session, url: string, headSha: string, signal: AbortSignal): Promise<ForgeViewedFiles | null>
/**
* Set or clear the signed-in user's viewed mark on one file of a change request of a Session.
* @param session - Session the change request is bound to.
* @param url - binding URL of the change request.
* @param request - the file, its mark, and the head commit of the shown diff.
* @param signal - request cancellation.
* @throws `forgePanel/not-bound` unless the URL is a visible binding of the Session that a provider serves;
* `forgePanel/stale-head` when the head moved past `request.headSha`; `forgePanel/action-failed` with the host's
* reason when the host refuses, cannot be reached, or keeps no viewed marks; `forgePanel/action-unknown` when the host
* did not confirm whether it saved the mark.
*/
@Remote async setFileViewed(session: Session, url: string, request: ForgeViewedRequest, signal: AbortSignal): Promise<void>
/**
* Read the review threads of a change request of a Session at the head commit of its displayed diff. Threads read
* at the same head commit and update time are reused from memory, for any Session, until they are
@@ -1475,6 +1756,60 @@ Serves the forge panel. Following a Session inspects the checkout of its current
*/
@Remote async merge(session: Session, url: string, method: MergeMethod, headSha: string, signal: AbortSignal): Promise<void>
/**
* Rerun the failed checks of a change request of a Session while its head is still the commit whose checks the user
* saw; the change request is polled again once the host answers.
* @param session - Session the change request is bound to.
* @param url - binding URL of the change request.
* @param request - the head commit whose checks the user saw.
* @param signal - request cancellation.
* @throws `forgePanel/not-bound` unless the URL is a visible binding of the Session that a provider serves;
* `forgePanel/stale-head` when the head moved past `request.headSha`; `forgePanel/action-failed` with the host's
* reason when the host refuses, cannot be reached, or reruns no checks; `forgePanel/action-unknown` when the host did
* not confirm whether it started the rerun.
*/
@Remote async rerunChecks(session: Session, url: string, request: ForgeRerunRequest, signal: AbortSignal): Promise<void>
/**
* Request reviews of a change request of a Session from more reviewers; the change request is polled again once the
* host answers.
* @param session - Session the change request is bound to.
* @param url - binding URL of the change request.
* @param reviewers - the reviewers to ask, by kind and login.
* @param signal - request cancellation.
* @throws `forgePanel/not-bound` unless the URL is a visible binding of the Session that a provider serves;
* `forgePanel/action-failed` with the host's reason when the host refuses, cannot be reached, or requests no reviews;
* `forgePanel/action-unknown` when the host did not confirm whether it requested the reviews.
*/
@Remote async requestReviews( session: Session, url: string, reviewers: readonly Pick<ChangeRequestReviewer, 'kind' | 'login'>[], signal: AbortSignal, ): Promise<void>
/**
* List accounts a review of a change request of a Session can be requested from.
* @param session - Session the change request is bound to.
* @param url - binding URL of the change request.
* @param query - text the login or name contains; empty for the host's suggestions and first accounts.
* @param signal - request cancellation.
* @returns the accounts, the host's suggestions first.
* @throws `forgePanel/not-bound` unless the URL is a visible binding of the Session that a provider serves;
* `forgePanel/reviewers-failed` when the host does not list them.
*/
@Remote async reviewerCandidates(session: Session, url: string, query: string, signal: AbortSignal): Promise<readonly ForgeReviewerCandidate[]>
/**
* Bring the base branch's new commits into the head branch of a change request of a Session while its head is still
* `headSha`; the change request is polled again once the host answers.
* @param session - Session the change request is bound to.
* @param url - binding URL of the change request.
* @param method - merge commit or rebase.
* @param headSha - head commit the user confirmed.
* @param signal - request cancellation.
* @throws `forgePanel/not-bound` unless the URL is a visible binding of the Session that a provider serves;
* `forgePanel/stale-head` when the head moved past `headSha`; `forgePanel/action-failed` with the host's reason when
* the host refuses, cannot be reached, or updates no branches; `forgePanel/action-unknown` when the host did not
* confirm whether it started the update.
*/
@Remote async updateBranch(session: Session, url: string, method: BranchUpdateMethod, headSha: string, signal: AbortSignal): Promise<void>
/**
* Ask for a new worktree before the Session's first turn, replacing an open
* request and forgetting a failed attempt. While the next message waits in
+340 -3
View File
@@ -101,6 +101,38 @@ interface ForgeProvider {
* with `a/` and `b/` path prefixes. Both are full object names; `head` descends from `base`.
*/
compare?(ref: ChangeRequestRef, base: string, head: string, signal: AbortSignal): Promise<string | ForgeFailure>
/**
* Read the signed-in user's viewed marks on the change request's files at head commit `headSha`. The marks are
* returned only when the read names `headSha` as the head; once the head is another commit, the read resolves to a
* `stale` failure. A provider implements `viewedFiles` and `setViewed` together; omitting either declares that the
* host keeps no viewed marks.
*/
viewedFiles?(ref: ChangeRequestRef, headSha: string, signal: AbortSignal): Promise<ForgeViewedFiles | ForgeFailure>
/**
* Set or clear the signed-in user's viewed mark on one file while the head is still `request.headSha`, resolving to
* undefined once the host saved it.
*/
setViewed?(ref: ChangeRequestRef, request: ForgeViewedRequest, signal: AbortSignal): Promise<ForgeActionFailure | undefined>
/**
* Rerun the failed checks of the head commit that name a `rerun` none of whose checks is pending, while the head is
* still `request.headSha`, resolving to undefined once the host accepted every rerun. Omission declares that the
* provider reruns no checks, and its snapshots then name none.
*/
rerunChecks?(ref: ChangeRequestRef, request: ForgeRerunRequest, signal: AbortSignal): Promise<ForgeActionFailure | undefined>
/**
* Request reviews from more reviewers, resolving to undefined once the host accepted the request. A provider implements
* `requestReviews` and `reviewerCandidates` together; omitting either declares that it requests no reviews, and its
* snapshots then deny `canRequestReviews`.
*/
requestReviews?(ref: ChangeRequestRef, request: ForgeReviewersRequest, signal: AbortSignal): Promise<ForgeActionFailure | undefined>
/** List accounts whose login or name matches `query`, the host's suggestions first, for a review request. */
reviewerCandidates?(ref: ChangeRequestRef, query: string, signal: AbortSignal): Promise<readonly ForgeReviewerCandidate[] | ForgeFailure>
/**
* Bring the base branch's new commits into the head branch while its head is still `request.headSha`, resolving to
* undefined once the host accepted the update. Omission declares that the provider updates no branches, and its
* snapshots then offer no `branchUpdates`.
*/
updateBranch?(ref: ChangeRequestRef, request: BranchUpdateRequest, signal: AbortSignal): Promise<ForgeActionFailure | undefined>
}
```
@@ -173,6 +205,11 @@ interface ChangeRequestCheck {
readonly startedAt: string | null
/** ISO 8601 time the check completed, or null while it runs and when the host reports none. */
readonly completedAt: string | null
/**
* Identity a rerun of this check names, or null when the provider cannot rerun it, as for a commit status. Checks that
* name one identity rerun together, and their failed checks can be rerun once none of them is pending.
*/
readonly rerun: ForgeCheckId | null
}
```
@@ -230,18 +267,36 @@ interface ChangeRequestSnapshot {
readonly mergeReady: boolean
/** Merge methods the repository accepts, the signed-in user's usual one first. */
readonly mergeMethods: readonly MergeMethod[]
/**
* Ways the signed-in user can bring the base branch's new commits into the head branch now; empty while the head is
* up to date, while the branches conflict, when the user cannot update the head branch, or when the provider cannot,
* so a head behind its base cannot be told apart from a current one for a user without the right to update it.
*/
readonly branchUpdates: readonly BranchUpdateMethod[]
/** Aggregate review outcome. */
readonly reviewDecision: ReviewDecision
/** Reviewers whose review is requested, in host order, then other accounts that reviewed, each once; the author is never listed. */
readonly reviewers: readonly ChangeRequestReviewer[]
/** Whether the host reported more review requests or reviews than the provider read, so `reviewers` may be incomplete. */
readonly reviewersTruncated: boolean
/** Whether the signed-in user may request reviews of the change request through its provider. */
readonly canRequestReviews: boolean
/** Checks on the head commit in host order. */
readonly checks: readonly ChangeRequestCheck[]
/** Combined check outcome. */
readonly checksRollup: ChecksRollup
/** Whether the host reported more checks than `checks` contains. */
readonly checksTruncated: boolean
/** Whether the signed-in user may rerun the failed checks that name a `rerun`. */
readonly canRerunChecks: boolean
/** Number of counted review threads that are not resolved. */
readonly unresolvedThreads: number
/** Whether the change request has more review threads than the provider counted, so `unresolvedThreads` is a lower bound. */
readonly threadsTruncated: boolean
/** Issues linked to the change request, which the host closes once it merges, in host order. */
readonly closingIssues: readonly ChangeRequestIssue[]
/** Whether the host reported more closing issues than `closingIssues` holds. */
readonly closingIssuesTruncated: boolean
/** ISO 8601 time of the host's last update to the change request. */
readonly updatedAt: string
/** ISO 8601 time the change request was merged or closed, or null while it is open. */
@@ -303,13 +358,15 @@ interface MergeRequest {
```
```ts type-equiv
/** Why a provider could not change a change request. */
/** Why a provider could not change a change request, or could not confirm that it did. */
interface ForgeActionFailure {
/**
* `unauthenticated`: credentials are missing or rejected; `stale`: the head
* moved past the confirmed commit; `failed`: the host refused or could not be reached.
* moved past the confirmed commit; `failed`: the host refused or could not be reached, so nothing changed;
* `unknown`: the request reached the host but its answer did not confirm the outcome, so the change may have been
* applied and must be checked on the host before it is tried again.
*/
readonly code: 'unauthenticated' | 'stale' | 'failed'
readonly code: 'unauthenticated' | 'stale' | 'failed' | 'unknown'
/** Human-readable cause, usually the host's own message. */
readonly message: string
}
@@ -517,6 +574,137 @@ type ForgeReviewWriteResult =
| { readonly ok: false; readonly code: 'unsupported' | 'stale' | 'failed' | 'unknown'; readonly message: string }
```
<a id="overview-and-viewed-marks"></a>
## 概览与已审阅标记
快照还携带变更请求的概览:`reviewers` 及每位评审者最近的结论、合并后托管平台会关闭的 `closingIssues`、能让落后于基线的 head 更新到最新的 `branchUpdates`、当前登录用户能否请求评审或重跑检查,以及每个检查指出的 `rerun`。`ctx.forge.rerunChecks`、`ctx.forge.requestReviews` 与 `ctx.forge.updateBranch` 据此操作,并像上文的操作一样返回 `ForgeActionFailure`,主机的答复无法确认结果时为 `unknown`,提供方答复后立即轮询被监听的变更请求;重跑与更新指明用户看到的 head 提交,head 移动后以 `stale` 拒绝。提供方同时实现 `requestReviews` 与 `reviewerCandidates`,`ctx.forge.reviewerCandidates` 借后者列出可以请求评审的账号;提供方缺少的操作以 `failed` 失败,`reviewerCandidates` 则返回 `unsupported`。GitHub 如何填写各字段并执行这些操作见 [GitHub 提供方 README](../../packages/experimental/forge-github/README.zh.md#use-this-package)。
```ts type-equiv
/** Opaque host identity of a status check that a rerun names. */
type ForgeCheckId = Branded<'ForgeCheckId'>
```
```ts type-equiv
/** How an update brings the base branch's new commits into the head branch: a merge commit, or a rebase of the head's commits. */
type BranchUpdateMethod = 'merge' | 'rebase'
```
```ts type-equiv
/** Outcome of a reviewer's latest submitted review. */
type ReviewVerdict = 'approved' | 'changes-requested' | 'commented' | 'dismissed'
```
```ts type-equiv
/** An account or team asked to review a change request, or an account that reviewed it. */
interface ChangeRequestReviewer {
/** Whether the reviewer is a person's account, an app or bot account, or a team. */
readonly kind: 'user' | 'bot' | 'team'
/** Login, or `organization/slug` for a team. */
readonly login: string
/** Avatar image URL, or null when the host reports none. */
readonly avatarUrl: string | null
/** Whether a review from the reviewer is requested now. */
readonly requested: boolean
/** Whether the host requested the review because the reviewer owns changed paths. */
readonly codeOwner: boolean
/** Outcome of the reviewer's latest submitted review, or null before the first. */
readonly verdict: ReviewVerdict | null
/** Commit the latest submitted review was on, or null before the first or when the host reports none. */
readonly reviewedSha: string | null
}
```
```ts type-equiv
/** One issue linked to a change request, which the host closes once the change request merges. */
interface ChangeRequestIssue {
/** Repository that holds the issue. */
readonly repository: ForgeRepository
/** Host-assigned issue number. */
readonly number: number
/** Title as the author wrote it. */
readonly title: string
/** Whether the issue is still open. */
readonly state: 'open' | 'closed'
/** Web page of the issue. */
readonly url: string
}
```
```ts type-equiv
/** A rerun of the failed checks of the head commit whose checks the user saw. */
interface ForgeRerunRequest {
/** Head commit whose checks the user saw; the provider refuses with `stale` once the head is another commit. */
readonly headSha: string
}
```
```ts type-equiv
/** Reviewers to ask in addition to those whose review is requested now; one who already reviewed is asked again. */
interface ForgeReviewersRequest {
/** The reviewers by kind and login, a team by `organization/slug`. */
readonly reviewers: readonly Pick<ChangeRequestReviewer, 'kind' | 'login'>[]
}
```
```ts type-equiv
/** An account a review of the change request can be requested from. */
interface ForgeReviewerCandidate {
/** Login as the host spells it. */
readonly login: string
/** Display name, or null when the account shows none. */
readonly name: string | null
/** Avatar image URL, or null when the host reports none. */
readonly avatarUrl: string | null
/** Whether the host suggests the account for this change request, as from the history of its changed files. */
readonly suggested: boolean
}
```
```ts type-equiv
/** A branch update the user confirmed for the head commit they saw. */
interface BranchUpdateRequest {
/** How the base branch's new commits enter the head branch. */
readonly method: BranchUpdateMethod
/** Commit object name the head must still have; the update is refused once the head moves. */
readonly headSha: string
}
```
`ctx.forge.viewedFiles` 与 `ctx.forge.setViewed` 在一个 head 提交上读取和修改当前登录用户对变更请求各文件的已审阅标记。只有同时实现两个方法的提供方保存已审阅标记;否则 `viewedFiles` 返回 undefined,`setViewed` 失败,由使用方自行保存标记。`stale` 答复会像过期的 diff 读取一样立即轮询被监听的变更请求。
```ts type-equiv
/**
* The signed-in user's review progress on one changed file: `viewed`, `unviewed`, or `dismissed` once the file
* changed after the user marked it viewed.
*/
type ForgeViewedState = 'viewed' | 'unviewed' | 'dismissed'
```
```ts type-equiv
/** The signed-in user's viewed marks on the files of a change request, read at one head commit. */
interface ForgeViewedFiles {
/** Head commit the marks were read at. */
readonly headSha: string
/** State of each changed file the host listed, by repository-relative path. */
readonly files: Readonly<Record<string, ForgeViewedState>>
/** Whether the change request has more files than `files` lists. */
readonly truncated: boolean
}
```
```ts type-equiv
/** A viewed mark the user set or cleared on a file of the head commit they saw. */
interface ForgeViewedRequest {
/** Repository-relative path of the changed file. */
readonly path: string
/** Whether the file is viewed. */
readonly viewed: boolean
/** Head commit whose changes the user saw; the provider refuses with `stale` once the head is another commit. */
readonly headSha: string
}
```
## Session 绑定
`ctx.forgeSession` 从每个 Session 自己的日志派生其绑定:`gh pr create` 的结果绑定其输出的 URL,`gh pr view`、`gh pr edit` 与 `gh pr checkout` 调用绑定它们所操作的变更请求,`git push` 的结果通过 `ctx.forge` 触发按 head 分支的发现;面板也会报告其检出所跟踪的分支,触发同样的发现。track、dismiss 与发现操作都是 `plugin:forge-session/binding` 插件记录,位于模型可见对话之外。`forgeChangeRequests` 投影的客户端视图随 Session 摘要下发,列出绑定但不含其状态。识别与发现规则见 [Session 绑定 README](../../packages/experimental/forge-session/README.zh.md#use-this-package)。
@@ -808,6 +996,8 @@ type ForgeChangeRequestStatesFrame =
`changeRequestReview(session, url, headSha, fresh)` 在视图所显示 diff 的 head 处读取已绑定变更请求的讨论;head 不同时以 `forgePanel/stale-head` 拒绝,提供方不支持读取讨论时返回 `forgePanel/review-unsupported`,其他失败返回 `forgePanel/review-failed`。每个变更请求在内存里保留一次读取结果,以 head 提交和状态的更新时间为键、受 `maxCachedReviewBytes` 约束,保留时间达到 `reviewRefreshMs` 后,或 `fresh` 要求时(读者刷新视图后的第一次读取就是这样)重新读取:在 GitHub 上,新评论和回复会改变 PR 的更新时间,解决讨论则不会。变更视图可见时,每收到一次状态就重新请求一次,并按[面板 README](../../packages/experimental/client-ui-forge/README.zh.md#use-this-package) 所述把讨论叠加到文件上。
`changeRequestViewed(session, url, headSha)` 在视图所示 diff 的 head 上读取已绑定变更请求的已审阅标记,提供方不保存标记时返回 null,head 不同时以 `forgePanel/stale-head` 拒绝,其他失败以 `forgePanel/viewed-failed` 拒绝;`setFileViewed` 在该 head 上保存一个文件的标记。`rerunChecks`、`requestReviews` 与 `updateBranch` 作用于已绑定的变更请求,托管平台未确认的结果以 `forgePanel/action-unknown` 拒绝,`reviewerCandidates` 列出可请求评审的账号,托管平台未列出时以 `forgePanel/reviewers-failed` 拒绝。变更视图随 diff 一起读取整个变更请求的标记,本地变更与所选提交的标记保存在浏览器中;两者以及提供这些操作的卡片行见[面板 README](../../packages/experimental/client-ui-forge/README.zh.md#use-this-package)。
`changeRequestReviewWrite(session, url, write)` 检查已绑定变更请求的一个 `ForgeReviewWrite` 的 head 提交、id、文字和行范围后,交给 `ctx.forge.writeReview`,并返回 `ForgeReviewWriteResult`。提供方给出答复后,无论结果如何,都会丢弃该变更请求保留的讨论,以及在此之前开始的所有读取,使下一次 `changeRequestReview` 从托管平台读取;`submitReview` 同样如此。变更视图一次只发送一个写操作,每个可能改变讨论的写操作之后都会重新读取讨论。
```ts type-equiv
@@ -1086,6 +1276,49 @@ async markReady(ref: ChangeRequestRef, signal: AbortSignal): Promise<ForgeAction
*/
async merge(ref: ChangeRequestRef, request: MergeRequest, signal: AbortSignal): Promise<ForgeActionFailure | undefined>
/**
* Rerun the failed checks of a change request's head commit while the head is still `request.headSha`, then poll it
* at once when it is watched.
* @param ref - change request served by a registered provider.
* @param request - the head commit whose checks the user saw.
* @param signal - cancellation of the request.
* @returns undefined once the host accepted the rerun, or why it did not; a provider that reruns no checks fails.
* @throws when no provider serves the change request's forge, or with `signal.reason` when it aborts.
*/
async rerunChecks(ref: ChangeRequestRef, request: ForgeRerunRequest, signal: AbortSignal): Promise<ForgeActionFailure | undefined>
/**
* Request reviews of a change request from more reviewers, then poll it at once when it is watched.
* @param ref - change request served by a registered provider.
* @param request - the reviewers to ask.
* @param signal - cancellation of the request.
* @returns undefined once the host accepted the request, or why it did not; a provider that requests no reviews fails.
* @throws when no provider serves the change request's forge, or with `signal.reason` when it aborts.
*/
async requestReviews( ref: ChangeRequestRef, request: ForgeReviewersRequest, signal: AbortSignal, ): Promise<ForgeActionFailure | undefined>
/**
* List accounts a review of a change request can be requested from.
* @param ref - change request served by a registered provider.
* @param query - text the login or name contains; empty for the host's suggestions and first accounts.
* @param signal - cancellation of the read.
* @returns the accounts, the host's suggestions first, or why the host did not list them; a provider that requests no
* reviews returns `unsupported`.
* @throws when no provider serves the change request's forge, or with `signal.reason` when it aborts.
*/
async reviewerCandidates( ref: ChangeRequestRef, query: string, signal: AbortSignal, ): Promise<readonly ForgeReviewerCandidate[] | ForgeFailure>
/**
* Bring the base branch's new commits into a change request's head branch while its head is still
* `request.headSha`, then poll it at once when it is watched.
* @param ref - change request served by a registered provider.
* @param request - update method and the head commit the user confirmed.
* @param signal - cancellation of the request.
* @returns undefined once the host accepted the update, or why it did not; a provider that updates no branches fails.
* @throws when no provider serves the change request's forge, or with `signal.reason` when it aborts.
*/
async updateBranch(ref: ChangeRequestRef, request: BranchUpdateRequest, signal: AbortSignal): Promise<ForgeActionFailure | undefined>
/**
* Read complete check details independently of periodic polling.
* @param ref - change request served by a registered provider.
@@ -1134,6 +1367,29 @@ async readReview(ref: ChangeRequestRef, headSha: string, signal: AbortSignal): P
*/
async writeReview(ref: ChangeRequestRef, write: ForgeReviewWrite, signal: AbortSignal): Promise<ForgeReviewWriteResult>
/**
* Read the signed-in user's viewed marks on the files of a change request at one head commit. A `stale` failure
* polls a watched change request again as {@link ForgeService.diff} does.
* @param ref - change request served by a registered provider.
* @param headSha - head commit the marks must be read at, usually the head of the displayed diff.
* @param signal - cancellation of the read.
* @returns the marks read at `headSha`, why the host did not provide them, or undefined when the provider keeps no
* viewed marks.
* @throws when no provider serves the change request's forge, or with `signal.reason` when it aborts.
*/
async viewedFiles(ref: ChangeRequestRef, headSha: string, signal: AbortSignal): Promise<ForgeViewedFiles | ForgeFailure | undefined>
/**
* Set or clear the signed-in user's viewed mark on one file of a change request while its head is still
* `request.headSha`. A `stale` failure polls a watched change request again as {@link ForgeService.diff} does.
* @param ref - change request served by a registered provider.
* @param request - the file, its mark, and the head commit the user saw.
* @param signal - cancellation of the request.
* @returns undefined once the host saved the mark, or why it did not; a provider that keeps no viewed marks fails.
* @throws when no provider serves the change request's forge, or with `signal.reason` when it aborts.
*/
async setViewed(ref: ChangeRequestRef, request: ForgeViewedRequest, signal: AbortSignal): Promise<ForgeActionFailure | undefined>
/**
* List the commits of a change request at its current head.
* @param ref - change request served by a registered provider.
@@ -1404,6 +1660,33 @@ Serves the forge panel. Following a Session inspects the checkout of its current
*/
@Remote async changeRequestText(session: Session, url: string, commit: string, path: string, signal: AbortSignal): Promise<string>
/**
* Read the signed-in user's viewed marks on the files of a change request of a Session, which the host keeps for the
* whole change request.
* @param session - Session the change request is bound to.
* @param url - binding URL of the change request.
* @param headSha - head commit of the shown diff; marks read at another head are refused.
* @param signal - request cancellation.
* @returns the marks at `headSha`, or null when the provider keeps no viewed marks.
* @throws `forgePanel/not-bound` unless the URL is a visible binding of the Session that a provider serves;
* `forgePanel/stale-head` when the head moved past `headSha`, which is then polled again; `forgePanel/viewed-failed`
* when the host does not provide the marks otherwise.
*/
@Remote async changeRequestViewed(session: Session, url: string, headSha: string, signal: AbortSignal): Promise<ForgeViewedFiles | null>
/**
* Set or clear the signed-in user's viewed mark on one file of a change request of a Session.
* @param session - Session the change request is bound to.
* @param url - binding URL of the change request.
* @param request - the file, its mark, and the head commit of the shown diff.
* @param signal - request cancellation.
* @throws `forgePanel/not-bound` unless the URL is a visible binding of the Session that a provider serves;
* `forgePanel/stale-head` when the head moved past `request.headSha`; `forgePanel/action-failed` with the host's
* reason when the host refuses, cannot be reached, or keeps no viewed marks; `forgePanel/action-unknown` when the host
* did not confirm whether it saved the mark.
*/
@Remote async setFileViewed(session: Session, url: string, request: ForgeViewedRequest, signal: AbortSignal): Promise<void>
/**
* Read the review threads of a change request of a Session at the head commit of its displayed diff. Threads read
* at the same head commit and update time are reused from memory, for any Session, until they are
@@ -1475,6 +1758,60 @@ Serves the forge panel. Following a Session inspects the checkout of its current
*/
@Remote async merge(session: Session, url: string, method: MergeMethod, headSha: string, signal: AbortSignal): Promise<void>
/**
* Rerun the failed checks of a change request of a Session while its head is still the commit whose checks the user
* saw; the change request is polled again once the host answers.
* @param session - Session the change request is bound to.
* @param url - binding URL of the change request.
* @param request - the head commit whose checks the user saw.
* @param signal - request cancellation.
* @throws `forgePanel/not-bound` unless the URL is a visible binding of the Session that a provider serves;
* `forgePanel/stale-head` when the head moved past `request.headSha`; `forgePanel/action-failed` with the host's
* reason when the host refuses, cannot be reached, or reruns no checks; `forgePanel/action-unknown` when the host did
* not confirm whether it started the rerun.
*/
@Remote async rerunChecks(session: Session, url: string, request: ForgeRerunRequest, signal: AbortSignal): Promise<void>
/**
* Request reviews of a change request of a Session from more reviewers; the change request is polled again once the
* host answers.
* @param session - Session the change request is bound to.
* @param url - binding URL of the change request.
* @param reviewers - the reviewers to ask, by kind and login.
* @param signal - request cancellation.
* @throws `forgePanel/not-bound` unless the URL is a visible binding of the Session that a provider serves;
* `forgePanel/action-failed` with the host's reason when the host refuses, cannot be reached, or requests no reviews;
* `forgePanel/action-unknown` when the host did not confirm whether it requested the reviews.
*/
@Remote async requestReviews( session: Session, url: string, reviewers: readonly Pick<ChangeRequestReviewer, 'kind' | 'login'>[], signal: AbortSignal, ): Promise<void>
/**
* List accounts a review of a change request of a Session can be requested from.
* @param session - Session the change request is bound to.
* @param url - binding URL of the change request.
* @param query - text the login or name contains; empty for the host's suggestions and first accounts.
* @param signal - request cancellation.
* @returns the accounts, the host's suggestions first.
* @throws `forgePanel/not-bound` unless the URL is a visible binding of the Session that a provider serves;
* `forgePanel/reviewers-failed` when the host does not list them.
*/
@Remote async reviewerCandidates(session: Session, url: string, query: string, signal: AbortSignal): Promise<readonly ForgeReviewerCandidate[]>
/**
* Bring the base branch's new commits into the head branch of a change request of a Session while its head is still
* `headSha`; the change request is polled again once the host answers.
* @param session - Session the change request is bound to.
* @param url - binding URL of the change request.
* @param method - merge commit or rebase.
* @param headSha - head commit the user confirmed.
* @param signal - request cancellation.
* @throws `forgePanel/not-bound` unless the URL is a visible binding of the Session that a provider serves;
* `forgePanel/stale-head` when the head moved past `headSha`; `forgePanel/action-failed` with the host's reason when
* the host refuses, cannot be reached, or updates no branches; `forgePanel/action-unknown` when the host did not
* confirm whether it started the update.
*/
@Remote async updateBranch(session: Session, url: string, method: BranchUpdateMethod, headSha: string, signal: AbortSignal): Promise<void>
/**
* Ask for a new worktree before the Session's first turn, replacing an open
* request and forgetting a failed attempt. While the next message waits in
@@ -12,5 +12,5 @@
en: e5d1027faa55adba
zh: 4b88ad6a70977fb3
/native-cua-application-and-window-api/migration:
en: 106eab81fd078fec
zh: 6fb30738af8bc621
en: 071b67613c512b84
zh: 7ee32d8dbcf7a0f2
@@ -16,7 +16,7 @@ Providers supply startup capabilities alongside their platform guidance. The nat
## Migration
1. After `cua.getApp(selector)`, select the target from `app.getWindows()` with `app.getWindow(windowId)`. Use `window.getScreenshot()`, `window.click()`, `window.scroll()`, and `window.drag()`. Replace `hover` with `window.mouseMove()`. On macOS, `window.click(id)` sends mouse events at the element center. Switch to `invoke(id)` for the default accessibility action, or `performAction(id, "AXShowMenu")` to request an advertised menu action.
2. Replace `getAXState()` with `getAccessibilityTree()`. Replace `getAXStateAndScreenshot()` with separate tree and screenshot reads. Selection reads the initial tree silently for a window, and for an app when `appLevelAccessibility` is true. Read the tree explicitly to display it. See [macOS AX read limits](../cua-ax-read-limits/guide.md) for changes to traversal defaults and configuration.
2. Replace `getAXState()` with `getAccessibilityTree()`. Replace `getAXStateAndScreenshot()` with separate tree and screenshot reads. Application and window selection does not read AX. Before using element IDs, call `getAccessibilityTree()` explicitly; use `{ emit: false }` to retain the snapshot without displaying it. A screenshot does not require a successful AX read. Before coordinate input, including relative coordinates, obtain a successful AX observation covering the window or a screenshot; absolute coordinates require a screenshot. See [macOS AX read limits](../cua-ax-read-limits/guide.md) for changes to traversal defaults and configuration.
3. Pass the opaque string ID from the latest tree wherever you passed a numeric element index. In raw requests use `elementId` with `snapshotId`. Replace `performSecondaryAction` with `listActions(id)` and `performAction(id, exactName, argument?)`, or use `invoke(id)` for the default action. `setValue` accepts the provider’s supported JSON values. On macOS, `performAction(id, 'AXRaise')` performs the advertised raise action. Call `app.activate()` first when the application must become active.
4. Replace a packed chord such as `pressKey('shift+Tab')` with `pressKey('Tab', ['shift'])`. Check `(await cua.getCapabilities()).methods` before using `sendKeyEvent`. On macOS, call it inside one `run_code` to hold a key across tool calls. To request one repeat, send another down for a non-modifier key held by that execution. Returning, throwing or pausing releases any remaining keys. If your script handles unknown macOS key names as `NATIVE_ERROR`, handle `INVALID_ARGUMENT` instead. Correct the key name before retrying.
5. Read `dispatched` from action results, then observe the application to verify the outcome. `invoke` returns `dispatched: false` when the element has no default action. Remove reads of the old `verified` field and of `pid` on selected objects or window records. Use `listApps()` or running `findApps()` matches when you need a PID.
@@ -16,7 +16,7 @@ CUA 脚本在指定窗口上截图和操作鼠标。App 和 Window 对象共享
## 迁移
1. 调用 `cua.getApp(selector)` 后,从 `app.getWindows()` 返回的列表选定目标,再调用 `app.getWindow(windowId)`。在窗口上调用 `getScreenshot()`、`click()`、`scroll()` 和 `drag()`,将原有的 `hover` 调用改为 `window.mouseMove()`。在 macOS 上,`window.click(id)` 在元素中心发送鼠标事件。需要执行默认辅助功能动作时,改用 `invoke(id)`。需要打开控件菜单且控件声明了 `AXShowMenu` 时,调用 `performAction(id, "AXShowMenu")`。
2. 将 `getAXState()` 改为 `getAccessibilityTree()`,将 `getAXStateAndScreenshot()` 拆成读取树和截图两次调用。选择窗口时会静默读取初始树。选择应用时,只有 `appLevelAccessibility` 为真才读取。要显示树,请显式读取。[读取上限的迁移说明](../cua-ax-read-limits/guide.zh.md)列出了 macOS 默认值和配置含义的变化。
2. 将 `getAXState()` 改为 `getAccessibilityTree()`,将 `getAXStateAndScreenshot()` 拆成读取树和截图两次调用。选择应用或窗口不读取 AX。使用元素 ID 前须显式调用 `getAccessibilityTree()`;使用 `{ emit: false }` 可保留快照但不显示树。截图不要求 AX 读取成功。所有坐标输入(包括相对坐标)之前都须成功读取覆盖该窗口的 AX 或取得截图;绝对坐标要求截图。[读取上限的迁移说明](../cua-ax-read-limits/guide.zh.md)列出了 macOS 默认值和配置含义的变化。
3. 将数字元素索引改为从最新树中取得的字符串 ID。直接发送请求时使用 `elementId` 和 `snapshotId`。原先调用 `performSecondaryAction` 的地方,先用 `listActions(id)` 取得完整动作名,再调用 `performAction(id, exactName, argument?)`。要执行默认动作,可调用 `invoke(id)`。`setValue` 接受提供方支持的 JSON 值。 在 macOS 上,`performAction(id, 'AXRaise')` 只执行元素声明的抬起窗口动作。需要把应用切到前台时先调用 `app.activate()`。
4. 将 `pressKey('shift+Tab')` 之类的组合键写法改为 `pressKey('Tab', ['shift'])`。调用 `sendKeyEvent` 前检查 `(await cua.getCapabilities()).methods`。在 macOS 上,同一次 `run_code` 中可调用此方法跨工具调用保持按键。如果需要一次重复按下,可在这次执行中对已按住的普通键再发一次 `down`。执行返回、异常退出或用户暂停时会释放仍按着的键。如果脚本用 `NATIVE_ERROR` 识别 macOS 上的未知键名,请改为处理 `INVALID_ARGUMENT`,并在重试前修正键名。
5. 从动作结果读取 `dispatched`,再观察应用确认效果。元素没有默认动作时,`invoke` 返回 `dispatched: false`。移除读取旧字段 `verified` 的代码,以及对已选对象和窗口记录中 `pid` 的读取。需要 PID 时,使用 `listApps()` 或 `findApps()` 返回的运行中应用记录。
@@ -0,0 +1,16 @@
# Bilingual-pair consistency record for guide.md (docs/i18n/README.md): per heading
# section, a hash of its English and Chinese blocks outside code blocks and generated regions.
# After editing either side, bring the other along and re-record with:
# pnpm run verify-translation-pairing --write docs/upgrade-guide/v0.2.2-rc.1/forge-change-request-overview/guide.md
/:
en: 5788ee9fab8253cf
zh: c8f8da46139d3aec
/forge-snapshots-carry-the-change-request-overview-and-actions-report-unknown-outcomes:
en: a3a5753044d1188b
zh: 16562b29b23a3fea
/forge-snapshots-carry-the-change-request-overview-and-actions-report-unknown-outcomes/change:
en: a571055593a2aa44
zh: 405b322b9863f841
/forge-snapshots-carry-the-change-request-overview-and-actions-report-unknown-outcomes/migration:
en: 92213118a4373782
zh: d41450b2776c59ea
@@ -0,0 +1,26 @@
---
kind: upgrade-guide
description: "ChangeRequestSnapshot gains required overview fields, ChangeRequestCheck gains the required rerun field, and ForgeActionFailure gains the unknown code."
---
# Forge snapshots carry the change request overview, and actions report unknown outcomes
English | [中文](guide.zh.md)
## Change
`ChangeRequestSnapshot` gains seven required fields: `reviewers` and `reviewersTruncated`, `closingIssues` and `closingIssuesTruncated`, `branchUpdates`, `canRequestReviews`, and `canRerunChecks`. `ChangeRequestCheck` gains the required `rerun: ForgeCheckId | null`, which names how the provider reruns the check. The change request card reads these fields to list reviewers, linked issues, and the branch update, and to offer rerunning failed checks, requesting reviews, and updating the branch.
`ForgeActionFailure['code']` gains `unknown`: the host's answer did not confirm the outcome, so the change may have been applied. The GitHub provider returns it for viewed marks, review requests, and branch updates GitHub did not confirm; `ctx.forge.markReady` and `ctx.forge.merge` return it only from a provider that does.
`ForgeProvider` also gains optional `viewedFiles` with `setViewed`, `rerunChecks`, `requestReviews` with `reviewerCandidates`, and `updateBranch`; a provider without them keeps working, and the card then offers none of those actions.
This affects third-party `ForgeProvider` implementations registered with `ctx.forge.register` and other code that builds `ChangeRequestSnapshot` or `ChangeRequestCheck` values. All types come from `@deepseek-ai/dsh-experimental-forge`.
## Migration
1. In every `ChangeRequestCheck` a provider builds, set `rerun: null` unless the provider implements `rerunChecks`; a provider that does names each rerunnable check with a branded `ForgeCheckId` it can resolve again, as [`actionsRun`](../../../../packages/experimental/forge-github/src/graphql.ts) does for GitHub Actions runs.
2. In every `ChangeRequestSnapshot`, set the overview fields the host reports. Without host data, use `reviewers: []`, `reviewersTruncated: false`, `closingIssues: []`, `closingIssuesTruncated: false`, `branchUpdates: []`, `canRequestReviews: false`, and `canRerunChecks: false`; the card then shows the review decision alone and offers no overview action.
3. Optionally implement the new provider methods; [`GitHubProvider`](../../../../packages/experimental/forge-github/src/provider.ts) shows each one, and the [forge subsystem page](../../../subsystems/forge.md#overview-and-viewed-marks) states their contract.
4. Handle `unknown` wherever code switches exhaustively over `ForgeActionFailure['code']`: show that the outcome must be checked on the host, and do not try the change again before it is.
5. Run your type check; it succeeds when every snapshot and check a provider builds sets the new fields and no `ForgeActionFailure` code is unhandled.
@@ -0,0 +1,26 @@
---
kind: upgrade-guide
description: "ChangeRequestSnapshot 新增必填的概览字段,ChangeRequestCheck 新增必填的 rerun 字段,ForgeActionFailure 新增 unknown 代码。"
---
# Forge 快照携带变更请求概览,操作报告结果不明
[English](guide.md) | 中文
## 变更
`ChangeRequestSnapshot` 新增七个必填字段:`reviewers` 与 `reviewersTruncated`、`closingIssues` 与 `closingIssuesTruncated`、`branchUpdates`、`canRequestReviews`,以及 `canRerunChecks`。`ChangeRequestCheck` 新增必填的 `rerun: ForgeCheckId | null`,指出提供方如何重跑该检查。变更请求卡片读取这些字段,列出评审者、关联 issue 与分支更新,并提供重跑失败检查、请求评审与更新分支。
`ForgeActionFailure['code']` 新增 `unknown`:主机的答复无法确认结果,改动可能已经生效。GitHub 提供方在 GitHub 未确认已审阅标记、评审请求与分支更新的结果时返回它;`ctx.forge.markReady` 与 `ctx.forge.merge` 只在提供方返回它时才会返回。
`ForgeProvider` 还新增可选的 `viewedFiles` 与 `setViewed`、`rerunChecks`、`requestReviews` 与 `reviewerCandidates`,以及 `updateBranch`;未实现它们的提供方照常工作,卡片不提供对应操作。
受影响的是通过 `ctx.forge.register` 注册的第三方 `ForgeProvider` 实现,以及其他构造 `ChangeRequestSnapshot` 或 `ChangeRequestCheck` 值的代码。所有类型都来自 `@deepseek-ai/dsh-experimental-forge`。
## 迁移
1. 在提供方构造的每个 `ChangeRequestCheck` 中设置 `rerun: null`,除非提供方实现了 `rerunChecks`;实现了的提供方为每个可重跑的检查给出能再次解析的品牌化 `ForgeCheckId`,GitHub Actions 运行的做法见 [`actionsRun`](../../../../packages/experimental/forge-github/src/graphql.ts)。
2. 在每个 `ChangeRequestSnapshot` 中设置托管平台报告的概览字段。没有平台数据时,使用 `reviewers: []`、`reviewersTruncated: false`、`closingIssues: []`、`closingIssuesTruncated: false`、`branchUpdates: []`、`canRequestReviews: false` 与 `canRerunChecks: false`;卡片随后只显示评审结论,不提供概览操作。
3. 可选地实现新的提供方方法;[`GitHubProvider`](../../../../packages/experimental/forge-github/src/provider.ts) 展示了每个方法,契约见 [forge 子系统页面](../../../subsystems/forge.zh.md#overview-and-viewed-marks)。
4. 在所有对 `ForgeActionFailure['code']` 做穷举的地方处理 `unknown`:提示需要到主机上核对结果,核对之前不要再次尝试该改动。
5. 运行类型检查;提供方构造的每个快照与检查都设置了新字段、且没有未处理的 `ForgeActionFailure` 代码时即通过。