GeezerVison is showing github.com — feat(app): send browser, file and review comments to the session with… · yusha/opencode@3bc82a1
File treeExpand file treeCollapse file tree Open diff view settings stories/mocks/gui-plugins ui/src/data-display/line-comment
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/app/src/composer/editor/interaction.ts +11-5Lines changed: 11 additions & 5 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -71,11 +71,10 @@ export type ComposerEditorView = { | 71 | 71 | canSubmit?: Accessor<boolean> | 72 | 72 | working?: Accessor<boolean> | 73 | 73 | queue?: ComposerQueue | 74 | | - quote?: { | 75 | | - available: Accessor<boolean> | 76 | | - delivery: Accessor<ComposerDelivery | undefined> | 77 | | - onSubmit: (key: string, comment: string) => Promise<boolean> | 78 | | - } | | 74 | + /** The quote comment editor's Mod+Enter send, which takes the composer's Mod+Enter delivery. */ | | 75 | + quote?: ComposerCommentSend | | 76 | + /** A plugin comment editor's send, which takes the follow-up behavior the composer's Enter uses. */ | | 77 | + comment?: ComposerCommentSend | 79 | 78 | onSubmit: (options?: { alternate?: boolean; first?: boolean }) => void | 80 | 79 | onStop: () => void | 81 | 80 | } | @@ -85,6 +84,13 @@ export type ComposerEditorView = { | 85 | 84 | } | 86 | 85 | } | 87 | 86 |
| | 87 | +/** Sends one attached part on its own; `delivery` is undefined while the session is idle. */ | | 88 | +export type ComposerCommentSend = { | | 89 | + available: Accessor<boolean> | | 90 | + delivery: Accessor<ComposerDelivery | undefined> | | 91 | + onSubmit: (key: string, comment: string) => Promise<boolean> | | 92 | +} | | 93 | + | 88 | 94 | const DRAFT_EDITED: ComposerInteractionEvent = Object.freeze({ type: "draft.edited" }) | 89 | 95 |
| 90 | 96 | const HISTORY_RESET: ComposerInteractionEvent = Object.freeze({ type: "history.reset" }) | |
Collapse file Copy file name to clipboard +133Lines changed: 133 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +import { createEffect, createSignal, Show } from "solid-js" | | 2 | +import type { ComposerDelivery } from "../adapter" | | 3 | +import { QuoteCommentEditor } from "./quote-comment" | | 4 | + | | 5 | +const docs = `### Overview | | 6 | +The comment editor of a quote attached to the composer, opened from the timeline's Quote action, a terminal quote or a quote chip. | | 7 | +
| | 8 | +### Actions | | 9 | +- Enter saves the comment: **Done** while it is empty, **Add comment** once typed, **Save** for a comment the quote already had. | | 10 | +- Mod+Enter sends the quote with its comment now, as a prompt of its own: **Send quote** while the session is idle, **Steer with quote** or **Queue quote** while it works. A new session's draft has no such action. | | 11 | +- While the send is in flight the editor shows a loader; when it fails the draft stays with an alert. | | 12 | +
| | 13 | +The browser pane, file viewer and review diff offer the same two actions on their own comment editors (see UI/LineComment). | | 14 | +` | | 15 | + | | 16 | +export default { | | 17 | + title: "Composer/QuoteComment", | | 18 | + id: "composer-quote-comment", | | 19 | + parameters: { docs: { description: { component: docs } } }, | | 20 | +} | | 21 | + | | 22 | +const base = { | | 23 | + text: "The composer clears once the prompt is in flight, so a failed send restores it.", | | 24 | + comment: "", | | 25 | + draft: "", | | 26 | + delivery: "steer", | | 27 | + sendUnavailable: false, | | 28 | + sending: false, | | 29 | + failed: false, | | 30 | +} | | 31 | + | | 32 | +type Args = typeof base | | 33 | + | | 34 | +function delivery(value: string): ComposerDelivery | undefined { | | 35 | + if (value === "steer" || value === "queue") return value | | 36 | +} | | 37 | + | | 38 | +export const Editor = { | | 39 | + args: base, | | 40 | + argTypes: { | | 41 | + delivery: { control: "select", options: ["none", "send", "steer", "queue"] }, | | 42 | + }, | | 43 | + render: (args: Args) => { | | 44 | + const [anchor, setAnchor] = createSignal<HTMLElement>() | | 45 | + | | 46 | + const [draft, setDraft] = createSignal(args.draft || args.comment) | | 47 | + | | 48 | + const [result, setResult] = createSignal("") | | 49 | + | | 50 | + createEffect(() => setDraft(args.draft || args.comment)) | | 51 | + | | 52 | + return ( | | 53 | + <div style={{ height: "360px", display: "flex", "flex-direction": "column", "justify-content": "flex-end" }}> | | 54 | + <div | | 55 | + ref={setAnchor} | | 56 | + class="w-[240px] truncate rounded-[6px] bg-v2-background-bg-layer-01 px-2 py-1 text-[12px] leading-[var(--line-height-compact)] text-v2-text-text-base" | | 57 | + > | | 58 | + {args.text} | | 59 | + </div> | | 60 | + <output aria-label="Editor result">{result()}</output> | | 61 | + <Show when={anchor()}> | | 62 | + {(element) => ( | | 63 | + <QuoteCommentEditor | | 64 | + anchor={element()} | | 65 | + text={args.text} | | 66 | + comment={args.comment} | | 67 | + view={{ | | 68 | + draft: draft(), | | 69 | + sending: args.sending, | | 70 | + failed: args.failed, | | 71 | + canDismissOutside: false, | | 72 | + }} | | 73 | + mention={async (query) => | | 74 | + ["src/composer/submit.ts", "src/composer/machine.ts"].filter((path) => path.includes(query)) | | 75 | + } | | 76 | + onInput={setDraft} | | 77 | + onSubmit={(comment) => setResult(`Saved: ${comment}`)} | | 78 | + onClose={() => setResult("Closed")} | | 79 | + send={ | | 80 | + args.delivery === "none" | | 81 | + ? undefined | | 82 | + : { | | 83 | + available: !args.sendUnavailable, | | 84 | + // The composer reports no delivery while the session is idle; the label then says Send. | | 85 | + delivery: delivery(args.delivery), | | 86 | + onSubmit: (comment) => setResult(`Sent (${args.delivery}): ${comment}`), | | 87 | + } | | 88 | + } | | 89 | + /> | | 90 | + )} | | 91 | + </Show> | | 92 | + </div> | | 93 | + ) | | 94 | + }, | | 95 | +} | | 96 | + | | 97 | +/** A quote that was just added: Enter closes it ("Done"), Mod+Enter steers the working session with it. */ | | 98 | +export const NewQuoteSteer = { args: base, render: Editor.render } | | 99 | + | | 100 | +/** A typed comment: Enter adds it to the quote, Mod+Enter steers with it. */ | | 101 | +export const DraftSteer = { args: { ...base, draft: "Does this also cover a promoted draft?" }, render: Editor.render } | | 102 | + | | 103 | +/** The session is idle: Mod+Enter sends the quote as a new prompt. */ | | 104 | +export const DraftSend = { args: { ...DraftSteer.args, delivery: "send" }, render: Editor.render } | | 105 | + | | 106 | +/** Mod+Enter queues while the session works, when the queue setting says so. */ | | 107 | +export const DraftQueue = { args: { ...DraftSteer.args, delivery: "queue" }, render: Editor.render } | | 108 | + | | 109 | +/** Nothing can be sent now, e.g. while another send is in flight or the models load. */ | | 110 | +export const DraftSendUnavailable = { args: { ...DraftSteer.args, sendUnavailable: true }, render: Editor.render } | | 111 | + | | 112 | +/** A new session's draft: there is no session to send to, so only Enter's action shows. */ | | 113 | +export const DraftWithoutSend = { args: { ...DraftSteer.args, delivery: "none" }, render: Editor.render } | | 114 | + | | 115 | +/** Editing the comment a quote already has: Enter saves it. */ | | 116 | +export const EditSaved = { | | 117 | + args: { ...base, comment: "Check the restore path too", draft: "Check the restore path too, and the retry ID" }, | | 118 | + render: Editor.render, | | 119 | +} | | 120 | + | | 121 | +export const Sending = { args: { ...DraftSteer.args, sending: true }, render: Editor.render } | | 122 | + | | 123 | +/** The send failed: the draft stays, with an alert until the next edit. */ | | 124 | +export const SendFailed = { args: { ...DraftSteer.args, failed: true }, render: Editor.render } | | 125 | + | | 126 | +/** A long multi-line quote, such as terminal output, previews its first lines. */ | | 127 | +export const LongQuote = { | | 128 | + args: { | | 129 | + ...DraftSteer.args, | | 130 | + text: '$ bun test\nsrc/composer/submit.test.ts:\n(fail) a file comment sends alone\nExpected: ["src/api.ts#c1"]\nReceived: []\n 53 pass\n 1 fail', | | 131 | + }, | | 132 | + render: Editor.render, | | 133 | +} |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/composer/machine.test.ts +7-7Lines changed: 7 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 8 | 8 | type ComposerSubmitEvent, | 9 | 9 | type ComposerSubmitState, | 10 | 10 | type ComposerSubmitTransition, | 11 | | - type QuoteSnapshot, | | 11 | + type CommentSnapshot, | 12 | 12 | type SubmitSnapshot, | 13 | 13 | } from "./machine" | 14 | 14 | import { retryFingerprint } from "./retry" | @@ -89,10 +89,10 @@ function snapshot( | 89 | 89 | } | 90 | 90 | } | 91 | 91 |
| 92 | | -function quoteSnapshot(input: Partial<QuoteSnapshot> = {}): QuoteSnapshot { | | 92 | +function commentSnapshot(input: Partial<CommentSnapshot> = {}): CommentSnapshot { | 93 | 93 | return { | 94 | 94 | key: "quote:c=selected", | 95 | | - quote: { key: "quote:c=selected", type: "quote", text: "Selected passage", commentID: "selected" }, | | 95 | + item: { key: "quote:c=selected", type: "quote", text: "Selected passage", commentID: "selected" }, | 96 | 96 | comment: "Compare", | 97 | 97 | selection, | 98 | 98 | delivery: "steer", | @@ -134,7 +134,7 @@ const states = { | 134 | 134 | started(1), | 135 | 135 | { type: "handoff.ready", attempt: 1, prompt: undefined }, | 136 | 136 | ]).state, | 137 | | - quoting: replay([{ type: "quote", snapshot: quoteSnapshot(), done }]).state, | | 137 | + quoting: replay([{ type: "comment", snapshot: commentSnapshot(), done }]).state, | 138 | 138 | } | 139 | 139 |
| 140 | 140 | describe("composer submit machine", () => { | @@ -146,7 +146,7 @@ describe("composer submit machine", () => { | 146 | 146 | // Enter, then a click on Send, Mod+Enter and a quote, all while the image's URL resolves. | 147 | 147 | { type: "submit", snapshot: snapshot(), done }, | 148 | 148 | { type: "submit", snapshot: snapshot({ alternate: true }), done }, | 149 | | - { type: "quote", snapshot: quoteSnapshot(), done }, | | 149 | + { type: "comment", snapshot: commentSnapshot(), done }, | 150 | 150 | { | 151 | 151 | type: "session.started", | 152 | 152 | attempt: 1, | @@ -200,12 +200,12 @@ describe("composer submit machine", () => { | 200 | 200 | expect(sent({ ...shell, retry: { id: retry.id, fingerprint: fingerprint(shell) } })).toBe(shell.id) | 201 | 201 | }) | 202 | 202 |
| 203 | | - test.each(Object.entries(states))("ignores another submit or quote while %s", (_name, state) => { | | 203 | + test.each(Object.entries(states))("ignores another submit or comment while %s", (_name, state) => { | 204 | 204 | expect(transitionComposerSubmit(state, { type: "submit", snapshot: snapshot(), done })).toEqual({ | 205 | 205 | state, | 206 | 206 | effects: [{ type: "done", done, sent: false }], | 207 | 207 | }) | 208 | | - expect(transitionComposerSubmit(state, { type: "quote", snapshot: quoteSnapshot(), done })).toEqual({ | | 208 | + expect(transitionComposerSubmit(state, { type: "comment", snapshot: commentSnapshot(), done })).toEqual({ | 209 | 209 | state, | 210 | 210 | effects: [{ type: "done", done, sent: false }], | 211 | 211 | }) | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/composer/machine.ts +16-22Lines changed: 16 additions & 22 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -20,7 +20,7 @@ export type ComposerSubmission = { | 20 | 20 | first?: boolean | 21 | 21 | } | 22 | 22 |
| 23 | | -type QuoteItem = Extract<ComposerSubmission["context"][number], { type: "quote" }> | | 23 | +type CommentItem = ComposerSubmission["context"][number] | 24 | 24 |
| 25 | 25 | /** What a submission sends. A prompt is in flight before the composer clears; shell and commands start after. */ | 26 | 26 | export type SubmissionKind = | @@ -46,7 +46,7 @@ export type CapturedDraft = { | 46 | 46 | */ | 47 | 47 | export type PromptSend = { settled: (restore: (cancelled: boolean) => boolean) => Promise<boolean> } | 48 | 48 |
| 49 | | -/** Settles the caller of `submit` or `submitQuote`; `sent` is false when nothing was sent. */ | | 49 | +/** Settles the caller of `submit` or `submitComment`; `sent` is false when nothing was sent. */ | 50 | 50 | export type SubmitDone = (sent: boolean) => void | 51 | 51 |
| 52 | 52 | /** A held prompt that already shows in its Session's timeline; `cleared` is the composer it left, once cleared. */ | @@ -65,8 +65,8 @@ export type ComposerSubmitState = | 65 | 65 | // Session shows in its timeline at once and leaves the composer (`shown`); any other send waits in the composer, | 66 | 66 | // where an edit cancels it. | 67 | 67 | | { type: "held"; attempt: number; snapshot: SubmitSnapshot; shown: ShownHold | undefined; done: SubmitDone } | 68 | | - // A client command or a quote runs; neither takes the draft, but the composer submits nothing else meanwhile. A quote | 69 | | - // is a prompt, so it waits on the gate as one does. | | 68 | + // A client command or one attached comment runs; neither takes the draft, but the composer submits nothing else | | 69 | + // meanwhile. A comment is a prompt, so it waits on the gate as one does. | 70 | 70 | | { type: "running"; attempt: number; gate: SendGate; done: SubmitDone } | 71 | 71 | // Image attachments resolve and, for a new Session, the Session starts. Nothing is sent yet. `cleared` is the | 72 | 72 | // composer a shown hold already cleared. | @@ -117,9 +117,9 @@ export type SubmitSnapshot = { | 117 | 117 | session: ComposerSession | undefined | 118 | 118 | } | 119 | 119 |
| 120 | | -export type QuoteSnapshot = { | | 120 | +export type CommentSnapshot = { | 121 | 121 | key: string | 122 | | - quote: QuoteItem | undefined | | 122 | + item: CommentItem | undefined | 123 | 123 | comment: string | 124 | 124 | selection: ComposerSelection | undefined | 125 | 125 | delivery: ComposerDelivery | @@ -129,7 +129,7 @@ export type QuoteSnapshot = { | 129 | 129 |
| 130 | 130 | export type ComposerSubmitEvent = | 131 | 131 | | { type: "submit"; snapshot: SubmitSnapshot; done: SubmitDone } | 132 | | - | { type: "quote"; snapshot: QuoteSnapshot; done: SubmitDone } | | 132 | + | { type: "comment"; snapshot: CommentSnapshot; done: SubmitDone } | 133 | 133 | | { type: "stop" } | 134 | 134 | | { type: "unmounted" } | 135 | 135 | | { type: "hold.changed"; attempt: number } | @@ -173,10 +173,10 @@ export type ComposerSubmitEffect = | 173 | 173 | | { type: "hold.cancel"; session: ComposerSession; snapshot: SubmitSnapshot; cleared: Prompt | undefined } | 174 | 174 | | { type: "command.run"; attempt: number; prompt: Prompt; run: () => void | Promise<void> } | 175 | 175 | | { | 176 | | - type: "quote.send" | | 176 | + type: "comment.send" | 177 | 177 | attempt: number | 178 | 178 | key: string | 179 | | - quote: QuoteItem | | 179 | + item: CommentItem | 180 | 180 | comment: string | 181 | 181 | session: ComposerSession | 182 | 182 | value: ComposerSubmission | @@ -226,7 +226,7 @@ export function transitionComposerSubmit( | 226 | 226 | ): ComposerSubmitTransition { | 227 | 227 | if (event.type === "submit") return submit(state, event.snapshot, event.done) | 228 | 228 |
| 229 | | - if (event.type === "quote") return quote(state, event.snapshot, event.done) | | 229 | + if (event.type === "comment") return comment(state, event.snapshot, event.done) | 230 | 230 |
| 231 | 231 | if (event.type === "stop") return stop(state) | 232 | 232 |
| @@ -385,7 +385,7 @@ function stop(state: ComposerSubmitState): ComposerSubmitTransition { | 385 | 385 | if (state.type === "sending" || (state.type === "handing-off" && state.gate === "pending")) | 386 | 386 | return settle(state, false, [{ type: "send.cancel", attempt: state.attempt }]) | 387 | 387 |
| 388 | | - // The quote's own send settles the run once it fails as cancelled. | | 388 | + // The comment's own send settles the run once it fails as cancelled. | 389 | 389 | if (state.type === "running" && state.gate === "pending") | 390 | 390 | return { state, effects: [{ type: "send.cancel", attempt: state.attempt }] } | 391 | 391 |
| @@ -487,8 +487,8 @@ function cancelHold(state: Extract<ComposerSubmitState, { type: "held" }>, effec | 487 | 487 | ]) | 488 | 488 | } | 489 | 489 |
| 490 | | -function quote(state: ComposerSubmitState, snapshot: QuoteSnapshot, done: SubmitDone): ComposerSubmitTransition { | 491 | | - if (state.type !== "idle" || !snapshot.quote) return { state, effects: [{ type: "done", done, sent: false }] } | | 490 | +function comment(state: ComposerSubmitState, snapshot: CommentSnapshot, done: SubmitDone): ComposerSubmitTransition { | | 491 | + if (state.type !== "idle" || !snapshot.item) return { state, effects: [{ type: "done", done, sent: false }] } | 492 | 492 |
| 493 | 493 | if (!snapshot.selection) | 494 | 494 | return { state, effects: [{ type: "notify.missing-selection" }, { type: "done", done, sent: false }] } | @@ -498,23 +498,17 @@ function quote(state: ComposerSubmitState, snapshot: QuoteSnapshot, done: Submit | 498 | 498 | state: { type: "running", attempt, gate: "pending", done }, | 499 | 499 | effects: [ | 500 | 500 | { | 501 | | - type: "quote.send", | | 501 | + type: "comment.send", | 502 | 502 | attempt, | 503 | 503 | key: snapshot.key, | 504 | | - quote: snapshot.quote, | | 504 | + item: snapshot.item, | 505 | 505 | comment: snapshot.comment, | 506 | 506 | session: snapshot.session, | 507 | 507 | value: { | 508 | 508 | id: snapshot.id, | 509 | 509 | mode: "normal", | 510 | 510 | prompt: [], | 511 | | - context: [ | 512 | | - { | 513 | | - ...snapshot.quote, | 514 | | - comment: snapshot.comment, | 515 | | - source: snapshot.quote.source ? { ...snapshot.quote.source } : undefined, | 516 | | - }, | 517 | | - ], | | 511 | + context: [{ ...snapshot.item, comment: snapshot.comment }], | 518 | 512 | text: "", | 519 | 513 | images: [], | 520 | 514 | selection: snapshot.selection, | |
Collapse file Copy file name to clipboardExpand all lines: packages/app/src/composer/model.ts +15-6Lines changed: 15 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -334,6 +334,7 @@ export function createComposerModel(adapter: ComposerAdapter, options?: { queue? | 334 | 334 | comments: { | 335 | 335 | capture: historyComments, | 336 | 336 | clear: comments.clear, | | 337 | + remove: comments.remove, | 337 | 338 | restore: restoreHistoryComments, | 338 | 339 | }, | 339 | 340 | clientCommand: (text) => { | @@ -350,6 +351,9 @@ export function createComposerModel(adapter: ComposerAdapter, options?: { queue? | 350 | 351 |
| 351 | 352 | const submitView = createMemo(() => composerSubmitView(submission.state())) | 352 | 353 |
| | 354 | + const commentSendable = () => | | 355 | + available() && !adapter.controls().model.loading && submitView().canSubmit && !options?.queue?.undoing() | | 356 | + | 353 | 357 | const controller = createComposerEditor({ | 354 | 358 | store: prompt.store, | 355 | 359 | history: { | @@ -540,13 +544,18 @@ export function createComposerModel(adapter: ComposerAdapter, options?: { queue? | 540 | 544 | quote: | 541 | 545 | adapter.kind === "active-session" | 542 | 546 | ? { | 543 | | - available: () => | 544 | | - available() && | 545 | | - !adapter.controls().model.loading && | 546 | | - submitView().canSubmit && | 547 | | - !options?.queue?.undoing(), | | 547 | + available: commentSendable, | 548 | 548 | delivery: () => (adapter.working() ? (options?.queue?.alternate() ?? "steer") : undefined), | 549 | | - onSubmit: submission.submitQuote, | | 549 | + onSubmit: submission.submitComment, | | 550 | + } | | 551 | + : undefined, | | 552 | + comment: | | 553 | + adapter.kind === "active-session" | | 554 | + ? { | | 555 | + available: commentSendable, | | 556 | + delivery: () => (adapter.working() ? (options?.queue?.delivery() ?? "steer") : undefined), | | 557 | + onSubmit: (key: string, comment: string) => | | 558 | + submission.submitComment(key, comment, { alternate: false }), | 550 | 559 | } | 551 | 560 | : undefined, | 552 | 561 | onSubmit: (submitOptions) => { | |
|