Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

178 linesCodeBlameRaw
1/**
2 * Home's way into Ask (components/ask-composer): the box at the top of the
3 * page, What changed (g1t's plain-English summary of the span, streamed
4 * onto the page by components/home-summary), and Explain on each change
5 * that landed (components/home.tsx). The box and Explain hand their
6 * question to the top bar's Ask panel (lib/ask.ts askG1t). Every question
7 * goes to the viewer's direct message with @g1t, so the answers stay in
8 * Chat and Ask carries on from them.
9 */
10import { ArrowUp, MessageSquare, RotateCcw, Sparkles } from "lucide-react";
11import { type FormEvent, type KeyboardEvent, Suspense, lazy, useCallback, useEffect, useRef, useState } from "react";
12import { Link } from "react-router";
13
14import { askG1t, openAsk } from "../lib/ask";
15import { HOME_STARTERS, type Span, summarizeQuestion } from "../lib/home";
16import { Suggestion, Suggestions } from "./ai-elements/suggestion";
17import { MarkGlyph } from "./logo";
18import { Button } from "./ui/button";
19import { Hint } from "./ui/hint";
20import { Skeleton } from "./ui/skeleton";
21import { Textarea } from "./ui/textarea";
22
23const loadSummary = () => import("./home-summary");
24const HomeSummary = lazy(loadSummary);
25
26type AskSpan = Pick<Span, "key" | "note" | "words" | "from" | "now">;
27
28/** The window event Home's box sends to have What changed summarize the span. */
29const SUMMARIZE_EVENT = "g1t:home-summarize";
30
31/** What the span is called on a button: "since I was last here", "in the last 24 hours". */
32function spanLabel(span: AskSpan): string {
33 return span.key === "last" && span.note == null ? "since I was last here" : `${span.words.charAt(0).toLowerCase()}${span.words.slice(1)}`;
34}
35
36/** The top of Home: what are we building today, a box that asks g1t, and a few things to ask first. */
37export function HomeAsk({ span }: { span: AskSpan }) {
38 const [draft, setDraft] = useState("");
39 const send = () => {
40 if (!draft.trim()) return;
41 askG1t(draft);
42 setDraft("");
43 };
44 const submit = (event: FormEvent) => {
45 event.preventDefault();
46 send();
47 };
48 const onKeyDown = (event: KeyboardEvent<HTMLTextAreaElement>) => {
49 if (event.key === "Enter" && !event.shiftKey && !event.nativeEvent.isComposing) {
50 event.preventDefault();
51 send();
52 }
53 };
54 return (
55 <section aria-labelledby="home-ask" className="mx-auto flex w-full max-w-3xl flex-col items-center gap-5 pt-4 pb-2 md:pt-8">
56 <h1 id="home-ask" className="text-center text-[1.75rem] leading-tight font-semibold tracking-tight md:text-[2rem]">
57 What are we building today?
58 </h1>
59 <form onSubmit={submit} className="w-full">
60 <div className="flex items-end gap-2 rounded-2xl border border-line bg-surface p-2 pl-4 shadow-sm transition-shadow focus-within:border-accent-dim focus-within:ring-2 focus-within:ring-accent/25">
61 <MarkGlyph className="mb-2.5 h-4 shrink-0" />
62 <label htmlFor="home-ask-box" className="sr-only">
63 Ask g1t
64 </label>
65 <Textarea
66 id="home-ask-box"
67 value={draft}
68 onChange={(event) => setDraft(event.target.value)}
69 onKeyDown={onKeyDown}
70 rows={1}
71 maxLength={16_000}
72 placeholder="Ask g1t what changed, what's blocked, or what to do next"
73 className="field-sizing-content max-h-40 min-h-10 resize-none border-0 bg-transparent px-1 py-2 text-[0.9375rem] shadow-none focus-visible:ring-0"
74 />
75 <Hint label="Ask (Enter)">
76 <Button type="submit" variant="accent" size="icon-sm" disabled={!draft.trim()} aria-label="Ask" className="mb-1">
77 <ArrowUp size={15} />
78 </Button>
79 </Hint>
80 </div>
81 </form>
82 <Suggestions className="justify-center">
83 <Suggestion
84 suggestion={`Summarize what changed ${spanLabel(span)}`}
85 onPick={() => window.dispatchEvent(new CustomEvent(SUMMARIZE_EVENT))}
86 onPointerEnter={() => void loadSummary()}
87 className="border-accent-dim text-fg"
88 />
89 {HOME_STARTERS.map((starter) => (
90 <Suggestion key={starter.label} suggestion={starter.label} onPick={() => askG1t(starter.question)} />
91 ))}
92 </Suggestions>
93 </section>
94 );
95}
96
97/**
98 * What changed: g1t's summary of the span in plain English, on the page,
99 * a strip in the span's card. Asked only when the viewer presses
100 * Summarize (each answer is a call to the workspace's own AI provider);
101 * asked again for another span.
102 */
103export function WhatChangedCard({ slug, span, tz }: { slug: string; span: AskSpan; tz: string | null }) {
104 // Each ask is its own: Summarize again asks anew.
105 const [asked, setAsked] = useState<{ question: string; at: number } | null>(null);
106 const [done, setDone] = useState<{ channelId: string | null } | null>(null);
107 const card = useRef<HTMLDivElement>(null);
108 const label = spanLabel(span);
109
110 const summarize = useCallback(() => {
111 setDone(null);
112 setAsked({ question: summarizeQuestion(span, tz), at: Date.now() });
113 }, [span, tz]);
114
115 // Home's box asks for it: bring the card into view and start.
116 useEffect(() => {
117 const onAsk = () => {
118 card.current?.scrollIntoView({ behavior: "smooth", block: "start" });
119 summarize();
120 };
121 window.addEventListener(SUMMARIZE_EVENT, onAsk);
122 return () => window.removeEventListener(SUMMARIZE_EVENT, onAsk);
123 }, [summarize]);
124
125 const onDone = useCallback((channelId: string | null) => setDone({ channelId }), []);
126
127 return (
128 <div ref={card} className="scroll-mt-4 border-t border-line">
129 <div className="px-5 py-3.5">
130 {!asked ? (
131 <div className="flex flex-col gap-3 sm:flex-row sm:items-center">
132 <p className="grow text-sm text-muted">
133 <span className="font-medium text-fg">What changed, in plain English.</span> g1t reads the commits, pull requests, deploys and conversations {label} and
134 tells you what changed, why, and what is live.
135 </p>
136 <Button type="button" variant="accent" size="sm" onClick={summarize} onPointerEnter={() => void loadSummary()} className="shrink-0 self-start sm:self-auto">
137 <Sparkles size={14} />
138 Summarize
139 </Button>
140 </div>
141 ) : (
142 <>
143 <Suspense
144 fallback={
145 <div className="space-y-2.5">
146 <Skeleton className="h-3.5 w-11/12" />
147 <Skeleton className="h-3.5 w-3/4" />
148 </div>
149 }
150 >
151 <HomeSummary key={asked.at} slug={slug} question={asked.question} onDone={onDone} />
152 </Suspense>
153 {done && (
154 <div className="mt-4 flex flex-wrap items-center gap-2 border-t border-line pt-3">
155 <Button type="button" variant="soft" size="sm" onClick={openAsk}>
156 <MarkGlyph className="h-3" />
157 Ask a follow-up
158 </Button>
159 <Button type="button" variant="ghost" size="sm" onClick={summarize}>
160 <RotateCcw size={13} />
161 Summarize again
162 </Button>
163 {done.channelId && (
164 <Button asChild variant="ghost" size="sm" className="sm:ml-auto">
165 <Link to={`/${slug}/-/chat/dm/${done.channelId}`}>
166 <MessageSquare size={13} />
167 In your direct message with g1t
168 </Link>
169 </Button>
170 )}
171 </div>
172 )}
173 </>
174 )}
175 </div>
176 </div>
177 );
178}