GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(app): send browser, file and review comments to the session with… · yusha/opencode@3bc82a1

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages
    • app/src
      • composer
        • editor
          • interaction.ts
          • quote-comment.stories.tsx
        • machine.test.ts
        • machine.ts
        • model.ts
        • submit.test.ts
        • submit.ts
      • runtime/plugin
        • mounted-session.ts
      • session
        • composer
          • region.tsx
        • screen.tsx
        • timeline
          • quote.stories.tsx
          • quote.tsx
    • gui-plugins/src
      • browser
        • i18n
          • en.ts
        • overlay-machine.test.ts
        • overlay-machine.ts
        • panel.fixture.tsx
        • panel.stories.tsx
        • panel.tsx
      • file
        • browser.stories.tsx
        • i18n
          • en.ts
        • view.tsx
      • review
        • i18n
          • en.ts
        • model.ts
        • panel.stories.tsx
        • panel.tsx
    • plugin/src/gui
      • host-apis.ts
    • session-ui/src
      • components
        • line-comment-annotations.tsx
        • line-comment-machine.test.ts
        • line-comment-machine.ts
        • session-review.tsx
      • v2/components
        • line-comment-annotations-v2.tsx
        • session-review-file-preview-v2.tsx
    • stories/mocks/gui-plugins
      • workspace-panel.tsx
      • workspace.ts
    • ui/src/data-display/line-comment
      • line-comment.stories.tsx
      • line-comment.tsx
      • machine.test.ts
      • machine.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/app/src/composer/editor/interaction.ts‎

Copy file name to clipboardExpand all lines: packages/app/src/composer/editor/interaction.ts
+11-5Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,10 @@ export type ComposerEditorView = {
7171
canSubmit?: Accessor<boolean>
7272
working?: Accessor<boolean>
7373
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
7978
onSubmit: (options?: { alternate?: boolean; first?: boolean }) => void
8079
onStop: () => void
8180
}
@@ -85,6 +84,13 @@ export type ComposerEditorView = {
8584
}
8685
}
8786

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+
8894
const DRAFT_EDITED: ComposerInteractionEvent = Object.freeze({ type: "draft.edited" })
8995

9096
const HISTORY_RESET: ComposerInteractionEvent = Object.freeze({ type: "history.reset" })
Collapse file

‎packages/app/src/composer/editor/quote-comment.stories.tsx‎

Copy file name to clipboard
+133Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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

‎packages/app/src/composer/machine.test.ts‎

Copy file name to clipboardExpand all lines: packages/app/src/composer/machine.test.ts
+7-7Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
type ComposerSubmitEvent,
99
type ComposerSubmitState,
1010
type ComposerSubmitTransition,
11-
type QuoteSnapshot,
11+
type CommentSnapshot,
1212
type SubmitSnapshot,
1313
} from "./machine"
1414
import { retryFingerprint } from "./retry"
@@ -89,10 +89,10 @@ function snapshot(
8989
}
9090
}
9191

