Merge pull request #8753 from deepseek-harness/fix/forge-panel-defer-session-resume

fix(forge-panel): follow the panel after the Session opens and name cold Sessions by id
This commit is contained in:
imccyu authored and GitHub committed 2026-11-19 04:43:33 +08:00
commit 54062b0d8b
22 files changed
+258 -112

No files matched your search

@@ -94,7 +94,7 @@ it.skipIf(webSnapshotMode() === 'record').each(['deepseek-official', 'google', '
await edit.click()
await key.press('Delete')
await dialog.getByRole('button', { name: '保存', exact: true }).click()
await expect.poll(() => key.count()).toBe(0)
await expect.poll(() => key.count(), { timeout: 10_000 }).toBe(0)
await generate()
expect(calls).toHaveLength(2)
expect(calls[0]?.key).toBe(messages || google ? 'fixture-saved-key' : 'Bearer fixture-saved-key')
@@ -155,7 +155,7 @@ it.each([{ name: 'Chromium', engine: chromium }, { name: 'WebKit', engine: webki
await expect.poll(() => key.inputValue()).toBe('')
await key.fill('fixture-new-key')
await dialog.getByRole('button', { name: '保存', exact: true }).click()
await expect.poll(() => key.count()).toBe(0)
await expect.poll(() => key.count(), { timeout: 10_000 }).toBe(0)
await edit.click()
expect(await key.getAttribute('placeholder')).toBe('•'.repeat('fixture-new-key'.length))
expect(await key.inputValue()).toBe('')
+10 -6
View File
@@ -89,17 +89,21 @@ describe('web e2e: session drag scrolling', () => {
// Drop onto a row that was out of view when the drag started.
const middle = (await listEdges()).top + 200
await page.mouse.move(x, middle, { steps: 3 })
await page.mouse.move(x + 1, middle)
await page.mouse.move(x, middle)
const target = await page.evaluate(({ x, y }) => document.elementFromPoint(x, y)!
.closest('[role="treeitem"]')!.querySelector('[class*="title"]')!.textContent, { x, y: middle })
expect(target).toMatch(/^Conversation (\d{2}|[89])$/)
// The point can rest on the gap between rows while the drop indicator settles, so read again until it names a row.
let target = ''
await expect.poll(async () => {
await page.mouse.move(x + 1, middle)
await page.mouse.move(x, middle)
target = await page.evaluate(({ x, y }) => document.elementFromPoint(x, y)
?.closest('[role="treeitem"]')?.querySelector('[class*="title"]')?.textContent ?? '', { x, y: middle })
return target
}, { timeout: 15_000 }).toMatch(/^Conversation (\d{2}|[89])$/)
await page.mouse.up()
const titles = () => rows.locator('[class*="title"]').allTextContents()
await expect.poll(async () => {
const order = await titles()
return Math.abs(order.indexOf('Conversation 0') - order.indexOf(target))
}).toBe(1)
}, { timeout: 10_000 }).toBe(1)
expect(tripwire.pageErrors).toEqual([])
expect(tripwire.warnings).toEqual([])
})
+1 -1
View File
@@ -73,7 +73,7 @@ Application listeners are outside this package matrix. Desktop Host subscribes t
| `schedule/resolve-agent` | `waterfall` | [`packages/schedule/schedule/src/index.ts:72`](../packages/schedule/schedule/src/index.ts) | [`schedule`](../packages/schedule/schedule) (`waterfall`) | `server` |
| `session-telemetry/record` | `waterfall` | [`packages/session/session-telemetry/src/index.ts:44`](../packages/session/session-telemetry/src/index.ts) | [`session-telemetry`](../packages/session/session-telemetry) (`waterfall`) | - |
| `session/created` | `emit` | [`packages/core/session/src/index.ts:56`](../packages/core/session/src/index.ts) | [`session`](../packages/core/session) (`events.dispatch`) | `server`, `session-controller`, [`session-projection`](../packages/session/session-projection), [`session-projection-cache`](../packages/session/session-projection-cache), [`session-telemetry`](../packages/session/session-telemetry) |
| `session/disposed` | `emit` | [`packages/core/session/src/index.ts:65`](../packages/core/session/src/index.ts) | [`session`](../packages/core/session) (`events.dispatch`) | [`agent-loop`](../packages/core/agent-loop), `file-upload`, `forge-session`, [`office-kit`](../packages/document/office-kit), `session-controller`, [`session-persistence-jsonl`](../packages/session/session-persistence-jsonl), [`session-persistence-sqlite`](../packages/session/session-persistence-sqlite), [`session-projection-cache`](../packages/session/session-projection-cache), [`session-telemetry`](../packages/session/session-telemetry), [`session-title`](../packages/session/session-title), `ui-trajectory`, [`workspace-changes`](../packages/deliverables/workspace-changes) |
| `session/disposed` | `emit` | [`packages/core/session/src/index.ts:65`](../packages/core/session/src/index.ts) | [`session`](../packages/core/session) (`events.dispatch`) | [`agent-loop`](../packages/core/agent-loop), `client-ui-forge`, `file-upload`, `forge-session`, [`office-kit`](../packages/document/office-kit), `session-controller`, [`session-persistence-jsonl`](../packages/session/session-persistence-jsonl), [`session-persistence-sqlite`](../packages/session/session-persistence-sqlite), [`session-projection-cache`](../packages/session/session-projection-cache), [`session-telemetry`](../packages/session/session-telemetry), [`session-title`](../packages/session/session-title), `ui-trajectory`, [`workspace-changes`](../packages/deliverables/workspace-changes) |
| `session/event` | `emit` | [`packages/core/session/src/index.ts:79`](../packages/core/session/src/index.ts) | [`session`](../packages/core/session) (`events.dispatch`) | [`acp`](../packages/acp/acp), [`agent-instructions`](../packages/context/agent-instructions), [`agent-loop`](../packages/core/agent-loop), [`agent-preset-registry`](../packages/preset/agent-preset-registry), `claude-code-mods`, `client-ui-forge`, [`compaction-basic`](../packages/compaction/compaction-basic), [`cua`](../packages/experimental/cua), [`file-reference-local`](../packages/context/file-reference-local), `file-upload`, `forge-session`, [`goal`](../packages/goal/goal), [`goal-round-driver`](../packages/goal/goal-round-driver), [`headless`](../packages/bundle/headless), [`loader-smoke`](../packages/test-support/loader-smoke), `product-analytics`, [`ptc-runtime-node`](../packages/ptc-runtime/ptc-runtime-node), `server`, `session-controller`, [`session-persistence-jsonl`](../packages/session/session-persistence-jsonl), [`session-persistence-sqlite`](../packages/session/session-persistence-sqlite), [`session-projection`](../packages/session/session-projection), [`session-projection-cache`](../packages/session/session-projection-cache), [`session-telemetry`](../packages/session/session-telemetry), [`session-telemetry-otel`](../packages/session/session-telemetry-otel), [`session-title`](../packages/session/session-title), [`subagent`](../packages/subagent/subagent), [`timeline`](../packages/experimental/timeline), [`token-meter`](../packages/llm/token-meter), [`tool-executor-ptc`](../packages/core/tool-executor-ptc), [`tool-jobs`](../packages/jobs/tool-jobs), [`tool-office`](../packages/document/tool-office), `ui-session-status`, `ui-trajectory`, [`user-questions`](../packages/interaction/user-questions), [`workspace-changes`](../packages/deliverables/workspace-changes) |
| `session/flush` | `parallel` | [`packages/core/session/src/index.ts:87`](../packages/core/session/src/index.ts) | [`session`](../packages/core/session) (`events.dispatch`) | [`session-persistence-jsonl`](../packages/session/session-persistence-jsonl), [`session-persistence-sqlite`](../packages/session/session-persistence-sqlite), [`session-telemetry`](../packages/session/session-telemetry) |
| `settings/document-updated` | `emit` | [`packages/settings/settings/src/types.ts:75`](../packages/settings/settings/src/types.ts) | [`settings`](../packages/settings/settings) (`emit`) | `remotes` |
+1 -1
View File
@@ -75,7 +75,7 @@
| `schedule/resolve-agent` | `waterfall` | [`packages/schedule/schedule/src/index.ts:72`](../packages/schedule/schedule/src/index.ts) | [`schedule`](../packages/schedule/schedule) (`waterfall`) | `server` |
| `session-telemetry/record` | `waterfall` | [`packages/session/session-telemetry/src/index.ts:44`](../packages/session/session-telemetry/src/index.ts) | [`session-telemetry`](../packages/session/session-telemetry) (`waterfall`) | - |
| `session/created` | `emit` | [`packages/core/session/src/index.ts:56`](../packages/core/session/src/index.ts) | [`session`](../packages/core/session) (`events.dispatch`) | `server`, `session-controller`, [`session-projection`](../packages/session/session-projection), [`session-projection-cache`](../packages/session/session-projection-cache), [`session-telemetry`](../packages/session/session-telemetry) |
| `session/disposed` | `emit` | [`packages/core/session/src/index.ts:65`](../packages/core/session/src/index.ts) | [`session`](../packages/core/session) (`events.dispatch`) | [`agent-loop`](../packages/core/agent-loop), `file-upload`, `forge-session`, [`office-kit`](../packages/document/office-kit), `session-controller`, [`session-persistence-jsonl`](../packages/session/session-persistence-jsonl), [`session-persistence-sqlite`](../packages/session/session-persistence-sqlite), [`session-projection-cache`](../packages/session/session-projection-cache), [`session-telemetry`](../packages/session/session-telemetry), [`session-title`](../packages/session/session-title), `ui-trajectory`, [`workspace-changes`](../packages/deliverables/workspace-changes) |
| `session/disposed` | `emit` | [`packages/core/session/src/index.ts:65`](../packages/core/session/src/index.ts) | [`session`](../packages/core/session) (`events.dispatch`) | [`agent-loop`](../packages/core/agent-loop), `client-ui-forge`, `file-upload`, `forge-session`, [`office-kit`](../packages/document/office-kit), `session-controller`, [`session-persistence-jsonl`](../packages/session/session-persistence-jsonl), [`session-persistence-sqlite`](../packages/session/session-persistence-sqlite), [`session-projection-cache`](../packages/session/session-projection-cache), [`session-telemetry`](../packages/session/session-telemetry), [`session-title`](../packages/session/session-title), `ui-trajectory`, [`workspace-changes`](../packages/deliverables/workspace-changes) |
| `session/event` | `emit` | [`packages/core/session/src/index.ts:79`](../packages/core/session/src/index.ts) | [`session`](../packages/core/session) (`events.dispatch`) | [`acp`](../packages/acp/acp), [`agent-instructions`](../packages/context/agent-instructions), [`agent-loop`](../packages/core/agent-loop), [`agent-preset-registry`](../packages/preset/agent-preset-registry), `claude-code-mods`, `client-ui-forge`, [`compaction-basic`](../packages/compaction/compaction-basic), [`cua`](../packages/experimental/cua), [`file-reference-local`](../packages/context/file-reference-local), `file-upload`, `forge-session`, [`goal`](../packages/goal/goal), [`goal-round-driver`](../packages/goal/goal-round-driver), [`headless`](../packages/bundle/headless), [`loader-smoke`](../packages/test-support/loader-smoke), `product-analytics`, [`ptc-runtime-node`](../packages/ptc-runtime/ptc-runtime-node), `server`, `session-controller`, [`session-persistence-jsonl`](../packages/session/session-persistence-jsonl), [`session-persistence-sqlite`](../packages/session/session-persistence-sqlite), [`session-projection`](../packages/session/session-projection), [`session-projection-cache`](../packages/session/session-projection-cache), [`session-telemetry`](../packages/session/session-telemetry), [`session-telemetry-otel`](../packages/session/session-telemetry-otel), [`session-title`](../packages/session/session-title), [`subagent`](../packages/subagent/subagent), [`timeline`](../packages/experimental/timeline), [`token-meter`](../packages/llm/token-meter), [`tool-executor-ptc`](../packages/core/tool-executor-ptc), [`tool-jobs`](../packages/jobs/tool-jobs), [`tool-office`](../packages/document/tool-office), `ui-session-status`, `ui-trajectory`, [`user-questions`](../packages/interaction/user-questions), [`workspace-changes`](../packages/deliverables/workspace-changes) |
| `session/flush` | `parallel` | [`packages/core/session/src/index.ts:87`](../packages/core/session/src/index.ts) | [`session`](../packages/core/session) (`events.dispatch`) | [`session-persistence-jsonl`](../packages/session/session-persistence-jsonl), [`session-persistence-sqlite`](../packages/session/session-persistence-sqlite), [`session-telemetry`](../packages/session/session-telemetry) |
| `settings/document-updated` | `emit` | [`packages/settings/settings/src/types.ts:75`](../packages/settings/settings/src/types.ts) | [`settings`](../packages/settings/settings) (`emit`) | `remotes` |
+7 -7
View File
@@ -2228,20 +2228,20 @@ Serves the forge panel. Following a Session inspects the checkout of its current
* Remember the change request a review conversation's draft quotes, or forget it with null. When the Session's next
* message enters its inbox, the change request is bound to the Session with a `track` record before the turn starts;
* a Session that already started is bound at its next message. The choice lives in memory until then.
* @param session - the Session whose draft quotes the change request.
* @param sessionId - the Session whose draft quotes the change request; staging neither loads nor resumes it.
* @param url - web URL of the change request, or null.
* @param signal - request cancellation.
* @throws `forgePanel/unrecognized-url` when no provider serves the URL.
*/
@Remote // oxlint-disable-next-line typescript/require-await -- async keeps a refused or cancelled request a rejection, as Remote callers expect async reviewStage(session: Session, url: string | null, signal: AbortSignal): Promise<void>
@Remote // oxlint-disable-next-line typescript/require-await -- async keeps a refused or cancelled request a rejection, as Remote callers expect async reviewStage(sessionId: SessionId, url: string | null, signal: AbortSignal): Promise<void>
/**
* Read or await the worktree service's archive cleanup of the Session's checkout.
* @param session - Session whose cleanup is visible to the caller.
* @param sessionId - Session whose cleanup is visible to the caller; reading neither loads nor resumes it.
* @param revision - null reads now; a matching revision waits for completion.
* @returns the cleanup state, or null without a worktree service, an attempt, or a current revision.
*/
@Remote async worktreeCleanup(session: Session, revision: number | null): Promise<WorktreeCleanup | null>
@Remote async worktreeCleanup(sessionId: SessionId, revision: number | null): Promise<WorktreeCleanup | null>
/**
* List the branches that can start a worktree of the Session's current checkout: the checked-out branch, each
@@ -2286,11 +2286,11 @@ Serves the forge panel. Following a Session inspects the checkout of its current
/**
* Reinspect a followed Session's checkout, probe sign-in again, and poll its
* change requests at once; an unfollowed Session is unchanged.
* @param session - Session whose panel refreshes.
* @param sessionId - Session whose panel refreshes; refreshing neither loads nor resumes it.
* @param signal - request cancellation.
* @returns settles once the inspection and the sign-in probe have ended; poll results reach the panel stream later.
*/
@Remote async refresh(session: Session, signal: AbortSignal): Promise<void>
@Remote async refresh(sessionId: SessionId, signal: AbortSignal): Promise<void>
/**
* Read the changes one scope covers in the checkout of the Session's
@@ -2665,7 +2665,7 @@ registerLens(lens: ForgeLens): () => Promise<void>
@Remote async continueInProject(session: Session, signal: AbortSignal): Promise<void>
```
Types: [Session](session.md) · [WorktreeCleanup](worktrees.md)
Types: [Session](session.md) · [SessionId](core.md) · [WorktreeCleanup](worktrees.md)
Source: [`packages/experimental/client-ui-forge/src/index.ts`](../../packages/experimental/client-ui-forge/src/index.ts)
+7 -7
View File
@@ -2232,20 +2232,20 @@ Serves the forge panel. Following a Session inspects the checkout of its current
* Remember the change request a review conversation's draft quotes, or forget it with null. When the Session's next
* message enters its inbox, the change request is bound to the Session with a `track` record before the turn starts;
* a Session that already started is bound at its next message. The choice lives in memory until then.
* @param session - the Session whose draft quotes the change request.
* @param sessionId - the Session whose draft quotes the change request; staging neither loads nor resumes it.
* @param url - web URL of the change request, or null.
* @param signal - request cancellation.
* @throws `forgePanel/unrecognized-url` when no provider serves the URL.
*/
@Remote // oxlint-disable-next-line typescript/require-await -- async keeps a refused or cancelled request a rejection, as Remote callers expect async reviewStage(session: Session, url: string | null, signal: AbortSignal): Promise<void>
@Remote // oxlint-disable-next-line typescript/require-await -- async keeps a refused or cancelled request a rejection, as Remote callers expect async reviewStage(sessionId: SessionId, url: string | null, signal: AbortSignal): Promise<void>
/**
* Read or await the worktree service's archive cleanup of the Session's checkout.
* @param session - Session whose cleanup is visible to the caller.
* @param sessionId - Session whose cleanup is visible to the caller; reading neither loads nor resumes it.
* @param revision - null reads now; a matching revision waits for completion.
* @returns the cleanup state, or null without a worktree service, an attempt, or a current revision.
*/
@Remote async worktreeCleanup(session: Session, revision: number | null): Promise<WorktreeCleanup | null>
@Remote async worktreeCleanup(sessionId: SessionId, revision: number | null): Promise<WorktreeCleanup | null>
/**
* List the branches that can start a worktree of the Session's current checkout: the checked-out branch, each
@@ -2290,11 +2290,11 @@ Serves the forge panel. Following a Session inspects the checkout of its current
/**
* Reinspect a followed Session's checkout, probe sign-in again, and poll its
* change requests at once; an unfollowed Session is unchanged.
* @param session - Session whose panel refreshes.
* @param sessionId - Session whose panel refreshes; refreshing neither loads nor resumes it.
* @param signal - request cancellation.
* @returns settles once the inspection and the sign-in probe have ended; poll results reach the panel stream later.
*/
@Remote async refresh(session: Session, signal: AbortSignal): Promise<void>
@Remote async refresh(sessionId: SessionId, signal: AbortSignal): Promise<void>
/**
* Read the changes one scope covers in the checkout of the Session's
@@ -2669,7 +2669,7 @@ registerLens(lens: ForgeLens): () => Promise<void>
@Remote async continueInProject(session: Session, signal: AbortSignal): Promise<void>
```
Types: [Session](session.zh.md) · [WorktreeCleanup](worktrees.zh.md)
Types: [Session](session.zh.md) · [SessionId](core.zh.md) · [WorktreeCleanup](worktrees.zh.md)
Source: [`packages/experimental/client-ui-forge/src/index.ts`](../../packages/experimental/client-ui-forge/src/index.ts)
+3 -3
View File
@@ -210,14 +210,14 @@ async exit(agent: Agent, signal?: AbortSignal): Promise<CreatedWorktree | Entere
/**
* Read the archive cleanup of a Session's created checkout; waiting never
* starts one. Absent without the Workspace and query providers.
* @param session - archived Session whose cleanup is read.
* @param sessionId - archived Session whose cleanup is read; reading neither loads nor resumes it.
* @param revision - null reads at once; a matching revision waits for that attempt to settle.
* @returns the attempt state, or null when none exists, the revision was superseded, or the service is stopping.
*/
async cleanupOf(session: Session, revision: number | null): Promise<WorktreeCleanup | null>
async cleanupOf(sessionId: SessionId, revision: number | null): Promise<WorktreeCleanup | null>
```
Types: [Agent](core.md) · [Session](session.md)
Types: [Agent](core.md) · [SessionId](core.md)
Source: [`packages/experimental/worktree/src/index.ts`](../../packages/experimental/worktree/src/index.ts)
+3 -3
View File
@@ -210,14 +210,14 @@ async exit(agent: Agent, signal?: AbortSignal): Promise<CreatedWorktree | Entere
/**
* Read the archive cleanup of a Session's created checkout; waiting never
* starts one. Absent without the Workspace and query providers.
* @param session - archived Session whose cleanup is read.
* @param sessionId - archived Session whose cleanup is read; reading neither loads nor resumes it.
* @param revision - null reads at once; a matching revision waits for that attempt to settle.
* @returns the attempt state, or null when none exists, the revision was superseded, or the service is stopping.
*/
async cleanupOf(session: Session, revision: number | null): Promise<WorktreeCleanup | null>
async cleanupOf(sessionId: SessionId, revision: number | null): Promise<WorktreeCleanup | null>
```
Types: [Agent](core.zh.md) · [Session](session.zh.md)
Types: [Agent](core.zh.md) · [SessionId](core.zh.md)
Source: [`packages/experimental/worktree/src/index.ts`](../../packages/experimental/worktree/src/index.ts)
@@ -18,8 +18,8 @@
en: b09c31932092f0a0
zh: b16598d5f50baab6
/deepseek-ai-dsh-experimental-client-ui-forge/understand-the-implementation:
en: af8aa7eeaf618133
zh: 95c763718f897df3
en: 5876ab4a46ee5e65
zh: b5ea47ac9665530e
/deepseek-ai-dsh-experimental-client-ui-forge/further-exploration:
en: fa4d8c579ffc49ff
zh: 5856ed7469e4585b
@@ -79,7 +79,7 @@ Each inspection also decides whether the worktree is missing: the Session's dire
`changeRequestStates` streams, for the Session list, the last known number, title, state, draft flag, checks rollup, review decision, and mergeability of every change request that a listed Session the caller may read binds: a `baseline` frame, then `changed` frames. One run serves every stream. Cancellation is observed before initialization and between frames; the last stream and plugin disposal await initialization and accepted writes, then close the run’s storage domain. A later run waits for that closure before reopening the domain and reading its stored states. Binding updates received during listing override its initial snapshot. It lists Sessions through `sessionQuery` without loading them, takes the visible bindings of a loaded Session from `ctx.forgeSession` and of another from its cached `forgeChangeRequests` summary, follows binding changes of loaded Sessions, and subscribes to each bound change request through `ctx.forge.watch`; closed requests use the idle polling cadence, and merged requests remain subscribed for explicit refresh. It stores every changed state in the `forge_panel_change_requests` storage domain under the SHA-256 digest of its URL and drops unbound stored states only when every listed Session has known bindings; a failed write is logged and the state stays in memory. The stream fails when the Host lacks the Session query, projection cache, storage, or Session store service.
The browser entry mounts the Remote, then the UI. One stream per Session feeds the Session panel entries, the New Session option, and the creation card; it opens with the first subscriber, closes with the last, reopens after a transport reset, and keeps the last state while the Session scope is retained. Releasing that scope closes the stream and removes its cached state. The New Session option fills `conversation.hero.options` and the worktree card `conversation.input.dock`. The worktree card shows a running creation, with Cancel calling `stopCreation` while a message waits for it, or the failed or stopped attempt a message waits after, with Retry calling `retryWorktree` and Continue without a worktree calling `cancelWorktree`. The change requests section is the `change-requests` entry of `conversation.session.panel.section` at order 100 with its count in `conversation.session.panel.section.actions`; the checkout, local changes, and connection rows are `conversation.session.panel.environment.row` entries at orders 20, 30, and 40, after the project row, and the attention mark is a `conversation.session.panel.indicator` entry. The checkout row shortens paths with the Host home from the Remote's Host facts, read again after each transport reset; it is mounted whenever the panel shows, so it runs the automatic refresh on mount and on window `focus` and `visibilitychange`, throttled per Session by the shared panel store. The toast lives in a `shell.overlay` entry so it outlives the panel. One stream of change request states feeds the Session row icons in `sidebar.session.row.trailing` and the hover card section in `sidebar.session.row.hover` while any of them is mounted; both take a Session's worktree and bindings from its Session list summary values. The change request card takes a change request, its snapshot, and optional actions, so another surface can reuse it. The changes view is the `forge-changes` resource tab type: its addresses, `dsh-resource://forge-changes/<session>/local` and `dsh-resource://forge-changes/<session>/change/<url>`, name the source, and a navigation may name a file to scroll to. The tab type enables `keepMounted`, retaining visited bodies and their owning Session references until their tab records end. Its keyed panel hook subscribes only for the visible body; other panel surfaces may keep the shared Session stream open. Its body keeps the scope, base branch, chosen commits, lens, test file switch, and layout choices of each tab in a slot store, keeps viewed marks per Session in `localStorage` under `dsh.forge-viewed.v1.<Session>`, at most 20 sources per Session and 50 Sessions, reads through the Remote, and passes each file section values that keep their identity across its renders, including the tab's visibility, so a render redraws only the sections whose values changed and a visibility change redraws every section. An expanded file draws its lines, highlighted with the shared code highlighter in the same render, once its section first comes within 1200px of the scrollport or a jump to one of its review threads targets it, keeps them drawn after that, and until then holds a 22px row per drawn line; a chip title shows its name with the changes icon. Once a file's whole new side is known, read for an expansion or, for local changes, read once per comparison when the file draws, each side of each run of drawn rows is highlighted again in idle time after up to 120 lines of the file before it, the old side rebuilt from the new side and the hunks; the new colors apply in one update after every run is done, and wait while the reader drags or holds a text selection in the file. A change request's files are not read for this, since each read is a request to the code host.
The browser entry mounts the Remote, then the UI. One stream per Session feeds the Session panel entries, the New Session option, and the creation card; it opens with the first subscriber, after a `forgePanel` Session reference has opened the Session's history, so the Host resumes the Session once rather than beside that opening, holds that reference until the stream ends, closes with the last, reopens after a transport reset, and keeps the last state while the Session scope is retained. Releasing that scope closes the stream and removes its cached state. The New Session option fills `conversation.hero.options` and the worktree card `conversation.input.dock`. The worktree card shows a running creation, with Cancel calling `stopCreation` while a message waits for it, or the failed or stopped attempt a message waits after, with Retry calling `retryWorktree` and Continue without a worktree calling `cancelWorktree`. The change requests section is the `change-requests` entry of `conversation.session.panel.section` at order 100 with its count in `conversation.session.panel.section.actions`; the checkout, local changes, and connection rows are `conversation.session.panel.environment.row` entries at orders 20, 30, and 40, after the project row, and the attention mark is a `conversation.session.panel.indicator` entry. The checkout row shortens paths with the Host home from the Remote's Host facts, read again after each transport reset; it is mounted whenever the panel shows, so it runs the automatic refresh on mount and on window `focus` and `visibilitychange`, throttled per Session by the shared panel store; a refresh asked for before the first panel state arrives runs once that state arrives, because the Host refreshes only a panel it follows. The toast lives in a `shell.overlay` entry so it outlives the panel. One stream of change request states feeds the Session row icons in `sidebar.session.row.trailing` and the hover card section in `sidebar.session.row.hover` while any of them is mounted; both take a Session's worktree and bindings from its Session list summary values. The change request card takes a change request, its snapshot, and optional actions, so another surface can reuse it. The changes view is the `forge-changes` resource tab type: its addresses, `dsh-resource://forge-changes/<session>/local` and `dsh-resource://forge-changes/<session>/change/<url>`, name the source, and a navigation may name a file to scroll to. The tab type enables `keepMounted`, retaining visited bodies and their owning Session references until their tab records end. Its keyed panel hook subscribes only for the visible body; other panel surfaces may keep the shared Session stream open. Its body keeps the scope, base branch, chosen commits, lens, test file switch, and layout choices of each tab in a slot store, keeps viewed marks per Session in `localStorage` under `dsh.forge-viewed.v1.<Session>`, at most 20 sources per Session and 50 Sessions, reads through the Remote, and passes each file section values that keep their identity across its renders, including the tab's visibility, so a render redraws only the sections whose values changed and a visibility change redraws every section. An expanded file draws its lines, highlighted with the shared code highlighter in the same render, once its section first comes within 1200px of the scrollport or a jump to one of its review threads targets it, keeps them drawn after that, and until then holds a 22px row per drawn line; a chip title shows its name with the changes icon. Once a file's whole new side is known, read for an expansion or, for local changes, read once per comparison when the file draws, each side of each run of drawn rows is highlighted again in idle time after up to 120 lines of the file before it, the old side rebuilt from the new side and the hunks; the new colors apply in one update after every run is done, and wait while the reader drags or holds a text selection in the file. A change request's files are not read for this, since each read is a request to the code host.
| Source | Responsibility |
|---|---|
@@ -79,7 +79,7 @@ Session 在所创建的 worktree 中工作时,`localDiff` 以它的 `baseCommi
`changeRequestStates` 为会话列表推送调用方可读的、已列出的 Session 所绑定的每个变更请求的最近编号、标题、状态、草稿标记、检查汇总、评审结论与可合并性:先是一个 `baseline` 帧,之后是 `changed` 帧。所有流共用一次运行。初始化之前和帧之间均响应取消;最后一条流结束及插件卸载会等待初始化与已接受的写入完成,再关闭本次运行的存储域。后续运行会等待该域关闭后重新打开,并读取已存状态。列举期间收到的绑定更新优先于初始快照。它经 `sessionQuery` 列出 Session 而不加载它们,已加载 Session 的可见绑定取自 `ctx.forgeSession`,其他 Session 的取自缓存的 `forgeChangeRequests` 摘要;它跟随已加载 Session 的绑定变化,并经 `ctx.forge.watch` 订阅每个已绑定的变更请求;已关闭的按空闲间隔轮询,已合并的保留订阅以接收显式刷新结果。每个变化了的状态以其 URL 的 SHA-256 摘要为键存入 `forge_panel_change_requests` 存储域,仅在所有已列出 Session 的绑定均已知时删除无人绑定的已存状态;写入失败时记录日志,状态仍保留在内存中。宿主缺少 Session 查询、投影缓存、存储或 Session 存储服务时,流以失败结束。
浏览器入口先挂载 Remote,再挂载界面。每个 Session 一条流,同时供给会话面板中的条目、新会话选项与创建卡片;第一个订阅方出现时打开,最后一个离开时关闭,传输重置后重新打开,在 Session scope 保留期间保存最后的状态。释放该 scope 时关闭流并移除缓存状态。新会话选项填入 `conversation.hero.options`,worktree 卡片填入 `conversation.input.dock`。worktree 卡片显示正在进行的创建,有消息在等待时“取消”调用 `stopCreation`;或显示消息等待时失败或被停止的那次尝试,“重试”调用 `retryWorktree`,“不使用工作树”调用 `cancelWorktree`。变更请求分栏是 `conversation.session.panel.section` 中 order 为 100 的 `change-requests` 条目,数量位于 `conversation.session.panel.section.actions`;检出行、本地变更行与连接行是 `conversation.session.panel.environment.row` 中 order 为 20、30 与 40 的条目,位于项目行之后;提醒标记是 `conversation.session.panel.indicator` 条目。检出行用 Remote 宿主信息中的宿主主目录缩短路径,每次传输重置后重新读取;面板显示时它始终挂载,因此由它在挂载时以及窗口 `focus` 与 `visibilitychange` 时触发自动刷新,按会话由共享的面板 store 限流。toast 位于 `shell.overlay` 条目中,因此比面板存在得更久。只要 `sidebar.session.row.trailing` 中的会话行图标或 `sidebar.session.row.hover` 中的悬浮卡片部分有一个已挂载,就由同一条变更请求状态流供给它们;两者都从会话列表的摘要值中读取 Session 的 worktree 与绑定。变更请求卡片接收变更请求、它的快照与可选操作,其他界面可以复用。变更视图是 `forge-changes` 资源标签页类型:它的地址 `dsh-resource://forge-changes/<session>/local` 与 `dsh-resource://forge-changes/<session>/change/<url>` 指明来源,导航参数可以指定要滚动到的文件。标签页类型启用 `keepMounted`,将访问过的正文及其所属 Session 引用保留至标签页记录结束。它的 keyed panel hook 仅为可见正文订阅;其他面板界面仍可能保持共享 Session 流开启。它的正文用 slot store 按标签页保存范围、基准分支、所选提交、透镜、测试文件开关与布局选择,按 Session 把已审阅标记保存在 `localStorage` 的 `dsh.forge-viewed.v1.<Session>` 下(每个 Session 最多 20 个来源,最多 50 个 Session),经 Remote 读取,并且传给每个文件段的值(包括标签页可见性)在多次渲染之间保持同一标识,所以一次渲染只重绘值有变化的文件段,可见性变化时重绘全部文件段。展开的文件在它的段第一次进入滚动区域 1200px 范围内,或跳转到它的某个评审讨论时,才绘制各行,并在同一次渲染中用共享的代码高亮器高亮,此后一直保留;在此之前按每个绘制行 22px 占位;标签页标题显示变更图标与视图名称。文件的整个新版本已知时(为展开而读取,或本地变更在文件绘制时按每次比较读取一次),每段绘制行的每一侧会在空闲时带上文件中它之前最多 120 行重新高亮,旧版本由新版本与 hunk 还原;所有段都算完后新颜色在一次更新中生效,读者正在拖选或文件内有文本选区时等它结束。变更请求的文件不为此读取,因为每次读取都是一次对代码托管平台的请求。
浏览器入口先挂载 Remote,再挂载界面。每个 Session 一条流,同时供给会话面板中的条目、新会话选项与创建卡片;第一个订阅方出现时,先由一个 `forgePanel` Session 引用打开该 Session 的历史再打开流,使 Host 只恢复一次该 Session、而不与这次打开并行,并持有该引用直到流结束;最后一个离开时关闭,传输重置后重新打开,在 Session scope 保留期间保存最后的状态。释放该 scope 时关闭流并移除缓存状态。新会话选项填入 `conversation.hero.options`,worktree 卡片填入 `conversation.input.dock`。worktree 卡片显示正在进行的创建,有消息在等待时“取消”调用 `stopCreation`;或显示消息等待时失败或被停止的那次尝试,“重试”调用 `retryWorktree`,“不使用工作树”调用 `cancelWorktree`。变更请求分栏是 `conversation.session.panel.section` 中 order 为 100 的 `change-requests` 条目,数量位于 `conversation.session.panel.section.actions`;检出行、本地变更行与连接行是 `conversation.session.panel.environment.row` 中 order 为 20、30 与 40 的条目,位于项目行之后;提醒标记是 `conversation.session.panel.indicator` 条目。检出行用 Remote 宿主信息中的宿主主目录缩短路径,每次传输重置后重新读取;面板显示时它始终挂载,因此由它在挂载时以及窗口 `focus` 与 `visibilitychange` 时触发自动刷新,按会话由共享的面板 store 限流;首个面板状态到达前请求的刷新等到该状态到达后执行,因为 Host 只刷新它正在跟随的面板。toast 位于 `shell.overlay` 条目中,因此比面板存在得更久。只要 `sidebar.session.row.trailing` 中的会话行图标或 `sidebar.session.row.hover` 中的悬浮卡片部分有一个已挂载,就由同一条变更请求状态流供给它们;两者都从会话列表的摘要值中读取 Session 的 worktree 与绑定。变更请求卡片接收变更请求、它的快照与可选操作,其他界面可以复用。变更视图是 `forge-changes` 资源标签页类型:它的地址 `dsh-resource://forge-changes/<session>/local` 与 `dsh-resource://forge-changes/<session>/change/<url>` 指明来源,导航参数可以指定要滚动到的文件。标签页类型启用 `keepMounted`,将访问过的正文及其所属 Session 引用保留至标签页记录结束。它的 keyed panel hook 仅为可见正文订阅;其他面板界面仍可能保持共享 Session 流开启。它的正文用 slot store 按标签页保存范围、基准分支、所选提交、透镜、测试文件开关与布局选择,按 Session 把已审阅标记保存在 `localStorage` 的 `dsh.forge-viewed.v1.<Session>` 下(每个 Session 最多 20 个来源,最多 50 个 Session),经 Remote 读取,并且传给每个文件段的值(包括标签页可见性)在多次渲染之间保持同一标识,所以一次渲染只重绘值有变化的文件段,可见性变化时重绘全部文件段。展开的文件在它的段第一次进入滚动区域 1200px 范围内,或跳转到它的某个评审讨论时,才绘制各行,并在同一次渲染中用共享的代码高亮器高亮,此后一直保留;在此之前按每个绘制行 22px 占位;标签页标题显示变更图标与视图名称。文件的整个新版本已知时(为展开而读取,或本地变更在文件绘制时按每次比较读取一次),每段绘制行的每一侧会在空闲时带上文件中它之前最多 120 行重新高亮,旧版本由新版本与 hunk 还原;所有段都算完后新颜色在一次更新中生效,读者正在拖选或文件内有文本选区时等它结束。变更请求的文件不为此读取,因为每次读取都是一次对代码托管平台的请求。
| 源码 | 职责 |
|---|---|
@@ -19,7 +19,7 @@ import type { ForgeReviewThread } from '@deepseek-ai/dsh-experimental-forge/type
import type { SessionId } from '@deepseek-ai/dsh-session/types'
import type { RemoteResult, TypertRemoteContribution } from '@deepseek-ai/dsh-typert-protocol'
import type {
ForgeChangeRequestListState, ForgeChangeRequestStatesFrame, ForgeExtensionState,
ForgeChangeRequestListState, ForgeChangeRequestStatesFrame, ForgeExtensionState, ForgePanelState,
} from '../types.ts'
import { actionReporter } from './action-notices.ts'
import { AnnotationView } from './annotations.ts'
@@ -48,7 +48,7 @@ import type { SessionListInjected } from './session-list.ts'
import { SessionHoverForge } from './SessionHoverForge.tsx'
import { SessionRowForge } from './SessionRowForge.tsx'
import {
createNoticeSource, createPanelSource, createStreamSource, foldStates, type PanelSource,
createNoticeSource, createPanelSource, createStreamSource, foldStates, type PanelSource, type PanelStream,
} from './source.ts'
import { numberOf, type ChangeRequestEntry } from './status.ts'
import type { WorktreeRequestResult } from './WorktreeNameDialog.tsx'
@@ -115,6 +115,34 @@ function registerUi(ctx: Context): void {
})
return { text: t('toast.archiveCleanupScheduled'), tone: 'success' }
})
/**
* Follow a Session's panel only after its own history connection opened: the Host resolves the `follow` argument
* by resuming the Session's Agent, which would otherwise read the Session log a second time beside that opening.
* The stream holds a Session reference until it ends, and calls `followed` once its first state arrived.
*/
const followOpened = (sessionId: SessionId, signal: AbortSignal, followed: () => void): PanelStream => {
let inner: PanelStream | undefined
async function* frames(): AsyncGenerator<ForgePanelState> {
const reference = ctx.sessions.retain(sessionId, { source: 'forgePanel', signal })
try {
const state = (await reference.ready).session.getSnapshot()
if (state.openState !== 'open') throw state.openError ?? new Error(`forge-panel: Session ${sessionId} is not open`)
inner = ctx.remote.forgePanel.follow(sessionId, signal)
let first = true
for await (const frame of inner) {
yield frame
// The source published the frame before asking for the next one.
if (first) {
first = false
followed()
}
}
} finally {
reference.release()
}
}
return Object.assign(frames(), { dispose: () => { inner?.dispose() } })
}
const stores = new Map<SessionId, SessionStores>()
ctx.effect(() => () => {
for (const store of [...stores.values()]) store.release()
@@ -125,8 +153,14 @@ function registerUi(ctx: Context): void {
if (store === undefined) {
const scope = ctx.sessions.scope(sessionId)
if (scope === undefined) throw new Error(`forge-panel: Session ${sessionId} is not retained`)
// A refresh asked for before the Host follows the panel would find no panel there, so it waits for the first state.
let deferred = false
const panel = createPanelSource({
open: signal => ctx.remote.forgePanel.follow(sessionId, signal),
open: signal => followOpened(sessionId, signal, () => {
if (!deferred) return
deferred = false
refreshIfStale()
}),
subscribeReset: listener => ctx.on('connection/reset', listener),
})
const dispose = scope.effect(() => () => {
@@ -135,6 +169,10 @@ function registerUi(ctx: Context): void {
}, 'forge-panel: release Session state')
let refreshedAt: number | undefined
const refreshIfStale = (): void => {
if (panel.hooks.panel.getSnapshot().state === null) {
deferred = true
return
}
const now = Date.now()
if (refreshedAt !== undefined && now - refreshedAt < AUTO_REFRESH_MIN_MS) return
refreshedAt = now
@@ -32,6 +32,8 @@ declare module '@deepseek-ai/dsh-api-session-controller/client' {
interface SessionReferenceSourceMap {
/** The review page's conversation about a change request. */
forgeReview: unknown
/** A Session panel stream, held from its opening until it ends. */
forgePanel: unknown
}
}
@@ -15,7 +15,7 @@ import type {
import type { SessionChangeRequest } from '@deepseek-ai/dsh-experimental-forge-session'
import type { WorktreeCleanup } from '@deepseek-ai/dsh-experimental-worktree/types'
import { appendPluginRecord } from '@deepseek-ai/dsh-session'
import type { Session, SessionEvent, UserMessage } from '@deepseek-ai/dsh-session'
import type { Session, SessionEvent, SessionId, UserMessage } from '@deepseek-ai/dsh-session'
import type { ProjectionHandle } from '@deepseek-ai/dsh-session-projection'
import type {} from '@deepseek-ai/dsh-session-projection-cache'
import type {} from '@deepseek-ai/dsh-session-query'
@@ -138,7 +138,7 @@ export class ForgePanelController extends TypertRemoteService {
private states: ChangeRequestStates | undefined
private readonly viewerLists: ViewerLists
/** The change request a review conversation's draft quotes, per Session, bound once its first message enters the inbox. */
private readonly staged = new WeakMap<Session, string>()
private readonly staged = new Map<SessionId, string>()
/** Review page streams of change requests shown in full, which a review change makes publish again. */
private readonly reviewFollowers = new Set<{ readonly key: ChangeRequestKey; readonly emit: () => void }>()
private readonly stopPanels: () => Promise<void>
@@ -223,6 +223,8 @@ export class ForgePanelController extends TypertRemoteService {
const events = ctx.on('session/event', (session: Session, event: SessionEvent) => {
this.panels.get(session)?.observe(event)
})
// A change request staged for a Session that is disposed before its next message is never bound.
const disposed = ctx.on('session/disposed', (session: Session) => { this.staged.delete(session.id) })
const reviewChanges = ctx.on('forge/review-changed', (ref: ChangeRequestRef) => { this.reviewChanged(ref) })
const services = ctx.on('internal/service', (name: string) => {
if (name !== 'worktrees') return
@@ -233,6 +235,7 @@ export class ForgePanelController extends TypertRemoteService {
yield stateOwner.dispose
yield inbox
yield events
yield disposed
yield reviewChanges
yield providers
yield services
@@ -614,32 +617,32 @@ export class ForgePanelController extends TypertRemoteService {
* Remember the change request a review conversation's draft quotes, or forget it with null. When the Session's next
* message enters its inbox, the change request is bound to the Session with a `track` record before the turn starts;
* a Session that already started is bound at its next message. The choice lives in memory until then.
* @param session - the Session whose draft quotes the change request.
* @param sessionId - the Session whose draft quotes the change request; staging neither loads nor resumes it.
* @param url - web URL of the change request, or null.
* @param signal - request cancellation.
* @throws `forgePanel/unrecognized-url` when no provider serves the URL.
*/
@Remote
// oxlint-disable-next-line typescript/require-await -- async keeps a refused or cancelled request a rejection, as Remote callers expect
async reviewStage(session: Session, url: string | null, signal: AbortSignal): Promise<void> {
async reviewStage(sessionId: SessionId, url: string | null, signal: AbortSignal): Promise<void> {
signal.throwIfAborted()
if (url === null) {
this.staged.delete(session)
this.staged.delete(sessionId)
return
}
this.served(url)
this.staged.set(session, url)
this.staged.set(sessionId, url)
}
/**
* Read or await the worktree service's archive cleanup of the Session's checkout.
* @param session - Session whose cleanup is visible to the caller.
* @param sessionId - Session whose cleanup is visible to the caller; reading neither loads nor resumes it.
* @param revision - null reads now; a matching revision waits for completion.
* @returns the cleanup state, or null without a worktree service, an attempt, or a current revision.
*/
@Remote
async worktreeCleanup(session: Session, revision: number | null): Promise<WorktreeCleanup | null> {
return await this.home.get('worktrees')?.cleanupOf(session, revision) ?? null
async worktreeCleanup(sessionId: SessionId, revision: number | null): Promise<WorktreeCleanup | null> {
return await this.home.get('worktrees')?.cleanupOf(sessionId, revision) ?? null
}
/**
@@ -713,14 +716,14 @@ export class ForgePanelController extends TypertRemoteService {
/**
* Reinspect a followed Session's checkout, probe sign-in again, and poll its
* change requests at once; an unfollowed Session is unchanged.
* @param session - Session whose panel refreshes.
* @param sessionId - Session whose panel refreshes; refreshing neither loads nor resumes it.
* @param signal - request cancellation.
* @returns settles once the inspection and the sign-in probe have ended; poll results reach the panel stream later.
*/
@Remote
async refresh(session: Session, signal: AbortSignal): Promise<void> {
async refresh(sessionId: SessionId, signal: AbortSignal): Promise<void> {
signal.throwIfAborted()
await this.panels.get(session)?.refresh()
for (const [session, panel] of this.panels) if (session.id === sessionId) await panel.refresh()
}
/**
@@ -1528,9 +1531,9 @@ export class ForgePanelController extends TypertRemoteService {
/** Bind the change request a review conversation staged once the Session's message enters its inbox. */
private bindStaged(session: Session): void {
const url = this.staged.get(session)
const url = this.staged.get(session.id)
if (url === undefined) return
this.staged.delete(session)
this.staged.delete(session.id)
// A provider withdrawn since the draft was staged leaves the message unbound.
if (this.home.forge.changeRequestFromUrl(url) !== undefined) this.home.forgeSession.track(session, url)
}
@@ -212,8 +212,11 @@ describe('forgePanel.follow', () => {
await follower.next(on('feat'))
expect(opened.provider.lookups).toEqual(['octo/demo feat'])
await opened.ctx.forgePanel.refresh(opened.session, signal)
await opened.ctx.forgePanel.refresh(opened.session.id, signal)
await vi.waitFor(() => { expect(opened.provider.lookups).toEqual(['octo/demo feat', 'octo/demo feat']) })
// A refresh names its Session by id and leaves the panels of other Sessions alone.
await opened.ctx.forgePanel.refresh(brandString<SessionId>('session-unfollowed'), signal)
expect(opened.provider.lookups).toEqual(['octo/demo feat', 'octo/demo feat'])
})
it('looks up nothing for an upstream on a remote that no provider recognizes', async () => {
@@ -239,7 +242,7 @@ describe('forgePanel.follow', () => {
const first = await follower.until(state => polled(state, pullUrl(7)) && failing(state, pullUrl(8)))
opened.provider.failures.set(7, { code: 'unavailable', message: 'offline' })
await opened.ctx.forgePanel.refresh(opened.session, signal)
await opened.ctx.forgePanel.refresh(opened.session.id, signal)
const later = await follower.until(state => failing(state, pullUrl(7)))
expect(first.changeRequests).toMatchObject([
@@ -475,7 +478,7 @@ describe('forgePanel local changes', () => {
.rejects.toMatchObject({ code: 'forgePanel/filter-config-failed' })
await git(repo, 'config', '--unset', key)
await opened.ctx.forgePanel.refresh(opened.session, signal)
await opened.ctx.forgePanel.refresh(opened.session.id, signal)
await expect(follower.until(state => state.local !== null)).resolves.toMatchObject({ local: { files: [{ path: 'tracked.txt' }] } })
await expect(opened.ctx.forgePanel.localDiff(opened.session, { kind: 'unstaged' }, signal))
.resolves.toMatchObject({ files: [{ path: 'tracked.txt' }] })
@@ -694,7 +697,7 @@ describe('forgePanel change request diffs', () => {
(await opened.ctx.forgePanel.changeRequestDiff(session, pullUrl(7), null, signal)).files.map(file => file.path)
const moved = async (snapshot: { headSha: string; baseBranch: string }): Promise<void> => {
opened.provider.overrides.set(7, snapshot)
await opened.ctx.forgePanel.refresh(opened.session, signal)
await opened.ctx.forgePanel.refresh(opened.session.id, signal)
await follower.until(state => state.changeRequests[0]?.snapshot?.baseBranch === snapshot.baseBranch
&& state.changeRequests[0].snapshot.headSha === snapshot.headSha)
}
@@ -980,7 +983,7 @@ describe('forgePanel worktree blockers', () => {
await follower.until(state => state.worktree.blocker === 'not-git')
opened.sandbox.failure = new Error('sandbox unavailable')
await opened.ctx.forgePanel.refresh(opened.session, signal)
await opened.ctx.forgePanel.refresh(opened.session.id, signal)
await expect(follower.next(state => state.checkout.state === 'failed')).resolves.toMatchObject({ worktree: { blocker: null } })
})
@@ -1050,11 +1053,11 @@ describe('forgePanel worktree requests', () => {
it('forwards the worktree service\'s cleanup state and answers null without the service', async () => {
const { repo } = await project()
const without = await open(repo)
expect(await without.ctx.forgePanel.worktreeCleanup(without.session, null)).toBeNull()
expect(await without.ctx.forgePanel.worktreeCleanup(without.session.id, null)).toBeNull()
const opened = await open(repo, {}, { worktrees: true })
expect(await opened.ctx.forgePanel.worktreeCleanup(opened.session, null)).toBeNull()
expect(await opened.ctx.forgePanel.worktreeCleanup(opened.session.id, null)).toBeNull()
vi.spyOn(opened.ctx.worktrees, 'cleanupOf').mockResolvedValue({ revision: 3, status: 'removed' })
expect(await opened.ctx.forgePanel.worktreeCleanup(opened.session, 3)).toEqual({ revision: 3, status: 'removed' })
expect(await opened.ctx.forgePanel.worktreeCleanup(opened.session.id, 3)).toEqual({ revision: 3, status: 'removed' })
})
it('refuses worktree requests and restoration without a worktree service, and keeps a waiting message for the withdrawal', async () => {
@@ -1603,7 +1606,7 @@ describe('forgePanel removed worktrees', () => {
await git(repo, 'worktree', 'prune')
await git(repo, 'branch', '-D', created.branch)
await opened.ctx.forgePanel.refresh(opened.session, signal)
await opened.ctx.forgePanel.refresh(opened.session.id, signal)
const gone = await follower.until(state => state.worktree.missing?.branchExists === false)
const restoration = follower.next(state => state.worktree.missing === null && state.checkout.state === 'ready')
await opened.ctx.forgePanel.restoreWorktree(opened.session, signal)
@@ -1650,13 +1653,13 @@ describe('forgePanel removed worktrees', () => {
await follower.until(state => state.directory === created.path && state.checkout.state === 'ready')
await rm(created.path, { recursive: true, force: true })
await opened.ctx.forgePanel.refresh(opened.session, signal)
await opened.ctx.forgePanel.refresh(opened.session.id, signal)
const inspected = await follower.next(state => state.worktree.missing !== null)
opened.sandbox.failure = new Error('sandbox unavailable')
sendPrompt(opened.agent, 'next')
await opened.agent.whenIdle()
const answer = follower.next(state => state.worktree.missing === null)
await opened.ctx.forgePanel.refresh(opened.session, signal)
await opened.ctx.forgePanel.refresh(opened.session.id, signal)
const unanswered = await answer
expect(inspected).toMatchObject({ directory: created.path, checkout: { state: 'failed' }, worktree: { missing: { branchExists: true } } })
@@ -1922,13 +1925,13 @@ describe('forgePanel actions', () => {
it('refreshes the checkout, sign-in state, and change requests of a followed Session only', async () => {
const { repo } = await project()
const opened = await open(repo)
await opened.ctx.forgePanel.refresh(opened.session, signal)
await opened.ctx.forgePanel.refresh(opened.session.id, signal)
shellTurn(opened.session, 1, [{ callId: 'create', command: 'gh pr create --fill', output: `${pullUrl(7)}\n` }])
const follower = reader(opened)
await follower.until(state => ready(state) && polled(state, pullUrl(7)))
const inspections = opened.sandbox.calls.length
await opened.ctx.forgePanel.refresh(opened.session, signal)
await opened.ctx.forgePanel.refresh(opened.session.id, signal)
await follower.until(() => opened.provider.fetches.length === 2
&& opened.sandbox.calls.length > inspections && opened.provider.probes.length === 2)
@@ -1943,7 +1946,7 @@ describe('forgePanel actions', () => {
let settled = false
const inspection = hold(opened.sandbox, '--show-toplevel')
const inspected = opened.ctx.forgePanel.refresh(opened.session, signal).then(() => { settled = true })
const inspected = opened.ctx.forgePanel.refresh(opened.session.id, signal).then(() => { settled = true })
await inspection.reached
await settle()
expect(settled).toBe(false)
@@ -1953,7 +1956,7 @@ describe('forgePanel actions', () => {
const probe = Promise.withResolvers<ForgeReadiness>()
opened.provider.readinessImpl = () => probe.promise
settled = false
const probed = opened.ctx.forgePanel.refresh(opened.session, signal).then(() => { settled = true })
const probed = opened.ctx.forgePanel.refresh(opened.session.id, signal).then(() => { settled = true })
await vi.waitFor(() => { expect(opened.provider.probes).toHaveLength(3) })
await settle()
expect(settled).toBe(false)
@@ -1972,7 +1975,7 @@ describe('forgePanel actions', () => {
const inspections = opened.sandbox.calls.length
shellTurn(opened.session, 1, [{ callId: 'list', command: 'ls', output: '' }])
await opened.ctx.forgePanel.refresh(opened.session, signal)
await opened.ctx.forgePanel.refresh(opened.session.id, signal)
await settle()
expect(opened.sandbox.calls.length).toBeGreaterThan(inspections)
@@ -2000,7 +2003,7 @@ describe('forgePanel actions', () => {
await follower.until(state => state.checkout.state === 'none')
const inspections = opened.sandbox.calls.length
await opened.ctx.forgePanel.refresh(opened.session, signal)
await opened.ctx.forgePanel.refresh(opened.session.id, signal)
// The refresh found the same state, which the panel already published.
const refreshed = follower.states.at(-1)
@@ -2201,7 +2204,7 @@ describe('forgePanel actions', () => {
await expect(opened.ctx.forgePanel.track(opened.session, pullUrl(1), controller.signal)).rejects.toThrow('closed')
await expect(opened.ctx.forgePanel.dismiss(opened.session, pullUrl(1), controller.signal)).rejects.toThrow('closed')
await expect(opened.ctx.forgePanel.refresh(opened.session, controller.signal)).rejects.toThrow('closed')
await expect(opened.ctx.forgePanel.refresh(opened.session.id, controller.signal)).rejects.toThrow('closed')
await expect(opened.ctx.forgePanel.localDiff(opened.session, { kind: 'unstaged' }, controller.signal)).rejects.toThrow('closed')
await expect(opened.ctx.forgePanel.localText(opened.session, { kind: 'unstaged' }, 'tracked.txt', controller.signal)).rejects.toThrow('closed')
await expect(opened.ctx.forgePanel.changeRequestDiff(opened.session, pullUrl(1), null, controller.signal)).rejects.toThrow('closed')
@@ -171,6 +171,11 @@ async function settle(): Promise<void> {
await new Promise(resolve => setTimeout(resolve, 0))
}
/** A Session binding whose history opening settled with `openState`. */
function opened(openState = 'open', openError: Error | null = null) {
return { session: { getSnapshot: () => ({ openState, openError }) } }
}
async function base() {
const ctx = new Context()
const unmount = vi.fn(async () => {})
@@ -307,9 +312,9 @@ async function base() {
if (fiber === undefined) { fiber = ctx.plugin(() => {}); scopes.set(id, fiber) }
return fiber.ctx
}),
// A reference to a retained Session whose opening has settled; only its identity and readiness are supplied.
retain: vi.fn((sessionId: SessionId, _options: { readonly source: string }) =>
({ sessionId, ready: Promise.resolve() })),
// A reference to a retained Session whose opening has settled; only its identity, readiness, open state, and release are supplied.
retain: vi.fn((sessionId: SessionId, _options: { readonly source: string; readonly signal?: AbortSignal }) =>
({ sessionId, ready: Promise.resolve(opened()), release: vi.fn() })),
}
ctx.provide('sessions', sessions)
const worktreeForm = stubConfigForm<WorktreeSettingsFields>()
@@ -496,6 +501,7 @@ describe('mountForgePanel registration', () => {
f.section(S1).hooks.panel.subscribe(() => {})
f.attention(S2)
f.list('row').hooks.states.subscribe(() => {})
await settle()
expect(f.streams).toHaveLength(1)
expect(f.stateStreams).toHaveLength(1)
@@ -630,7 +636,7 @@ describe('mountForgePanel Session stores', () => {
const seen: unknown[] = []
const unsubscribe = tab.hooks.panel.subscribe(() => { seen.push(tab.hooks.panel.getSnapshot().state) })
expect(f.forgePanel.follow).toHaveBeenCalledWith(S1, expect.any(AbortSignal))
await vi.waitFor(() => { expect(f.forgePanel.follow).toHaveBeenCalledWith(S1, expect.any(AbortSignal)) })
f.streams[0]?.push(ready())
await vi.waitFor(() => { expect(seen).toEqual([ready()]) })
@@ -638,12 +644,69 @@ describe('mountForgePanel Session stores', () => {
expect(f.forgePanel.follow).toHaveBeenCalledOnce()
f.ctx.emit('connection/reset')
expect(f.streams[0]?.disposed).toHaveBeenCalled()
expect(f.forgePanel.follow).toHaveBeenCalledTimes(2)
await vi.waitFor(() => { expect(f.forgePanel.follow).toHaveBeenCalledTimes(2) })
unsubscribe()
expect(f.streams[1]?.disposed).toHaveBeenCalled()
await f.dispose()
})
it('follows a Session panel only after the Session opened, holding a reference until the stream ends', async () => {
const f = await fixture()
const opening = Promise.withResolvers<ReturnType<typeof opened>>()
const release = vi.fn()
f.sessions.retain.mockReturnValueOnce({ sessionId: S1, ready: opening.promise, release })
const unsubscribe = f.section(S1).hooks.panel.subscribe(() => {})
expect(f.sessions.retain.mock.calls.at(-1)?.[0]).toBe(S1)
expect(f.sessions.retain.mock.calls.at(-1)?.[1]).toMatchObject({ source: 'forgePanel' })
expect(f.sessions.retain.mock.calls.at(-1)?.[1].signal).toBeInstanceOf(AbortSignal)
await settle()
expect(f.forgePanel.follow).not.toHaveBeenCalled()
opening.resolve(opened())
await vi.waitFor(() => { expect(f.forgePanel.follow).toHaveBeenCalledOnce() })
expect(release).not.toHaveBeenCalled()
unsubscribe()
await vi.waitFor(() => { expect(release).toHaveBeenCalledOnce() })
expect(f.streams[0]?.disposed).toHaveBeenCalled()
await f.dispose()
})
it('releases the reference without following when the panel closes before the Session opens', async () => {
const f = await fixture()
const release = vi.fn()
f.sessions.retain.mockImplementationOnce((sessionId, options) => {
const ready = new Promise<never>((_resolve, reject) => {
options.signal?.addEventListener('abort', () => { reject(new Error('waiter aborted')) }, { once: true })
})
return { sessionId, ready, release }
})
const unsubscribe = f.section(S1).hooks.panel.subscribe(() => {})
await settle()
unsubscribe()
await vi.waitFor(() => { expect(release).toHaveBeenCalledOnce() })
expect(f.forgePanel.follow).not.toHaveBeenCalled()
await f.dispose()
})
it.each([
['not open', opened('error', new Error('history failed'))],
['not open without a reported error', opened('error')],
])('shows the panel disconnected when the Session is %s, and follows after a reconnect', async (_name, binding) => {
const f = await fixture()
const release = vi.fn()
f.sessions.retain.mockReturnValueOnce({ sessionId: S1, ready: Promise.resolve(binding), release })
const panel = f.section(S1).hooks.panel
const unsubscribe = panel.subscribe(() => {})
await vi.waitFor(() => { expect(panel.getSnapshot().disconnected).toBe(true) })
expect(release).toHaveBeenCalledOnce()
expect(f.forgePanel.follow).not.toHaveBeenCalled()
f.connection(S1).reconnect()
await vi.waitFor(() => { expect(f.forgePanel.follow).toHaveBeenCalledOnce() })
unsubscribe()
await f.dispose()
})
it('shares the Host facts between Sessions and reads them again after each reconnect', async () => {
const f = await fixture()
const host = f.checkout(S1).hooks.host
@@ -666,6 +729,7 @@ describe('mountForgePanel Session stores', () => {
const f = await fixture()
const first = f.section(S1)
first.hooks.panel.subscribe(() => {})
await settle()
expect(f.attention(S1).hooks.panel).toBe(first.hooks.panel)
f.streams[0]!.push(ready({ changeRequests: [entry(1, snapshot(1))] }))
await settle()
@@ -677,7 +741,7 @@ describe('mountForgePanel Session stores', () => {
expect(next.hooks.panel.getSnapshot().state).toBeNull()
expect(f.attention(S1).hooks.panel).toBe(next.hooks.panel)
next.hooks.panel.subscribe(() => {})
expect(f.streams).toHaveLength(2)
await vi.waitFor(() => { expect(f.streams).toHaveLength(2) })
await f.dispose()
})
@@ -748,6 +812,10 @@ describe('mountForgePanel Session panel actions', () => {
it('refreshes each Session automatically at most once every 10 seconds', async () => {
const f = await fixture()
for (const id of [S1, S2]) f.section(id).hooks.panel.subscribe(() => {})
await vi.waitFor(() => { expect(f.streams).toHaveLength(2) })
for (const handle of f.streams) handle.push(ready())
await vi.waitFor(() => { expect(f.section(S2).hooks.panel.getSnapshot().state).not.toBeNull() })
const now = vi.spyOn(Date, 'now').mockReturnValue(1_000_000)
const refreshIfStale = f.checkout(S1).refreshIfStale
expect(f.checkout(S1).refreshIfStale).toBe(refreshIfStale)
@@ -769,6 +837,27 @@ describe('mountForgePanel Session panel actions', () => {
await f.dispose()
})
it('defers an automatic refresh asked for before the panel state arrives until the Host follows the panel', async () => {
const f = await fixture()
const unsubscribe = f.section(S1).hooks.panel.subscribe(() => {})
f.checkout(S1).refreshIfStale()
await vi.waitFor(() => { expect(f.forgePanel.follow).toHaveBeenCalledOnce() })
expect(f.forgePanel.refresh).not.toHaveBeenCalled()
f.streams[0]?.push(ready())
await vi.waitFor(() => { expect(f.forgePanel.refresh).toHaveBeenCalledWith(S1) })
f.streams[0]?.push(ready({ local: null }))
await settle()
expect(f.forgePanel.refresh).toHaveBeenCalledOnce()
// A later stream refreshes nothing on its own: only a refresh that was asked for waits for the first state.
f.ctx.emit('connection/reset')
await vi.waitFor(() => { expect(f.streams).toHaveLength(2) })
f.streams[1]?.push(ready())
await settle()
expect(f.forgePanel.refresh).toHaveBeenCalledOnce()
unsubscribe()
await f.dispose()
})
it('restores a removed worktree, confirming it or reporting why it failed until the notice is dismissed', async () => {
const f = await fixture()
f.checkout(S1).restore()
@@ -1818,7 +1907,7 @@ describe('mountForgePanel review page chat', () => {
it('warns when the conversation does not open', async () => {
const f = await chatFace()
const failure = new Error('closed')
f.sessions.retain.mockReturnValueOnce({ sessionId: S1, ready: Promise.reject(failure) })
f.sessions.retain.mockReturnValueOnce({ sessionId: S1, ready: Promise.reject(failure), release: vi.fn() })
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
await f.chat.fill(f.chat.retain(S1), { kind: 'reference', frame: reviewed(7) })
expect(warn).toHaveBeenCalledWith('forge-panel: the review conversation did not open:', failure)
@@ -433,7 +433,7 @@ describe('forgePanel review page actions', () => {
() => panel.reviewRequestReviews(UNSERVED, [{ kind: 'user', login: 'mona' }], signal),
() => panel.reviewReviewerCandidates(UNSERVED, '', signal),
() => panel.reviewUpdateBranch(UNSERVED, 'merge', HEAD, signal),
() => panel.reviewStage(opened.session, UNSERVED, signal),
() => panel.reviewStage(opened.session.id, UNSERVED, signal),
]
for (const request of requests) {
@@ -462,7 +462,7 @@ describe('forgePanel review page actions', () => {
() => panel.reviewText(url, HEAD, 'src/a.ts', aborted),
() => panel.reviewViewed(url, HEAD, aborted),
() => panel.reviewMarkReady(url, aborted),
() => panel.reviewStage(opened.session, url, aborted),
() => panel.reviewStage(opened.session.id, url, aborted),
]
for (const request of requests) await expect(request()).rejects.toThrow('closed')
@@ -475,7 +475,7 @@ describe('forgePanel.reviewStage', () => {
const opened = await page()
const bound = (): readonly unknown[] => opened.ctx.forgeSession.changeRequests(opened.session).map(entry => [entry.url, entry.origin])
await opened.ctx.forgePanel.reviewStage(opened.session, pullUrl(7), signal)
await opened.ctx.forgePanel.reviewStage(opened.session.id, pullUrl(7), signal)
expect(bound()).toEqual([])
sendPrompt(opened.agent, 'Review this change')
expect(bound()).toEqual([[pullUrl(7), 'tracked']])
@@ -489,17 +489,24 @@ describe('forgePanel.reviewStage', () => {
const opened = await page()
const bound = (): readonly string[] => opened.ctx.forgeSession.changeRequests(opened.session).map(entry => entry.url)
await opened.ctx.forgePanel.reviewStage(opened.session, pullUrl(7), signal)
await opened.ctx.forgePanel.reviewStage(opened.session, null, signal)
await opened.ctx.forgePanel.reviewStage(opened.session.id, pullUrl(7), signal)
await opened.ctx.forgePanel.reviewStage(opened.session.id, null, signal)
sendPrompt(opened.agent, 'Review this change')
expect(bound()).toEqual([])
const { registration } = await registerViewer(opened)
await opened.ctx.forgePanel.reviewStage(opened.session, 'https://view.test/octo/demo/pull/3', signal)
await opened.ctx.forgePanel.reviewStage(opened.session.id, 'https://view.test/octo/demo/pull/3', signal)
await registration.dispose()
sendPrompt(opened.agent, 'Review that change')
expect(bound()).toEqual([])
})
it('forgets a choice staged for a Session that leaves the store before its next message', async () => {
const opened = await page()
await opened.ctx.forgePanel.reviewStage(opened.session.id, pullUrl(7), signal)
opened.ctx.emit('session/disposed', opened.session)
sendPrompt(opened.agent, 'Review this change')
expect(opened.ctx.forgeSession.changeRequests(opened.session)).toEqual([])
})
})
describe('forgePanel review lists', () => {
@@ -81,7 +81,7 @@ describe('forgePanel change request reviews', () => {
expect(readReview).toHaveBeenCalledTimes(1)
panel.provider.overrides.set(7, { updatedAt: '2026-11-07T05:00:00Z' })
await panel.ctx.forgePanel.refresh(panel.session, signal)
await panel.ctx.forgePanel.refresh(panel.session.id, signal)
await follower.until(state => polledAt(state, pullUrl(7), HEAD, '2026-11-07T05:00:00Z'))
readReview.mockResolvedValueOnce(review(HEAD, 'src/b.ts'))
await expect(panel.ctx.forgePanel.changeRequestReview(panel.session, pullUrl(7), HEAD, false, signal))
@@ -105,16 +105,16 @@ export class WorktreeReclamation {
/**
* Read the most recent cleanup attempt of a Session; waiting never starts one.
* @param session - archived Session whose attempt is read.
* @param sessionId - archived Session whose attempt is read.
* @param revision - null reads at once; a matching revision waits for that attempt to settle.
* @returns the attempt state, or null when none exists, the revision was superseded, or the service is stopping.
*/
async cleanupOf(session: Session, revision: number | null): Promise<WorktreeCleanup | null> {
const attempt = this.attempts.get(session.id)
async cleanupOf(sessionId: SessionId, revision: number | null): Promise<WorktreeCleanup | null> {
const attempt = this.attempts.get(sessionId)
if (attempt === undefined || (revision !== null && revision !== attempt.revision)) return null
if (revision !== null) await attempt.done
// A cold Session without creations withdraws its placeholder while it settles.
if (this.lifetime.signal.aborted || this.attempts.get(session.id) !== attempt) return null
if (this.lifetime.signal.aborted || this.attempts.get(sessionId) !== attempt) return null
return { revision: attempt.revision, status: attempt.status }
}
+4 -4
View File
@@ -12,7 +12,7 @@ import type { SandboxExecutionPolicy } from '@deepseek-ai/dsh-sandbox'
import type {} from '@deepseek-ai/dsh-sandbox-policy'
import type {} from '@deepseek-ai/dsh-settings'
import { appendPluginRecord } from '@deepseek-ai/dsh-session'
import type { Session } from '@deepseek-ai/dsh-session'
import type { Session, SessionId } from '@deepseek-ai/dsh-session'
import type { ProjectionHandle } from '@deepseek-ai/dsh-session-projection'
import type {} from '@deepseek-ai/dsh-working-directory'
import { HarnessError } from '@deepseek-ai/dsh-error'
@@ -283,12 +283,12 @@ export class WorktreeService extends Service {
/**
* Read the archive cleanup of a Session's created checkout; waiting never
* starts one. Absent without the Workspace and query providers.
* @param session - archived Session whose cleanup is read.
* @param sessionId - archived Session whose cleanup is read; reading neither loads nor resumes it.
* @param revision - null reads at once; a matching revision waits for that attempt to settle.
* @returns the attempt state, or null when none exists, the revision was superseded, or the service is stopping.
*/
async cleanupOf(session: Session, revision: number | null): Promise<WorktreeCleanup | null> {
return await this.reclamation?.cleanupOf(session, revision) ?? null
async cleanupOf(sessionId: SessionId, revision: number | null): Promise<WorktreeCleanup | null> {
return await this.reclamation?.cleanupOf(sessionId, revision) ?? null
}
/**
@@ -103,8 +103,8 @@ type Fixture = Awaited<ReturnType<typeof fixture>>
/** The settled attempt of `session`, or null when the service registered none. */
async function settled(f: Fixture, session: Session = f.session): Promise<WorktreeCleanup | null> {
const scheduled = await f.ctx.worktrees.cleanupOf(session, null)
return scheduled === null ? null : await f.ctx.worktrees.cleanupOf(session, scheduled.revision)
const scheduled = await f.ctx.worktrees.cleanupOf(session.id, null)
return scheduled === null ? null : await f.ctx.worktrees.cleanupOf(session.id, scheduled.revision)
}
async function persisted(f: Fixture, session: Session): Promise<void> {
@@ -132,7 +132,7 @@ describe('archive-triggered worktree cleanup', () => {
const statuses: WorktreeCleanup['status'][] = []
f.ctx.on('worktree/cleanup', ({ cleanup }) => { statuses.push(cleanup.status) })
await f.ctx.workspaceRegistry.archiveSession(f.session.id)
expect(await f.ctx.worktrees.cleanupOf(f.session, null)).toMatchObject({ status: 'scheduled' })
expect(await f.ctx.worktrees.cleanupOf(f.session.id, null)).toMatchObject({ status: 'scheduled' })
expect(await settled(f)).toMatchObject({ status: 'removed' })
expect(statuses).toEqual(['scheduled', 'removed'])
await expect(access(f.worktree.path)).rejects.toMatchObject({ code: 'ENOENT' })
@@ -185,7 +185,7 @@ describe('archive-triggered worktree cleanup', () => {
})
cleanups.push(async () => { release.resolve(undefined) })
await f.ctx.workspaceRegistry.archiveSession(f.session.id)
expect(await f.ctx.worktrees.cleanupOf(f.session, null)).toMatchObject({ status: 'scheduled' })
expect(await f.ctx.worktrees.cleanupOf(f.session.id, null)).toMatchObject({ status: 'scheduled' })
release.resolve(undefined)
expect(await settled(f)).toMatchObject({ status: 'removed' })
})
@@ -224,13 +224,13 @@ describe('archive-triggered worktree cleanup', () => {
const f = await fixture()
const other = f.ctx.sessions.create(brandString<SessionId>('no-checkout'), { meta: { cwd: f.root } })
await f.ctx.workspaceRegistry.archiveSession(other.id)
expect(await f.ctx.worktrees.cleanupOf(other, null)).toBeNull()
expect(await f.ctx.worktrees.cleanupOf(other.id, null)).toBeNull()
const seed = f.session.snapshotEvents()
const fork = f.ctx.sessions.create(brandString<SessionId>('fork'), {
seed, inheritedEventCount: SessionLogOffset(seed.length), meta: { isSeeded: true, cwd: f.root },
})
await f.ctx.workspaceRegistry.archiveSession(fork.id)
expect(await f.ctx.worktrees.cleanupOf(fork, null)).toBeNull()
expect(await f.ctx.worktrees.cleanupOf(fork.id, null)).toBeNull()
await access(f.worktree.path)
})
@@ -244,7 +244,7 @@ describe('archive-triggered worktree cleanup', () => {
expect(await settled(f)).toMatchObject({ status: 'retained' })
await access(f.worktree.path)
await f.ctx.workspaceRegistry.archiveSession(fork.id)
expect(await f.ctx.worktrees.cleanupOf(fork, null)).toBeNull()
expect(await f.ctx.worktrees.cleanupOf(fork.id, null)).toBeNull()
await access(f.worktree.path)
await f.ctx.workspaceRegistry.unarchiveSession(f.session.id)
const borrower = f.ctx.sessions.create(brandString<SessionId>('borrower'), { meta: { cwd: f.worktree.path } })
@@ -381,7 +381,7 @@ describe('archive-triggered worktree cleanup', () => {
release.resolve(undefined)
await unarchive
expect(f.ctx.workspaceRegistry.archivedSessionIds).not.toContain(f.session.id)
expect(await f.ctx.worktrees.cleanupOf(f.session, null)).toBeNull()
expect(await f.ctx.worktrees.cleanupOf(f.session.id, null)).toBeNull()
await access(f.worktree.path)
expect(await f.ctx.workingDirectory.ensure(f.agent)).toBe(f.worktree.path)
})
@@ -423,7 +423,7 @@ describe('archive-triggered worktree cleanup', () => {
await f.ctx.workspaceRegistry.archiveSession(cold.session.id)
// A cold Session's creations are only known once its log or cache was read, so the placeholder settles to nothing.
expect(await settled(f, cold.session)).toBeNull()
expect(await f.ctx.worktrees.cleanupOf(cold.session, null)).toBeNull()
expect(await f.ctx.worktrees.cleanupOf(cold.session.id, null)).toBeNull()
await f.ctx.workspaceRegistry.unarchiveSession(cold.session.id)
expect(f.ctx.workspaceRegistry.archivedSessionIds).not.toContain(cold.session.id)
})
@@ -472,14 +472,14 @@ describe('archive-triggered worktree cleanup', () => {
expect(f.ctx.sessionProjections.snapshot(visitor).values.worktree).toEqual([])
await f.ctx.workspaceRegistry.archiveSession(visitor.id)
expect(await f.ctx.worktrees.cleanupOf(visitor, null)).toBeNull()
expect(await f.ctx.worktrees.cleanupOf(visitor.id, null)).toBeNull()
await access(f.worktree.path)
})
it('registers no attempt while retainOnArchive is set, and resumes once it is cleared', async () => {
const f = await fixture({ retainOnArchive: true })
await f.ctx.workspaceRegistry.archiveSession(f.session.id)
expect(await f.ctx.worktrees.cleanupOf(f.session, null)).toBeNull()
expect(await f.ctx.worktrees.cleanupOf(f.session.id, null)).toBeNull()
await access(f.worktree.path)
await f.ctx.workspaceRegistry.unarchiveSession(f.session.id)
await f.worktrees.update({ retainOnArchive: false })
@@ -499,8 +499,8 @@ describe('archive-triggered worktree cleanup', () => {
cleanups.push(async () => { release.resolve(undefined) })
await f.ctx.workspaceRegistry.archiveSession(f.session.id)
await entered.promise
const scheduled = await f.ctx.worktrees.cleanupOf(f.session, null)
const result = f.ctx.worktrees.cleanupOf(f.session, scheduled!.revision)
const scheduled = await f.ctx.worktrees.cleanupOf(f.session.id, null)
const result = f.ctx.worktrees.cleanupOf(f.session.id, scheduled!.revision)
const disposing = f.ctx.fiber.dispose()
release.resolve(undefined)
await disposing
@@ -1714,15 +1714,15 @@ export const SERVICE_API: readonly ServiceApiEntry[] = [
throws: ['`forgePanel/unrecognized-url` when no provider serves the URL; `forgePanel/stale-head`, `forgePanel/action-failed`, or `forgePanel/action-unknown` with the host\'s reason.'],
},
{
signature: '@Remote // oxlint-disable-next-line typescript/require-await -- async keeps a refused or cancelled request a rejection, as Remote callers expect async reviewStage(session: Session, url: string | null, signal: AbortSignal): Promise<void>',
signature: '@Remote // oxlint-disable-next-line typescript/require-await -- async keeps a refused or cancelled request a rejection, as Remote callers expect async reviewStage(sessionId: SessionId, url: string | null, signal: AbortSignal): Promise<void>',
description: 'Remember the change request a review conversation\'s draft quotes, or forget it with null. When the Session\'s next message enters its inbox, the change request is bound to the Session with a `track` record before the turn starts; a Session that already started is bound at its next message. The choice lives in memory until then.',
parameters: [{ name: 'session', description: 'the Session whose draft quotes the change request.' }, { name: 'url', description: 'web URL of the change request, or null.' }, { name: 'signal', description: 'request cancellation.' }],
parameters: [{ name: 'sessionId', description: 'the Session whose draft quotes the change request; staging neither loads nor resumes it.' }, { name: 'url', description: 'web URL of the change request, or null.' }, { name: 'signal', description: 'request cancellation.' }],
throws: ['`forgePanel/unrecognized-url` when no provider serves the URL.'],
},
{
signature: '@Remote async worktreeCleanup(session: Session, revision: number | null): Promise<WorktreeCleanup | null>',
signature: '@Remote async worktreeCleanup(sessionId: SessionId, revision: number | null): Promise<WorktreeCleanup | null>',
description: 'Read or await the worktree service\'s archive cleanup of the Session\'s checkout.',
parameters: [{ name: 'session', description: 'Session whose cleanup is visible to the caller.' }, { name: 'revision', description: 'null reads now; a matching revision waits for completion.' }],
parameters: [{ name: 'sessionId', description: 'Session whose cleanup is visible to the caller; reading neither loads nor resumes it.' }, { name: 'revision', description: 'null reads now; a matching revision waits for completion.' }],
returns: 'the cleanup state, or null without a worktree service, an attempt, or a current revision.',
},
{
@@ -1751,9 +1751,9 @@ export const SERVICE_API: readonly ServiceApiEntry[] = [
parameters: [{ name: 'session', description: 'Session that owns the binding.' }, { name: 'url', description: 'web URL of the change request.' }, { name: 'signal', description: 'request cancellation.' }],
},
{
signature: '@Remote async refresh(session: Session, signal: AbortSignal): Promise<void>',
signature: '@Remote async refresh(sessionId: SessionId, signal: AbortSignal): Promise<void>',
description: 'Reinspect a followed Session\'s checkout, probe sign-in again, and poll its change requests at once; an unfollowed Session is unchanged.',
parameters: [{ name: 'session', description: 'Session whose panel refreshes.' }, { name: 'signal', description: 'request cancellation.' }],
parameters: [{ name: 'sessionId', description: 'Session whose panel refreshes; refreshing neither loads nor resumes it.' }, { name: 'signal', description: 'request cancellation.' }],
returns: 'settles once the inspection and the sign-in probe have ended; poll results reach the panel stream later.',
},
{
@@ -5443,9 +5443,9 @@ export const SERVICE_API: readonly ServiceApiEntry[] = [
throws: ['{WorktreeError} `WORKTREE_NOT_ENTERED` when no recorded worktree contains the current directory and `WORKTREE_UNAVAILABLE` after service disposal, or the working-directory service\'s error when the source checkout no longer exists.'],
},
{
signature: 'async cleanupOf(session: Session, revision: number | null): Promise<WorktreeCleanup | null>',
signature: 'async cleanupOf(sessionId: SessionId, revision: number | null): Promise<WorktreeCleanup | null>',
description: 'Read the archive cleanup of a Session\'s created checkout; waiting never starts one. Absent without the Workspace and query providers.',
parameters: [{ name: 'session', description: 'archived Session whose cleanup is read.' }, { name: 'revision', description: 'null reads at once; a matching revision waits for that attempt to settle.' }],
parameters: [{ name: 'sessionId', description: 'archived Session whose cleanup is read; reading neither loads nor resumes it.' }, { name: 'revision', description: 'null reads at once; a matching revision waits for that attempt to settle.' }],
returns: 'the attempt state, or null when none exists, the revision was superseded, or the service is stopping.',
},
],