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.

188 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/**
37 * Home's box that asks g1t, with a few things to ask first: under the
38 * daily signal, `compact`, it says to ask about any of it; on its own, it
39 * leads the page with what are we building today.
40 */
41export function HomeAsk({ span, compact = false }: { span: AskSpan; compact?: boolean }) {
42 const [draft, setDraft] = useState("");
43 const send = () => {
44 if (!draft.trim()) return;
45 askG1t(draft);
46 setDraft("");
47 };
48 const submit = (event: FormEvent) => {
49 event.preventDefault();
50 send();
51 };
52 const onKeyDown = (event: KeyboardEvent<HTMLTextAreaElement>) => {
53 if (event.key === "Enter" && !event.shiftKey && !event.nativeEvent.isComposing) {
54 event.preventDefault();
55 send();
56 }
57 };
58 return (
59 <section aria-labelledby="home-ask" className={compact ? "flex w-full flex-col gap-3" : "mx-auto flex w-full max-w-3xl flex-col items-center gap-5 pt-4 pb-2 md:pt-8"}>
60 {compact ? (
61 <h2 id="home-ask" className="text-sm font-semibold text-fg">
62 Ask about any of this
63 </h2>
64 ) : (
65 <h1 id="home-ask" className="text-center text-[1.75rem] leading-tight font-semibold tracking-tight md:text-[2rem]">
66 What are we building today?
67 </h1>
68 )}
69 <form onSubmit={submit} className="w-full">
70 <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">
71 <MarkGlyph className="mb-2.5 h-4 shrink-0 max-sm:hidden" />
72 <label htmlFor="home-ask-box" className="sr-only">
73 Ask g1t
74 </label>
75 <Textarea
76 id="home-ask-box"
77 value={draft}
78 onChange={(event) => setDraft(event.target.value)}
79 onKeyDown={onKeyDown}
80 rows={1}
81 maxLength={16_000}
82 placeholder="Ask g1t what changed, what's blocked, or what to do next"
83 className="field-sizing-content max-h-40 min-h-10 resize-none border-0 bg-transparent px-1 py-2 text-base shadow-none focus-visible:ring-0 sm:text-[0.9375rem]"
84 />
85 <Hint label="Ask (Enter)">
86 <Button type="submit" variant="accent" size="icon-sm" disabled={!draft.trim()} aria-label="Ask" className="mb-1">
87 <ArrowUp size={15} />
88 </Button>
89 </Hint>
90 </div>
91 </form>
92 <Suggestions className={compact ? "" : "justify-center"}>
93 <Suggestion
94 suggestion={`Summarize what changed ${spanLabel(span)}`}
95 onPick={() => window.dispatchEvent(new CustomEvent(SUMMARIZE_EVENT))}
96 onPointerEnter={() => void loadSummary()}
97 className="border-accent-dim text-fg"
98 />
99 {HOME_STARTERS.map((starter) => (
100 <Suggestion key={starter.label} suggestion={starter.label} onPick={() => askG1t(starter.question)} />
101 ))}
102 </Suggestions>
103 </section>
104 );
105}
106
107/**
108 * What changed: g1t's summary of the span in plain English, on the page,
109 * a strip in the span's card. Asked only when the viewer presses
110 * Summarize (each answer is a call to the workspace's own AI provider);
111 * asked again for another span.
112 */
113export function WhatChangedCard({ slug, span, tz }: { slug: string; span: AskSpan; tz: string | null }) {
114 // Each ask is its own: Summarize again asks anew.
115 const [asked, setAsked] = useState<{ question: string; at: number } | null>(null);
116 const [done, setDone] = useState<{ channelId: string | null } | null>(null);
117 const card = useRef<HTMLDivElement>(null);
118 const label = spanLabel(span);
119
120 const summarize = useCallback(() => {
121 setDone(null);
122 setAsked({ question: summarizeQuestion(span, tz), at: Date.now() });
123 }, [span, tz]);
124
125 // Home's box asks for it: bring the card into view and start.
126 useEffect(() => {
127 const onAsk = () => {
128 card.current?.scrollIntoView({ behavior: "smooth", block: "start" });
129 summarize();
130 };
131 window.addEventListener(SUMMARIZE_EVENT, onAsk);
132 return () => window.removeEventListener(SUMMARIZE_EVENT, onAsk);
133 }, [summarize]);
134
135 const onDone = useCallback((channelId: string | null) => setDone({ channelId }), []);
136
137 return (
138 <div ref={card} className="scroll-mt-4 border-t border-line">
139 <div className="px-5 py-3.5">
140 {!asked ? (
141 <div className="flex flex-col gap-3 sm:flex-row sm:items-center">
142 <p className="grow text-sm text-muted">
143 <span className="font-medium text-fg">What changed, in plain English.</span> g1t reads the commits, pull requests, deploys and conversations {label} and
144 tells you what changed, why, and what is live.
145 </p>
146 <Button type="button" variant="accent" size="sm" onClick={summarize} onPointerEnter={() => void loadSummary()} className="shrink-0 self-start sm:self-auto">
147 <Sparkles size={14} />
148 Summarize
149 </Button>
150 </div>
151 ) : (
152 <>
153 <Suspense
154 fallback={
155 <div className="space-y-2.5">
156 <Skeleton className="h-3.5 w-11/12" />
157 <Skeleton className="h-3.5 w-3/4" />
158 </div>
159 }
160 >
161 <HomeSummary key={asked.at} slug={slug} question={asked.question} onDone={onDone} />
162 </Suspense>
163 {done && (
164 <div className="mt-4 flex flex-wrap items-center gap-2 border-t border-line pt-3">
165 <Button type="button" variant="soft" size="sm" onClick={openAsk}>
166 <MarkGlyph className="h-3" />
167 Ask a follow-up
168 </Button>
169 <Button type="button" variant="ghost" size="sm" onClick={summarize}>
170 <RotateCcw size={13} />
171 Summarize again
172 </Button>
173 {done.channelId && (
174 <Button asChild variant="ghost" size="sm" className="sm:ml-auto">
175 <Link to={`/${slug}/-/chat/dm/${done.channelId}`}>
176 <MessageSquare size={13} />
177 In your direct message with g1t
178 </Link>
179 </Button>
180 )}
181 </div>
182 )}
183 </>
184 )}
185 </div>
186 </div>
187 );
188}