92-
function quoteSnapshot(input: Partial<QuoteSnapshot> = {}): QuoteSnapshot {
92+
function commentSnapshot(input: Partial<CommentSnapshot> = {}): CommentSnapshot {
9393
return {
9494
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" },
9696
comment: "Compare",
9797
selection,
9898
delivery: "steer",
@@ -134,7 +134,7 @@ const states = {
134134
started(1),
135135
{ type: "handoff.ready", attempt: 1, prompt: undefined },
136136
]).state,
137-
quoting: replay([{ type: "quote", snapshot: quoteSnapshot(), done }]).state,
137+
quoting: replay([{ type: "comment", snapshot: commentSnapshot(), done }]).state,
138138
}
139139

140140
describe("composer submit machine", () => {
@@ -146,7 +146,7 @@ describe("composer submit machine", () => {
146146
// Enter, then a click on Send, Mod+Enter and a quote, all while the image's URL resolves.
147147
{ type: "submit", snapshot: snapshot(), done },
148148
{ type: "submit", snapshot: snapshot({ alternate: true }), done },
149-
{ type: "quote", snapshot: quoteSnapshot(), done },
149+
{ type: "comment", snapshot: commentSnapshot(), done },
150150
{
151151
type: "session.started",
152152
attempt: 1,
@@ -200,12 +200,12 @@ describe("composer submit machine", () => {
200200
expect(sent({ ...shell, retry: { id: retry.id, fingerprint: fingerprint(shell) } })).toBe(shell.id)
201201
})
202202

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) => {
204204
expect(transitionComposerSubmit(state, { type: "submit", snapshot: snapshot(), done })).toEqual({
205205
state,
206206
effects: [{ type: "done", done, sent: false }],
207207
})
208-
expect(transitionComposerSubmit(state, { type: "quote", snapshot: quoteSnapshot(), done })).toEqual({
208+
expect(transitionComposerSubmit(state, { type: "comment", snapshot: commentSnapshot(), done })).toEqual({
209209
state,
210210
effects: [{ type: "done", done, sent: false }],
211211
})
Collapse file

‎packages/app/src/composer/machine.ts‎

Copy file name to clipboardExpand all lines: packages/app/src/composer/machine.ts
+16-22Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export type ComposerSubmission = {
2020
first?: boolean
2121
}
2222

23-
type QuoteItem = Extract<ComposerSubmission["context"][number], { type: "quote" }>
23+
type CommentItem = ComposerSubmission["context"][number]
2424

2525
/** What a submission sends. A prompt is in flight before the composer clears; shell and commands start after. */
2626
export type SubmissionKind =
@@ -46,7 +46,7 @@ export type CapturedDraft = {
4646
*/
4747
export type PromptSend = { settled: (restore: (cancelled: boolean) => boolean) => Promise<boolean> }
4848

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. */
5050
export type SubmitDone = (sent: boolean) => void
5151

5252
/** 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 =
6565
// Session shows in its timeline at once and leaves the composer (`shown`); any other send waits in the composer,
6666
// where an edit cancels it.
6767
| { 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.
7070
| { type: "running"; attempt: number; gate: SendGate; done: SubmitDone }
7171
// Image attachments resolve and, for a new Session, the Session starts. Nothing is sent yet. `cleared` is the
7272
// composer a shown hold already cleared.
@@ -117,9 +117,9 @@ export type SubmitSnapshot = {
117117
session: ComposerSession | undefined
118118
}
119119

120-
export type QuoteSnapshot = {
120+
export type CommentSnapshot = {
121121
key: string
122-
quote: QuoteItem | undefined
122+
item: CommentItem | undefined
123123
comment: string
124124
selection: ComposerSelection | undefined
125125
delivery: ComposerDelivery
@@ -129,7 +129,7 @@ export type QuoteSnapshot = {
129129

130130
export type ComposerSubmitEvent =
131131
| { type: "submit"; snapshot: SubmitSnapshot; done: SubmitDone }
132-
| { type: "quote"; snapshot: QuoteSnapshot; done: SubmitDone }
132+
| { type: "comment"; snapshot: CommentSnapshot; done: SubmitDone }
133133
| { type: "stop" }
134134
| { type: "unmounted" }
135135
| { type: "hold.changed"; attempt: number }
@@ -173,10 +173,10 @@ export type ComposerSubmitEffect =
173173
| { type: "hold.cancel"; session: ComposerSession; snapshot: SubmitSnapshot; cleared: Prompt | undefined }
174174
| { type: "command.run"; attempt: number; prompt: Prompt; run: () => void | Promise<void> }
175175
| {
176-
type: "quote.send"
176+
type: "comment.send"
177177
attempt: number
178178
key: string
179-
quote: QuoteItem
179+
item: CommentItem
180180
comment: string
181181
session: ComposerSession
182182
value: ComposerSubmission
@@ -226,7 +226,7 @@ export function transitionComposerSubmit(
226226
): ComposerSubmitTransition {
227227
if (event.type === "submit") return submit(state, event.snapshot, event.done)
228228

229-
if (event.type === "quote") return quote(state, event.snapshot, event.done)
229+
if (event.type === "comment") return comment(state, event.snapshot, event.done)
230230

231231
if (event.type === "stop") return stop(state)
232232

@@ -385,7 +385,7 @@ function stop(state: ComposerSubmitState): ComposerSubmitTransition {
385385
if (state.type === "sending" || (state.type === "handing-off" && state.gate === "pending"))
386386
return settle(state, false, [{ type: "send.cancel", attempt: state.attempt }])
387387

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.
389389
if (state.type === "running" && state.gate === "pending")
390390
return { state, effects: [{ type: "send.cancel", attempt: state.attempt }] }
391391

@@ -487,8 +487,8 @@ function cancelHold(state: Extract<ComposerSubmitState, { type: "held" }>, effec
487487
])
488488
}
489489

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 }] }
492492

493493
if (!snapshot.selection)
494494
return { state, effects: [{ type: "notify.missing-selection" }, { type: "done", done, sent: false }] }
@@ -498,23 +498,17 @@ function quote(state: ComposerSubmitState, snapshot: QuoteSnapshot, done: Submit
498498
state: { type: "running", attempt, gate: "pending", done },
499499
effects: [
500500
{
501-
type: "quote.send",
501+
type: "comment.send",
502502
attempt,
503503
key: snapshot.key,
504-
quote: snapshot.quote,
504+
item: snapshot.item,
505505
comment: snapshot.comment,
506506
session: snapshot.session,
507507
value: {
508508
id: snapshot.id,
509509
mode: "normal",
510510
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 }],
518512
text: "",
519513
images: [],
520514
selection: snapshot.selection,
Collapse file

‎packages/app/src/composer/model.ts‎

Copy file name to clipboardExpand all lines: packages/app/src/composer/model.ts
+15-6Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ export function createComposerModel(adapter: ComposerAdapter, options?: { queue?
334334
comments: {
335335
capture: historyComments,
336336
clear: comments.clear,
337+
remove: comments.remove,
337338
restore: restoreHistoryComments,
338339
},
339340
clientCommand: (text) => {
@@ -350,6 +351,9 @@ export function createComposerModel(adapter: ComposerAdapter, options?: { queue?
350351

351352
const submitView = createMemo(() => composerSubmitView(submission.state()))
352353

354+
const commentSendable = () =>
355+
available() && !adapter.controls().model.loading && submitView().canSubmit && !options?.queue?.undoing()
356+
353357
const controller = createComposerEditor({
354358
store: prompt.store,
355359
history: {
@@ -540,13 +544,18 @@ export function createComposerModel(adapter: ComposerAdapter, options?: { queue?
540544
quote:
541545
adapter.kind === "active-session"
542546
? {
543-
available: () =>
544-
available() &&
545-
!adapter.controls().model.loading &&
546-
submitView().canSubmit &&
547-
!options?.queue?.undoing(),
547+
available: commentSendable,
548548
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 }),
550559
}
551560
: undefined,
552561
onSubmit: (submitOptions) => {

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.