-
Notifications
You must be signed in to change notification settings - Fork 286
refactor(ui): route surfaces through one session runtime #998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| --- | ||
| --- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import { resolve } from "node:path"; | ||
| import type { AppBootstrap } from "../core/bootstrap"; | ||
| import type { TerminalThemeMode } from "../core/theme/detection"; | ||
| import type { ExtensionVcsHistoryReviewAction } from "../extension-api/types"; | ||
| import { retireExtensionLoadResult } from "../extensions/events"; | ||
| import type { ExtensionLoadResult } from "../extensions/types"; | ||
| import { prepareStartupPlan } from "./startup"; | ||
|
|
||
| export interface EmbeddedHistoryReviewRequest { | ||
| action: ExtensionVcsHistoryReviewAction; | ||
| providerId: string; | ||
| startupCwd: string; | ||
| extensionsEnabled: boolean; | ||
| extensionPaths: readonly string[]; | ||
| extensionSession?: ExtensionLoadResult; | ||
| themeId?: string; | ||
| themeMode?: TerminalThemeMode; | ||
| } | ||
|
|
||
| export interface EmbeddedHistoryReview { | ||
| bootstrap: AppBootstrap<ExtensionLoadResult>; | ||
| /** The history session owns this bootstrap's extension registry. */ | ||
| borrowsExtensions: boolean; | ||
| } | ||
|
|
||
| /** Convert a provider-owned review declaration into one option-safe internal invocation. */ | ||
| export function historyReviewArgs(action: ExtensionVcsHistoryReviewAction) { | ||
| const payload = Buffer.from(JSON.stringify(action), "utf8").toString("base64url"); | ||
| return [action.kind === "revision-range" ? "diff" : "show", "--history-review", payload]; | ||
| } | ||
|
|
||
| /** Bootstrap one provider-planned history review without creating or claiming a renderer. */ | ||
| export async function prepareEmbeddedHistoryReview( | ||
| request: EmbeddedHistoryReviewRequest, | ||
| { | ||
| signal, | ||
| env = process.env, | ||
| prepareStartupPlanImpl = prepareStartupPlan, | ||
| }: { | ||
| signal?: AbortSignal; | ||
| env?: NodeJS.ProcessEnv; | ||
| prepareStartupPlanImpl?: typeof prepareStartupPlan; | ||
| } = {}, | ||
| ): Promise<EmbeddedHistoryReview> { | ||
| signal?.throwIfAborted(); | ||
| const extensionArgs = request.extensionPaths.flatMap((path) => [ | ||
| "--extension", | ||
| resolve(request.startupCwd, path), | ||
| ]); | ||
| const args = [ | ||
| ...historyReviewArgs(request.action), | ||
| "--vcs", | ||
| request.providerId, | ||
| ...(request.themeId ? ["--theme", request.themeId] : []), | ||
| ...(request.extensionsEnabled ? extensionArgs : ["--no-extensions"]), | ||
| ]; | ||
| const plan = await prepareStartupPlanImpl(["hunk", "hunk", ...args], { | ||
| cwd: request.startupCwd, | ||
| env, | ||
| signal, | ||
| borrowedExtensionLoad: request.extensionSession, | ||
| stdinIsTTY: true, | ||
| stdoutIsTTY: true, | ||
| terminalThemeMode: request.themeMode, | ||
| }); | ||
| if (signal?.aborted && plan.kind === "app") { | ||
| plan.controllingTerminal?.close(); | ||
| if (plan.bootstrap.extensions !== request.extensionSession) { | ||
| await retireExtensionLoadResult(plan.bootstrap.extensions); | ||
| } | ||
| signal.throwIfAborted(); | ||
| } | ||
| if (plan.kind !== "app") { | ||
| throw new Error("The selected commit did not produce an interactive review."); | ||
| } | ||
| plan.controllingTerminal?.close(); | ||
| return { | ||
| bootstrap: plan.bootstrap as AppBootstrap<ExtensionLoadResult>, | ||
| borrowsExtensions: plan.bootstrap.extensions === request.extensionSession, | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import { createNativeSessionBrokerLifecycleClock } from "@hunk/session-broker"; | ||
| import type { AppBootstrap } from "../../core/bootstrap"; | ||
| import { SessionBrokerClient } from "../../session/broker/brokerClient"; | ||
| import { reportHunkSessionBrokerLifecycleDefect } from "../../session/broker/lifecycleDefect"; | ||
| import { ReviewProducer } from "../review/producer"; | ||
| import { createInitialSessionSnapshot, createSessionRegistration } from "./registration"; | ||
|
|
||
| export interface ReviewSessionRuntime { | ||
| hostClient: SessionBrokerClient; | ||
| reviewProducer: ReviewProducer; | ||
| stop(): void; | ||
| } | ||
|
|
||
| /** Create broker and producer resources for one independently mountable review surface. */ | ||
| export function createReviewSessionRuntime( | ||
| bootstrap: AppBootstrap, | ||
| cwd = process.cwd(), | ||
| ): ReviewSessionRuntime { | ||
| const reviewProducer = new ReviewProducer({ | ||
| files: bootstrap.changeset.files, | ||
| sourceLabel: bootstrap.changeset.sourceLabel, | ||
| }); | ||
| const publication = reviewProducer.getPublication(); | ||
| const lifecycleClock = createNativeSessionBrokerLifecycleClock(); | ||
| const hostClient = new SessionBrokerClient( | ||
| createSessionRegistration(bootstrap, publication, cwd), | ||
| createInitialSessionSnapshot(bootstrap, publication), | ||
| { lifecycleClock, onDefect: reportHunkSessionBrokerLifecycleDefect }, | ||
| ); | ||
| hostClient.start(); | ||
| let stopped = false; | ||
| return { | ||
| hostClient, | ||
| reviewProducer, | ||
| stop() { | ||
| if (stopped) return; | ||
| hostClient.stop(); | ||
| stopped = true; | ||
| }, | ||
| }; | ||
| } |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,2 @@ | ||
| /** Preserve the original import seam while interactive history moves into the log feature folder. */ | ||
| export { historyReviewArgs } from "../log/reviewLaunch"; | ||
| /** Preserve the original runner import seam while interactive history lives in the log feature. */ | ||
| export { runInteractiveLog as runInteractiveHistory } from "../log/runInteractiveLog"; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new file uses a camel-cased filename, but the repository requires TypeScript filenames to use dash-case. The same violation appears in
src/app/session/reviewRuntime.tsandsrc/ui/session/HunkSessionHost.tsx, with another occurrence elsewhere in the new session module. These files must be renamed and their imports updated before merging.Context Used: guidelines.mdc Cursor rule (source)
Prompt To Fix With AI
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This repository does not require dash-case TypeScript filenames. Its established naming convention includes
AppHost.tsx,LogApp.tsx,useAppKeyboardShortcuts.ts, and many other camel-cased component/hook/module names. The cited rule belongs to a different repository (modem-dev/modem), while Hunk’s ownAGENTS.mdcontains no dash-case requirement. These new filenames follow the local convention, so no rename is needed.This comment was generated by Pi using gpt-5.6-sol
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. I incorrectly applied a dash-case convention from another repository; Hunk's
AGENTS.mddoes not require it, and the existingAppHost.tsx,LogApp.tsx, anduseAppKeyboardShortcuts.tsnames support the local convention. No rename is needed, and I withdraw this comment.